From 0f0d21e869726c947c958702f6db000e016203ce Mon Sep 17 00:00:00 2001 From: David Blaikie Date: Fri, 17 Apr 2015 19:56:21 +0000 Subject: [PATCH] [opaque pointer types] Use the pointee type loaded from bitcode when constructing a LoadInst Now (with a few carefully placed suppressions relating to general type serialization, etc) we can round trip a simple load through bitcode and textual IR without calling getElementType on a PointerType. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@235221 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/IR/Instructions.h | 6 +++++- lib/Bitcode/Reader/BitcodeReader.cpp | 11 ++++++----- lib/IR/Instructions.cpp | 4 ++-- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/include/llvm/IR/Instructions.h b/include/llvm/IR/Instructions.h index ddb441b6e5d..5d53b252c14 100644 --- a/include/llvm/IR/Instructions.h +++ b/include/llvm/IR/Instructions.h @@ -176,7 +176,11 @@ public: Instruction *InsertBefore = nullptr); LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile, BasicBlock *InsertAtEnd); - LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile, + LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile, unsigned Align, + Instruction *InsertBefore = nullptr) + : LoadInst(cast(Ptr->getType())->getElementType(), Ptr, + NameStr, isVolatile, Align, InsertBefore) {} + LoadInst(Type *Ty, Value *Ptr, const Twine &NameStr, bool isVolatile, unsigned Align, Instruction *InsertBefore = nullptr); LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile, unsigned Align, BasicBlock *InsertAtEnd); diff --git a/lib/Bitcode/Reader/BitcodeReader.cpp b/lib/Bitcode/Reader/BitcodeReader.cpp index a3552e92a53..bc78a71efad 100644 --- a/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/lib/Bitcode/Reader/BitcodeReader.cpp @@ -4002,15 +4002,16 @@ std::error_code BitcodeReader::ParseFunctionBody(Function *F) { Type *Ty = nullptr; if (OpNum + 3 == Record.size()) Ty = getTypeByID(Record[OpNum++]); + if (!Ty) + Ty = cast(Op->getType())->getElementType(); + else if (Ty != cast(Op->getType())->getElementType()) + return Error("Explicit load type does not match pointee type of " + "pointer operand"); unsigned Align; if (std::error_code EC = parseAlignmentValue(Record[OpNum], Align)) return EC; - I = new LoadInst(Op, "", Record[OpNum+1], Align); - - if (Ty && Ty != I->getType()) - return Error("Explicit load type does not match pointee type of " - "pointer operand"); + I = new LoadInst(Ty, Op, "", Record[OpNum + 1], Align); InstructionList.push_back(I); break; diff --git a/lib/IR/Instructions.cpp b/lib/IR/Instructions.cpp index 85b7521f316..1c831ccd289 100644 --- a/lib/IR/Instructions.cpp +++ b/lib/IR/Instructions.cpp @@ -945,9 +945,9 @@ LoadInst::LoadInst(Value *Ptr, const Twine &Name, bool isVolatile, BasicBlock *InsertAE) : LoadInst(Ptr, Name, isVolatile, /*Align=*/0, InsertAE) {} -LoadInst::LoadInst(Value *Ptr, const Twine &Name, bool isVolatile, +LoadInst::LoadInst(Type *Ty, Value *Ptr, const Twine &Name, bool isVolatile, unsigned Align, Instruction *InsertBef) - : LoadInst(Ptr, Name, isVolatile, Align, NotAtomic, CrossThread, + : LoadInst(Ty, Ptr, Name, isVolatile, Align, NotAtomic, CrossThread, InsertBef) {} LoadInst::LoadInst(Value *Ptr, const Twine &Name, bool isVolatile, -- 2.34.1