Add hasNote() to check note associated with a function.
llvm-svn: 56477
diff --git a/llvm/include/llvm/Function.h b/llvm/include/llvm/Function.h
index d47746d..3aef7c5 100644
--- a/llvm/include/llvm/Function.h
+++ b/llvm/include/llvm/Function.h
@@ -159,6 +159,11 @@
///
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/llvm/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp b/llvm/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp
index 678b619..aae38a0 100644
--- a/llvm/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp
+++ b/llvm/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp
@@ -160,7 +160,7 @@
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/llvm/lib/Target/X86/AsmPrinter/X86IntelAsmPrinter.cpp b/llvm/lib/Target/X86/AsmPrinter/X86IntelAsmPrinter.cpp
index 25a1995..12a083a 100644
--- a/llvm/lib/Target/X86/AsmPrinter/X86IntelAsmPrinter.cpp
+++ b/llvm/lib/Target/X86/AsmPrinter/X86IntelAsmPrinter.cpp
@@ -147,7 +147,7 @@
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/llvm/lib/Transforms/IPO/InlineAlways.cpp b/llvm/lib/Transforms/IPO/InlineAlways.cpp
index 5568937..ddcc79c 100644
--- a/llvm/lib/Transforms/IPO/InlineAlways.cpp
+++ b/llvm/lib/Transforms/IPO/InlineAlways.cpp
@@ -63,7 +63,7 @@
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/llvm/lib/Transforms/IPO/InlineSimple.cpp b/llvm/lib/Transforms/IPO/InlineSimple.cpp
index 8bc2563..6fb695d 100644
--- a/llvm/lib/Transforms/IPO/InlineSimple.cpp
+++ b/llvm/lib/Transforms/IPO/InlineSimple.cpp
@@ -65,7 +65,7 @@
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/llvm/lib/Transforms/IPO/Inliner.cpp b/llvm/lib/Transforms/IPO/Inliner.cpp
index d960948..447bd6f 100644
--- a/llvm/lib/Transforms/IPO/Inliner.cpp
+++ b/llvm/lib/Transforms/IPO/Inliner.cpp
@@ -141,7 +141,7 @@
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/llvm/lib/Transforms/Scalar/LoopUnswitch.cpp b/llvm/lib/Transforms/Scalar/LoopUnswitch.cpp
index 1c4bba2..aa9158e 100644
--- a/llvm/lib/Transforms/Scalar/LoopUnswitch.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopUnswitch.cpp
@@ -430,7 +430,7 @@
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/llvm/lib/Transforms/Utils/InlineCost.cpp b/llvm/lib/Transforms/Utils/InlineCost.cpp
index 2eaec06..2a39158 100644
--- a/llvm/lib/Transforms/Utils/InlineCost.cpp
+++ b/llvm/lib/Transforms/Utils/InlineCost.cpp
@@ -222,7 +222,7 @@
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/llvm/lib/VMCore/AsmWriter.cpp b/llvm/lib/VMCore/AsmWriter.cpp
index daf3a31..1088236 100644
--- a/llvm/lib/VMCore/AsmWriter.cpp
+++ b/llvm/lib/VMCore/AsmWriter.cpp
@@ -1407,28 +1407,37 @@
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