Add hasNote() to check note associated with a function.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@56477 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Devang Patel 2008-09-22 22:32:29 +00:00
parent ef901c5756
commit f3ba70861c
9 changed files with 40 additions and 26 deletions

View File

@ -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;}

View File

@ -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!");

View File

@ -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!");

View File

@ -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;

View File

@ -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

View File

@ -141,7 +141,7 @@ bool Inliner::runOnSCC(const std::vector<CallGraphNode*> &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;
}

View File

@ -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.

View File

@ -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

View File

@ -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