static int getListOffset();
};
-typedef unsigned FunctionNotes;
-const FunctionNotes FN_NOTE_None = 0;
-const FunctionNotes FN_NOTE_NoInline = 1<<0;
-const FunctionNotes FN_NOTE_AlwaysInline = 1<<1;
-const FunctionNotes FN_NOTE_OptimizeForSize = 1<<2;
-
class Function : public GlobalValue, public Annotable,
public ilist_node<Function> {
public:
mutable ArgumentListType ArgumentList; ///< The formal arguments
ValueSymbolTable *SymTab; ///< Symbol table of args/instructions
PAListPtr ParamAttrs; ///< Parameter attributes
- FunctionNotes Notes; ///< Function properties
// The Calling Convention is stored in Value::SubclassData.
/*unsigned CallingConvention;*/
///
void setParamAttrs(const PAListPtr &attrs) { ParamAttrs = attrs; }
- /// getNotes - Return function notes
- ///
- const FunctionNotes &getNotes() const { return Notes; }
/// hasNote - Return true if this function has given note.
- bool hasNote(FunctionNotes N) const {
- return (!isDeclaration() && (Notes & N));
+ bool hasNote(ParameterAttributes N) const {
+ // Notes are stored at ~0 index in parameter attribute list
+ return (!isDeclaration() && paramHasAttr(~0, N));
}
/// setNotes - Set notes for this function
///
- void setNotes(const FunctionNotes P) { Notes = Notes | P;}
+ void setNotes(const ParameterAttributes N) {
+ // Notes are stored at ~0 index in parameter attribute list
+ addParamAttr(~0, N);
+ }
/// hasGC/getGC/setGC/clearGC - The name of the garbage collection algorithm
/// to use during code generation.
const Attributes ReadOnly = 1<<10; ///< Function only reads from memory
const Attributes Alignment = 0xffff<<16; ///< Alignment of parameter (16 bits)
// 0 = unknown, else in clear (not log)
+
+/// Function notes are implemented as attributes stored at index ~0 in
+/// parameter attribute list.
+const Attributes FN_NOTE_None = 0;
+const Attributes FN_NOTE_NoInline = 1<<0; // inline=never
+const Attributes FN_NOTE_AlwaysInline = 1<<1; // inline=always
+const Attributes FN_NOTE_OptimizeForSize = 1<<2; // opt_size
/// @brief Attributes that only apply to function parameters.
const Attributes ParameterOnly = ByVal | Nest | StructRet;
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
typedef union YYSTYPE
-#line 970 "/Users/sabre/llvm/lib/AsmParser/llvmAsmParser.y"
+#line 970 "/Volumes/Nanpura/mainline/llvm/lib/AsmParser/llvmAsmParser.y"
{
llvm::Module *ModuleVal;
llvm::Function *FunctionVal;
llvm::GlobalValue::LinkageTypes Linkage;
llvm::GlobalValue::VisibilityTypes Visibility;
llvm::ParameterAttributes ParamAttrs;
- llvm::FunctionNotes FunctionNotes;
+ llvm::ParameterAttributes FunctionNotes;
llvm::APInt *APIntVal;
int64_t SInt64Val;
uint64_t UInt64Val;
llvm::GlobalValue::LinkageTypes Linkage;
llvm::GlobalValue::VisibilityTypes Visibility;
llvm::ParameterAttributes ParamAttrs;
- llvm::FunctionNotes FunctionNotes;
+ llvm::ParameterAttributes FunctionNotes;
llvm::APInt *APIntVal;
int64_t SInt64Val;
uint64_t UInt64Val;
%type <UIntVal> OptCallingConv LocalNumber
%type <ParamAttrs> OptParamAttrs ParamAttr
%type <ParamAttrs> OptFuncAttrs FuncAttr
-%type <FunctionNotes> OptFuncNotes FuncNote
-%type <FunctionNotes> FuncNoteList
+%type <ParamAttrs> OptFuncNotes FuncNote
+%type <ParamAttrs> FuncNoteList
// Basic Block Terminating Operators
%token <TermOpVal> RET BR SWITCH INVOKE UNWIND UNREACHABLE
FuncNoteList : FuncNote { $$ = $1; }
| FuncNoteList ',' FuncNote {
- FunctionNotes tmp = $1 | $3;
- if ($3 == FN_NOTE_NoInline && ($1 & FN_NOTE_AlwaysInline))
+ unsigned tmp = $1 | $3;
+ if ($3 == ParamAttr::FN_NOTE_NoInline
+ && ($1 & ParamAttr::FN_NOTE_AlwaysInline))
GEN_ERROR("Function Notes may include only one inline notes!")
- if ($3 == FN_NOTE_AlwaysInline && ($1 & FN_NOTE_NoInline))
+ if ($3 == ParamAttr::FN_NOTE_AlwaysInline
+ && ($1 & ParamAttr::FN_NOTE_NoInline))
GEN_ERROR("Function Notes may include only one inline notes!")
$$ = tmp;
CHECK_FOR_ERROR
}
;
-FuncNote : INLINE '=' NEVER { $$ = FN_NOTE_NoInline; }
- | INLINE '=' ALWAYS { $$ = FN_NOTE_AlwaysInline; }
- | OPTIMIZEFORSIZE { $$ = FN_NOTE_OptimizeForSize; }
+FuncNote : INLINE '=' NEVER { $$ = ParamAttr::FN_NOTE_NoInline; }
+ | INLINE '=' ALWAYS { $$ = ParamAttr::FN_NOTE_AlwaysInline; }
+ | OPTIMIZEFORSIZE { $$ = ParamAttr::FN_NOTE_OptimizeForSize; }
;
-OptFuncNotes : /* empty */ { $$ = FN_NOTE_None; }
+OptFuncNotes : /* empty */ { $$ = ParamAttr::FN_NOTE_None; }
| FNNOTE '(' FuncNoteList ')' {
$$ = $3;
}
llvm::GlobalValue::LinkageTypes Linkage;
llvm::GlobalValue::VisibilityTypes Visibility;
llvm::ParameterAttributes ParamAttrs;
- llvm::FunctionNotes FunctionNotes;
+ llvm::ParameterAttributes FunctionNotes;
llvm::APInt *APIntVal;
int64_t SInt64Val;
uint64_t UInt64Val;
%type <UIntVal> OptCallingConv LocalNumber
%type <ParamAttrs> OptParamAttrs ParamAttr
%type <ParamAttrs> OptFuncAttrs FuncAttr
-%type <FunctionNotes> OptFuncNotes FuncNote
-%type <FunctionNotes> FuncNoteList
+%type <ParamAttrs> OptFuncNotes FuncNote
+%type <ParamAttrs> FuncNoteList
// Basic Block Terminating Operators
%token <TermOpVal> RET BR SWITCH INVOKE UNWIND UNREACHABLE
FuncNoteList : FuncNote { $$ = $1; }
| FuncNoteList ',' FuncNote {
- FunctionNotes tmp = $1 | $3;
- if ($3 == FN_NOTE_NoInline && ($1 & FN_NOTE_AlwaysInline))
+ unsigned tmp = $1 | $3;
+ if ($3 == ParamAttr::FN_NOTE_NoInline
+ && ($1 & ParamAttr::FN_NOTE_AlwaysInline))
GEN_ERROR("Function Notes may include only one inline notes!")
- if ($3 == FN_NOTE_AlwaysInline && ($1 & FN_NOTE_NoInline))
+ if ($3 == ParamAttr::FN_NOTE_AlwaysInline
+ && ($1 & ParamAttr::FN_NOTE_NoInline))
GEN_ERROR("Function Notes may include only one inline notes!")
$$ = tmp;
CHECK_FOR_ERROR
}
;
-FuncNote : INLINE '=' NEVER { $$ = FN_NOTE_NoInline; }
- | INLINE '=' ALWAYS { $$ = FN_NOTE_AlwaysInline; }
- | OPTIMIZEFORSIZE { $$ = FN_NOTE_OptimizeForSize; }
+FuncNote : INLINE '=' NEVER { $$ = ParamAttr::FN_NOTE_NoInline; }
+ | INLINE '=' ALWAYS { $$ = ParamAttr::FN_NOTE_AlwaysInline; }
+ | OPTIMIZEFORSIZE { $$ = ParamAttr::FN_NOTE_OptimizeForSize; }
;
-OptFuncNotes : /* empty */ { $$ = FN_NOTE_None; }
+OptFuncNotes : /* empty */ { $$ = ParamAttr::FN_NOTE_None; }
| FNNOTE '(' FuncNoteList ')' {
$$ = $3;
}
return Error("Invalid GC ID");
Func->setGC(GCTable[Record[8]-1].c_str());
}
- if (!isProto && Record.size() > 9 && Record[9]) {
- Func->setNotes(Record[9]);
- }
-
ValueList.push_back(Func);
// If this is a function with a body, remember the prototype we are
Vals.push_back(F->hasSection() ? SectionMap[F->getSection()] : 0);
Vals.push_back(getEncodedVisibility(F));
Vals.push_back(F->hasGC() ? GCMap[F->getGC()] : 0);
- Vals.push_back(F->getNotes());
unsigned AbbrevToUse = 0;
Stream.EmitRecord(bitc::MODULE_CODE_FUNCTION, Vals, AbbrevToUse);
SwitchToTextSection(SectionName.c_str());
unsigned FnAlign = OptimizeForSize ? 1 : 4;
- if (F->hasNote(FN_NOTE_OptimizeForSize))
+ if (F->hasNote(ParamAttr::FN_NOTE_OptimizeForSize))
FnAlign = 1;
switch (F->getLinkage()) {
default: assert(0 && "Unknown linkage type!");
SwitchToTextSection(getSectionForFunction(*F).c_str(), F);
unsigned FnAlign = OptimizeForSize ? 1 : 4;
- if (F->hasNote(FN_NOTE_OptimizeForSize))
+ if (F->hasNote(ParamAttr::FN_NOTE_OptimizeForSize))
FnAlign = 1;
switch (F->getLinkage()) {
default: assert(0 && "Unsupported linkage type!");
for (Module::iterator I = M.begin(), E = M.end();
I != E; ++I)
- if (!I->isDeclaration() && !I->hasNote(FN_NOTE_AlwaysInline))
+ if (!I->isDeclaration() && !I->hasNote(ParamAttr::FN_NOTE_AlwaysInline))
NeverInline.insert(I);
return false;
for (Module::iterator I = M.begin(), E = M.end();
I != E; ++I)
- if (I->hasNote(FN_NOTE_NoInline))
+ if (I->hasNote(ParamAttr::FN_NOTE_NoInline))
NeverInline.insert(I);
// Get llvm.noinline
int CurrentThreshold = InlineThreshold;
Function *Fn = CS.getCaller();
- if (Fn && Fn->hasNote(FN_NOTE_OptimizeForSize)
+ if (Fn && Fn->hasNote(ParamAttr::FN_NOTE_OptimizeForSize)
&& InlineThreshold != 50) {
CurrentThreshold = 50;
}
Function *F = loopHeader->getParent();
// Do not unswitch if the function is optimized for size.
- if (F->hasNote(FN_NOTE_OptimizeForSize))
+ if (F->hasNote(ParamAttr::FN_NOTE_OptimizeForSize))
return false;
// Check to see if it would be profitable to unswitch current loop.
if (CalleeFI.NeverInline)
return 2000000000;
- if (Callee->hasNote(FN_NOTE_AlwaysInline))
+ if (Callee->hasNote(ParamAttr::FN_NOTE_AlwaysInline))
return -2000000000;
// Add to the inline quality for properties that make the call valuable to
} else {
bool insideNotes = false;
- if (F->hasNote(FN_NOTE_AlwaysInline)) {
+ if (F->hasNote(ParamAttr::FN_NOTE_AlwaysInline)) {
Out << "notes(";
insideNotes = true;
Out << "inline=always";
}
- if (F->hasNote(FN_NOTE_NoInline)) {
+ if (F->hasNote(ParamAttr::FN_NOTE_NoInline)) {
if (insideNotes)
Out << ",";
else {
}
Out << "inline=never";
}
- if (F->hasNote(FN_NOTE_OptimizeForSize)) {
+ if (F->hasNote(ParamAttr::FN_NOTE_OptimizeForSize)) {
if (insideNotes)
Out << ",";
else {
if (unsigned IID = getIntrinsicID(true))
setParamAttrs(Intrinsic::getParamAttrs(Intrinsic::ID(IID)));
- Notes = 0;
}
Function::~Function() {
/// getParamAttrs - The parameter attributes for the specified parameter are
/// returned. Parameters for the result are denoted with Idx = 0.
+/// Function notes are denoted with idx = ~0.
ParameterAttributes PAListPtr::getParamAttrs(unsigned Idx) const {
if (PAList == 0) return ParamAttr::None;
}
}
+static bool VerifyAttributeCount(const PAListPtr &Attrs, unsigned Params) {
+ if (Attrs.isEmpty())
+ return true;
+
+ unsigned LastSlot = Attrs.getNumSlots() - 1;
+ unsigned LastIndex = Attrs.getSlot(LastSlot).Index;
+ if (LastIndex <= Params
+ || (LastIndex == (unsigned)~0
+ && (LastSlot == 0 || Attrs.getSlot(LastSlot - 1).Index <= Params)))
+ return true;
+
+ return false;
+}
// visitFunction - Verify that a function is ok.
//
void Verifier::visitFunction(Function &F) {
const PAListPtr &Attrs = F.getParamAttrs();
- Assert1(Attrs.isEmpty() ||
- Attrs.getSlot(Attrs.getNumSlots()-1).Index <= FT->getNumParams(),
+ Assert1(VerifyAttributeCount(Attrs, FT->getNumParams()),
"Attributes after last parameter!", &F);
// Check function attributes.
const PAListPtr &Attrs = CS.getParamAttrs();
- Assert1(Attrs.isEmpty() ||
- Attrs.getSlot(Attrs.getNumSlots()-1).Index <= CS.arg_size(),
+ Assert1(VerifyAttributeCount(Attrs, CS.arg_size()),
"Attributes after last parameter!", I);
// Verify call attributes.