Mercurial > hg > CbC > CbC_llvm
comparison lib/Analysis/MemDepPrinter.cpp @ 120:1172e4bd9c6f
update 4.0.0
author | mir3636 |
---|---|
date | Fri, 25 Nov 2016 19:14:25 +0900 |
parents | afa8332a0e37 |
children | 803732b1fca8 |
comparison
equal
deleted
inserted
replaced
101:34baf5011add | 120:1172e4bd9c6f |
---|---|
48 | 48 |
49 void print(raw_ostream &OS, const Module * = nullptr) const override; | 49 void print(raw_ostream &OS, const Module * = nullptr) const override; |
50 | 50 |
51 void getAnalysisUsage(AnalysisUsage &AU) const override { | 51 void getAnalysisUsage(AnalysisUsage &AU) const override { |
52 AU.addRequiredTransitive<AAResultsWrapperPass>(); | 52 AU.addRequiredTransitive<AAResultsWrapperPass>(); |
53 AU.addRequiredTransitive<MemoryDependenceAnalysis>(); | 53 AU.addRequiredTransitive<MemoryDependenceWrapperPass>(); |
54 AU.setPreservesAll(); | 54 AU.setPreservesAll(); |
55 } | 55 } |
56 | 56 |
57 void releaseMemory() override { | 57 void releaseMemory() override { |
58 Deps.clear(); | 58 Deps.clear(); |
77 } | 77 } |
78 | 78 |
79 char MemDepPrinter::ID = 0; | 79 char MemDepPrinter::ID = 0; |
80 INITIALIZE_PASS_BEGIN(MemDepPrinter, "print-memdeps", | 80 INITIALIZE_PASS_BEGIN(MemDepPrinter, "print-memdeps", |
81 "Print MemDeps of function", false, true) | 81 "Print MemDeps of function", false, true) |
82 INITIALIZE_PASS_DEPENDENCY(MemoryDependenceAnalysis) | 82 INITIALIZE_PASS_DEPENDENCY(MemoryDependenceWrapperPass) |
83 INITIALIZE_PASS_END(MemDepPrinter, "print-memdeps", | 83 INITIALIZE_PASS_END(MemDepPrinter, "print-memdeps", |
84 "Print MemDeps of function", false, true) | 84 "Print MemDeps of function", false, true) |
85 | 85 |
86 FunctionPass *llvm::createMemDepPrinter() { | 86 FunctionPass *llvm::createMemDepPrinter() { |
87 return new MemDepPrinter(); | 87 return new MemDepPrinter(); |
90 const char *const MemDepPrinter::DepTypeStr[] | 90 const char *const MemDepPrinter::DepTypeStr[] |
91 = {"Clobber", "Def", "NonFuncLocal", "Unknown"}; | 91 = {"Clobber", "Def", "NonFuncLocal", "Unknown"}; |
92 | 92 |
93 bool MemDepPrinter::runOnFunction(Function &F) { | 93 bool MemDepPrinter::runOnFunction(Function &F) { |
94 this->F = &F; | 94 this->F = &F; |
95 MemoryDependenceAnalysis &MDA = getAnalysis<MemoryDependenceAnalysis>(); | 95 MemoryDependenceResults &MDA = getAnalysis<MemoryDependenceWrapperPass>().getMemDep(); |
96 | 96 |
97 // All this code uses non-const interfaces because MemDep is not | 97 // All this code uses non-const interfaces because MemDep is not |
98 // const-friendly, though nothing is actually modified. | 98 // const-friendly, though nothing is actually modified. |
99 for (auto &I : instructions(F)) { | 99 for (auto &I : instructions(F)) { |
100 Instruction *Inst = &I; | 100 Instruction *Inst = &I; |
105 MemDepResult Res = MDA.getDependency(Inst); | 105 MemDepResult Res = MDA.getDependency(Inst); |
106 if (!Res.isNonLocal()) { | 106 if (!Res.isNonLocal()) { |
107 Deps[Inst].insert(std::make_pair(getInstTypePair(Res), | 107 Deps[Inst].insert(std::make_pair(getInstTypePair(Res), |
108 static_cast<BasicBlock *>(nullptr))); | 108 static_cast<BasicBlock *>(nullptr))); |
109 } else if (auto CS = CallSite(Inst)) { | 109 } else if (auto CS = CallSite(Inst)) { |
110 const MemoryDependenceAnalysis::NonLocalDepInfo &NLDI = | 110 const MemoryDependenceResults::NonLocalDepInfo &NLDI = |
111 MDA.getNonLocalCallDependency(CS); | 111 MDA.getNonLocalCallDependency(CS); |
112 | 112 |
113 DepSet &InstDeps = Deps[Inst]; | 113 DepSet &InstDeps = Deps[Inst]; |
114 for (MemoryDependenceAnalysis::NonLocalDepInfo::const_iterator | 114 for (const NonLocalDepEntry &I : NLDI) { |
115 I = NLDI.begin(), E = NLDI.end(); I != E; ++I) { | 115 const MemDepResult &Res = I.getResult(); |
116 const MemDepResult &Res = I->getResult(); | 116 InstDeps.insert(std::make_pair(getInstTypePair(Res), I.getBB())); |
117 InstDeps.insert(std::make_pair(getInstTypePair(Res), I->getBB())); | |
118 } | 117 } |
119 } else { | 118 } else { |
120 SmallVector<NonLocalDepResult, 4> NLDI; | 119 SmallVector<NonLocalDepResult, 4> NLDI; |
121 assert( (isa<LoadInst>(Inst) || isa<StoreInst>(Inst) || | 120 assert( (isa<LoadInst>(Inst) || isa<StoreInst>(Inst) || |
122 isa<VAArgInst>(Inst)) && "Unknown memory instruction!"); | 121 isa<VAArgInst>(Inst)) && "Unknown memory instruction!"); |
123 MDA.getNonLocalPointerDependency(Inst, NLDI); | 122 MDA.getNonLocalPointerDependency(Inst, NLDI); |
124 | 123 |
125 DepSet &InstDeps = Deps[Inst]; | 124 DepSet &InstDeps = Deps[Inst]; |
126 for (SmallVectorImpl<NonLocalDepResult>::const_iterator | 125 for (const NonLocalDepResult &I : NLDI) { |
127 I = NLDI.begin(), E = NLDI.end(); I != E; ++I) { | 126 const MemDepResult &Res = I.getResult(); |
128 const MemDepResult &Res = I->getResult(); | 127 InstDeps.insert(std::make_pair(getInstTypePair(Res), I.getBB())); |
129 InstDeps.insert(std::make_pair(getInstTypePair(Res), I->getBB())); | |
130 } | 128 } |
131 } | 129 } |
132 } | 130 } |
133 | 131 |
134 return false; | 132 return false; |