Skip to content

Commit a3e0f8e

Browse files
karolzwolakigcbot
authored andcommitted
LLVM API changes minor fixes
Wrap removed ConstantExpr::getUIToFP. LLVM 22 PatternMatch.h now calls matcher.match() on a const matcher object. Mark match() const in FMaxMinCast_match, ClampWithConstants_match, and IsNaN_match. For LLVM < 22 compat, mark by-value sub-matcher members mutable so their non-const match() is still callable on older LLVM versions.
1 parent 362fd38 commit a3e0f8e

4 files changed

Lines changed: 34 additions & 11 deletions

File tree

IGC/Compiler/CISACodeGen/GenIRLowering.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ char GenIRLowering::ID = 0;
7777

7878
template <typename LHS_t, typename RHS_t, typename Pred_t> struct FMaxMinCast_match {
7979
unsigned &CastOpcode;
80-
LHS_t L;
81-
RHS_t R;
80+
mutable LHS_t L;
81+
mutable RHS_t R;
8282

8383
FMaxMinCast_match(unsigned &Opcode, const LHS_t &LHS, const RHS_t &RHS) : CastOpcode(Opcode), L(LHS), R(RHS) {}
8484

@@ -100,7 +100,7 @@ template <typename LHS_t, typename RHS_t, typename Pred_t> struct FMaxMinCast_ma
100100
return false;
101101
}
102102

