1 // 2 // Copyright 2016 Francisco Jerez 3 // 4 // Permission is hereby granted, free of charge, to any person obtaining a 5 // copy of this software and associated documentation files (the "Software"), 6 // to deal in the Software without restriction, including without limitation 7 // the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 // and/or sell copies of the Software, and to permit persons to whom the 9 // Software is furnished to do so, subject to the following conditions: 10 // 11 // The above copyright notice and this permission notice shall be included in 12 // all copies or substantial portions of the Software. 13 // 14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 // OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 // OTHER DEALINGS IN THE SOFTWARE. 21 // 22 23 /// 24 /// \file 25 /// Some thin wrappers around the Clang/LLVM API used to preserve 26 /// compatibility with older API versions while keeping the ifdef clutter low 27 /// in the rest of the clover::llvm subtree. In case of an API break please 28 /// consider whether it's possible to preserve backwards compatibility by 29 /// introducing a new one-liner inline function or typedef here under the 30 /// compat namespace in order to keep the running code free from preprocessor 31 /// conditionals. 32 /// 33 34 #ifndef CLOVER_LLVM_COMPAT_HPP 35 #define CLOVER_LLVM_COMPAT_HPP 36 37 #include "util/algorithm.hpp" 38 39 #include <llvm/Config/llvm-config.h> 40 41 #include <llvm/IR/LLVMContext.h> 42 #include <llvm/Linker/Linker.h> 43 #include <llvm/Transforms/IPO.h> 44 #include <llvm/Transforms/Utils/Cloning.h> 45 #include <llvm/Target/TargetMachine.h> 46 47 #include <llvm/IR/LegacyPassManager.h> 48 #include <llvm/Analysis/TargetLibraryInfo.h> 49 50 #include <clang/Basic/TargetInfo.h> 51 #include <clang/Frontend/CompilerInstance.h> 52 53 #if LLVM_VERSION_MAJOR >= 10 54 #include <llvm/Support/CodeGen.h> 55 #endif 56 57 namespace clover { 58 namespace llvm { 59 namespace compat { 60 61 #if LLVM_VERSION_MAJOR >= 10 62 const auto CGFT_ObjectFile = ::llvm::CGFT_ObjectFile; 63 const auto CGFT_AssemblyFile = ::llvm::CGFT_AssemblyFile; 64 typedef ::llvm::CodeGenFileType CodeGenFileType; 65 #else 66 const auto CGFT_ObjectFile = ::llvm::TargetMachine::CGFT_ObjectFile; 67 const auto CGFT_AssemblyFile = 68 ::llvm::TargetMachine::CGFT_AssemblyFile; 69 typedef ::llvm::TargetMachine::CodeGenFileType CodeGenFileType; 70 #endif 71 72 #if LLVM_VERSION_MAJOR >= 10 73 const clang::InputKind ik_opencl = clang::Language::OpenCL; 74 #else 75 const clang::InputKind ik_opencl = clang::InputKind::OpenCL; 76 #endif 77 78 template<typename T> inline bool create_compiler_invocation_from_args(clang::CompilerInvocation & cinv,T copts,clang::DiagnosticsEngine & diag)79 create_compiler_invocation_from_args(clang::CompilerInvocation &cinv, 80 T copts, 81 clang::DiagnosticsEngine &diag) 82 { 83 #if LLVM_VERSION_MAJOR >= 10 84 return clang::CompilerInvocation::CreateFromArgs( 85 cinv, copts, diag); 86 #else 87 return clang::CompilerInvocation::CreateFromArgs( 88 cinv, copts.data(), copts.data() + copts.size(), diag); 89 #endif 90 } 91 } 92 } 93 } 94 95 #endif 96