From 60136b453bb3a109bfc88c4040b871af9d522ed5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20B=C3=B6sz=C3=B6rm=C3=A9nyi?= 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 Signed-off-by: Naveen Saini --- 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 #include #include +#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 +#include #include #include #include @@ -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(ldmcs->getType())->getElementType()->isFloatTy()) { m_builder->SetInsertPoint(ldmcs); -#if LLVM_VERSION_MAJOR >= 12 uint ldmcsNumOfElements = cast(ldmcs->getType())->getNumElements(); uint new_mcs_callNumOfElements = cast(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 Vals; - for (unsigned i = 0; -#if LLVM_VERSION_MAJOR >= 12 - i < cast(DestTy)->getNumElements(); -#else - i < DestTy->getVectorNumElements(); -#endif - i++) + for (unsigned i = 0; i < cast(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(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 SmallVectornewVector; - unsigned width = int_cast(dyn_cast(SI->getType())->getNumElements()); + unsigned width = int_cast(cast(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