[llvm-branch-commits] [llvm-branch] r195604 - Merging r195491:

Bill Wendling isanbard at gmail.com
Sun Nov 24 21:21:51 PST 2013


Author: void
Date: Sun Nov 24 23:21:50 2013
New Revision: 195604

URL: http://llvm.org/viewvc/llvm-project?rev=195604&view=rev
Log:
Merging r195491:
------------------------------------------------------------------------
r195491 | probinson | 2013-11-22 11:11:24 -0800 (Fri, 22 Nov 2013) | 11 lines

Teach ISel not to optimize 'optnone' functions (revised).

Improvements over r195317:
- Set/restore EnableFastISel flag instead of just running FastISel within
  SelectAllBasicBlocks; the flag is checked in various places, and
  FastISel won't run properly if those places don't do the right thing.
- Test looks for normal ISel versus FastISel behavior, and not
  something more subtle that doesn't work everywhere.

Based on work by Andrea Di Biagio.

------------------------------------------------------------------------

Added:
    llvm/branches/release_34/test/CodeGen/X86/isel-optnone.ll
      - copied unchanged from r195491, llvm/trunk/test/CodeGen/X86/isel-optnone.ll
Modified:
    llvm/branches/release_34/   (props changed)
    llvm/branches/release_34/include/llvm/MC/MCCodeGenInfo.h
    llvm/branches/release_34/include/llvm/Target/TargetMachine.h
    llvm/branches/release_34/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
    llvm/branches/release_34/lib/Target/TargetMachine.cpp

Propchange: llvm/branches/release_34/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Sun Nov 24 23:21:50 2013
@@ -1,3 +1,3 @@
 /llvm/branches/Apple/Pertwee:110850,110961
 /llvm/branches/type-system-rewrite:133420-134817
-/llvm/trunk:155241,195092-195094,195100,195102-195103,195118,195129,195138,195152,195156-195157,195161-195162,195193,195272,195317-195318,195333,195339,195355,195397-195399,195421,195423,195432,195439,195476-195477,195567,195599
+/llvm/trunk:155241,195092-195094,195100,195102-195103,195118,195129,195138,195152,195156-195157,195161-195162,195193,195272,195317-195318,195333,195339,195355,195397-195399,195421,195423,195432,195439,195476-195477,195491,195567,195599

Modified: llvm/branches/release_34/include/llvm/MC/MCCodeGenInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_34/include/llvm/MC/MCCodeGenInfo.h?rev=195604&r1=195603&r2=195604&view=diff
==============================================================================
--- llvm/branches/release_34/include/llvm/MC/MCCodeGenInfo.h (original)
+++ llvm/branches/release_34/include/llvm/MC/MCCodeGenInfo.h Sun Nov 24 23:21:50 2013
@@ -42,6 +42,9 @@ namespace llvm {
     CodeModel::Model getCodeModel() const { return CMModel; }
 
     CodeGenOpt::Level getOptLevel() const { return OptLevel; }
+
+    // Allow overriding OptLevel on a per-function basis.
+    void setOptLevel(CodeGenOpt::Level Level) { OptLevel = Level; }
   };
 } // namespace llvm
 

Modified: llvm/branches/release_34/include/llvm/Target/TargetMachine.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_34/include/llvm/Target/TargetMachine.h?rev=195604&r1=195603&r2=195604&view=diff
==============================================================================
--- llvm/branches/release_34/include/llvm/Target/TargetMachine.h (original)
+++ llvm/branches/release_34/include/llvm/Target/TargetMachine.h Sun Nov 24 23:21:50 2013
@@ -75,7 +75,8 @@ protected: // Can only create subclasses
   std::string TargetFS;
 
   /// CodeGenInfo - Low level target information such as relocation model.
-  const MCCodeGenInfo *CodeGenInfo;
+  /// Non-const to allow resetting optimization level per-function.
+  MCCodeGenInfo *CodeGenInfo;
 
   /// AsmInfo - Contains target specific asm information.
   ///
@@ -213,6 +214,9 @@ public:
   /// Default, or Aggressive.
   CodeGenOpt::Level getOptLevel() const;
 
