mirror of
https://github.com/RPCS3/llvm.git
synced 2025-02-04 09:37:20 +00:00
LLVMContext-ify the bitcode reader.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@74942 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
f667e7ed18
commit
74a77812d1
@ -17,6 +17,7 @@
|
|||||||
#include "llvm/DerivedTypes.h"
|
#include "llvm/DerivedTypes.h"
|
||||||
#include "llvm/InlineAsm.h"
|
#include "llvm/InlineAsm.h"
|
||||||
#include "llvm/Instructions.h"
|
#include "llvm/Instructions.h"
|
||||||
|
#include "llvm/LLVMContext.h"
|
||||||
#include "llvm/MDNode.h"
|
#include "llvm/MDNode.h"
|
||||||
#include "llvm/Module.h"
|
#include "llvm/Module.h"
|
||||||
#include "llvm/AutoUpgrade.h"
|
#include "llvm/AutoUpgrade.h"
|
||||||
@ -137,9 +138,9 @@ namespace {
|
|||||||
void *operator new(size_t s) {
|
void *operator new(size_t s) {
|
||||||
return User::operator new(s, 1);
|
return User::operator new(s, 1);
|
||||||
}
|
}
|
||||||
explicit ConstantPlaceHolder(const Type *Ty)
|
explicit ConstantPlaceHolder(const Type *Ty, LLVMContext& Context)
|
||||||
: ConstantExpr(Ty, Instruction::UserOp1, &Op<0>(), 1) {
|
: ConstantExpr(Ty, Instruction::UserOp1, &Op<0>(), 1) {
|
||||||
Op<0>() = UndefValue::get(Type::Int32Ty);
|
Op<0>() = Context.getUndef(Type::Int32Ty);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Methods to support type inquiry through isa, cast, and dyn_cast.
|
/// @brief Methods to support type inquiry through isa, cast, and dyn_cast.
|
||||||
@ -202,7 +203,7 @@ Constant *BitcodeReaderValueList::getConstantFwdRef(unsigned Idx,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create and return a placeholder, which will later be RAUW'd.
|
// Create and return a placeholder, which will later be RAUW'd.
|
||||||
Constant *C = new ConstantPlaceHolder(Ty);
|
Constant *C = new ConstantPlaceHolder(Ty, Context);
|
||||||
ValuePtrs[Idx] = C;
|
ValuePtrs[Idx] = C;
|
||||||
return C;
|
return C;
|
||||||
}
|
}
|
||||||
@ -285,12 +286,13 @@ void BitcodeReaderValueList::ResolveConstantForwardRefs() {
|
|||||||
// Make the new constant.
|
// Make the new constant.
|
||||||
Constant *NewC;
|
Constant *NewC;
|
||||||
if (ConstantArray *UserCA = dyn_cast<ConstantArray>(UserC)) {
|
if (ConstantArray *UserCA = dyn_cast<ConstantArray>(UserC)) {
|
||||||
NewC = ConstantArray::get(UserCA->getType(), &NewOps[0], NewOps.size());
|
NewC = Context.getConstantArray(UserCA->getType(), &NewOps[0],
|
||||||
|
NewOps.size());
|
||||||
} else if (ConstantStruct *UserCS = dyn_cast<ConstantStruct>(UserC)) {
|
} else if (ConstantStruct *UserCS = dyn_cast<ConstantStruct>(UserC)) {
|
||||||
NewC = ConstantStruct::get(&NewOps[0], NewOps.size(),
|
NewC = Context.getConstantStruct(&NewOps[0], NewOps.size(),
|
||||||
UserCS->getType()->isPacked());
|
UserCS->getType()->isPacked());
|
||||||
} else if (isa<ConstantVector>(UserC)) {
|
} else if (isa<ConstantVector>(UserC)) {
|
||||||
NewC = ConstantVector::get(&NewOps[0], NewOps.size());
|
NewC = Context.getConstantVector(&NewOps[0], NewOps.size());
|
||||||
} else {
|
} else {
|
||||||
assert(isa<ConstantExpr>(UserC) && "Must be a ConstantExpr.");
|
assert(isa<ConstantExpr>(UserC) && "Must be a ConstantExpr.");
|
||||||
NewC = cast<ConstantExpr>(UserC)->getWithOperands(&NewOps[0],
|
NewC = cast<ConstantExpr>(UserC)->getWithOperands(&NewOps[0],
|
||||||
@ -318,7 +320,7 @@ const Type *BitcodeReader::getTypeByID(unsigned ID, bool isTypeTable) {
|
|||||||
// The type table allows forward references. Push as many Opaque types as
|
// The type table allows forward references. Push as many Opaque types as
|
||||||
// needed to get up to ID.
|
// needed to get up to ID.
|
||||||
while (TypeList.size() <= ID)
|
while (TypeList.size() <= ID)
|
||||||
TypeList.push_back(OpaqueType::get());
|
TypeList.push_back(Context.getOpaqueType());
|
||||||
return TypeList.back().get();
|
return TypeList.back().get();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -508,7 +510,7 @@ bool BitcodeReader::ParseTypeTable() {
|
|||||||
if (Record.size() < 1)
|
if (Record.size() < 1)
|
||||||
return Error("Invalid Integer type record");
|
return Error("Invalid Integer type record");
|
||||||
|
|
||||||
ResultTy = IntegerType::get(Record[0]);
|
ResultTy = Context.getIntegerType(Record[0]);
|
||||||
break;
|
break;
|
||||||
case bitc::TYPE_CODE_POINTER: { // POINTER: [pointee type] or
|
case bitc::TYPE_CODE_POINTER: { // POINTER: [pointee type] or
|
||||||
// [pointee type, address space]
|
// [pointee type, address space]
|
||||||
@ -517,7 +519,8 @@ bool BitcodeReader::ParseTypeTable() {
|
|||||||
unsigned AddressSpace = 0;
|
unsigned AddressSpace = 0;
|
||||||
if (Record.size() == 2)
|
if (Record.size() == 2)
|
||||||
AddressSpace = Record[1];
|
AddressSpace = Record[1];
|
||||||
ResultTy = PointerType::get(getTypeByID(Record[0], true), AddressSpace);
|
ResultTy = Context.getPointerType(getTypeByID(Record[0], true),
|
||||||
|
AddressSpace);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case bitc::TYPE_CODE_FUNCTION: {
|
case bitc::TYPE_CODE_FUNCTION: {
|
||||||
@ -529,7 +532,7 @@ bool BitcodeReader::ParseTypeTable() {
|
|||||||
for (unsigned i = 3, e = Record.size(); i != e; ++i)
|
for (unsigned i = 3, e = Record.size(); i != e; ++i)
|
||||||
ArgTys.push_back(getTypeByID(Record[i], true));
|
ArgTys.push_back(getTypeByID(Record[i], true));
|
||||||
|
|
||||||
ResultTy = FunctionType::get(getTypeByID(Record[2], true), ArgTys,
|
ResultTy = Context.getFunctionType(getTypeByID(Record[2], true), ArgTys,
|
||||||
Record[0]);
|
Record[0]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -539,24 +542,24 @@ bool BitcodeReader::ParseTypeTable() {
|
|||||||
std::vector<const Type*> EltTys;
|
std::vector<const Type*> EltTys;
|
||||||
for (unsigned i = 1, e = Record.size(); i != e; ++i)
|
for (unsigned i = 1, e = Record.size(); i != e; ++i)
|
||||||
EltTys.push_back(getTypeByID(Record[i], true));
|
EltTys.push_back(getTypeByID(Record[i], true));
|
||||||
ResultTy = StructType::get(EltTys, Record[0]);
|
ResultTy = Context.getStructType(EltTys, Record[0]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case bitc::TYPE_CODE_ARRAY: // ARRAY: [numelts, eltty]
|
case bitc::TYPE_CODE_ARRAY: // ARRAY: [numelts, eltty]
|
||||||
if (Record.size() < 2)
|
if (Record.size() < 2)
|
||||||
return Error("Invalid ARRAY type record");
|
return Error("Invalid ARRAY type record");
|
||||||
ResultTy = ArrayType::get(getTypeByID(Record[1], true), Record[0]);
|
ResultTy = Context.getArrayType(getTypeByID(Record[1], true), Record[0]);
|
||||||
break;
|
break;
|
||||||
case bitc::TYPE_CODE_VECTOR: // VECTOR: [numelts, eltty]
|
case bitc::TYPE_CODE_VECTOR: // VECTOR: [numelts, eltty]
|
||||||
if (Record.size() < 2)
|
if (Record.size() < 2)
|
||||||
return Error("Invalid VECTOR type record");
|
return Error("Invalid VECTOR type record");
|
||||||
ResultTy = VectorType::get(getTypeByID(Record[1], true), Record[0]);
|
ResultTy = Context.getVectorType(getTypeByID(Record[1], true), Record[0]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NumRecords == TypeList.size()) {
|
if (NumRecords == TypeList.size()) {
|
||||||
// If this is a new type slot, just append it.
|
// If this is a new type slot, just append it.
|
||||||
TypeList.push_back(ResultTy ? ResultTy : OpaqueType::get());
|
TypeList.push_back(ResultTy ? ResultTy : Context.getOpaqueType());
|
||||||
++NumRecords;
|
++NumRecords;
|
||||||
} else if (ResultTy == 0) {
|
} else if (ResultTy == 0) {
|
||||||
// Otherwise, this was forward referenced, so an opaque type was created,
|
// Otherwise, this was forward referenced, so an opaque type was created,
|
||||||
@ -777,7 +780,7 @@ bool BitcodeReader::ParseConstants() {
|
|||||||
switch (Stream.ReadRecord(Code, Record)) {
|
switch (Stream.ReadRecord(Code, Record)) {
|
||||||
default: // Default behavior: unknown constant
|
default: // Default behavior: unknown constant
|
||||||
case bitc::CST_CODE_UNDEF: // UNDEF
|
case bitc::CST_CODE_UNDEF: // UNDEF
|
||||||
V = UndefValue::get(CurTy);
|
V = Context.getUndef(CurTy);
|
||||||
break;
|
break;
|
||||||
case bitc::CST_CODE_SETTYPE: // SETTYPE: [typeid]
|
case bitc::CST_CODE_SETTYPE: // SETTYPE: [typeid]
|
||||||
if (Record.empty())
|
if (Record.empty())
|
||||||
@ -787,12 +790,12 @@ bool BitcodeReader::ParseConstants() {
|
|||||||
CurTy = TypeList[Record[0]];
|
CurTy = TypeList[Record[0]];
|
||||||
continue; // Skip the ValueList manipulation.
|
continue; // Skip the ValueList manipulation.
|
||||||
case bitc::CST_CODE_NULL: // NULL
|
case bitc::CST_CODE_NULL: // NULL
|
||||||
V = Constant::getNullValue(CurTy);
|
V = Context.getNullValue(CurTy);
|
||||||
break;
|
break;
|
||||||
case bitc::CST_CODE_INTEGER: // INTEGER: [intval]
|
case bitc::CST_CODE_INTEGER: // INTEGER: [intval]
|
||||||
if (!isa<IntegerType>(CurTy) || Record.empty())
|
if (!isa<IntegerType>(CurTy) || Record.empty())
|
||||||
return Error("Invalid CST_INTEGER record");
|
return Error("Invalid CST_INTEGER record");
|
||||||
V = ConstantInt::get(CurTy, DecodeSignRotatedValue(Record[0]));
|
V = Context.getConstantInt(CurTy, DecodeSignRotatedValue(Record[0]));
|
||||||
break;
|
break;
|
||||||
case bitc::CST_CODE_WIDE_INTEGER: {// WIDE_INTEGER: [n x intval]
|
case bitc::CST_CODE_WIDE_INTEGER: {// WIDE_INTEGER: [n x intval]
|
||||||
if (!isa<IntegerType>(CurTy) || Record.empty())
|
if (!isa<IntegerType>(CurTy) || Record.empty())
|
||||||
@ -803,7 +806,7 @@ bool BitcodeReader::ParseConstants() {
|
|||||||
Words.resize(NumWords);
|
Words.resize(NumWords);
|
||||||
for (unsigned i = 0; i != NumWords; ++i)
|
for (unsigned i = 0; i != NumWords; ++i)
|
||||||
Words[i] = DecodeSignRotatedValue(Record[i]);
|
Words[i] = DecodeSignRotatedValue(Record[i]);
|
||||||
V = ConstantInt::get(APInt(cast<IntegerType>(CurTy)->getBitWidth(),
|
V = Context.getConstantInt(APInt(cast<IntegerType>(CurTy)->getBitWidth(),
|
||||||
NumWords, &Words[0]));
|
NumWords, &Words[0]));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -811,21 +814,21 @@ bool BitcodeReader::ParseConstants() {
|
|||||||
if (Record.empty())
|
if (Record.empty())
|
||||||
return Error("Invalid FLOAT record");
|
return Error("Invalid FLOAT record");
|
||||||
if (CurTy == Type::FloatTy)
|
if (CurTy == Type::FloatTy)
|
||||||
V = ConstantFP::get(APFloat(APInt(32, (uint32_t)Record[0])));
|
V = Context.getConstantFP(APFloat(APInt(32, (uint32_t)Record[0])));
|
||||||
else if (CurTy == Type::DoubleTy)
|
else if (CurTy == Type::DoubleTy)
|
||||||
V = ConstantFP::get(APFloat(APInt(64, Record[0])));
|
V = Context.getConstantFP(APFloat(APInt(64, Record[0])));
|
||||||
else if (CurTy == Type::X86_FP80Ty) {
|
else if (CurTy == Type::X86_FP80Ty) {
|
||||||
// Bits are not stored the same way as a normal i80 APInt, compensate.
|
// Bits are not stored the same way as a normal i80 APInt, compensate.
|
||||||
uint64_t Rearrange[2];
|
uint64_t Rearrange[2];
|
||||||
Rearrange[0] = (Record[1] & 0xffffLL) | (Record[0] << 16);
|
Rearrange[0] = (Record[1] & 0xffffLL) | (Record[0] << 16);
|
||||||
Rearrange[1] = Record[0] >> 48;
|
Rearrange[1] = Record[0] >> 48;
|
||||||
V = ConstantFP::get(APFloat(APInt(80, 2, Rearrange)));
|
V = Context.getConstantFP(APFloat(APInt(80, 2, Rearrange)));
|
||||||
} else if (CurTy == Type::FP128Ty)
|
} else if (CurTy == Type::FP128Ty)
|
||||||
V = ConstantFP::get(APFloat(APInt(128, 2, &Record[0]), true));
|
V = Context.getConstantFP(APFloat(APInt(128, 2, &Record[0]), true));
|
||||||
else if (CurTy == Type::PPC_FP128Ty)
|
else if (CurTy == Type::PPC_FP128Ty)
|
||||||
V = ConstantFP::get(APFloat(APInt(128, 2, &Record[0])));
|
V = Context.getConstantFP(APFloat(APInt(128, 2, &Record[0])));
|
||||||
else
|
else
|
||||||
V = UndefValue::get(CurTy);
|
V = Context.getUndef(CurTy);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -840,19 +843,19 @@ bool BitcodeReader::ParseConstants() {
|
|||||||
for (unsigned i = 0; i != Size; ++i)
|
for (unsigned i = 0; i != Size; ++i)
|
||||||
Elts.push_back(ValueList.getConstantFwdRef(Record[i],
|
Elts.push_back(ValueList.getConstantFwdRef(Record[i],
|
||||||
STy->getElementType(i)));
|
STy->getElementType(i)));
|
||||||
V = ConstantStruct::get(STy, Elts);
|
V = Context.getConstantStruct(STy, Elts);
|
||||||
} else if (const ArrayType *ATy = dyn_cast<ArrayType>(CurTy)) {
|
} else if (const ArrayType *ATy = dyn_cast<ArrayType>(CurTy)) {
|
||||||
const Type *EltTy = ATy->getElementType();
|
const Type *EltTy = ATy->getElementType();
|
||||||
for (unsigned i = 0; i != Size; ++i)
|
for (unsigned i = 0; i != Size; ++i)
|
||||||
Elts.push_back(ValueList.getConstantFwdRef(Record[i], EltTy));
|
Elts.push_back(ValueList.getConstantFwdRef(Record[i], EltTy));
|
||||||
V = ConstantArray::get(ATy, Elts);
|
V = Context.getConstantArray(ATy, Elts);
|
||||||
} else if (const VectorType *VTy = dyn_cast<VectorType>(CurTy)) {
|
} else if (const VectorType *VTy = dyn_cast<VectorType>(CurTy)) {
|
||||||
const Type *EltTy = VTy->getElementType();
|
const Type *EltTy = VTy->getElementType();
|
||||||
for (unsigned i = 0; i != Size; ++i)
|
for (unsigned i = 0; i != Size; ++i)
|
||||||
Elts.push_back(ValueList.getConstantFwdRef(Record[i], EltTy));
|
Elts.push_back(ValueList.getConstantFwdRef(Record[i], EltTy));
|
||||||
V = ConstantVector::get(Elts);
|
V = Context.getConstantVector(Elts);
|
||||||
} else {
|
} else {
|
||||||
V = UndefValue::get(CurTy);
|
V = Context.getUndef(CurTy);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -866,8 +869,8 @@ bool BitcodeReader::ParseConstants() {
|
|||||||
unsigned Size = Record.size();
|
unsigned Size = Record.size();
|
||||||
std::vector<Constant*> Elts;
|
std::vector<Constant*> Elts;
|
||||||
for (unsigned i = 0; i != Size; ++i)
|
for (unsigned i = 0; i != Size; ++i)
|
||||||
Elts.push_back(ConstantInt::get(EltTy, Record[i]));
|
Elts.push_back(Context.getConstantInt(EltTy, Record[i]));
|
||||||
V = ConstantArray::get(ATy, Elts);
|
V = Context.getConstantArray(ATy, Elts);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case bitc::CST_CODE_CSTRING: { // CSTRING: [values]
|
case bitc::CST_CODE_CSTRING: { // CSTRING: [values]
|
||||||
@ -880,20 +883,20 @@ bool BitcodeReader::ParseConstants() {
|
|||||||
unsigned Size = Record.size();
|
unsigned Size = Record.size();
|
||||||
std::vector<Constant*> Elts;
|
std::vector<Constant*> Elts;
|
||||||
for (unsigned i = 0; i != Size; ++i)
|
for (unsigned i = 0; i != Size; ++i)
|
||||||
Elts.push_back(ConstantInt::get(EltTy, Record[i]));
|
Elts.push_back(Context.getConstantInt(EltTy, Record[i]));
|
||||||
Elts.push_back(Constant::getNullValue(EltTy));
|
Elts.push_back(Context.getNullValue(EltTy));
|
||||||
V = ConstantArray::get(ATy, Elts);
|
V = Context.getConstantArray(ATy, Elts);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case bitc::CST_CODE_CE_BINOP: { // CE_BINOP: [opcode, opval, opval]
|
case bitc::CST_CODE_CE_BINOP: { // CE_BINOP: [opcode, opval, opval]
|
||||||
if (Record.size() < 3) return Error("Invalid CE_BINOP record");
|
if (Record.size() < 3) return Error("Invalid CE_BINOP record");
|
||||||
int Opc = GetDecodedBinaryOpcode(Record[0], CurTy);
|
int Opc = GetDecodedBinaryOpcode(Record[0], CurTy);
|
||||||
if (Opc < 0) {
|
if (Opc < 0) {
|
||||||
V = UndefValue::get(CurTy); // Unknown binop.
|
V = Context.getUndef(CurTy); // Unknown binop.
|
||||||
} else {
|
} else {
|
||||||
Constant *LHS = ValueList.getConstantFwdRef(Record[1], CurTy);
|
Constant *LHS = ValueList.getConstantFwdRef(Record[1], CurTy);
|
||||||
Constant *RHS = ValueList.getConstantFwdRef(Record[2], CurTy);
|
Constant *RHS = ValueList.getConstantFwdRef(Record[2], CurTy);
|
||||||
V = ConstantExpr::get(Opc, LHS, RHS);
|
V = Context.getConstantExpr(Opc, LHS, RHS);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -901,12 +904,12 @@ bool BitcodeReader::ParseConstants() {
|
|||||||
if (Record.size() < 3) return Error("Invalid CE_CAST record");
|
if (Record.size() < 3) return Error("Invalid CE_CAST record");
|
||||||
int Opc = GetDecodedCastOpcode(Record[0]);
|
int Opc = GetDecodedCastOpcode(Record[0]);
|
||||||
if (Opc < 0) {
|
if (Opc < 0) {
|
||||||
V = UndefValue::get(CurTy); // Unknown cast.
|
V = Context.getUndef(CurTy); // Unknown cast.
|
||||||
} else {
|
} else {
|
||||||
const Type *OpTy = getTypeByID(Record[1]);
|
const Type *OpTy = getTypeByID(Record[1]);
|
||||||
if (!OpTy) return Error("Invalid CE_CAST record");
|
if (!OpTy) return Error("Invalid CE_CAST record");
|
||||||
Constant *Op = ValueList.getConstantFwdRef(Record[2], OpTy);
|
Constant *Op = ValueList.getConstantFwdRef(Record[2], OpTy);
|
||||||
V = ConstantExpr::getCast(Opc, Op, CurTy);
|
V = Context.getConstantExprCast(Opc, Op, CurTy);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -918,12 +921,13 @@ bool BitcodeReader::ParseConstants() {
|
|||||||
if (!ElTy) return Error("Invalid CE_GEP record");
|
if (!ElTy) return Error("Invalid CE_GEP record");
|
||||||
Elts.push_back(ValueList.getConstantFwdRef(Record[i+1], ElTy));
|
Elts.push_back(ValueList.getConstantFwdRef(Record[i+1], ElTy));
|
||||||
}
|
}
|
||||||
V = ConstantExpr::getGetElementPtr(Elts[0], &Elts[1], Elts.size()-1);
|
V = Context.getConstantExprGetElementPtr(Elts[0], &Elts[1],
|
||||||
|
Elts.size()-1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case bitc::CST_CODE_CE_SELECT: // CE_SELECT: [opval#, opval#, opval#]
|
case bitc::CST_CODE_CE_SELECT: // CE_SELECT: [opval#, opval#, opval#]
|
||||||
if (Record.size() < 3) return Error("Invalid CE_SELECT record");
|
if (Record.size() < 3) return Error("Invalid CE_SELECT record");
|
||||||
V = ConstantExpr::getSelect(ValueList.getConstantFwdRef(Record[0],
|
V = Context.getConstantExprSelect(ValueList.getConstantFwdRef(Record[0],
|
||||||
Type::Int1Ty),
|
Type::Int1Ty),
|
||||||
ValueList.getConstantFwdRef(Record[1],CurTy),
|
ValueList.getConstantFwdRef(Record[1],CurTy),
|
||||||
ValueList.getConstantFwdRef(Record[2],CurTy));
|
ValueList.getConstantFwdRef(Record[2],CurTy));
|
||||||
@ -935,7 +939,7 @@ bool BitcodeReader::ParseConstants() {
|
|||||||
if (OpTy == 0) return Error("Invalid CE_EXTRACTELT record");
|
if (OpTy == 0) return Error("Invalid CE_EXTRACTELT record");
|
||||||
Constant *Op0 = ValueList.getConstantFwdRef(Record[1], OpTy);
|
Constant *Op0 = ValueList.getConstantFwdRef(Record[1], OpTy);
|
||||||
Constant *Op1 = ValueList.getConstantFwdRef(Record[2], Type::Int32Ty);
|
Constant *Op1 = ValueList.getConstantFwdRef(Record[2], Type::Int32Ty);
|
||||||
V = ConstantExpr::getExtractElement(Op0, Op1);
|
V = Context.getConstantExprExtractElement(Op0, Op1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case bitc::CST_CODE_CE_INSERTELT: { // CE_INSERTELT: [opval, opval, opval]
|
case bitc::CST_CODE_CE_INSERTELT: { // CE_INSERTELT: [opval, opval, opval]
|
||||||
@ -946,7 +950,7 @@ bool BitcodeReader::ParseConstants() {
|
|||||||
Constant *Op1 = ValueList.getConstantFwdRef(Record[1],
|
Constant *Op1 = ValueList.getConstantFwdRef(Record[1],
|
||||||
OpTy->getElementType());
|
OpTy->getElementType());
|
||||||
Constant *Op2 = ValueList.getConstantFwdRef(Record[2], Type::Int32Ty);
|
Constant *Op2 = ValueList.getConstantFwdRef(Record[2], Type::Int32Ty);
|
||||||
V = ConstantExpr::getInsertElement(Op0, Op1, Op2);
|
V = Context.getConstantExprInsertElement(Op0, Op1, Op2);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case bitc::CST_CODE_CE_SHUFFLEVEC: { // CE_SHUFFLEVEC: [opval, opval, opval]
|
case bitc::CST_CODE_CE_SHUFFLEVEC: { // CE_SHUFFLEVEC: [opval, opval, opval]
|
||||||
@ -955,9 +959,10 @@ bool BitcodeReader::ParseConstants() {
|
|||||||
return Error("Invalid CE_SHUFFLEVEC record");
|
return Error("Invalid CE_SHUFFLEVEC record");
|
||||||
Constant *Op0 = ValueList.getConstantFwdRef(Record[0], OpTy);
|
Constant *Op0 = ValueList.getConstantFwdRef(Record[0], OpTy);
|
||||||
Constant *Op1 = ValueList.getConstantFwdRef(Record[1], OpTy);
|
Constant *Op1 = ValueList.getConstantFwdRef(Record[1], OpTy);
|
||||||
const Type *ShufTy=VectorType::get(Type::Int32Ty, OpTy->getNumElements());
|
const Type *ShufTy = Context.getVectorType(Type::Int32Ty,
|
||||||
|
OpTy->getNumElements());
|
||||||
Constant *Op2 = ValueList.getConstantFwdRef(Record[2], ShufTy);
|
Constant *Op2 = ValueList.getConstantFwdRef(Record[2], ShufTy);
|
||||||
V = ConstantExpr::getShuffleVector(Op0, Op1, Op2);
|
V = Context.getConstantExprShuffleVector(Op0, Op1, Op2);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case bitc::CST_CODE_CE_SHUFVEC_EX: { // [opty, opval, opval, opval]
|
case bitc::CST_CODE_CE_SHUFVEC_EX: { // [opty, opval, opval, opval]
|
||||||
@ -967,9 +972,10 @@ bool BitcodeReader::ParseConstants() {
|
|||||||
return Error("Invalid CE_SHUFVEC_EX record");
|
return Error("Invalid CE_SHUFVEC_EX record");
|
||||||
Constant *Op0 = ValueList.getConstantFwdRef(Record[1], OpTy);
|
Constant *Op0 = ValueList.getConstantFwdRef(Record[1], OpTy);
|
||||||
Constant *Op1 = ValueList.getConstantFwdRef(Record[2], OpTy);
|
Constant *Op1 = ValueList.getConstantFwdRef(Record[2], OpTy);
|
||||||
const Type *ShufTy=VectorType::get(Type::Int32Ty, RTy->getNumElements());
|
const Type *ShufTy = Context.getVectorType(Type::Int32Ty,
|
||||||
|
RTy->getNumElements());
|
||||||
Constant *Op2 = ValueList.getConstantFwdRef(Record[3], ShufTy);
|
Constant *Op2 = ValueList.getConstantFwdRef(Record[3], ShufTy);
|
||||||
V = ConstantExpr::getShuffleVector(Op0, Op1, Op2);
|
V = Context.getConstantExprShuffleVector(Op0, Op1, Op2);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case bitc::CST_CODE_CE_CMP: { // CE_CMP: [opty, opval, opval, pred]
|
case bitc::CST_CODE_CE_CMP: { // CE_CMP: [opty, opval, opval, pred]
|
||||||
@ -980,13 +986,13 @@ bool BitcodeReader::ParseConstants() {
|
|||||||
Constant *Op1 = ValueList.getConstantFwdRef(Record[2], OpTy);
|
Constant *Op1 = ValueList.getConstantFwdRef(Record[2], OpTy);
|
||||||
|
|
||||||
if (OpTy->isFloatingPoint())
|
if (OpTy->isFloatingPoint())
|
||||||
V = ConstantExpr::getFCmp(Record[3], Op0, Op1);
|
V = Context.getConstantExprFCmp(Record[3], Op0, Op1);
|
||||||
else if (!isa<VectorType>(OpTy))
|
else if (!isa<VectorType>(OpTy))
|
||||||
V = ConstantExpr::getICmp(Record[3], Op0, Op1);
|
V = Context.getConstantExprICmp(Record[3], Op0, Op1);
|
||||||
else if (OpTy->isFPOrFPVector())
|
else if (OpTy->isFPOrFPVector())
|
||||||
V = ConstantExpr::getVFCmp(Record[3], Op0, Op1);
|
V = Context.getConstantExprVFCmp(Record[3], Op0, Op1);
|
||||||
else
|
else
|
||||||
V = ConstantExpr::getVICmp(Record[3], Op0, Op1);
|
V = Context.getConstantExprVICmp(Record[3], Op0, Op1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case bitc::CST_CODE_INLINEASM: {
|
case bitc::CST_CODE_INLINEASM: {
|
||||||
@ -1015,7 +1021,7 @@ bool BitcodeReader::ParseConstants() {
|
|||||||
String.resize(MDStringLength);
|
String.resize(MDStringLength);
|
||||||
for (unsigned i = 0; i != MDStringLength; ++i)
|
for (unsigned i = 0; i != MDStringLength; ++i)
|
||||||
String[i] = Record[i];
|
String[i] = Record[i];
|
||||||
V = MDString::get(String.c_str(), String.c_str() + MDStringLength);
|
V = Context.getMDString(String.c_str(), String.c_str() + MDStringLength);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case bitc::CST_CODE_MDNODE: {
|
case bitc::CST_CODE_MDNODE: {
|
||||||
@ -1031,7 +1037,7 @@ bool BitcodeReader::ParseConstants() {
|
|||||||
else
|
else
|
||||||
Elts.push_back(NULL);
|
Elts.push_back(NULL);
|
||||||
}
|
}
|
||||||
V = MDNode::get(&Elts[0], Elts.size());
|
V = Context.getMDNode(&Elts[0], Elts.size());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1693,7 +1699,7 @@ bool BitcodeReader::ParseFunctionBody(Function *F) {
|
|||||||
if (Vs.size() > 1 ||
|
if (Vs.size() > 1 ||
|
||||||
(isa<StructType>(ReturnType) &&
|
(isa<StructType>(ReturnType) &&
|
||||||
(Vs.empty() || Vs[0]->getType() != ReturnType))) {
|
(Vs.empty() || Vs[0]->getType() != ReturnType))) {
|
||||||
Value *RV = UndefValue::get(ReturnType);
|
Value *RV = Context.getUndef(ReturnType);
|
||||||
for (unsigned i = 0, e = Vs.size(); i != e; ++i) {
|
for (unsigned i = 0, e = Vs.size(); i != e; ++i) {
|
||||||
I = InsertValueInst::Create(RV, Vs[i], i, "mrv");
|
I = InsertValueInst::Create(RV, Vs[i], i, "mrv");
|
||||||
CurBB->getInstList().push_back(I);
|
CurBB->getInstList().push_back(I);
|
||||||
@ -1879,7 +1885,8 @@ bool BitcodeReader::ParseFunctionBody(Function *F) {
|
|||||||
unsigned OpNum = 0;
|
unsigned OpNum = 0;
|
||||||
Value *Val, *Ptr;
|
Value *Val, *Ptr;
|
||||||
if (getValueTypePair(Record, OpNum, NextValueNo, Val) ||
|
if (getValueTypePair(Record, OpNum, NextValueNo, Val) ||
|
||||||
getValue(Record, OpNum, PointerType::getUnqual(Val->getType()), Ptr)||
|
getValue(Record, OpNum,
|
||||||
|
Context.getPointerTypeUnqual(Val->getType()), Ptr)||
|
||||||
OpNum+2 != Record.size())
|
OpNum+2 != Record.size())
|
||||||
return Error("Invalid STORE record");
|
return Error("Invalid STORE record");
|
||||||
|
|
||||||
@ -1972,7 +1979,7 @@ bool BitcodeReader::ParseFunctionBody(Function *F) {
|
|||||||
// We found at least one unresolved value. Nuke them all to avoid leaks.
|
// We found at least one unresolved value. Nuke them all to avoid leaks.
|
||||||
for (unsigned i = ModuleValueListSize, e = ValueList.size(); i != e; ++i){
|
for (unsigned i = ModuleValueListSize, e = ValueList.size(); i != e; ++i){
|
||||||
if ((A = dyn_cast<Argument>(ValueList.back())) && A->getParent() == 0) {
|
if ((A = dyn_cast<Argument>(ValueList.back())) && A->getParent() == 0) {
|
||||||
A->replaceAllUsesWith(UndefValue::get(A->getType()));
|
A->replaceAllUsesWith(Context.getUndef(A->getType()));
|
||||||
delete A;
|
delete A;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -44,8 +44,9 @@ class BitcodeReaderValueList {
|
|||||||
/// number that holds the resolved value.
|
/// number that holds the resolved value.
|
||||||
typedef std::vector<std::pair<Constant*, unsigned> > ResolveConstantsTy;
|
typedef std::vector<std::pair<Constant*, unsigned> > ResolveConstantsTy;
|
||||||
ResolveConstantsTy ResolveConstants;
|
ResolveConstantsTy ResolveConstants;
|
||||||
|
LLVMContext& Context;
|
||||||
public:
|
public:
|
||||||
BitcodeReaderValueList() {}
|
BitcodeReaderValueList(LLVMContext& C) : Context(C) {}
|
||||||
~BitcodeReaderValueList() {
|
~BitcodeReaderValueList() {
|
||||||
assert(ResolveConstants.empty() && "Constants not resolved?");
|
assert(ResolveConstants.empty() && "Constants not resolved?");
|
||||||
}
|
}
|
||||||
@ -126,7 +127,7 @@ class BitcodeReader : public ModuleProvider {
|
|||||||
DenseMap<Function*, std::pair<uint64_t, unsigned> > DeferredFunctionInfo;
|
DenseMap<Function*, std::pair<uint64_t, unsigned> > DeferredFunctionInfo;
|
||||||
public:
|
public:
|
||||||
explicit BitcodeReader(MemoryBuffer *buffer, LLVMContext& C)
|
explicit BitcodeReader(MemoryBuffer *buffer, LLVMContext& C)
|
||||||
: Context(C), Buffer(buffer), ErrorString(0) {
|
: Context(C), Buffer(buffer), ErrorString(0), ValueList(C) {
|
||||||
HasReversedFunctionsWithBodies = false;
|
HasReversedFunctionsWithBodies = false;
|
||||||
}
|
}
|
||||||
~BitcodeReader() {
|
~BitcodeReader() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user