diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2017-12-18 20:10:56 +0000 |
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2017-12-18 20:10:56 +0000 |
| commit | 044eb2f6afba375a914ac9d8024f8f5142bb912e (patch) | |
| tree | 1475247dc9f9fe5be155ebd4c9069c75aadf8c20 /lib/Target/AMDGPU/AMDILCFGStructurizer.cpp | |
| parent | eb70dddbd77e120e5d490bd8fbe7ff3f8fa81c6b (diff) | |
Notes
Diffstat (limited to 'lib/Target/AMDGPU/AMDILCFGStructurizer.cpp')
| -rw-r--r-- | lib/Target/AMDGPU/AMDILCFGStructurizer.cpp | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/lib/Target/AMDGPU/AMDILCFGStructurizer.cpp b/lib/Target/AMDGPU/AMDILCFGStructurizer.cpp index 1a393845a822..0a0e43123ae0 100644 --- a/lib/Target/AMDGPU/AMDILCFGStructurizer.cpp +++ b/lib/Target/AMDGPU/AMDILCFGStructurizer.cpp @@ -1,11 +1,10 @@ -//===-- AMDILCFGStructurizer.cpp - CFG Structurizer -----------------------===// +//===- AMDILCFGStructurizer.cpp - CFG Structurizer ------------------------===// // // The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. // -/// \file //==-----------------------------------------------------------------------===// #include "AMDGPU.h" @@ -67,7 +66,7 @@ STATISTIC(numClonedInstr, "CFGStructurizer cloned instructions"); namespace llvm { - void initializeAMDGPUCFGStructurizerPass(PassRegistry&); +void initializeAMDGPUCFGStructurizerPass(PassRegistry &); } // end namespace llvm @@ -121,9 +120,9 @@ public: class AMDGPUCFGStructurizer : public MachineFunctionPass { public: - typedef SmallVector<MachineBasicBlock *, 32> MBBVector; - typedef std::map<MachineBasicBlock *, BlockInformation *> MBBInfoMap; - typedef std::map<MachineLoop *, MachineBasicBlock *> LoopLandInfoMap; + using MBBVector = SmallVector<MachineBasicBlock *, 32>; + using MBBInfoMap = std::map<MachineBasicBlock *, BlockInformation *>; + using LoopLandInfoMap = std::map<MachineLoop *, MachineBasicBlock *>; enum PathToKind { Not_SinglePath = 0, @@ -234,6 +233,7 @@ protected: void insertCondBranchBefore(MachineBasicBlock *MBB, MachineBasicBlock::iterator I, int NewOpcode, int RegNum, const DebugLoc &DL); + static int getBranchNzeroOpcode(int OldOpcode); static int getBranchZeroOpcode(int OldOpcode); static int getContinueNzeroOpcode(int OldOpcode); @@ -246,21 +246,25 @@ protected: static bool isUncondBranch(MachineInstr *MI); static DebugLoc getLastDebugLocInBB(MachineBasicBlock *MBB); static MachineInstr *getNormalBlockBranchInstr(MachineBasicBlock *MBB); + /// The correct naming for this is getPossibleLoopendBlockBranchInstr. /// /// BB with backward-edge could have move instructions after the branch /// instruction. Such move instruction "belong to" the loop backward-edge. MachineInstr *getLoopendBlockBranchInstr(MachineBasicBlock *MBB); + static MachineInstr *getReturnInstr(MachineBasicBlock *MBB); static bool isReturnBlock(MachineBasicBlock *MBB); static void cloneSuccessorList(MachineBasicBlock *DstMBB, - MachineBasicBlock *SrcMBB) ; + MachineBasicBlock *SrcMBB); static MachineBasicBlock *clone(MachineBasicBlock *MBB); + /// MachineBasicBlock::ReplaceUsesOfBlockWith doesn't serve the purpose /// because the AMDGPU instruction is not recognized as terminator fix this /// and retire this routine void replaceInstrUseOfBlockWith(MachineBasicBlock *SrcMBB, MachineBasicBlock *OldMBB, MachineBasicBlock *NewBlk); + static void wrapup(MachineBasicBlock *MBB); int patternMatch(MachineBasicBlock *MBB); @@ -299,6 +303,7 @@ protected: MachineBasicBlock *LandMBB); void settleLoopcontBlock(MachineBasicBlock *ContingMBB, MachineBasicBlock *ContMBB); + /// normalizeInfiniteLoopExit change /// B1: /// uncond_br LoopHeader @@ -309,6 +314,7 @@ protected: /// and return the newly added dummy exit block MachineBasicBlock *normalizeInfiniteLoopExit(MachineLoop *LoopRep); void removeUnconditionalBranch(MachineBasicBlock *MBB); + /// Remove duplicate branches instructions in a block. /// For instance /// B0: @@ -318,6 +324,7 @@ protected: /// B0: /// cond_br X B1 B2 void removeRedundantConditionalBranch(MachineBasicBlock *MBB); + void addDummyExitBlock(SmallVectorImpl<MachineBasicBlock *> &RetMBB); void removeSuccessor(MachineBasicBlock *MBB); MachineBasicBlock *cloneBlockForPredecessor(MachineBasicBlock *MBB, @@ -335,10 +342,10 @@ private: SmallVector<MachineBasicBlock *, DEFAULT_VEC_SLOTS> OrderedBlks; }; -char AMDGPUCFGStructurizer::ID = 0; - } // end anonymous namespace +char AMDGPUCFGStructurizer::ID = 0; + int AMDGPUCFGStructurizer::getSCCNum(MachineBasicBlock *MBB) const { MBBInfoMap::const_iterator It = BlockInfoMap.find(MBB); if (It == BlockInfoMap.end()) @@ -535,7 +542,7 @@ int AMDGPUCFGStructurizer::getContinueNzeroOpcode(int OldOpcode) { case AMDGPU::JUMP_COND: case AMDGPU::JUMP: return AMDGPU::CONTINUE_LOGICALNZ_i32; default: llvm_unreachable("internal error"); - }; + } return -1; } @@ -1168,6 +1175,7 @@ int AMDGPUCFGStructurizer::handleJumpintoIfImp(MachineBasicBlock *HeadMBB, return Num; } +#ifndef NDEBUG void AMDGPUCFGStructurizer::showImproveSimpleJumpintoIf( MachineBasicBlock *HeadMBB, MachineBasicBlock *TrueMBB, MachineBasicBlock *FalseMBB, MachineBasicBlock *LandMBB, bool Detail) { @@ -1209,6 +1217,7 @@ void AMDGPUCFGStructurizer::showImproveSimpleJumpintoIf( dbgs() << "\n"; } +#endif int AMDGPUCFGStructurizer::improveSimpleJumpintoIf(MachineBasicBlock *HeadMBB, MachineBasicBlock *TrueMBB, MachineBasicBlock *FalseMBB, @@ -1595,7 +1604,7 @@ void AMDGPUCFGStructurizer::migrateInstruction(MachineBasicBlock *SrcMBB, MachineInstr *BranchMI = getNormalBlockBranchInstr(SrcMBB); if (!BranchMI) { DEBUG( - dbgs() << "migrateInstruction don't see branch instr\n" ; + dbgs() << "migrateInstruction don't see branch instr\n"; ); SpliceEnd = SrcMBB->end(); } else { @@ -1632,7 +1641,7 @@ AMDGPUCFGStructurizer::normalizeInfiniteLoopExit(MachineLoop* LoopRep) { FuncRep->push_back(DummyExitBlk); //insert to function SHOWNEWBLK(DummyExitBlk, "DummyExitBlock to normalize infiniteLoop: "); DEBUG(dbgs() << "Old branch instr: " << *BranchMI << "\n";); - LLVMContext &Ctx = LoopHeader->getParent()->getFunction()->getContext(); + LLVMContext &Ctx = LoopHeader->getParent()->getFunction().getContext(); Ctx.emitError("Extra register needed to handle CFG"); return nullptr; } |
