Use parameter attribute store (soon to be renamed) for
authorDevang Patel <dpatel@apple.com>
Tue, 23 Sep 2008 22:35:17 +0000 (22:35 +0000)
committerDevang Patel <dpatel@apple.com>
Tue, 23 Sep 2008 22:35:17 +0000 (22:35 +0000)
Function Notes also. Function notes are stored at index ~0.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@56511 91177308-0d34-0410-b5e6-96231b3b80d8

18 files changed:
include/llvm/Function.h
include/llvm/ParameterAttributes.h
lib/AsmParser/llvmAsmParser.h.cvs
lib/AsmParser/llvmAsmParser.y
lib/AsmParser/llvmAsmParser.y.cvs
lib/Bitcode/Reader/BitcodeReader.cpp
lib/Bitcode/Writer/BitcodeWriter.cpp
lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp
lib/Target/X86/AsmPrinter/X86IntelAsmPrinter.cpp
lib/Transforms/IPO/InlineAlways.cpp
lib/Transforms/IPO/InlineSimple.cpp
lib/Transforms/IPO/Inliner.cpp
lib/Transforms/Scalar/LoopUnswitch.cpp
lib/Transforms/Utils/InlineCost.cpp
lib/VMCore/AsmWriter.cpp
lib/VMCore/Function.cpp
lib/VMCore/ParameterAttributes.cpp
lib/VMCore/Verifier.cpp

index 3aef7c5da9c97fa2235b0ce96424215290ed350f..fea9e0fc48bb92409141e8c9b8ba9544601867bc 100644 (file)
@@ -51,12 +51,6 @@ template<> struct ilist_traits<Argument>
   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:
@@ -76,7 +70,6 @@ private:
   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;*/
@@ -155,18 +148,19 @@ public:
   ///
   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.
index 16f798ee2a48fe1ab4a00b61ae5ac2412c6993c2..848bb504294ae457583d73b5fa9ad7f32a628493 100644 (file)
@@ -46,6 +46,13 @@ const Attributes ReadNone  = 1<<9;  ///< Function does not access memory
 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;
index 7275b9e0262545b35f8448bc11176fb38c333e85..a45ec5254c0fbfa1f6333d214a143a23d4efa373 100644 (file)
 
 #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;
@@ -395,7 +395,7 @@ typedef union YYSTYPE
   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;
