<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, Apr 18, 2013 at 11:11 PM, John Criswell <span dir="ltr"><<a href="mailto:criswell@illinois.edu" target="_blank">criswell@illinois.edu</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
  
    
  
  <div bgcolor="#FFFFFF" text="#000000"><div class="im">
    <div>On 4/18/13 9:56 AM, Jun Koi wrote:<br>
    </div>
    <blockquote type="cite">
      
      <div dir="ltr">
        <div>
          <div>
            <div>hi,<br>
              <br>
              i am writing a simple LLVM pass to analyze the Store
              instruction.<br>
              my pass derives from InstVisitor class, and the method to
              handle Store instruction is like this:<br>
              <br>
              void MyPass::visitStoreInst(StoreInst &I) {<br>
              ...<br>
              }<br>
              <br>
              It is pretty simple to handle Store. however, in on test i
              got an instruction like below:<br>
              <br>
                store i8 %tmp5, i8* inttoptr (i32 301959828 to i8*)<br>
            </div>
          </div>
        </div>
      </div>
    </blockquote>
    <br></div>
    The inttoptr used here is a Constant Expression
    (llvm::ConstantExpr).  You'll need to take the operand to the store,
    cast it to llvm::ConstantExpr, and then examine the opcode and
    operands of the constant expression.<br>
    <br>
    The ConstantExpr class is documented at
    <a href="http://llvm.org/doxygen/classllvm_1_1ConstantExpr.html" target="_blank">http://llvm.org/doxygen/classllvm_1_1ConstantExpr.html</a> and is
    described in the LLVM Language Reference Manual.<br>
    <br></div></blockquote><div><br></div><div>OK, I tried my best, and come up with code like below:<br> <br>void MyPass::visitStoreInst(StoreInst &I)<br>{<br>    Value *op2 = I.getOperand(1);    // the address where we store data<br>

<br>    if (const ConstantExpr *c = dyn_cast <ConstantExpr>(op2)) {<br>    // how to extract the Int Constant here?<br>    }<br>}<br><br></div><div>The problem is that given ConstantExpr, i am not sure how to extract the Int Constant operand.<br>

</div><div>According to     <a href="http://llvm.org/doxygen/classllvm_1_1ConstantExpr.html" target="_blank">http://llvm.org/doxygen/classllvm_1_1ConstantExpr.html</a>, this class only provides method such as getWithOperands(), but this method doesnt seem to do what I want.<br>

<br></div><div>I grep through the code of LLVM, but cannot find any example doing this.<br><br>any more hint, please?<br><br>Thanks,<br>Jun<br></div></div></div></div>