diff --git a/include/llvm/Function.h b/include/llvm/Function.h index d47746d1610..3aef7c5da9c 100644 --- a/include/llvm/Function.h +++ b/include/llvm/Function.h @@ -159,6 +159,11 @@ public: /// const FunctionNotes &getNotes() const { return Notes; } + /// hasNote - Return true if this function has given note. + bool hasNote(FunctionNotes N) const { + return (!isDeclaration() && (Notes & N)); + } + /// setNotes - Set notes for this function /// void setNotes(const FunctionNotes P) { Notes = Notes | P;} diff --git a/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp b/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp index 678b619f7ee..aae38a04238 100644 --- a/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp +++ b/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp @@ -160,7 +160,7 @@ void X86ATTAsmPrinter::emitFunctionHeader(const MachineFunction &MF) { SwitchToTextSection(SectionName.c_str()); unsigned FnAlign = OptimizeForSize ? 1 : 4; - if (FnAlign == 4 && (F->getNotes() & FN_NOTE_OptimizeForSize)) + if (F->hasNote(FN_NOTE_OptimizeForSize)) FnAlign = 1; switch (F->getLinkage()) { default: assert(0 && "Unknown linkage type!"); diff --git a/lib/Target/X86/AsmPrinter/X86IntelAsmPrinter.cpp b/lib/Target/X86/AsmPrinter/X86IntelAsmPrinter.cpp index 25a1995ca79..12a083aa74e 100644 --- a/lib/Target/X86/AsmPrinter/X86IntelAsmPrinter.cpp +++ b/lib/Target/X86/AsmPrinter/X86IntelAsmPrinter.cpp @@ -147,7 +147,7 @@ bool X86IntelAsmPrinter::runOnMachineFunction(MachineFunction &MF) { SwitchToTextSection(getSectionForFunction(*F).c_str(), F); unsigned FnAlign = OptimizeForSize ? 1 : 4; - if (FnAlign == 4 && (F->getNotes() & FN_NOTE_OptimizeForSize)) + if (F->hasNote(FN_NOTE_OptimizeForSize)) FnAlign = 1; switch (F->getLinkage()) { default: assert(0 && "Unsupported linkage type!"); diff --git a/lib/Transforms/IPO/InlineAlways.cpp b/lib/Transforms/IPO/InlineAlways.cpp index 5568937b020..ddcc79cf59b 100644 --- a/lib/Transforms/IPO/InlineAlways.cpp +++ b/lib/Transforms/IPO/InlineAlways.cpp @@ -63,7 +63,7 @@ bool AlwaysInliner::doInitialization(CallGraph &CG) { for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) - if (!I->isDeclaration() && I->getNotes() != FN_NOTE_AlwaysInline) + if (!I->isDeclaration() && !I->hasNote(FN_NOTE_AlwaysInline)) NeverInline.insert(I); return false; diff --git a/lib/Transforms/IPO/InlineSimple.cpp b/lib/Transforms/IPO/InlineSimple.cpp index 8bc256392f2..6fb695dc18e 100644 --- a/lib/Transforms/IPO/InlineSimple.cpp +++ b/lib/Transforms/IPO/InlineSimple.cpp @@ -65,7 +65,7 @@ bool SimpleInliner::doInitialization(CallGraph &CG) { for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) - if (!I->isDeclaration() && (I->getNotes() & FN_NOTE_NoInline)) + if (I->hasNote(FN_NOTE_NoInline)) NeverInline.insert(I); // Get llvm.noinline diff --git a/lib/Transforms/IPO/Inliner.cpp b/lib/Transforms/IPO/Inliner.cpp index d9609489a9d..447bd6fb7d3 100644 --- a/lib/Transforms/IPO/Inliner.cpp +++ b/lib/Transforms/IPO/Inliner.cpp @@ -141,7 +141,7 @@ bool Inliner::runOnSCC(const std::vector &SCC) { int CurrentThreshold = InlineThreshold; Function *Fn = CS.getCaller(); - if (Fn && (Fn->getNotes() & FN_NOTE_OptimizeForSize) + if (Fn && Fn->hasNote(FN_NOTE_OptimizeForSize) && InlineThreshold != 50) { CurrentThreshold = 50; } diff --git a/lib/Transforms/Scalar/LoopUnswitch.cpp b/lib/Transforms/Scalar/LoopUnswitch.cpp index 1c4bba295bd..aa9158ed502 100644 --- a/lib/Transforms/Scalar/LoopUnswitch.cpp +++ b/lib/Transforms/Scalar/LoopUnswitch.cpp @@ -430,7 +430,7 @@ bool LoopUnswitch::UnswitchIfProfitable(Value *LoopCond, Constant *Val){ Function *F = loopHeader->getParent(); // Do not unswitch if the function is optimized for size. - if (F->getNotes() & FN_NOTE_OptimizeForSize) + if (F->hasNote(FN_NOTE_OptimizeForSize)) return false; // Check to see if it would be profitable to unswitch current loop. diff --git a/lib/Transforms/Utils/InlineCost.cpp b/lib/Transforms/Utils/InlineCost.cpp index 2eaec06b353..2a39158d24e 100644 --- a/lib/Transforms/Utils/InlineCost.cpp +++ b/lib/Transforms/Utils/InlineCost.cpp @@ -222,7 +222,7 @@ int InlineCostAnalyzer::getInlineCost(CallSite CS, if (CalleeFI.NeverInline) return 2000000000; - if (Callee->getNotes() & FN_NOTE_AlwaysInline) + if (Callee->hasNote(FN_NOTE_AlwaysInline)) return -2000000000; // Add to the inline quality for properties that make the call valuable to diff --git a/lib/VMCore/AsmWriter.cpp b/lib/VMCore/AsmWriter.cpp index daf3a31a29b..1088236c102 100644 --- a/lib/VMCore/AsmWriter.cpp +++ b/lib/VMCore/AsmWriter.cpp @@ -1407,28 +1407,37 @@ void AssemblyWriter::printFunction(const Function *F) { Out << " align " << F->getAlignment(); if (F->hasGC()) Out << " gc \"" << F->getGC() << '"'; - FunctionNotes FNotes = F->getNotes(); - if (FNotes != FN_NOTE_None) { - Out << " notes("; - bool NeedComma = false; - if (FNotes & FN_NOTE_AlwaysInline) { - NeedComma = true; - Out << "inline=always"; - } - else if (FNotes & FN_NOTE_NoInline) { - NeedComma = true; - Out << "inline=never"; - } - if (FNotes & FN_NOTE_OptimizeForSize) { - if (NeedComma) - Out << ","; - Out << "opt_size"; - } - Out << ")"; - } if (F->isDeclaration()) { Out << "\n"; } else { + + bool insideNotes = false; + if (F->hasNote(FN_NOTE_AlwaysInline)) { + Out << "notes("; + insideNotes = true; + Out << "inline=always"; + } + if (F->hasNote(FN_NOTE_NoInline)) { + if (insideNotes) + Out << ","; + else { + Out << "notes("; + insideNotes = true; + } + Out << "inline=never"; + } + if (F->hasNote(FN_NOTE_OptimizeForSize)) { + if (insideNotes) + Out << ","; + else { + Out << "notes("; + insideNotes = true; + } + Out << "opt_size"; + } + if (insideNotes) + Out << ")"; + Out << " {"; // Output all of its basic blocks... for the function