<div class="gmail_extra">I read the tutorial doc and some info of SSA, finally understand it. Thanks for your help.<br><br>And the segmentation error of loading arguementation occurs, (gdb error info)<br>Program received signal SIGSEGV, Segmentation fault.<br>

0x0855bb68 in llvm::LoadInst::LoadInst(llvm::Value*, char const*, bool, llvm::Instruction*) ()<br>code is like follows:<br>//#include necessary header files<br><br>int main(){<br>    InitializeNativeTarget();<br>    LLVMContext Context; <br>
    module = new Module("Program", Context);<br><br>    vector<Type *> argslist;<br>    argslist.push_back(Type::getDoubleTy(Context));<br>    FunctionType *funType = FunctionType::get(Type::getDoubleTy(Context), argslist, false);<br>
    Function *fun= cast<Function> ( module->getOrInsertFunction("fun", funType));<br><br>    BasicBlock * block = BasicBlock::Create(Context, "mainBlock", fun);<br>    IRBuilder<> builder(block);<br>
    Function::arg_iterator itr = fun->arg_begin();<br>    builder.CreateLoad(itr);<br><br>    Value *result = ConstantFP::get(Type::getDoubleTy(getGlobalContext()), 1.0);<br>    builder.CreateRet(result);<br><br>    vector<GenericValue> args;<br>
    ExecutionEngine *e  = EngineBuilder(module).create();<br>    outs()<<*module<<"\n";<br>    outs().flush();<br>    return 0;<br>}<br><br>I'm confused that   arg_iterator itr (  Function::arg_iterator itr = fun->arg_begin(); ) can be used in CreateStore() function, however, it can not be used as the arguments of CreateLoad() function.<br>
<br><br><div class="gmail_quote">2012/4/22 Hongbin Zheng <span dir="ltr"><<a href="mailto:etherzhhb@gmail.com" target="_blank">etherzhhb@gmail.com</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
hi<br>
<div class="im"><br>
On Sun, Apr 22, 2012 at 8:36 PM, Jianfei Hu <<a href="mailto:hujianfei258@gmail.com">hujianfei258@gmail.com</a>> wrote:<br>
> in the  tutorial of official llvm doc, chapter 3, it deals with arguement of<br>
> function as follow:<br>
><br>
> for (Function::arg_iterator AI = F->arg_begin(); Idx != Args.size();<br>
>        ++AI, ++Idx) {<br>
>     AI->setName(Args[Idx]);<br>
><br>
>     // NamedValues is map<string, Value*><br>
>     NamedValues[Args[Idx]] = AI;<br>
><br>
> and when it try to get the value of arguement, it simply does:<br>
><br>
> Value *VariableExprAST::Codegen() {<br>
>   Value *V = NamedValues[Name];<br>
>   return V ? V : ErrorV("Unknown variable name");<br>
> }<br>
><br>
> It means that we can access value of arguement directly.<br>
</div>Yes, it is possible to access the values (virtual registers) direclty,<br>
but you may need to construct SSA form by yourself.<br>
<div class="im">><br>
> However, in <a href="http://llvm.org/demo" target="_blank">llvm.org/demo</a> and the chapter 6 of tutorial, it deals with<br>
> arguemnt:<br>
> 1. allocate memory for arguement<br>
> 2. then store the arguemnt into the memory.<br>
> 3. CreateLoad() to load the arguement when accessing the value of arguement.<br>
><br>
> I have several problems:<br>
> Which way should I follow to get the vale of arguement?<br>
</div>If you do not want to construct SSA from by yourself, you probably<br>
should follow this way. You can schedule the "mem2reg"[1] after you<br>
build the IR, it will promote alloca/load/store into scalar virtual<br>
registers for you. (I remember the tutorial had a discussion about<br>
this.)<br>
<div class="im">><br>
> When I tried to use CreateLoad(arguement), the program gives a segmentation<br>
> error.<br>
> Does this result from the wrong type of argument, unsuitable to be the<br>
> params of CreateLoad()?<br>
</div>Could you paste your code? Had you initialize the IRBuilder with<br>
insert position?<br>
<div class="im">> If it is, what's the type of Function->arg_begin() ? (The source code is too<br>
> nested for me to find the original type of that)<br>
><br>
<br>
</div>best regards<br>
ether<br>
[1]<a href="http://llvm.org/docs/doxygen/html/Mem2Reg_8cpp_source.html" target="_blank">http://llvm.org/docs/doxygen/html/Mem2Reg_8cpp_source.html</a><br>
</blockquote></div><br></div>