blob: c9bb5461aa3c903c86590be9b50e2ff5177a83ff [file] [log] [blame]
Puyan Lotfia521c4ac52017-11-02 23:37:32 +00001//===-------------- MIRCanonicalizer.cpp - MIR Canonicalizer --------------===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Puyan Lotfia521c4ac52017-11-02 23:37:32 +00006//
7//===----------------------------------------------------------------------===//
8//
9// The purpose of this pass is to employ a canonical code transformation so
10// that code compiled with slightly different IR passes can be diffed more
11// effectively than otherwise. This is done by renaming vregs in a given
12// LiveRange in a canonical way. This pass also does a pseudo-scheduling to
13// move defs closer to their use inorder to reduce diffs caused by slightly
14// different schedules.
15//
16// Basic Usage:
17//
18// llc -o - -run-pass mir-canonicalizer example.mir
19//
20// Reorders instructions canonically.
21// Renames virtual register operands canonically.
22// Strips certain MIR artifacts (optionally).
23//
24//===----------------------------------------------------------------------===//
25
Puyan Lotfi028061d2019-09-04 21:29:10 +000026#include "MIRVRegNamerUtils.h"
Puyan Lotfia521c4ac52017-11-02 23:37:32 +000027#include "llvm/ADT/PostOrderIterator.h"
28#include "llvm/ADT/STLExtras.h"
Puyan Lotfia521c4ac52017-11-02 23:37:32 +000029#include "llvm/CodeGen/MachineFunctionPass.h"
30#include "llvm/CodeGen/MachineInstrBuilder.h"
31#include "llvm/CodeGen/MachineRegisterInfo.h"
David Blaikie3f833ed2017-11-08 01:01:31 +000032#include "llvm/CodeGen/Passes.h"
Reid Kleckner1d7b4132019-10-19 00:22:07 +000033#include "llvm/Support/Debug.h"
Puyan Lotfia521c4ac52017-11-02 23:37:32 +000034#include "llvm/Support/raw_ostream.h"
Puyan Lotfia521c4ac52017-11-02 23:37:32 +000035
36#include <queue>
37
38using namespace llvm;
39
40namespace llvm {
41extern char &MIRCanonicalizerID;
42} // namespace llvm
43
44#define DEBUG_TYPE "mir-canonicalizer"
45
46static cl::opt<unsigned>
Puyan Lotfi6ea89b42018-04-16 08:12:15 +000047 CanonicalizeFunctionNumber("canon-nth-function", cl::Hidden, cl::init(~0u),
48 cl::value_desc("N"),
49 cl::desc("Function number to canonicalize."));
Puyan Lotfia521c4ac52017-11-02 23:37:32 +000050
Puyan Lotfi6ea89b42018-04-16 08:12:15 +000051static cl::opt<unsigned> CanonicalizeBasicBlockNumber(
52 "canon-nth-basicblock", cl::Hidden, cl::init(~0u), cl::value_desc("N"),
53 cl::desc("BasicBlock number to canonicalize."));
Puyan Lotfia521c4ac52017-11-02 23:37:32 +000054
55namespace {
56
57class MIRCanonicalizer : public MachineFunctionPass {
58public:
59 static char ID;
60 MIRCanonicalizer() : MachineFunctionPass(ID) {}
61
62 StringRef getPassName() const override {
63 return "Rename register operands in a canonical ordering.";
64 }
65
66 void getAnalysisUsage(AnalysisUsage &AU) const override {
67 AU.setPreservesCFG();
68 MachineFunctionPass::getAnalysisUsage(AU);
69 }
70
71 bool runOnMachineFunction(MachineFunction &MF) override;
72};
73
74} // end anonymous namespace
75
Puyan Lotfia521c4ac52017-11-02 23:37:32 +000076char MIRCanonicalizer::ID;
77
78char &llvm::MIRCanonicalizerID = MIRCanonicalizer::ID;
79
80INITIALIZE_PASS_BEGIN(MIRCanonicalizer, "mir-canonicalizer",
Craig Topper666e23b2017-11-03 18:02:46 +000081 "Rename Register Operands Canonically", false, false)
Puyan Lotfia521c4ac52017-11-02 23:37:32 +000082
83INITIALIZE_PASS_END(MIRCanonicalizer, "mir-canonicalizer",
Craig Topper666e23b2017-11-03 18:02:46 +000084 "Rename Register Operands Canonically", false, false)
Puyan Lotfia521c4ac52017-11-02 23:37:32 +000085
86static std::vector<MachineBasicBlock *> GetRPOList(MachineFunction &MF) {
Puyan Lotfidaaecf92019-05-30 21:37:25 +000087 if (MF.empty())
88 return {};
Puyan Lotfia521c4ac52017-11-02 23:37:32 +000089 ReversePostOrderTraversal<MachineBasicBlock *> RPOT(&*MF.begin());
90 std::vector<MachineBasicBlock *> RPOList;
91 for (auto MBB : RPOT) {
92 RPOList.push_back(MBB);
93 }
94
95 return RPOList;
96}
97
Puyan Lotfi57c4f382018-03-31 05:48:51 +000098static bool
99rescheduleLexographically(std::vector<MachineInstr *> instructions,
100 MachineBasicBlock *MBB,
101 std::function<MachineBasicBlock::iterator()> getPos) {
102
103 bool Changed = false;
Puyan Lotfi380a6f52018-05-13 06:07:20 +0000104 using StringInstrPair = std::pair<std::string, MachineInstr *>;
105 std::vector<StringInstrPair> StringInstrMap;
Puyan Lotfi57c4f382018-03-31 05:48:51 +0000106
107 for (auto *II : instructions) {
108 std::string S;
109 raw_string_ostream OS(S);
110 II->print(OS);
111 OS.flush();
112
113 // Trim the assignment, or start from the begining in the case of a store.
114 const size_t i = S.find("=");
Puyan Lotfi380a6f52018-05-13 06:07:20 +0000115 StringInstrMap.push_back({(i == std::string::npos) ? S : S.substr(i), II});
Puyan Lotfi57c4f382018-03-31 05:48:51 +0000116 }
117
Fangrui Song0cac7262018-09-27 02:13:45 +0000118 llvm::sort(StringInstrMap,
119 [](const StringInstrPair &a, const StringInstrPair &b) -> bool {
120 return (a.first < b.first);
121 });
Puyan Lotfi380a6f52018-05-13 06:07:20 +0000122
Puyan Lotfi57c4f382018-03-31 05:48:51 +0000123 for (auto &II : StringInstrMap) {
124
Nicola Zaghend34e60c2018-05-14 12:53:11 +0000125 LLVM_DEBUG({
Puyan Lotfi57c4f382018-03-31 05:48:51 +0000126 dbgs() << "Splicing ";
127 II.second->dump();
128 dbgs() << " right before: ";
129 getPos()->dump();
130 });
131
132 Changed = true;
133 MBB->splice(getPos(), MBB, II.second);
134 }
135
136 return Changed;
137}
138
139static bool rescheduleCanonically(unsigned &PseudoIdempotentInstCount,
140 MachineBasicBlock *MBB) {
Puyan Lotfia521c4ac52017-11-02 23:37:32 +0000141
142 bool Changed = false;
143
144 // Calculates the distance of MI from the begining of its parent BB.
145 auto getInstrIdx = [](const MachineInstr &MI) {
146 unsigned i = 0;
147 for (auto &CurMI : *MI.getParent()) {
148 if (&CurMI == &MI)
149 return i;
150 i++;
151 }
152 return ~0U;
153 };
154
155 // Pre-Populate vector of instructions to reschedule so that we don't
156 // clobber the iterator.
157 std::vector<MachineInstr *> Instructions;
158 for (auto &MI : *MBB) {
159 Instructions.push_back(&MI);
160 }
161
Puyan Lotfi26c504f2018-04-05 00:08:15 +0000162 std::map<MachineInstr *, std::vector<MachineInstr *>> MultiUsers;
Puyan Lotfi4d894622019-06-11 00:00:25 +0000163 std::map<unsigned, MachineInstr *> MultiUserLookup;
164 unsigned UseToBringDefCloserToCount = 0;
Puyan Lotfi57c4f382018-03-31 05:48:51 +0000165 std::vector<MachineInstr *> PseudoIdempotentInstructions;
166 std::vector<unsigned> PhysRegDefs;
167 for (auto *II : Instructions) {
168 for (unsigned i = 1; i < II->getNumOperands(); i++) {
169 MachineOperand &MO = II->getOperand(i);
170 if (!MO.isReg())
171 continue;
172
Daniel Sanders2bea69b2019-08-01 23:27:28 +0000173 if (Register::isVirtualRegister(MO.getReg()))
Puyan Lotfi57c4f382018-03-31 05:48:51 +0000174 continue;
175
176 if (!MO.isDef())
177 continue;
178
179 PhysRegDefs.push_back(MO.getReg());
180 }
181 }
182
Puyan Lotfia521c4ac52017-11-02 23:37:32 +0000183 for (auto *II : Instructions) {
184 if (II->getNumOperands() == 0)
185 continue;
Puyan Lotfi57c4f382018-03-31 05:48:51 +0000186 if (II->mayLoadOrStore())
187 continue;
Puyan Lotfia521c4ac52017-11-02 23:37:32 +0000188
189 MachineOperand &MO = II->getOperand(0);
Daniel Sanders2bea69b2019-08-01 23:27:28 +0000190 if (!MO.isReg() || !Register::isVirtualRegister(MO.getReg()))
Puyan Lotfia521c4ac52017-11-02 23:37:32 +0000191 continue;
Puyan Lotfi57c4f382018-03-31 05:48:51 +0000192 if (!MO.isDef())
193 continue;
194
195 bool IsPseudoIdempotent = true;
196 for (unsigned i = 1; i < II->getNumOperands(); i++) {
197
198 if (II->getOperand(i).isImm()) {
199 continue;
200 }
201
202 if (II->getOperand(i).isReg()) {
Daniel Sanders2bea69b2019-08-01 23:27:28 +0000203 if (!Register::isVirtualRegister(II->getOperand(i).getReg()))
Puyan Lotfi57c4f382018-03-31 05:48:51 +0000204 if (llvm::find(PhysRegDefs, II->getOperand(i).getReg()) ==
Puyan Lotfi6ea89b42018-04-16 08:12:15 +0000205 PhysRegDefs.end()) {
Puyan Lotfi57c4f382018-03-31 05:48:51 +0000206 continue;
207 }
208 }
209
210 IsPseudoIdempotent = false;
211 break;
212 }
213
214 if (IsPseudoIdempotent) {
215 PseudoIdempotentInstructions.push_back(II);
216 continue;
217 }
Puyan Lotfia521c4ac52017-11-02 23:37:32 +0000218
Nicola Zaghend34e60c2018-05-14 12:53:11 +0000219 LLVM_DEBUG(dbgs() << "Operand " << 0 << " of "; II->dump(); MO.dump(););
Puyan Lotfia521c4ac52017-11-02 23:37:32 +0000220
221 MachineInstr *Def = II;
222 unsigned Distance = ~0U;
223 MachineInstr *UseToBringDefCloserTo = nullptr;
224 MachineRegisterInfo *MRI = &MBB->getParent()->getRegInfo();
225 for (auto &UO : MRI->use_nodbg_operands(MO.getReg())) {
226 MachineInstr *UseInst = UO.getParent();
227
228 const unsigned DefLoc = getInstrIdx(*Def);
229 const unsigned UseLoc = getInstrIdx(*UseInst);
230 const unsigned Delta = (UseLoc - DefLoc);
231
232 if (UseInst->getParent() != Def->getParent())
233 continue;
234 if (DefLoc >= UseLoc)
235 continue;
236
237 if (Delta < Distance) {
238 Distance = Delta;
239 UseToBringDefCloserTo = UseInst;
Puyan Lotfi4d894622019-06-11 00:00:25 +0000240 MultiUserLookup[UseToBringDefCloserToCount++] = UseToBringDefCloserTo;
Puyan Lotfia521c4ac52017-11-02 23:37:32 +0000241 }
242 }
243
244 const auto BBE = MBB->instr_end();
245 MachineBasicBlock::iterator DefI = BBE;
246 MachineBasicBlock::iterator UseI = BBE;
247
248 for (auto BBI = MBB->instr_begin(); BBI != BBE; ++BBI) {
249
250 if (DefI != BBE && UseI != BBE)
251 break;
252
Puyan Lotfia521c4ac52017-11-02 23:37:32 +0000253 if (&*BBI == Def) {
254 DefI = BBI;
255 continue;
256 }
257
258 if (&*BBI == UseToBringDefCloserTo) {
259 UseI = BBI;
260 continue;
261 }
262 }
263
264 if (DefI == BBE || UseI == BBE)
265 continue;
266
Nicola Zaghend34e60c2018-05-14 12:53:11 +0000267 LLVM_DEBUG({
Puyan Lotfia521c4ac52017-11-02 23:37:32 +0000268 dbgs() << "Splicing ";
269 DefI->dump();
270 dbgs() << " right before: ";
271 UseI->dump();
272 });
273
Puyan Lotfi26c504f2018-04-05 00:08:15 +0000274 MultiUsers[UseToBringDefCloserTo].push_back(Def);
Puyan Lotfia521c4ac52017-11-02 23:37:32 +0000275 Changed = true;
276 MBB->splice(UseI, MBB, DefI);
277 }
278
Puyan Lotfi26c504f2018-04-05 00:08:15 +0000279 // Sort the defs for users of multiple defs lexographically.
Puyan Lotfi4d894622019-06-11 00:00:25 +0000280 for (const auto &E : MultiUserLookup) {
Puyan Lotfi26c504f2018-04-05 00:08:15 +0000281
282 auto UseI =
283 std::find_if(MBB->instr_begin(), MBB->instr_end(),
Puyan Lotfi4d894622019-06-11 00:00:25 +0000284 [&](MachineInstr &MI) -> bool { return &MI == E.second; });
Puyan Lotfi26c504f2018-04-05 00:08:15 +0000285
286 if (UseI == MBB->instr_end())
287 continue;
288
Nicola Zaghend34e60c2018-05-14 12:53:11 +0000289 LLVM_DEBUG(
290 dbgs() << "Rescheduling Multi-Use Instructions Lexographically.";);
Puyan Lotfi26c504f2018-04-05 00:08:15 +0000291 Changed |= rescheduleLexographically(
Puyan Lotfi4d894622019-06-11 00:00:25 +0000292 MultiUsers[E.second], MBB,
293 [&]() -> MachineBasicBlock::iterator { return UseI; });
Puyan Lotfi26c504f2018-04-05 00:08:15 +0000294 }
295
Puyan Lotfi57c4f382018-03-31 05:48:51 +0000296 PseudoIdempotentInstCount = PseudoIdempotentInstructions.size();
Nicola Zaghend34e60c2018-05-14 12:53:11 +0000297 LLVM_DEBUG(
298 dbgs() << "Rescheduling Idempotent Instructions Lexographically.";);
Puyan Lotfi57c4f382018-03-31 05:48:51 +0000299 Changed |= rescheduleLexographically(
300 PseudoIdempotentInstructions, MBB,
301 [&]() -> MachineBasicBlock::iterator { return MBB->begin(); });
302
Puyan Lotfia521c4ac52017-11-02 23:37:32 +0000303 return Changed;
304}
305
Benjamin Kramer651d0bf2018-05-15 21:26:47 +0000306static bool propagateLocalCopies(MachineBasicBlock *MBB) {
Puyan Lotfi14b6637e2018-04-16 09:03:03 +0000307 bool Changed = false;
308 MachineRegisterInfo &MRI = MBB->getParent()->getRegInfo();
309
310 std::vector<MachineInstr *> Copies;
311 for (MachineInstr &MI : MBB->instrs()) {
312 if (MI.isCopy())
313 Copies.push_back(&MI);
314 }
315
316 for (MachineInstr *MI : Copies) {
317
318 if (!MI->getOperand(0).isReg())
319 continue;
320 if (!MI->getOperand(1).isReg())
321 continue;
322
Daniel Sanders0c476112019-08-15 19:22:08 +0000323 const Register Dst = MI->getOperand(0).getReg();
324 const Register Src = MI->getOperand(1).getReg();
Puyan Lotfi14b6637e2018-04-16 09:03:03 +0000325
Daniel Sanders2bea69b2019-08-01 23:27:28 +0000326 if (!Register::isVirtualRegister(Dst))
Puyan Lotfi14b6637e2018-04-16 09:03:03 +0000327 continue;
Daniel Sanders2bea69b2019-08-01 23:27:28 +0000328 if (!Register::isVirtualRegister(Src))
Puyan Lotfi14b6637e2018-04-16 09:03:03 +0000329 continue;
Puyan Lotfi2a901402019-05-31 04:49:58 +0000330 // Not folding COPY instructions if regbankselect has not set the RCs.
331 // Why are we only considering Register Classes? Because the verifier
332 // sometimes gets upset if the register classes don't match even if the
333 // types do. A future patch might add COPY folding for matching types in
334 // pre-registerbankselect code.
335 if (!MRI.getRegClassOrNull(Dst))
336 continue;
Puyan Lotfi14b6637e2018-04-16 09:03:03 +0000337 if (MRI.getRegClass(Dst) != MRI.getRegClass(Src))
338 continue;
339
Puyan Lotfi2a901402019-05-31 04:49:58 +0000340 std::vector<MachineOperand *> Uses;
341 for (auto UI = MRI.use_begin(Dst); UI != MRI.use_end(); ++UI)
342 Uses.push_back(&*UI);
343 for (auto *MO : Uses)
Puyan Lotfi14b6637e2018-04-16 09:03:03 +0000344 MO->setReg(Src);
Puyan Lotfi14b6637e2018-04-16 09:03:03 +0000345
Puyan Lotfi2a901402019-05-31 04:49:58 +0000346 Changed = true;
Puyan Lotfi14b6637e2018-04-16 09:03:03 +0000347 MI->eraseFromParent();
348 }
349
350 return Changed;
351}
352
Puyan Lotfia521c4ac52017-11-02 23:37:32 +0000353static bool doDefKillClear(MachineBasicBlock *MBB) {
354 bool Changed = false;
355
356 for (auto &MI : *MBB) {
357 for (auto &MO : MI.operands()) {
358 if (!MO.isReg())
359 continue;
360 if (!MO.isDef() && MO.isKill()) {
361 Changed = true;
362 MO.setIsKill(false);
363 }
364
365 if (MO.isDef() && MO.isDead()) {
366 Changed = true;
367 MO.setIsDead(false);
368 }
369 }
370 }
371
372 return Changed;
373}
374
375static bool runOnBasicBlock(MachineBasicBlock *MBB,
376 std::vector<StringRef> &bbNames,
Puyan Lotfi028061d2019-09-04 21:29:10 +0000377 unsigned &basicBlockNum, NamedVRegCursor &NVC) {
Puyan Lotfia521c4ac52017-11-02 23:37:32 +0000378
379 if (CanonicalizeBasicBlockNumber != ~0U) {
380 if (CanonicalizeBasicBlockNumber != basicBlockNum++)
381 return false;
Nicola Zaghend34e60c2018-05-14 12:53:11 +0000382 LLVM_DEBUG(dbgs() << "\n Canonicalizing BasicBlock " << MBB->getName()
383 << "\n";);
Puyan Lotfia521c4ac52017-11-02 23:37:32 +0000384 }
385
386 if (llvm::find(bbNames, MBB->getName()) != bbNames.end()) {
Nicola Zaghend34e60c2018-05-14 12:53:11 +0000387 LLVM_DEBUG({
Puyan Lotfia521c4ac52017-11-02 23:37:32 +0000388 dbgs() << "Found potentially duplicate BasicBlocks: " << MBB->getName()
389 << "\n";
390 });
391 return false;
392 }
393
Nicola Zaghend34e60c2018-05-14 12:53:11 +0000394 LLVM_DEBUG({
Puyan Lotfia521c4ac52017-11-02 23:37:32 +0000395 dbgs() << "\n\n NEW BASIC BLOCK: " << MBB->getName() << " \n\n";
396 dbgs() << "\n\n================================================\n\n";
397 });
398
399 bool Changed = false;
400 MachineFunction &MF = *MBB->getParent();
401 MachineRegisterInfo &MRI = MF.getRegInfo();
402
Puyan Lotfia521c4ac52017-11-02 23:37:32 +0000403 bbNames.push_back(MBB->getName());
Nicola Zaghend34e60c2018-05-14 12:53:11 +0000404 LLVM_DEBUG(dbgs() << "\n\n NEW BASIC BLOCK: " << MBB->getName() << "\n\n";);
Puyan Lotfia521c4ac52017-11-02 23:37:32 +0000405
Nicola Zaghend34e60c2018-05-14 12:53:11 +0000406 LLVM_DEBUG(dbgs() << "MBB Before Canonical Copy Propagation:\n";
407 MBB->dump(););
Puyan Lotfi14b6637e2018-04-16 09:03:03 +0000408 Changed |= propagateLocalCopies(MBB);
Nicola Zaghend34e60c2018-05-14 12:53:11 +0000409 LLVM_DEBUG(dbgs() << "MBB After Canonical Copy Propagation:\n"; MBB->dump(););
Puyan Lotfi14b6637e2018-04-16 09:03:03 +0000410
Nicola Zaghend34e60c2018-05-14 12:53:11 +0000411 LLVM_DEBUG(dbgs() << "MBB Before Scheduling:\n"; MBB->dump(););
Puyan Lotfi57c4f382018-03-31 05:48:51 +0000412 unsigned IdempotentInstCount = 0;
413 Changed |= rescheduleCanonically(IdempotentInstCount, MBB);
Nicola Zaghend34e60c2018-05-14 12:53:11 +0000414 LLVM_DEBUG(dbgs() << "MBB After Scheduling:\n"; MBB->dump(););
Puyan Lotfia521c4ac52017-11-02 23:37:32 +0000415
Puyan Lotfi028061d2019-09-04 21:29:10 +0000416 Changed |= NVC.renameVRegs(MBB);
Puyan Lotfi57c4f382018-03-31 05:48:51 +0000417
418 // Here we renumber the def vregs for the idempotent instructions from the top
419 // of the MachineBasicBlock so that they are named in the order that we sorted
420 // them alphabetically. Eventually we wont need SkipVRegs because we will use
421 // named vregs instead.
Puyan Lotfi3ea6b242019-05-31 17:34:25 +0000422 if (IdempotentInstCount)
Puyan Lotfi028061d2019-09-04 21:29:10 +0000423 NVC.skipVRegs();
Puyan Lotfi57c4f382018-03-31 05:48:51 +0000424
425 auto MII = MBB->begin();
426 for (unsigned i = 0; i < IdempotentInstCount && MII != MBB->end(); ++i) {
427 MachineInstr &MI = *MII++;
428 Changed = true;
Daniel Sanders0c476112019-08-15 19:22:08 +0000429 Register vRegToRename = MI.getOperand(0).getReg();
Puyan Lotfi0f4446b2019-05-30 18:06:28 +0000430 auto Rename = NVC.createVirtualRegister(vRegToRename);
Puyan Lotfi57c4f382018-03-31 05:48:51 +0000431
432 std::vector<MachineOperand *> RenameMOs;
433 for (auto &MO : MRI.reg_operands(vRegToRename)) {
434 RenameMOs.push_back(&MO);
435 }
436
437 for (auto *MO : RenameMOs) {
438 MO->setReg(Rename);
439 }
440 }
441
Puyan Lotfia521c4ac52017-11-02 23:37:32 +0000442 Changed |= doDefKillClear(MBB);
443
Nicola Zaghend34e60c2018-05-14 12:53:11 +0000444 LLVM_DEBUG(dbgs() << "Updated MachineBasicBlock:\n"; MBB->dump();
445 dbgs() << "\n";);
446 LLVM_DEBUG(
447 dbgs() << "\n\n================================================\n\n");
Puyan Lotfia521c4ac52017-11-02 23:37:32 +0000448 return Changed;
449}
450
451bool MIRCanonicalizer::runOnMachineFunction(MachineFunction &MF) {
452
453 static unsigned functionNum = 0;
454 if (CanonicalizeFunctionNumber != ~0U) {
455 if (CanonicalizeFunctionNumber != functionNum++)
456 return false;
Nicola Zaghend34e60c2018-05-14 12:53:11 +0000457 LLVM_DEBUG(dbgs() << "\n Canonicalizing Function " << MF.getName()
458 << "\n";);
Puyan Lotfia521c4ac52017-11-02 23:37:32 +0000459 }
460
461 // we need a valid vreg to create a vreg type for skipping all those
462 // stray vreg numbers so reach alignment/canonical vreg values.
Puyan Lotfi6ea89b42018-04-16 08:12:15 +0000463 std::vector<MachineBasicBlock *> RPOList = GetRPOList(MF);
Puyan Lotfia521c4ac52017-11-02 23:37:32 +0000464
Nicola Zaghend34e60c2018-05-14 12:53:11 +0000465 LLVM_DEBUG(
466 dbgs() << "\n\n NEW MACHINE FUNCTION: " << MF.getName() << " \n\n";
467 dbgs() << "\n\n================================================\n\n";
468 dbgs() << "Total Basic Blocks: " << RPOList.size() << "\n";
469 for (auto MBB
470 : RPOList) { dbgs() << MBB->getName() << "\n"; } dbgs()
471 << "\n\n================================================\n\n";);
Puyan Lotfia521c4ac52017-11-02 23:37:32 +0000472
473 std::vector<StringRef> BBNames;
Puyan Lotfia521c4ac52017-11-02 23:37:32 +0000474
Puyan Lotfia521c4ac52017-11-02 23:37:32 +0000475 unsigned BBNum = 0;
476
477 bool Changed = false;
478
Puyan Lotfid6f73132018-04-05 00:27:15 +0000479 MachineRegisterInfo &MRI = MF.getRegInfo();
480 NamedVRegCursor NVC(MRI);
Puyan Lotfia521c4ac52017-11-02 23:37:32 +0000481 for (auto MBB : RPOList)
Puyan Lotfi028061d2019-09-04 21:29:10 +0000482 Changed |= runOnBasicBlock(MBB, BBNames, BBNum, NVC);
Puyan Lotfia521c4ac52017-11-02 23:37:32 +0000483
484 return Changed;
485}