Skip to content

Commit 69f0d9b

Browse files
aparshin-inteligcbot
authored andcommitted
minor cosmetic changes to VC ConstantLoader
---------------------------
1 parent 29b536e commit 69f0d9b

File tree

2 files changed

+42
-40
lines changed

2 files changed

+42
-40
lines changed

IGC/VectorCompiler/lib/GenXCodeGen/GenXConstants.cpp

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ bool genx::loadNonSimpleConstants(
172172
continue;
173173
ConstantLoader CL(C, Subtarget, DL, Inst, AddedInstructions);
174174
if (CL.needFixingSimple()) {
175+
Modified = true;
175176
CL.fixSimple(i);
176177
continue;
177178
}
@@ -773,7 +774,7 @@ bool genx::loadPhiConstants(Function &F, DominatorTree *DT,
773774
Value *Load = nullptr;
774775
Instruction *InsertBefore = InsertBB->getTerminator();
775776
if (!CL.isSimple())
776-
Load = CL.loadNonSimple(InsertBefore);
777+
Load = CL.loadBig(InsertBefore);
777778
else
778779
Load = CL.load(InsertBefore);
779780
Modified = true;
@@ -852,6 +853,7 @@ bool genx::isReplicatedConstantVector(
852853
}
853854

854855
void ConstantLoader::fixSimple(int OperandIdx) {
856+
IGC_ASSERT_MESSAGE(User, "user must be provided");
855857
IGC_ASSERT_MESSAGE(NewC, "no need to fix simple case");
856858
IGC_ASSERT_MESSAGE(User->getOperand(OperandIdx) == C,
857859
"wrong arguments: wrong operand index was provided");
@@ -870,8 +872,7 @@ void ConstantLoader::fixSimple(int OperandIdx) {
870872
*
871873
* Return: new instruction
872874
*/
873-
Instruction *ConstantLoader::loadNonSimple(Instruction *Inst)
874-
{
875+
Instruction *ConstantLoader::loadNonSimple(Instruction *Inst) {
875876
IGC_ASSERT(!isSimple());
876877
if (!isLegalSize())
877878
return loadBig(Inst);
@@ -1153,8 +1154,7 @@ Instruction *ConstantLoader::loadNonSimple(Instruction *Inst)
11531154
* maximizing how many of NeededBits are set
11541155
*/
11551156
unsigned ConstantLoader::getRegionBits(unsigned NeededBits,
1156-
unsigned OptionalBits, unsigned VecWidth)
1157-
{
1157+
unsigned OptionalBits, unsigned VecWidth) {
11581158
if (!NeededBits)
11591159
return 0;
11601160
// Get the first and last element numbers in NeededBits.
@@ -1257,8 +1257,7 @@ Instruction *ConstantLoader::loadSplatConstant(Instruction *InsertPos) {
12571257
*
12581258
* Return: new instruction
12591259
*/
1260-
Instruction *ConstantLoader::load(Instruction *InsertBefore)
1261-
{
1260+
Instruction *ConstantLoader::load(Instruction *InsertBefore) {
12621261
IGC_ASSERT(isSimple());
12631262
// Do not splat load on byte data as HW does not support byte imm source.
12641263
if (!C->getType()->getScalarType()->isIntegerTy(8))
@@ -1335,8 +1334,7 @@ Instruction *ConstantLoader::loadNonPackedIntConst(Instruction *InsertBefore) {
13351334
* ConstantLoader::loadBig : insert instruction to load a constant that might
13361335
* be illegally sized
13371336
*/
1338-
Instruction *ConstantLoader::loadBig(Instruction *InsertBefore)
1339-
{
1337+
Instruction *ConstantLoader::loadBig(Instruction *InsertBefore) {
13401338
if (isLegalSize() || isa<UndefValue>(C)) {
13411339
// Does not need legalizing.
13421340
if (!isSimple())
@@ -1388,12 +1386,11 @@ Instruction *ConstantLoader::loadBig(Instruction *InsertBefore)
13881386
/***********************************************************************
13891387
* ConstantLoader::isLegalSize : detect if a constant is a legal size
13901388
*/
1391-
bool ConstantLoader::isLegalSize()
1392-
{
1389+
bool ConstantLoader::isLegalSize() const {
13931390
auto *VT = dyn_cast<IGCLLVM::FixedVectorType>(C->getType());
13941391
if (!VT)
13951392
return true;
1396-
const int NumBits = DL.getTypeSizeInBits(C->getType());
1393+
const int NumBits = DL.getTypeSizeInBits(VT);
13971394
if (!llvm::isPowerOf2_32(NumBits))
13981395
return false;
13991396
const int GRFSizeInBits = Subtarget.getGRFByteSize() * genx::ByteBits;
@@ -1411,8 +1408,7 @@ bool ConstantLoader::isLegalSize()
14111408
* This does not do a thorough check so it misses some cases of a constant
14121409
* that would split into simple constants.
14131410
*/
1414-
bool ConstantLoader::isBigSimple()
1415-
{
1411+
bool ConstantLoader::isBigSimple() const {
14161412
IGC_ASSERT_MESSAGE(!needFixingSimple(),
14171413
"simple case shall be fixed first before this call");
14181414
if (isa<UndefValue>(C))
@@ -1432,8 +1428,7 @@ bool ConstantLoader::isBigSimple()
14321428
*
14331429
* A simple constant is one we know can be a constant operand in an instruction.
14341430
*/
1435-
bool ConstantLoader::isSimple()
1436-
{
1431+
bool ConstantLoader::isSimple() const {
14371432
IGC_ASSERT_MESSAGE(!needFixingSimple(),
14381433
"simple case shall be fixed first before this call");
14391434
if (isa<UndefValue>(C))
@@ -1465,8 +1460,7 @@ bool ConstantLoader::allowI64Ops() const {
14651460
* ConstantLoader::isPackedIntVector : check for a packed int vector
14661461
* (having already done the analysis in the ConstantLoader constructor)
14671462
*/
1468-
bool ConstantLoader::isPackedIntVector()
1469-
{
1463+
bool ConstantLoader::isPackedIntVector() const {
14701464
// Check for a packed int vector. Either the element type must be i16, or
14711465
// the user (instruction using the constant) must be genx.constanti or
14721466
// wrregion or wrconstregion. Not allowed if the user is a logic op.
@@ -1498,7 +1492,7 @@ bool ConstantLoader::isPackedIntVector()
14981492
* ConstantLoader::isPackedFloatVector : check for a packed float vector
14991493
* (having already done the analysis in the ConstantLoader constructor)
15001494
*/
1501-
bool ConstantLoader::isPackedFloatVector() {
1495+
bool ConstantLoader::isPackedFloatVector() const {
15021496
auto *VT = dyn_cast<IGCLLVM::FixedVectorType>(C->getType());
15031497
if (!VT)
15041498
return false;
@@ -1514,8 +1508,7 @@ bool ConstantLoader::isPackedFloatVector() {
15141508
* A "consolidated constant" is one where a vector of byte or short is
15151509
* turned into the equivalent (as if by bitcast) vector of int.
15161510
*/
1517-
Constant *ConstantLoader::getConsolidatedConstant(Constant *C)
1518-
{
1511+
Constant *ConstantLoader::getConsolidatedConstant(Constant *C) {
15191512
if (isa<UndefValue>(C))
15201513
return nullptr;
15211514
auto *VT = dyn_cast<IGCLLVM::FixedVectorType>(C->getType());
@@ -1573,8 +1566,7 @@ Constant *ConstantLoader::getConsolidatedConstant(Constant *C)
15731566
* (integer 8 or fp 4) can be loaded as a packed vector, possibly scaled
15741567
* and adjusted.
15751568
*/
1576-
void ConstantLoader::analyze()
1577-
{
1569+
void ConstantLoader::analyze() {
15781570
auto *VT = dyn_cast<IGCLLVM::FixedVectorType>(C->getType());
15791571
if (!VT)
15801572
return;
@@ -1593,8 +1585,7 @@ void ConstantLoader::analyze()
15931585
analyzeForPackedFloat(NumElements);
15941586
}
15951587

1596-
void ConstantLoader::analyzeForPackedInt(unsigned NumElements)
1597-
{
1588+
void ConstantLoader::analyzeForPackedInt(unsigned NumElements) {
15981589
// Get element values.
15991590
int64_t Min = INT64_MAX;
16001591
int64_t Max = INT64_MIN;

IGC/VectorCompiler/lib/GenXCodeGen/GenXConstants.h

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ SPDX-License-Identifier: MIT
66
77
============================= end_copyright_notice ===========================*/
88

9-
#ifndef GENX_CONSTANTS_H
10-
#define GENX_CONSTANTS_H
9+
#ifndef LIB_GENXCODEGEN_GENXCONSTANTS_H
10+
#define LIB_GENXCODEGEN_GENXCONSTANTS_H
1111

1212
#include "GenXSubtarget.h"
1313
#include "llvm/ADT/SmallVector.h"
@@ -20,6 +20,10 @@ namespace genx {
2020

2121
// ConstantLoader : class to insert instruction(s) to load a constant
2222
class ConstantLoader {
23+
friend bool loadNonSimpleConstants(
24+
Instruction *Inst, const GenXSubtarget &Subtarget, const DataLayout &DL,
25+
SmallVectorImpl<Instruction *> *AddedInstructions);
26+
2327
Constant *C;
2428
Instruction *User;
2529

@@ -58,27 +62,34 @@ class ConstantLoader {
5862
AddedInstructions(AddedInstructions) {
5963
analyze();
6064
}
65+
6166
Instruction *load(Instruction *InsertBefore);
6267
Instruction *loadBig(Instruction *InsertBefore);
63-
Instruction *loadNonSimple(Instruction *InsertBefore);
64-
Instruction *loadNonPackedIntConst(Instruction *InsertBefore);
65-
bool needFixingSimple() const { return NewC; }
66-
void fixSimple(int OperandIdx);
67-
bool isBigSimple();
68-
bool isSimple();
69-
bool isLegalSize();
68+
69+
bool isBigSimple() const;
70+
bool isSimple() const;
71+
bool isLegalSize() const;
7072

7173
private:
7274
bool allowI64Ops() const;
73-
bool isPackedIntVector();
74-
bool isPackedFloatVector();
75+
7576
void analyze();
77+
void analyzeForPackedInt(unsigned NumElements);
78+
void analyzeForPackedFloat(unsigned NumElements);
79+
80+
bool isPackedIntVector() const;
81+
bool isPackedFloatVector() const;
82+
7683
Constant *getConsolidatedConstant(Constant *C);
7784
unsigned getRegionBits(unsigned NeededBits, unsigned OptionalBits,
7885
unsigned VecWidth);
79-
void analyzeForPackedInt(unsigned NumElements);
80-
void analyzeForPackedFloat(unsigned NumElements);
81-
Instruction *loadSplatConstant(Instruction *InsertPos);
86+
87+
bool needFixingSimple() const { return NewC; }
88+
void fixSimple(int OperandIdx);
89+
90+
Instruction *loadNonSimple(Instruction *InsertBefore);
91+
Instruction *loadSplatConstant(Instruction *InsertPt);
92+
Instruction *loadNonPackedIntConst(Instruction *InsertPt);
8293
};
8394

8495
// Some instructions force their operands to be constants.
@@ -134,4 +145,4 @@ bool isReplicatedConstantVector(const ConstantVector *Orig,
134145
} // namespace genx
135146
} // namespace llvm
136147

137-
#endif // GENX_CONSTANTS_H
148+
#endif // LIB_GENXCODEGEN_GENXCONSTANTS_H

0 commit comments

Comments
 (0)