0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1 //===-- BasicBlock.cpp - Implement BasicBlock related methods -------------===//
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2 //
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
3 // The LLVM Compiler Infrastructure
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
4 //
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
5 // This file is distributed under the University of Illinois Open Source
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
6 // License. See LICENSE.TXT for details.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
7 //
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
8 //===----------------------------------------------------------------------===//
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
9 //
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
10 // This file implements the BasicBlock class for the IR library.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
11 //
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
12 //===----------------------------------------------------------------------===//
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
13
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
14 #include "llvm/IR/BasicBlock.h"
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
15 #include "SymbolTableListTraitsImpl.h"
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
16 #include "llvm/ADT/STLExtras.h"
|
77
|
17 #include "llvm/IR/CFG.h"
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
18 #include "llvm/IR/Constants.h"
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
19 #include "llvm/IR/Instructions.h"
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
20 #include "llvm/IR/IntrinsicInst.h"
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
21 #include "llvm/IR/LLVMContext.h"
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
22 #include "llvm/IR/Type.h"
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
23 #include <algorithm>
|
95
|
24
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
25 using namespace llvm;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
26
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
27 ValueSymbolTable *BasicBlock::getValueSymbolTable() {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
28 if (Function *F = getParent())
|
120
|
29 return F->getValueSymbolTable();
|
77
|
30 return nullptr;
|
|
31 }
|
|
32
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
33 LLVMContext &BasicBlock::getContext() const {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
34 return getType()->getContext();
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
35 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
36
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
37 // Explicit instantiation of SymbolTableListTraits since some of the methods
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
38 // are not in the public header file...
|
95
|
39 template class llvm::SymbolTableListTraits<Instruction>;
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
40
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
41 BasicBlock::BasicBlock(LLVMContext &C, const Twine &Name, Function *NewParent,
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
42 BasicBlock *InsertBefore)
|
77
|
43 : Value(Type::getLabelTy(C), Value::BasicBlockVal), Parent(nullptr) {
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
44
|
77
|
45 if (NewParent)
|
|
46 insertInto(NewParent, InsertBefore);
|
|
47 else
|
|
48 assert(!InsertBefore &&
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
49 "Cannot insert block before another block with no function!");
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
50
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
51 setName(Name);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
52 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
53
|
77
|
54 void BasicBlock::insertInto(Function *NewParent, BasicBlock *InsertBefore) {
|
|
55 assert(NewParent && "Expected a parent");
|
|
56 assert(!Parent && "Already has a parent");
|
|
57
|
|
58 if (InsertBefore)
|
95
|
59 NewParent->getBasicBlockList().insert(InsertBefore->getIterator(), this);
|
77
|
60 else
|
|
61 NewParent->getBasicBlockList().push_back(this);
|
|
62 }
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
63
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
64 BasicBlock::~BasicBlock() {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
65 // If the address of the block is taken and it is being deleted (e.g. because
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
66 // it is dead), this means that there is either a dangling constant expr
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
67 // hanging off the block, or an undefined use of the block (source code
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
68 // expecting the address of a label to keep the block alive even though there
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
69 // is no indirect branch). Handle these cases by zapping the BlockAddress
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
70 // nodes. There are no other possible uses at this point.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
71 if (hasAddressTaken()) {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
72 assert(!use_empty() && "There should be at least one blockaddress!");
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
73 Constant *Replacement =
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
74 ConstantInt::get(llvm::Type::getInt32Ty(getContext()), 1);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
75 while (!use_empty()) {
|
77
|
76 BlockAddress *BA = cast<BlockAddress>(user_back());
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
77 BA->replaceAllUsesWith(ConstantExpr::getIntToPtr(Replacement,
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
78 BA->getType()));
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
79 BA->destroyConstant();
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
80 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
81 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
82
|
77
|
83 assert(getParent() == nullptr && "BasicBlock still linked into the program!");
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
84 dropAllReferences();
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
85 InstList.clear();
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
86 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
87
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
88 void BasicBlock::setParent(Function *parent) {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
89 // Set Parent=parent, updating instruction symtab entries as appropriate.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
90 InstList.setSymTabObject(&Parent, parent);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
91 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
92
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
93 void BasicBlock::removeFromParent() {
|
95
|
94 getParent()->getBasicBlockList().remove(getIterator());
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
95 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
96
|
95
|
97 iplist<BasicBlock>::iterator BasicBlock::eraseFromParent() {
|
|
98 return getParent()->getBasicBlockList().erase(getIterator());
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
99 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
100
|
95
|
101 /// Unlink this basic block from its current function and
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
102 /// insert it into the function that MovePos lives in, right before MovePos.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
103 void BasicBlock::moveBefore(BasicBlock *MovePos) {
|
95
|
104 MovePos->getParent()->getBasicBlockList().splice(
|
|
105 MovePos->getIterator(), getParent()->getBasicBlockList(), getIterator());
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
106 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
107
|
95
|
108 /// Unlink this basic block from its current function and
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
109 /// insert it into the function that MovePos lives in, right after MovePos.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
110 void BasicBlock::moveAfter(BasicBlock *MovePos) {
|
95
|
111 MovePos->getParent()->getBasicBlockList().splice(
|
|
112 ++MovePos->getIterator(), getParent()->getBasicBlockList(),
|
|
113 getIterator());
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
114 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
115
|
95
|
116 const Module *BasicBlock::getModule() const {
|
|
117 return getParent()->getParent();
|
|
118 }
|
|
119
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
120 const TerminatorInst *BasicBlock::getTerminator() const {
|
77
|
121 if (InstList.empty()) return nullptr;
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
122 return dyn_cast<TerminatorInst>(&InstList.back());
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
123 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
124
|
121
|
125 const CallInst *BasicBlock::getTerminatingMustTailCall() const {
|
77
|
126 if (InstList.empty())
|
|
127 return nullptr;
|
121
|
128 const ReturnInst *RI = dyn_cast<ReturnInst>(&InstList.back());
|
77
|
129 if (!RI || RI == &InstList.front())
|
|
130 return nullptr;
|
|
131
|
121
|
132 const Instruction *Prev = RI->getPrevNode();
|
77
|
133 if (!Prev)
|
|
134 return nullptr;
|
|
135
|
|
136 if (Value *RV = RI->getReturnValue()) {
|
|
137 if (RV != Prev)
|
|
138 return nullptr;
|
|
139
|
|
140 // Look through the optional bitcast.
|
|
141 if (auto *BI = dyn_cast<BitCastInst>(Prev)) {
|
|
142 RV = BI->getOperand(0);
|
|
143 Prev = BI->getPrevNode();
|
|
144 if (!Prev || RV != Prev)
|
|
145 return nullptr;
|
|
146 }
|
|
147 }
|
|
148
|
|
149 if (auto *CI = dyn_cast<CallInst>(Prev)) {
|
|
150 if (CI->isMustTailCall())
|
|
151 return CI;
|
|
152 }
|
|
153 return nullptr;
|
|
154 }
|
|
155
|
121
|
156 const CallInst *BasicBlock::getTerminatingDeoptimizeCall() const {
|
120
|
157 if (InstList.empty())
|
|
158 return nullptr;
|
|
159 auto *RI = dyn_cast<ReturnInst>(&InstList.back());
|
|
160 if (!RI || RI == &InstList.front())
|
|
161 return nullptr;
|
|
162
|
|
163 if (auto *CI = dyn_cast_or_null<CallInst>(RI->getPrevNode()))
|
|
164 if (Function *F = CI->getCalledFunction())
|
|
165 if (F->getIntrinsicID() == Intrinsic::experimental_deoptimize)
|
|
166 return CI;
|
|
167
|
|
168 return nullptr;
|
|
169 }
|
|
170
|
121
|
171 const Instruction* BasicBlock::getFirstNonPHI() const {
|
|
172 for (const Instruction &I : *this)
|
95
|
173 if (!isa<PHINode>(I))
|
|
174 return &I;
|
|
175 return nullptr;
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
176 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
177
|
121
|
178 const Instruction* BasicBlock::getFirstNonPHIOrDbg() const {
|
|
179 for (const Instruction &I : *this)
|
95
|
180 if (!isa<PHINode>(I) && !isa<DbgInfoIntrinsic>(I))
|
|
181 return &I;
|
|
182 return nullptr;
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
183 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
184
|
121
|
185 const Instruction* BasicBlock::getFirstNonPHIOrDbgOrLifetime() const {
|
|
186 for (const Instruction &I : *this) {
|
95
|
187 if (isa<PHINode>(I) || isa<DbgInfoIntrinsic>(I))
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
188 continue;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
189
|
95
|
190 if (auto *II = dyn_cast<IntrinsicInst>(&I))
|
|
191 if (II->getIntrinsicID() == Intrinsic::lifetime_start ||
|
|
192 II->getIntrinsicID() == Intrinsic::lifetime_end)
|
|
193 continue;
|
|
194
|
|
195 return &I;
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
196 }
|
95
|
197 return nullptr;
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
198 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
199
|
121
|
200 BasicBlock::const_iterator BasicBlock::getFirstInsertionPt() const {
|
|
201 const Instruction *FirstNonPHI = getFirstNonPHI();
|
95
|
202 if (!FirstNonPHI)
|
|
203 return end();
|
|
204
|
121
|
205 const_iterator InsertPt = FirstNonPHI->getIterator();
|
95
|
206 if (InsertPt->isEHPad()) ++InsertPt;
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
207 return InsertPt;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
208 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
209
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
210 void BasicBlock::dropAllReferences() {
|
120
|
211 for (Instruction &I : *this)
|
|
212 I.dropAllReferences();
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
213 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
214
|
95
|
215 /// If this basic block has a single predecessor block,
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
216 /// return the block, otherwise return a null pointer.
|
121
|
217 const BasicBlock *BasicBlock::getSinglePredecessor() const {
|
|
218 const_pred_iterator PI = pred_begin(this), E = pred_end(this);
|
77
|
219 if (PI == E) return nullptr; // No preds.
|
121
|
220 const BasicBlock *ThePred = *PI;
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
221 ++PI;
|
77
|
222 return (PI == E) ? ThePred : nullptr /*multiple preds*/;
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
223 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
224
|
95
|
225 /// If this basic block has a unique predecessor block,
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
226 /// return the block, otherwise return a null pointer.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
227 /// Note that unique predecessor doesn't mean single edge, there can be
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
228 /// multiple edges from the unique predecessor to this block (for example
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
229 /// a switch statement with multiple cases having the same destination).
|
121
|
230 const BasicBlock *BasicBlock::getUniquePredecessor() const {
|
|
231 const_pred_iterator PI = pred_begin(this), E = pred_end(this);
|
77
|
232 if (PI == E) return nullptr; // No preds.
|
121
|
233 const BasicBlock *PredBB = *PI;
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
234 ++PI;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
235 for (;PI != E; ++PI) {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
236 if (*PI != PredBB)
|
77
|
237 return nullptr;
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
238 // The same predecessor appears multiple times in the predecessor list.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
239 // This is OK.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
240 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
241 return PredBB;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
242 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
243
|
121
|
244 const BasicBlock *BasicBlock::getSingleSuccessor() const {
|
|
245 succ_const_iterator SI = succ_begin(this), E = succ_end(this);
|
95
|
246 if (SI == E) return nullptr; // no successors
|
121
|
247 const BasicBlock *TheSucc = *SI;
|
95
|
248 ++SI;
|
|
249 return (SI == E) ? TheSucc : nullptr /* multiple successors */;
|
|
250 }
|
|
251
|
121
|
252 const BasicBlock *BasicBlock::getUniqueSuccessor() const {
|
|
253 succ_const_iterator SI = succ_begin(this), E = succ_end(this);
|
95
|
254 if (SI == E) return nullptr; // No successors
|
121
|
255 const BasicBlock *SuccBB = *SI;
|
83
|
256 ++SI;
|
|
257 for (;SI != E; ++SI) {
|
|
258 if (*SI != SuccBB)
|
95
|
259 return nullptr;
|
83
|
260 // The same successor appears multiple times in the successor list.
|
|
261 // This is OK.
|
|
262 }
|
|
263 return SuccBB;
|
|
264 }
|
|
265
|
121
|
266 iterator_range<BasicBlock::phi_iterator> BasicBlock::phis() {
|
134
|
267 PHINode *P = empty() ? nullptr : dyn_cast<PHINode>(&*begin());
|
|
268 return make_range<phi_iterator>(P, nullptr);
|
121
|
269 }
|
|
270
|
95
|
271 /// This method is used to notify a BasicBlock that the
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
272 /// specified Predecessor of the block is no longer able to reach it. This is
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
273 /// actually not used to update the Predecessor list, but is actually used to
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
274 /// update the PHI nodes that reside in the block. Note that this should be
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
275 /// called while the predecessor still refers to this block.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
276 ///
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
277 void BasicBlock::removePredecessor(BasicBlock *Pred,
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
278 bool DontDeleteUselessPHIs) {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
279 assert((hasNUsesOrMore(16)||// Reduce cost of this assertion for complex CFGs.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
280 find(pred_begin(this), pred_end(this), Pred) != pred_end(this)) &&
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
281 "removePredecessor: BB is not a predecessor!");
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
282
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
283 if (InstList.empty()) return;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
284 PHINode *APN = dyn_cast<PHINode>(&front());
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
285 if (!APN) return; // Quick exit.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
286
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
287 // If there are exactly two predecessors, then we want to nuke the PHI nodes
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
288 // altogether. However, we cannot do this, if this in this case:
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
289 //
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
290 // Loop:
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
291 // %x = phi [X, Loop]
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
292 // %x2 = add %x, 1 ;; This would become %x2 = add %x2, 1
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
293 // br Loop ;; %x2 does not dominate all uses
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
294 //
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
295 // This is because the PHI node input is actually taken from the predecessor
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
296 // basic block. The only case this can happen is with a self loop, so we
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
297 // check for this case explicitly now.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
298 //
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
299 unsigned max_idx = APN->getNumIncomingValues();
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
300 assert(max_idx != 0 && "PHI Node in block with 0 predecessors!?!?!");
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
301 if (max_idx == 2) {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
302 BasicBlock *Other = APN->getIncomingBlock(APN->getIncomingBlock(0) == Pred);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
303
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
304 // Disable PHI elimination!
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
305 if (this == Other) max_idx = 3;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
306 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
307
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
308 // <= Two predecessors BEFORE I remove one?
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
309 if (max_idx <= 2 && !DontDeleteUselessPHIs) {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
310 // Yup, loop through and nuke the PHI nodes
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
311 while (PHINode *PN = dyn_cast<PHINode>(&front())) {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
312 // Remove the predecessor first.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
313 PN->removeIncomingValue(Pred, !DontDeleteUselessPHIs);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
314
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
315 // If the PHI _HAD_ two uses, replace PHI node with its now *single* value
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
316 if (max_idx == 2) {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
317 if (PN->getIncomingValue(0) != PN)
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
318 PN->replaceAllUsesWith(PN->getIncomingValue(0));
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
319 else
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
320 // We are left with an infinite loop with no entries: kill the PHI.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
321 PN->replaceAllUsesWith(UndefValue::get(PN->getType()));
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
322 getInstList().pop_front(); // Remove the PHI node
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
323 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
324
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
325 // If the PHI node already only had one entry, it got deleted by
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
326 // removeIncomingValue.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
327 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
328 } else {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
329 // Okay, now we know that we need to remove predecessor #pred_idx from all
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
330 // PHI nodes. Iterate over each PHI node fixing them up
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
331 PHINode *PN;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
332 for (iterator II = begin(); (PN = dyn_cast<PHINode>(II)); ) {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
333 ++II;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
334 PN->removeIncomingValue(Pred, false);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
335 // If all incoming values to the Phi are the same, we can replace the Phi
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
336 // with that value.
|
77
|
337 Value* PNV = nullptr;
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
338 if (!DontDeleteUselessPHIs && (PNV = PN->hasConstantValue()))
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
339 if (PNV != PN) {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
340 PN->replaceAllUsesWith(PNV);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
341 PN->eraseFromParent();
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
342 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
343 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
344 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
345 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
346
|
95
|
347 bool BasicBlock::canSplitPredecessors() const {
|
|
348 const Instruction *FirstNonPHI = getFirstNonPHI();
|
|
349 if (isa<LandingPadInst>(FirstNonPHI))
|
|
350 return true;
|
|
351 // This is perhaps a little conservative because constructs like
|
|
352 // CleanupBlockInst are pretty easy to split. However, SplitBlockPredecessors
|
|
353 // cannot handle such things just yet.
|
|
354 if (FirstNonPHI->isEHPad())
|
|
355 return false;
|
|
356 return true;
|
|
357 }
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
358
|
121
|
359 bool BasicBlock::isLegalToHoistInto() const {
|
|
360 auto *Term = getTerminator();
|
|
361 // No terminator means the block is under construction.
|
|
362 if (!Term)
|
|
363 return true;
|
|
364
|
|
365 // If the block has no successors, there can be no instructions to hoist.
|
|
366 assert(Term->getNumSuccessors() > 0);
|
|
367
|
|
368 // Instructions should not be hoisted across exception handling boundaries.
|
|
369 return !Term->isExceptional();
|
|
370 }
|
|
371
|
95
|
372 /// This splits a basic block into two at the specified
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
373 /// instruction. Note that all instructions BEFORE the specified iterator stay
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
374 /// as part of the original basic block, an unconditional branch is added to
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
375 /// the new BB, and the rest of the instructions in the BB are moved to the new
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
376 /// BB, including the old terminator. This invalidates the iterator.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
377 ///
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
378 /// Note that this only works on well formed basic blocks (must have a
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
379 /// terminator), and 'I' must not be the end of instruction list (which would
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
380 /// cause a degenerate basic block to be formed, having a terminator inside of
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
381 /// the basic block).
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
382 ///
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
383 BasicBlock *BasicBlock::splitBasicBlock(iterator I, const Twine &BBName) {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
384 assert(getTerminator() && "Can't use splitBasicBlock on degenerate BB!");
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
385 assert(I != InstList.end() &&
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
386 "Trying to get me to create degenerate basic block!");
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
387
|
120
|
388 BasicBlock *New = BasicBlock::Create(getContext(), BBName, getParent(),
|
|
389 this->getNextNode());
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
390
|
95
|
391 // Save DebugLoc of split point before invalidating iterator.
|
|
392 DebugLoc Loc = I->getDebugLoc();
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
393 // Move all of the specified instructions from the original basic block into
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
394 // the new basic block.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
395 New->getInstList().splice(New->end(), this->getInstList(), I, end());
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
396
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
397 // Add a branch instruction to the newly formed basic block.
|
95
|
398 BranchInst *BI = BranchInst::Create(New, this);
|
|
399 BI->setDebugLoc(Loc);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
400
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
401 // Now we must loop through all of the successors of the New block (which
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
402 // _were_ the successors of the 'this' block), and update any PHI nodes in
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
403 // successors. If there were PHI nodes in the successors, then they need to
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
404 // know that incoming branches will be from New, not from Old.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
405 //
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
406 for (succ_iterator I = succ_begin(New), E = succ_end(New); I != E; ++I) {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
407 // Loop over any phi nodes in the basic block, updating the BB field of
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
408 // incoming values...
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
409 BasicBlock *Successor = *I;
|
121
|
410 for (auto &PN : Successor->phis()) {
|
|
411 int Idx = PN.getBasicBlockIndex(this);
|
|
412 while (Idx != -1) {
|
|
413 PN.setIncomingBlock((unsigned)Idx, New);
|
|
414 Idx = PN.getBasicBlockIndex(this);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
415 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
416 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
417 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
418 return New;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
419 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
420
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
421 void BasicBlock::replaceSuccessorsPhiUsesWith(BasicBlock *New) {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
422 TerminatorInst *TI = getTerminator();
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
423 if (!TI)
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
424 // Cope with being called on a BasicBlock that doesn't have a terminator
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
425 // yet. Clang's CodeGenFunction::EmitReturnBlock() likes to do this.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
426 return;
|
95
|
427 for (BasicBlock *Succ : TI->successors()) {
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
428 // N.B. Succ might not be a complete BasicBlock, so don't assume
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
429 // that it ends with a non-phi instruction.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
430 for (iterator II = Succ->begin(), IE = Succ->end(); II != IE; ++II) {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
431 PHINode *PN = dyn_cast<PHINode>(II);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
432 if (!PN)
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
433 break;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
434 int i;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
435 while ((i = PN->getBasicBlockIndex(this)) >= 0)
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
436 PN->setIncomingBlock(i, New);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
437 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
438 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
439 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
440
|
95
|
441 /// Return true if this basic block is a landing pad. I.e., it's
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
442 /// the destination of the 'unwind' edge of an invoke instruction.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
443 bool BasicBlock::isLandingPad() const {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
444 return isa<LandingPadInst>(getFirstNonPHI());
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
445 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
446
|
95
|
447 /// Return the landingpad instruction associated with the landing pad.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
448 const LandingPadInst *BasicBlock::getLandingPadInst() const {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
449 return dyn_cast<LandingPadInst>(getFirstNonPHI());
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
450 }
|
134
|
451
|
|
452 Optional<uint64_t> BasicBlock::getIrrLoopHeaderWeight() const {
|
|
453 const TerminatorInst *TI = getTerminator();
|
|
454 if (MDNode *MDIrrLoopHeader =
|
|
455 TI->getMetadata(LLVMContext::MD_irr_loop)) {
|
|
456 MDString *MDName = cast<MDString>(MDIrrLoopHeader->getOperand(0));
|
|
457 if (MDName->getString().equals("loop_header_weight")) {
|
|
458 auto *CI = mdconst::extract<ConstantInt>(MDIrrLoopHeader->getOperand(1));
|
|
459 return Optional<uint64_t>(CI->getValue().getZExtValue());
|
|
460 }
|
|
461 }
|
|
462 return Optional<uint64_t>();
|
|
463 }
|