comparison lib/CodeGen/EarlyIfConversion.cpp @ 134:3a76565eade5 LLVM5.0.1

update 5.0.1
author mir3636
date Sat, 17 Feb 2018 09:57:20 +0900
parents 803732b1fca8
children c2174574ed3a
comparison
equal deleted inserted replaced
133:c60214abe0e8 134:3a76565eade5
28 #include "llvm/CodeGen/MachineFunctionPass.h" 28 #include "llvm/CodeGen/MachineFunctionPass.h"
29 #include "llvm/CodeGen/MachineLoopInfo.h" 29 #include "llvm/CodeGen/MachineLoopInfo.h"
30 #include "llvm/CodeGen/MachineRegisterInfo.h" 30 #include "llvm/CodeGen/MachineRegisterInfo.h"
31 #include "llvm/CodeGen/MachineTraceMetrics.h" 31 #include "llvm/CodeGen/MachineTraceMetrics.h"
32 #include "llvm/CodeGen/Passes.h" 32 #include "llvm/CodeGen/Passes.h"
33 #include "llvm/CodeGen/TargetInstrInfo.h"
34 #include "llvm/CodeGen/TargetRegisterInfo.h"
35 #include "llvm/CodeGen/TargetSubtargetInfo.h"
33 #include "llvm/Support/CommandLine.h" 36 #include "llvm/Support/CommandLine.h"
34 #include "llvm/Support/Debug.h" 37 #include "llvm/Support/Debug.h"
35 #include "llvm/Support/raw_ostream.h" 38 #include "llvm/Support/raw_ostream.h"
36 #include "llvm/Target/TargetInstrInfo.h"
37 #include "llvm/Target/TargetRegisterInfo.h"
38 #include "llvm/Target/TargetSubtargetInfo.h"
39 39
40 using namespace llvm; 40 using namespace llvm;
41 41
42 #define DEBUG_TYPE "early-ifcvt" 42 #define DEBUG_TYPE "early-ifcvt"
43 43
183 /// 183 ///
184 bool SSAIfConv::canSpeculateInstrs(MachineBasicBlock *MBB) { 184 bool SSAIfConv::canSpeculateInstrs(MachineBasicBlock *MBB) {
185 // Reject any live-in physregs. It's probably CPSR/EFLAGS, and very hard to 185 // Reject any live-in physregs. It's probably CPSR/EFLAGS, and very hard to
186 // get right. 186 // get right.
187 if (!MBB->livein_empty()) { 187 if (!MBB->livein_empty()) {
188 DEBUG(dbgs() << "BB#" << MBB->getNumber() << " has live-ins.\n"); 188 DEBUG(dbgs() << printMBBReference(*MBB) << " has live-ins.\n");
189 return false; 189 return false;
190 } 190 }
191 191
192 unsigned InstrCount = 0; 192 unsigned InstrCount = 0;
193 193
197 E = MBB->getFirstTerminator(); I != E; ++I) { 197 E = MBB->getFirstTerminator(); I != E; ++I) {
198 if (I->isDebugValue()) 198 if (I->isDebugValue())
199 continue; 199 continue;
200 200
201 if (++InstrCount > BlockInstrLimit && !Stress) { 201 if (++InstrCount > BlockInstrLimit && !Stress) {
202 DEBUG(dbgs() << "BB#" << MBB->getNumber() << " has more than " 202 DEBUG(dbgs() << printMBBReference(*MBB) << " has more than "
203 << BlockInstrLimit << " instructions.\n"); 203 << BlockInstrLimit << " instructions.\n");
204 return false; 204 return false;
205 } 205 }
206 206
207 // There shouldn't normally be any phis in a single-predecessor block. 207 // There shouldn't normally be any phis in a single-predecessor block.
244 continue; 244 continue;
245 MachineInstr *DefMI = MRI->getVRegDef(Reg); 245 MachineInstr *DefMI = MRI->getVRegDef(Reg);
246 if (!DefMI || DefMI->getParent() != Head) 246 if (!DefMI || DefMI->getParent() != Head)
247 continue; 247 continue;
248 if (InsertAfter.insert(DefMI).second) 248 if (InsertAfter.insert(DefMI).second)
249 DEBUG(dbgs() << "BB#" << MBB->getNumber() << " depends on " << *DefMI); 249 DEBUG(dbgs() << printMBBReference(*MBB) << " depends on " << *DefMI);
250 if (DefMI->isTerminator()) { 250 if (DefMI->isTerminator()) {
251 DEBUG(dbgs() << "Can't insert instructions below terminator.\n"); 251 DEBUG(dbgs() << "Can't insert instructions below terminator.\n");
252 return false; 252 return false;
253 } 253 }
254 } 254 }
315 if (!LiveRegUnits.empty()) { 315 if (!LiveRegUnits.empty()) {
316 DEBUG({ 316 DEBUG({
317 dbgs() << "Would clobber"; 317 dbgs() << "Would clobber";
318 for (SparseSet<unsigned>::const_iterator 318 for (SparseSet<unsigned>::const_iterator
319 i = LiveRegUnits.begin(), e = LiveRegUnits.end(); i != e; ++i) 319 i = LiveRegUnits.begin(), e = LiveRegUnits.end(); i != e; ++i)
320 dbgs() << ' ' << PrintRegUnit(*i, TRI); 320 dbgs() << ' ' << printRegUnit(*i, TRI);
321 dbgs() << " live before " << *I; 321 dbgs() << " live before " << *I;
322 }); 322 });
323 continue; 323 continue;
324 } 324 }
325 325
359 if (Tail != Succ1) { 359 if (Tail != Succ1) {
360 // Check for a diamond. We won't deal with any critical edges. 360 // Check for a diamond. We won't deal with any critical edges.
361 if (Succ1->pred_size() != 1 || Succ1->succ_size() != 1 || 361 if (Succ1->pred_size() != 1 || Succ1->succ_size() != 1 ||
362 Succ1->succ_begin()[0] != Tail) 362 Succ1->succ_begin()[0] != Tail)
363 return false; 363 return false;
364 DEBUG(dbgs() << "\nDiamond: BB#" << Head->getNumber() 364 DEBUG(dbgs() << "\nDiamond: " << printMBBReference(*Head) << " -> "
365 << " -> BB#" << Succ0->getNumber() 365 << printMBBReference(*Succ0) << "/"
366 << "/BB#" << Succ1->getNumber() 366 << printMBBReference(*Succ1) << " -> "
367 << " -> BB#" << Tail->getNumber() << '\n'); 367 << printMBBReference(*Tail) << '\n');
368 368
369 // Live-in physregs are tricky to get right when speculating code. 369 // Live-in physregs are tricky to get right when speculating code.
370 if (!Tail->livein_empty()) { 370 if (!Tail->livein_empty()) {
371 DEBUG(dbgs() << "Tail has live-ins.\n"); 371 DEBUG(dbgs() << "Tail has live-ins.\n");
372 return false; 372 return false;
373 } 373 }
374 } else { 374 } else {
375 DEBUG(dbgs() << "\nTriangle: BB#" << Head->getNumber() 375 DEBUG(dbgs() << "\nTriangle: " << printMBBReference(*Head) << " -> "
376 << " -> BB#" << Succ0->getNumber() 376 << printMBBReference(*Succ0) << " -> "
377 << " -> BB#" << Tail->getNumber() << '\n'); 377 << printMBBReference(*Tail) << '\n');
378 } 378 }
379 379
380 // This is a triangle or a diamond. 380 // This is a triangle or a diamond.
381 // If Tail doesn't have any phis, there must be side effects. 381 // If Tail doesn't have any phis, there must be side effects.
382 if (Tail->empty() || !Tail->front().isPHI()) { 382 if (Tail->empty() || !Tail->front().isPHI()) {
561 } 561 }
562 562
563 assert(Head->succ_empty() && "Additional head successors?"); 563 assert(Head->succ_empty() && "Additional head successors?");
564 if (!ExtraPreds && Head->isLayoutSuccessor(Tail)) { 564 if (!ExtraPreds && Head->isLayoutSuccessor(Tail)) {
565 // Splice Tail onto the end of Head. 565 // Splice Tail onto the end of Head.
566 DEBUG(dbgs() << "Joining tail BB#" << Tail->getNumber() 566 DEBUG(dbgs() << "Joining tail " << printMBBReference(*Tail) << " into head "
567 << " into head BB#" << Head->getNumber() << '\n'); 567 << printMBBReference(*Head) << '\n');
568 Head->splice(Head->end(), Tail, 568 Head->splice(Head->end(), Tail,
569 Tail->begin(), Tail->end()); 569 Tail->begin(), Tail->end());
570 Head->transferSuccessorsAndUpdatePHIs(Tail); 570 Head->transferSuccessorsAndUpdatePHIs(Tail);
571 RemovedBlocks.push_back(Tail); 571 RemovedBlocks.push_back(Tail);
572 Tail->eraseFromParent(); 572 Tail->eraseFromParent();
783 } 783 }
784 784
785 bool EarlyIfConverter::runOnMachineFunction(MachineFunction &MF) { 785 bool EarlyIfConverter::runOnMachineFunction(MachineFunction &MF) {
786 DEBUG(dbgs() << "********** EARLY IF-CONVERSION **********\n" 786 DEBUG(dbgs() << "********** EARLY IF-CONVERSION **********\n"
787 << "********** Function: " << MF.getName() << '\n'); 787 << "********** Function: " << MF.getName() << '\n');
788 if (skipFunction(*MF.getFunction())) 788 if (skipFunction(MF.getFunction()))
789 return false; 789 return false;
790 790
791 // Only run if conversion if the target wants it. 791 // Only run if conversion if the target wants it.
792 const TargetSubtargetInfo &STI = MF.getSubtarget(); 792 const TargetSubtargetInfo &STI = MF.getSubtarget();
793 if (!STI.enableEarlyIfConversion()) 793 if (!STI.enableEarlyIfConversion())