+  /// \brief Overrides the optimization level.
+  void setOptLevel(CodeGenOpt::Level Level) const;
+
   void setFastISel(bool Enable) { Options.EnableFastISel = Enable; }
 
   bool shouldPrintMachineCode() const { return Options.PrintMachineCode; }

Modified: llvm/branches/release_34/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_34/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp?rev=195604&r1=195603&r2=195604&view=diff
==============================================================================
--- llvm/branches/release_34/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp (original)
+++ llvm/branches/release_34/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp Sun Nov 24 23:21:50 2013
@@ -223,6 +223,44 @@ defaultListDAGScheduler("default", "Best
 
 namespace llvm {
   //===--------------------------------------------------------------------===//
+  /// \brief This class is used by SelectionDAGISel to temporarily override
+  /// the optimization level on a per-function basis.
+  class OptLevelChanger {
+    SelectionDAGISel &IS;
+    CodeGenOpt::Level SavedOptLevel;
+    bool SavedFastISel;
+
+  public:
+    OptLevelChanger(SelectionDAGISel &ISel,
+                    CodeGenOpt::Level NewOptLevel) : IS(ISel) {
+      SavedOptLevel = IS.OptLevel;
+      if (NewOptLevel == SavedOptLevel)
+        return;
+      IS.OptLevel = NewOptLevel;
+      IS.TM.setOptLevel(NewOptLevel);
+      SavedFastISel = IS.TM.Options.EnableFastISel;
+      if (NewOptLevel == CodeGenOpt::None)
+        IS.TM.setFastISel(true);
+      DEBUG(dbgs() << "\nChanging optimization level for Function "
+            << IS.MF->getFunction()->getName() << "\n");
+      DEBUG(dbgs() << "\tBefore: -O" << SavedOptLevel
+            << " ; After: -O" << NewOptLevel << "\n");
+    }
+
+    ~OptLevelChanger() {
+      if (IS.OptLevel == SavedOptLevel)
+        return;
+      DEBUG(dbgs() << "\nRestoring optimization level for Function "
+            << IS.MF->getFunction()->getName() << "\n");
+      DEBUG(dbgs() << "\tBefore: -O" << IS.OptLevel
+            << " ; After: -O" << SavedOptLevel << "\n");
+      IS.OptLevel = SavedOptLevel;
+      IS.TM.setOptLevel(SavedOptLevel);
+      IS.TM.setFastISel(SavedFastISel);
+    }
+  };
+
+  //===--------------------------------------------------------------------===//
   /// createDefaultScheduler - This creates an instruction scheduler appropriate
   /// for the target.
   ScheduleDAGSDNodes* createDefaultScheduler(SelectionDAGISel *IS,
@@ -370,6 +408,12 @@ bool SelectionDAGISel::runOnMachineFunct
   ST.resetSubtargetFeatures(MF);
   TM.resetTargetOptions(MF);
 
+  // Reset OptLevel to None for optnone functions.
+  CodeGenOpt::Level NewOptLevel = OptLevel;
+  if (Fn.hasFnAttribute(Attribute::OptimizeNone))
+    NewOptLevel = CodeGenOpt::None;
+  OptLevelChanger OLC(*this, NewOptLevel);
+
   DEBUG(dbgs() << "\n\n\n=== " << Fn.getName() << "\n");
 
   SplitCriticalSideEffectEdges(const_cast<Function&>(Fn), this);

Modified: llvm/branches/release_34/lib/Target/TargetMachine.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_34/lib/Target/TargetMachine.cpp?rev=195604&r1=195603&r2=195604&view=diff
==============================================================================
--- llvm/branches/release_34/lib/Target/TargetMachine.cpp (original)
+++ llvm/branches/release_34/lib/Target/TargetMachine.cpp Sun Nov 24 23:21:50 2013
@@ -164,6 +164,11 @@ CodeGenOpt::Level TargetMachine::getOptL
   return CodeGenInfo->getOptLevel();
 }
 
+void TargetMachine::setOptLevel(CodeGenOpt::Level Level) const {
+  if (CodeGenInfo)
+    CodeGenInfo->setOptLevel(Level);
+}
+
 bool TargetMachine::getAsmVerbosityDefault() {
   return AsmVerbosityDefault;
 }





More information about the llvm-branch-commits mailing list