<div dir="ltr"><div>Hi Paul,</div><div><br></div><div>I know our bot is a bit unstable lately, but this seems like a real test error:</div><div><br></div><a href="http://lab.llvm.org:8011/builders/clang-native-arm-cortex-a9/builds/13534">http://lab.llvm.org:8011/builders/clang-native-arm-cortex-a9/builds/13534</a><br>
<div><br></div><div>cheers,</div><div>--renato</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On 21 November 2013 06:33, Paul Robinson <span dir="ltr"><<a href="mailto:paul_robinson@playstation.sony.com" target="_blank">paul_robinson@playstation.sony.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: probinson<br>
Date: Thu Nov 21 00:33:32 2013<br>
New Revision: 195317<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=195317&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=195317&view=rev</a><br>
Log:<br>
Teach ISel not to optimize 'optnone' functions.<br>
<br>
Based on work by Andrea Di Biagio.<br>
<br>
Added:<br>
llvm/trunk/test/CodeGen/Generic/isel-optnone.ll<br>
Modified:<br>
llvm/trunk/include/llvm/MC/MCCodeGenInfo.h<br>
llvm/trunk/include/llvm/Target/TargetMachine.h<br>
llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp<br>
llvm/trunk/lib/Target/TargetMachine.cpp<br>
<br>
Modified: llvm/trunk/include/llvm/MC/MCCodeGenInfo.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCCodeGenInfo.h?rev=195317&r1=195316&r2=195317&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCCodeGenInfo.h?rev=195317&r1=195316&r2=195317&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/MC/MCCodeGenInfo.h (original)<br>
+++ llvm/trunk/include/llvm/MC/MCCodeGenInfo.h Thu Nov 21 00:33:32 2013<br>
@@ -42,6 +42,9 @@ namespace llvm {<br>
CodeModel::Model getCodeModel() const { return CMModel; }<br>
<br>
CodeGenOpt::Level getOptLevel() const { return OptLevel; }<br>
+<br>
+ // Allow overriding OptLevel on a per-function basis.<br>
+ void setOptLevel(CodeGenOpt::Level Level) { OptLevel = Level; }<br>
};<br>
} // namespace llvm<br>
<br>
<br>
Modified: llvm/trunk/include/llvm/Target/TargetMachine.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/TargetMachine.h?rev=195317&r1=195316&r2=195317&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/TargetMachine.h?rev=195317&r1=195316&r2=195317&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/Target/TargetMachine.h (original)<br>
+++ llvm/trunk/include/llvm/Target/TargetMachine.h Thu Nov 21 00:33:32 2013<br>
@@ -75,7 +75,8 @@ protected: // Can only create subclasses<br>
std::string TargetFS;<br>
<br>
/// CodeGenInfo - Low level target information such as relocation model.<br>
- const MCCodeGenInfo *CodeGenInfo;<br>
+ /// Non-const to allow resetting optimization level per-function.<br>
+ MCCodeGenInfo *CodeGenInfo;<br>
<br>
/// AsmInfo - Contains target specific asm information.<br>
///<br>
@@ -213,6 +214,9 @@ public:<br>
/// Default, or Aggressive.<br>
CodeGenOpt::Level getOptLevel() const;<br>
<br>
+ /// \brief Overrides the optimization level.<br>
+ void setOptLevel(CodeGenOpt::Level Level) const;<br>
+<br>
void setFastISel(bool Enable) { Options.EnableFastISel = Enable; }<br>
<br>
bool shouldPrintMachineCode() const { return Options.PrintMachineCode; }<br>
<br>
Modified: llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp?rev=195317&r1=195316&r2=195317&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp?rev=195317&r1=195316&r2=195317&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp (original)<br>
+++ llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp Thu Nov 21 00:33:32 2013<br>
@@ -223,6 +223,39 @@ defaultListDAGScheduler("default", "Best<br>
<br>
namespace llvm {<br>
//===--------------------------------------------------------------------===//<br>
+ /// \brief This struct is used by SelectionDAGISel to temporarily override<br>
+ /// the optimization level on a per-function basis.<br>
+ class OptLevelChanger {<br>
+ SelectionDAGISel &IS;<br>
+ CodeGenOpt::Level SavedOptLevel;<br>
+<br>
+ public:<br>
+ OptLevelChanger(SelectionDAGISel &ISel,<br>
+ CodeGenOpt::Level NewOptLevel) : IS(ISel) {<br>
+ SavedOptLevel = IS.OptLevel;<br>
+ if (NewOptLevel == SavedOptLevel)<br>
+ return;<br>
+ IS.OptLevel = NewOptLevel;<br>
+ IS.TM.setOptLevel(NewOptLevel);<br>
+ DEBUG(dbgs() << "\nChanging optimization level for Function "<br>
+ << IS.MF->getFunction()->getName() << "\n");<br>
+ DEBUG(dbgs() << "\tBefore: -O" << SavedOptLevel<br>
+ << " ; After: -O" << NewOptLevel << "\n");<br>
+ }<br>
+<br>
+ ~OptLevelChanger() {<br>
+ if (IS.OptLevel == SavedOptLevel)<br>
+ return;<br>
+ DEBUG(dbgs() << "\nRestoring optimization level for Function "<br>
+ << IS.MF->getFunction()->getName() << "\n");<br>
+ DEBUG(dbgs() << "\tBefore: -O" << IS.OptLevel<br>
+ << " ; After: -O" << SavedOptLevel << "\n");<br>
+ IS.OptLevel = SavedOptLevel;<br>
+ IS.TM.setOptLevel(SavedOptLevel);<br>
+ }<br>
+ };<br>
+<br>
+ //===--------------------------------------------------------------------===//<br>
/// createDefaultScheduler - This creates an instruction scheduler appropriate<br>
/// for the target.<br>
ScheduleDAGSDNodes* createDefaultScheduler(SelectionDAGISel *IS,<br>
@@ -370,6 +403,12 @@ bool SelectionDAGISel::runOnMachineFunct<br>
ST.resetSubtargetFeatures(MF);<br>
TM.resetTargetOptions(MF);<br>
<br>
+ // Reset OptLevel to None for optnone functions.<br>
+ CodeGenOpt::Level NewOptLevel = OptLevel;<br>
+ if (Fn.hasFnAttribute(Attribute::OptimizeNone))<br>
+ NewOptLevel = CodeGenOpt::None;<br>
+ OptLevelChanger OLC(*this, NewOptLevel);<br>
+<br>
DEBUG(dbgs() << "\n\n\n=== " << Fn.getName() << "\n");<br>
<br>
SplitCriticalSideEffectEdges(const_cast<Function&>(Fn), this);<br>
@@ -948,7 +987,7 @@ static void collectFailStats(const Instr<br>
void SelectionDAGISel::SelectAllBasicBlocks(const Function &Fn) {<br>
// Initialize the Fast-ISel state, if needed.<br>
FastISel *FastIS = 0;<br>
- if (TM.Options.EnableFastISel)<br>
+ if (TM.Options.EnableFastISel || Fn.hasFnAttribute(Attribute::OptimizeNone))<br>
FastIS = getTargetLowering()->createFastISel(*FuncInfo, LibInfo);<br>
<br>
// Iterate over all basic blocks in the function.<br>
<br>
Modified: llvm/trunk/lib/Target/TargetMachine.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/TargetMachine.cpp?rev=195317&r1=195316&r2=195317&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/TargetMachine.cpp?rev=195317&r1=195316&r2=195317&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Target/TargetMachine.cpp (original)<br>
+++ llvm/trunk/lib/Target/TargetMachine.cpp Thu Nov 21 00:33:32 2013<br>
@@ -164,6 +164,11 @@ CodeGenOpt::Level TargetMachine::getOptL<br>
return CodeGenInfo->getOptLevel();<br>
}<br>
<br>
+void TargetMachine::setOptLevel(CodeGenOpt::Level Level) const {<br>
+ if (CodeGenInfo)<br>
+ CodeGenInfo->setOptLevel(Level);<br>
+}<br>
+<br>
bool TargetMachine::getAsmVerbosityDefault() {<br>
return AsmVerbosityDefault;<br>
}<br>
<br>
Added: llvm/trunk/test/CodeGen/Generic/isel-optnone.ll<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/Generic/isel-optnone.ll?rev=195317&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/Generic/isel-optnone.ll?rev=195317&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/test/CodeGen/Generic/isel-optnone.ll (added)<br>
+++ llvm/trunk/test/CodeGen/Generic/isel-optnone.ll Thu Nov 21 00:33:32 2013<br>
@@ -0,0 +1,31 @@<br>
+; RUN: llc -debug < %s -o /dev/null 2>&1 | FileCheck %s<br>
+<br>
+; Verify that the backend correctly overrides the optimization level<br>
+; of optnone functions during instruction selection.<br>
+<br>
+define float @foo(float %x) #0 {<br>
+entry:<br>
+ %add = fadd fast float %x, %x<br>
+ %add1 = fadd fast float %add, %x<br>
+ ret float %add1<br>
+}<br>
+<br>
+; CHECK-NOT: Changing optimization level for Function foo<br>
+; CHECK-NOT: Restoring optimization level for Function foo<br>
+<br>
+; Function Attrs: noinline optnone<br>
+define float @fooWithOptnone(float %x) #1 {<br>
+entry:<br>
+ %add = fadd fast float %x, %x<br>
+ %add1 = fadd fast float %add, %x<br>
+ ret float %add1<br>
+}<br>
+<br>
+; CHECK: Changing optimization level for Function fooWithOptnone<br>
+; CHECK-NEXT: Before: -O2 ; After: -O0<br>
+<br>
+; CHECK: Restoring optimization level for Function fooWithOptnone<br>
+; CHECK-NEXT: Before: -O0 ; After: -O2<br>
+<br>
+attributes #0 = { "unsafe-fp-math"="true" }<br>
+attributes #1 = { noinline optnone "unsafe-fp-math"="true" }<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div>