[llvm-commits] [llvm] r71427 - /llvm/trunk/lib/CodeGen/IntrinsicLowering.cpp
Jay Foad
jay.foad at gmail.com
Mon May 11 08:38:55 PDT 2009
>> +// Return the integer value Val zero-extended or truncated (if necessary) to
>> +// type ITy. Any new instructions are inserted at InsertBefore.
>
> this sounds like a generally useful thing, so shouldn't be here.
I'll move it if you can suggest where it should go. I guess an extra
"bool signed = false" argument would be in order, to make it a bit
more generic.
>> +template<typename InsertType>
>> +static Value *getZExtOrTrunc(Value *Val, const IntegerType *ITy,
>> + InsertType InsertPoint) {
>> + const IntegerType *ValTy = cast<IntegerType>(Val->getType());
>> + if (ValTy == ITy)
>> + return Val;
>> + Constant *CVal = dyn_cast<Constant>(Val);
>> + if (ValTy->getBitWidth() < ITy->getBitWidth()) {
>> + if (CVal)
>> + return ConstantExpr::getZExt(CVal, ITy);
>> + return new ZExtInst(Val, ITy, "", InsertPoint);
>> + } else {
>> + if (CVal)
>> + return ConstantExpr::getTrunc(CVal, ITy);
>> + return new TruncInst(Val, ITy, "", InsertPoint);
>> + }
>> +}
>
> Doesn't the IRBuilder stuff already do this? If so, why not just
> use a builder here?
I'm not familiar with the IRBuilder. I was just following the style of
the existing code.
Cheers,
Jay.
More information about the llvm-commits
mailing list