X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;ds=sidebyside;f=lib%2FBitcode%2FReader%2FBitcodeReader.cpp;h=b392122b77858288e667f85d6e0915d3108ed190;hb=22bbd9b9b89806fa9099442f8892f4e970ca54e9;hp=be0ec4bd85b8b9d4c6e5da82230fa5ba4420e686;hpb=96b930ddc7f0df9e278a5cb65ad77a559a20964e;p=oota-llvm.git diff --git a/lib/Bitcode/Reader/BitcodeReader.cpp b/lib/Bitcode/Reader/BitcodeReader.cpp index be0ec4bd85b..b392122b778 100644 --- a/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/lib/Bitcode/Reader/BitcodeReader.cpp @@ -342,7 +342,7 @@ Value *BitcodeReaderMDValueList::getValueFwdRef(unsigned Idx) { resize(Idx + 1); if (Value *V = MDValuePtrs[Idx]) { - assert(V->getType() == Type::getMetadataTy(Context) && "Type mismatch in value table!"); + assert(V->getType()->isMetadataTy() && "Type mismatch in value table!"); return V; } @@ -808,7 +808,7 @@ bool BitcodeReader::ParseMetadata() { SmallVector Elts; for (unsigned i = 0; i != Size; i += 2) { const Type *Ty = getTypeByID(Record[i], false); - if (Ty == Type::getMetadataTy(Context)) + if (Ty->isMetadataTy()) Elts.push_back(MDValueList.getValueFwdRef(Record[i+1])); else if (Ty != Type::getVoidTy(Context)) Elts.push_back(ValueList.getValueFwdRef(Record[i+1], Ty)); @@ -836,14 +836,21 @@ bool BitcodeReader::ParseMetadata() { return Error("Invalid METADATA_KIND record"); SmallString<8> Name; Name.resize(RecordLength-1); - MDKindID Kind = Record[0]; + unsigned Kind = Record[0]; + (void) Kind; for (unsigned i = 1; i != RecordLength; ++i) Name[i-1] = Record[i]; - Metadata &TheMetadata = Context.getMetadata(); - assert(TheMetadata.MDHandlerNames.find(Name.str()) - == TheMetadata.MDHandlerNames.end() && - "Already registered MDKind!"); - TheMetadata.MDHandlerNames[Name.str()] = Kind; + MetadataContext &TheMetadata = Context.getMetadata(); + unsigned ExistingKind = TheMetadata.getMDKind(Name.str()); + if (ExistingKind == 0) { + unsigned NewKind = TheMetadata.registerMDKind(Name.str()); + (void) NewKind; + assert (Kind == NewKind + && "Unable to handle custom metadata mismatch!"); + } else { + assert (ExistingKind == Kind + && "Unable to handle custom metadata mismatch!"); + } break; } } @@ -967,19 +974,19 @@ bool BitcodeReader::ParseConstants() { case bitc::CST_CODE_FLOAT: { // FLOAT: [fpval] if (Record.empty()) return Error("Invalid FLOAT record"); - if (CurTy == Type::getFloatTy(Context)) + if (CurTy->isFloatTy()) V = ConstantFP::get(Context, APFloat(APInt(32, (uint32_t)Record[0]))); - else if (CurTy == Type::getDoubleTy(Context)) + else if (CurTy->isDoubleTy()) V = ConstantFP::get(Context, APFloat(APInt(64, Record[0]))); - else if (CurTy == Type::getX86_FP80Ty(Context)) { + else if (CurTy->isX86_FP80Ty()) { // Bits are not stored the same way as a normal i80 APInt, compensate. uint64_t Rearrange[2]; Rearrange[0] = (Record[1] & 0xffffLL) | (Record[0] << 16); Rearrange[1] = Record[0] >> 48; V = ConstantFP::get(Context, APFloat(APInt(80, 2, Rearrange))); - } else if (CurTy == Type::getFP128Ty(Context)) + } else if (CurTy->isFP128Ty()) V = ConstantFP::get(Context, APFloat(APInt(128, 2, &Record[0]), true)); - else if (CurTy == Type::getPPC_FP128Ty(Context)) + else if (CurTy->isPPC_FP128Ty()) V = ConstantFP::get(Context, APFloat(APInt(128, 2, &Record[0]))); else V = UndefValue::get(CurTy); @@ -1167,7 +1174,8 @@ bool BitcodeReader::ParseConstants() { case bitc::CST_CODE_INLINEASM: { if (Record.size() < 2) return Error("Invalid INLINEASM record"); std::string AsmStr, ConstrStr; - bool HasSideEffects = Record[0]; + bool HasSideEffects = Record[0] & 1; + bool IsAlignStack = Record[0] >> 1; unsigned AsmStrSize = Record[1]; if (2+AsmStrSize >= Record.size()) return Error("Invalid INLINEASM record"); @@ -1181,7 +1189,7 @@ bool BitcodeReader::ParseConstants() { ConstrStr += (char)Record[3+AsmStrSize+i]; const PointerType *PTy = cast(CurTy); V = InlineAsm::get(cast(PTy->getElementType()), - AsmStr, ConstrStr, HasSideEffects); + AsmStr, ConstrStr, HasSideEffects, IsAlignStack); break; } } @@ -1556,7 +1564,7 @@ bool BitcodeReader::ParseMetadataAttachment() { if (Stream.EnterSubBlock(bitc::METADATA_ATTACHMENT_ID)) return Error("Malformed block record"); - Metadata &TheMetadata = Context.getMetadata(); + MetadataContext &TheMetadata = Context.getMetadata(); SmallVector Record; while(1) { unsigned Code = Stream.ReadCode(); @@ -1580,9 +1588,9 @@ bool BitcodeReader::ParseMetadataAttachment() { return Error ("Invalid METADATA_ATTACHMENT reader!"); Instruction *Inst = InstructionList[Record[0]]; for (unsigned i = 1; i != RecordLength; i = i+2) { - MDKindID Kind = Record[i]; + unsigned Kind = Record[i]; Value *Node = MDValueList.getValueFwdRef(Record[i+1]); - TheMetadata.setMD(Kind, cast(Node), Inst); + TheMetadata.addMD(Kind, cast(Node), Inst); } break; } @@ -2047,6 +2055,7 @@ bool BitcodeReader::ParseFunctionBody(Function *F) { case bitc::FUNC_CODE_INST_MALLOC: { // MALLOC: [instty, op, align] // Autoupgrade malloc instruction to malloc call. + // FIXME: Remove in LLVM 3.0. if (Record.size() < 3) return Error("Invalid MALLOC record"); const PointerType *Ty = @@ -2054,13 +2063,9 @@ bool BitcodeReader::ParseFunctionBody(Function *F) { Value *Size = getFnValueByID(Record[1], Type::getInt32Ty(Context)); if (!Ty || !Size) return Error("Invalid MALLOC record"); if (!CurBB) return Error("Invalid malloc instruction with no BB"); - const Type* Int32Ty = IntegerType::getInt32Ty(CurBB->getContext()); - if (Size->getType() != Int32Ty) - Size = CastInst::CreateIntegerCast(Size, Int32Ty, false /*ZExt*/, - "", CurBB); - Value* Malloc = CallInst::CreateMalloc(CurBB, Int32Ty, - Ty->getElementType(), Size, NULL); - I = cast(Malloc); + const Type *Int32Ty = IntegerType::getInt32Ty(CurBB->getContext()); + I = CallInst::CreateMalloc(CurBB, Int32Ty, Ty->getElementType(), + Size, NULL); InstructionList.push_back(I); break; } @@ -2070,7 +2075,8 @@ bool BitcodeReader::ParseFunctionBody(Function *F) { if (getValueTypePair(Record, OpNum, NextValueNo, Op) || OpNum != Record.size()) return Error("Invalid FREE record"); - I = new FreeInst(Op); + if (!CurBB) return Error("Invalid free instruction with no BB"); + I = CallInst::CreateFree(Op, CurBB); InstructionList.push_back(I); break; }