比方说,我们有一些代码LLVM代码生成:恒定值fptoui指令
%conv = fptoui double -1 to i32
执行转化%后为4294967295确定。但是,当我试图生成这样的代码,我叫
Builder.CreateFPToUI(val, Builder.getInt32Ty())
其中val是ConstantFP其值是-1,则返回ConstantInt其值为0,而不是4294967295!有人可以解释为什么吗?
UPD: Example.Let说,我需要生成IR下一码
a << -1
代码生成会像水木清华
Value* one; // for 1 literal
Value* minusOne; // for -1
Value* a; //represents variable a
....
one = llvm::ConstantFP::get(Builder.getDoubleTy(), 1);
....
/* Negation. CreateFSub also doesn't emits instruction but returns ConstantFP with -1 value */
minusOne = CreateFSub(ConstantFP::getZeroValueForNegation(Builder.getDoubleTy()), one);
....
Value* unsignedOne = Builder.CreateFPToUI(minusOne, Builder.getInt32Ty());
....
Value* shift = Builder.CreateShl(a, unsignedOne, "shl");
而这一切,只是变成了
%shl = shl i32 %a, 0
“返回值为0的constantint” - 您使用什么代码来获取常量值? – Oak
我不需要这个值,所以我只是在调试器中观察它。但是如果你有兴趣获得int值,你可以使用像下面这样的smth:dyn_cast(value) - > getValue()。getWord() –
user1215562