Disable each MachineFunctionPass for 'optnone' functions, unless that
authorPaul Robinson <paul_robinson@playstation.sony.com>
Mon, 31 Mar 2014 17:43:35 +0000 (17:43 +0000)
committerPaul Robinson <paul_robinson@playstation.sony.com>
Mon, 31 Mar 2014 17:43:35 +0000 (17:43 +0000)
pass normally runs at optimization level None, or is part of the
register allocation pipeline.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@205228 91177308-0d34-0410-b5e6-96231b3b80d8

15 files changed:
lib/CodeGen/BranchFolding.cpp
lib/CodeGen/CodeGenPrepare.cpp
lib/CodeGen/DeadMachineInstructionElim.cpp
lib/CodeGen/MachineBlockPlacement.cpp
lib/CodeGen/MachineCSE.cpp
lib/CodeGen/MachineCopyPropagation.cpp
lib/CodeGen/MachineLICM.cpp
lib/CodeGen/MachineScheduler.cpp
lib/CodeGen/MachineSink.cpp
lib/CodeGen/OptimizePHIs.cpp
lib/CodeGen/PeepholeOptimizer.cpp
lib/CodeGen/PostRASchedulerList.cpp
lib/CodeGen/StackColoring.cpp
lib/CodeGen/TailDuplication.cpp
test/Feature/optnone-llc.ll [new file with mode: 0644]

