llvm dominator


#include<llvm/ExecutionEngine/ExecutionEngine.h>
#include "llvm/ExecutionEngine/Orc/LLJIT.h"
#include<llvm/ExecutionEngine/GenericValue.h>
#include<llvm/ExecutionEngine/MCJIT.h>
#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<llvm/IRReader/IRReader.h>
#include<llvm/Support/SourceMgr.h>
#include<llvm/IR/Dominators.h>
#include<llvm/Analysis/DominanceFrontier.h>
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);
	
	

}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值