[LLVMdev] Generating GetElementPtr inlined in a function argument list programmatically

chentommy baiypwup at hotmail.com
Mon Aug 19 14:26:58 PDT 2013




Hello LLVMDev List,
It's my first time sending a message to the List - I have been working on a tool for my research project using LLVM. Thanks for your awesome work!
I have come across some bytecode like the following with an GetElementPtr instruction in brackets:
Bytecode:%3 = call i32 @_Z4funcPKc(i8* getelementptr inbounds ([5 x i8]* @.str2, i32 0, i32 0))
C++ code:func("bleh");
However when I am generating bytecode programmatically, I can not have the GetElementPtr value "inlined" in the function argument list:
Bytecode:%bbname = getelementptr inbounds [29 x i8]* @bbname10, i32 0, i32 0call void @incrementFaultSiteCount(i8* %bbname, i32 2)
C++ code: (What I mean to generate)incrementFaultSiteCount("BBName", 2);
My question is:- What is this phenomenon called, is it called "inlined/expanded function argument"?- It seems the "inlined" GetElementPtr instruction is just more concise and saves the need for a name for a register holding the value of the pointer. Is this correct?- I'm now generating the aforementioned instructions (non-inlined) with the following code snippet with LLVM 3.2. Is there a way to generate "inlined" GetElementPtr instructions when calling a function just like the first example programmatically?
-------------------------------------------------------------------BasicBlock* bb = (omitted)IRBuilder<> irb(bb);Value* global_str_ptr = irb.CreateGlobalString(bbn, "bbname");std::vector<Value*> indices;indices.push_back(ConstantInt::get(IntegerType::getInt32Ty(getGlobalContext()), 0));indices.push_back(ConstantInt::get(IntegerType::getInt32Ty(getGlobalContext()), 0));GetElementPtrInst* gep_str = GetElementPtrInst::CreateInBounds(global_str_ptr,	indices,	"bbname", bb->getFirstNonPHI());args.push_back(gep_str);args.push_back(ConstantInt::get(IntegerType::getInt32Ty(getGlobalContext()),	size));CallInst* inc_call = CallInst::Create(func_incrementFaultSitesEnumerated, args,	"", first_inst);-------------------------------------------------------------------
Thanks in advance!
Tommy Chen08-19-2013
 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130820/ea3df464/attachment.html>


More information about the llvm-dev mailing list