Skip to content

Commit 2d085c5

Browse files
MaciejKalinskiigcbot
authored andcommitted
Use getShuffleMaskForBitcode() from IGCLLVM wrapper
Rationale: this is llvm-agnostic implementation for obtaining shuffle mask as llvm::Constant*.
1 parent 4426658 commit 2d085c5

File tree

3 files changed

+45
-53
lines changed

3 files changed

+45
-53
lines changed

IGC/Compiler/LegalizationPass.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ SPDX-License-Identifier: MIT
2222
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
2323
#include "llvm/Transforms/Utils/Local.h"
2424
#include "llvmWrapper/IR/InstrTypes.h"
25+
#include "llvmWrapper/IR/Instructions.h"
2526
#include "llvmWrapper/Transforms/Utils/Cloning.h"
2627
#include "common/LLVMWarningsPop.hpp"
2728
#include "GenISAIntrinsics/GenIntrinsicInst.h"
@@ -1652,11 +1653,7 @@ void Legalization::visitShuffleVectorInst(ShuffleVectorInst& I)
16521653
Value* src0 = I.getOperand(0);
16531654
Value* src1 = I.getOperand(1);
16541655
// The mask is guaranteed by the LLVM IR spec to be constant
1655-
#if LLVM_VERSION_MAJOR < 11
1656-
Constant* mask = cast<Constant>(I.getOperand(2));
1657-
#else
1658-
Constant* mask = I.getShuffleMaskForBitcode();
1659-
#endif
1656+
Constant* mask = IGCLLVM::getShuffleMaskForBitcode(&I);
16601657
// The two inputs are guaranteed to be of the same type
16611658
IGCLLVM::FixedVectorType* inType = cast<IGCLLVM::FixedVectorType>(src0->getType());
16621659
int inCount = int_cast<int>(inType->getNumElements());

IGC/Compiler/Legalizer/InstLegalChecker.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ SPDX-License-Identifier: MIT
1212
#include "llvm/Config/llvm-config.h"
1313
#include "llvm/Support/Debug.h"
1414
#include "llvm/Support/raw_ostream.h"
15+
#include "llvmWrapper/IR/Instructions.h"
1516
#include "common/LLVMWarningsPop.hpp"
1617
#include "Probe/Assertion.h"
1718

@@ -250,13 +251,7 @@ LegalizeAction InstLegalChecker::visitShuffleVectorInst(ShuffleVectorInst& I) {
250251
if ((Act = TL->getTypeLegalizeAction(I.getOperand(0)->getType())) != Legal)
251252
return Act;
252253
// Check the constant mask.
253-
return TL->getTypeLegalizeAction(I.
254-
#if LLVM_VERSION_MAJOR <= 10
255-
getMask
256-
#else
257-
getShuffleMaskForBitcode
258-
#endif
259-
()->getType());
254+
return TL->getTypeLegalizeAction(IGCLLVM::getShuffleMaskForBitcode(&I)->getType());
260255
}
261256