103-
template <typename OpTy> bool match(OpTy *V) {
103+
template <typename OpTy> bool match(OpTy *V) const {
104104
SelectInst *SI = dyn_cast<SelectInst>(V);
105105
if (!SI)
106106
return false;
@@ -158,12 +158,12 @@ inline FMaxMinCast_match<LHS, RHS, llvm::PatternMatch::ofmin_pred_ty> m_OrdFMinC
158158
template <typename Op_t, typename ConstTy> struct ClampWithConstants_match {
159159
typedef ConstTy *ConstPtrTy;
160160

161-
Op_t Op;
161+
mutable Op_t Op;
162162
ConstPtrTy &CMin, &CMax;
163163

164164
ClampWithConstants_match(const Op_t &OpMatch, ConstPtrTy &Min, ConstPtrTy &Max) : Op(OpMatch), CMin(Min), CMax(Max) {}
165165

166-
template <typename OpTy> bool match(OpTy *V) {
166+
template <typename OpTy> bool match(OpTy *V) const {
167167
CallInst *GII = dyn_cast<CallInst>(V);
168168
if (!GII)
169169
return false;

IGC/Compiler/CISACodeGen/PatternMatchPass.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ SPDX-License-Identifier: MIT
2323
#include <llvmWrapper/IR/Instructions.h>
2424
#include "llvmWrapper/Support/Alignment.h"
2525
#include <llvmWrapper/IR/CmpPredicate.h>
26+
#include "llvmWrapper/IR/Constants.h"
2627
#include "Compiler/IGCPassSupport.h"
2728
#include "Compiler/InitializePasses.h"
2829
#include "Compiler/DebugInfo/ScalarVISAModule.h"
@@ -480,12 +481,12 @@ void CodeGenPatternMatch::SetPatternRoot(llvm::Instruction &inst) {
480481
template <typename Op_t, typename ConstTy> struct ClampWithConstants_match {
481482
typedef ConstTy *ConstPtrTy;
482483

483-
Op_t Op;
484+
mutable Op_t Op;
484485
ConstPtrTy &CMin, &CMax;
485486

486487
ClampWithConstants_match(const Op_t &OpMatch, ConstPtrTy &Min, ConstPtrTy &Max) : Op(OpMatch), CMin(Min), CMax(Max) {}
487488

488-
template <typename OpTy> bool match(OpTy *V) {
489+
template <typename OpTy> bool match(OpTy *V) const {
489490
CallInst *GII = dyn_cast<CallInst>(V);
490491
if (!GII)
491492
return false;
@@ -540,7 +541,7 @@ template <typename Op_t> struct IsNaN_match {
540541

541542
IsNaN_match(const Op_t &OpMatch) : Op(OpMatch) {}
542543

543-
template <typename OpTy> bool match(OpTy *V) {
544+
template <typename OpTy> bool match(OpTy *V) const {
544545
using namespace llvm::PatternMatch;
545546

546547
FCmpInst *FCI = dyn_cast<FCmpInst>(V);
@@ -676,8 +677,8 @@ CodeGenPatternMatch::isFPToUnsignedIntSatWithInexactConstant(llvm::SelectInst *S
676677
if (!CMax || !CMin || !CMax->isMaxValue(false) || !CMin->isMinValue(false))
677678
return std::make_tuple(nullptr, 0, ISA_TYPE_F);
678679

679-
Constant *FMin = ConstantExpr::getUIToFP(CMin, Ty);
680-
Constant *FMax = ConstantExpr::getUIToFP(CMax, Ty);
680+
Constant *FMin = IGCLLVM::ConstantExpr::getUIToFP(CMin, Ty);
681+
Constant *FMax = IGCLLVM::ConstantExpr::getUIToFP(CMax, Ty);
681682

682683
IGCLLVM::FCmpInstPredicate Pred(FCmpInst::FCMP_FALSE);
683684
if (!match(Cond2, m_FCmp(Pred, m_Specific(X), m_Specific(FMax))))

IGC/VectorCompiler/lib/GenXOpts/CMTrans/GenXTypeLegalization.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ SPDX-License-Identifier: MIT
2525
#include "Probe/Assertion.h"
2626

2727
#include "llvmWrapper/IR/IRBuilder.h"
28+
#include "llvmWrapper/IR/Constants.h"
2829

2930
#include <llvm/IR/Dominators.h>
3031
#include <llvm/IR/Function.h>
@@ -130,7 +131,7 @@ Value *GenXTypeLegalization::getLegalizedValue(Value *OldV) {
130131
if (auto *C = dyn_cast<Constant>(OldV)) {
131132
auto *NewCType = getLegalizedType(C->getType());
132133
// TODO: consider signess here.
133-
return ConstantExpr::getZExt(C, NewCType);
134+
return IGCLLVM::ConstantExpr::getZExt(C, NewCType);
134135
}
135136
auto *NewV = ValueMap[OldV];
136137
// Instructions are visited in topological order so a record should exist.

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,27 @@ inline llvm::Constant *getShuffleVector(llvm::Constant *V1, llvm::Constant *V2,
2323
llvm::Type *OnlyIfReducedTy = nullptr) {
2424
return llvm::ConstantExpr::getShuffleVector(V1, V2, static_cast<int>(Mask), OnlyIfReducedTy);
2525
}
26+
inline llvm::Constant *getZExt(llvm::Constant *C, llvm::Type *Ty, bool OnlyIfReduced = false) {
27+
#if LLVM_VERSION_MAJOR < 22
28+
return llvm::ConstantExpr::getZExt(C, Ty, OnlyIfReduced);
29+
#else
30+
return llvm::ConstantExpr::getCast(llvm::Instruction::ZExt, C, Ty, OnlyIfReduced);
31+
#endif
32+
}
33+
inline llvm::Constant *getSExt(llvm::Constant *C, llvm::Type *Ty, bool OnlyIfReduced = false) {
34+
#if LLVM_VERSION_MAJOR < 22
35+
return llvm::ConstantExpr::getSExt(C, Ty, OnlyIfReduced);
36+
#else
37+
return llvm::ConstantExpr::getCast(llvm::Instruction::SExt, C, Ty, OnlyIfReduced);
38+
#endif
39+
}
40+
inline llvm::Constant *getUIToFP(llvm::Constant *C, llvm::Type *Ty, bool OnlyIfReduced = false) {
41+
#if LLVM_VERSION_MAJOR < 22
42+
return llvm::ConstantExpr::getUIToFP(C, Ty, OnlyIfReduced);
43+
#else
44+
return llvm::ConstantExpr::getCast(llvm::Instruction::UIToFP, C, Ty, OnlyIfReduced);
45+
#endif
46+
}
2647
} // namespace ConstantExpr
2748

2849
namespace ConstantFixedVector {

0 commit comments

Comments
 (0)