Skip to content

Commit 30fded7

Browse files
committed
Revert "[LoopVectorizer] NFCI: Calculate register usage based on TLI.getTypeLegalizationCost."
This reverts commits: * [LoopVectorizer] NFCI: Calculate register usage based on TLI.getTypeLegalizationCost. b873aba. * [LoopVectorizer] Silence warning in GetRegUsage. 9ff7011.
1 parent 830ed64 commit 30fded7

File tree

5 files changed

+8
-19
lines changed

5 files changed

+8
-19
lines changed

llvm/include/llvm/Analysis/TargetTransformInfo.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -708,9 +708,6 @@ class TargetTransformInfo {
708708
/// Return true if this type is legal.
709709
bool isTypeLegal(Type *Ty) const;
710710

711-
/// Returns the estimated number of registers required to represent \p Ty.
712-
unsigned getRegUsageForType(Type *Ty) const;
713-
714711
/// Return true if switches should be turned into lookup tables for the
715712
/// target.
716713
bool shouldBuildLookupTables() const;
@@ -1450,7 +1447,6 @@ class TargetTransformInfo::Concept {
14501447
virtual bool isProfitableToHoist(Instruction *I) = 0;
14511448
virtual bool useAA() = 0;
14521449
virtual bool isTypeLegal(Type *Ty) = 0;
1453-
virtual unsigned getRegUsageForType(Type *Ty) = 0;
14541450
virtual bool shouldBuildLookupTables() = 0;
14551451
virtual bool shouldBuildLookupTablesForConstant(Constant *C) = 0;
14561452
virtual bool useColdCCForColdCall(Function &F) = 0;
@@ -1811,9 +1807,6 @@ class TargetTransformInfo::Model final : public TargetTransformInfo::Concept {
18111807
}
18121808
bool useAA() override { return Impl.useAA(); }
18131809
bool isTypeLegal(Type *Ty) override { return Impl.isTypeLegal(Ty); }
1814-
unsigned getRegUsageForType(Type *Ty) override {
1815-
return Impl.getRegUsageForType(Ty);
1816-
}
18171810
bool shouldBuildLookupTables() override {
18181811
return Impl.shouldBuildLookupTables();
18191812
}

llvm/include/llvm/Analysis/TargetTransformInfoImpl.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,6 @@ class TargetTransformInfoImplBase {
259259

260260
bool isTypeLegal(Type *Ty) { return false; }
261261

262-
unsigned getRegUsageForType(Type *Ty) { return 1; }
263-
264262
bool shouldBuildLookupTables() { return true; }
265263
bool shouldBuildLookupTablesForConstant(Constant *C) { return true; }
266264

llvm/include/llvm/CodeGen/BasicTTIImpl.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -297,10 +297,6 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
297297
return getTLI()->isTypeLegal(VT);
298298
}
299299

300-
unsigned getRegUsageForType(Type *Ty) {
301-
return getTLI()->getTypeLegalizationCost(DL, Ty).first;
302-
}
303-
304300
int getGEPCost(Type *PointeeType, const Value *Ptr,
305301
ArrayRef<const Value *> Operands) {
306302
return BaseT::getGEPCost(PointeeType, Ptr, Operands);

llvm/lib/Analysis/TargetTransformInfo.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -482,10 +482,6 @@ bool TargetTransformInfo::isTypeLegal(Type *Ty) const {
482482
return TTIImpl->isTypeLegal(Ty);
483483
}
484484

485-
unsigned TargetTransformInfo::getRegUsageForType(Type *Ty) const {
486-
return TTIImpl->getRegUsageForType(Ty);
487-
}
488-
489485
bool TargetTransformInfo::shouldBuildLookupTables() const {
490486
return TTIImpl->shouldBuildLookupTables();
491487
}

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5793,17 +5793,23 @@ LoopVectorizationCostModel::calculateRegisterUsage(ArrayRef<ElementCount> VFs) {
57935793
unsigned MaxSafeDepDist = -1U;
57945794
if (Legal->getMaxSafeDepDistBytes() != -1U)
57955795
MaxSafeDepDist = Legal->getMaxSafeDepDistBytes() * 8;
5796+
unsigned WidestRegister =
5797+
std::min(TTI.getRegisterBitWidth(true), MaxSafeDepDist);
5798+
const DataLayout &DL = TheFunction->getParent()->getDataLayout();
57965799

57975800
SmallVector<RegisterUsage, 8> RUs(VFs.size());
57985801
SmallVector<SmallMapVector<unsigned, unsigned, 4>, 8> MaxUsages(VFs.size());
57995802

58005803
LLVM_DEBUG(dbgs() << "LV(REG): Calculating max register usage:\n");
58015804

58025805
// A lambda that gets the register usage for the given type and VF.
5803-
auto GetRegUsage = [&TTI=TTI](Type *Ty, ElementCount VF) {
5806+
auto GetRegUsage = [&DL, WidestRegister](Type *Ty, ElementCount VF) {
58045807
if (Ty->isTokenTy())
58055808
return 0U;
5806-
return TTI.getRegUsageForType(VectorType::get(Ty, VF));
5809+
unsigned TypeSize = DL.getTypeSizeInBits(Ty->getScalarType());
5810+
assert(!VF.isScalable() && "scalable vectors not yet supported.");
5811+
return std::max<unsigned>(1, VF.getKnownMinValue() * TypeSize /
5812+
WidestRegister);
58075813
};
58085814

58095815
for (unsigned int i = 0, s = IdxToInstr.size(); i < s; ++i) {

0 commit comments

Comments
 (0)