def-use 指令链
我是一个 LLVM 新手,想要获取示例代码的所有指令的 use-def 链,为此我使用以下代码。
示例代码:
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#define ARRAY_SIZE 5
int main() {
int x, y, holder;
int k,z,f,i;
z=0;
f=0;
k=0;
for(x = 0; x < ARRAY_SIZE; x++)
for(y = 0; y < ARRAY_SIZE-1; y++)
if(x+y>10) {
holder = x+y;
k=z+1;
f=k+x;
if (i>k)
i=i+1;
}
// return 1;
}
pass code:
virtual bool runOnFunction(Function &F) {
std::vector<Instruction*> worklist;
for(inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I){
worklist.push_back(&*I);
}
for(std::vector<Instruction*>::iterator iter = worklist.begin();
iter != worklist.end(); ++iter){
Instruction* instr = *iter;
errs() << "def: " <<*instr << "\n";
for(Value::use_iterator i = instr->use_begin(), ie = instr->use_end();
i!=ie; ++i){
Value *v = *i;
Instruction *vi = dyn_cast<Instruction>(*i);
errs() << "\t\t" << *vi << "\n";
}
}
return false;
}
output: def: ret void
但我的输出不是我的目标,有人可以帮助我吗?
谢谢
I am a LLVM newer who want to obtain the use-def chain for all instruction of a sample code, for this purpose i use the following code.
sample code:
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#define ARRAY_SIZE 5
int main() {
int x, y, holder;
int k,z,f,i;
z=0;
f=0;
k=0;
for(x = 0; x < ARRAY_SIZE; x++)
for(y = 0; y < ARRAY_SIZE-1; y++)
if(x+y>10) {
holder = x+y;
k=z+1;
f=k+x;
if (i>k)
i=i+1;
}
// return 1;
}
pass code:
virtual bool runOnFunction(Function &F) {
std::vector<Instruction*> worklist;
for(inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I){
worklist.push_back(&*I);
}
for(std::vector<Instruction*>::iterator iter = worklist.begin();
iter != worklist.end(); ++iter){
Instruction* instr = *iter;
errs() << "def: " <<*instr << "\n";
for(Value::use_iterator i = instr->use_begin(), ie = instr->use_end();
i!=ie; ++i){
Value *v = *i;
Instruction *vi = dyn_cast<Instruction>(*i);
errs() << "\t\t" << *vi << "\n";
}
}
return false;
}
output: def: ret void
but my output isn't my aim, can anyone help me?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
示例代码中的
main()
除了更改局部变量的值之外什么也不做 - 它不可能对任何事物产生任何外部可见的影响,因为它不调用任何外部函数,也不更改任何全局变量变量,或取消引用任何指针。所以我怀疑在运行密码之前,除了返回之外,所有这些都被优化了。
main()
in your sample code does nothing except changing the values of local variables - it can't possibly have any externally visible effect on anything, as it doesn't call any external functions, change any global variables, or dereference any pointers.So I suspect that it is all being optimised away to nothing except a return, before your pass code is run.