1 /*========================== begin_copyright_notice ============================
2 
3 Copyright (C) 2020-2021 Intel Corporation
4 
5 SPDX-License-Identifier: MIT
6 
7 ============================= end_copyright_notice ===========================*/
8 
9 #ifndef IGCLLVM_IR_DERIVEDTYPES_H
10 #define IGCLLVM_IR_DERIVEDTYPES_H
11 
12 #include "llvm/Config/llvm-config.h"
13 #include "llvm/IR/DerivedTypes.h"
14 #include "llvm/IR/Module.h"
15 
16 namespace IGCLLVM
17 {
18 
19  #if LLVM_VERSION_MAJOR <= 10
20      using FixedVectorType = llvm::VectorType;
21      const uint32_t VectorTyID = llvm::Type::VectorTyID;
22  #else
23      using FixedVectorType = llvm::FixedVectorType;
24      const uint32_t VectorTyID = llvm::Type::FixedVectorTyID;
25  #endif
26 
GetVectorTypeBitWidth(llvm::Type * pType)27     inline uint32_t GetVectorTypeBitWidth(llvm::Type* pType)
28     {
29 #if LLVM_VERSION_MAJOR <= 10
30         return llvm::cast<llvm::VectorType>(pType)->getBitWidth();
31 #else
32         return (uint32_t)pType->getPrimitiveSizeInBits().getFixedSize();
33 #endif
34     }
35 
isScalable(const FixedVectorType & Ty)36     inline bool isScalable(const FixedVectorType &Ty)
37     {
38 #if LLVM_VERSION_MAJOR < 9
39         // There were no scalable vectors before LLVM-9
40         return false;
41 #elif LLVM_VERSION_MAJOR < 11
42         return Ty.isScalable();
43 #else
44         // Scalable vectors became a separate type since LLVM-11
45         return false;
46 #endif
47     }
48 
getTypeByName(llvm::Module * M,llvm::StringRef Name)49     inline llvm::StructType *getTypeByName(llvm::Module *M, llvm::StringRef Name) {
50 #if LLVM_VERSION_MAJOR >= 12
51         return llvm::StructType::getTypeByName(M->getContext(), Name);
52 #else
53         return M->getTypeByName(Name);
54 #endif
55     }
56 
57 }
58 
59 #endif
60