diff --git a/docs/LangRef.html b/docs/LangRef.html index 8987af254f0..24f08eb92a1 100644 --- a/docs/LangRef.html +++ b/docs/LangRef.html @@ -26,8 +26,8 @@
  • Functions
  • Aliases
  • Parameter Attributes
  • +
  • Function Attributes
  • Garbage Collector Names
  • -
  • Function Notes
  • Module-Level Inline Assembly
  • Data Layout
  • @@ -826,8 +826,8 @@ a power of 2.

    -declare i32 @printf(i8* noalias , ...) nounwind
    -declare i32 @atoi(i8*) nounwind readonly
    +declare i32 @printf(i8* noalias , ...)
    +declare i32 @atoi(i8 zeroext*)
     
    @@ -870,29 +870,9 @@ declare i32 @atoi(i8*) nounwind readonly parameter. The caller is responsible for ensuring that this is the case, usually by placing the value in a stack allocation. -
    noreturn
    -
    This function attribute indicates that the function never returns. This - indicates to LLVM that every call to this function should be treated as if - an unreachable instruction immediately followed the call.
    - -
    nounwind
    -
    This function attribute indicates that no exceptions unwind out of the - function. Usually this is because the function makes no use of exceptions, - but it may also be that the function catches any exceptions thrown when - executing it.
    -
    nest
    This indicates that the pointer parameter can be excised using the trampoline intrinsics.
    -
    readonly
    -
    This function attribute indicates that the function has no side-effects - except for producing a return value or throwing an exception. The value - returned must only depend on the function arguments and/or global variables. - It may use values obtained by dereferencing pointers.
    -
    readnone
    -
    A readnone function has the same restrictions as a readonly - function, but in addition it is not allowed to dereference any pointer arguments - or global variables. @@ -916,38 +896,65 @@ the named garbage collection algorithm.

    - Function Notes + Function Attributes
    -

    The function definition may list function notes which are used by -various passes.

    + +

    Function attributes are set to communicate additional information about + a function. Function attributes are considered to be part of the function, + not of the function type, so functions with different parameter attributes + can have the same function type.

    + +

    Function attributes are simple keywords that follow the type specified. If + multiple attributes are needed, they are space separated. For + example:

    -define void @f() notes(inline=Always) { ... }
    -define void @f() notes(inline=Always,opt-size) { ... }
    -define void @f() notes(inline=Never,opt-size) { ... }
    -define void @f() notes(opt-size) { ... }
    +define void @f() noinline { ... }
    +define void @f() alwaysinline { ... }
    +define void @f() alwaysinline optsize { ... }
    +define void @f() optsize
     
    -
    inline=Always
    -
    This note requests inliner to inline this function irrespective of inlining -size threshold for this function.
    +
    alwaysinline
    +
    This attribute requests inliner to inline this function irrespective of +inlining size threshold for this function.
    -
    inline=Never
    -
    This note requests inliner to never inline this function in any situation. -This note may not be used together with inline=Always note.
    +
    noinline
    +
    This attributes requests inliner to never inline this function in any +situation. This attribute may not be used together with alwaysinline + attribute.
    -
    opt-size
    -
    This note suggests optimization passes and code generator passes to make -choices that help reduce code size.
    +
    optsize
    +
    This attribute suggests optimization passes and code generator passes to +make choices that help reduce code size.
    +
    noreturn
    +
    This function attribute indicates that the function never returns. This + indicates to LLVM that every call to this function should be treated as if + an unreachable instruction immediately followed the call.
    + +
    nounwind
    +
    This function attribute indicates that no exceptions unwind out of the + function. Usually this is because the function makes no use of exceptions, + but it may also be that the function catches any exceptions thrown when + executing it.
    + +
    readonly
    +
    This function attribute indicates that the function has no side-effects + except for producing a return value or throwing an exception. The value + returned must only depend on the function arguments and/or global variables. + It may use values obtained by dereferencing pointers.
    +
    readnone
    +
    A readnone function has the same restrictions as a readonly + function, but in addition it is not allowed to dereference any pointer arguments + or global variables.
    -

    Any notes that are not documented here are considered invalid notes.

    diff --git a/include/llvm/Function.h b/include/llvm/Function.h index 19ff2bf4da5..3beda6e2892 100644 --- a/include/llvm/Function.h +++ b/include/llvm/Function.h @@ -149,16 +149,16 @@ public: void setAttributes(const AttrListPtr &attrs) { AttributeList = attrs; } - /// hasNote - Return true if this function has given note. - bool hasNote(Attributes N) const { - // Notes are stored at ~0 index in parameter attribute list - return (paramHasAttr(~0, N)); + /// hasFnAttr - Return true if this function has given attribute. + bool hasFnAttr(Attributes N) const { + // Function Attributes are stored at ~0 index + return AttributeList.paramHasAttr(~0U, N); } - /// setNotes - Set notes for this function + /// addFnAttr - Add function attributes /// - void setNotes(const Attributes N) { - // Notes are stored at ~0 index in parameter attribute list + void addFnAttr(const Attributes N) { + // Function Attributes are stored at ~0 index addAttribute(~0, N); } diff --git a/lib/AsmParser/LLLexer.cpp b/lib/AsmParser/LLLexer.cpp index 16f4e158f57..39d62bf71cf 100644 --- a/lib/AsmParser/LLLexer.cpp +++ b/lib/AsmParser/LLLexer.cpp @@ -496,11 +496,9 @@ int LLLexer::LexIdentifier() { KEYWORD("readnone", READNONE); KEYWORD("readonly", READONLY); - KEYWORD("notes", FNNOTE); - KEYWORD("inline", INLINE); - KEYWORD("always", ALWAYS); - KEYWORD("never", NEVER); - KEYWORD("opt_size", OPTIMIZEFORSIZE); + KEYWORD("noinline", NOINLINE); + KEYWORD("alwaysinline", ALWAYSINLINE); + KEYWORD("optsize", OPTSIZE); KEYWORD("type", TYPE); KEYWORD("opaque", OPAQUE); diff --git a/lib/AsmParser/llvmAsmParser.h.cvs b/lib/AsmParser/llvmAsmParser.h.cvs index 59f18ddadb7..6caebc88a6e 100644 --- a/lib/AsmParser/llvmAsmParser.h.cvs +++ b/lib/AsmParser/llvmAsmParser.h.cvs @@ -189,14 +189,12 @@ READNONE = 405, READONLY = 406, GC = 407, - FNNOTE = 408, - INLINE = 409, - ALWAYS = 410, - NEVER = 411, - OPTIMIZEFORSIZE = 412, - DEFAULT = 413, - HIDDEN = 414, - PROTECTED = 415 + OPTSIZE = 408, + NOINLINE = 409, + ALWAYSINLINE = 410, + DEFAULT = 411, + HIDDEN = 412, + PROTECTED = 413 }; #endif /* Tokens. */ @@ -350,21 +348,19 @@ #define READNONE 405 #define READONLY 406 #define GC 407 -#define FNNOTE 408 -#define INLINE 409 -#define ALWAYS 410 -#define NEVER 411 -#define OPTIMIZEFORSIZE 412 -#define DEFAULT 413 -#define HIDDEN 414 -#define PROTECTED 415 +#define OPTSIZE 408 +#define NOINLINE 409 +#define ALWAYSINLINE 410 +#define DEFAULT 411 +#define HIDDEN 412 +#define PROTECTED 413 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED typedef union YYSTYPE -#line 970 "/Volumes/MacOS9/gcc/llvm/lib/AsmParser/llvmAsmParser.y" +#line 970 "/Volumes/Nanpura/mainline/llvm/lib/AsmParser/llvmAsmParser.y" { llvm::Module *ModuleVal; llvm::Function *FunctionVal; @@ -413,7 +409,7 @@ typedef union YYSTYPE llvm::FCmpInst::Predicate FPredicate; } /* Line 1529 of yacc.c. */ -#line 417 "llvmAsmParser.tab.h" +#line 413 "llvmAsmParser.tab.h" YYSTYPE; # define yystype YYSTYPE /* obsolescent; will be withdrawn */ # define YYSTYPE_IS_DECLARED 1 diff --git a/lib/AsmParser/llvmAsmParser.y b/lib/AsmParser/llvmAsmParser.y index a049cea8d85..fa86c1887e9 100644 --- a/lib/AsmParser/llvmAsmParser.y +++ b/lib/AsmParser/llvmAsmParser.y @@ -1089,8 +1089,6 @@ Module *llvm::RunVMAsmParser(llvm::MemoryBuffer *MB) { %type OptCallingConv LocalNumber %type OptAttributes Attribute %type OptFuncAttrs FuncAttr -%type OptFuncNotes FuncNote -%type FuncNoteList // Basic Block Terminating Operators %token RET BR SWITCH INVOKE UNWIND UNREACHABLE @@ -1122,10 +1120,7 @@ Module *llvm::RunVMAsmParser(llvm::MemoryBuffer *MB) { // Function Attributes %token SIGNEXT ZEROEXT NORETURN INREG SRET NOUNWIND NOALIAS BYVAL NEST -%token READNONE READONLY GC - -// Function Notes -%token FNNOTE INLINE ALWAYS NEVER OPTIMIZEFORSIZE +%token READNONE READONLY GC OPTSIZE NOINLINE ALWAYSINLINE // Visibility Styles %token DEFAULT HIDDEN PROTECTED @@ -1284,6 +1279,9 @@ FuncAttr : NORETURN { $$ = Attribute::NoReturn; } | SIGNEXT { $$ = Attribute::SExt; } | READNONE { $$ = Attribute::ReadNone; } | READONLY { $$ = Attribute::ReadOnly; } + | NOINLINE { $$ = Attribute::NoInline } + | ALWAYSINLINE { $$ = Attribute::AlwaysInline } + | OPTSIZE { $$ = Attribute::OptimizeForSize } ; OptFuncAttrs : /* empty */ { $$ = Attribute::None; } @@ -1292,31 +1290,6 @@ OptFuncAttrs : /* empty */ { $$ = Attribute::None; } } ; -FuncNoteList : FuncNote { $$ = $1; } - | FuncNoteList ',' FuncNote { - unsigned tmp = $1 | $3; - if ($3 == Attribute::NoInline - && ($1 & Attribute::AlwaysInline)) - GEN_ERROR("Function Notes may include only one inline notes!") - if ($3 == Attribute::AlwaysInline - && ($1 & Attribute::NoInline)) - GEN_ERROR("Function Notes may include only one inline notes!") - $$ = tmp; - CHECK_FOR_ERROR - } - ; - -FuncNote : INLINE '=' NEVER { $$ = Attribute::NoInline; } - | INLINE '=' ALWAYS { $$ = Attribute::AlwaysInline; } - | OPTIMIZEFORSIZE { $$ = Attribute::OptimizeForSize; } - ; - -OptFuncNotes : /* empty */ { $$ = Attribute::None; } - | FNNOTE '(' FuncNoteList ')' { - $$ = $3; - } - ; - OptGC : /* empty */ { $$ = 0; } | GC STRINGCONSTANT { $$ = $2; @@ -2332,7 +2305,7 @@ ArgList : ArgListH { }; FunctionHeaderH : OptCallingConv ResultTypes GlobalName '(' ArgList ')' - OptFuncAttrs OptSection OptAlign OptGC OptFuncNotes { + OptFuncAttrs OptSection OptAlign OptGC { std::string FunctionName(*$3); delete $3; // Free strdup'd memory! @@ -2453,9 +2426,6 @@ FunctionHeaderH : OptCallingConv ResultTypes GlobalName '(' ArgList ')' Fn->setGC($10->c_str()); delete $10; } - if ($11) { - Fn->setNotes($11); - } // Add all of the arguments we parsed to the function... if ($5) { // Is null if empty... diff --git a/lib/AsmParser/llvmAsmParser.y.cvs b/lib/AsmParser/llvmAsmParser.y.cvs index a049cea8d85..fa86c1887e9 100644 --- a/lib/AsmParser/llvmAsmParser.y.cvs +++ b/lib/AsmParser/llvmAsmParser.y.cvs @@ -1089,8 +1089,6 @@ Module *llvm::RunVMAsmParser(llvm::MemoryBuffer *MB) { %type OptCallingConv LocalNumber %type OptAttributes Attribute %type OptFuncAttrs FuncAttr -%type OptFuncNotes FuncNote -%type FuncNoteList // Basic Block Terminating Operators %token RET BR SWITCH INVOKE UNWIND UNREACHABLE @@ -1122,10 +1120,7 @@ Module *llvm::RunVMAsmParser(llvm::MemoryBuffer *MB) { // Function Attributes %token SIGNEXT ZEROEXT NORETURN INREG SRET NOUNWIND NOALIAS BYVAL NEST -%token READNONE READONLY GC - -// Function Notes -%token FNNOTE INLINE ALWAYS NEVER OPTIMIZEFORSIZE +%token READNONE READONLY GC OPTSIZE NOINLINE ALWAYSINLINE // Visibility Styles %token DEFAULT HIDDEN PROTECTED @@ -1284,6 +1279,9 @@ FuncAttr : NORETURN { $$ = Attribute::NoReturn; } | SIGNEXT { $$ = Attribute::SExt; } | READNONE { $$ = Attribute::ReadNone; } | READONLY { $$ = Attribute::ReadOnly; } + | NOINLINE { $$ = Attribute::NoInline } + | ALWAYSINLINE { $$ = Attribute::AlwaysInline } + | OPTSIZE { $$ = Attribute::OptimizeForSize } ; OptFuncAttrs : /* empty */ { $$ = Attribute::None; } @@ -1292,31 +1290,6 @@ OptFuncAttrs : /* empty */ { $$ = Attribute::None; } } ; -FuncNoteList : FuncNote { $$ = $1; } - | FuncNoteList ',' FuncNote { - unsigned tmp = $1 | $3; - if ($3 == Attribute::NoInline - && ($1 & Attribute::AlwaysInline)) - GEN_ERROR("Function Notes may include only one inline notes!") - if ($3 == Attribute::AlwaysInline - && ($1 & Attribute::NoInline)) - GEN_ERROR("Function Notes may include only one inline notes!") - $$ = tmp; - CHECK_FOR_ERROR - } - ; - -FuncNote : INLINE '=' NEVER { $$ = Attribute::NoInline; } - | INLINE '=' ALWAYS { $$ = Attribute::AlwaysInline; } - | OPTIMIZEFORSIZE { $$ = Attribute::OptimizeForSize; } - ; - -OptFuncNotes : /* empty */ { $$ = Attribute::None; } - | FNNOTE '(' FuncNoteList ')' { - $$ = $3; - } - ; - OptGC : /* empty */ { $$ = 0; } | GC STRINGCONSTANT { $$ = $2; @@ -2332,7 +2305,7 @@ ArgList : ArgListH { }; FunctionHeaderH : OptCallingConv ResultTypes GlobalName '(' ArgList ')' - OptFuncAttrs OptSection OptAlign OptGC OptFuncNotes { + OptFuncAttrs OptSection OptAlign OptGC { std::string FunctionName(*$3); delete $3; // Free strdup'd memory! @@ -2453,9 +2426,6 @@ FunctionHeaderH : OptCallingConv ResultTypes GlobalName '(' ArgList ')' Fn->setGC($10->c_str()); delete $10; } - if ($11) { - Fn->setNotes($11); - } // Add all of the arguments we parsed to the function... if ($5) { // Is null if empty... diff --git a/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp b/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp index eb66a4fc611..6e596b48db7 100644 --- a/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp +++ b/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp @@ -154,7 +154,7 @@ void X86ATTAsmPrinter::emitFunctionHeader(const MachineFunction &MF) { SwitchToSection(TAI->SectionForGlobal(F)); unsigned FnAlign = OptimizeForSize ? 1 : 4; - if (!F->isDeclaration() && F->hasNote(Attribute::OptimizeForSize)) + if (!F->isDeclaration() && F->hasFnAttr(Attribute::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 d2521d00d0c..c8199c59cfb 100644 --- a/lib/Target/X86/AsmPrinter/X86IntelAsmPrinter.cpp +++ b/lib/Target/X86/AsmPrinter/X86IntelAsmPrinter.cpp @@ -141,7 +141,7 @@ bool X86IntelAsmPrinter::runOnMachineFunction(MachineFunction &MF) { SwitchToTextSection("_text", F); unsigned FnAlign = OptimizeForSize ? 1 : 4; - if (!F->isDeclaration() && F->hasNote(Attribute::OptimizeForSize)) + if (!F->isDeclaration() && F->hasFnAttr(Attribute::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 448f2461411..1079c4ad738 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->hasNote(Attribute::AlwaysInline)) + if (!I->isDeclaration() && !I->hasFnAttr(Attribute::AlwaysInline)) NeverInline.insert(I); return false; diff --git a/lib/Transforms/IPO/InlineSimple.cpp b/lib/Transforms/IPO/InlineSimple.cpp index b19494a6a41..02cae2a6e67 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->hasNote(Attribute::NoInline)) + if (!I->isDeclaration() && I->hasFnAttr(Attribute::NoInline)) NeverInline.insert(I); // Get llvm.noinline diff --git a/lib/Transforms/IPO/Inliner.cpp b/lib/Transforms/IPO/Inliner.cpp index abc10944141..c2672720040 100644 --- a/lib/Transforms/IPO/Inliner.cpp +++ b/lib/Transforms/IPO/Inliner.cpp @@ -141,7 +141,8 @@ bool Inliner::runOnSCC(const std::vector &SCC) { int CurrentThreshold = InlineThreshold; Function *Fn = CS.getCaller(); - if (Fn && !Fn->isDeclaration() && Fn->hasNote(Attribute::OptimizeForSize) + if (Fn && !Fn->isDeclaration() + && Fn->hasFnAttr(Attribute::OptimizeForSize) && InlineThreshold != 50) { CurrentThreshold = 50; } diff --git a/lib/Transforms/Scalar/LoopUnswitch.cpp b/lib/Transforms/Scalar/LoopUnswitch.cpp index 15eaa786bea..fbfe2977278 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->isDeclaration() && F->hasNote(Attribute::OptimizeForSize)) + if (!F->isDeclaration() && F->hasFnAttr(Attribute::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 55755c1995e..d0b51855d9c 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->isDeclaration() && Callee->hasNote(Attribute::AlwaysInline)) + if (!Callee->isDeclaration() && Callee->hasFnAttr(Attribute::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 e1869859ec2..14c827452a7 100644 --- a/lib/VMCore/AsmWriter.cpp +++ b/lib/VMCore/AsmWriter.cpp @@ -1413,34 +1413,6 @@ void AssemblyWriter::printFunction(const Function *F) { if (F->isDeclaration()) { Out << "\n"; } else { - - bool insideNotes = false; - if (F->hasNote(Attribute::AlwaysInline)) { - Out << " notes("; - insideNotes = true; - Out << "inline=always"; - } - if (F->hasNote(Attribute::NoInline)) { - if (insideNotes) - Out << ","; - else { - Out << " notes("; - insideNotes = true; - } - Out << "inline=never"; - } - if (F->hasNote(Attribute::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 diff --git a/test/CodeGen/ARM/fpow.ll b/test/CodeGen/ARM/fpow.ll index 02a895bf96c..155763c9847 100644 --- a/test/CodeGen/ARM/fpow.ll +++ b/test/CodeGen/ARM/fpow.ll @@ -1,7 +1,7 @@ ; RUN: llvm-as < %s | llc -march=arm ; RUN: llvm-as < %s | llc -march=thumb -define double @t(double %x, double %y) nounwind notes(opt_size) { +define double @t(double %x, double %y) nounwind optsize { entry: %0 = tail call double @llvm.pow.f64( double %x, double %y ) ; [#uses=1] ret double %0 diff --git a/test/Transforms/Inline/2008-09-02-AlwaysInline.ll b/test/Transforms/Inline/2008-09-02-AlwaysInline.ll index 188d4c9470e..b42e559c5af 100644 --- a/test/Transforms/Inline/2008-09-02-AlwaysInline.ll +++ b/test/Transforms/Inline/2008-09-02-AlwaysInline.ll @@ -1,6 +1,6 @@ ; RUN: llvm-as < %s | opt -inline-threshold=0 -inline | llvm-dis | not grep call -define i32 @fn2() notes(inline=always) { +define i32 @fn2() alwaysinline { ret i32 1 } diff --git a/test/Transforms/Inline/2008-09-02-NoInline.ll b/test/Transforms/Inline/2008-09-02-NoInline.ll index 1d37b08ac78..35b4b4678b7 100644 --- a/test/Transforms/Inline/2008-09-02-NoInline.ll +++ b/test/Transforms/Inline/2008-09-02-NoInline.ll @@ -1,6 +1,6 @@ ; RUN: llvm-as < %s | opt -inline | llvm-dis | grep call | count 1 -define i32 @fn2() notes(inline=never) { +define i32 @fn2() noinline { ret i32 1 }