比方說,我們有一些代碼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