mirror of
https://github.com/RPCS3/llvm.git
synced 2024-12-13 14:47:00 +00:00
add more support for ConstantDataSequential
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@148802 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
53fa1ae510
commit
1ee0ecf84a
@ -623,6 +623,9 @@ public:
|
||||
|
||||
/// getElementType - Return the element type of the array/vector.
|
||||
Type *getElementType() const;
|
||||
|
||||
/// getNumElements - Return the number of elements in the array or vector.
|
||||
unsigned getNumElements() const;
|
||||
|
||||
/// getElementByteSize - Return the size (in bytes) of each element in the
|
||||
/// array/vector. The size of the elements is known to be a multiple of one
|
||||
|
@ -1055,6 +1055,23 @@ SDValue SelectionDAGBuilder::getValueImpl(const Value *V) {
|
||||
return DAG.getMergeValues(&Constants[0], Constants.size(),
|
||||
getCurDebugLoc());
|
||||
}
|
||||
|
||||
if (const ConstantDataSequential *CDS =
|
||||
dyn_cast<ConstantDataSequential>(C)) {
|
||||
SmallVector<SDValue, 4> Ops;
|
||||
for (unsigned i = 0, e = CDS->getType()->getNumElements(); i != e; ++i) {
|
||||
SDNode *Val = getValue(CDS->getElementAsConstant(i)).getNode();
|
||||
// Add each leaf value from the operand to the Constants list
|
||||
// to form a flattened list of all the values.
|
||||
for (unsigned i = 0, e = Val->getNumValues(); i != e; ++i)
|
||||
Ops.push_back(SDValue(Val, i));
|
||||
}
|
||||
|
||||
if (isa<ArrayType>(CDS->getType()))
|
||||
return DAG.getMergeValues(&Ops[0], Ops.size(), getCurDebugLoc());
|
||||
return NodeMap[V] = DAG.getNode(ISD::BUILD_VECTOR, getCurDebugLoc(),
|
||||
VT, &Ops[0], Ops.size());
|
||||
}
|
||||
|
||||
if (C->getType()->isStructTy() || C->getType()->isArrayTy()) {
|
||||
assert((isa<ConstantAggregateZero>(C) || isa<UndefValue>(C)) &&
|
||||
@ -1089,9 +1106,9 @@ SDValue SelectionDAGBuilder::getValueImpl(const Value *V) {
|
||||
// Now that we know the number and type of the elements, get that number of
|
||||
// elements into the Ops array based on what kind of constant it is.
|
||||
SmallVector<SDValue, 16> Ops;
|
||||
if (const ConstantVector *CP = dyn_cast<ConstantVector>(C)) {
|
||||
if (const ConstantVector *CV = dyn_cast<ConstantVector>(C)) {
|
||||
for (unsigned i = 0; i != NumElements; ++i)
|
||||
Ops.push_back(getValue(CP->getOperand(i)));
|
||||
Ops.push_back(getValue(CV->getOperand(i)));
|
||||
} else {
|
||||
assert(isa<ConstantAggregateZero>(C) && "Unknown vector constant!");
|
||||
EVT EltVT = TLI.getValueType(VecTy->getElementType());
|
||||
|
@ -307,13 +307,12 @@ void ExecutionEngine::runStaticConstructorsDestructors(Module *module,
|
||||
|
||||
// Should be an array of '{ i32, void ()* }' structs. The first value is
|
||||
// the init priority, which we ignore.
|
||||
if (isa<ConstantAggregateZero>(GV->getInitializer()))
|
||||
ConstantArray *InitList = dyn_cast<ConstantArray>(GV->getInitializer());
|
||||
if (InitList == 0)
|
||||
return;
|
||||
ConstantArray *InitList = cast<ConstantArray>(GV->getInitializer());
|
||||
for (unsigned i = 0, e = InitList->getNumOperands(); i != e; ++i) {
|
||||
if (isa<ConstantAggregateZero>(InitList->getOperand(i)))
|
||||
continue;
|
||||
ConstantStruct *CS = cast<ConstantStruct>(InitList->getOperand(i));
|
||||
ConstantStruct *CS = dyn_cast<ConstantStruct>(InitList->getOperand(i));
|
||||
if (CS == 0) continue;
|
||||
|
||||
Constant *FP = CS->getOperand(1);
|
||||
if (FP->isNullValue())
|
||||
@ -954,30 +953,47 @@ void ExecutionEngine::LoadValueFromMemory(GenericValue &Result,
|
||||
void ExecutionEngine::InitializeMemory(const Constant *Init, void *Addr) {
|
||||
DEBUG(dbgs() << "JIT: Initializing " << Addr << " ");
|
||||
DEBUG(Init->dump());
|
||||
if (isa<UndefValue>(Init)) {
|
||||
if (isa<UndefValue>(Init))
|
||||
return;
|
||||
} else if (const ConstantVector *CP = dyn_cast<ConstantVector>(Init)) {
|
||||
|
||||
if (const ConstantVector *CP = dyn_cast<ConstantVector>(Init)) {
|
||||
unsigned ElementSize =
|
||||
getTargetData()->getTypeAllocSize(CP->getType()->getElementType());
|
||||
for (unsigned i = 0, e = CP->getNumOperands(); i != e; ++i)
|
||||
InitializeMemory(CP->getOperand(i), (char*)Addr+i*ElementSize);
|
||||
return;
|
||||
} else if (isa<ConstantAggregateZero>(Init)) {
|
||||
}
|
||||
|
||||
if (isa<ConstantAggregateZero>(Init)) {
|
||||
memset(Addr, 0, (size_t)getTargetData()->getTypeAllocSize(Init->getType()));
|
||||
return;
|
||||
} else if (const ConstantArray *CPA = dyn_cast<ConstantArray>(Init)) {
|
||||
}
|
||||
|
||||
if (const ConstantArray *CPA = dyn_cast<ConstantArray>(Init)) {
|
||||
unsigned ElementSize =
|
||||
getTargetData()->getTypeAllocSize(CPA->getType()->getElementType());
|
||||
for (unsigned i = 0, e = CPA->getNumOperands(); i != e; ++i)
|
||||
InitializeMemory(CPA->getOperand(i), (char*)Addr+i*ElementSize);
|
||||
return;
|
||||
} else if (const ConstantStruct *CPS = dyn_cast<ConstantStruct>(Init)) {
|
||||
}
|
||||
|
||||
if (const ConstantStruct *CPS = dyn_cast<ConstantStruct>(Init)) {
|
||||
const StructLayout *SL =
|
||||
getTargetData()->getStructLayout(cast<StructType>(CPS->getType()));
|
||||
for (unsigned i = 0, e = CPS->getNumOperands(); i != e; ++i)
|
||||
InitializeMemory(CPS->getOperand(i), (char*)Addr+SL->getElementOffset(i));
|
||||
return;
|
||||
} else if (Init->getType()->isFirstClassType()) {
|
||||
}
|
||||
|
||||
if (const ConstantDataSequential *CDS =
|
||||
dyn_cast<ConstantDataSequential>(Init)) {
|
||||
// CDS is already laid out in host memory order.
|
||||
StringRef Data = CDS->getRawDataValues();
|
||||
memcpy(Addr, Data.data(), Data.size());
|
||||
return;
|
||||
}
|
||||
|
||||
if (Init->getType()->isFirstClassType()) {
|
||||
GenericValue Val = getConstantValue(Init);
|
||||
StoreValueToMemory(Val, (GenericValue*)Addr, Init->getType());
|
||||
return;
|
||||
|
@ -843,29 +843,32 @@ bool ModuleLinker::linkAliasProto(GlobalAlias *SGA) {
|
||||
return false;
|
||||
}
|
||||
|
||||
static void getArrayElements(Constant *C, SmallVectorImpl<Constant*> &Dest) {
|
||||
if (ConstantArray *I = dyn_cast<ConstantArray>(C)) {
|
||||
for (unsigned i = 0, e = I->getNumOperands(); i != e; ++i)
|
||||
Dest.push_back(I->getOperand(i));
|
||||
return;
|
||||
}
|
||||
|
||||
if (ConstantDataSequential *CDS = dyn_cast<ConstantDataSequential>(C)) {
|
||||
for (unsigned i = 0, e = CDS->getNumElements(); i != e; ++i)
|
||||
Dest.push_back(CDS->getElementAsConstant(i));
|
||||
return;
|
||||
}
|
||||
|
||||
ConstantAggregateZero *CAZ = cast<ConstantAggregateZero>(C);
|
||||
Dest.append(cast<ArrayType>(C->getType())->getNumElements(),
|
||||
CAZ->getSequentialElement());
|
||||
}
|
||||
|
||||
void ModuleLinker::linkAppendingVarInit(const AppendingVarInfo &AVI) {
|
||||
// Merge the initializer.
|
||||
SmallVector<Constant*, 16> Elements;
|
||||
if (ConstantArray *I = dyn_cast<ConstantArray>(AVI.DstInit)) {
|
||||
for (unsigned i = 0, e = I->getNumOperands(); i != e; ++i)
|
||||
Elements.push_back(I->getOperand(i));
|
||||
} else {
|
||||
assert(isa<ConstantAggregateZero>(AVI.DstInit));
|
||||
ArrayType *DstAT = cast<ArrayType>(AVI.DstInit->getType());
|
||||
Type *EltTy = DstAT->getElementType();
|
||||
Elements.append(DstAT->getNumElements(), Constant::getNullValue(EltTy));
|
||||
}
|
||||
getArrayElements(AVI.DstInit, Elements);
|
||||
|
||||
Constant *SrcInit = MapValue(AVI.SrcInit, ValueMap, RF_None, &TypeMap);
|
||||
if (const ConstantArray *I = dyn_cast<ConstantArray>(SrcInit)) {
|
||||
for (unsigned i = 0, e = I->getNumOperands(); i != e; ++i)
|
||||
Elements.push_back(I->getOperand(i));
|
||||
} else {
|
||||
assert(isa<ConstantAggregateZero>(SrcInit));
|
||||
ArrayType *SrcAT = cast<ArrayType>(SrcInit->getType());
|
||||
Type *EltTy = SrcAT->getElementType();
|
||||
Elements.append(SrcAT->getNumElements(), Constant::getNullValue(EltTy));
|
||||
}
|
||||
getArrayElements(SrcInit, Elements);
|
||||
|
||||
ArrayType *NewType = cast<ArrayType>(AVI.NewGV->getType()->getElementType());
|
||||
AVI.NewGV->setInitializer(ConstantArray::get(NewType, Elements));
|
||||
}
|
||||
|
@ -1995,8 +1995,7 @@ Type *ConstantDataSequential::getElementType() const {
|
||||
}
|
||||
|
||||
StringRef ConstantDataSequential::getRawDataValues() const {
|
||||
return StringRef(DataElements,
|
||||
getType()->getNumElements()*getElementByteSize());
|
||||
return StringRef(DataElements, getNumElements()*getElementByteSize());
|
||||
}
|
||||
|
||||
/// isElementTypeCompatible - Return true if a ConstantDataSequential can be
|
||||
@ -2018,6 +2017,12 @@ bool ConstantDataSequential::isElementTypeCompatible(const Type *Ty) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/// getNumElements - Return the number of elements in the array or vector.
|
||||
unsigned ConstantDataSequential::getNumElements() const {
|
||||
return getType()->getNumElements();
|
||||
}
|
||||
|
||||
|
||||
/// getElementByteSize - Return the size in bytes of the elements in the data.
|
||||
uint64_t ConstantDataSequential::getElementByteSize() const {
|
||||
return getElementType()->getPrimitiveSizeInBits()/8;
|
||||
@ -2025,7 +2030,7 @@ uint64_t ConstantDataSequential::getElementByteSize() const {
|
||||
|
||||
/// getElementPointer - Return the start of the specified element.
|
||||
const char *ConstantDataSequential::getElementPointer(unsigned Elt) const {
|
||||
assert(Elt < getElementType()->getNumElements() && "Invalid Elt");
|
||||
assert(Elt < getNumElements() && "Invalid Elt");
|
||||
return DataElements+Elt*getElementByteSize();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user