262257
LegalizeAction InstLegalChecker::visitExtractValueInst(ExtractValueInst& I) {

IGC/WrapperLLVM/include/llvmWrapper/IR/Instructions.h

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -19,78 +19,78 @@ SPDX-License-Identifier: MIT
1919
namespace IGCLLVM
2020
{
2121

22-
inline llvm::Value* getCalledValue(llvm::CallInst& CI)
23-
{
22+
inline llvm::Value* getCalledValue(llvm::CallInst& CI)
23+
{
2424
#if LLVM_VERSION_MAJOR <= 10
25-
return CI.getCalledValue();
25+
return CI.getCalledValue();
2626
#else
27-
return CI.getCalledOperand();
27+
return CI.getCalledOperand();
2828
#endif
29-
}
29+
}
3030

31-
inline llvm::Value* getCalledValue(llvm::CallInst* CI)
32-
{
31+
inline llvm::Value* getCalledValue(llvm::CallInst* CI)
32+
{
3333
#if LLVM_VERSION_MAJOR <= 10
34-
return CI->getCalledValue();
34+
return CI->getCalledValue();
3535
#else
36-
return CI->getCalledOperand();
36+
return CI->getCalledOperand();
3737
#endif
38-
}
38+
}
3939

40-
inline const llvm::Value* getCalledValue(const llvm::CallInst* CI)
41-
{
40+
inline const llvm::Value* getCalledValue(const llvm::CallInst* CI)
41+
{
4242
#if LLVM_VERSION_MAJOR <= 10
43-
return CI->getCalledValue();
43+
return CI->getCalledValue();
4444
#else
45-
return CI->getCalledOperand();
45+
return CI->getCalledOperand();
4646
#endif
47-
}
47+
}
4848

49-
inline unsigned getNumArgOperands(const llvm::CallInst* CI)
50-
{
49+
inline unsigned getNumArgOperands(const llvm::CallInst* CI)
50+
{
5151
#if LLVM_VERSION_MAJOR < 14
52-
return CI->getNumArgOperands();
52+
return CI->getNumArgOperands();
5353
#else
54-
return CI->arg_size();
54+
return CI->arg_size();
5555
#endif
56-
}
56+
}
5757

58-
inline unsigned getArgOperandNo(llvm::CallInst &CI, const llvm::Use *U) {
58+
inline unsigned getArgOperandNo(llvm::CallInst &CI, const llvm::Use *U) {
5959
#if LLVM_VERSION_MAJOR < 10
60-
IGC_ASSERT_MESSAGE(CI.isArgOperand(U), "Arg operand # out of range!");
61-
return (unsigned)(U - CI.arg_begin());
60+
IGC_ASSERT_MESSAGE(CI.isArgOperand(U), "Arg operand # out of range!");
61+
return (unsigned)(U - CI.arg_begin());
6262
#else
63-
return CI.getArgOperandNo(U);
63+
return CI.getArgOperandNo(U);
6464
#endif
65-
}
65+
}
6666

67-
inline llvm::Constant* getShuffleMaskForBitcode(llvm::ShuffleVectorInst* SVI)
68-
{
67+
inline llvm::Constant* getShuffleMaskForBitcode(llvm::ShuffleVectorInst* SVI)
68+
{
6969
#if LLVM_VERSION_MAJOR < 11
70-
return SVI->getMask();
70+
return SVI->getMask();
7171
#else
72-
return SVI->getShuffleMaskForBitcode();
72+
return llvm::ShuffleVectorInst::convertShuffleMaskForBitcode(SVI->getShuffleMask(), SVI->getType());
7373
#endif
74-
}
74+
}
7575

76-
inline bool isFreezeInst(llvm::Instruction* I)
77-
{
76+
inline bool isFreezeInst(llvm::Instruction* I)
77+
{
7878
#if LLVM_VERSION_MAJOR < 10
79-
(void)I;
80-
return false;
79+
(void)I;
80+
return false;
8181
#else
82-
return llvm::isa<llvm::FreezeInst>(I);
82+
return llvm::isa<llvm::FreezeInst>(I);
8383
#endif
84-
}
84+
}
8585

86-
inline bool isDebugOrPseudoInst(llvm::Instruction& I)
87-
{
86+
inline bool isDebugOrPseudoInst(llvm::Instruction& I)
87+
{
8888
#if LLVM_VERSION_MAJOR < 14
89-
return llvm::isa<llvm::DbgInfoIntrinsic>(&I);
89+
return llvm::isa<llvm::DbgInfoIntrinsic>(&I);
9090
#else
91-
return I.isDebugOrPseudoInst();
91+
return I.isDebugOrPseudoInst();
9292
#endif
93-
}
93+
}
9494
}
9595

9696
#endif

0 commit comments

Comments
 (0)