summaryrefslogtreecommitdiffstats
path: root/dynamic-layers/clang-layer/recipes-opencl/igc/files/0002-Review-fixes-for-LLVM-12-phase-1.patch
blob: 6580df751a444f882e9ab915ca79305b0242df5d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
From 60136b453bb3a109bfc88c4040b871af9d522ed5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Zolt=C3=A1n=20B=C3=B6sz=C3=B6rm=C3=A9nyi?= <zboszor@pr.hu>
Date: Thu, 25 Feb 2021 19:40:21 +0100
Subject: [PATCH 2/3] Review fixes for LLVM 12 phase 1
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Upstream-Status: Pending

Signed-off-by: Zoltán Böszörményi <zboszor@gmail.com>
Signed-off-by: Naveen Saini <naveen.kumar.saini@intel.com>
---
 IGC/AdaptorOCL/SPIRV/SPIRVReader.cpp                  |  6 +-----
 IGC/AdaptorOCL/SPIRV/SPIRVUtil.cpp                    |  6 +-----
 IGC/Compiler/CISACodeGen/AdvMemOpt.cpp                |  7 ++-----
 IGC/Compiler/CISACodeGen/Simd32Profitability.cpp      |  7 ++-----
 IGC/Compiler/ConvertMSAAPayloadTo16Bit.cpp            | 11 +----------
 IGC/Compiler/GenTTI.cpp                               |  9 ++-------
 IGC/Compiler/Legalizer/InstPromoter.cpp               |  8 +-------
 .../DeviceEnqueueFuncs/TransformBlocks.cpp            |  6 +-----
 .../OpenCLPasses/WIFuncs/WIFuncResolution.cpp         |  4 ----
 IGC/Compiler/Optimizer/Scalarizer.cpp                 |  2 +-
 IGC/WrapperLLVM/include/llvmWrapper/IR/DerivedTypes.h | 10 ++++++++++
 .../include/llvmWrapper/Support/TypeSize.h            |  4 +---
 .../include/llvmWrapper/Transforms/Utils/LoopUtils.h  |  8 ++++++++
 IGC/common/igc_resourceDimTypes.h                     |  5 ++---
 14 files changed, 33 insertions(+), 60 deletions(-)

