[llvm] r295518 - MachineRegionInfo: Fix pass initialization
Matthias Braun via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 17 16:41:17 PST 2017
Author: matze
Date: Fri Feb 17 18:41:16 2017
New Revision: 295518
URL: http://llvm.org/viewvc/llvm-project?rev=295518&view=rev
Log:
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 at apple.com>
Added:
llvm/trunk/test/CodeGen/X86/machine-region-info.mir
Modified:
llvm/trunk/include/llvm/CodeGen/MachineBasicBlock.h
llvm/trunk/lib/CodeGen/CodeGen.cpp
llvm/trunk/lib/CodeGen/MachineBasicBlock.cpp
llvm/trunk/lib/CodeGen/MachineRegionInfo.cpp
Modified: llvm/trunk/include/llvm/CodeGen/MachineBasicBlock.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/MachineBasicBlock.h?rev=295518&r1=295517&r2=295518&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/MachineBasicBlock.h (original)
+++ llvm/trunk/include/llvm/CodeGen/MachineBasicBlock.h Fri Feb 17 18:41:16 2017
@@ -128,7 +128,7 @@ public:
/// to an LLVM basic block.
const BasicBlock *getBasicBlock() const { return BB; }
- /// Return the name of the corresponding LLVM basic block, or "(null)".
+ /// Return the name of the corresponding LLVM basic block, or an empty string.
StringRef getName() const;
/// Return a formatted string to identify this block and its parent function.
Modified: llvm/trunk/lib/CodeGen/CodeGen.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/CodeGen.cpp?rev=295518&r1=295517&r2=295518&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/CodeGen.cpp (original)
+++ llvm/trunk/lib/CodeGen/CodeGen.cpp Fri Feb 17 18:41:16 2017
@@ -58,6 +58,7 @@ void llvm::initializeCodeGen(PassRegistr
initializeMachineModuleInfoPass(Registry);
initializeMachinePipelinerPass(Registry);
initializeMachinePostDominatorTreePass(Registry);
+ initializeMachineRegionInfoPassPass(Registry);
initializeMachineSchedulerPass(Registry);
initializeMachineSinkingPass(Registry);
initializeMachineVerifierPassPass(Registry);
Modified: llvm/trunk/lib/CodeGen/MachineBasicBlock.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineBasicBlock.cpp?rev=295518&r1=295517&r2=295518&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MachineBasicBlock.cpp (original)
+++ llvm/trunk/lib/CodeGen/MachineBasicBlock.cpp Fri Feb 17 18:41:16 2017
@@ -232,7 +232,7 @@ StringRef MachineBasicBlock::getName() c
if (const BasicBlock *LBB = getBasicBlock())
return LBB->getName();
else
- return "(null)";
+ return StringRef("", 0);
}
/// Return a hopefully unique identifier for this block.
Modified: llvm/trunk/lib/CodeGen/MachineRegionInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineRegionInfo.cpp?rev=295518&r1=295517&r2=295518&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MachineRegionInfo.cpp (original)
+++ llvm/trunk/lib/CodeGen/MachineRegionInfo.cpp Fri Feb 17 18:41:16 2017
@@ -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 @@ bool MachineRegionInfoPass::runOnMachine
auto DF = &getAnalysis<MachineDominanceFrontier>();
RI.recalculate(F, DT, PDT, DF);
+
+ DEBUG(RI.dump());
+
return false;
}
@@ -103,9 +106,10 @@ void MachineRegionInfoPass::verifyAnalys
void MachineRegionInfoPass::getAnalysisUsage(AnalysisUsage &AU) const {
AU.setPreservesAll();
- AU.addRequiredTransitive<DominatorTreeWrapperPass>();
- AU.addRequired<PostDominatorTreeWrapperPass>();
- AU.addRequired<DominanceFrontierWrapperPass>();
+ AU.addRequired<MachineDominatorTree>();
+ AU.addRequired<MachinePostDominatorTree>();
+ AU.addRequired<MachineDominanceFrontier>();
+ MachineFunctionPass::getAnalysisUsage(AU);
}
void MachineRegionInfoPass::print(raw_ostream &OS, const Module *) const {
@@ -120,13 +124,13 @@ LLVM_DUMP_METHOD void MachineRegionInfoP
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
Added: llvm/trunk/test/CodeGen/X86/machine-region-info.mir
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/machine-region-info.mir?rev=295518&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/X86/machine-region-info.mir (added)
+++ llvm/trunk/test/CodeGen/X86/machine-region-info.mir Fri Feb 17 18:41:16 2017
@@ -0,0 +1,86 @@
+# RUN: llc -run-pass=machine-region-info %s -debug-only=machine-region-info -o /dev/null 2>&1 | FileCheck %s
+
+--- |
+ define void @fun() { ret void }
+...
+---
+name: fun
+body: |
+ bb.0:
+ successors: %bb.1(0x40000000), %bb.7(0x40000000)
+
+ CMP32ri8 %edi, 40, implicit-def %eflags
+ JNE_1 %bb.7, implicit killed %eflags
+ JMP_1 %bb.1
+
+ bb.1:
+ successors: %bb.2(0x40000000), %bb.11(0x40000000)
+
+ CMP32ri8 %edi, 1, implicit-def %eflags
+ JNE_1 %bb.11, implicit killed %eflags
+ JMP_1 %bb.2
+
+ bb.2:
+ successors: %bb.3(0x40000000), %bb.5(0x40000000)
+
+ CMP32ri8 %edi, 2, implicit-def %eflags
+ JNE_1 %bb.5, implicit killed %eflags
+ JMP_1 %bb.3
+
+ bb.3:
+ successors: %bb.4(0x40000000), %bb.5(0x40000000)
+
+ CMP32ri8 %edi, 90, implicit-def %eflags
+ JNE_1 %bb.5, implicit killed %eflags
+ JMP_1 %bb.4
+
+ bb.4:
+ successors: %bb.5(0x80000000)
+
+ bb.5:
+ successors: %bb.6(0x40000000), %bb.11(0x40000000)
+
+ CMP32ri8 %edi, 4, implicit-def %eflags
+ JNE_1 %bb.11, implicit killed %eflags
+ JMP_1 %bb.6
+
+ bb.6:
+ successors: %bb.11(0x80000000)
+
+ JMP_1 %bb.11
+
+ bb.7:
+ successors: %bb.9(0x40000000), %bb.8(0x40000000)
+
+ CMP32ri8 %edi, 5, implicit-def %eflags
+ JE_1 %bb.9, implicit killed %eflags
+ JMP_1 %bb.8
+
+ bb.8:
+ successors: %bb.9(0x80000000)
+
+ bb.9:
+ successors: %bb.11(0x40000000), %bb.10(0x40000000)
+
+ CMP32ri8 %edi, 6, implicit-def %eflags
+ JE_1 %bb.11, implicit killed %eflags
+ JMP_1 %bb.10
+
+ bb.10:
+ successors: %bb.11(0x80000000)
+
+ bb.11:
+ RET 0
+
+...
+
+# CHECK: Region tree:
+# CHECK-NEXT: [0] BB#0 => <Function Return>
+# CHECK-NEXT: [1] BB#0 => BB#11
+# CHECK-NEXT: [2] BB#1 => BB#11
+# CHECK-NEXT: [3] BB#2 => BB#5
+# CHECK-NEXT: [4] BB#3 => BB#5
+# CHECK-NEXT: [3] BB#5 => BB#11
+# CHECK-NEXT: [2] BB#7 => BB#9
+# CHECK-NEXT: [2] BB#9 => BB#11
+# CHECK-NEXT: End region tree
More information about the llvm-commits
mailing list