Skip to content
This repository was archived by the owner on Apr 23, 2020. It is now read-only.

Commit 5e55477

Browse files
committed
MachineRegionInfo: Fix pass initialization
- Adapt MachineBasicBlock::getName() to have the same behavior as the IR BasicBlock (Value::getName()). - Add it to lib/CodeGen/CodeGen.cpp::initializeCodeGen so that it is linked in the CodeGen library. - MachineRegionInfoPass's name conflicts with RegionInfoPass's name ("region"). - MachineRegionInfo should depend on MachineDominatorTree, MachinePostDominatorTree and MachineDominanceFrontier instead of their respective IR versions. - Since there were no tests for this, add a X86 MIR test. Patch by Francis Visoiu Mistrih<fvisoiumistrih@apple.com> git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@295518 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent a39b1ce commit 5e55477

File tree

5 files changed

+101
-10
lines changed

5 files changed

+101
-10
lines changed

include/llvm/CodeGen/MachineBasicBlock.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ class MachineBasicBlock
128128
/// to an LLVM basic block.
129129
const BasicBlock *getBasicBlock() const { return BB; }
130130

131-
/// Return the name of the corresponding LLVM basic block, or "(null)".
131+
/// Return the name of the corresponding LLVM basic block, or an empty string.
132132
StringRef getName() const;
133133

134134
/// Return a formatted string to identify this block and its parent function.

