forked from OSchip/llvm-project
[opaque pointer types] [NFC] DataLayout::getIndexedOffset: take source element type instead of pointer type and rename to getIndexedOffsetInType.
Summary: Reviewers: mjacob, dblaikie Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D16282 llvm-svn: 258478
This commit is contained in:
parent
e2a6917849
commit
68e7f49f8e
|
@ -441,8 +441,9 @@ public:
|
||||||
/// \brief Returns the offset from the beginning of the type for the specified
|
/// \brief Returns the offset from the beginning of the type for the specified
|
||||||
/// indices.
|
/// indices.
|
||||||
///
|
///
|
||||||
|
/// Note that this takes the element type, not the pointer type.
|
||||||
/// This is used to implement getelementptr.
|
/// This is used to implement getelementptr.
|
||||||
uint64_t getIndexedOffset(Type *Ty, ArrayRef<Value *> Indices) const;
|
uint64_t getIndexedOffsetInType(Type *ElemTy, ArrayRef<Value *> Indices) const;
|
||||||
|
|
||||||
/// \brief Returns a StructLayout object, indicating the alignment of the
|
/// \brief Returns a StructLayout object, indicating the alignment of the
|
||||||
/// struct, its size, and the offsets of its fields.
|
/// struct, its size, and the offsets of its fields.
|
||||||
|
|
|
@ -772,8 +772,8 @@ static Constant *SymbolicallyEvaluateGEP(const GEPOperator *GEP,
|
||||||
unsigned BitWidth = DL.getTypeSizeInBits(IntPtrTy);
|
unsigned BitWidth = DL.getTypeSizeInBits(IntPtrTy);
|
||||||
APInt Offset =
|
APInt Offset =
|
||||||
APInt(BitWidth,
|
APInt(BitWidth,
|
||||||
DL.getIndexedOffset(
|
DL.getIndexedOffsetInType(
|
||||||
Ptr->getType(),
|
SrcElemTy,
|
||||||
makeArrayRef((Value * const *)Ops.data() + 1, Ops.size() - 1)));
|
makeArrayRef((Value * const *)Ops.data() + 1, Ops.size() - 1)));
|
||||||
Ptr = StripPtrCastKeepAS(Ptr, SrcElemTy);
|
Ptr = StripPtrCastKeepAS(Ptr, SrcElemTy);
|
||||||
|
|
||||||
|
@ -792,7 +792,8 @@ static Constant *SymbolicallyEvaluateGEP(const GEPOperator *GEP,
|
||||||
break;
|
break;
|
||||||
|
|
||||||
Ptr = cast<Constant>(GEP->getOperand(0));
|
Ptr = cast<Constant>(GEP->getOperand(0));
|
||||||
Offset += APInt(BitWidth, DL.getIndexedOffset(Ptr->getType(), NestedOps));
|
SrcElemTy = GEP->getSourceElementType();
|
||||||
|
Offset += APInt(BitWidth, DL.getIndexedOffsetInType(SrcElemTy, NestedOps));
|
||||||
Ptr = StripPtrCastKeepAS(Ptr, SrcElemTy);
|
Ptr = StripPtrCastKeepAS(Ptr, SrcElemTy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -192,14 +192,14 @@ DIE *DwarfCompileUnit::getOrCreateGlobalVariableDIE(
|
||||||
addToAccelTable = true;
|
addToAccelTable = true;
|
||||||
// GV is a merged global.
|
// GV is a merged global.
|
||||||
DIELoc *Loc = new (DIEValueAllocator) DIELoc;
|
DIELoc *Loc = new (DIEValueAllocator) DIELoc;
|
||||||
Value *Ptr = CE->getOperand(0);
|
auto *Ptr = cast<GlobalValue>(CE->getOperand(0));
|
||||||
MCSymbol *Sym = Asm->getSymbol(cast<GlobalValue>(Ptr));
|
MCSymbol *Sym = Asm->getSymbol(Ptr);
|
||||||
DD->addArangeLabel(SymbolCU(this, Sym));
|
DD->addArangeLabel(SymbolCU(this, Sym));
|
||||||
addOpAddress(*Loc, Sym);
|
addOpAddress(*Loc, Sym);
|
||||||
addUInt(*Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_constu);
|
addUInt(*Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_constu);
|
||||||
SmallVector<Value *, 3> Idx(CE->op_begin() + 1, CE->op_end());
|
SmallVector<Value *, 3> Idx(CE->op_begin() + 1, CE->op_end());
|
||||||
addUInt(*Loc, dwarf::DW_FORM_udata,
|
addUInt(*Loc, dwarf::DW_FORM_udata,
|
||||||
Asm->getDataLayout().getIndexedOffset(Ptr->getType(), Idx));
|
Asm->getDataLayout().getIndexedOffsetInType(Ptr->getValueType(), Idx));
|
||||||
addUInt(*Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_plus);
|
addUInt(*Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_plus);
|
||||||
addBlock(*VariableDIE, dwarf::DW_AT_location, Loc);
|
addBlock(*VariableDIE, dwarf::DW_AT_location, Loc);
|
||||||
}
|
}
|
||||||
|
|
|
@ -723,40 +723,33 @@ unsigned DataLayout::getLargestLegalIntTypeSize() const {
|
||||||
return Max != LegalIntWidths.end() ? *Max : 0;
|
return Max != LegalIntWidths.end() ? *Max : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t DataLayout::getIndexedOffset(Type *ptrTy,
|
uint64_t DataLayout::getIndexedOffsetInType(Type *ElemTy,
|
||||||
ArrayRef<Value *> Indices) const {
|
ArrayRef<Value *> Indices) const {
|
||||||
Type *Ty = ptrTy;
|
|
||||||
assert(Ty->isPointerTy() && "Illegal argument for getIndexedOffset()");
|
|
||||||
uint64_t Result = 0;
|
uint64_t Result = 0;
|
||||||
|
|
||||||
// We can use 0 as the address space as we don't need
|
// We can use 0 as the address space as we don't need
|
||||||
// to get pointer types back from gep_type_iterator.
|
// to get pointer types back from gep_type_iterator.
|
||||||
unsigned AS = 0;
|
unsigned AS = 0;
|
||||||
generic_gep_type_iterator<Value* const*>
|
generic_gep_type_iterator<Value* const*>
|
||||||
TI = gep_type_begin(ptrTy->getPointerElementType(), AS, Indices);
|
GTI = gep_type_begin(ElemTy, AS, Indices),
|
||||||
for (unsigned CurIDX = 0, EndIDX = Indices.size(); CurIDX != EndIDX;
|
GTE = gep_type_end(ElemTy, AS, Indices);
|
||||||
++CurIDX, ++TI) {
|
for (; GTI != GTE; ++GTI) {
|
||||||
if (StructType *STy = dyn_cast<StructType>(*TI)) {
|
Value *Idx = GTI.getOperand();
|
||||||
assert(Indices[CurIDX]->getType() ==
|
if (StructType *STy = dyn_cast<StructType>(*GTI)) {
|
||||||
Type::getInt32Ty(ptrTy->getContext()) &&
|
assert(Idx->getType() ==
|
||||||
|
Type::getInt32Ty(ElemTy->getContext()) &&
|
||||||
"Illegal struct idx");
|
"Illegal struct idx");
|
||||||
unsigned FieldNo = cast<ConstantInt>(Indices[CurIDX])->getZExtValue();
|
unsigned FieldNo = cast<ConstantInt>(Idx)->getZExtValue();
|
||||||
|
|
||||||
// Get structure layout information...
|
// Get structure layout information...
|
||||||
const StructLayout *Layout = getStructLayout(STy);
|
const StructLayout *Layout = getStructLayout(STy);
|
||||||
|
|
||||||
// Add in the offset, as calculated by the structure layout info...
|
// Add in the offset, as calculated by the structure layout info...
|
||||||
Result += Layout->getElementOffset(FieldNo);
|
Result += Layout->getElementOffset(FieldNo);
|
||||||
|
|
||||||
// Update Ty to refer to current element
|
|
||||||
Ty = STy->getElementType(FieldNo);
|
|
||||||
} else {
|
} else {
|
||||||
// Update Ty to refer to current element
|
|
||||||
Ty = cast<SequentialType>(Ty)->getElementType();
|
|
||||||
|
|
||||||
// Get the array index and the size of each array element.
|
// Get the array index and the size of each array element.
|
||||||
if (int64_t arrayIdx = cast<ConstantInt>(Indices[CurIDX])->getSExtValue())
|
if (int64_t arrayIdx = cast<ConstantInt>(Idx)->getSExtValue())
|
||||||
Result += (uint64_t)arrayIdx * getTypeAllocSize(Ty);
|
Result += (uint64_t)arrayIdx * getTypeAllocSize(GTI.getIndexedType());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -524,7 +524,7 @@ bool ConvertToScalarInfo::CanConvertToScalar(Value *V, uint64_t Offset,
|
||||||
HadDynamicAccess = true;
|
HadDynamicAccess = true;
|
||||||
} else
|
} else
|
||||||
GEPNonConstantIdx = NonConstantIdx;
|
GEPNonConstantIdx = NonConstantIdx;
|
||||||
uint64_t GEPOffset = DL.getIndexedOffset(GEP->getPointerOperandType(),
|
uint64_t GEPOffset = DL.getIndexedOffsetInType(GEP->getSourceElementType(),
|
||||||
Indices);
|
Indices);
|
||||||
// See if all uses can be converted.
|
// See if all uses can be converted.
|
||||||
if (!CanConvertToScalar(GEP, Offset+GEPOffset, GEPNonConstantIdx))
|
if (!CanConvertToScalar(GEP, Offset+GEPOffset, GEPNonConstantIdx))
|
||||||
|
@ -619,7 +619,7 @@ void ConvertToScalarInfo::ConvertUsesToScalar(Value *Ptr, AllocaInst *NewAI,
|
||||||
GEPNonConstantIdx = Indices.pop_back_val();
|
GEPNonConstantIdx = Indices.pop_back_val();
|
||||||
} else
|
} else
|
||||||
GEPNonConstantIdx = NonConstantIdx;
|
GEPNonConstantIdx = NonConstantIdx;
|
||||||
uint64_t GEPOffset = DL.getIndexedOffset(GEP->getPointerOperandType(),
|
uint64_t GEPOffset = DL.getIndexedOffsetInType(GEP->getSourceElementType(),
|
||||||
Indices);
|
Indices);
|
||||||
ConvertUsesToScalar(GEP, NewAI, Offset+GEPOffset*8, GEPNonConstantIdx);
|
ConvertUsesToScalar(GEP, NewAI, Offset+GEPOffset*8, GEPNonConstantIdx);
|
||||||
GEP->eraseFromParent();
|
GEP->eraseFromParent();
|
||||||
|
@ -1736,7 +1736,7 @@ void SROA::isSafeGEP(GetElementPtrInst *GEPI,
|
||||||
Indices.pop_back();
|
Indices.pop_back();
|
||||||
|
|
||||||
const DataLayout &DL = GEPI->getModule()->getDataLayout();
|
const DataLayout &DL = GEPI->getModule()->getDataLayout();
|
||||||
Offset += DL.getIndexedOffset(GEPI->getPointerOperandType(), Indices);
|
Offset += DL.getIndexedOffsetInType(GEPI->getSourceElementType(), Indices);
|
||||||
if (!TypeHasComponent(Info.AI->getAllocatedType(), Offset, NonConstantIdxSize,
|
if (!TypeHasComponent(Info.AI->getAllocatedType(), Offset, NonConstantIdxSize,
|
||||||
DL))
|
DL))
|
||||||
MarkUnsafe(Info, GEPI);
|
MarkUnsafe(Info, GEPI);
|
||||||
|
@ -2052,7 +2052,7 @@ void SROA::RewriteGEP(GetElementPtrInst *GEPI, AllocaInst *AI, uint64_t Offset,
|
||||||
Value* NonConstantIdx = nullptr;
|
Value* NonConstantIdx = nullptr;
|
||||||
if (!GEPI->hasAllConstantIndices())
|
if (!GEPI->hasAllConstantIndices())
|
||||||
NonConstantIdx = Indices.pop_back_val();
|
NonConstantIdx = Indices.pop_back_val();
|
||||||
Offset += DL.getIndexedOffset(GEPI->getPointerOperandType(), Indices);
|
Offset += DL.getIndexedOffsetInType(GEPI->getSourceElementType(), Indices);
|
||||||
|
|
||||||
RewriteForScalarRepl(GEPI, AI, Offset, NewElts);
|
RewriteForScalarRepl(GEPI, AI, Offset, NewElts);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue