用LLVM中的指令代替教学的RHS
假设这是一个问题,
我有以下我想要的说明
%add = add nsw i32 %argc, 50
,首先要创建一个二进制指令
%T1 = add nsw i32 %argc, 50
%add = add nsw i32 %argc, 50
,然后以某种方式将%add的指令替换为T1分配,因为以下
%add = %T1 //psuedo code as I do not know how to this
需要一些建议,以实现“%” add =%t1“
bakcground: 我需要这种植物来进行我的懒惰代码运动分析
Here is the problem,
Lets say suppose, I have the following instruction
%add = add nsw i32 %argc, 50
I would like at first, create a Binary instruction something like below
%T1 = add nsw i32 %argc, 50
%add = add nsw i32 %argc, 50
And then somehow replace %add's instruction with an assignment to T1 as below
%add = %T1 //psuedo code as I do not know how to this
Need some suggestion to how to implement "%add = %T1"
Bakcground:
I need this kind of implemenatation for my Lazy Code Motion analysis
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
LLVM IR中没有任务运算符,因此您不能按原样写入,但是好消息是您不需要。
%name =添加i32%,%
是单个指令,在内存中的单个llvm ::指令*
。如果您调用i-> getName()
在该指令上,您将获得名称为“名称”。 LLVM根本没有分配运算符,印刷文本表单中的平等符号是一个虚构的小说,使其更容易阅读。由于LLVM为SSA形式,因此无需分配运算符,每个寄存器都会在创建时一次分配给一次,并且永远无法突变或重新分配到。这是两个常见情况。假设您有
%a =添加i32%b,%c
,您想用%c
用%d
替换此用途。反而。您可以调用i-> setoperand(1,d)
(其中d是llvm :: value*
for%d
)。在另一种情况下,假设您有%e =添加i32%f,0
,您想将其删除。调用e-> prepAceAllaseWith(f); e-> erasefromparent();
。第一个语句将在任何地方找到%e
,并用%f
替换为,该语句将删除现有的%e
和免费它的内存(要求e
是llvm ::指令*
,而不是常数(永不删除)或参数(删除它需要更改函数的类型))。如果您可以编写
%add = copy%t1
,则说add- add-> deprAceAllaseWith(t1);
and remove%add add add add add ad add
代码>用%T1
替换它。There is no assignment operator in LLVM IR so you can't write that as-is, but the good news is that you never need to.
%name = add i32 %this, %that
is a single instruction, a singlellvm::Instruction*
in memory. If you callI->getName()
on that instruction you will get the name "name". LLVM has no assignment operator at all, the equals sign in the printed text form is a fiction to make it easier to read. There's no need for an assignment operator because LLVM is in SSA form, every register is assigned to once when created and can never be mutated or reassigned to.Here's two common situations. Suppose you have
%a = add i32 %b, %c
and you'd like to replace this one use of%c
with%d
instead. You may callI->setOperand(1, D)
(where D is thellvm::Value*
for%d
). In another case, suppose you have%e = add i32 %f, 0
and you'd like to remove it. CallE->replaceAllUsesWith(F); E->eraseFromParent();
. The first statement will find everywhere%e
is mentioned and replace it with%f
, the statement will delete the now-unused%e
and free its memory (requires thatE
is anllvm::Instruction*
, not a Constant (never deleted) or Argument (deleting it requires changing the type of the function)).If you could write
%add = copy %T1
then it would also be valid to sayAdd->replaceAllUsesWith(T1);
and remove%add
replacing it with%t1
everywhere.