#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);
}
llvm dominator
最新推荐文章于 2024-07-24 20:55:30 发布