<html>
  <head>
    <meta content="text/html; charset=windows-1252"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <div class="moz-cite-prefix">On 11/05/2014 02:04 PM, Dingbao Xie
      wrote:<br>
    </div>
    <blockquote
cite="mid:CAJH+FQwmzpgotg9yQNV+Pd-xVX45G0q2vfxHrfLxZ+DkFktBAQ@mail.gmail.com"
      type="cite">
      <meta http-equiv="Content-Type" content="text/html;
        charset=windows-1252">
      <div dir="ltr">
        <div class="" itemprop="text">
          <p>The documentation of LLVM says that "The llvm.objectsize
            intrinsic is lowered to a constant representing the size of
            the object concerned". I'm attempting to lower this
            intrinsic function to a constant in a pass. Below is the
            code snippet that I wrote:</p>
        </div>
      </div>
    </blockquote>
    Why do you need to handle this yourself? This should already be
    handled for you (see InstCombineCalls.cpp). However, you have a few
    problems with this.<br>
    <br>
    <blockquote
cite="mid:CAJH+FQwmzpgotg9yQNV+Pd-xVX45G0q2vfxHrfLxZ+DkFktBAQ@mail.gmail.com"
      type="cite">
      <div dir="ltr">
        <div class="" itemprop="text">
          <pre><code>for (BasicBlock::iterator i = b.begin(), ie = b.end();
   (i != ie) && (block_split == false);) {
 IntrinsicInst *ii = dyn_cast<IntrinsicInst>(&*i);
 ++i;  
 if(ii) {
 switch (ii->getIntrinsicID()) {
  case Intrinsic::objectsize: {
   IRBuilder<> builder(ii->getParent(), ii);
   Value *op1 = ii->getArgOperand(0); //i8*
   uint64_t bit_size = op1->getType()->getPointerElementType()->getPrimitiveSizeInBits();</code></pre>
        </div>
      </div>
    </blockquote>
    First, you can't always determine the size. Just looking at the
    pointer element type isn't enough. This requires finding the object
    definition, which can fail, and the existing handling uses
    llvm::getObjectSize to for. In general when looking at type sizes
    you don't want to use getPrimitiveSizeInBits, and should use the
    DataLayout for various reasons.<br>
    <br>
    <code></code>
    <blockquote
cite="mid:CAJH+FQwmzpgotg9yQNV+Pd-xVX45G0q2vfxHrfLxZ+DkFktBAQ@mail.gmail.com"
      type="cite">
      <div dir="ltr">
        <div class="" itemprop="text">
          <pre><code>
   Value *result = ConstantInt::get(ii->getType(), bit_size);
   ii->replaceAllUsesWith(result);
   ii->removeFromParent();
   delete ii;</code></pre>
        </div>
      </div>
    </blockquote>
    <code>You shouldn't use delete here. You probably want
      ii->eraseFromParent().<br>
    </code>
    <blockquote
cite="mid:CAJH+FQwmzpgotg9yQNV+Pd-xVX45G0q2vfxHrfLxZ+DkFktBAQ@mail.gmail.com"
      type="cite">
      <div dir="ltr">
        <div class="" itemprop="text">
          <pre><code>
   break;
  }
 }
}
</code></pre>
          <p>I'm new to LLVM and not sure whether the implementation is
            correct.
            Can anybody tell me whether the implementation is correct?</p>
          <p>
            Thanks in advance.</p>
        </div>
        <br clear="all">
        <br>
        -- <br>
        <div class="gmail_signature">
          <div dir="ltr">
            <div>Dingbao Xie<br>
            </div>
          </div>
        </div>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
LLVM Developers mailing list
<a class="moz-txt-link-abbreviated" href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a>         <a class="moz-txt-link-freetext" href="http://llvm.cs.uiuc.edu">http://llvm.cs.uiuc.edu</a>
<a class="moz-txt-link-freetext" href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a>
</pre>
    </blockquote>
    <br>
  </body>
</html>