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
This commit is contained in:
Duncan Sands
2007-11-27 13:23:08 +00:00
parent f19341dec7
commit dc024674ff
51 changed files with 6340 additions and 5206 deletions

View File

@ -329,15 +329,15 @@ bool BitcodeReader::ParseTypeTable() {
ResultTy = PointerType::get(getTypeByID(Record[0], true));
break;
case bitc::TYPE_CODE_FUNCTION: {
// FUNCTION: [vararg, attrid, retty, paramty x N]
if (Record.size() < 3)
// FUNCTION: [vararg, retty, paramty x N]
if (Record.size() < 2)
return Error("Invalid FUNCTION type record");
std::vector<const Type*> ArgTys;
for (unsigned i = 3, e = Record.size(); i != e; ++i)
for (unsigned i = 2, e = Record.size(); i != e; ++i)
ArgTys.push_back(getTypeByID(Record[i], true));
ResultTy = FunctionType::get(getTypeByID(Record[2], true), ArgTys,
Record[0], getParamAttrs(Record[1]));
ResultTy = FunctionType::get(getTypeByID(Record[1], true), ArgTys,
Record[0]);
break;
}
case bitc::TYPE_CODE_STRUCT: { // STRUCT: [ispacked, eltty x N]
@ -1033,9 +1033,8 @@ bool BitcodeReader::ParseModule(const std::string &ModuleID) {
Func->setCallingConv(Record[1]);
bool isProto = Record[2];
Func->setLinkage(GetDecodedLinkage(Record[3]));
assert(Func->getFunctionType()->getParamAttrs() ==
getParamAttrs(Record[4]));
const ParamAttrsList *PAL = getParamAttrs(Record[4]);
Func->setParamAttrs(PAL);
Func->setAlignment((1 << Record[5]) >> 1);
if (Record[6]) {
@ -1360,8 +1359,10 @@ bool BitcodeReader::ParseFunctionBody(Function *F) {
break;
}
case bitc::FUNC_CODE_INST_INVOKE: { // INVOKE: [cc,fnty, op0,op1,op2, ...]
case bitc::FUNC_CODE_INST_INVOKE: {
// INVOKE: [attrs, cc, normBB, unwindBB, fnty, op0,op1,op2, ...]
if (Record.size() < 4) return Error("Invalid INVOKE record");
const ParamAttrsList *PAL = getParamAttrs(Record[0]);
unsigned CCInfo = Record[1];
BasicBlock *NormalBB = getBasicBlock(Record[2]);
BasicBlock *UnwindBB = getBasicBlock(Record[3]);
@ -1380,8 +1381,6 @@ bool BitcodeReader::ParseFunctionBody(Function *F) {
Record.size() < OpNum+FTy->getNumParams())
return Error("Invalid INVOKE record");
assert(FTy->getParamAttrs() == getParamAttrs(Record[0]));
SmallVector<Value*, 16> Ops;
for (unsigned i = 0, e = FTy->getNumParams(); i != e; ++i, ++OpNum) {
Ops.push_back(getFnValueByID(Record[OpNum], FTy->getParamType(i)));
@ -1403,6 +1402,7 @@ bool BitcodeReader::ParseFunctionBody(Function *F) {
I = new InvokeInst(Callee, NormalBB, UnwindBB, Ops.begin(), Ops.end());
cast<InvokeInst>(I)->setCallingConv(CCInfo);
cast<InvokeInst>(I)->setParamAttrs(PAL);
break;
}
case bitc::FUNC_CODE_INST_UNWIND: // UNWIND
@ -1482,10 +1482,12 @@ bool BitcodeReader::ParseFunctionBody(Function *F) {
I = new StoreInst(Val, Ptr, Record[OpNum+1], (1 << Record[OpNum]) >> 1);
break;
}
case bitc::FUNC_CODE_INST_CALL: { // CALL: [cc, fnty, fnid, arg0, arg1...]
if (Record.size() < 2)
case bitc::FUNC_CODE_INST_CALL: {
// CALL: [paramattrs, cc, fnty, fnid, arg0, arg1...]
if (Record.size() < 3)
return Error("Invalid CALL record");
const ParamAttrsList *PAL = getParamAttrs(Record[0]);
unsigned CCInfo = Record[1];
unsigned OpNum = 2;
@ -1499,8 +1501,6 @@ bool BitcodeReader::ParseFunctionBody(Function *F) {
if (!FTy || Record.size() < FTy->getNumParams()+OpNum)
return Error("Invalid CALL record");
assert(FTy->getParamAttrs() == getParamAttrs(Record[0]));
SmallVector<Value*, 16> Args;
// Read the fixed params.
for (unsigned i = 0, e = FTy->getNumParams(); i != e; ++i, ++OpNum) {
@ -1527,6 +1527,7 @@ bool BitcodeReader::ParseFunctionBody(Function *F) {
I = new CallInst(Callee, Args.begin(), Args.end());
cast<CallInst>(I)->setCallingConv(CCInfo>>1);
cast<CallInst>(I)->setTailCall(CCInfo & 1);
cast<CallInst>(I)->setParamAttrs(PAL);
break;
}
case bitc::FUNC_CODE_INST_VAARG: { // VAARG: [valistty, valist, instty]

View File

@ -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<FunctionType>(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<FunctionType>(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<InvokeInst>(I).getCallingConv());
const InvokeInst *II = cast<InvokeInst>(&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<CallInst>(I).getCallingConv() << 1) |
unsigned(cast<CallInst>(I).isTailCall()));
PushValueAndType(I.getOperand(0), InstID, Vals, VE); // Callee
const CallInst *CI = cast<CallInst>(&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)

View File

@ -17,6 +17,7 @@
#include "llvm/Module.h"
#include "llvm/TypeSymbolTable.h"
#include "llvm/ValueSymbolTable.h"
#include "llvm/Instructions.h"
#include <algorithm>
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<Function>(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<CallInst>(I))
EnumerateParamAttrs(CI->getParamAttrs());
else if (const InvokeInst *II = dyn_cast<InvokeInst>(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<FunctionType>(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.