[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:
Eduard Burtescu 2016-01-22 03:08:27 +00:00
parent e2a6917849
commit 68e7f49f8e
5 changed files with 27 additions and 32 deletions

View File

@ -441,8 +441,9 @@ public:
/// \brief Returns the offset from the beginning of the type for the specified
/// indices.
///
/// Note that this takes the element type, not the pointer type.
/// 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
/// struct, its size, and the offsets of its fields.

View File

@ -772,8 +772,8 @@ static Constant *SymbolicallyEvaluateGEP(const GEPOperator *GEP,
unsigned BitWidth = DL.getTypeSizeInBits(IntPtrTy);
APInt Offset =
APInt(BitWidth,
DL.getIndexedOffset(
Ptr->getType(),
DL.getIndexedOffsetInType(
SrcElemTy,
makeArrayRef((Value * const *)Ops.data() + 1, Ops.size() - 1)));
Ptr = StripPtrCastKeepAS(Ptr, SrcElemTy);
@ -792,7 +792,8 @@ static Constant *SymbolicallyEvaluateGEP(const GEPOperator *GEP,
break;
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);
}

View File

@ -192,14 +192,14 @@ DIE *DwarfCompileUnit::getOrCreateGlobalVariableDIE(
addToAccelTable = true;
// GV is a merged global.
DIELoc *Loc = new (DIEValueAllocator) DIELoc;
Value *Ptr = CE->getOperand(0);
MCSymbol *Sym = Asm->getSymbol(cast<GlobalValue>(Ptr));
auto *Ptr = cast<GlobalValue>(CE->getOperand(0));
MCSymbol *Sym = Asm->getSymbol(Ptr);
DD->addArangeLabel(SymbolCU(this, Sym));
addOpAddress(*Loc, Sym);
addUInt(*Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_constu);
SmallVector<Value *, 3> Idx(CE->op_begin() + 1, CE->op_end());
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);
addBlock(*VariableDIE, dwarf::DW_AT_location, Loc);
}

View File

@ -723,40 +723,33 @@ unsigned DataLayout::getLargestLegalIntTypeSize() const {
return Max != LegalIntWidths.end() ? *Max : 0;
}
uint64_t DataLayout::getIndexedOffset(Type *ptrTy,
ArrayRef<Value *> Indices) const {
Type *Ty = ptrTy;
assert(Ty->isPointerTy() && "Illegal argument for getIndexedOffset()");
uint64_t DataLayout::getIndexedOffsetInType(Type *ElemTy,
ArrayRef<Value *> Indices) const {
uint64_t Result = 0;
// We can use 0 as the address space as we don't need
// to get pointer types back from gep_type_iterator.
unsigned AS = 0;
generic_gep_type_iterator<Value* const*>
TI = gep_type_begin(ptrTy->getPointerElementType(), AS, Indices);
for (unsigned CurIDX = 0, EndIDX = Indices.size(); CurIDX != EndIDX;
++CurIDX, ++TI) {
if (StructType *STy = dyn_cast<StructType>(*TI)) {
assert(Indices[CurIDX]->getType() ==
Type::getInt32Ty(ptrTy->getContext()) &&
GTI = gep_type_begin(ElemTy, AS, Indices),
GTE = gep_type_end(ElemTy, AS, Indices);
for (; GTI != GTE; ++GTI) {
Value *Idx = GTI.getOperand();
if (StructType *STy = dyn_cast<StructType>(*GTI)) {
assert(Idx->getType() ==
Type::getInt32Ty(ElemTy->getContext()) &&
"Illegal struct idx");
unsigned FieldNo = cast<ConstantInt>(Indices[CurIDX])->getZExtValue();
unsigned FieldNo = cast<ConstantInt>(Idx)->getZExtValue();
// Get structure layout information...
const StructLayout *Layout = getStructLayout(STy);
// Add in the offset, as calculated by the structure layout info...
Result += Layout->getElementOffset(FieldNo);
// Update Ty to refer to current element
Ty = STy->getElementType(FieldNo);
} else {
// Update Ty to refer to current element
Ty = cast<SequentialType>(Ty)->getElementType();
// Get the array index and the size of each array element.
if (int64_t arrayIdx = cast<ConstantInt>(Indices[CurIDX])->getSExtValue())
Result += (uint64_t)arrayIdx * getTypeAllocSize(Ty);
if (int64_t arrayIdx = cast<ConstantInt>(Idx)->getSExtValue())
Result += (uint64_t)arrayIdx * getTypeAllocSize(GTI.getIndexedType());
}
}

View File

@ -524,8 +524,8 @@ bool ConvertToScalarInfo::CanConvertToScalar(Value *V, uint64_t Offset,
HadDynamicAccess = true;
} else
GEPNonConstantIdx = NonConstantIdx;
uint64_t GEPOffset = DL.getIndexedOffset(GEP->getPointerOperandType(),
Indices);
uint64_t GEPOffset = DL.getIndexedOffsetInType(GEP->getSourceElementType(),
Indices);
// See if all uses can be converted.
if (!CanConvertToScalar(GEP, Offset+GEPOffset, GEPNonConstantIdx))
return false;
@ -619,8 +619,8 @@ void ConvertToScalarInfo::ConvertUsesToScalar(Value *Ptr, AllocaInst *NewAI,
GEPNonConstantIdx = Indices.pop_back_val();
} else
GEPNonConstantIdx = NonConstantIdx;
uint64_t GEPOffset = DL.getIndexedOffset(GEP->getPointerOperandType(),
Indices);
uint64_t GEPOffset = DL.getIndexedOffsetInType(GEP->getSourceElementType(),
Indices);
ConvertUsesToScalar(GEP, NewAI, Offset+GEPOffset*8, GEPNonConstantIdx);
GEP->eraseFromParent();
continue;
@ -1736,7 +1736,7 @@ void SROA::isSafeGEP(GetElementPtrInst *GEPI,
Indices.pop_back();
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,
DL))
MarkUnsafe(Info, GEPI);
@ -2052,7 +2052,7 @@ void SROA::RewriteGEP(GetElementPtrInst *GEPI, AllocaInst *AI, uint64_t Offset,
Value* NonConstantIdx = nullptr;
if (!GEPI->hasAllConstantIndices())
NonConstantIdx = Indices.pop_back_val();
Offset += DL.getIndexedOffset(GEPI->getPointerOperandType(), Indices);
Offset += DL.getIndexedOffsetInType(GEPI->getSourceElementType(), Indices);
RewriteForScalarRepl(GEPI, AI, Offset, NewElts);