From dc024674ff96820d6020757b48d47f46d4c07db2 Mon Sep 17 00:00:00 2001 From: Duncan Sands Date: Tue, 27 Nov 2007 13:23:08 +0000 Subject: Fix PR1146: parameter attributes are longer part of the function type, instead they belong to functions and function calls. This is an updated and slightly corrected version of Reid Spencer's original patch. The only known problem is that auto-upgrading of bitcode files doesn't seem to work properly (see test/Bitcode/AutoUpgradeIntrinsics.ll). Hopefully a bitcode guru (who might that be? :) ) will fix it. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44359 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Bitcode/Writer/BitcodeWriter.cpp | 37 ++++++++++------------------------ lib/Bitcode/Writer/ValueEnumerator.cpp | 17 +++++++++++----- 2 files changed, 23 insertions(+), 31 deletions(-) (limited to 'lib/Bitcode/Writer') diff --git a/lib/Bitcode/Writer/BitcodeWriter.cpp b/lib/Bitcode/Writer/BitcodeWriter.cpp index 6bf27123c9..9249c70209 100644 --- a/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -147,8 +147,6 @@ static void WriteTypeTable(const ValueEnumerator &VE, BitstreamWriter &Stream) { Abbv = new BitCodeAbbrev(); Abbv->Add(BitCodeAbbrevOp(bitc::TYPE_CODE_FUNCTION)); Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isvararg - Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, - Log2_32_Ceil(VE.getParamAttrs().size()+1))); Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, Log2_32_Ceil(VE.getTypes().size()+1))); @@ -206,10 +204,9 @@ static void WriteTypeTable(const ValueEnumerator &VE, BitstreamWriter &Stream) { case Type::FunctionTyID: { const FunctionType *FT = cast(T); - // FUNCTION: [isvararg, attrid, retty, paramty x N] + // FUNCTION: [isvararg, retty, paramty x N] Code = bitc::TYPE_CODE_FUNCTION; TypeVals.push_back(FT->isVarArg()); - TypeVals.push_back(VE.getParamAttrID(FT->getParamAttrs())); TypeVals.push_back(VE.getTypeID(FT->getReturnType())); for (unsigned i = 0, e = FT->getNumParams(); i != e; ++i) TypeVals.push_back(VE.getTypeID(FT->getParamType(i))); @@ -383,18 +380,13 @@ static void WriteModuleInfo(const Module *M, const ValueEnumerator &VE, // Emit the function proto information. for (Module::const_iterator F = M->begin(), E = M->end(); F != E; ++F) { - // FUNCTION: [type, callingconv, isproto, linkage, alignment, section, - // visibility] + // FUNCTION: [type, callingconv, isproto, paramattr, + // linkage, alignment, section, visibility] Vals.push_back(VE.getTypeID(F->getType())); Vals.push_back(F->getCallingConv()); Vals.push_back(F->isDeclaration()); Vals.push_back(getEncodedLinkage(F)); - - // Note: we emit the param attr ID number for the function type of this - // function. In the future, we intend for attrs to be properties of - // functions, instead of on the type. This is to support this future work. - Vals.push_back(VE.getParamAttrID(F->getFunctionType()->getParamAttrs())); - + Vals.push_back(VE.getParamAttrID(F->getParamAttrs())); Vals.push_back(Log2_32(F->getAlignment())+1); Vals.push_back(F->hasSection() ? SectionMap[F->getSection()] : 0); Vals.push_back(getEncodedVisibility(F)); @@ -760,12 +752,9 @@ static void WriteInstruction(const Instruction &I, unsigned InstID, const FunctionType *FTy = cast(PTy->getElementType()); Code = bitc::FUNC_CODE_INST_INVOKE; - // Note: we emit the param attr ID number for the function type of this - // function. In the future, we intend for attrs to be properties of - // functions, instead of on the type. This is to support this future work. - Vals.push_back(VE.getParamAttrID(FTy->getParamAttrs())); - - Vals.push_back(cast(I).getCallingConv()); + const InvokeInst *II = cast(&I); + Vals.push_back(VE.getParamAttrID(II->getParamAttrs())); + Vals.push_back(II->getCallingConv()); Vals.push_back(VE.getValueID(I.getOperand(1))); // normal dest Vals.push_back(VE.getValueID(I.getOperand(2))); // unwind dest PushValueAndType(I.getOperand(0), InstID, Vals, VE); // callee @@ -837,14 +826,10 @@ static void WriteInstruction(const Instruction &I, unsigned InstID, Code = bitc::FUNC_CODE_INST_CALL; - // Note: we emit the param attr ID number for the function type of this - // function. In the future, we intend for attrs to be properties of - // functions, instead of on the type. This is to support this future work. - Vals.push_back(VE.getParamAttrID(FTy->getParamAttrs())); - - Vals.push_back((cast(I).getCallingConv() << 1) | - unsigned(cast(I).isTailCall())); - PushValueAndType(I.getOperand(0), InstID, Vals, VE); // Callee + const CallInst *CI = cast(&I); + Vals.push_back(VE.getParamAttrID(CI->getParamAttrs())); + Vals.push_back((CI->getCallingConv() << 1) | unsigned(CI->isTailCall())); + PushValueAndType(CI->getOperand(0), InstID, Vals, VE); // Callee // Emit value #'s for the fixed parameters. for (unsigned i = 0, e = FTy->getNumParams(); i != e; ++i) diff --git a/lib/Bitcode/Writer/ValueEnumerator.cpp b/lib/Bitcode/Writer/ValueEnumerator.cpp index 6b3885ed1c..21b03725ff 100644 --- a/lib/Bitcode/Writer/ValueEnumerator.cpp +++ b/lib/Bitcode/Writer/ValueEnumerator.cpp @@ -17,6 +17,7 @@ #include "llvm/Module.h" #include "llvm/TypeSymbolTable.h" #include "llvm/ValueSymbolTable.h" +#include "llvm/Instructions.h" #include using namespace llvm; @@ -44,8 +45,10 @@ ValueEnumerator::ValueEnumerator(const Module *M) { EnumerateValue(I); // Enumerate the functions. - for (Module::const_iterator I = M->begin(), E = M->end(); I != E; ++I) + for (Module::const_iterator I = M->begin(), E = M->end(); I != E; ++I) { EnumerateValue(I); + EnumerateParamAttrs(cast(I)->getParamAttrs()); + } // Enumerate the aliases. for (Module::const_alias_iterator I = M->alias_begin(), E = M->alias_end(); @@ -86,6 +89,10 @@ ValueEnumerator::ValueEnumerator(const Module *M) { OI != E; ++OI) EnumerateOperandType(*OI); EnumerateType(I->getType()); + if (const CallInst *CI = dyn_cast(I)) + EnumerateParamAttrs(CI->getParamAttrs()); + else if (const InvokeInst *II = dyn_cast(I)) + EnumerateParamAttrs(II->getParamAttrs()); } } @@ -220,10 +227,6 @@ void ValueEnumerator::EnumerateType(const Type *Ty) { for (Type::subtype_iterator I = Ty->subtype_begin(), E = Ty->subtype_end(); I != E; ++I) EnumerateType(*I); - - // If this is a function type, enumerate the param attrs. - if (const FunctionType *FTy = dyn_cast(Ty)) - EnumerateParamAttrs(FTy->getParamAttrs()); } // Enumerate the types for the specified value. If the value is a constant, @@ -296,6 +299,10 @@ void ValueEnumerator::incorporateFunction(const Function &F) { // Optimize the constant layout. OptimizeConstants(FirstFuncConstantID, Values.size()); + // Add the function's parameter attributes so they are available for use in + // the function's instruction. + EnumerateParamAttrs(F.getParamAttrs()); + FirstInstID = Values.size(); // Add all of the instructions. -- cgit v1.2.3-70-g09d2