Skip to content

Commit ce85e34

Browse files
aparshin-inteligcbot
authored andcommitted
minor cosmetic changes to VC ConstantLoader
---------------------------
1 parent 607b5e8 commit ce85e34

File tree

2 files changed

+40
-34
lines changed

2 files changed

+40
-34
lines changed

IGC/VectorCompiler/lib/GenXCodeGen/GenXConstants.cpp

Lines changed: 14 additions & 19 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);
@@ -1335,8 +1336,7 @@ Instruction *ConstantLoader::loadNonPackedIntConst(Instruction *InsertBefore) {
13351336
* ConstantLoader::loadBig : insert instruction to load a constant that might
13361337
* be illegally sized
13371338
*/
1338-
Instruction *ConstantLoader::loadBig(Instruction *InsertBefore)
1339-
{
1339+
Instruction *ConstantLoader::loadBig(Instruction *InsertBefore) {
13401340
if (isLegalSize() || isa<UndefValue>(C)) {
13411341
// Does not need legalizing.
13421342
if (!isSimple())
@@ -1388,12 +1388,11 @@ Instruction *ConstantLoader::loadBig(Instruction *InsertBefore)
13881388
/***********************************************************************
13891389
* ConstantLoader::isLegalSize : detect if a constant is a legal size
13901390
*/
1391-
bool ConstantLoader::isLegalSize()
1392-
{
1391+
bool ConstantLoader::isLegalSize() const {
13931392
auto *VT = dyn_cast<IGCLLVM::FixedVectorType>(C->getType());
13941393
if (!VT)
13951394
return true;
1396-
const int NumBits = DL.getTypeSizeInBits(C->getType());
1395+
const int NumBits = DL.getTypeSizeInBits(VT);
13971396
if (!llvm::isPowerOf2_32(NumBits))
13981397
return false;
13991398
const int GRFSizeInBits = Subtarget.getGRFByteSize() * genx::ByteBits;
@@ -1411,7 +1410,7 @@ bool ConstantLoader::isLegalSize()
14111410
* This does not do a thorough check so it misses some cases of a constant
14121411
* that would split into simple constants.
14131412
*/
1414-
bool ConstantLoader::isBigSimple()
1413+
bool ConstantLoader::isBigSimple() const
14151414
{
14161415
IGC_ASSERT_MESSAGE(!needFixingSimple(),
14171416
"simple case shall be fixed first before this call");
@@ -1432,7 +1431,7 @@ bool ConstantLoader::isBigSimple()
14321431
*
14331432
* A simple constant is one we know can be a constant operand in an instruction.
14341433
*/
1435-
bool ConstantLoader::isSimple()
1434+
bool ConstantLoader::isSimple() const
14361435
{
14371436
IGC_ASSERT_MESSAGE(!needFixingSimple(),
14381437
"simple case shall be fixed first before this call");
@@ -1465,8 +1464,7 @@ bool ConstantLoader::allowI64Ops() const {
14651464
* ConstantLoader::isPackedIntVector : check for a packed int vector
14661465
* (having already done the analysis in the ConstantLoader constructor)
14671466
*/
1468-
bool ConstantLoader::isPackedIntVector()
1469-
{
1467+
bool ConstantLoader::isPackedIntVector() const {
14701468
// Check for a packed int vector. Either the element type must be i16, or
14711469
// the user (instruction using the constant) must be genx.constanti or
14721470
// wrregion or wrconstregion. Not allowed if the user is a logic op.
@@ -1498,7 +1496,7 @@ bool ConstantLoader::isPackedIntVector()
14981496
* ConstantLoader::isPackedFloatVector : check for a packed float vector
14991497
* (having already done the analysis in the ConstantLoader constructor)
15001498
*/
1501-
bool ConstantLoader::isPackedFloatVector() {
1499+
bool ConstantLoader::isPackedFloatVector() const {
15021500
auto *VT = dyn_cast<IGCLLVM::FixedVectorType>(C->getType());
15031501
if (!VT)
15041502
return false;
@@ -1514,8 +1512,7 @@ bool ConstantLoader::isPackedFloatVector() {
15141512
* A "consolidated constant" is one where a vector of byte or short is
15151513
* turned into the equivalent (as if by bitcast) vector of int.
15161514
*/
1517-
Constant *ConstantLoader::getConsolidatedConstant(Constant *C)
1518-
{
1515+
Constant *ConstantLoader::getConsolidatedConstant(Constant *C) {
15191516
if (isa<UndefValue>(C))
15201517
return nullptr;
15211518
auto *VT = dyn_cast<IGCLLVM::FixedVectorType>(C->getType());
@@ -1573,8 +1570,7 @@ Constant *ConstantLoader::getConsolidatedConstant(Constant *C)
15731570
* (integer 8 or fp 4) can be loaded as a packed vector, possibly scaled
15741571
* and adjusted.
15751572
*/
1576-
void ConstantLoader::analyze()
1577-
{
1573+
void ConstantLoader::analyze() {
15781574
auto *VT = dyn_cast<IGCLLVM::FixedVectorType>(C->getType());
15791575
if (!VT)
15801576
return;
@@ -1593,8 +1589,7 @@ void ConstantLoader::analyze()
15931589
analyzeForPackedFloat(NumElements);
15941590
}
15951591

1596-
void ConstantLoader::analyzeForPackedInt(unsigned NumElements)
1597-
{
1592+
void ConstantLoader::analyzeForPackedInt(unsigned NumElements) {
15981593
// Get element values.
15991594
int64_t Min = INT64_MAX;
16001595
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)