llvm.org GIT mirror llvm / 54075bb
Merging r195339: ------------------------------------------------------------------------ r195339 | chapuni | 2013-11-21 02:55:15 -0800 (Thu, 21 Nov 2013) | 5 lines Revert r195317 (and r195333), "Teach ISel not to optimize 'optnone' functions." It broke, at least, i686 target. It is reproducible with "llc -mtriple=i686-unknown". FYI, it didn't appear to add either "-O0" or "-fast-isel". ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_34@195375 91177308-0d34-0410-b5e6-96231b3b80d8 Bill Wendling 6 years ago
5 changed file(s) with 2 addition(s) and 85 deletion(s). Raw diff Collapse all Expand all
4141 CodeModel::Model getCodeModel() const { return CMModel; }
4242
4343 CodeGenOpt::Level getOptLevel() const { return OptLevel; }
44
45 // Allow overriding OptLevel on a per-function basis.
46 void setOptLevel(CodeGenOpt::Level Level) { OptLevel = Level; }
4744 };
4845 } // namespace llvm
4946
7474 std::string TargetFS;
7575
7676 /// CodeGenInfo - Low level target information such as relocation model.
77 /// Non-const to allow resetting optimization level per-function.
78 MCCodeGenInfo *CodeGenInfo;
77 const MCCodeGenInfo *CodeGenInfo;
7978
8079 /// AsmInfo - Contains target specific asm information.
8180 ///
213212 /// Default, or Aggressive.
214213 CodeGenOpt::Level getOptLevel() const;
215214
216 /// \brief Overrides the optimization level.
217 void setOptLevel(CodeGenOpt::Level Level) const;
218
219215 void setFastISel(bool Enable) { Options.EnableFastISel = Enable; }
220216
221217 bool shouldPrintMachineCode() const { return Options.PrintMachineCode; }
222222
223223 namespace llvm {
224224 //===--------------------------------------------------------------------===//
225 /// \brief This struct is used by SelectionDAGISel to temporarily override
226 /// the optimization level on a per-function basis.
227 class OptLevelChanger {
228 SelectionDAGISel &IS;
229 CodeGenOpt::Level SavedOptLevel;
230
231 public:
232 OptLevelChanger(SelectionDAGISel &ISel,
233 CodeGenOpt::Level NewOptLevel) : IS(ISel) {
234 SavedOptLevel = IS.OptLevel;
235 if (NewOptLevel == SavedOptLevel)
236 return;
237 IS.OptLevel = NewOptLevel;
238 IS.TM.setOptLevel(NewOptLevel);
239 DEBUG(dbgs() << "\nChanging optimization level for Function "
240 << IS.MF->getFunction()->getName() << "\n");
241 DEBUG(dbgs() << "\tBefore: -O" << SavedOptLevel
242 << " ; After: -O" << NewOptLevel << "\n");
243 }
244
245 ~OptLevelChanger() {
246 if (IS.OptLevel == SavedOptLevel)
247 return;
248 DEBUG(dbgs() << "\nRestoring optimization level for Function "
249 << IS.MF->getFunction()->getName() << "\n");
250 DEBUG(dbgs() << "\tBefore: -O" << IS.OptLevel
251 << " ; After: -O" << SavedOptLevel << "\n");
252 IS.OptLevel = SavedOptLevel;
253 IS.TM.setOptLevel(SavedOptLevel);
254 }
255 };
256
257 //===--------------------------------------------------------------------===//
258225 /// createDefaultScheduler - This creates an instruction scheduler appropriate
259226 /// for the target.
260227 ScheduleDAGSDNodes* createDefaultScheduler(SelectionDAGISel *IS,
400367 const_cast(TM.getSubtarget());
401368 ST.resetSubtargetFeatures(MF);
402369 TM.resetTargetOptions(MF);
403
404 // Reset OptLevel to None for optnone functions.
405 CodeGenOpt::Level NewOptLevel = OptLevel;
406 if (Fn.hasFnAttribute(Attribute::OptimizeNone))
407 NewOptLevel = CodeGenOpt::None;
408 OptLevelChanger OLC(*this, NewOptLevel);
409370
410371 DEBUG(dbgs() << "\n\n\n=== " << Fn.getName() << "\n");
411372
984945 void SelectionDAGISel::SelectAllBasicBlocks(const Function &Fn) {
985946 // Initialize the Fast-ISel state, if needed.
986947 FastISel *FastIS = 0;
987 if (TM.Options.EnableFastISel || Fn.hasFnAttribute(Attribute::OptimizeNone))
948 if (TM.Options.EnableFastISel)
988949 FastIS = getTargetLowering()->createFastISel(*FuncInfo, LibInfo);
989950
990951 // Iterate over all basic blocks in the function.
163163 return CodeGenInfo->getOptLevel();
164164 }
165165
166 void TargetMachine::setOptLevel(CodeGenOpt::Level Level) const {
167 if (CodeGenInfo)
168 CodeGenInfo->setOptLevel(Level);
169 }
170
171166 bool TargetMachine::getAsmVerbosityDefault() {
172167 return AsmVerbosityDefault;
173168 }
+0
-32
test/CodeGen/Generic/isel-optnone.ll less more
None ; RUN: llc -debug < %s -o /dev/null 2>&1 | FileCheck %s
1 ; REQUIRES: asserts
2
3 ; Verify that the backend correctly overrides the optimization level
4 ; of optnone functions during instruction selection.
5
6 define float @foo(float %x) #0 {
7 entry:
8 %add = fadd fast float %x, %x
9 %add1 = fadd fast float %add, %x
10 ret float %add1
11 }
12
13 ; CHECK-NOT: Changing optimization level for Function foo
14 ; CHECK-NOT: Restoring optimization level for Function foo
15
16 ; Function Attrs: noinline optnone
17 define float @fooWithOptnone(float %x) #1 {
18 entry:
19 %add = fadd fast float %x, %x
20 %add1 = fadd fast float %add, %x
21 ret float %add1
22 }
23
24 ; CHECK: Changing optimization level for Function fooWithOptnone
25 ; CHECK-NEXT: Before: -O2 ; After: -O0
26
27 ; CHECK: Restoring optimization level for Function fooWithOptnone
28 ; CHECK-NEXT: Before: -O0 ; After: -O2
29
30 attributes #0 = { "unsafe-fp-math"="true" }
31 attributes #1 = { noinline optnone "unsafe-fp-math"="true" }