• llvm dominator


    
    #include
    #include "llvm/ExecutionEngine/Orc/LLJIT.h"
    #include
    #include
    #include "llvm/ExecutionEngine/Orc/LLJIT.h"
    #include "llvm/IR/Function.h"
    #include "llvm/IR/IRBuilder.h"
    #include "llvm/IR/Module.h"
    #include "llvm/Support/CommandLine.h"
    #include "llvm/Support/InitLLVM.h"
    #include "llvm/Support/TargetSelect.h"
    #include "llvm/Support/raw_ostream.h"
    #include "llvm/Transforms/Utils/Mem2Reg.h"
    #include"llvm/IR/LegacyPassManager.h"
    #include "llvm/Transforms/Utils.h"
    #include
    #include
    #include
    #include
    using namespace std;
    using namespace llvm;
    
    std::unique_ptr<LLVMContext> TheContext;
    
    void myprint(llvm::DominatorTree& tree) {
    	auto t = tree.getRootNode();
    	queue<llvm::DomTreeNode*> q;
    	q.push(t);
    	while (q.size()) {
    		auto t = q.front();
    		q.pop();
    		outs() << t->getBlock()->getName() << "{ ";
    		for (auto elem : *t) {
    			outs() << elem->getBlock()->getName() << " ";
    			q.push(elem);
    		}outs() << "}\n";
    	}
    }
    void printDF(DominanceFrontier& DF, DominatorTree& tree) {
    	auto a = tree.getRootNode();
    	queue<DomTreeNode*> q;
    	q.push(a);
    	while (q.size()) {
    		auto t = q.front();
    		q.pop();
    		set<BasicBlock*> ans = DF.calculate(tree,t);
    		for (auto i : ans)outs() << i->getName() << " ";
    		outs() << "\n";
    		for (auto i : t->children())q.push(i);
    	}
    }
    
    
    
    int main(int argc,char **argv) {
    	if (argc < 2) {
    		errs() << "Expected an argument - IR file name\n";
    		return 0;
    	}
    	TheContext = make_unique<LLVMContext>();
    	llvm::SMDiagnostic Err;
    	auto TheModule = parseIRFile(argv[1], Err, *TheContext);
    	auto func=TheModule->getFunction("add");
    
    	auto dom = DominatorTree::DominatorTree(*func);
    	dom.updateDFSNumbers();
    	dom.print(outs());
    	DominanceFrontier DF = DominanceFrontier();
    	printDF(DF, dom);
    	//myprint(dom);
    	
    	
    
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
  • 相关阅读:
    平板用电容笔还是触控笔?双十一值得买电容笔推荐
    ws升级为wss
    socket编程中服务器端常用函数以及简单实现
    仅从个人的角度,聊聊年底的程序员招聘与入职情况
    Java BIO模型分析(提供单线程和多线程服务端代码示例)
    架构基本概念和架构本质
    关于flume 采集kafka问题
    python编程题3
    [算法刷题笔记]二叉树之左叶子之和
    flutter笔记-主要控件及布局
  • 原文地址:https://blog.csdn.net/weixin_39057744/article/details/133492171