llvm.org GIT mirror llvm / 0d51e7e
Expand ParameterAttributes to 32 bits (in preparation for adding alignment info, not there yet). Clean up interfaces to reference ParameterAttributes consistently. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@47342 91177308-0d34-0410-b5e6-96231b3b80d8 Dale Johannesen 12 years ago
16 changed file(s) with 122 addition(s) and 96 deletion(s). Raw diff Collapse all Expand all
2121 #include "llvm/BasicBlock.h"
2222 #include "llvm/Argument.h"
2323 #include "llvm/Support/Annotation.h"
24 #include "llvm/ParameterAttributes.h"
2425
2526 namespace llvm {
2627
162163 void clearCollector();
163164
164165 /// @brief Determine whether the function has the given attribute.
165 bool paramHasAttr(uint16_t i, unsigned attr) const;
166 bool paramHasAttr(uint16_t i, ParameterAttributes attr) const;
166167
167168 /// @brief Determine if the function cannot return.
168169 bool doesNotReturn() const;
1919
2020 #include "llvm/InstrTypes.h"
2121 #include "llvm/DerivedTypes.h"
22 #include "llvm/ParameterAttributes.h"
2223
2324 namespace llvm {
2425
17341735 void setParamAttrs(const ParamAttrsList *attrs);
17351736
17361737 /// @brief Determine whether the call or the callee has the given attribute.
1737 bool paramHasAttr(uint16_t i, unsigned attr) const;
1738 bool paramHasAttr(uint16_t i, ParameterAttributes attr) const;
17381739
17391740 /// @brief Determine if the call does not access memory.
17401741 bool doesNotAccessMemory() const;
3030 /// lists the attributes that can be associated with parameters or function
3131 /// results.
3232 /// @brief Function parameter attributes.
33 enum Attributes {
34 None = 0, ///< No attributes have been set
35 ZExt = 1 << 0, ///< Zero extended before/after call
36 SExt = 1 << 1, ///< Sign extended before/after call
37 NoReturn = 1 << 2, ///< Mark the function as not returning
38 InReg = 1 << 3, ///< Force argument to be passed in register
39 StructRet = 1 << 4, ///< Hidden pointer to structure to return
40 NoUnwind = 1 << 5, ///< Function doesn't unwind stack
41 NoAlias = 1 << 6, ///< Considered to not alias after call
42 ByVal = 1 << 7, ///< Pass structure by value
43 Nest = 1 << 8, ///< Nested function static chain
44 ReadNone = 1 << 9, ///< Function does not access memory
45 ReadOnly = 1 << 10 ///< Function only reads from memory
46 };
33
34 /// @brief A more friendly way to reference the attributes.
35 typedef uint32_t Attributes;
36
37 const Attributes None = 0; ///< No attributes have been set
38 const Attributes ZExt = 1<<0; ///< Zero extended before/after call
39 const Attributes SExt = 1<<1; ///< Sign extended before/after call
40 const Attributes NoReturn = 1<<2; ///< Mark the function as not returning
41 const Attributes InReg = 1<<3; ///< Force argument to be passed in register
42 const Attributes StructRet = 1<<4; ///< Hidden pointer to structure to return
43 const Attributes NoUnwind = 1<<5; ///< Function doesn't unwind stack
44 const Attributes NoAlias = 1<<6; ///< Considered to not alias after call
45 const Attributes ByVal = 1<<7; ///< Pass structure by value
46 const Attributes Nest = 1<<8; ///< Nested function static chain
47 const Attributes ReadNone = 1<<9; ///< Function does not access memory
48 const Attributes ReadOnly = 1<<10; ///< Function only reads from memory
4749
4850 /// @brief Attributes that only apply to function parameters.
49 const uint16_t ParameterOnly = ByVal | InReg | Nest | StructRet;
51 const Attributes ParameterOnly = ByVal | InReg | Nest | StructRet;
5052
5153 /// @brief Attributes that only apply to function return values.
52 const uint16_t ReturnOnly = NoReturn | NoUnwind | ReadNone | ReadOnly;
54 const Attributes ReturnOnly = NoReturn | NoUnwind | ReadNone | ReadOnly;
5355
5456 /// @brief Parameter attributes that do not apply to vararg call arguments.
55 const uint16_t VarArgsIncompatible = StructRet;
57 const Attributes VarArgsIncompatible = StructRet;
5658
5759 /// @brief Attributes that are mutually incompatible.
58 const uint16_t MutuallyIncompatible[3] = {
60 const Attributes MutuallyIncompatible[3] = {
5961 ByVal | InReg | Nest | StructRet,
6062 ZExt | SExt,
6163 ReadNone | ReadOnly
6264 };
6365
6466 /// @brief Which attributes cannot be applied to a type.
65 uint16_t typeIncompatible (const Type *Ty);
67 Attributes typeIncompatible (const Type *Ty);
6668
6769 } // end namespace ParamAttr
70
71 /// @brief A more friendly way to reference the attributes.
72 typedef ParamAttr::Attributes ParameterAttributes;
6873
6974 /// This is just a pair of values to associate a set of parameter attributes
7075 /// with a parameter index.
7176 /// @brief ParameterAttributes with a parameter index.
7277 struct ParamAttrsWithIndex {
73 uint16_t attrs; ///< The attributes that are set, or'd together
78 ParameterAttributes attrs; ///< The attributes that are set, or'd together
7479 uint16_t index; ///< Index of the parameter for which the attributes apply
7580
76 static ParamAttrsWithIndex get(uint16_t idx, uint16_t attrs) {
81 static ParamAttrsWithIndex get(uint16_t idx, ParameterAttributes attrs) {
7782 ParamAttrsWithIndex P;
7883 P.index = idx;
7984 P.attrs = attrs;
8388
8489 /// @brief A vector of attribute/index pairs.
8590 typedef SmallVector ParamAttrsVector;
86
87 /// @brief A more friendly way to reference the attributes.
88 typedef ParamAttr::Attributes ParameterAttributes;
8991
9092 /// This class represents a list of attribute/index pairs for parameter
9193 /// attributes. Each entry in the list contains the index of a function
142144
143145 /// @brief Add the specified attributes to those in PAL at index idx.
144146 static const ParamAttrsList *includeAttrs(const ParamAttrsList *PAL,
145 uint16_t idx, uint16_t attrs);
147 uint16_t idx,
148 ParameterAttributes attrs);
146149
147150 /// @brief Remove the specified attributes from those in PAL at index idx.
148151 static const ParamAttrsList *excludeAttrs(const ParamAttrsList *PAL,
149 uint16_t idx, uint16_t attrs);
152 uint16_t idx,
153 ParameterAttributes attrs);
150154
151155 /// @}
152156 /// @name Accessors
160164 /// @returns The all the ParameterAttributes for the \p indexth parameter
161165 /// as a uint16_t of enumeration values OR'd together.
162166 /// @brief Get the attributes for a parameter
163 uint16_t getParamAttrs(uint16_t param_index) const;
167 ParameterAttributes getParamAttrs(uint16_t param_index) const;
164168
165169 /// This checks to see if the \p ith function parameter has the parameter
166170 /// attribute given by \p attr set.
180184 /// string of equivalent mnemonics. This is, presumably, for writing out
181185 /// the mnemonics for the assembly writer.
182186 /// @brief Convert parameter attribute bits to text
183 static std::string getParamAttrsText(uint16_t Attributes);
187 static std::string getParamAttrsText(ParameterAttributes Attributes);
184188
185189 /// The \p Indexth parameter attribute is converted to string.
186190 /// @brief Get the text for the parmeter attributes for one parameter.
217221 return attrs[attr_index].index;
218222 }
219223
220 uint16_t getParamAttrsAtIndex(unsigned attr_index) const {
224 ParameterAttributes getParamAttrsAtIndex(unsigned attr_index) const {
221225 return attrs[attr_index].attrs;
222226 }
223227
2121
2222 #include "llvm/Instruction.h"
2323 #include "llvm/BasicBlock.h"
24 #include "llvm/ParameterAttributes.h"
2425
2526 namespace llvm {
2627
6465 void setParamAttrs(const ParamAttrsList *PAL);
6566
6667 /// paramHasAttr - whether the call or the callee has the given attribute.
67 bool paramHasAttr(uint16_t i, unsigned attr) const;
68 bool paramHasAttr(uint16_t i, ParameterAttributes attr) const;
6869
6970 /// @brief Determine if the call does not access memory.
7071 bool doesNotAccessMemory() const;
973973
974974 llvm::GlobalValue::LinkageTypes Linkage;
975975 llvm::GlobalValue::VisibilityTypes Visibility;
976 uint16_t ParamAttrs;
976 llvm::ParameterAttributes ParamAttrs;
977977 llvm::APInt *APIntVal;
978978 int64_t SInt64Val;
979979 uint64_t UInt64Val;
118118 const ParamAttrsList *A = Attrs[i];
119119 for (unsigned op = 0, e = A->size(); op != e; ++op) {
120120 Record.push_back(A->getParamIndex(op));
121 Record.push_back(A->getParamAttrsAtIndex(op));
121 Record.push_back((uint16_t)A->getParamAttrsAtIndex(op));
122122 }
123123
124124 Stream.EmitRecord(bitc::PARAMATTR_CODE_ENTRY, Record);
404404 const ParamAttrsList *PAL = F->getParamAttrs();
405405
406406 // Add any return attributes.
407 if (unsigned attrs = PAL ? PAL->getParamAttrs(0) : 0)
407 if (ParameterAttributes attrs = PAL ? PAL->getParamAttrs(0) : ParamAttr::None)
408408 ParamAttrsVec.push_back(ParamAttrsWithIndex::get(0, attrs));
409409
410410 unsigned ArgIndex = 1;
419419 ++NumByValArgsPromoted;
420420 } else if (!ArgsToPromote.count(I)) {
421421 Params.push_back(I->getType());
422 if (unsigned attrs = PAL ? PAL->getParamAttrs(ArgIndex) : 0)
422 if (ParameterAttributes attrs = PAL ? PAL->getParamAttrs(ArgIndex) :
423 ParamAttr::None)
423424 ParamAttrsVec.push_back(ParamAttrsWithIndex::get(Params.size(), attrs));
424425 } else if (I->use_empty()) {
425426 ++NumArgumentsDead;
495496 PAL = CS.getParamAttrs();
496497
497498 // Add any return attributes.
498 if (unsigned attrs = PAL ? PAL->getParamAttrs(0) : 0)
499 if (ParameterAttributes attrs = PAL ? PAL->getParamAttrs(0) :
500 ParamAttr::None)
499501 ParamAttrsVec.push_back(ParamAttrsWithIndex::get(0, attrs));
500502
501503 // Loop over the operands, inserting GEP and loads in the caller as
507509 if (!ArgsToPromote.count(I) && !ByValArgsToTransform.count(I)) {
508510 Args.push_back(*AI); // Unmodified argument
509511
510 if (unsigned Attrs = PAL ? PAL->getParamAttrs(ArgIndex) : 0)
512 if (ParameterAttributes Attrs = PAL ? PAL->getParamAttrs(ArgIndex) :
513 ParamAttr::None)
511514 ParamAttrsVec.push_back(ParamAttrsWithIndex::get(Args.size(), Attrs));
512515
513516 } else if (ByValArgsToTransform.count(I)) {
546549 // Push any varargs arguments on the list
547550 for (; AI != CS.arg_end(); ++AI, ++ArgIndex) {
548551 Args.push_back(*AI);
549 if (unsigned Attrs = PAL ? PAL->getParamAttrs(ArgIndex) : 0)
552 if (ParameterAttributes Attrs = PAL ? PAL->getParamAttrs(ArgIndex) :
553 ParamAttr::None)
550554 ParamAttrsVec.push_back(ParamAttrsWithIndex::get(Args.size(), Attrs));
551555 }
552556
511511 const ParamAttrsList *PAL = F->getParamAttrs();
512512
513513 // The existing function return attributes.
514 uint16_t RAttrs = PAL ? PAL->getParamAttrs(0) : 0;
514 ParameterAttributes RAttrs = PAL ? PAL->getParamAttrs(0) : ParamAttr::None;
515515
516516 // Make the function return void if the return value is dead.
517517 const Type *RetTy = FTy->getReturnType();
531531 ++I, ++index)
532532 if (!DeadArguments.count(I)) {
533533 Params.push_back(I->getType());
534 uint16_t Attrs = PAL ? PAL->getParamAttrs(index) : 0;
534 ParameterAttributes Attrs = PAL ? PAL->getParamAttrs(index) :
535 ParamAttr::None;
535536 if (Attrs)
536537 ParamAttrsVec.push_back(ParamAttrsWithIndex::get(Params.size(), Attrs));
537538 }
571572 PAL = CS.getParamAttrs();
572573
573574 // The call return attributes.
574 uint16_t RAttrs = PAL ? PAL->getParamAttrs(0) : 0;
575 ParameterAttributes RAttrs = PAL ? PAL->getParamAttrs(0) : ParamAttr::None;
575576 // Adjust in case the function was changed to return void.
576577 RAttrs &= ~ParamAttr::typeIncompatible(NF->getReturnType());
577578 if (RAttrs)
584585 I != E; ++I, ++AI, ++index)
585586 if (!DeadArguments.count(I)) { // Remove operands for dead arguments
586587 Args.push_back(*AI);
587 uint16_t Attrs = PAL ? PAL->getParamAttrs(index) : 0;
588 ParameterAttributes Attrs = PAL ? PAL->getParamAttrs(index) :
589 ParamAttr::None;
588590 if (Attrs)
589591 ParamAttrsVec.push_back(ParamAttrsWithIndex::get(Args.size(), Attrs));
590592 }
595597 // Push any varargs arguments on the list. Don't forget their attributes.
596598 for (; AI != CS.arg_end(); ++AI) {
597599 Args.push_back(*AI);
598 uint16_t Attrs = PAL ? PAL->getParamAttrs(index++) : 0;
600 ParameterAttributes Attrs = PAL ? PAL->getParamAttrs(index++) :
601 ParamAttr::None;
599602 if (Attrs)
600603 ParamAttrsVec.push_back(ParamAttrsWithIndex::get(Args.size(), Attrs));
601604 }
122122 // If the SCC doesn't unwind or doesn't throw, note this fact.
123123 if (!SCCMightUnwind || !SCCMightReturn)
124124 for (unsigned i = 0, e = SCC.size(); i != e; ++i) {
125 uint16_t NewAttributes = ParamAttr::None;
125 ParameterAttributes NewAttributes = ParamAttr::None;
126126
127127 if (!SCCMightUnwind)
128128 NewAttributes |= ParamAttr::NoUnwind;
83838383 return false; // Cannot transform this return value.
83848384
83858385 if (CallerPAL && !Caller->use_empty()) {
8386 uint16_t RAttrs = CallerPAL->getParamAttrs(0);
8386 ParameterAttributes RAttrs = CallerPAL->getParamAttrs(0);
83878387 if (RAttrs & ParamAttr::typeIncompatible(FT->getReturnType()))
83888388 return false; // Attribute not compatible with transformed value.
83898389 }
84148414 return false; // Cannot transform this parameter value.
84158415
84168416 if (CallerPAL) {
8417 uint16_t PAttrs = CallerPAL->getParamAttrs(i + 1);
8417 ParameterAttributes PAttrs = CallerPAL->getParamAttrs(i + 1);
84188418 if (PAttrs & ParamAttr::typeIncompatible(ParamTy))
84198419 return false; // Attribute not compatible with transformed value.
84208420 }
84428442 for (unsigned i = CallerPAL->size(); i; --i) {
84438443 if (CallerPAL->getParamIndex(i - 1) <= FT->getNumParams())
84448444 break;
8445 uint16_t PAttrs = CallerPAL->getParamAttrsAtIndex(i - 1);
8445 ParameterAttributes PAttrs = CallerPAL->getParamAttrsAtIndex(i - 1);
84468446 if (PAttrs & ParamAttr::VarArgsIncompatible)
84478447 return false;
84488448 }
84558455 attrVec.reserve(NumCommonArgs);
84568456
84578457 // Get any return attributes.
8458 uint16_t RAttrs = CallerPAL ? CallerPAL->getParamAttrs(0) : 0;
8458 ParameterAttributes RAttrs = CallerPAL ? CallerPAL->getParamAttrs(0) :
8459 ParamAttr::None;
84598460
84608461 // If the return value is not being used, the type may not be compatible
84618462 // with the existing attributes. Wipe out any problematic attributes.
84788479 }
84798480
84808481 // Add any parameter attributes.
8481 uint16_t PAttrs = CallerPAL ? CallerPAL->getParamAttrs(i + 1) : 0;
8482 ParameterAttributes PAttrs = CallerPAL ? CallerPAL->getParamAttrs(i + 1) :
8483 ParamAttr::None;
84828484 if (PAttrs)
84838485 attrVec.push_back(ParamAttrsWithIndex::get(i + 1, PAttrs));
84848486 }
85098511 }
85108512
85118513 // Add any parameter attributes.
8512 uint16_t PAttrs = CallerPAL ? CallerPAL->getParamAttrs(i + 1) : 0;
8514 ParameterAttributes PAttrs = CallerPAL ?
8515 CallerPAL->getParamAttrs(i + 1) :
8516 ParamAttr::None;
85138517 if (PAttrs)
85148518 attrVec.push_back(ParamAttrsWithIndex::get(i + 1, PAttrs));
85158519 }
85928596 if (const ParamAttrsList *NestAttrs = NestF->getParamAttrs()) {
85938597 unsigned NestIdx = 1;
85948598 const Type *NestTy = 0;
8595 uint16_t NestAttr = 0;
8599 ParameterAttributes NestAttr = ParamAttr::None;
85968600
85978601 // Look for a parameter marked with the 'nest' attribute.
85988602 for (FunctionType::param_iterator I = NestFTy->param_begin(),
86168620 // mean appending it. Likewise for attributes.
86178621
86188622 // Add any function result attributes.
8619 uint16_t Attr = Attrs ? Attrs->getParamAttrs(0) : 0;
8623 ParameterAttributes Attr = Attrs ? Attrs->getParamAttrs(0) :
8624 ParamAttr::None;
86208625 if (Attr)
86218626 NewAttrs.push_back (ParamAttrsWithIndex::get(0, Attr));
86228627
741741 inline void write(const Type *Ty) { printType(Ty); }
742742
743743 void writeOperand(const Value *Op, bool PrintType);
744 void writeParamOperand(const Value *Operand, uint16_t Attrs);
744 void writeParamOperand(const Value *Operand, ParameterAttributes Attrs);
745745
746746 const Module* getModule() { return TheModule; }
747747
751751 void printGlobal(const GlobalVariable *GV);
752752 void printAlias(const GlobalAlias *GV);
753753 void printFunction(const Function *F);
754 void printArgument(const Argument *FA, uint16_t ParamAttrs);
754 void printArgument(const Argument *FA, ParameterAttributes Attrs);
755755 void printBasicBlock(const BasicBlock *BB);
756756 void printInstruction(const Instruction &I);
757757
838838 }
839839 }
840840
841 void AssemblyWriter::writeParamOperand(const Value *Operand, uint16_t Attrs) {
841 void AssemblyWriter::writeParamOperand(const Value *Operand,
842 ParameterAttributes Attrs) {
842843 if (Operand == 0) {
843844 Out << "";
844845 } else {
10911092 // Insert commas as we go... the first arg doesn't get a comma
10921093 if (I != F->arg_begin()) Out << ", ";
10931094 printArgument(I, (Attrs ? Attrs->getParamAttrs(Idx)
1094 : uint16_t(ParamAttr::None)));
1095 : ParamAttr::None));
10951096 Idx++;
10961097 }
10971098 } else {
11031104 // Output type...
11041105 printType(FT->getParamType(i));
11051106
1106 unsigned ArgAttrs = ParamAttr::None;
1107 ParameterAttributes ArgAttrs = ParamAttr::None;
11071108 if (Attrs) ArgAttrs = Attrs->getParamAttrs(i+1);
11081109 if (ArgAttrs != ParamAttr::None)
11091110 Out << ' ' << ParamAttrsList::getParamAttrsText(ArgAttrs);
11431144 /// printArgument - This member is called for every argument that is passed into
11441145 /// the function. Simply print it out
11451146 ///
1146 void AssemblyWriter::printArgument(const Argument *Arg, uint16_t Attrs) {
1147 void AssemblyWriter::printArgument(const Argument *Arg,
1148 ParameterAttributes Attrs) {
11471149 // Output type...
11481150 printType(Arg->getType());
11491151
13221324 for (unsigned op = 1, Eop = I.getNumOperands(); op < Eop; ++op) {
13231325 if (op > 1)
13241326 Out << ',';
1325 writeParamOperand(I.getOperand(op), PAL ? PAL->getParamAttrs(op) : 0);
1327 writeParamOperand(I.getOperand(op), PAL ? PAL->getParamAttrs(op) :
1328 ParamAttr::None);
13261329 }
13271330 Out << " )";
13281331 if (PAL && PAL->getParamAttrs(0) != ParamAttr::None)
13601363 for (unsigned op = 3, Eop = I.getNumOperands(); op < Eop; ++op) {
13611364 if (op > 3)
13621365 Out << ',';
1363 writeParamOperand(I.getOperand(op), PAL ? PAL->getParamAttrs(op-2) : 0);
1366 writeParamOperand(I.getOperand(op), PAL ? PAL->getParamAttrs(op-2) :
1367 ParamAttr::None);
13641368 }
13651369
13661370 Out << " )";
15141518 cerr << "PAL[ ";
15151519 for (unsigned i = 0; i < attrs.size(); ++i) {
15161520 uint16_t index = getParamIndex(i);
1517 uint16_t attrs = getParamAttrs(index);
1521 ParameterAttributes attrs = getParamAttrs(index);
15181522 cerr << "{" << index << "," << attrs << "} ";
15191523 }
1524
15201525 cerr << "]\n";
15211526 }
15221527
138138 }
139139
140140 /// @brief Determine whether the function has the given attribute.
141 bool Function::paramHasAttr(uint16_t i, unsigned attr) const {
142 return ParamAttrs && ParamAttrs->paramHasAttr(i, (ParameterAttributes)attr);
141 bool Function::paramHasAttr(uint16_t i, ParameterAttributes attr) const {
142 return ParamAttrs && ParamAttrs->paramHasAttr(i, attr);
143143 }
144144
145145 /// @brief Determine if the function cannot return.
364364
365365 const ParamAttrsList *Intrinsic::getParamAttrs(ID id) {
366366 ParamAttrsVector Attrs;
367 uint16_t Attr = ParamAttr::None;
367 ParameterAttributes Attr = ParamAttr::None;
368368
369369 #define GET_INTRINSIC_ATTRIBUTES
370370 #include "llvm/Intrinsics.gen"
5454 else
5555 cast(I)->setParamAttrs(PAL);
5656 }
57 bool CallSite::paramHasAttr(uint16_t i, unsigned attr) const {
57 bool CallSite::paramHasAttr(uint16_t i, ParameterAttributes attr) const {
5858 if (CallInst *CI = dyn_cast(I))
59 return CI->paramHasAttr(i, (ParameterAttributes)attr);
59 return CI->paramHasAttr(i, attr);
6060 else
61 return cast(I)->paramHasAttr(i, (ParameterAttributes)attr);
61 return cast(I)->paramHasAttr(i, attr);
6262 }
6363 bool CallSite::doesNotAccessMemory() const {
6464 if (CallInst *CI = dyn_cast(I))
373373 ParamAttrs = newAttrs;
374374 }
375375
376 bool CallInst::paramHasAttr(uint16_t i, unsigned attr) const {
377 if (ParamAttrs && ParamAttrs->paramHasAttr(i, (ParameterAttributes)attr))
376 bool CallInst::paramHasAttr(uint16_t i, ParameterAttributes attr) const {
377 if (ParamAttrs && ParamAttrs->paramHasAttr(i, attr))
378378 return true;
379379 if (const Function *F = getCalledFunction())
380 return F->paramHasAttr(i, (ParameterAttributes)attr);
380 return F->paramHasAttr(i, attr);
381381 return false;
382382 }
383383
497497 ParamAttrs = newAttrs;
498498 }
499499
500 bool InvokeInst::paramHasAttr(uint16_t i, unsigned attr) const {
501 if (ParamAttrs && ParamAttrs->paramHasAttr(i, (ParameterAttributes)attr))
500 bool InvokeInst::paramHasAttr(uint16_t i, ParameterAttributes attr) const {
501 if (ParamAttrs && ParamAttrs->paramHasAttr(i, attr))
502502 return true;
503503 if (const Function *F = getCalledFunction())
504 return F->paramHasAttr(i, (ParameterAttributes)attr);
504 return F->paramHasAttr(i, attr);
505505 return false;
506506 }
507507
2626 ParamAttrsLists->RemoveNode(this);
2727 }
2828
29 uint16_t
29 ParameterAttributes
3030 ParamAttrsList::getParamAttrs(uint16_t Index) const {
3131 unsigned limit = attrs.size();
3232 for (unsigned i = 0; i < limit && attrs[i].index <= Index; ++i)
4343 }
4444
4545 std::string
46 ParamAttrsList::getParamAttrsText(uint16_t Attrs) {
46 ParamAttrsList::getParamAttrsText(ParameterAttributes Attrs) {
4747 std::string Result;
4848 if (Attrs & ParamAttr::ZExt)
4949 Result += "zeroext ";
169169
170170 const ParamAttrsList *
171171 ParamAttrsList::includeAttrs(const ParamAttrsList *PAL,
172 uint16_t idx, uint16_t attrs) {
173 uint16_t OldAttrs = PAL ? PAL->getParamAttrs(idx) : 0;
174 uint16_t NewAttrs = OldAttrs | attrs;
172 uint16_t idx, ParameterAttributes attrs) {
173 ParameterAttributes OldAttrs = PAL ? PAL->getParamAttrs(idx) :
174 ParamAttr::None;
175 ParameterAttributes NewAttrs = OldAttrs | attrs;
175176 if (NewAttrs == OldAttrs)
176177 return PAL;
177178
182183
183184 const ParamAttrsList *
184185 ParamAttrsList::excludeAttrs(const ParamAttrsList *PAL,
185 uint16_t idx, uint16_t attrs) {
186 uint16_t OldAttrs = PAL ? PAL->getParamAttrs(idx) : 0;
187 uint16_t NewAttrs = OldAttrs & ~attrs;
186 uint16_t idx, ParameterAttributes attrs) {
187 ParameterAttributes OldAttrs = PAL ? PAL->getParamAttrs(idx) :
188 ParamAttr::None;
189 ParameterAttributes NewAttrs = OldAttrs & ~attrs;
188190 if (NewAttrs == OldAttrs)
189191 return PAL;
190192
193195 return getModified(PAL, modVec);
194196 }
195197
196 uint16_t ParamAttr::typeIncompatible (const Type *Ty) {
197 uint16_t Incompatible = None;
198 ParameterAttributes ParamAttr::typeIncompatible (const Type *Ty) {
199 ParameterAttributes Incompatible = None;
198200
199201 if (!Ty->isInteger())
200202 // Attributes that only apply to integers.
260260 void VerifyCallSite(CallSite CS);
261261 void VerifyIntrinsicPrototype(Intrinsic::ID ID, Function *F,
262262 unsigned Count, ...);
263 void VerifyAttrs(uint16_t Attrs, const Type *Ty, bool isReturnValue,
264 const Value *V);
263 void VerifyAttrs(ParameterAttributes Attrs, const Type *Ty,
264 bool isReturnValue, const Value *V);
265265 void VerifyFunctionAttrs(const FunctionType *FT, const ParamAttrsList *Attrs,
266266 const Value *V);
267267
385385
386386 // VerifyAttrs - Check the given parameter attributes for an argument or return
387387 // value of the specified type. The value V is printed in error messages.
388 void Verifier::VerifyAttrs(uint16_t Attrs, const Type *Ty, bool isReturnValue,
389 const Value *V) {
388 void Verifier::VerifyAttrs(ParameterAttributes Attrs, const Type *Ty,
389 bool isReturnValue, const Value *V) {
390390 if (Attrs == ParamAttr::None)
391391 return;
392392
393393 if (isReturnValue) {
394 uint16_t RetI = Attrs & ParamAttr::ParameterOnly;
394 ParameterAttributes RetI = Attrs & ParamAttr::ParameterOnly;
395395 Assert1(!RetI, "Attribute " + ParamAttrsList::getParamAttrsText(RetI) +
396396 "does not apply to return values!", V);
397397 } else {
398 uint16_t ParmI = Attrs & ParamAttr::ReturnOnly;
398 ParameterAttributes ParmI = Attrs & ParamAttr::ReturnOnly;
399399 Assert1(!ParmI, "Attribute " + ParamAttrsList::getParamAttrsText(ParmI) +
400400 "only applies to return values!", V);
401401 }
402402
403403 for (unsigned i = 0;
404404 i < array_lengthof(ParamAttr::MutuallyIncompatible); ++i) {
405 uint16_t MutI = Attrs & ParamAttr::MutuallyIncompatible[i];
405 ParameterAttributes MutI = Attrs & ParamAttr::MutuallyIncompatible[i];
406406 Assert1(!(MutI & (MutI - 1)), "Attributes " +
407407 ParamAttrsList::getParamAttrsText(MutI) + "are incompatible!", V);
408408 }
409409
410 uint16_t TypeI = Attrs & ParamAttr::typeIncompatible(Ty);
410 ParameterAttributes TypeI = Attrs & ParamAttr::typeIncompatible(Ty);
411411 Assert1(!TypeI, "Wrong type for attribute " +
412412 ParamAttrsList::getParamAttrsText(TypeI), V);
413413 }
423423 bool SawNest = false;
424424
425425 for (unsigned Idx = 0; Idx <= FT->getNumParams(); ++Idx) {
426 uint16_t Attr = Attrs->getParamAttrs(Idx);
426 ParameterAttributes Attr = Attrs->getParamAttrs(Idx);
427427
428428 VerifyAttrs(Attr, FT->getParamType(Idx-1), !Idx, V);
429429
872872 if (Attrs && FTy->isVarArg())
873873 // Check attributes on the varargs part.
874874 for (unsigned Idx = 1 + FTy->getNumParams(); Idx <= CS.arg_size(); ++Idx) {
875 uint16_t Attr = Attrs->getParamAttrs(Idx);
875 ParameterAttributes Attr = Attrs->getParamAttrs(Idx);
876876
877877 VerifyAttrs(Attr, CS.getArgument(Idx-1)->getType(), false, I);
878878
879 uint16_t VArgI = Attr & ParamAttr::VarArgsIncompatible;
879 ParameterAttributes VArgI = Attr & ParamAttr::VarArgsIncompatible;
880880 Assert1(!VArgI, "Attribute " + ParamAttrsList::getParamAttrsText(VArgI) +
881881 "cannot be used for vararg call arguments!", I);
882882 }
446446 Out << "ParamAttrsWithIndex PAWI;"; nl(Out);
447447 for (unsigned i = 0; i < PAL->size(); ++i) {
448448 uint16_t index = PAL->getParamIndex(i);
449 uint16_t attrs = PAL->getParamAttrs(index);
449 ParameterAttributes attrs = PAL->getParamAttrs(index);
450450 Out << "PAWI.index = " << index << "; PAWI.attrs = 0 ";
451451 if (attrs & ParamAttr::SExt)
452452 Out << " | ParamAttr::SExt";