diff --git a/IGC/AdaptorOCL/SPIRV/SPIRVReader.cpp b/IGC/AdaptorOCL/SPIRV/SPIRVReader.cpp
index 725a1512..12f42be8 100644
--- a/IGC/AdaptorOCL/SPIRV/SPIRVReader.cpp
+++ b/IGC/AdaptorOCL/SPIRV/SPIRVReader.cpp
@@ -1929,11 +1929,7 @@ SPIRVToLLVM::transType(SPIRVType *T) {
         auto name = isSubgroupAvcINTELTypeOpCode(OC) ?
             OCLSubgroupINTELTypeOpCodeMap::rmap(OC) :
             BuiltinOpaqueGenericTypeOpCodeMap::rmap(OC);
-#if LLVM_VERSION_MAJOR >= 12
-        auto *pST = llvm::StructType::getTypeByName(M->getContext(), name);
-#else
-        auto *pST = M->getTypeByName(name);
-#endif
+        auto *pST = IGCLLVM::getTypeByName(M, name);
         pST = pST ? pST : StructType::create(*Context, name);
 
         return mapType(T, PointerType::get(pST, getOCLOpaqueTypeAddrSpace(OC)));
diff --git a/IGC/AdaptorOCL/SPIRV/SPIRVUtil.cpp b/IGC/AdaptorOCL/SPIRV/SPIRVUtil.cpp
index 91b4623c..f4f0dee5 100644
--- a/IGC/AdaptorOCL/SPIRV/SPIRVUtil.cpp
+++ b/IGC/AdaptorOCL/SPIRV/SPIRVUtil.cpp
@@ -93,11 +93,7 @@ saveLLVMModule(Module *M, const std::string &OutputFile) {
 PointerType*
 getOrCreateOpaquePtrType(Module *M, const std::string &Name,
     unsigned AddrSpace) {
-#if LLVM_VERSION_MAJOR >= 12
-  auto OpaqueType = llvm::StructType::getTypeByName(M->getContext(), Name);
-#else
-  auto OpaqueType = M->getTypeByName(Name);
-#endif
+  auto OpaqueType = IGCLLVM::getTypeByName(M, Name);
   if (!OpaqueType)
     OpaqueType = StructType::create(M->getContext(), Name);
   return PointerType::get(OpaqueType, AddrSpace);
diff --git a/IGC/Compiler/CISACodeGen/AdvMemOpt.cpp b/IGC/Compiler/CISACodeGen/AdvMemOpt.cpp
index fc45a510..a612a473 100644
--- a/IGC/Compiler/CISACodeGen/AdvMemOpt.cpp
+++ b/IGC/Compiler/CISACodeGen/AdvMemOpt.cpp
@@ -33,6 +33,7 @@ IN THE SOFTWARE.
 #include <llvm/Support/Debug.h>
 #include <llvm/Support/raw_ostream.h>
 #include <llvm/Transforms/Utils/Local.h>
+#include "llvmWrapper/Transforms/Utils/LoopUtils.h"
 #include "common/LLVMWarningsPop.hpp"
 #include "GenISAIntrinsics/GenIntrinsics.h"
 #include "Compiler/CISACodeGen/ShaderCodeGen.hpp"
@@ -134,11 +135,7 @@ bool AdvMemOpt::runOnFunction(Function& F) {
     for (auto I = LI->begin(), E = LI->end(); I != E; ++I)
         for (auto DFI = df_begin(*I), DFE = df_end(*I); DFI != DFE; ++DFI) {
             Loop* L = *DFI;
-#if LLVM_VERSION_MAJOR >= 12
-            if (L->isInnermost())
-#else
-            if (L->empty())
-#endif
+            if (IGCLLVM::isInnermost(L))
                 InnermostLoops.push_back(L);
         }
 
diff --git a/IGC/Compiler/CISACodeGen/Simd32Profitability.cpp b/IGC/Compiler/CISACodeGen/Simd32Profitability.cpp
index c1f4a419..5393d4e8 100644
--- a/IGC/Compiler/CISACodeGen/Simd32Profitability.cpp
+++ b/IGC/Compiler/CISACodeGen/Simd32Profitability.cpp
@@ -28,6 +28,7 @@ IN THE SOFTWARE.
 #include "Compiler/CISACodeGen/Platform.hpp"
 #include "common/LLVMWarningsPush.hpp"
 #include <llvmWrapper/IR/DerivedTypes.h>
+#include <llvmWrapper/Transforms/Utils/LoopUtils.h>
 #include <llvm/IR/InstIterator.h>
 #include <llvm/IR/Operator.h>
 #include <llvmWrapper/IR/DerivedTypes.h>
@@ -995,11 +996,7 @@ static bool hasLongStridedLdStInLoop(Function* F, LoopInfo* LI, WIAnalysis* WI)
     // Collect innermost simple loop.
     for (auto I = LI->begin(), E = LI->end(); I != E; ++I) {
         auto L = *I;
-#if LLVM_VERSION_MAJOR >= 12
-        if (!L->isInnermost())
-#else
-        if (!L->empty())
-#endif
+        if (!IGCLLVM::isInnermost(L))
             continue;
         if (L->getNumBlocks() != 2)
             continue;
diff --git a/IGC/Compiler/ConvertMSAAPayloadTo16Bit.cpp b/IGC/Compiler/ConvertMSAAPayloadTo16Bit.cpp
index adf992cb..33473c23 100644
--- a/IGC/Compiler/ConvertMSAAPayloadTo16Bit.cpp
+++ b/IGC/Compiler/ConvertMSAAPayloadTo16Bit.cpp
@@ -153,21 +153,12 @@ void ConvertMSAAPayloadTo16Bit::visitCallInst(CallInst& I)
             // In OGL there are uses of ldmcs other then ldms, using vec4float type.
             // Fix them to use newly created 16bit ldmcs.
             if (ldmcs->getType()->isVectorTy() &&
-#if LLVM_VERSION_MAJOR >= 12
-                ldmcs->getType()->getScalarType()->isFloatTy())
-#else
-                ldmcs->getType()->getVectorElementType()->isFloatTy())
-#endif
+                cast<IGCLLVM::FixedVectorType>(ldmcs->getType())->getElementType()->isFloatTy())
             {
                 m_builder->SetInsertPoint(ldmcs);
 
-#if LLVM_VERSION_MAJOR >= 12
                 uint ldmcsNumOfElements = cast<IGCLLVM::FixedVectorType>(ldmcs->getType())->getNumElements();
                 uint new_mcs_callNumOfElements = cast<IGCLLVM::FixedVectorType>(new_mcs_call->getType())->getNumElements();
-#else
-                uint ldmcsNumOfElements = ldmcs->getType()->getVectorNumElements();
-                uint new_mcs_callNumOfElements = new_mcs_call->getType()->getVectorNumElements();
-#endif
 
                 // vec of 16bit ints to vec of 32bit ints
                 Type* new_mcs_callVecType = IGCLLVM::FixedVectorType::get(m_builder->getInt32Ty(), new_mcs_callNumOfElements);
diff --git a/IGC/Compiler/GenTTI.cpp b/IGC/Compiler/GenTTI.cpp
index 9e4d2f26..53e3ec9e 100644
--- a/IGC/Compiler/GenTTI.cpp
+++ b/IGC/Compiler/GenTTI.cpp
@@ -37,6 +37,7 @@ IN THE SOFTWARE.
 #include "llvm/Analysis/LoopInfo.h"
 #include "llvm/Analysis/ScalarEvolution.h"
 #include "llvm/Support/raw_ostream.h"
+#include "llvmWrapper/Transforms/Utils/LoopUtils.h"
 #include "common/LLVMWarningsPop.hpp"
 
 using namespace llvm;
@@ -216,13 +217,7 @@ namespace llvm {
 
         // Skip non-simple loop.
         if (L->getNumBlocks() != 1) {
-            if (IGC_IS_FLAG_ENABLED(EnableAdvRuntimeUnroll) &&
-#if LLVM_VERSION_MAJOR >= 12
-                L->isInnermost()
-#else
-                L->empty()
-#endif
-               ) {
+            if (IGC_IS_FLAG_ENABLED(EnableAdvRuntimeUnroll) && IGCLLVM::isInnermost(L)) {
                 auto countNonPHI = [](BasicBlock* BB) {
                     unsigned Total = BB->size();
                     unsigned PHIs = 0;
diff --git a/IGC/Compiler/Legalizer/InstPromoter.cpp b/IGC/Compiler/Legalizer/InstPromoter.cpp
index 8fadf89f..63cbccb5 100644
--- a/IGC/Compiler/Legalizer/InstPromoter.cpp
+++ b/IGC/Compiler/Legalizer/InstPromoter.cpp
@@ -398,13 +398,7 @@ bool InstPromoter::visitBitCastInst(BitCastInst& I) {
             IRB->CreateBitCast(Val, IGCLLVM::FixedVectorType::get(DestTy->getScalarType(), N));
 
         std::vector<Constant*> Vals;
-        for (unsigned i = 0;
-#if LLVM_VERSION_MAJOR >= 12
-             i < cast<IGCLLVM::FixedVectorType>(DestTy)->getNumElements();
-#else
-             i < DestTy->getVectorNumElements();
-#endif
-             i++)
+        for (unsigned i = 0; i < cast<IGCLLVM::FixedVectorType>(DestTy)->getNumElements(); i++)
             Vals.push_back(IRB->getInt32(i));
 
         Value* Mask = ConstantVector::get(Vals);
diff --git a/IGC/Compiler/Optimizer/OpenCLPasses/DeviceEnqueueFuncs/TransformBlocks.cpp b/IGC/Compiler/Optimizer/OpenCLPasses/DeviceEnqueueFuncs/TransformBlocks.cpp
index 119520ed..a3681b79 100644
--- a/IGC/Compiler/Optimizer/OpenCLPasses/DeviceEnqueueFuncs/TransformBlocks.cpp
+++ b/IGC/Compiler/Optimizer/OpenCLPasses/DeviceEnqueueFuncs/TransformBlocks.cpp
@@ -952,11 +952,7 @@ namespace //Anonymous
         {
             auto ndrangeStructName = "struct.ndrange_t";
             auto module = _deviceExecCall->getModule();
-#if LLVM_VERSION_MAJOR >= 12
-            auto ndrangeTy = llvm::StructType::getTypeByName(module->getContext(), ndrangeStructName);
-#else
-            auto ndrangeTy = module->getTypeByName(ndrangeStructName);
-#endif
+            auto ndrangeTy = IGCLLVM::getTypeByName(module, ndrangeStructName);
             if (ndrangeTy == nullptr)
             {
                 //create struct type
diff --git a/IGC/Compiler/Optimizer/OpenCLPasses/WIFuncs/WIFuncResolution.cpp b/IGC/Compiler/Optimizer/OpenCLPasses/WIFuncs/WIFuncResolution.cpp
index 535d6268..c23c661d 100644
--- a/IGC/Compiler/Optimizer/OpenCLPasses/WIFuncs/WIFuncResolution.cpp
+++ b/IGC/Compiler/Optimizer/OpenCLPasses/WIFuncs/WIFuncResolution.cpp
@@ -303,11 +303,7 @@ static Value* BuildLoadInst(CallInst& CI, unsigned int Offset, Type* DataType)
     auto Size = ElemByteSize;
     if (DataType->isVectorTy())
     {
-#if LLVM_VERSION_MAJOR >= 12
         Size *= cast<IGCLLVM::FixedVectorType>(DataType)->getNumElements();
-#else
-        Size *= DataType->getVectorNumElements();
-#endif
     }
     unsigned int AlignedOffset = (Offset / ElemByteSize) * ElemByteSize;
     unsigned int LoadByteSize = (Offset == AlignedOffset) ? Size : Size * 2;
diff --git a/IGC/Compiler/Optimizer/Scalarizer.cpp b/IGC/Compiler/Optimizer/Scalarizer.cpp
index a4e73a6d..38627553 100644
--- a/IGC/Compiler/Optimizer/Scalarizer.cpp
+++ b/IGC/Compiler/Optimizer/Scalarizer.cpp
@@ -778,7 +778,7 @@ void ScalarizeFunction::scalarizeInstruction(ShuffleVectorInst* SI)
 
     // Generate array for shuffled scalar values
     SmallVector<Value*, MAX_INPUT_VECTOR_WIDTH>newVector;
-    unsigned width = int_cast<unsigned>(dyn_cast<IGCLLVM::FixedVectorType>(SI->getType())->getNumElements());
+    unsigned width = int_cast<unsigned>(cast<IGCLLVM::FixedVectorType>(SI->getType())->getNumElements());
 
     // Generate undef value, which may be needed as some scalar elements
     UndefValue* undef = UndefValue::get(inputType->getElementType());
diff --git a/IGC/WrapperLLVM/include/llvmWrapper/IR/DerivedTypes.h b/IGC/WrapperLLVM/include/llvmWrapper/IR/DerivedTypes.h
index a3f5a0b8..6a5407bb 100644
--- a/IGC/WrapperLLVM/include/llvmWrapper/IR/DerivedTypes.h
+++ b/IGC/WrapperLLVM/include/llvmWrapper/IR/DerivedTypes.h
@@ -29,6 +29,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 #include "llvm/Config/llvm-config.h"
 #include "llvm/IR/DerivedTypes.h"
+#include "llvm/IR/Module.h"
 
 namespace IGCLLVM
 {
@@ -62,6 +63,15 @@ namespace IGCLLVM
         return false;
 #endif
     }
+
+    inline llvm::StructType *getTypeByName(llvm::Module *M, llvm::StringRef Name) {
+#if LLVM_VERSION_MAJOR >= 12
+        return llvm::StructType::getTypeByName(M->getContext(), Name);
+#else
+        return M->getTypeByName(Name);
+#endif
+    }
+
 }
 
 #endif
diff --git a/IGC/WrapperLLVM/include/llvmWrapper/Support/TypeSize.h b/IGC/WrapperLLVM/include/llvmWrapper/Support/TypeSize.h
index 30e29720..7021820c 100644
--- a/IGC/WrapperLLVM/include/llvmWrapper/Support/TypeSize.h
+++ b/IGC/WrapperLLVM/include/llvmWrapper/Support/TypeSize.h
@@ -39,12 +39,10 @@ inline unsigned getElementCount(unsigned EC) { return EC; }
 inline ElementCount getElementCount(unsigned EC) {
   return ElementCount(EC, false);
 }
-#elif LLVM_VERSION_MAJOR  == 12
+#else
 inline ElementCount getElementCount(unsigned EC) {
   return ElementCount::get(EC, false);
 }
-#else
-#error "unsupported LLVM version"
 #endif
 } // namespace IGCLLVM
 
diff --git a/IGC/WrapperLLVM/include/llvmWrapper/Transforms/Utils/LoopUtils.h b/IGC/WrapperLLVM/include/llvmWrapper/Transforms/Utils/LoopUtils.h
index db47b00b..bce9cfc1 100644
--- a/IGC/WrapperLLVM/include/llvmWrapper/Transforms/Utils/LoopUtils.h
+++ b/IGC/WrapperLLVM/include/llvmWrapper/Transforms/Utils/LoopUtils.h
@@ -41,6 +41,14 @@ namespace IGCLLVM
         return llvm::InsertPreheaderForLoop(L, DT, LI, nullptr, PreserveLCSSA);
     }
 #endif
+
+    inline bool isInnermost(llvm::Loop *L) {
+#if LLVM_VERSION_MAJOR >= 12
+        return L->isInnermost();
+#else
+        return L->empty();
+#endif
+    }
 }
 
 #endif
diff --git a/IGC/common/igc_resourceDimTypes.h b/IGC/common/igc_resourceDimTypes.h
index d790330f..2d675969 100644
--- a/IGC/common/igc_resourceDimTypes.h
+++ b/IGC/common/igc_resourceDimTypes.h
@@ -67,10 +67,9 @@ namespace IGC
             resourceDimTypeId == DIM_3D_TYPE || resourceDimTypeId == DIM_CUBE_TYPE || resourceDimTypeId == DIM_CUBE_ARRAY_TYPE));
 
 #if LLVM_VERSION_MAJOR >= 12
-        llvm::LLVMContext& llvmCtx = module.getContext();
-        return llvm::StructType::getTypeByName(llvmCtx, ResourceDimensionTypeName[resourceDimTypeId]);
+        return llvm::StructType::getTypeByName(module.getContext(), ResourceDimensionTypeName[resourceDimTypeId]);
 #else
         return module.getTypeByName(ResourceDimensionTypeName[resourceDimTypeId]);
 #endif
     }
-}
\ No newline at end of file
+}
-- 
2.17.1