【发布时间】:2013-11-18 22:12:34
【问题描述】:
我有想要使用fadd 添加的ConstantInt 和ConstantFP 值。但是,我无法将 ConstantInt 转换为 fadd 可以接受的浮点数。
以下是代码的摘录:
Value* left = ConstantInt::get(Type::getInt64Ty(getGlobalContext()), 12, true);
Value* right = ConstantFP::get(Type::getFloatTy(getGlobalContext()), 11.6);
Instruction* cast = CastInst::Create(Instruction::SIToFP, left, left->getType(), "", currentBlock());
left = cast->getOperand(0);
BinaryOperator::Create(Instruction::FAdd, left, right, "", currentBlock());
其中currentBlock() 返回BasicBlock。在尝试为此生成操作码后,LLVM 抱怨它无法添加这两个值,因为它们不一样。
我对 LLVM 比较陌生,所以如果这段代码没有意义,我会接受任何建议。
【问题讨论】:
标签: c++ llvm llvm-c++-api