LLVM: lib/CodeGen/GCEmptyBasicBlocks.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
22
23using namespace llvm;
24
25#define DEBUG_TYPE "gc-empty-basic-blocks"
26
27STATISTIC(NumEmptyBlocksRemoved, "Number of empty blocks removed");
28
30public:
32
36
38 return "Remove Empty Basic Blocks.";
39 }
40
42};
43
45 if (MF.size() < 2)
46 return false;
48 int NumRemoved = 0;
49
50
51
54 NextMBB;
55 MBB != LastMBB; MBB = NextMBB) {
56 NextMBB = std::next(MBB);
57
58
59
60 if (MBB->isEHPad() || MBB->hasAddressTaken())
61 continue;
62
64 return .isPosition() &&
.isImplicitDef() &&
.isKill() &&
65 .isDebugInstr();
66 });
67 if (HasAnyRealCode)
68 continue;
69
71 << " in function " << MF.getName() << ":\n"
72 << *MBB << "\n");
74
75 for (auto &Pred : Preds)
76 Pred->ReplaceUsesOfBlockWith(&*MBB, &*NextMBB);
77
78 if (JTI)
80
81 while (->succ_empty())
82 MBB->removeSuccessor(MBB->succ_end() - 1);
83
84 MBB->eraseFromParent();
85 ++NumRemoved;
86 }
87 NumEmptyBlocksRemoved += NumRemoved;
88 return NumRemoved != 0;
89}
90
93 "Removes empty basic blocks and redirects their uses to their "
94 "fallthrough blocks.",
95 false, false)
96
99}
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
This file defines the SmallVector class.
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
GCEmptyBasicBlocks()
Definition GCEmptyBasicBlocks.cpp:33
StringRef getPassName() const override
getPassName - Return a nice clean name for a pass.
Definition GCEmptyBasicBlocks.cpp:37
bool runOnMachineFunction(MachineFunction &MF) override
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
Definition GCEmptyBasicBlocks.cpp:44
static char ID
Definition GCEmptyBasicBlocks.cpp:31
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
MachineFunctionPass(char &ID)
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
const MachineBasicBlock & back() const
BasicBlockListType::iterator iterator
const MachineJumpTableInfo * getJumpTableInfo() const
getJumpTableInfo - Return the jump table info object for the current function.
Representation of each machine instruction.
LLVM_ABI bool ReplaceMBBInJumpTables(MachineBasicBlock *Old, MachineBasicBlock *New)
ReplaceMBBInJumpTables - If Old is the target of any jump tables, update the jump tables to branch to...
static LLVM_ABI PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI MachineFunctionPass * createGCEmptyBasicBlocksPass()
createGCEmptyBasicblocksPass - Empty basic blocks (basic blocks without real code) appear as the resu...
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
LLVM_ABI void initializeGCEmptyBasicBlocksPass(PassRegistry &)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.