#include "llvm/Constants.h"
#include "llvm/DerivedTypes.h"
+#include "llvm/ParameterAttributes.h"
#include "llvm/Function.h"
#include "llvm/Instructions.h"
#include "llvm/Assembly/Parser.h"
struct TypeWithAttrs {
llvm::PATypeHolder *Ty;
- FunctionType::ParameterAttributes Attrs;
+ uint16_t Attrs;
};
typedef std::vector<TypeWithAttrs> TypeWithAttrsList;
struct ArgListEntry {
- FunctionType::ParameterAttributes Attrs;
+ uint16_t Attrs;
llvm::PATypeHolder *Ty;
char *Name;
};
struct ValueRefListEntry {
Value *Val;
- FunctionType::ParameterAttributes Attrs;
+ uint16_t Attrs;
};
typedef std::vector<ValueRefListEntry> ValueRefList;
}
return false;
}
-
-
} CurModule;
static struct PerFunctionInfo {
llvm::GlobalValue::LinkageTypes Linkage;
llvm::GlobalValue::VisibilityTypes Visibility;
- llvm::FunctionType::ParameterAttributes ParamAttrs;
+ uint16_t ParamAttrs;
llvm::APInt *APIntVal;
int64_t SInt64Val;
uint64_t UInt64Val;
CHECK_FOR_ERROR
};
-ParamAttr : ZEXT { $$ = FunctionType::ZExtAttribute; }
- | SEXT { $$ = FunctionType::SExtAttribute; }
- | INREG { $$ = FunctionType::InRegAttribute; }
- | SRET { $$ = FunctionType::StructRetAttribute; }
+ParamAttr : ZEXT { $$ = ZExtAttribute; }
+ | SEXT { $$ = SExtAttribute; }
+ | INREG { $$ = InRegAttribute; }
+ | SRET { $$ = StructRetAttribute; }
;
-OptParamAttrs : /* empty */ { $$ = FunctionType::NoAttributeSet; }
+OptParamAttrs : /* empty */ { $$ = NoAttributeSet; }
| OptParamAttrs ParamAttr {
- $$ = FunctionType::ParameterAttributes($1 | $2);
+ $$ = $1 | $2;
}
;
-FuncAttr : NORETURN { $$ = FunctionType::NoReturnAttribute; }
- | NOUNWIND { $$ = FunctionType::NoUnwindAttribute; }
+FuncAttr : NORETURN { $$ = NoReturnAttribute; }
+ | NOUNWIND { $$ = NoUnwindAttribute; }
| ParamAttr
;
-OptFuncAttrs : /* empty */ { $$ = FunctionType::NoAttributeSet; }
+OptFuncAttrs : /* empty */ { $$ = NoAttributeSet; }
| OptFuncAttrs FuncAttr {
- $$ = FunctionType::ParameterAttributes($1 | $2);
+ $$ = $1 | $2;
}
;
}
| Types '(' ArgTypeListI ')' OptFuncAttrs {
std::vector<const Type*> Params;
- std::vector<FunctionType::ParameterAttributes> Attrs;
- Attrs.push_back($5);
- for (TypeWithAttrsList::iterator I=$3->begin(), E=$3->end(); I != E; ++I) {
+ ParamAttrsList Attrs;
+ if ($5 != NoAttributeSet)
+ Attrs.addAttributes(0, $5);
+ unsigned index = 1;
+ TypeWithAttrsList::iterator I = $3->begin(), E = $3->end();
+ for (; I != E; ++I, ++index) {
const Type *Ty = I->Ty->get();
Params.push_back(Ty);
if (Ty != Type::VoidTy)
- Attrs.push_back(I->Attrs);
+ if (I->Attrs != NoAttributeSet)
+ Attrs.addAttributes(index, I->Attrs);
}
bool isVarArg = Params.size() && Params.back() == Type::VoidTy;
if (isVarArg) Params.pop_back();
- FunctionType *FT = FunctionType::get(*$1, Params, isVarArg, Attrs);
+ ParamAttrsList *ActualAttrs = 0;
+ if (!Attrs.empty())
+ ActualAttrs = new ParamAttrsList(Attrs);
+ FunctionType *FT = FunctionType::get(*$1, Params, isVarArg, ActualAttrs);
delete $3; // Delete the argument list
delete $1; // Delete the return type handle
$$ = new PATypeHolder(HandleUpRefs(FT));
}
| VOID '(' ArgTypeListI ')' OptFuncAttrs {
std::vector<const Type*> Params;
- std::vector<FunctionType::ParameterAttributes> Attrs;
- Attrs.push_back($5);
- for (TypeWithAttrsList::iterator I=$3->begin(), E=$3->end(); I != E; ++I) {
+ ParamAttrsList Attrs;
+ if ($5 != NoAttributeSet)
+ Attrs.addAttributes(0, $5);
+ TypeWithAttrsList::iterator I = $3->begin(), E = $3->end();
+ unsigned index = 1;
+ for ( ; I != E; ++I, ++index) {
const Type* Ty = I->Ty->get();
Params.push_back(Ty);
if (Ty != Type::VoidTy)
- Attrs.push_back(I->Attrs);
+ if (I->Attrs != NoAttributeSet)
+ Attrs.addAttributes(index, I->Attrs);
}
bool isVarArg = Params.size() && Params.back() == Type::VoidTy;
if (isVarArg) Params.pop_back();
- FunctionType *FT = FunctionType::get($1, Params, isVarArg, Attrs);
+ ParamAttrsList *ActualAttrs = 0;
+ if (!Attrs.empty())
+ ActualAttrs = new ParamAttrsList(Attrs);
+
+ FunctionType *FT = FunctionType::get($1, Params, isVarArg, ActualAttrs);
delete $3; // Delete the argument list
$$ = new PATypeHolder(HandleUpRefs(FT));
CHECK_FOR_ERROR
: ArgTypeList
| ArgTypeList ',' DOTDOTDOT {
$$=$1;
- TypeWithAttrs TWA; TWA.Attrs = FunctionType::NoAttributeSet;
+ TypeWithAttrs TWA; TWA.Attrs = NoAttributeSet;
TWA.Ty = new PATypeHolder(Type::VoidTy);
$$->push_back(TWA);
CHECK_FOR_ERROR
}
| DOTDOTDOT {
$$ = new TypeWithAttrsList;
- TypeWithAttrs TWA; TWA.Attrs = FunctionType::NoAttributeSet;
+ TypeWithAttrs TWA; TWA.Attrs = NoAttributeSet;
TWA.Ty = new PATypeHolder(Type::VoidTy);
$$->push_back(TWA);
CHECK_FOR_ERROR
struct ArgListEntry E;
E.Ty = new PATypeHolder(Type::VoidTy);
E.Name = 0;
- E.Attrs = FunctionType::NoAttributeSet;
+ E.Attrs = NoAttributeSet;
$$->push_back(E);
CHECK_FOR_ERROR
}
struct ArgListEntry E;
E.Ty = new PATypeHolder(Type::VoidTy);
E.Name = 0;
- E.Attrs = FunctionType::NoAttributeSet;
+ E.Attrs = NoAttributeSet;
$$->push_back(E);
CHECK_FOR_ERROR
}
GEN_ERROR("Reference to abstract result: "+ $2->get()->getDescription());
std::vector<const Type*> ParamTypeList;
- std::vector<FunctionType::ParameterAttributes> ParamAttrs;
- ParamAttrs.push_back($7);
+ ParamAttrsList ParamAttrs;
+ if ($7 != NoAttributeSet)
+ ParamAttrs.addAttributes(0, $7);
if ($5) { // If there are arguments...
- for (ArgListType::iterator I = $5->begin(); I != $5->end(); ++I) {
+ unsigned index = 1;
+ for (ArgListType::iterator I = $5->begin(); I != $5->end(); ++I, ++index) {
const Type* Ty = I->Ty->get();
if (!CurFun.isDeclare && CurModule.TypeIsUnresolved(I->Ty))
GEN_ERROR("Reference to abstract argument: " + Ty->getDescription());
ParamTypeList.push_back(Ty);
if (Ty != Type::VoidTy)
- ParamAttrs.push_back(I->Attrs);
+ if (I->Attrs != NoAttributeSet)
+ ParamAttrs.addAttributes(index, I->Attrs);
}
}
bool isVarArg = ParamTypeList.size() && ParamTypeList.back() == Type::VoidTy;
if (isVarArg) ParamTypeList.pop_back();
- FunctionType *FT = FunctionType::get(*$2, ParamTypeList, isVarArg,
- ParamAttrs);
+ ParamAttrsList *ActualAttrs = 0;
+ if (!ParamAttrs.empty())
+ ActualAttrs = new ParamAttrsList(ParamAttrs);
+
+ FunctionType *FT = FunctionType::get(*$2, ParamTypeList, isVarArg,
+ ActualAttrs);
const PointerType *PFT = PointerType::get(FT);
delete $2;
!(Ty = dyn_cast<FunctionType>(PFTy->getElementType()))) {
// Pull out the types of all of the arguments...
std::vector<const Type*> ParamTypes;
- FunctionType::ParamAttrsList ParamAttrs;
- ParamAttrs.push_back($8);
- for (ValueRefList::iterator I = $6->begin(), E = $6->end(); I != E; ++I) {
+ ParamAttrsList ParamAttrs;
+ if ($8 != NoAttributeSet)
+ ParamAttrs.addAttributes(0, $8);
+ ValueRefList::iterator I = $6->begin(), E = $6->end();
+ unsigned index = 1;
+ for (; I != E; ++I, ++index) {
const Type *Ty = I->Val->getType();
if (Ty == Type::VoidTy)
GEN_ERROR("Short call syntax cannot be used with varargs");
ParamTypes.push_back(Ty);
- ParamAttrs.push_back(I->Attrs);
+ if (I->Attrs != NoAttributeSet)
+ ParamAttrs.addAttributes(index, I->Attrs);
}
- Ty = FunctionType::get($3->get(), ParamTypes, false, ParamAttrs);
+ ParamAttrsList *Attrs = 0;
+ if (!ParamAttrs.empty())
+ Attrs = new ParamAttrsList(ParamAttrs);
+ Ty = FunctionType::get($3->get(), ParamTypes, false, Attrs);
PFTy = PointerType::get(Ty);
}
!(Ty = dyn_cast<FunctionType>(PFTy->getElementType()))) {
// Pull out the types of all of the arguments...
std::vector<const Type*> ParamTypes;
- FunctionType::ParamAttrsList ParamAttrs;
- ParamAttrs.push_back($8);
- for (ValueRefList::iterator I = $6->begin(), E = $6->end(); I != E; ++I) {
+ ParamAttrsList ParamAttrs;
+ if ($8 != NoAttributeSet)
+ ParamAttrs.addAttributes(0, $8);
+ unsigned index = 1;
+ ValueRefList::iterator I = $6->begin(), E = $6->end();
+ for (; I != E; ++I, ++index) {
const Type *Ty = I->Val->getType();
if (Ty == Type::VoidTy)
GEN_ERROR("Short call syntax cannot be used with varargs");
ParamTypes.push_back(Ty);
- ParamAttrs.push_back(I->Attrs);
+ if (I->Attrs != NoAttributeSet)
+ ParamAttrs.addAttributes(index, I->Attrs);
}
- Ty = FunctionType::get($3->get(), ParamTypes, false, ParamAttrs);
+ ParamAttrsList *Attrs = 0;
+ if (!ParamAttrs.empty())
+ Attrs = new ParamAttrsList(ParamAttrs);
+
+ Ty = FunctionType::get($3->get(), ParamTypes, false, Attrs);
PFTy = PointerType::get(Ty);
}
#include "llvm/Instructions.h"
#include "llvm/Intrinsics.h"
#include "llvm/IntrinsicInst.h"
+#include "llvm/ParameterAttributes.h"
#include "llvm/CodeGen/MachineModuleInfo.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineFrameInfo.h"
else
TmpVT = MVT::i32;
const FunctionType *FTy = I.getParent()->getParent()->getFunctionType();
+ const ParamAttrsList *Attrs = FTy->getParamAttrs();
ISD::NodeType ExtendKind = ISD::ANY_EXTEND;
- if (FTy->paramHasAttr(0, FunctionType::SExtAttribute))
+ if (Attrs && Attrs->paramHasAttr(0, SExtAttribute))
ExtendKind = ISD::SIGN_EXTEND;
- if (FTy->paramHasAttr(0, FunctionType::ZExtAttribute))
+ if (Attrs && Attrs->paramHasAttr(0, ZExtAttribute))
ExtendKind = ISD::ZERO_EXTEND;
RetOp = DAG.getNode(ExtendKind, TmpVT, RetOp);
}
SDOperand Callee, unsigned OpIdx) {
const PointerType *PT = cast<PointerType>(CalledValueTy);
const FunctionType *FTy = cast<FunctionType>(PT->getElementType());
+ const ParamAttrsList *Attrs = FTy->getParamAttrs();
TargetLowering::ArgListTy Args;
TargetLowering::ArgListEntry Entry;
Value *Arg = I.getOperand(i);
SDOperand ArgNode = getValue(Arg);
Entry.Node = ArgNode; Entry.Ty = Arg->getType();
- Entry.isSExt = FTy->paramHasAttr(i, FunctionType::SExtAttribute);
- Entry.isZExt = FTy->paramHasAttr(i, FunctionType::ZExtAttribute);
- Entry.isInReg = FTy->paramHasAttr(i, FunctionType::InRegAttribute);
- Entry.isSRet = FTy->paramHasAttr(i, FunctionType::StructRetAttribute);
+ Entry.isSExt = Attrs && Attrs->paramHasAttr(i, SExtAttribute);
+ Entry.isZExt = Attrs && Attrs->paramHasAttr(i, ZExtAttribute);
+ Entry.isInReg = Attrs && Attrs->paramHasAttr(i, InRegAttribute);
+ Entry.isSRet = Attrs && Attrs->paramHasAttr(i, StructRetAttribute);
Args.push_back(Entry);
}
std::pair<SDOperand,SDOperand> Result =
TLI.LowerCallTo(getRoot(), I.getType(),
- FTy->paramHasAttr(0,FunctionType::SExtAttribute),
+ Attrs && Attrs->paramHasAttr(0, SExtAttribute),
FTy->isVarArg(), CallingConv, IsTailCall,
Callee, Args, DAG);
if (I.getType() != Type::VoidTy)
std::vector<SDOperand>
TargetLowering::LowerArguments(Function &F, SelectionDAG &DAG) {
const FunctionType *FTy = F.getFunctionType();
+ const ParamAttrsList *Attrs = FTy->getParamAttrs();
// Add CC# and isVararg as operands to the FORMAL_ARGUMENTS node.
std::vector<SDOperand> Ops;
Ops.push_back(DAG.getRoot());
// FIXME: Distinguish between a formal with no [sz]ext attribute from one
// that is zero extended!
- if (FTy->paramHasAttr(j, FunctionType::ZExtAttribute))
+ if (Attrs && Attrs->paramHasAttr(j, ZExtAttribute))
Flags &= ~(ISD::ParamFlags::SExt);
- if (FTy->paramHasAttr(j, FunctionType::SExtAttribute))
+ if (Attrs && Attrs->paramHasAttr(j, SExtAttribute))
Flags |= ISD::ParamFlags::SExt;
- if (FTy->paramHasAttr(j, FunctionType::InRegAttribute))
+ if (Attrs && Attrs->paramHasAttr(j, InRegAttribute))
Flags |= ISD::ParamFlags::InReg;
- if (FTy->paramHasAttr(j, FunctionType::StructRetAttribute))
+ if (Attrs && Attrs->paramHasAttr(j, StructRetAttribute))
Flags |= ISD::ParamFlags::StructReturn;
Flags |= (OriginalAlignment << ISD::ParamFlags::OrigAlignmentOffs);
case Promote: {
SDOperand Op(Result, i++);
if (MVT::isInteger(VT)) {
- if (FTy->paramHasAttr(Idx, FunctionType::SExtAttribute))
+ if (Attrs && Attrs->paramHasAttr(Idx, SExtAttribute))
Op = DAG.getNode(ISD::AssertSext, Op.getValueType(), Op,
DAG.getValueType(VT));
- else if (FTy->paramHasAttr(Idx, FunctionType::ZExtAttribute))
+ else if (Attrs && Attrs->paramHasAttr(Idx, ZExtAttribute))
Op = DAG.getNode(ISD::AssertZext, Op.getValueType(), Op,
DAG.getValueType(VT));
Op = DAG.getNode(ISD::TRUNCATE, VT, Op);
#include "llvm/DerivedTypes.h"
#include "llvm/Module.h"
#include "llvm/Instructions.h"
+#include "llvm/ParameterAttributes.h"
#include "llvm/Pass.h"
#include "llvm/PassManager.h"
#include "llvm/TypeSymbolTable.h"
FunctionType::param_iterator I = FTy->param_begin(), E = FTy->param_end();
const Type *RetTy = cast<PointerType>(I->get())->getElementType();
unsigned Idx = 1;
+ const ParamAttrsList *Attrs = FTy->getParamAttrs();
for (++I; I != E; ++I) {
if (PrintedType)
FunctionInnards << ", ";
printType(FunctionInnards, *I,
- /*isSigned=*/FTy->paramHasAttr(Idx, FunctionType::SExtAttribute), "");
+ /*isSigned=*/Attrs && Attrs->paramHasAttr(Idx, SExtAttribute), "");
PrintedType = true;
}
if (FTy->isVarArg()) {
FunctionInnards << ')';
std::string tstr = FunctionInnards.str();
printType(Out, RetTy,
- /*isSigned=*/FTy->paramHasAttr(0, FunctionType::SExtAttribute), tstr);
+ /*isSigned=*/Attrs && Attrs->paramHasAttr(0, SExtAttribute), tstr);
}
std::ostream &
const FunctionType *FTy = cast<FunctionType>(Ty);
std::stringstream FunctionInnards;
FunctionInnards << " (" << NameSoFar << ") (";
+ const ParamAttrsList *Attrs = FTy->getParamAttrs();
unsigned Idx = 1;
for (FunctionType::param_iterator I = FTy->param_begin(),
E = FTy->param_end(); I != E; ++I) {
if (I != FTy->param_begin())
FunctionInnards << ", ";
printType(FunctionInnards, *I,
- /*isSigned=*/FTy->paramHasAttr(Idx, FunctionType::SExtAttribute), "");
+ /*isSigned=*/Attrs && Attrs->paramHasAttr(Idx, SExtAttribute), "");
++Idx;
}
if (FTy->isVarArg()) {
FunctionInnards << ')';
std::string tstr = FunctionInnards.str();
printType(Out, FTy->getReturnType(),
- /*isSigned=*/FTy->paramHasAttr(0, FunctionType::SExtAttribute), tstr);
+ /*isSigned=*/Attrs && Attrs->paramHasAttr(0, SExtAttribute), tstr);
return Out;
}
case Type::StructTyID: {
// Loop over the arguments, printing them...
const FunctionType *FT = cast<FunctionType>(F->getFunctionType());
+ const ParamAttrsList *Attrs = FT->getParamAttrs();
std::stringstream FunctionInnards;
else
ArgName = "";
printType(FunctionInnards, I->getType(),
- /*isSigned=*/FT->paramHasAttr(Idx, FunctionType::SExtAttribute),
+ /*isSigned=*/Attrs && Attrs->paramHasAttr(Idx, SExtAttribute),
ArgName);
PrintedArg = true;
++Idx;
for (; I != E; ++I) {
if (PrintedArg) FunctionInnards << ", ";
printType(FunctionInnards, *I,
- /*isSigned=*/FT->paramHasAttr(Idx, FunctionType::SExtAttribute));
+ /*isSigned=*/Attrs && Attrs->paramHasAttr(Idx, SExtAttribute));
PrintedArg = true;
++Idx;
}
// Print out the return type and the signature built above.
printType(Out, RetTy,
- /*isSigned=*/FT->paramHasAttr(0, FunctionType::SExtAttribute),
+ /*isSigned=*/ Attrs && Attrs->paramHasAttr(0, SExtAttribute),
FunctionInnards.str());
}
++ArgNo;
}
+ const ParamAttrsList *Attrs = FTy->getParamAttrs();
bool PrintedArg = false;
unsigned Idx = 1;
for (; AI != AE; ++AI, ++ArgNo, ++Idx) {
(*AI)->getType() != FTy->getParamType(ArgNo)) {
Out << '(';
printType(Out, FTy->getParamType(ArgNo),
- /*isSigned=*/FTy->paramHasAttr(Idx, FunctionType::SExtAttribute));
+ /*isSigned=*/Attrs && Attrs->paramHasAttr(Idx, SExtAttribute));
Out << ')';
}
writeOperand(*AI);
#include "llvm/DerivedTypes.h"
#include "llvm/Intrinsics.h"
#include "llvm/IntrinsicInst.h"
+#include "llvm/ParameterAttributes.h"
#include "llvm/TypeSymbolTable.h"
#include "llvm/Analysis/ConstantsScanner.h"
#include "llvm/Support/CallSite.h"
void MSILWriter::printFunction(const Function& F) {
const FunctionType* FTy = F.getFunctionType();
- bool isSigned = FTy->paramHasAttr(0,FunctionType::SExtAttribute);
+ const ParamAttrsList *Attrs = FTy->getParamAttrs();
+ bool isSigned = Attrs && Attrs->paramHasAttr(0, SExtAttribute);
Out << "\n.method static ";
Out << (F.hasInternalLinkage() ? "private " : "public ");
if (F.isVarArg()) Out << "vararg ";
unsigned ArgIdx = 1;
for (Function::const_arg_iterator I = F.arg_begin(), E = F.arg_end(); I!=E;
++I, ++ArgIdx) {
- isSigned = FTy->paramHasAttr(ArgIdx,FunctionType::SExtAttribute);
+ isSigned = Attrs && Attrs->paramHasAttr(ArgIdx, SExtAttribute);
if (I!=F.arg_begin()) Out << ", ";
Out << getTypeName(I->getType(),isSigned) << getValueName(I);
}