aboutsummaryrefslogtreecommitdiffstats
path: root/lib/VMCore
diff options
context:
space:
mode:
Diffstat (limited to 'lib/VMCore')
-rw-r--r--lib/VMCore/AsmWriter.cpp51
-rw-r--r--lib/VMCore/AutoUpgrade.cpp11
-rw-r--r--lib/VMCore/Function.cpp34
-rw-r--r--lib/VMCore/Instructions.cpp44
-rw-r--r--lib/VMCore/Type.cpp56
-rw-r--r--lib/VMCore/Verifier.cpp6
6 files changed, 105 insertions, 97 deletions
diff --git a/lib/VMCore/AsmWriter.cpp b/lib/VMCore/AsmWriter.cpp
index 859807b..ef8161b 100644
--- a/lib/VMCore/AsmWriter.cpp
+++ b/lib/VMCore/AsmWriter.cpp
@@ -305,28 +305,17 @@ static void calcTypeName(const Type *Ty,
const FunctionType *FTy = cast<FunctionType>(Ty);
calcTypeName(FTy->getReturnType(), TypeStack, TypeNames, Result);
Result += " (";
- unsigned Idx = 1;
- const ParamAttrsList *Attrs = FTy->getParamAttrs();
for (FunctionType::param_iterator I = FTy->param_begin(),
- E = FTy->param_end(); I != E; ++I) {
+ E = FTy->param_end(); I != E; ++I) {
if (I != FTy->param_begin())
Result += ", ";
calcTypeName(*I, TypeStack, TypeNames, Result);
- if (Attrs && Attrs->getParamAttrs(Idx) != ParamAttr::None) {
- Result += + " ";
- Result += Attrs->getParamAttrsTextByIndex(Idx);
- }
- Idx++;
}
if (FTy->isVarArg()) {
if (FTy->getNumParams()) Result += ", ";
Result += "...";
}
Result += ")";
- if (Attrs && Attrs->getParamAttrs(0) != ParamAttr::None) {
- Result += " ";
- Result += Attrs->getParamAttrsTextByIndex(0);
- }
break;
}
case Type::StructTyID: {
@@ -749,6 +738,7 @@ public:
inline void write(const Type *Ty) { printType(Ty); }
void writeOperand(const Value *Op, bool PrintType);
+ void writeParamOperand(const Value *Operand, uint16_t Attrs);
const Module* getModule() { return TheModule; }
@@ -789,25 +779,17 @@ std::ostream &AssemblyWriter::printTypeAtLeastOneLevel(const Type *Ty) {
else if (const FunctionType *FTy = dyn_cast<FunctionType>(Ty)) {
printType(FTy->getReturnType());
Out << " (";
- unsigned Idx = 1;
- const ParamAttrsList *Attrs = FTy->getParamAttrs();
for (FunctionType::param_iterator I = FTy->param_begin(),
E = FTy->param_end(); I != E; ++I) {
if (I != FTy->param_begin())
Out << ", ";
printType(*I);
- if (Attrs && Attrs->getParamAttrs(Idx) != ParamAttr::None) {
- Out << " " << Attrs->getParamAttrsTextByIndex(Idx);
- }
- Idx++;
}
if (FTy->isVarArg()) {
if (FTy->getNumParams()) Out << ", ";
Out << "...";
}
Out << ')';
- if (Attrs && Attrs->getParamAttrs(0) != ParamAttr::None)
- Out << ' ' << Attrs->getParamAttrsTextByIndex(0);
} else if (const StructType *STy = dyn_cast<StructType>(Ty)) {
if (STy->isPacked())
Out << '<';
@@ -850,6 +832,20 @@ void AssemblyWriter::writeOperand(const Value *Operand, bool PrintType) {
}
}
+void AssemblyWriter::writeParamOperand(const Value *Operand, uint16_t Attrs) {
+ if (Operand == 0) {
+ Out << "<null operand!>";
+ } else {
+ Out << ' ';
+ // Print the type
+ printType(Operand->getType());
+ // Print parameter attributes list
+ if (Attrs != ParamAttr::None)
+ Out << ' ' << ParamAttrsList::getParamAttrsText(Attrs);
+ // Print the operand
+ WriteAsOperandInternal(Out, Operand, TypeNames, &Machine);
+ }
+}
void AssemblyWriter::printModule(const Module *M) {
if (!M->getModuleIdentifier().empty() &&
@@ -1066,7 +1062,7 @@ void AssemblyWriter::printFunction(const Function *F) {
}
const FunctionType *FT = F->getFunctionType();
- const ParamAttrsList *Attrs = FT->getParamAttrs();
+ const ParamAttrsList *Attrs = F->getParamAttrs();
printType(F->getReturnType()) << ' ';
if (!F->getName().empty())
Out << getLLVMName(F->getName(), GlobalPrefix);
@@ -1139,6 +1135,7 @@ void AssemblyWriter::printArgument(const Argument *Arg, uint16_t Attrs) {
// Output type...
printType(Arg->getType());
+ // Output parameter attributes list
if (Attrs != ParamAttr::None)
Out << ' ' << ParamAttrsList::getParamAttrsText(Attrs);
@@ -1295,7 +1292,7 @@ void AssemblyWriter::printInstruction(const Instruction &I) {
const PointerType *PTy = cast<PointerType>(Operand->getType());
const FunctionType *FTy = cast<FunctionType>(PTy->getElementType());
const Type *RetTy = FTy->getReturnType();
- const ParamAttrsList *PAL = FTy->getParamAttrs();
+ const ParamAttrsList *PAL = CI->getParamAttrs();
// If possible, print out the short form of the call instruction. We can
// only do this if the first argument is a pointer to a nonvararg function,
@@ -1313,9 +1310,7 @@ void AssemblyWriter::printInstruction(const Instruction &I) {
for (unsigned op = 1, Eop = I.getNumOperands(); op < Eop; ++op) {
if (op > 1)
Out << ',';
- writeOperand(I.getOperand(op), true);
- if (PAL && PAL->getParamAttrs(op) != ParamAttr::None)
- Out << " " << PAL->getParamAttrsTextByIndex(op);
+ writeParamOperand(I.getOperand(op), PAL ? PAL->getParamAttrs(op) : 0);
}
Out << " )";
if (PAL && PAL->getParamAttrs(0) != ParamAttr::None)
@@ -1324,7 +1319,7 @@ void AssemblyWriter::printInstruction(const Instruction &I) {
const PointerType *PTy = cast<PointerType>(Operand->getType());
const FunctionType *FTy = cast<FunctionType>(PTy->getElementType());
const Type *RetTy = FTy->getReturnType();
- const ParamAttrsList *PAL = FTy->getParamAttrs();
+ const ParamAttrsList *PAL = II->getParamAttrs();
// Print the calling convention being used.
switch (II->getCallingConv()) {
@@ -1353,9 +1348,7 @@ void AssemblyWriter::printInstruction(const Instruction &I) {
for (unsigned op = 3, Eop = I.getNumOperands(); op < Eop; ++op) {
if (op > 3)
Out << ',';
- writeOperand(I.getOperand(op), true);
- if (PAL && PAL->getParamAttrs(op-2) != ParamAttr::None)
- Out << " " << PAL->getParamAttrsTextByIndex(op-2);
+ writeParamOperand(I.getOperand(op), PAL ? PAL->getParamAttrs(op-2) : 0);
}
Out << " )";
diff --git a/lib/VMCore/AutoUpgrade.cpp b/lib/VMCore/AutoUpgrade.cpp
index b56fe70..40c431c 100644
--- a/lib/VMCore/AutoUpgrade.cpp
+++ b/lib/VMCore/AutoUpgrade.cpp
@@ -127,9 +127,6 @@ void llvm::UpgradeIntrinsicCall(CallInst *CI, Function *NewFn) {
Function *F = CI->getCalledFunction();
assert(F && "CallInst has no function associated with it.");
-
- const FunctionType *FTy = F->getFunctionType();
- const FunctionType *NewFnTy = NewFn->getFunctionType();
switch(NewFn->getIntrinsicID()) {
default: assert(0 && "Unknown function for CallInst upgrade.");
@@ -149,10 +146,10 @@ void llvm::UpgradeIntrinsicCall(CallInst *CI, Function *NewFn) {
// Handle any uses of the old CallInst.
if (!CI->use_empty()) {
// Check for sign extend parameter attributes on the return values.
- bool SrcSExt = NewFnTy->getParamAttrs() &&
- NewFnTy->getParamAttrs()->paramHasAttr(0,ParamAttr::SExt);
- bool DestSExt = FTy->getParamAttrs() &&
- FTy->getParamAttrs()->paramHasAttr(0,ParamAttr::SExt);
+ bool SrcSExt = NewFn->getParamAttrs() &&
+ NewFn->getParamAttrs()->paramHasAttr(0,ParamAttr::SExt);
+ bool DestSExt = F->getParamAttrs() &&
+ F->getParamAttrs()->paramHasAttr(0,ParamAttr::SExt);
// Construct an appropriate cast from the new return type to the old.
CastInst *RetCast = CastInst::create(
diff --git a/lib/VMCore/Function.cpp b/lib/VMCore/Function.cpp
index 2b83e6b..023cb55 100644
--- a/lib/VMCore/Function.cpp
+++ b/lib/VMCore/Function.cpp
@@ -161,7 +161,7 @@ ParamAttrsList::areCompatible(const ParamAttrsList *A, const ParamAttrsList *B){
void
ParamAttrsList::Profile(FoldingSetNodeID &ID) const {
for (unsigned i = 0; i < attrs.size(); ++i) {
- unsigned val = attrs[i].attrs << 16 | attrs[i].index;
+ uint32_t val = uint32_t(attrs[i].attrs) << 16 | attrs[i].index;
ID.AddInteger(val);
}
}
@@ -170,7 +170,10 @@ static ManagedStatic<FoldingSet<ParamAttrsList> > ParamAttrsLists;
ParamAttrsList *
ParamAttrsList::get(const ParamAttrsVector &attrVec) {
- assert(!attrVec.empty() && "Illegal to create empty ParamAttrsList");
+ // If there are no attributes then return a null ParamAttrsList pointer.
+ if (attrVec.empty())
+ return 0;
+
#ifndef NDEBUG
for (unsigned i = 0, e = attrVec.size(); i < e; ++i) {
assert(attrVec[i].attrs != ParamAttr::None
@@ -179,15 +182,22 @@ ParamAttrsList::get(const ParamAttrsVector &attrVec) {
&& "Misordered ParamAttrsList!");
}
#endif
+
+ // Otherwise, build a key to look up the existing attributes.
ParamAttrsList key(attrVec);
FoldingSetNodeID ID;
key.Profile(ID);
void *InsertPos;
ParamAttrsList* PAL = ParamAttrsLists->FindNodeOrInsertPos(ID, InsertPos);
+
+ // If we didn't find any existing attributes of the same shape then
+ // create a new one and insert it.
if (!PAL) {
PAL = new ParamAttrsList(attrVec);
ParamAttrsLists->InsertNode(PAL, InsertPos);
}
+
+ // Return the ParamAttrsList that we found or created.
return PAL;
}
@@ -201,8 +211,8 @@ ParamAttrsList::~ParamAttrsList() {
Function::Function(const FunctionType *Ty, LinkageTypes Linkage,
const std::string &name, Module *ParentModule)
- : GlobalValue(PointerType::get(Ty), Value::FunctionVal, 0, 0, Linkage, name) {
- ParamAttrs = 0;
+ : GlobalValue(PointerType::get(Ty), Value::FunctionVal, 0, 0, Linkage, name),
+ ParamAttrs(0) {
SymTab = new ValueSymbolTable();
assert((getReturnType()->isFirstClassType() ||getReturnType() == Type::VoidTy)
@@ -259,16 +269,30 @@ void Function::setParent(Module *parent) {
LeakDetector::removeGarbageObject(this);
}
-void Function::setParamAttrs(ParamAttrsList *attrs) {
+void Function::setParamAttrs(const ParamAttrsList *attrs) {
+ // Avoid deleting the ParamAttrsList if they are setting the
+ // attributes to the same list.
+ if (ParamAttrs == attrs)
+ return;
+
+ // Drop reference on the old ParamAttrsList
if (ParamAttrs)
ParamAttrs->dropRef();
+ // Add reference to the new ParamAttrsList
if (attrs)
attrs->addRef();
+ // Set the new ParamAttrsList.
ParamAttrs = attrs;
}
+bool Function::isStructReturn() const {
+ if (ParamAttrs)
+ return ParamAttrs->paramHasAttr(1, ParamAttr::StructRet);
+ return false;
+}
+
const FunctionType *Function::getFunctionType() const {
return cast<FunctionType>(getType()->getElementType());
}
diff --git a/lib/VMCore/Instructions.cpp b/lib/VMCore/Instructions.cpp
index 6bee186..7226f66 100644
--- a/lib/VMCore/Instructions.cpp
+++ b/lib/VMCore/Instructions.cpp
@@ -35,6 +35,18 @@ void CallSite::setCallingConv(unsigned CC) {
else
cast<InvokeInst>(I)->setCallingConv(CC);
}
+const ParamAttrsList* CallSite::getParamAttrs() const {
+ if (CallInst *CI = dyn_cast<CallInst>(I))
+ return CI->getParamAttrs();
+ else
+ return cast<InvokeInst>(I)->getParamAttrs();
+}
+void CallSite::setParamAttrs(const ParamAttrsList *PAL) {
+ if (CallInst *CI = dyn_cast<CallInst>(I))
+ CI->setParamAttrs(PAL);
+ else
+ cast<InvokeInst>(I)->setParamAttrs(PAL);
+}
@@ -341,8 +353,9 @@ CallInst::CallInst(Value *Func, const std::string &Name,
CallInst::CallInst(const CallInst &CI)
: Instruction(CI.getType(), Instruction::Call, new Use[CI.getNumOperands()],
- CI.getNumOperands()) {
- ParamAttrs = 0;
+ CI.getNumOperands()),
+ ParamAttrs(0) {
+ setParamAttrs(CI.getParamAttrs());
SubclassData = CI.SubclassData;
Use *OL = OperandList;
Use *InOL = CI.OperandList;
@@ -350,7 +363,10 @@ CallInst::CallInst(const CallInst &CI)
OL[i].init(InOL[i], this);
}
-void CallInst::setParamAttrs(ParamAttrsList *newAttrs) {
+void CallInst::setParamAttrs(const ParamAttrsList *newAttrs) {
+ if (ParamAttrs == newAttrs)
+ return;
+
if (ParamAttrs)
ParamAttrs->dropRef();
@@ -360,6 +376,12 @@ void CallInst::setParamAttrs(ParamAttrsList *newAttrs) {
ParamAttrs = newAttrs;
}
+bool CallInst::isStructReturn() const {
+ if (ParamAttrs)
+ return ParamAttrs->paramHasAttr(1, ParamAttr::StructRet);
+ return false;
+}
+
//===----------------------------------------------------------------------===//
// InvokeInst Implementation
//===----------------------------------------------------------------------===//
@@ -397,8 +419,9 @@ void InvokeInst::init(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
InvokeInst::InvokeInst(const InvokeInst &II)
: TerminatorInst(II.getType(), Instruction::Invoke,
- new Use[II.getNumOperands()], II.getNumOperands()) {
- ParamAttrs = 0;
+ new Use[II.getNumOperands()], II.getNumOperands()),
+ ParamAttrs(0) {
+ setParamAttrs(II.getParamAttrs());
SubclassData = II.SubclassData;
Use *OL = OperandList, *InOL = II.OperandList;
for (unsigned i = 0, e = II.getNumOperands(); i != e; ++i)
@@ -415,7 +438,10 @@ void InvokeInst::setSuccessorV(unsigned idx, BasicBlock *B) {
return setSuccessor(idx, B);
}
-void InvokeInst::setParamAttrs(ParamAttrsList *newAttrs) {
+void InvokeInst::setParamAttrs(const ParamAttrsList *newAttrs) {
+ if (ParamAttrs == newAttrs)
+ return;
+
if (ParamAttrs)
ParamAttrs->dropRef();
@@ -425,6 +451,12 @@ void InvokeInst::setParamAttrs(ParamAttrsList *newAttrs) {
ParamAttrs = newAttrs;
}
+bool InvokeInst::isStructReturn() const {
+ if (ParamAttrs)
+ return ParamAttrs->paramHasAttr(1, ParamAttr::StructRet);
+ return false;
+}
+
//===----------------------------------------------------------------------===//
// ReturnInst Implementation
//===----------------------------------------------------------------------===//
diff --git a/lib/VMCore/Type.cpp b/lib/VMCore/Type.cpp
index b8ce47b..1e58477 100644
--- a/lib/VMCore/Type.cpp
+++ b/lib/VMCore/Type.cpp
@@ -12,7 +12,6 @@
//===----------------------------------------------------------------------===//
#include "llvm/DerivedTypes.h"
-#include "llvm/ParameterAttributes.h"
#include "llvm/Constants.h"
#include "llvm/ADT/DepthFirstIterator.h"
#include "llvm/ADT/StringExtras.h"
@@ -307,15 +306,10 @@ static std::string getTypeDescription(const Type *Ty,
if (!Result.empty())
Result += " ";
Result += getTypeDescription(FTy->getReturnType(), TypeStack) + " (";
- unsigned Idx = 1;
- const ParamAttrsList *Attrs = FTy->getParamAttrs();
for (FunctionType::param_iterator I = FTy->param_begin(),
- E = FTy->param_end(); I != E; ++I) {
+ E = FTy->param_end(); I != E; ++I) {
if (I != FTy->param_begin())
Result += ", ";
- if (Attrs && Attrs->getParamAttrs(Idx) != ParamAttr::None)
- Result += Attrs->getParamAttrsTextByIndex(Idx);
- Idx++;
Result += getTypeDescription(*I, TypeStack);
}
if (FTy->isVarArg()) {
@@ -323,9 +317,6 @@ static std::string getTypeDescription(const Type *Ty,
Result += "...";
}
Result += ")";
- if (Attrs && Attrs->getParamAttrs(0) != ParamAttr::None) {
- Result += " " + Attrs->getParamAttrsTextByIndex(0);
- }
break;
}
case Type::StructTyID: {
@@ -444,8 +435,8 @@ const IntegerType *Type::Int64Ty = new BuiltinIntegerType(64);
FunctionType::FunctionType(const Type *Result,
const std::vector<const Type*> &Params,
- bool IsVarArgs, const ParamAttrsList *Attrs)
- : DerivedType(FunctionTyID), isVarArgs(IsVarArgs), ParamAttrs(Attrs) {
+ bool IsVarArgs)
+ : DerivedType(FunctionTyID), isVarArgs(IsVarArgs) {
ContainedTys = reinterpret_cast<PATypeHandle*>(this+1);
NumContainedTys = Params.size() + 1; // + 1 for result type
assert((Result->isFirstClassType() || Result == Type::VoidTy ||
@@ -667,16 +658,7 @@ static bool TypesEqual(const Type *Ty, const Type *Ty2,
FTy->getNumParams() != FTy2->getNumParams() ||
!TypesEqual(FTy->getReturnType(), FTy2->getReturnType(), EqTypes))
return false;
- const ParamAttrsList *Attrs1 = FTy->getParamAttrs();
- const ParamAttrsList *Attrs2 = FTy2->getParamAttrs();
- if ((!Attrs1 && Attrs2) || (!Attrs2 && Attrs1) ||
- (Attrs1 && Attrs2 && (Attrs1->size() != Attrs2->size() ||
- (Attrs1->getParamAttrs(0) != Attrs2->getParamAttrs(0)))))
- return false;
-
for (unsigned i = 0, e = FTy2->getNumParams(); i != e; ++i) {
- if (Attrs1 && Attrs1->getParamAttrs(i+1) != Attrs2->getParamAttrs(i+1))
- return false;
if (!TypesEqual(FTy->getParamType(i), FTy2->getParamType(i), EqTypes))
return false;
}
@@ -1055,12 +1037,10 @@ namespace llvm {
class FunctionValType {
const Type *RetTy;
std::vector<const Type*> ArgTypes;
- const ParamAttrsList *ParamAttrs;
bool isVarArg;
public:
FunctionValType(const Type *ret, const std::vector<const Type*> &args,
- bool IVA, const ParamAttrsList *attrs)
- : RetTy(ret), ParamAttrs(attrs), isVarArg(IVA) {
+ bool isVA) : RetTy(ret), isVarArg(isVA) {
for (unsigned i = 0; i < args.size(); ++i)
ArgTypes.push_back(args[i]);
}
@@ -1068,9 +1048,7 @@ public:
static FunctionValType get(const FunctionType *FT);
static unsigned hashTypeStructure(const FunctionType *FT) {
- unsigned Result = FT->getNumParams()*64 + FT->isVarArg();
- if (FT->getParamAttrs())
- Result += FT->getParamAttrs()->size()*2;
+ unsigned Result = FT->getNumParams()*2 + FT->isVarArg();
return Result;
}
@@ -1081,13 +1059,6 @@ public:
if (isVarArg > MTV.isVarArg) return false;
if (ArgTypes < MTV.ArgTypes) return true;
if (ArgTypes > MTV.ArgTypes) return false;
- if (ParamAttrs)
- if (MTV.ParamAttrs)
- return *ParamAttrs < *MTV.ParamAttrs;
- else
- return false;
- else if (MTV.ParamAttrs)
- return true;
return false;
}
};
@@ -1102,18 +1073,15 @@ FunctionValType FunctionValType::get(const FunctionType *FT) {
ParamTypes.reserve(FT->getNumParams());
for (unsigned i = 0, e = FT->getNumParams(); i != e; ++i)
ParamTypes.push_back(FT->getParamType(i));
- return FunctionValType(FT->getReturnType(), ParamTypes, FT->isVarArg(),
- FT->getParamAttrs());
+ return FunctionValType(FT->getReturnType(), ParamTypes, FT->isVarArg());
}
// FunctionType::get - The factory function for the FunctionType class...
FunctionType *FunctionType::get(const Type *ReturnType,
const std::vector<const Type*> &Params,
- bool isVarArg,
- const ParamAttrsList *Attrs) {
-
- FunctionValType VT(ReturnType, Params, isVarArg, Attrs);
+ bool isVarArg) {
+ FunctionValType VT(ReturnType, Params, isVarArg);
FunctionType *FT = FunctionTypes->get(VT);
if (FT) {
return FT;
@@ -1121,7 +1089,7 @@ FunctionType *FunctionType::get(const Type *ReturnType,
FT = (FunctionType*) new char[sizeof(FunctionType) +
sizeof(PATypeHandle)*(Params.size()+1)];
- new (FT) FunctionType(ReturnType, Params, isVarArg, Attrs);
+ new (FT) FunctionType(ReturnType, Params, isVarArg);
FunctionTypes->add(VT, FT);
#ifdef DEBUG_MERGE_TYPES
@@ -1130,12 +1098,6 @@ FunctionType *FunctionType::get(const Type *ReturnType,
return FT;
}
-bool FunctionType::isStructReturn() const {
- if (ParamAttrs)
- return ParamAttrs->paramHasAttr(1, ParamAttr::StructRet);
- return false;
-}
-
//===----------------------------------------------------------------------===//
// Array Type Factory...
//
diff --git a/lib/VMCore/Verifier.cpp b/lib/VMCore/Verifier.cpp
index a547721..eb7c90f 100644
--- a/lib/VMCore/Verifier.cpp
+++ b/lib/VMCore/Verifier.cpp
@@ -390,12 +390,12 @@ void Verifier::visitFunction(Function &F) {
F.getReturnType() == Type::VoidTy,
"Functions cannot return aggregate values!", &F);
- Assert1(!FT->isStructReturn() || FT->getReturnType() == Type::VoidTy,
+ Assert1(!F.isStructReturn() || FT->getReturnType() == Type::VoidTy,
"Invalid struct-return function!", &F);
bool SawSRet = false;
- if (const ParamAttrsList *Attrs = FT->getParamAttrs()) {
+ if (const ParamAttrsList *Attrs = F.getParamAttrs()) {
bool SawNest = false;
for (unsigned Idx = 0; Idx <= FT->getNumParams(); ++Idx) {
@@ -448,7 +448,7 @@ void Verifier::visitFunction(Function &F) {
}
}
- Assert1(SawSRet == FT->isStructReturn(),
+ Assert1(SawSRet == F.isStructReturn(),
"StructReturn function with no sret attribute!", &F);
// Check that this function meets the restrictions on this calling convention.