<div dir="ltr">If you don't expect it to ever be null you could probably make it a reference :)<div><br></div><div>-eric</div></div><br><div class="gmail_quote"><div dir="ltr">On Wed, Mar 16, 2016 at 12:54 PM Chad Rosier via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: mcrosier<br>
Date: Wed Mar 16 14:48:42 2016<br>
New Revision: 263656<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=263656&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=263656&view=rev</a><br>
Log:<br>
[SLP] Make DataLayout a member variable.<br>
<br>
Modified:<br>
llvm/trunk/lib/Transforms/Vectorize/SLPVectorizer.cpp<br>
<br>
Modified: llvm/trunk/lib/Transforms/Vectorize/SLPVectorizer.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Vectorize/SLPVectorizer.cpp?rev=263656&r1=263655&r2=263656&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Vectorize/SLPVectorizer.cpp?rev=263656&r1=263655&r2=263656&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Transforms/Vectorize/SLPVectorizer.cpp (original)<br>
+++ llvm/trunk/lib/Transforms/Vectorize/SLPVectorizer.cpp Wed Mar 16 14:48:42 2016<br>
@@ -368,10 +368,11 @@ public:<br>
<br>
BoUpSLP(Function *Func, ScalarEvolution *Se, TargetTransformInfo *Tti,<br>
TargetLibraryInfo *TLi, AliasAnalysis *Aa, LoopInfo *Li,<br>
- DominatorTree *Dt, AssumptionCache *AC, DemandedBits *DB)<br>
+ DominatorTree *Dt, AssumptionCache *AC, DemandedBits *DB,<br>
+ const DataLayout *DL)<br>
: NumLoadsWantToKeepOrder(0), NumLoadsWantToChangeOrder(0), F(Func),<br>
SE(Se), TTI(Tti), TLI(TLi), AA(Aa), LI(Li), DT(Dt), AC(AC), DB(DB),<br>
- Builder(Se->getContext()) {<br>
+ DL(DL), Builder(Se->getContext()) {<br>
CodeMetrics::collectEphemeralValues(F, AC, EphValues);<br>
}<br>
<br>
@@ -925,6 +926,7 @@ private:<br>
DominatorTree *DT;<br>
AssumptionCache *AC;<br>
DemandedBits *DB;<br>
+ const DataLayout *DL;<br>
/// Instruction builder to construct the vectorized tree.<br>
IRBuilder<> Builder;<br>
<br>
@@ -1176,11 +1178,10 @@ void BoUpSLP::buildTree_rec(ArrayRef<Val<br>
// loading/storing it as an i8 struct. If we vectorize loads/stores from<br>
// such a struct we read/write packed bits disagreeing with the<br>
// unvectorized version.<br>
- const DataLayout &DL = F->getParent()->getDataLayout();<br>
Type *ScalarTy = VL[0]->getType();<br>
<br>
- if (DL.getTypeSizeInBits(ScalarTy) !=<br>
- DL.getTypeAllocSizeInBits(ScalarTy)) {<br>
+ if (DL->getTypeSizeInBits(ScalarTy) !=<br>
+ DL->getTypeAllocSizeInBits(ScalarTy)) {<br>
BS.cancelScheduling(VL);<br>
newTreeEntry(VL, false);<br>
DEBUG(dbgs() << "SLP: Gathering loads of non-packed type.\n");<br>
@@ -1196,8 +1197,8 @@ void BoUpSLP::buildTree_rec(ArrayRef<Val<br>
return;<br>
}<br>
<br>
- if (!isConsecutiveAccess(VL[i], VL[i + 1], DL, *SE)) {<br>
- if (VL.size() == 2 && isConsecutiveAccess(VL[1], VL[0], DL, *SE)) {<br>
+ if (!isConsecutiveAccess(VL[i], VL[i + 1], *DL, *SE)) {<br>
+ if (VL.size() == 2 && isConsecutiveAccess(VL[1], VL[0], *DL, *SE)) {<br>
++NumLoadsWantToChangeOrder;<br>
}<br>
BS.cancelScheduling(VL);<br>
@@ -1366,10 +1367,9 @@ void BoUpSLP::buildTree_rec(ArrayRef<Val<br>
return;<br>
}<br>
case Instruction::Store: {<br>
- const DataLayout &DL = F->getParent()->getDataLayout();<br>
// Check if the stores are consecutive or of we need to swizzle them.<br>
for (unsigned i = 0, e = VL.size() - 1; i < e; ++i)<br>
- if (!isConsecutiveAccess(VL[i], VL[i + 1], DL, *SE)) {<br>
+ if (!isConsecutiveAccess(VL[i], VL[i + 1], *DL, *SE)) {<br>
BS.cancelScheduling(VL);<br>
newTreeEntry(VL, false);<br>
DEBUG(dbgs() << "SLP: Non-consecutive store.\n");<br>
@@ -1872,8 +1872,6 @@ int BoUpSLP::getGatherCost(ArrayRef<Valu<br>
void BoUpSLP::reorderAltShuffleOperands(ArrayRef<Value *> VL,<br>
SmallVectorImpl<Value *> &Left,<br>
SmallVectorImpl<Value *> &Right) {<br>
- const DataLayout &DL = F->getParent()->getDataLayout();<br>
-<br>
// Push left and right operands of binary operation into Left and Right<br>
for (unsigned i = 0, e = VL.size(); i < e; ++i) {<br>
Left.push_back(cast<Instruction>(VL[i])->getOperand(0));<br>
@@ -1887,10 +1885,11 @@ void BoUpSLP::reorderAltShuffleOperands(<br>
if (LoadInst *L1 = dyn_cast<LoadInst>(Right[j + 1])) {<br>
Instruction *VL1 = cast<Instruction>(VL[j]);<br>
Instruction *VL2 = cast<Instruction>(VL[j + 1]);<br>
- if (VL1->isCommutative() && isConsecutiveAccess(L, L1, DL, *SE)) {<br>
+ if (VL1->isCommutative() && isConsecutiveAccess(L, L1, *DL, *SE)) {<br>
std::swap(Left[j], Right[j]);<br>
continue;<br>
- } else if (VL2->isCommutative() && isConsecutiveAccess(L, L1, DL, *SE)) {<br>
+ } else if (VL2->isCommutative() &&<br>
+ isConsecutiveAccess(L, L1, *DL, *SE)) {<br>
std::swap(Left[j + 1], Right[j + 1]);<br>
continue;<br>
}<br>
@@ -1901,10 +1900,11 @@ void BoUpSLP::reorderAltShuffleOperands(<br>
if (LoadInst *L1 = dyn_cast<LoadInst>(Left[j + 1])) {<br>
Instruction *VL1 = cast<Instruction>(VL[j]);<br>
Instruction *VL2 = cast<Instruction>(VL[j + 1]);<br>
- if (VL1->isCommutative() && isConsecutiveAccess(L, L1, DL, *SE)) {<br>
+ if (VL1->isCommutative() && isConsecutiveAccess(L, L1, *DL, *SE)) {<br>
std::swap(Left[j], Right[j]);<br>
continue;<br>
- } else if (VL2->isCommutative() && isConsecutiveAccess(L, L1, DL, *SE)) {<br>
+ } else if (VL2->isCommutative() &&<br>
+ isConsecutiveAccess(L, L1, *DL, *SE)) {<br>
std::swap(Left[j + 1], Right[j + 1]);<br>
continue;<br>
}<br>
@@ -2034,8 +2034,6 @@ void BoUpSLP::reorderInputsAccordingToOp<br>
if (SplatRight || SplatLeft)<br>
return;<br>
<br>
- const DataLayout &DL = F->getParent()->getDataLayout();<br>
-<br>
// Finally check if we can get longer vectorizable chain by reordering<br>
// without breaking the good operand order detected above.<br>
// E.g. If we have something like-<br>
@@ -2054,7 +2052,7 @@ void BoUpSLP::reorderInputsAccordingToOp<br>
for (unsigned j = 0; j < VL.size() - 1; ++j) {<br>
if (LoadInst *L = dyn_cast<LoadInst>(Left[j])) {<br>
if (LoadInst *L1 = dyn_cast<LoadInst>(Right[j + 1])) {<br>
- if (isConsecutiveAccess(L, L1, DL, *SE)) {<br>
+ if (isConsecutiveAccess(L, L1, *DL, *SE)) {<br>
std::swap(Left[j + 1], Right[j + 1]);<br>
continue;<br>
}<br>
@@ -2062,7 +2060,7 @@ void BoUpSLP::reorderInputsAccordingToOp<br>
}<br>
if (LoadInst *L = dyn_cast<LoadInst>(Right[j])) {<br>
if (LoadInst *L1 = dyn_cast<LoadInst>(Left[j + 1])) {<br>
- if (isConsecutiveAccess(L, L1, DL, *SE)) {<br>
+ if (isConsecutiveAccess(L, L1, *DL, *SE)) {<br>
std::swap(Left[j + 1], Right[j + 1]);<br>
continue;<br>
}<br>
@@ -2158,7 +2156,6 @@ Value *BoUpSLP::vectorizeTree(TreeEntry<br>
return Gather(E->Scalars, VecTy);<br>
}<br>
<br>
- const DataLayout &DL = F->getParent()->getDataLayout();<br>
unsigned Opcode = getSameOpcode(E->Scalars);<br>
<br>
switch (Opcode) {<br>
@@ -2355,7 +2352,7 @@ Value *BoUpSLP::vectorizeTree(TreeEntry<br>
unsigned Alignment = LI->getAlignment();<br>
LI = Builder.CreateLoad(VecPtr);<br>
if (!Alignment) {<br>
- Alignment = DL.getABITypeAlignment(ScalarLoadTy);<br>
+ Alignment = DL->getABITypeAlignment(ScalarLoadTy);<br>
}<br>
LI->setAlignment(Alignment);<br>
E->VectorizedValue = LI;<br>
@@ -2386,7 +2383,7 @@ Value *BoUpSLP::vectorizeTree(TreeEntry<br>
ExternalUser(SI->getPointerOperand(), cast<User>(VecPtr), 0));<br>
<br>
if (!Alignment) {<br>
- Alignment = DL.getABITypeAlignment(SI->getValueOperand()->getType());<br>
+ Alignment = DL->getABITypeAlignment(SI->getValueOperand()->getType());<br>
}<br>
S->setAlignment(Alignment);<br>
E->VectorizedValue = S;<br>
@@ -3133,12 +3130,10 @@ void BoUpSLP::scheduleBlock(BlockSchedul<br>
}<br>
<br>
unsigned BoUpSLP::getVectorElementSize(Value *V) {<br>
- auto &DL = F->getParent()->getDataLayout();<br>
-<br>
// If V is a store, just return the width of the stored value without<br>
// traversing the expression tree. This is the common case.<br>
if (auto *Store = dyn_cast<StoreInst>(V))<br>
- return DL.getTypeSizeInBits(Store->getValueOperand()->getType());<br>
+ return DL->getTypeSizeInBits(Store->getValueOperand()->getType());<br>
<br>
// If V is not a store, we can traverse the expression tree to find loads<br>
// that feed it. The type of the loaded value may indicate a more suitable<br>
@@ -3166,7 +3161,7 @@ unsigned BoUpSLP::getVectorElementSize(V<br>
// If the current instruction is a load, update MaxWidth to reflect the<br>
// width of the loaded value.<br>
else if (isa<LoadInst>(I))<br>
- MaxWidth = std::max<unsigned>(MaxWidth, DL.getTypeSizeInBits(Ty));<br>
+ MaxWidth = std::max<unsigned>(MaxWidth, DL->getTypeSizeInBits(Ty));<br>
<br>
// Otherwise, we need to visit the operands of the instruction. We only<br>
// handle the interesting cases from buildTree here. If an operand is an<br>
@@ -3187,7 +3182,7 @@ unsigned BoUpSLP::getVectorElementSize(V<br>
// If we didn't encounter a memory access in the expression tree, or if we<br>
// gave up for some reason, just return the width of V.<br>
if (!MaxWidth || FoundUnknownInst)<br>
- return DL.getTypeSizeInBits(V->getType());<br>
+ return DL->getTypeSizeInBits(V->getType());<br>
<br>
// Otherwise, return the maximum width we found.<br>
return MaxWidth;<br>
@@ -3265,8 +3260,6 @@ static bool collectValuesToDemote(Value<br>
}<br>
<br>
void BoUpSLP::computeMinimumValueSizes() {<br>
- auto &DL = F->getParent()->getDataLayout();<br>
-<br>
// If there are no external uses, the expression tree must be rooted by a<br>
// store. We can't demote in-memory values, so there is nothing to do here.<br>
if (ExternalUses.empty())<br>
@@ -3334,11 +3327,11 @@ void BoUpSLP::computeMinimumValueSizes()<br>
// We start by looking at each entry that can be demoted. We compute the<br>
// maximum bit width required to store the scalar by using ValueTracking to<br>
// compute the number of high-order bits we can truncate.<br>
- if (MaxBitWidth == DL.getTypeSizeInBits(TreeRoot[0]->getType())) {<br>
+ if (MaxBitWidth == DL->getTypeSizeInBits(TreeRoot[0]->getType())) {<br>
MaxBitWidth = 8u;<br>
for (auto *Scalar : ToDemote) {<br>
- auto NumSignBits = ComputeNumSignBits(Scalar, DL, 0, AC, 0, DT);<br>
- auto NumTypeBits = DL.getTypeSizeInBits(Scalar->getType());<br>
+ auto NumSignBits = ComputeNumSignBits(Scalar, *DL, 0, AC, 0, DT);<br>
+ auto NumTypeBits = DL->getTypeSizeInBits(Scalar->getType());<br>
MaxBitWidth = std::max<unsigned>(NumTypeBits - NumSignBits, MaxBitWidth);<br>
}<br>
}<br>
@@ -3385,6 +3378,12 @@ struct SLPVectorizer : public FunctionPa<br>
DominatorTree *DT;<br>
AssumptionCache *AC;<br>
DemandedBits *DB;<br>
+ const DataLayout *DL;<br>
+<br>
+ bool doInitialization(Module &M) override {<br>
+ DL = &M.getDataLayout();<br>
+ return false;<br>
+ }<br>
<br>
bool runOnFunction(Function &F) override {<br>
if (skipOptnoneFunction(F))<br>
@@ -3430,7 +3429,7 @@ struct SLPVectorizer : public FunctionPa<br>
<br>
// Use the bottom up slp vectorizer to construct chains that start with<br>
// store instructions.<br>
- BoUpSLP R(&F, SE, TTI, TLI, AA, LI, DT, AC, DB);<br>
+ BoUpSLP R(&F, SE, TTI, TLI, AA, LI, DT, AC, DB, DL);<br>
<br>
// A general note: the vectorizer must use BoUpSLP::eraseInstruction() to<br>
// delete instructions.<br>
@@ -3611,7 +3610,6 @@ bool SLPVectorizer::vectorizeStores(Arra<br>
// all of the pairs of stores that follow each other.<br>
SmallVector<unsigned, 16> IndexQueue;<br>
for (unsigned i = 0, e = Stores.size(); i < e; ++i) {<br>
- const DataLayout &DL = Stores[i]->getModule()->getDataLayout();<br>
IndexQueue.clear();<br>
// If a store has multiple consecutive store candidates, search Stores<br>
// array according to the sequence: from i+1 to e, then from i-1 to 0.<br>
@@ -3624,7 +3622,7 @@ bool SLPVectorizer::vectorizeStores(Arra<br>
IndexQueue.push_back(j - 1);<br>
<br>
for (auto &k : IndexQueue) {<br>
- if (isConsecutiveAccess(Stores[i], Stores[k], DL, *SE)) {<br>
+ if (isConsecutiveAccess(Stores[i], Stores[k], *DL, *SE)) {<br>
Tails.insert(Stores[k]);<br>
Heads.insert(Stores[i]);<br>
ConsecutiveChain[Stores[i]] = Stores[k];<br>
@@ -3673,7 +3671,6 @@ void SLPVectorizer::collectSeedInstructi<br>
Stores.clear();<br>
GEPs.clear();<br>
NumStores = NumGEPs = 0;<br>
- const DataLayout &DL = BB->getModule()->getDataLayout();<br>
<br>
// Visit the store and getelementptr instructions in BB and organize them in<br>
// Stores and GEPs according to the underlying objects of their pointer<br>
@@ -3687,7 +3684,7 @@ void SLPVectorizer::collectSeedInstructi<br>
continue;<br>
if (!isValidElementType(SI->getValueOperand()->getType()))<br>
continue;<br>
- Stores[GetUnderlyingObject(SI->getPointerOperand(), DL)].push_back(SI);<br>
+ Stores[GetUnderlyingObject(SI->getPointerOperand(), *DL)].push_back(SI);<br>
++NumStores;<br>
}<br>
<br>
@@ -3700,7 +3697,7 @@ void SLPVectorizer::collectSeedInstructi<br>
continue;<br>
if (!isValidElementType(Idx->getType()))<br>
continue;<br>
- GEPs[GetUnderlyingObject(GEP->getPointerOperand(), DL)].push_back(GEP);<br>
+ GEPs[GetUnderlyingObject(GEP->getPointerOperand(), *DL)].push_back(GEP);<br>
++NumGEPs;<br>
}<br>
}<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div>