用LLVM中的指令代替教学的RHS

发布于 2025-01-24 11:37:02 字数 388 浏览 0 评论 0原文

假设这是一个问题,

我有以下我想要的说明

%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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦萦几度 2025-01-31 11:37:03

%add =%t1 // psuedo代码,因为我不知道该如何

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和免费它的内存(要求ellvm ::指令*,而不是常数(永不删除)或参数(删除它需要更改函数的类型))。

如果您可以编写%add = copy%t1,则说add- add-> deprAceAllaseWith(t1); and remove %add add add add add ad add代码>用%T1替换它。

%add = %T1 //psuedo code as I do not know how to this

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 single llvm::Instruction* in memory. If you call I->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 call I->setOperand(1, D) (where D is the llvm::Value* for %d). In another case, suppose you have %e = add i32 %f, 0 and you'd like to remove it. Call E->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 that E is an llvm::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 say Add->replaceAllUsesWith(T1); and remove %add replacing it with %t1 everywhere.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文