llvm - 如何制定新的 LLVM 指令?
问题描述
我正在尝试做出指示
%a = i32 add %b, %c
进入
%a = i32 mul %b, %c
我一直在寻找几个小时,但到目前为止我发现的答案是与创建在 Instructions.h(前 AllocaInst)中定义的新指令相关的答案,而不是 mul、sdiv、div、指令。我还阅读了https://llvm.org/docs/ProgrammersManual.html#creating-and-inserting-new-instructions 但我无法获得示例“auto *newInst = new Instruction(...);” 工作,因为即使在查看https://llvm.org/doxygen/classllvm_1_1Instruction.html#a2b30181f228bc6318130557d7ffca945之后我也不知道应该是什么参数
编辑:我认为我已经成功地创建了指令本身,但不是我无法以正确的方式替换它。
Instruction *ni = BinaryOperator::CreateMul(inst.getOperand(0), newvalue);
ReplaceInstWithInst(*i, ni);
其中 *i 来自对基本块的迭代(例如 (auto &i : bb))
解决方案
解决了!
Instruction *ni = BinaryOperator::CreateMul(inst.getOperand(0), newvalue);
bb.getInstList().insert(inst.getIterator(), ni);
推荐阅读
- c# - 存储更新、插入或删除语句影响了意外的行数 (0),实体框架
- vb.net - VB.NET 更改 TableAdapter 中的 SQL 查询?
- jquery - jquery checkoxes 和 php 循环
- sql - Get first value of column without using TOP 1
- c++ - 使用 C++11 的 STLPort
- swift - 计算属性和在 Swift 中将函数设置为变量之间的区别
- webforms - DropdownList asp web表单控件
- regex - 在bash中替换文件名字符串变量后的字符
- python - 将带有分子和分母的分数转换为二进制
- rest - 如何使用已经存在的 EJB 项目制作宁静的服务?