diff options
Diffstat (limited to 'contrib/llvm/lib/Bitcode')
-rw-r--r-- | contrib/llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 26 | ||||
-rw-r--r-- | contrib/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | 33 | ||||
-rw-r--r-- | contrib/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp | 13 | ||||
-rw-r--r-- | contrib/llvm/lib/Bitcode/Writer/ValueEnumerator.h | 7 |
4 files changed, 44 insertions, 35 deletions
diff --git a/contrib/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/contrib/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index 69adead..b3f0776 100644 --- a/contrib/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/contrib/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -75,6 +75,7 @@ static GlobalValue::LinkageTypes GetDecodedLinkage(unsigned Val) { case 11: return GlobalValue::LinkOnceODRLinkage; case 12: return GlobalValue::AvailableExternallyLinkage; case 13: return GlobalValue::LinkerPrivateLinkage; + case 14: return GlobalValue::LinkerPrivateWeakLinkage; } } @@ -252,17 +253,18 @@ void BitcodeReaderValueList::ResolveConstantForwardRefs() { // at once. while (!Placeholder->use_empty()) { Value::use_iterator UI = Placeholder->use_begin(); + User *U = *UI; // If the using object isn't uniqued, just update the operands. This // handles instructions and initializers for global variables. - if (!isa<Constant>(*UI) || isa<GlobalValue>(*UI)) { + if (!isa<Constant>(U) || isa<GlobalValue>(U)) { UI.getUse().set(RealVal); continue; } // Otherwise, we have a constant that uses the placeholder. Replace that // constant with a new constant that has *all* placeholder uses updated. - Constant *UserC = cast<Constant>(*UI); + Constant *UserC = cast<Constant>(U); for (User::op_iterator I = UserC->op_begin(), E = UserC->op_end(); I != E; ++I) { Value *NewOp; @@ -818,7 +820,7 @@ bool BitcodeReader::ParseMetadata() { IsFunctionLocal = true; // fall-through case bitc::METADATA_NODE: { - if (Record.empty() || Record.size() % 2 == 1) + if (Record.size() % 2 == 1) return Error("Invalid METADATA_NODE record"); unsigned Size = Record.size(); @@ -832,7 +834,8 @@ bool BitcodeReader::ParseMetadata() { else Elts.push_back(NULL); } - Value *V = MDNode::getWhenValsUnresolved(Context, &Elts[0], Elts.size(), + Value *V = MDNode::getWhenValsUnresolved(Context, + Elts.data(), Elts.size(), IsFunctionLocal); IsFunctionLocal = false; MDValueList.AssignValue(V, NextMDValueNo++); @@ -2178,13 +2181,18 @@ bool BitcodeReader::ParseFunctionBody(Function *F) { InstructionList.push_back(I); break; } - case bitc::FUNC_CODE_INST_ALLOCA: { // ALLOCA: [instty, op, align] - if (Record.size() < 3) + case bitc::FUNC_CODE_INST_ALLOCA: { // ALLOCA: [instty, opty, op, align] + // For backward compatibility, tolerate a lack of an opty, and use i32. + // LLVM 3.0: Remove this. + if (Record.size() < 3 || Record.size() > 4) return Error("Invalid ALLOCA record"); + unsigned OpNum = 0; const PointerType *Ty = - dyn_cast_or_null<PointerType>(getTypeByID(Record[0])); - Value *Size = getFnValueByID(Record[1], Type::getInt32Ty(Context)); - unsigned Align = Record[2]; + dyn_cast_or_null<PointerType>(getTypeByID(Record[OpNum++])); + const Type *OpTy = Record.size() == 4 ? getTypeByID(Record[OpNum++]) : + Type::getInt32Ty(Context); + Value *Size = getFnValueByID(Record[OpNum++], OpTy); + unsigned Align = Record[OpNum++]; if (!Ty || !Size) return Error("Invalid ALLOCA record"); I = new AllocaInst(Ty->getElementType(), Size, (1 << Align) >> 1); InstructionList.push_back(I); diff --git a/contrib/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/contrib/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp index 9bda6dc..fa1b2c4 100644 --- a/contrib/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/contrib/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -313,6 +313,7 @@ static unsigned getEncodedLinkage(const GlobalValue *GV) { case GlobalValue::LinkOnceODRLinkage: return 11; case GlobalValue::AvailableExternallyLinkage: return 12; case GlobalValue::LinkerPrivateLinkage: return 13; + case GlobalValue::LinkerPrivateWeakLinkage: return 14; } } @@ -577,10 +578,9 @@ static void WriteFunctionLocalMetadata(const Function &F, BitstreamWriter &Stream) { bool StartedMetadataBlock = false; SmallVector<uint64_t, 64> Record; - const ValueEnumerator::ValueList &Vals = VE.getMDValues(); - + const SmallVector<const MDNode *, 8> &Vals = VE.getFunctionLocalMDValues(); for (unsigned i = 0, e = Vals.size(); i != e; ++i) - if (const MDNode *N = dyn_cast<MDNode>(Vals[i].first)) + if (const MDNode *N = Vals[i]) if (N->isFunctionLocal() && N->getFunction() == &F) { if (!StartedMetadataBlock) { Stream.EnterSubblock(bitc::METADATA_BLOCK_ID, 3); @@ -588,7 +588,7 @@ static void WriteFunctionLocalMetadata(const Function &F, } WriteMDNode(N, VE, Stream, Record); } - + if (StartedMetadataBlock) Stream.ExitBlock(); } @@ -1114,6 +1114,7 @@ static void WriteInstruction(const Instruction &I, unsigned InstID, case Instruction::Alloca: Code = bitc::FUNC_CODE_INST_ALLOCA; Vals.push_back(VE.getTypeID(I.getType())); + Vals.push_back(VE.getTypeID(I.getOperand(0)->getType())); Vals.push_back(VE.getValueID(I.getOperand(0))); // size. Vals.push_back(Log2_32(cast<AllocaInst>(I).getAlignment())+1); break; @@ -1134,26 +1135,25 @@ static void WriteInstruction(const Instruction &I, unsigned InstID, Vals.push_back(cast<StoreInst>(I).isVolatile()); break; case Instruction::Call: { - const PointerType *PTy = cast<PointerType>(I.getOperand(0)->getType()); + const CallInst &CI = cast<CallInst>(I); + const PointerType *PTy = cast<PointerType>(CI.getCalledValue()->getType()); const FunctionType *FTy = cast<FunctionType>(PTy->getElementType()); Code = bitc::FUNC_CODE_INST_CALL; - const CallInst *CI = cast<CallInst>(&I); - Vals.push_back(VE.getAttributeID(CI->getAttributes())); - Vals.push_back((CI->getCallingConv() << 1) | unsigned(CI->isTailCall())); - PushValueAndType(CI->getOperand(0), InstID, Vals, VE); // Callee + Vals.push_back(VE.getAttributeID(CI.getAttributes())); + Vals.push_back((CI.getCallingConv() << 1) | unsigned(CI.isTailCall())); + PushValueAndType(CI.getCalledValue(), InstID, Vals, VE); // Callee // Emit value #'s for the fixed parameters. for (unsigned i = 0, e = FTy->getNumParams(); i != e; ++i) - Vals.push_back(VE.getValueID(I.getOperand(i+1))); // fixed param. + Vals.push_back(VE.getValueID(CI.getArgOperand(i))); // fixed param. // Emit type/value pairs for varargs params. if (FTy->isVarArg()) { - unsigned NumVarargs = I.getNumOperands()-1-FTy->getNumParams(); - for (unsigned i = I.getNumOperands()-NumVarargs, e = I.getNumOperands(); + for (unsigned i = FTy->getNumParams(), e = CI.getNumArgOperands(); i != e; ++i) - PushValueAndType(I.getOperand(i), InstID, Vals, VE); // varargs + PushValueAndType(CI.getArgOperand(i), InstID, Vals, VE); // varargs } break; } @@ -1662,15 +1662,8 @@ void llvm::WriteBitcodeToFile(const Module *M, raw_ostream &Out) { WriteBitcodeToStream( M, Stream ); - // If writing to stdout, set binary mode. - if (&llvm::outs() == &Out) - sys::Program::ChangeStdoutToBinary(); - // Write the generated bitstream to "Out". Out.write((char*)&Buffer.front(), Buffer.size()); - - // Make sure it hits disk now. - Out.flush(); } /// WriteBitcodeToStream - Write the specified module to the specified output diff --git a/contrib/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp b/contrib/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp index d2baec7..7fa425a 100644 --- a/contrib/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp +++ b/contrib/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp @@ -72,7 +72,7 @@ ValueEnumerator::ValueEnumerator(const Module *M) { // Enumerate types used by the type symbol table. EnumerateTypeSymbolTable(M->getTypeSymbolTable()); - // Insert constants and metadata that are named at module level into the slot + // Insert constants and metadata that are named at module level into the slot // pool so that the module symbol table can refer to them... EnumerateValueSymbolTable(M->getValueSymbolTable()); EnumerateMDSymbolTable(M->getMDSymbolTable()); @@ -257,6 +257,8 @@ void ValueEnumerator::EnumerateMetadata(const Value *MD) { else EnumerateType(Type::getVoidTy(MD->getContext())); } + if (N->isFunctionLocal() && N->getFunction()) + FunctionLocalMDs.push_back(N); return; } @@ -414,7 +416,8 @@ void ValueEnumerator::incorporateFunction(const Function &F) { FirstInstID = Values.size(); - SmallVector<MDNode *, 8> FunctionLocalMDs; + FunctionLocalMDs.clear(); + SmallVector<MDNode *, 8> FnLocalMDVector; // Add all of the instructions. for (Function::const_iterator BB = F.begin(), E = F.end(); BB != E; ++BB) { for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I!=E; ++I) { @@ -423,7 +426,7 @@ void ValueEnumerator::incorporateFunction(const Function &F) { if (MDNode *MD = dyn_cast<MDNode>(*OI)) if (MD->isFunctionLocal() && MD->getFunction()) // Enumerate metadata after the instructions they might refer to. - FunctionLocalMDs.push_back(MD); + FnLocalMDVector.push_back(MD); } if (!I->getType()->isVoidTy()) EnumerateValue(I); @@ -431,8 +434,8 @@ void ValueEnumerator::incorporateFunction(const Function &F) { } // Add all of the function-local metadata. - for (unsigned i = 0, e = FunctionLocalMDs.size(); i != e; ++i) - EnumerateOperandType(FunctionLocalMDs[i]); + for (unsigned i = 0, e = FnLocalMDVector.size(); i != e; ++i) + EnumerateOperandType(FnLocalMDVector[i]); } void ValueEnumerator::purgeFunction() { diff --git a/contrib/llvm/lib/Bitcode/Writer/ValueEnumerator.h b/contrib/llvm/lib/Bitcode/Writer/ValueEnumerator.h index 4f8ebf5..2b9b15f 100644 --- a/contrib/llvm/lib/Bitcode/Writer/ValueEnumerator.h +++ b/contrib/llvm/lib/Bitcode/Writer/ValueEnumerator.h @@ -15,6 +15,7 @@ #define VALUE_ENUMERATOR_H #include "llvm/ADT/DenseMap.h" +#include "llvm/ADT/SmallVector.h" #include "llvm/Attributes.h" #include <vector> @@ -26,7 +27,7 @@ class Instruction; class BasicBlock; class Function; class Module; -class MetadataBase; +class MDNode; class NamedMDNode; class AttrListPtr; class TypeSymbolTable; @@ -49,6 +50,7 @@ private: ValueMapType ValueMap; ValueList Values; ValueList MDValues; + SmallVector<const MDNode *, 8> FunctionLocalMDs; ValueMapType MDValueMap; typedef DenseMap<void*, unsigned> AttributeMapType; @@ -105,6 +107,9 @@ public: const ValueList &getValues() const { return Values; } const ValueList &getMDValues() const { return MDValues; } + const SmallVector<const MDNode *, 8> &getFunctionLocalMDValues() const { + return FunctionLocalMDs; + } const TypeList &getTypes() const { return Types; } const std::vector<const BasicBlock*> &getBasicBlocks() const { return BasicBlocks; |