Skip to content

Commit 43e0b0f

Browse files
aparshin-inteligcbot
authored andcommitted
extend VC type size wrapper with strict size calculation
In some situations we'd like to ensure that the type size can be represented in the specified units of measurements exactly.
1 parent 278c9b5 commit 43e0b0f

File tree

4 files changed

+30
-11
lines changed

4 files changed

+30
-11
lines changed

IGC/VectorCompiler/include/vc/Utils/GenX/TypeSize.h

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,30 @@ class TypeSizeWrapper {
5757
TypeSizeWrapper(uint64_t TSIn) : TS{FixedDLSize(TSIn)} {};
5858
#endif
5959

60-
SzType inBits() const { return asIntegral<1>(); }
61-
SzType inBytes() const { return asIntegral<ByteBits>(); }
62-
SzType inWords() const { return asIntegral<WordBits>(); }
63-
SzType inDWords() const { return asIntegral<DWordBits>(); }
64-
SzType inQWords() const { return asIntegral<QWordBits>(); }
65-
SzType inOWords() const { return asIntegral<OWordBits>(); }
60+
SzType inBytesCeil() const { return asIntegralCeil<ByteBits>(); }
61+
SzType inWordsCeil() const { return asIntegralCeil<WordBits>(); }
62+
SzType inDWordsCeil() const { return asIntegralCeil<DWordBits>(); }
63+
SzType inQWordsCeil() const { return asIntegralCeil<QWordBits>(); }
64+
SzType inOWordsCeil() const { return asIntegralCeil<OWordBits>(); }
65+
66+
SzType inBits() const { return asIntegralStrict<1>(); }
67+
SzType inBytes() const { return asIntegralStrict<ByteBits>(); }
68+
SzType inWords() const { return asIntegralStrict<WordBits>(); }
69+
SzType inDWords() const { return asIntegralStrict<DWordBits>(); }
70+
SzType inQWords() const { return asIntegralStrict<QWordBits>(); }
71+
SzType inOWords() const { return asIntegralStrict<OWordBits>(); }
6672

6773
bool operator==(const TypeSizeWrapper &Other) const { return TS == Other.TS; }
6874

6975
private:
70-
template <unsigned UnitBitSize> SzType asIntegral() const {
76+
template <unsigned UnitBitSize> SzType asIntegralStrict() const {
77+
return asIntegral<UnitBitSize, true>();
78+
}
79+
template <unsigned UnitBitSize> SzType asIntegralCeil() const {
80+
return asIntegral<UnitBitSize, false>();
81+
}
82+
83+
template <unsigned UnitBitSize, bool Strict> SzType asIntegral() const {
7184
#if LLVM_VERSION_MAJOR >= 10
7285
IGC_ASSERT(!TS.isScalable());
7386
uint64_t BitsAsUI = TS.getFixedSize();
@@ -77,7 +90,13 @@ class TypeSizeWrapper {
7790
IGC_ASSERT_MESSAGE(BitsAsUI <= std::numeric_limits<SzType>::max(),
7891
"Type is too large to operate on");
7992
IGC_ASSERT_MESSAGE(BitsAsUI > 0, "Could not determine size of Type");
80-
return static_cast<SzType>(llvm::divideCeil(BitsAsUI, UnitBitSize));
93+
if constexpr (Strict) {
94+
IGC_ASSERT_MESSAGE(BitsAsUI % UnitBitSize == 0,
95+
"Type size in bits cannot be represented in requested units exactly");
96+
return BitsAsUI / UnitBitSize;
97+
} else {
98+
return static_cast<SzType>(llvm::divideCeil(BitsAsUI, UnitBitSize));
99+
}
81100
}
82101
DLTypeSize TS;
83102
};

IGC/VectorCompiler/lib/GenXCodeGen/GenXCoalescing.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -829,7 +829,7 @@ unsigned GenXCoalescing::getPriority(Type *Ty, BasicBlock *BB) const
829829
constexpr unsigned LoopScale = 4;
830830

831831
// Estimate number of moves required for this type.
832-
unsigned VecWidth = vc::getTypeSize(Ty, DL).inBytes();
832+
unsigned VecWidth = vc::getTypeSize(Ty, DL).inBytesCeil();
833833
unsigned Priority = VecWidth / ST->getGRFByteSize() +
834834
countPopulation(VecWidth % ST->getGRFByteSize());
835835
// Scale by loop depth.

IGC/VectorCompiler/lib/GenXCodeGen/GenXPressureTracker.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ unsigned PressureTracker::getSizeInBytes(LiveRange *LR, bool AllowWidening) {
3838
SimpleValue SV = *LR->value_begin();
3939
Value *V = SV.getValue();
4040
Type *Ty = IndexFlattener::getElementType(V->getType(), SV.getIndex());
41-
unsigned Bytes = vc::getTypeSize(Ty, &DL).inWords() * WordBytes;
41+
unsigned Bytes = vc::getTypeSize(Ty, &DL).inWordsCeil() * WordBytes;
4242
if (!AllowWidening)
4343
return Bytes;
4444

IGC/VectorCompiler/lib/GenXCodeGen/GenXVisaRegAlloc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,7 @@ void GenXVisaRegAlloc::print(raw_ostream &OS, const FunctionGroup *FG) const {
859859
}
860860
Type *ElTy = IndexFlattener::getElementType(SV.getValue()->getType(),
861861
SV.getIndex());
862-
unsigned Bytes = vc::getTypeSize(ElTy).inWords() * WordBytes;
862+
unsigned Bytes = vc::getTypeSize(ElTy).inBytes();
863863
bool IsFlag = ElTy->getScalarType()->isIntegerTy(1);
864864
OS << "] (" << Bytes << " bytes, length " << i->Length <<") ";
865865
// Dump some indication of what the live range is. For a kernel argument,

0 commit comments

Comments
 (0)