<html>
<head>
<style>
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 9pt;
font-family:新細明體
}
</style>
</head>
<body class='hmmessage'>
<font style="font-size: 12pt;" face="Arial" size="3">Thank you for your answer.  But there is still a problem.</font><font style="font-size: 12pt;" face="Arial" size="3"><br></font><font style="font-size: 12pt;" face="Arial" size="3"><br></font><font style="font-size: 12pt;" face="Arial" size="3">You seem correct about how to define a constant operand.  So I added it into my code, like so:</font><font style="font-size: 12pt;" face="Arial" size="3"><br></font><font style="font-size: 12pt;" face="Arial" size="3">       Builder.SetInsertPoint(LLVMBB, I);</font><font style="font-size: 12pt;" face="Arial" size="3"><br>    </font><font style="font-size: 12pt;" face="Arial" size="3">   Constant *C = ConstantInt::get(APInt(32, 5, false));</font><font style="font-size: 12pt;" face="Arial" size="3"><br></font><font style="font-size: 12pt;" face="Arial" size="3">        Instruction *newI=Builder.Create!
 Load(C,"");</font><font style="font-size: 12pt;" size="3"><br>
</font><font style="font-size: 12pt;" size="3"><br><font style="" face="Arial">It compiles. But it still aborts at runtime with a complaint that the type is not right.</font><font style="" face="Arial"><br></font><font style="" face="Arial">This leads me to think that immediate loads are not generated with the CreateLoad </font><font style="" face="Arial"><br></font><font style="" face="Arial">instruction?</font><font style="" face="Arial"><br></font><font style="" face="Arial"><br></font><font style="" face="Arial">Another person's reply to my question indicated that a way to avoid inserting the <br>immediate load</font><font style="" face="Arial"> entirely; but that is also not what I want, because my explicit purpose <br>in inserting this</font><font style="" face="Arial"> load is to claim a register.</font><font style="" face="Arial"><br></font><font style="" face="Arial"><br></font><font style="" face="Arial">Thank you,</font><font style="" face="Arial"><br></font><font!
  style="" face="Arial">Kao Chang</font><br></font><br><hr id="stopSpelling">Date: Tue, 5 May 2009 16:07:33 +0200<br>From: meurant.olivier@gmail.com<br>To: llvmdev@cs.uiuc.edu<br>Subject: Re: [LLVMdev] A problem creating operands for a new IR instruction to the mailing list<br><br>If you want an immediate constant value, ConstantInt::get(APInt(32, 5, false)) will perhaps help you ?<br><br>Olivier.<br><br><div class="EC_gmail_quote">2009/5/5 seventh moon <span dir="ltr"><<a href="mailto:suigintou_@hotmail.com">suigintou_@hotmail.com</a>></span><br>
<blockquote class="EC_gmail_quote" style="padding-left: 1ex;">



<div>
<font style="font-size: 12pt;" size="3">I have a question about inserting instructions into the LLVM IR.  I can insert instructions, but my operands do not have the right type, so it fails an assertion at runtime.</font><font style="font-size: 12pt;" size="3"><br>
</font><font style="font-size: 12pt;" size="3"><br></font><font style="font-size: 12pt;" size="3">I am trying to insert an immediate load instructions, as a means of claiming a new register.</font><font style="font-size: 12pt;" size="3"><br>
</font><font style="font-size: 12pt;" size="3"><br></font><font style="font-size: 12pt;" size="3">Here is what I do:</font><font style="font-size: 12pt;" size="3"><br></font><font style="font-size: 12pt;" size="3">    Builder.SetInsertPoint(LLVMBB, I);</font><font style="font-size: 12pt;" size="3"><br>
</font><font style="font-size: 12pt;" size="3"><br></font><font style="font-size: 12pt;" size="3">// The following line looks to me like it would have a chance o!
 f loading either</font><font style="font-size: 12pt;" size="3"><br></font><font style="font-size: 12pt;" size="3">// address 5, or else immediate value 5. Unfortunately, it does neither. It compiles</font><font style="font-size: 12pt;" size="3"><br>
</font><font style="font-size: 12pt;" size="3">// but crashes at runtime, that the type of the operand is incompatible</font><font style="font-size: 12pt;" size="3"><br></font><font style="font-size: 12pt;" size="3">        Instruction *newI=Builder.CreateLoad(5,"");</font><font style="font-size: 12pt;" size="3"><br>
</font><font style="font-size: 12pt;" size="3"><br></font><font style="font-size: 12pt;" size="3">// I also tested this, just to do a little sanity check. It also compiles then</font><font style="font-size: 12pt;" size="3"><br>
</font><font style="font-size: 12pt;" size="3">// crashes, for the obvious reason that the operand is a register, but an address</font><font style="" size="3"><br></font><font style="font-size: 12pt;" size="3">// or an immediate value is expected.</font><font style="font-size: 12pt;" size="3"><br>
</font><font style="font-size: 12pt;" size="3">        //Instruction *newI=Builder.CreateLoad(I->getOperand(1),""); // also wrong</font><font style="font-size: 12pt;" size="3"><br></font><font style="font-size: 12pt;" size="3"><br>
</font><font style="font-size: 12pt;" size="3">So to say it simply, my question is, "How can I create a new Value*, which indicates</font><font style="font-size: 12pt;" size="3"><br></font><font style="font-size: 12pt;" size="3">an immediate value, such as immediate value 5?"</font><font style="font-size: 12pt;" size="3"><br>
</font><font style="font-size: 12pt;" size="3"><br></font><font style="font-size: 12pt;" size="3">Thank you for your assistance,</font><font style="font-size: 12pt;" size="3"><br></font><font style="font-size: 12pt;" size="3">Kao Chang<br>
<hr>用部落格分享照片、影音、趣味小工具和最愛清單,盡情秀出!
 你自己 — <a href="http://home.spaces.live.com/?showUnauth=1&lc=1028">Windows Live Spaces</a></font></div>
<br>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
<br></blockquote></div><br><br /><hr />隨身的 Windows Live Messenger 和 Hotmail,不限時地掌握資訊盡在指間— <a href='http://3c.msn.com.tw/mobile/' target='_new'>Windows Live for Mobile</a></body>
</html>