Index: lib/CodeGen/CodeGen.cpp =================================================================== --- lib/CodeGen/CodeGen.cpp +++ lib/CodeGen/CodeGen.cpp @@ -58,6 +58,7 @@ initializeMachineModuleInfoPass(Registry); initializeMachinePipelinerPass(Registry); initializeMachinePostDominatorTreePass(Registry); + initializeMachineRegionInfoPassPass(Registry); initializeMachineSchedulerPass(Registry); initializeMachineSinkingPass(Registry); initializeMachineVerifierPassPass(Registry); Index: lib/CodeGen/MachineRegionInfo.cpp =================================================================== --- lib/CodeGen/MachineRegionInfo.cpp +++ lib/CodeGen/MachineRegionInfo.cpp @@ -4,7 +4,7 @@ #include "llvm/Analysis/RegionInfoImpl.h" #include "llvm/CodeGen/MachinePostDominators.h" -#define DEBUG_TYPE "region" +#define DEBUG_TYPE "machine-region-info" using namespace llvm; @@ -86,6 +86,9 @@ auto DF = &getAnalysis(); RI.recalculate(F, DT, PDT, DF); + + DEBUG(RI.dump()); + return false; } @@ -103,9 +106,10 @@ void MachineRegionInfoPass::getAnalysisUsage(AnalysisUsage &AU) const { AU.setPreservesAll(); - AU.addRequiredTransitive(); - AU.addRequired(); - AU.addRequired(); + AU.addRequired(); + AU.addRequired(); + AU.addRequired(); + MachineFunctionPass::getAnalysisUsage(AU); } void MachineRegionInfoPass::print(raw_ostream &OS, const Module *) const { @@ -120,13 +124,13 @@ char MachineRegionInfoPass::ID = 0; -INITIALIZE_PASS_BEGIN(MachineRegionInfoPass, "regions", - "Detect single entry single exit regions", true, true) +INITIALIZE_PASS_BEGIN(MachineRegionInfoPass, DEBUG_TYPE, + "Detect single entry single exit regions", true, true) INITIALIZE_PASS_DEPENDENCY(MachineDominatorTree) INITIALIZE_PASS_DEPENDENCY(MachinePostDominatorTree) INITIALIZE_PASS_DEPENDENCY(MachineDominanceFrontier) -INITIALIZE_PASS_END(MachineRegionInfoPass, "regions", - "Detect single entry single exit regions", true, true) +INITIALIZE_PASS_END(MachineRegionInfoPass, DEBUG_TYPE, + "Detect single entry single exit regions", true, true) // Create methods available outside of this file, to use them // "include/llvm/LinkAllPasses.h". Otherwise the pass would be deleted by Index: test/CodeGen/MIR/X86/machine-region-info.mir =================================================================== --- /dev/null +++ test/CodeGen/MIR/X86/machine-region-info.mir @@ -0,0 +1,190 @@ +# RUN: llc -run-pass=machine-region-info %s -debug-only=machine-region-info -o /dev/null 2>&1 | FileCheck %s + +--- | + target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128" + + define i32 @fun(i32 %a) { + A: + %cmp0 = icmp eq i32 %a, 40 + br i1 %cmp0, label %B, label %I + + B: ; preds = %A + %cmp1 = icmp eq i32 %a, 1 + br i1 %cmp1, label %C, label %P + + C: ; preds = %B + %cmp2 = icmp eq i32 %a, 2 + br i1 %cmp2, label %D, label %F + + D: ; preds = %C + %cmp3 = icmp eq i32 %a, 90 + br i1 %cmp3, label %E, label %F + + E: ; preds = %D + call void @fun1(i32 100) + br label %F + + F: ; preds = %E, %D, %C + %cmp4 = icmp eq i32 %a, 4 + br i1 %cmp4, label %G, label %P + + G: ; preds = %F + call void @fun1(i32 300) + br label %P + + I: ; preds = %A + %cmp5 = icmp eq i32 %a, 5 + br i1 %cmp5, label %L, label %K + + K: ; preds = %I + call void @fun1(i32 400) + br label %L + + L: ; preds = %I, %K + %cmp6 = icmp eq i32 %a, 6 + br i1 %cmp6, label %P, label %N + + N: ; preds = %L + call void @fun1(i32 500) + br label %P + + P: ; preds = %N, %L, %B, %F, %G + ret i32 %a + } + + declare void @fun1(i32) + +... +--- +name: fun +alignment: 4 +exposesReturnsTwice: false +legalized: false +regBankSelected: false +selected: false +tracksRegLiveness: true +liveins: + - { reg: '%edi' } +calleeSavedRegisters: [ '%bh', '%bl', '%bp', '%bpl', '%bx', '%ebp', '%ebx', + '%rbp', '%rbx', '%r12', '%r13', '%r14', '%r15', + '%r12b', '%r13b', '%r14b', '%r15b', '%r12d', '%r13d', + '%r14d', '%r15d', '%r12w', '%r13w', '%r14w', '%r15w' ] +frameInfo: + isFrameAddressTaken: false + isReturnAddressTaken: false + hasStackMap: false + hasPatchPoint: false + stackSize: 0 + offsetAdjustment: 0 + maxAlignment: 0 + adjustsStack: false + hasCalls: true + maxCallFrameSize: 0 + hasOpaqueSPAdjustment: false + hasVAStart: false + hasMustTailInVarArgFunc: false +body: | + bb.0.A: + successors: %bb.1.B(0x40000000), %bb.7.I(0x40000000) + liveins: %edi + + %ebx = COPY %edi + CMP32ri8 %ebx, 40, implicit-def %eflags + JNE_1 %bb.7.I, implicit killed %eflags + JMP_1 %bb.1.B + + bb.1.B: + successors: %bb.2.C(0x40000000), %bb.11.P(0x40000000) + liveins: %ebx + + CMP32ri8 %ebx, 1, implicit-def %eflags + JNE_1 %bb.11.P, implicit killed %eflags + JMP_1 %bb.2.C + + bb.2.C: + successors: %bb.3.D(0x40000000), %bb.5.F(0x40000000) + liveins: %ebx + + CMP32ri8 %ebx, 2, implicit-def %eflags + JNE_1 %bb.5.F, implicit killed %eflags + JMP_1 %bb.3.D + + bb.3.D: + successors: %bb.4.E(0x40000000), %bb.5.F(0x40000000) + liveins: %ebx + + CMP32ri8 %ebx, 90, implicit-def %eflags + JNE_1 %bb.5.F, implicit killed %eflags + JMP_1 %bb.4.E + + bb.4.E: + successors: %bb.5.F(0x80000000) + liveins: %ebx + + %edi = MOV32ri 100 + CALL64pcrel32 @fun1, csr_64, implicit %rsp, implicit %edi, implicit-def %rsp + + bb.5.F: + successors: %bb.6.G(0x40000000), %bb.11.P(0x40000000) + liveins: %ebx + + CMP32ri8 %ebx, 4, implicit-def %eflags + JNE_1 %bb.11.P, implicit killed %eflags + JMP_1 %bb.6.G + + bb.6.G: + successors: %bb.11.P(0x80000000) + liveins: %ebx + + %edi = MOV32ri 300 + CALL64pcrel32 @fun1, csr_64, implicit %rsp, implicit %edi, implicit-def %rsp + JMP_1 %bb.11.P + + bb.7.I: + successors: %bb.9.L(0x40000000), %bb.8.K(0x40000000) + liveins: %ebx + + CMP32ri8 %ebx, 5, implicit-def %eflags + JE_1 %bb.9.L, implicit killed %eflags + JMP_1 %bb.8.K + + bb.8.K: + successors: %bb.9.L(0x80000000) + liveins: %ebx + + %edi = MOV32ri 400 + CALL64pcrel32 @fun1, csr_64, implicit %rsp, implicit %edi, implicit-def %rsp + + bb.9.L: + successors: %bb.11.P(0x40000000), %bb.10.N(0x40000000) + liveins: %ebx + + CMP32ri8 %ebx, 6, implicit-def %eflags + JE_1 %bb.11.P, implicit killed %eflags + JMP_1 %bb.10.N + + bb.10.N: + successors: %bb.11.P(0x80000000) + liveins: %ebx + + %edi = MOV32ri 500 + CALL64pcrel32 @fun1, csr_64, implicit %rsp, implicit %edi, implicit-def %rsp + + bb.11.P: + liveins: %ebx + + %eax = COPY killed %ebx + RET 0, killed %eax + +... + +# CHECK: Region tree: +# CHECK-NEXT: [0] A => +# CHECK-NEXT: [1] A => P +# CHECK-NEXT: [2] B => P +# CHECK-NEXT: [3] C => F +# CHECK-NEXT: [4] D => F +# CHECK-NEXT: [3] F => P +# CHECK-NEXT: [2] I => L +# CHECK-NEXT: [2] L => P +# CHECK-NEXT: End region tree