#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);
}

- 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