[llvm] r258478 - [opaque pointer types] [NFC] DataLayout::getIndexedOffset: take source element type instead of pointer type and rename to getIndexedOffsetInType.
Eduard Burtescu via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 21 19:08:28 PST 2016
Author: eddyb
Date: Thu Jan 21 21:08:27 2016
New Revision: 258478
URL: http://llvm.org/viewvc/llvm-project?rev=258478&view=rev
Log:
[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
Modified:
llvm/trunk/include/llvm/IR/DataLayout.h
llvm/trunk/lib/Analysis/ConstantFolding.cpp
llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
llvm/trunk/lib/IR/DataLayout.cpp
llvm/trunk/lib/Transforms/Scalar/ScalarReplAggregates.cpp
Modified: llvm/trunk/include/llvm/IR/DataLayout.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/DataLayout.h?rev=258478&r1=258477&r2=258478&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/DataLayout.h (original)
+++ llvm/trunk/include/llvm/IR/DataLayout.h Thu Jan 21 21:08:27 2016
@@ -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.
Modified: llvm/trunk/lib/Analysis/ConstantFolding.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ConstantFolding.cpp?rev=258478&r1=258477&r2=258478&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ConstantFolding.cpp (original)
+++ llvm/trunk/lib/Analysis/ConstantFolding.cpp Thu Jan 21 21:08:27 2016
@@ -772,8 +772,8 @@ static Constant *SymbolicallyEvaluateGEP
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
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);
}
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp?rev=258478&r1=258477&r2=258478&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp Thu Jan 21 21:08:27 2016
@@ -192,14 +192,14 @@ DIE *DwarfCompileUnit::getOrCreateGlobal
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);
}
Modified: llvm/trunk/lib/IR/DataLayout.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/DataLayout.cpp?rev=258478&r1=258477&r2=258478&view=diff
==============================================================================
--- llvm/trunk/lib/IR/DataLayout.cpp (original)
+++ llvm/trunk/lib/IR/DataLayout.cpp Thu Jan 21 21:08:27 2016
@@ -723,40 +723,33 @@ unsigned DataLayout::getLargestLegalIntT
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());
}
}
Modified: llvm/trunk/lib/Transforms/Scalar/ScalarReplAggregates.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/ScalarReplAggregates.cpp?rev=258478&r1=258477&r2=258478&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/ScalarReplAggregates.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/ScalarReplAggregates.cpp Thu Jan 21 21:08:27 2016
@@ -524,8 +524,8 @@ bool ConvertToScalarInfo::CanConvertToSc
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::ConvertUsesToS
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 *
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
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);
More information about the llvm-commits
mailing list