<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>
<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();
Value *result = ConstantInt::get(ii->getType(), bit_size);
ii->replaceAllUsesWith(result);
ii->removeFromParent();
delete ii;
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>