lib/CodeGen/CodeGen.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ void llvm::initializeCodeGen(PassRegistry &Registry) {
5858
initializeMachineModuleInfoPass(Registry);
5959
initializeMachinePipelinerPass(Registry);
6060
initializeMachinePostDominatorTreePass(Registry);
61+
initializeMachineRegionInfoPassPass(Registry);
6162
initializeMachineSchedulerPass(Registry);
6263
initializeMachineSinkingPass(Registry);
6364
initializeMachineVerifierPassPass(Registry);

lib/CodeGen/MachineBasicBlock.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ StringRef MachineBasicBlock::getName() const {
232232
if (const BasicBlock *LBB = getBasicBlock())
233233
return LBB->getName();
234234
else
235-
return "(null)";
235+
return StringRef("", 0);
236236
}
237237

238238
/// Return a hopefully unique identifier for this block.

lib/CodeGen/MachineRegionInfo.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include "llvm/Analysis/RegionInfoImpl.h"
55
#include "llvm/CodeGen/MachinePostDominators.h"
66

7-
#define DEBUG_TYPE "region"
7+
#define DEBUG_TYPE "machine-region-info"
88

99
using namespace llvm;
1010

@@ -86,6 +86,9 @@ bool MachineRegionInfoPass::runOnMachineFunction(MachineFunction &F) {
8686
auto DF = &getAnalysis<MachineDominanceFrontier>();
8787

8888
RI.recalculate(F, DT, PDT, DF);
89+
90+
DEBUG(RI.dump());
91+
8992
return false;
9093
}
9194

@@ -103,9 +106,10 @@ void MachineRegionInfoPass::verifyAnalysis() const {
103106

104107
void MachineRegionInfoPass::getAnalysisUsage(AnalysisUsage &AU) const {
105108
AU.setPreservesAll();
106-
AU.addRequiredTransitive<DominatorTreeWrapperPass>();
107-
AU.addRequired<PostDominatorTreeWrapperPass>();
108-
AU.addRequired<DominanceFrontierWrapperPass>();
109+
AU.addRequired<MachineDominatorTree>();
110+
AU.addRequired<MachinePostDominatorTree>();
111+
AU.addRequired<MachineDominanceFrontier>();
112+
MachineFunctionPass::getAnalysisUsage(AU);
109113
}
110114

111115
void MachineRegionInfoPass::print(raw_ostream &OS, const Module *) const {
@@ -120,13 +124,13 @@ LLVM_DUMP_METHOD void MachineRegionInfoPass::dump() const {
120124

121125
char MachineRegionInfoPass::ID = 0;
122126

123-
INITIALIZE_PASS_BEGIN(MachineRegionInfoPass, "regions",
124-
"Detect single entry single exit regions", true, true)
127+
INITIALIZE_PASS_BEGIN(MachineRegionInfoPass, DEBUG_TYPE,
128+
"Detect single entry single exit regions", true, true)
125129
INITIALIZE_PASS_DEPENDENCY(MachineDominatorTree)
126130
INITIALIZE_PASS_DEPENDENCY(MachinePostDominatorTree)
127131
INITIALIZE_PASS_DEPENDENCY(MachineDominanceFrontier)
128-
INITIALIZE_PASS_END(MachineRegionInfoPass, "regions",
129-
"Detect single entry single exit regions", true, true)
132+
INITIALIZE_PASS_END(MachineRegionInfoPass, DEBUG_TYPE,
133+
"Detect single entry single exit regions", true, true)
130134

131135
// Create methods available outside of this file, to use them
132136
// "include/llvm/LinkAllPasses.h". Otherwise the pass would be deleted by
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# RUN: llc -run-pass=machine-region-info %s -debug-only=machine-region-info -o /dev/null 2>&1 | FileCheck %s
2+
3+
--- |
4+
define void @fun() { ret void }
5+
...
6+
---
7+
name: fun
8+
body: |
9+
bb.0:
10+
successors: %bb.1(0x40000000), %bb.7(0x40000000)
11+
12+
CMP32ri8 %edi, 40, implicit-def %eflags
13+
JNE_1 %bb.7, implicit killed %eflags
14+
JMP_1 %bb.1
15+
16+
bb.1:
17+
successors: %bb.2(0x40000000), %bb.11(0x40000000)
18+
19+
CMP32ri8 %edi, 1, implicit-def %eflags
20+
JNE_1 %bb.11, implicit killed %eflags
21+
JMP_1 %bb.2
22+
23+
bb.2:
24+
successors: %bb.3(0x40000000), %bb.5(0x40000000)
25+
26+
CMP32ri8 %edi, 2, implicit-def %eflags
27+
JNE_1 %bb.5, implicit killed %eflags
28+
JMP_1 %bb.3
29+
30+
bb.3:
31+
successors: %bb.4(0x40000000), %bb.5(0x40000000)
32+
33+
CMP32ri8 %edi, 90, implicit-def %eflags
34+
JNE_1 %bb.5, implicit killed %eflags
35+
JMP_1 %bb.4
36+
37+
bb.4:
38+
successors: %bb.5(0x80000000)
39+
40+
bb.5:
41+
successors: %bb.6(0x40000000), %bb.11(0x40000000)
42+
43+
CMP32ri8 %edi, 4, implicit-def %eflags
44+
JNE_1 %bb.11, implicit killed %eflags
45+
JMP_1 %bb.6
46+
47+
bb.6:
48+
successors: %bb.11(0x80000000)
49+
50+
JMP_1 %bb.11
51+
52+
bb.7:
53+
successors: %bb.9(0x40000000), %bb.8(0x40000000)
54+
55+
CMP32ri8 %edi, 5, implicit-def %eflags
56+
JE_1 %bb.9, implicit killed %eflags
57+
JMP_1 %bb.8
58+
59+
bb.8:
60+
successors: %bb.9(0x80000000)
61+
62+
bb.9:
63+
successors: %bb.11(0x40000000), %bb.10(0x40000000)
64+
65+
CMP32ri8 %edi, 6, implicit-def %eflags
66+
JE_1 %bb.11, implicit killed %eflags
67+
JMP_1 %bb.10
68+
69+
bb.10:
70+
successors: %bb.11(0x80000000)
71+
72+
bb.11:
73+
RET 0
74+
75+
...
76+
77+
# CHECK: Region tree:
78+
# CHECK-NEXT: [0] BB#0 => <Function Return>
79+
# CHECK-NEXT: [1] BB#0 => BB#11
80+
# CHECK-NEXT: [2] BB#1 => BB#11
81+
# CHECK-NEXT: [3] BB#2 => BB#5
82+
# CHECK-NEXT: [4] BB#3 => BB#5
83+
# CHECK-NEXT: [3] BB#5 => BB#11
84+
# CHECK-NEXT: [2] BB#7 => BB#9
85+
# CHECK-NEXT: [2] BB#9 => BB#11
86+
# CHECK-NEXT: End region tree

0 commit comments

Comments
 (0)