index a298dde43426063483ec0106f119507f3ed2d268..5cfc47dc9d7d75c480ebfbf6678a5ca50139b4dd 100644 (file)
@@ -995,7 +995,7 @@ Module *llvm::RunVMAsmParser(llvm::MemoryBuffer *MB) {
   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;
@@ -1091,8 +1091,8 @@ Module *llvm::RunVMAsmParser(llvm::MemoryBuffer *MB) {
 %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
@@ -1297,22 +1297,24 @@ OptFuncAttrs  : /* empty */ { $$ = ParamAttr::None; }
 
 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;
               }
index a298dde43426063483ec0106f119507f3ed2d268..5cfc47dc9d7d75c480ebfbf6678a5ca50139b4dd 100644 (file)
@@ -995,7 +995,7 @@ Module *llvm::RunVMAsmParser(llvm::MemoryBuffer *MB) {
   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;
@@ -1091,8 +1091,8 @@ Module *llvm::RunVMAsmParser(llvm::MemoryBuffer *MB) {
 %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
@@ -1297,22 +1297,24 @@ OptFuncAttrs  : /* empty */ { $$ = ParamAttr::None; }
 
 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;
               }
index 975075c60e53132234c92972a724fbd8032fa254..cfe2ba95441c3cf988677a8400645718c0aefeea 100644 (file)
@@ -1197,10 +1197,6 @@ bool BitcodeReader::ParseModule(const std::string &ModuleID) {
           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
index c647828eeb42b99a2f11e384a699c536488db093..931e944a410d1dc13f9abe128a4b5b95771cfb2f 100644 (file)
@@ -412,7 +412,6 @@ static void WriteModuleInfo(const Module *M, const ValueEnumerator &VE,
     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);
index aae38a04238f98fdbbf844d1d3cb1c302618aedb..a783bd279aadb69a4516532f5566aeead9ccf502 100644 (file)
@@ -160,7 +160,7 @@ void X86ATTAsmPrinter::emitFunctionHeader(const MachineFunction &MF) {
   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!");
index 12a083aa74e56217ab4aa0ca2594b1e833fb343a..559e9ebd5b37d4ed0b7b8f0f40fc3f20bd77603c 100644 (file)
@@ -147,7 +147,7 @@ bool X86IntelAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
   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!");
index ddcc79cf59be994e2dfb4d52ac60ac653867f0e8..4793a17b84236f00ab49aa02fdb239f19752fee5 100644 (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->hasNote(FN_NOTE_AlwaysInline))
+    if (!I->isDeclaration() && !I->hasNote(ParamAttr::FN_NOTE_AlwaysInline))
       NeverInline.insert(I);
 
   return false;
index 6fb695dc18e330d6bb5d2b7b9712cd47558b3e97..6db4c908b772afd676798c6d0759f12f3f499f97 100644 (file)
@@ -65,7 +65,7 @@ bool SimpleInliner::doInitialization(CallGraph &CG) {
   
   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
index 447bd6fb7d3f56ce8e2e418a165d62433ec0c204..2af5a7264df69bc7bfc1cd5b1fce8bc35588af2a 100644 (file)
@@ -141,7 +141,7 @@ bool Inliner::runOnSCC(const std::vector<CallGraphNode*> &SCC) {
         
         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;
         }
index aa9158ed5021d6181f55b08b8de8b224d0b13ff4..178bf783971a96cc6401defec4373bce608c7bf5 100644 (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->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.
index 2a39158d24ec46888b2134f6c0a0346bec84b0f0..eb825287be6ea0298b70018913f9264f4ae77dc2 100644 (file)
@@ -222,7 +222,7 @@ int InlineCostAnalyzer::getInlineCost(CallSite CS,
   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
index ab8b59bc275f2f1684d38c501c7a988dc9d657c8..32c468b4809c118aec27ba3ce49ca23ca8b5dd58 100644 (file)
@@ -1412,12 +1412,12 @@ void AssemblyWriter::printFunction(const Function *F) {
   } 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 {
@@ -1426,7 +1426,7 @@ void AssemblyWriter::printFunction(const Function *F) {
       }
       Out << "inline=never";
     }
-    if (F->hasNote(FN_NOTE_OptimizeForSize)) {
+    if (F->hasNote(ParamAttr::FN_NOTE_OptimizeForSize)) {
       if (insideNotes) 
         Out << ",";
       else {
index c1546a8e53f2ad1a580d055be52ae660f9b9fd9b..93e39df830789f65d613c16bbf4cb0c70ce9c921 100644 (file)
@@ -174,7 +174,6 @@ Function::Function(const FunctionType *Ty, LinkageTypes Linkage,
   if (unsigned IID = getIntrinsicID(true))
     setParamAttrs(Intrinsic::getParamAttrs(Intrinsic::ID(IID)));
 
-  Notes = 0;
 }
 
 Function::~Function() {
index d16f54de23aacf6dbe1ba94aff7114e64084c3d7..f1a38c4a91a36e0ec30ddcb7816d68da31a4697d 100644 (file)
@@ -186,6 +186,7 @@ const ParamAttrsWithIndex &PAListPtr::getSlot(unsigned Slot) const {
 
 /// 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;
   
index be053aba944c7d5a606a87c743583c223945bae8..f4a59c25242e97db025296b3520d4e9de0a0b813 100644 (file)
@@ -477,6 +477,19 @@ void Verifier::VerifyFunctionAttrs(const FunctionType *FT,
   }
 }
 
+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) {
@@ -497,8 +510,7 @@ 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.
@@ -955,8 +967,7 @@ void Verifier::VerifyCallSite(CallSite CS) {
 
   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.