Inserting Instructions (pass)

Hi,

I’ am trying to insert an InlineAsm Instruction in my pass, which FunctionType do I need for Inlineasm?

If I understand it right, I need a call instruction to insert the new produced InlineAsm?

Thanks for help,

Michael

for (BasicBlock::iterator bi = i->begin(), be = i->end(); bi != be; ++bi){

std::vector<const Type*> asm_arguments;

FunctionType *asm_type = FunctionType::get(Type::VoidTy, asm_arguments, false);

InlineAsm* au = new InlineAsm(asm_type ???, “isync”,“~{dirflag},~{fpsr},~{flags}”,true);

//CallInst* ae = new CallInst(au ??);

//Works fine

AllocaInst* ai = new AllocaInst(Type::Int16Ty);

Instruction *pi = bi;

pi->getParent()->getInstList().insert(pi, ai);

}

Test.ll

call void asm sideeffect “isync”, “~{dirflag},~{fpsr},~{flags}”() nounwind

llvm::FunctionType

public:

/// FunctionType::get - This static method is the primary way of constructing

/// a FunctionType.

///

static FunctionType *get(

const Type *Result, ///< The result type, isync is Void

const std::vector<const Type*> &Params, ///< The types of the parameters ???

bool isVarArg ///< Whether this is a variable argument length function, isync false?

);

Hi,
I’ am trying to insert an InlineAsm Instruction in my pass, which FunctionType do I need for Inlineasm?
If I understand it right, I need a call instruction to insert the new produced InlineAsm?

Thanks for help

Inline asm works like a “callee”. So for:

call void asm sideeffect “isync”, “~{dirflag},~{fpsr},~{flags}”() nounwind

The thing your calling has type “void()*”. You just pass “void()” into the InlineAsm ctor.

-Chris

Thank you Chris,

for your hint, but I am still too stupid. I tried two versions

asm_arguments.push_back(Type::VoidTy);

FunctionType *asm_type = FunctionType::get(Type::VoidTy, asm_arguments, false);

Alternatively

FunctionType asm_type = FunctionType::get(Type::VoidTy, std::vector<const Type>(), false);

. Can you give me a snippet of example code, or somebody else?

Thanks for help

Michael

for (BasicBlock::iterator bi = i->begin(), be = i->end(); bi != be; ++bi){

std::vector<const Type*> asm_arguments;

asm_arguments.push_back(Type::VoidTy);

FunctionType *asm_type = FunctionType::get(Type::VoidTy, asm_arguments, false);

InlineAsm* au = new InlineAsm(asm_type ???, “isync”,“~{dirflag},~{fpsr},~{flags}”,true);

//CallInst* ae = new CallInst(au ??);

//Works fine

AllocaInst* ai = new AllocaInst(Type::Int16Ty);

Instruction *pi = bi;

pi->getParent()->getInstList().insert(pi, ai);

}

Yes, either of these should work. What problem are you seeing?

-Chris

Hi,

both versions are working:

FunctionType asm_Ftype = FunctionType::get(Type::VoidTy, std::vector<const Type>(), false);

InlineAsm* Iasm = InlineAsm::get(asm_Ftype,“isync”,“~{dirflag},~{fpsr},~{flags}”,true);

How can I insert this InlineAsm, because it is no instruction and this way it will not work:

Instruction *pi = bi;

pi->getParent()->getInstList().insert(pi, Iasm);

I try to build a CallInst with a function, but I have still some problems

Function *NewF = new Function(asm_Ftype,???,???);

CallInst* NewCInst = new CallInst(NewF, ???

But where to set the InlineAsm and what type of LinkageType is required …?

Thanks for help

Michael

Hi,

my last question can be ignored, now it’s working fine, thank you Chris for your help.

Michael