Skip to content

Commit 3b21974

Browse files
mmereckiigcbot
authored andcommitted
Code refactor in SynchronizationObjectCoalescing
_OS_DESCRIPTION
1 parent 01a212f commit 3b21974

File tree

3 files changed

+52
-23
lines changed

3 files changed

+52
-23
lines changed

IGC/Compiler/CISACodeGen/helper.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1633,6 +1633,15 @@ namespace IGC
16331633
return ival;
16341634
}
16351635

1636+
bool getImmValueBool(const llvm::Value* value)
1637+
{
1638+
const llvm::ConstantInt* cval = llvm::cast<llvm::ConstantInt>(value);
1639+
IGC_ASSERT(nullptr != cval);
1640+
IGC_ASSERT(cval->getBitWidth() == 1);
1641+
1642+
return cval->getValue().getBoolValue();
1643+
}
1644+
16361645
llvm::Value* ExtractElementFromInsertChain(llvm::Value* inst, int pos)
16371646
{
16381647

IGC/Compiler/CISACodeGen/helper.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,13 @@ namespace IGC
108108
BufferType GetBufferType(uint addrSpace);
109109

110110
uint getImmValueU32(const llvm::Value* value);
111+
bool getImmValueBool(const llvm::Value* value);
112+
113+
template <typename EnumT>
114+
static inline EnumT getImmValueEnum(const llvm::Value* val)
115+
{
116+
return static_cast<EnumT>(getImmValueU32(val));
117+
}
111118

112119
void VectorToElement(
113120
llvm::Value* inst,

IGC/Compiler/Optimizer/SynchronizationObjectCoalescing.cpp

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,15 @@ SPDX-License-Identifier: MIT
1313
#include "GenISAIntrinsics/GenIntrinsicInst.h"
1414
#include "IGC/Compiler/CodeGenPublic.h"
1515
#include "Probe/Assertion.h"
16+
#include "Compiler/CISACodeGen/helper.h"
1617
#include "Compiler/IGCPassSupport.h"
1718
#include "SynchronizationObjectCoalescing.hpp"
19+
#include "visa_igc_common_header.h"
1820
#include <memory>
1921
#include <utility>
2022
#include <map>
2123

24+
using namespace llvm;
2225
namespace IGC
2326
{
2427

@@ -48,6 +51,30 @@ struct ExplanationEntry
4851
};
4952
#endif // _DEBUG
5053

54+
////////////////////////////////////////////////////////////////////////////////
55+
enum InstructionMask : uint32_t
56+
{
57+
None = 0x0,
58+
AtomicOperation = 0x1,
59+
TypedReadOperation = 0x2,
60+
TypedWriteOperation = 0x4,
61+
OutputUrbReadOperation = 0x8,
62+
UrbWriteOperation = 0x10,
63+
BufferReadOperation = 0x20,
64+
BufferWriteOperation = 0x40,
65+
SharedMemoryReadOperation = 0x80,
66+
SharedMemoryWriteOperation = 0x100
67+
};
68+
inline constexpr InstructionMask operator|(InstructionMask a, InstructionMask b)
69+
{
70+
return InstructionMask(uint32_t(a) | uint32_t(b));
71+
}
72+
inline constexpr InstructionMask& operator|=(InstructionMask& a, InstructionMask b)
73+
{
74+
a = a | b;
75+
return a;
76+
}
77+
5178
////////////////////////////////////////////////////////////////////////
5279
/// @brief Synchronization objects prevents from hazardous situations in kernels.
5380
/// They cannot be removed if one of hazards is possible:
@@ -187,22 +214,6 @@ class SynchronizationObjectCoalescingAnalysis : public llvm::FunctionPass
187214
void dump(bool onlyMemoryInstructionMask = true) const;
188215
#endif // _DEBUG
189216
private:
190-
191-
////////////////////////////////////////////////////////////////////////
192-
enum InstructionMask : uint32_t
193-
{
194-
None = 0x0,
195-
AtomicOperation = 0x1,
196-
TypedReadOperation = 0x2,
197-
TypedWriteOperation = 0x4,
198-
OutputUrbReadOperation = 0x8,
199-
UrbWriteOperation = 0x10,
200-
BufferReadOperation = 0x20,
201-
BufferWriteOperation = 0x40,
202-
SharedMemoryReadOperation = 0x80,
203-
SharedMemoryWriteOperation = 0x100
204-
};
205-
206217
static constexpr InstructionMask sc_MemoryWriteInstructionMask = static_cast<InstructionMask>(
207218
AtomicOperation |
208219
TypedWriteOperation |
@@ -372,6 +383,7 @@ class SynchronizationObjectCoalescingAnalysis : public llvm::FunctionPass
372383
////////////////////////////////////////////////////////////////////////
373384
bool IsUntypedMemoryFenceOperationForGlobalAccess(const llvm::Instruction* pInst) const;
374385

386+
375387
////////////////////////////////////////////////////////////////////////
376388
static bool IsFenceOperation(const llvm::Instruction* pInst);
377389

@@ -402,6 +414,7 @@ class SynchronizationObjectCoalescingAnalysis : public llvm::FunctionPass
402414
#endif // _DEBUG
403415
};
404416

417+
405418
char SynchronizationObjectCoalescingAnalysis::ID = 0;
406419

407420
////////////////////////////////////////////////////////////////////////////
@@ -593,7 +606,7 @@ void SynchronizationObjectCoalescingAnalysis::FindRedundancies()
593606
////////////////////////////////////////////////////////////////////////
594607
/// @brief Provides write memory instructions mask which are synchronized
595608
/// by the instruction.
596-
IGC::SynchronizationObjectCoalescingAnalysis::InstructionMask SynchronizationObjectCoalescingAnalysis::GetDefaultWriteMemoryInstructionMask(const llvm::Instruction* pSourceInst) const
609+
InstructionMask SynchronizationObjectCoalescingAnalysis::GetDefaultWriteMemoryInstructionMask(const llvm::Instruction* pSourceInst) const
597610
{
598611
InstructionMask result = InstructionMask::None;
599612
if (IsUntypedMemoryFenceOperation(pSourceInst))
@@ -647,7 +660,7 @@ IGC::SynchronizationObjectCoalescingAnalysis::InstructionMask SynchronizationObj
647660
////////////////////////////////////////////////////////////////////////
648661
/// @brief Provides default memory instruction mask which is used for
649662
/// graph searching.
650-
IGC::SynchronizationObjectCoalescingAnalysis::InstructionMask SynchronizationObjectCoalescingAnalysis::GetDefaultMemoryInstructionMask(
663+
InstructionMask SynchronizationObjectCoalescingAnalysis::GetDefaultMemoryInstructionMask(
651664
const llvm::Instruction* pSourceInst) const
652665
{
653666
// All the rules stems from assumptions in the main comment of this analysis (the paragraph about a strict redundancy).
@@ -982,7 +995,7 @@ void SynchronizationObjectCoalescingAnalysis::GetAllUnsynchronizedMemoryInstruct
982995
/// a substitute is not crossed by another substitute.
983996
/// @param pSourceInst the source synchronization instruction
984997
/// @param forwardDirection the direction of searching
985-
SynchronizationObjectCoalescingAnalysis::InstructionMask SynchronizationObjectCoalescingAnalysis::GetInstructionMask(
998+
InstructionMask SynchronizationObjectCoalescingAnalysis::GetInstructionMask(
986999
const llvm::Instruction* pSourceInst,
9871000
bool forwardDirection) const
9881001
{
@@ -1126,7 +1139,7 @@ SynchronizationObjectCoalescingAnalysis::SynchronizationCaseMask Synchronization
11261139
/// memory instructions (in the next synchronization block delineated by
11271140
/// thread group barriers)
11281141
/// @param pSourceInst the source synchronization instruction
1129-
IGC::SynchronizationObjectCoalescingAnalysis::InstructionMask SynchronizationObjectCoalescingAnalysis::GetUnsynchronizedForwardInstructionMask(
1142+
InstructionMask SynchronizationObjectCoalescingAnalysis::GetUnsynchronizedForwardInstructionMask(
11301143
const llvm::Instruction* pSourceInst) const
11311144
{
11321145
std::vector<const llvm::Instruction*> boundaryInstructions;
@@ -1143,7 +1156,7 @@ IGC::SynchronizationObjectCoalescingAnalysis::InstructionMask SynchronizationObj
11431156
/// a substitute is not crossed by another substitute.
11441157
/// @param pSourceInst the source synchronization instruction
11451158
/// @param forwardDirection the direction of searching
1146-
SynchronizationObjectCoalescingAnalysis::InstructionMask SynchronizationObjectCoalescingAnalysis::GetInstructionMask(
1159+
InstructionMask SynchronizationObjectCoalescingAnalysis::GetInstructionMask(
11471160
const std::vector<const llvm::Instruction*>& input) const
11481161
{
11491162
InstructionMask result = InstructionMask::None;
@@ -1554,6 +1567,7 @@ bool SynchronizationObjectCoalescingAnalysis::IsThreadBarrierOperation(const llv
15541567

15551568
return false;
15561569
}
1570+
15571571
////////////////////////////////////////////////////////////////////////
15581572
bool SynchronizationObjectCoalescingAnalysis::IsUntypedMemoryFenceOperation(const llvm::Instruction* pInst)
15591573
{
@@ -1569,7 +1583,6 @@ bool SynchronizationObjectCoalescingAnalysis::IsUntypedMemoryFenceOperation(cons
15691583
break;
15701584
}
15711585
}
1572-
15731586
return false;
15741587
}
15751588

@@ -1600,7 +1613,7 @@ bool SynchronizationObjectCoalescingAnalysis::IsUntypedMemoryFenceOperationForGl
16001613
}
16011614

16021615
////////////////////////////////////////////////////////////////////////
1603-
SynchronizationObjectCoalescingAnalysis::InstructionMask SynchronizationObjectCoalescingAnalysis::GetInstructionMask(const llvm::Instruction* pInst) const
1616+
InstructionMask SynchronizationObjectCoalescingAnalysis::GetInstructionMask(const llvm::Instruction* pInst) const
16041617
{
16051618
if (IsAtomicOperation(pInst))
16061619
{

0 commit comments

Comments
 (0)