index bf6d56ceac8828c6cb69fffc16301e57ed377179..b39777edf465a27d3d4476c123351b378b1e691d 100644 (file)
@@ -82,6 +82,9 @@ INITIALIZE_PASS(BranchFolderPass, "branch-folder",
                 "Control Flow Optimizer", false, false)
 
 bool BranchFolderPass::runOnMachineFunction(MachineFunction &MF) {
+  if (skipOptnoneFunction(*MF.getFunction()))
+    return false;
+
   TargetPassConfig *PassConfig = &getAnalysis<TargetPassConfig>();
   // TailMerge can create jump into if branches that make CFG irreducible for
   // HW that requires structurized CFG.
index 72d6ac5636251a6c0692115e6e933bf6df41936c..e82a30617d2204e6ff75d38ac01900ee3b4bf9e8 100644 (file)
@@ -164,6 +164,9 @@ FunctionPass *llvm::createCodeGenPreparePass(const TargetMachine *TM) {
 }
 
 bool CodeGenPrepare::runOnFunction(Function &F) {
+  if (skipOptnoneFunction(F))
+    return false;
+
   bool EverMadeChange = false;
   // Clear per function information.
   InsertedTruncsSet.clear();
index 643efc2a4f90a06e233b5afdb31591cd0e567cd9..aa03e7752a2b967f899304c3a5122a7d7b604b5f 100644 (file)
@@ -84,6 +84,9 @@ bool DeadMachineInstructionElim::isDead(const MachineInstr *MI) const {
 }
 
 bool DeadMachineInstructionElim::runOnMachineFunction(MachineFunction &MF) {
+  if (skipOptnoneFunction(*MF.getFunction()))
+    return false;
+
   bool AnyChanges = false;
   MRI = &MF.getRegInfo();
   TRI = MF.getTarget().getRegisterInfo();
index 75745e5cb005c6fdab773f4b440b22d9ed5ce2c5..771e7ce3eadd63673fbc77413fbaa4eea9888c71 100644 (file)
@@ -1104,6 +1104,9 @@ bool MachineBlockPlacement::runOnMachineFunction(MachineFunction &F) {
   if (std::next(F.begin()) == F.end())
     return false;
 
+  if (skipOptnoneFunction(*F.getFunction()))
+    return false;
+
   MBPI = &getAnalysis<MachineBranchProbabilityInfo>();
   MBFI = &getAnalysis<MachineBlockFrequencyInfo>();
   MLI = &getAnalysis<MachineLoopInfo>();
index fd153d8c448c6a785bda42f8582593ffa418b178..9c3bcc444c44aa821fd1637b32b0fa7f51f0e94f 100644 (file)
@@ -659,6 +659,9 @@ bool MachineCSE::PerformCSE(MachineDomTreeNode *Node) {
 }
 
 bool MachineCSE::runOnMachineFunction(MachineFunction &MF) {
+  if (skipOptnoneFunction(*MF.getFunction()))
+    return false;
+
   TII = MF.getTarget().getInstrInfo();
   TRI = MF.getTarget().getRegisterInfo();
   MRI = &MF.getRegInfo();
index 7c981cae26f8dd473174ef0a5910d7da35aa5017..7e1970cf6d8e12fa00b2d84d0e63cccd48c3def5 100644 (file)
@@ -329,6 +329,9 @@ bool MachineCopyPropagation::CopyPropagateBlock(MachineBasicBlock &MBB) {
 }
 
 bool MachineCopyPropagation::runOnMachineFunction(MachineFunction &MF) {
+  if (skipOptnoneFunction(*MF.getFunction()))
+    return false;
+
   bool Changed = false;
 
   TRI = MF.getTarget().getRegisterInfo();
index 08678f81da51fb088f625f6aca242e69921754cb..d3a1ee7380fa5ebc55e080d756b20cb0d3970586 100644 (file)
@@ -319,6 +319,9 @@ static bool LoopIsOuterMostWithPredecessor(MachineLoop *CurLoop) {
 }
 
 bool MachineLICM::runOnMachineFunction(MachineFunction &MF) {
+  if (skipOptnoneFunction(*MF.getFunction()))
+    return false;
+
   Changed = FirstInLoop = false;
   TM = &MF.getTarget();
   TII = TM->getInstrInfo();
index f99fc72e75b74064224c6eb7cdf1147b0f59c9b3..d90cd239e04eb5ab10d07fef4e135eeae971295f 100644 (file)
@@ -330,6 +330,9 @@ bool MachineScheduler::runOnMachineFunction(MachineFunction &mf) {
 }
 
 bool PostMachineScheduler::runOnMachineFunction(MachineFunction &mf) {
+  if (skipOptnoneFunction(*mf.getFunction()))
+    return false;
+
   DEBUG(dbgs() << "Before post-MI-sched:\n"; mf.print(dbgs()));
 
   // Initialize the context of the pass.
index e9e97cc2379d1ef043ee9f1e1ef9063460e6350c..dbff1f6440ac266e7268d9916df6fcc26eee2afe 100644 (file)
@@ -207,6 +207,9 @@ MachineSinking::AllUsesDominatedByBlock(unsigned Reg,
 }
 
 bool MachineSinking::runOnMachineFunction(MachineFunction &MF) {
+  if (skipOptnoneFunction(*MF.getFunction()))
+    return false;
+
   DEBUG(dbgs() << "******** Machine Sinking ********\n");
 
   const TargetMachine &TM = MF.getTarget();
index 4973802aa05fc184136b35f2d6d5ce81dcb47956..56cb6735272b888fe5b9584e29137ba44f0adf40 100644 (file)
@@ -61,6 +61,9 @@ INITIALIZE_PASS(OptimizePHIs, "opt-phis",
                 "Optimize machine instruction PHIs", false, false)
 
 bool OptimizePHIs::runOnMachineFunction(MachineFunction &Fn) {
+  if (skipOptnoneFunction(*Fn.getFunction()))
+    return false;
+
   MRI = &Fn.getRegInfo();
   TII = Fn.getTarget().getInstrInfo();
 
index 73c9e1ce1a869b11247476fddec8cc6b55028b2c..23be3c80961f67aab3acf4e0d6f133cd8df2477c 100644 (file)
@@ -554,6 +554,9 @@ bool PeepholeOptimizer::foldImmediate(MachineInstr *MI, MachineBasicBlock *MBB,
 }
 
 bool PeepholeOptimizer::runOnMachineFunction(MachineFunction &MF) {
+  if (skipOptnoneFunction(*MF.getFunction()))
+    return false;
+
   DEBUG(dbgs() << "********** PEEPHOLE OPTIMIZER **********\n");
   DEBUG(dbgs() << "********** Function: " << MF.getName() << '\n');
 
index 1e1b0075651b9e054381c99b4843aeead6a9fbb1..a13e51f1d485b9ab499c6c0b69cdeeb2b79a16a6 100644 (file)
@@ -245,6 +245,9 @@ void SchedulePostRATDList::dumpSchedule() const {
 #endif
 
 bool PostRAScheduler::runOnMachineFunction(MachineFunction &Fn) {
+  if (skipOptnoneFunction(*Fn.getFunction()))
+    return false;
+
   TII = Fn.getTarget().getInstrInfo();
   MachineLoopInfo &MLI = getAnalysis<MachineLoopInfo>();
   MachineDominatorTree &MDT = getAnalysis<MachineDominatorTree>();
index 9a79a3afec66e2cf066e2ae10a257a7da6a7076e..7b1de85baa7bf51328055870143bc9df4ae57a49 100644 (file)
@@ -640,6 +640,9 @@ void StackColoring::expungeSlotMap(DenseMap<int, int> &SlotRemap,
 }
 
 bool StackColoring::runOnMachineFunction(MachineFunction &Func) {
+  if (skipOptnoneFunction(*Func.getFunction()))
+    return false;
+
   DEBUG(dbgs() << "********** Stack Coloring **********\n"
                << "********** Function: "
                << ((const Value*)Func.getFunction())->getName() << '\n');
index 40ce2b6cbba9907dbfc89972553836d303362454..3b7a04c6831f7f24d224a87308085ab14869cffd 100644 (file)
@@ -131,6 +131,9 @@ INITIALIZE_PASS(TailDuplicatePass, "tailduplication", "Tail Duplication",
                 false, false)
 
 bool TailDuplicatePass::runOnMachineFunction(MachineFunction &MF) {
+  if (skipOptnoneFunction(*MF.getFunction()))
+    return false;
+
   TII = MF.getTarget().getInstrInfo();
   TRI = MF.getTarget().getRegisterInfo();
   MRI = &MF.getRegInfo();
diff --git a/test/Feature/optnone-llc.ll b/test/Feature/optnone-llc.ll
new file mode 100644 (file)
index 0000000..6cb27d0
--- /dev/null
@@ -0,0 +1,54 @@
+; RUN: llc -O0 -debug %s -o /dev/null 2>&1 | FileCheck %s --check-prefix=LLC-O0
+; RUN: llc -O1 -debug %s -o /dev/null 2>&1 | FileCheck %s --check-prefix=LLC-Ox
+; RUN: llc -O2 -debug %s -o /dev/null 2>&1 | FileCheck %s --check-prefix=LLC-Ox
+; RUN: llc -O3 -debug %s -o /dev/null 2>&1 | FileCheck %s --check-prefix=LLC-Ox
+; RUN: llc -misched-postra -debug %s -o /dev/null 2>&1 | FileCheck %s --check-prefix=LLC-MORE
+
+; REQUIRES: asserts
+
+; This test verifies that we don't run Machine Function optimizations
+; on optnone functions.
+
+; Function Attrs: noinline optnone
+define i32 @_Z3fooi(i32 %x) #0 {
+entry:
+  %x.addr = alloca i32, align 4
+  store i32 %x, i32* %x.addr, align 4
+  br label %while.cond
+
+while.cond:                                       ; preds = %while.body, %entry
+  %0 = load i32* %x.addr, align 4
+  %dec = add nsw i32 %0, -1
+  store i32 %dec, i32* %x.addr, align 4
+  %tobool = icmp ne i32 %0, 0
+  br i1 %tobool, label %while.body, label %while.end
+
+while.body:                                       ; preds = %while.cond
+  br label %while.cond
+
+while.end:                                        ; preds = %while.cond
+  ret i32 0
+}
+
+attributes #0 = { optnone noinline }
+
+; Nothing that runs at -O0 gets skipped.
+; LLC-O0-NOT: Skipping pass
+
+; Machine Function passes run at -O1 and higher.
+; LLC-Ox-DAG: Skipping pass 'Branch Probability Basic Block Placement'
+; LLC-Ox-DAG: Skipping pass 'CodeGen Prepare'
+; LLC-Ox-DAG: Skipping pass 'Control Flow Optimizer'
+; LLC-Ox-DAG: Skipping pass 'Machine code sinking'
+; LLC-Ox-DAG: Skipping pass 'Machine Common Subexpression Elimination'
+; LLC-Ox-DAG: Skipping pass 'Machine Copy Propagation Pass'
+; LLC-Ox-DAG: Skipping pass 'Machine Loop Invariant Code Motion'
+; LLC-Ox-DAG: Skipping pass 'Merge disjoint stack slots'
+; LLC-Ox-DAG: Skipping pass 'Optimize machine instruction PHIs'
+; LLC-Ox-DAG: Skipping pass 'Peephole Optimizations'
+; LLC-Ox-DAG: Skipping pass 'Post RA top-down list latency scheduler'
+; LLC-Ox-DAG: Skipping pass 'Remove dead machine instructions'
+; LLC-Ox-DAG: Skipping pass 'Tail Duplication'
+
+; Alternate post-RA scheduler.
+; LLC-MORE: Skipping pass 'PostRA Machine Instruction Scheduler'