diff --git a/rocclr/compiler/lib/backends/common/codegen.cpp b/rocclr/compiler/lib/backends/common/codegen.cpp index 92908ab058..2ab55dc629 100644 --- a/rocclr/compiler/lib/backends/common/codegen.cpp +++ b/rocclr/compiler/lib/backends/common/codegen.cpp @@ -2,6 +2,7 @@ // Copyright (c) 2008 Advanced Micro Devices, Inc. All rights reserved. // #include "top.hpp" + #include "codegen.hpp" #include "utils/libUtils.h" #include "os/os.hpp" @@ -163,11 +164,14 @@ llvm::sys::MemoryBlock OCLMCJITMemoryManager::allocateSection(uintptr_t Size) { #if !defined(LEGACY_COMPLIB) void OCLMCJITMemoryManager::reserveAllocationSpace(uintptr_t CodeSize, - uintptr_t DataSizeRO, - uintptr_t DataSizeRW) { + uint32_t CodeAlign, + uintptr_t RODataSize, + uint32_t RODataAlign, + uintptr_t RWDataSize, + uint32_t RWDataAlign) { uint64_t GOTTableReserveSize = 4096; - uint64_t Size = (uint64_t)CodeSize + (uint64_t)DataSizeRO + - (uint64_t)DataSizeRW + GOTTableReserveSize; + uint64_t Size = (uint64_t)CodeSize + (uint64_t)RODataSize + + (uint64_t)RWDataSize + GOTTableReserveSize; if ((uint64_t)allocPtr + (uint64_t)Size > (uint64_t)allocMaxPtr) reserveMemory(Size); } @@ -396,11 +400,6 @@ llvmCodeGen( return 1; } -#if 1 || LLVM_TRUNK_INTEGRATION_CL >= 1463 -#else - // a dirty way to guarantee "push bp" inserted by CodeGen in prologue - llvm::NoFramePointerElim = !optimize; -#endif // Load the module to be compiled... Module &mod = *Composite; @@ -456,8 +455,13 @@ llvmCodeGen( } #endif +#if defined(LEGACY_COMPLIB) for (TargetRegistry::iterator it = TargetRegistry::begin(), ie = TargetRegistry::end(); it != ie; ++it) { +#else + for (TargetRegistry::iterator it = TargetRegistry::targets().begin(), + ie = TargetRegistry::targets().end(); it != ie; ++it) { +#endif if (MArch == it->getName()) { TheTarget = &*it; break; @@ -499,7 +503,6 @@ llvmCodeGen( std::string FeatureStr = getFeatureString(binary->target, OptionsObj); llvm::TargetOptions targetOptions; - targetOptions.NoFramePointerElim = false; targetOptions.StackAlignmentOverride = OptionsObj->oVariables->CPUStackAlignment; // jgolds @@ -545,61 +548,69 @@ llvmCodeGen( TargetMachine &Target = *target; // Figure out where we are going to send the output... +#if defined(LEGACY_COMPLIB) raw_string_ostream *RSOut = new raw_string_ostream(output); formatted_raw_ostream *Out = new formatted_raw_ostream(*RSOut, formatted_raw_ostream::DELETE_STREAM); - if (Out == 0) { +#else + auto RSOut = llvm::make_unique(output); + if (!RSOut) { + LogError("llvmCodeGen couldn't create an output stream"); + return 1; + } + auto Out = llvm::make_unique(*RSOut); +#endif + if (!Out) { LogError("llvmCodeGen couldn't create an output stream"); return 1; } // Build up all of the passes that we want to do to the module or function or // Basic Block. - PassManager Passes; - - // Add the target data from the target machine, if it exists. - if (const DataLayout *TD = Target.getSubtargetImpl()->getDataLayout()) - mod.setDataLayout(TD); - Passes.add(new DataLayoutPass()); + legacy::PassManager Passes; + // Add the target data from the target machine, if it exists, or the module. + mod.setDataLayout(Target.createDataLayout()); // Override default to generate verbose assembly, if the device is not the GPU. // The GPU sets this in AMDILTargetMachine.cpp. if (familyMap.target == (const TargetMapping*)&X86TargetMapping || familyMap.target == (const TargetMapping*)&X64TargetMapping ) { +#if defined(LEGACY_COMPLIB) Target.setAsmVerbosityDefault(true); +#else + Target.Options.MCOptions.AsmVerbose = true; +#endif } #ifdef WITH_TARGET_HSAIL if (isHSAILTarget(binary->target)) { if (Target.addPassesToEmitFile(Passes, *Out, TargetMachine::CGFT_ObjectFile, true)) { +#if defined(LEGACY_COMPLIB) delete Out; +#endif return 1; } } else #endif { #ifndef NDEBUG -#if 1 || LLVM_TRUNK_INTEGRATION_CL >= 1144 if (Target.addPassesToEmitFile(Passes, *Out, TargetMachine::CGFT_AssemblyFile, false)) #else - if (Target.addPassesToEmitFile(Passes, *Out, TargetMachine::CGFT_AssemblyFile, OLvl, false)) -#endif -#else -#if 1 || LLVM_TRUNK_INTEGRATION_CL >= 1144 if (Target.addPassesToEmitFile(Passes, *Out, TargetMachine::CGFT_AssemblyFile, true)) -#else - if (Target.addPassesToEmitFile(Passes, *Out, TargetMachine::CGFT_AssemblyFile, OLvl, true)) -#endif #endif { +#if defined(LEGACY_COMPLIB) delete Out; +#endif return 1; } } Passes.run(mod); llvm::PrintStatistics(); +#if defined(LEGACY_COMPLIB) delete Out; +#endif return 0; } diff --git a/rocclr/compiler/lib/backends/common/codegen.hpp b/rocclr/compiler/lib/backends/common/codegen.hpp index 9528d4f67d..c36899cd5b 100644 --- a/rocclr/compiler/lib/backends/common/codegen.hpp +++ b/rocclr/compiler/lib/backends/common/codegen.hpp @@ -143,8 +143,11 @@ public: #else virtual bool needsToReserveAllocationSpace() override { return true; } - virtual void reserveAllocationSpace(uintptr_t CodeSize, uintptr_t DataSizeRO, - uintptr_t DataSizeRW) override; + virtual void reserveAllocationSpace(uintptr_t CodeSize, uint32_t CodeAlign, + uintptr_t RODataSize, + uint32_t RODataAlign, + uintptr_t RWDataSize, + uint32_t RWDataAlign) override; uint8_t *allocateCodeSection(uintptr_t Size, unsigned Alignment, unsigned SectionID, llvm::StringRef SectionName) override; diff --git a/rocclr/compiler/lib/backends/common/compiler_stage.cpp b/rocclr/compiler/lib/backends/common/compiler_stage.cpp index 2585a96b40..e9f2450c0b 100644 --- a/rocclr/compiler/lib/backends/common/compiler_stage.cpp +++ b/rocclr/compiler/lib/backends/common/compiler_stage.cpp @@ -111,8 +111,8 @@ LLVMCompilerStage::loadBitcode(std::string& llvmBinary) if (std::unique_ptr Buffer = llvm::MemoryBuffer::getMemBufferCopy( llvm::StringRef(llvmBinary), "input.bc")) { - llvm::ErrorOr M = llvm::parseBitcodeFile(Buffer->getMemBufferRef(), Context()); - if( M ) return M.get(); + auto ModuleOrErr = llvm::parseBitcodeFile(Buffer->getMemBufferRef(), Context()); + if( !ModuleOrErr.getError() ) return ModuleOrErr.get().release(); } #endif return NULL; diff --git a/rocclr/compiler/lib/backends/common/compiler_stage.hpp b/rocclr/compiler/lib/backends/common/compiler_stage.hpp index 1b69a9c7a3..019342ddcc 100644 --- a/rocclr/compiler/lib/backends/common/compiler_stage.hpp +++ b/rocclr/compiler/lib/backends/common/compiler_stage.hpp @@ -3,15 +3,25 @@ // #ifndef _BE_COMPILER_STAGE_HPP_ #define _BE_COMPILER_STAGE_HPP_ -#include "aclTypes.h" -#include "utils/options.hpp" + +#if defined DEBUG +#undef DEBUG +#endif + #include "llvm/AMDLLVMContextHook.h" +#if defined(LEGACY_COMPLIB) #include "llvm/PassManager.h" +#else +#include "llvm/IR/LegacyPassManager.h" +#endif #include "llvm/Pass.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/SourceMgr.h" #include "llvm/Bitcode/ReaderWriter.h" +#include "aclTypes.h" +#include "utils/options.hpp" + #include #include diff --git a/rocclr/compiler/lib/backends/common/frontend_clang.cpp b/rocclr/compiler/lib/backends/common/frontend_clang.cpp index 9a94e23b96..933e540ad4 100644 --- a/rocclr/compiler/lib/backends/common/frontend_clang.cpp +++ b/rocclr/compiler/lib/backends/common/frontend_clang.cpp @@ -52,7 +52,12 @@ int amdcl::ClangOCLFrontend::compileCommand(const std::string& src) { if (amdOpts) { for (std::vector::const_iterator it = amdOpts->clangOptions.begin(); it != amdOpts->clangOptions.end(); ++it) { - argsToClang.push_back((*it).c_str()); + if ("-g" == *it) { + argsToClang.push_back("-dwarf-version=2"); + argsToClang.push_back("-debug-info-kind=standalone"); + } else { + argsToClang.push_back((*it).c_str()); + } } } diff --git a/rocclr/compiler/lib/backends/common/linker.cpp b/rocclr/compiler/lib/backends/common/linker.cpp index f914d945d1..f3010a0bfc 100644 --- a/rocclr/compiler/lib/backends/common/linker.cpp +++ b/rocclr/compiler/lib/backends/common/linker.cpp @@ -33,6 +33,7 @@ #include "llvm/Assembly/Writer.h" #endif #else +#include "llvm/Support/Debug.h" #include "llvm/IR/DataLayout.h" #include "llvm/IR/CallSite.h" #include "llvm/IR/Instructions.h" @@ -95,12 +96,6 @@ #include "llvm/Support/SPIRV.h" #endif -// need to undef DEBUG before using DEBUG macro in llvm/Support/Debug.h -#ifdef DEBUG -#undef DEBUG -#endif -#include "llvm/Support/Debug.h" - #include #include #include @@ -117,9 +112,6 @@ #include #endif // _WIN32 -#ifdef DEBUG_TYPE -#undef DEBUG_TYPE -#endif #define DEBUG_TYPE "ocl_linker" namespace AMDSpir { @@ -158,8 +150,8 @@ inline llvm::Module* #else ErrorOr> FileOrErr = MemoryBuffer::getFileOrSTDIN(Filename); if (!FileOrErr) { - llvm::ErrorOr M = llvm::parseBitcodeFile(FileOrErr.get()->getMemBufferRef(), Context); - if (M) return M.get(); + auto ModuleOrErr = llvm::parseBitcodeFile(FileOrErr.get()->getMemBufferRef(), Context); + if (!ModuleOrErr.getError()) return ModuleOrErr.get().release(); } return nullptr; @@ -232,15 +224,13 @@ llvm::Module* LoadLibrary(const char* libBC, size_t libBCSize, LLVMContext& Context) { - llvm::ErrorOr M(nullptr); - std::string ErrorMessage; auto Buffer = MemoryBuffer::getMemBuffer(StringRef(libBC, libBCSize), ""); if ( Buffer ) { - M = llvm::getLazyBitcodeModule(std::move(Buffer), Context); - if (!M) return nullptr; + auto ModuleOrErr = llvm::getLazyBitcodeModule(std::move(Buffer), Context); + if (!ModuleOrErr.getError()) return ModuleOrErr.get().release(); } - return *M; + return nullptr; } #endif @@ -259,7 +249,7 @@ static std::set *getAmdRtFunctions() bool -amdcl::OCLLinker::linkWithModule(llvm::Module* Dst, llvm::Module* Src) +amdcl::OCLLinker::linkWithModule(llvm::Module* Dst, std::unique_ptr Src) { #ifndef NDEBUG if (Options()->oVariables->EnableDebugLinker) { @@ -268,7 +258,7 @@ amdcl::OCLLinker::linkWithModule(llvm::Module* Dst, llvm::Module* Src) } #endif std::string ErrorMessage; - if (llvm::linkWithModule(Dst, Src, &ErrorMessage)) { + if (llvm::linkWithModule(Dst, std::move(Src), &ErrorMessage)) { DEBUG(llvm::dbgs() << "Error: " << ErrorMessage << "\n"); BuildLog() += "\nInternal Error: linking libraries failed!\n"; LogError("linkWithModule(): linking bc libraries failed!"); @@ -277,14 +267,8 @@ amdcl::OCLLinker::linkWithModule(llvm::Module* Dst, llvm::Module* Src) return false; } - - -static void delete_llvm_module(llvm::Module *a) -{ - delete a; -} - bool -amdcl::OCLLinker::linkLLVMModules(std::vector &libs) +bool +amdcl::OCLLinker::linkLLVMModules(std::vector> &libs) { // Load input modules first bool Failed = false; @@ -316,7 +300,7 @@ amdcl::OCLLinker::linkLLVMModules(std::vector &libs) std::error_code EC; llvm::raw_fd_ostream outs(fileName.c_str(), EC, llvm::sys::fs::F_None); if (!EC) - llvm::WriteBitcodeToFile(libs[i], outs); + llvm::WriteBitcodeToFile(libs[i].get(), outs); else printf(EC.message().c_str()); #endif @@ -327,7 +311,7 @@ amdcl::OCLLinker::linkLLVMModules(std::vector &libs) // Link input modules together for (size_t i = 0; i < libs.size(); ++i) { DEBUG(llvm::dbgs() << "LinkWithModule " << i << ":\n"); - if (amdcl::OCLLinker::linkWithModule(LLVMBinary(), libs[i])) { + if (amdcl::OCLLinker::linkWithModule(LLVMBinary(), std::move(libs[i]))) { Failed = true; } } @@ -336,7 +320,6 @@ amdcl::OCLLinker::linkLLVMModules(std::vector &libs) if (Failed) { delete LLVMBinary(); } - std::for_each(libs.begin(), libs.end(), std::ptr_fun(delete_llvm_module)); libs.clear(); return Failed; @@ -512,7 +495,7 @@ translateSpirv(llvm::Module *&M, const std::string &DumpSpirv, #endif int -amdcl::OCLLinker::link(llvm::Module* input, std::vector &libs) +amdcl::OCLLinker::link(llvm::Module* input, std::vector> &libs) { bool IsGPUTarget = isGpuTarget(Elf()->target); uint64_t start_time = 0ULL, time_link = 0ULL, time_prelinkopt = 0ULL; @@ -566,7 +549,7 @@ amdcl::OCLLinker::link(llvm::Module* input, std::vector &libs) } #ifdef HAS_SPIRV - if (Options()->oVariables->RoundTripSPIRV && isSPIRModule(*llvmbinary_)) { + if (Options()->oVariables->RoundTripSPIRV && isAMDSPIRModule(*llvmbinary_)) { std::string DumpSpirv; std::string DumpLlvm; if (Options()->isDumpFlagSet(amd::option::DUMP_BC_ORIGINAL)) { @@ -634,6 +617,8 @@ amdcl::OCLLinker::link(llvm::Module* input, std::vector &libs) } #endif } + DEBUG_WITH_TYPE("linkTriple", llvm::dbgs() << "Library[" << i << "] " << + Library->getTargetTriple() << ' ' << LibDataLayout << '\n'); if (LibTargetTriple.empty()) { // The first member in the list of libraries is assumed to be @@ -654,7 +639,7 @@ amdcl::OCLLinker::link(llvm::Module* input, std::vector &libs) } std::string clp_errmsg; - llvm::Module *OnFlyLib = AMDPrelink(LLVMBinary(), clp_errmsg); + std::unique_ptr OnFlyLib(AMDPrelink(LLVMBinary(), clp_errmsg)); if (!clp_errmsg.empty()) { delete LLVMBinary(); @@ -666,13 +651,11 @@ amdcl::OCLLinker::link(llvm::Module* input, std::vector &libs) if (OnFlyLib) { // OnFlyLib must be the first! std::string ErrorMsg; - if (resolveLink(LLVMBinary(), OnFlyLib, &ErrorMsg)) { - delete OnFlyLib; + if (resolveLink(LLVMBinary(), std::move(OnFlyLib), &ErrorMsg)) { BuildLog() += ErrorMsg; BuildLog() += "\nInternal Error: linking libraries failed!\n"; return 1; } - delete OnFlyLib; } if (Options()->oVariables->EnableBuildTiming) { @@ -696,7 +679,7 @@ amdcl::OCLLinker::link(llvm::Module* input, std::vector &libs) // Link libraries to get every functions that are referenced. std::string ErrorMsg; - if (resolveLink(LLVMBinary(), Library.get(), &ErrorMsg)) { + if (resolveLink(LLVMBinary(), std::move(Library), &ErrorMsg)) { BuildLog() += ErrorMsg; BuildLog() += "\nInternal Error: linking libraries failed!\n"; return 1; diff --git a/rocclr/compiler/lib/backends/common/linker.hpp b/rocclr/compiler/lib/backends/common/linker.hpp index 09d7a31d33..f15e9a6123 100644 --- a/rocclr/compiler/lib/backends/common/linker.hpp +++ b/rocclr/compiler/lib/backends/common/linker.hpp @@ -38,7 +38,7 @@ namespace amdcl * binary and links in a vector of libraries. * Returns 0 on success, non-zero on failure. */ - virtual int link(llvm::Module* input, std::vector &libs) = 0; + virtual int link(llvm::Module* input, std::vector> &libs) = 0; }; // class Linker /*@}*/ @@ -74,10 +74,10 @@ namespace amdcl * This version also links in the OpenCL math libraries along with * the list of libraries that are passed in. */ - int link(llvm::Module* input, std::vector &libs); + int link(llvm::Module* input, std::vector> &libs); protected: - bool linkLLVMModules(std::vector &libs); - bool linkWithModule(llvm::Module* Dst, llvm::Module* Src); + bool linkLLVMModules(std::vector> &libs); + bool linkWithModule(llvm::Module* Dst, std::unique_ptr Src); private: diff --git a/rocclr/compiler/lib/backends/common/opt_level.cpp b/rocclr/compiler/lib/backends/common/opt_level.cpp index ee96f2cdf7..ff86f4a4ce 100644 --- a/rocclr/compiler/lib/backends/common/opt_level.cpp +++ b/rocclr/compiler/lib/backends/common/opt_level.cpp @@ -12,6 +12,8 @@ #if defined(LEGACY_COMPLIB) #include "llvm/DataLayout.h" #include "llvm/Module.h" +#else +#include "llvm/Analysis/TargetTransformInfo.h" #endif #include "llvm/Transforms/IPO/PassManagerBuilder.h" #include "llvm/LinkAllPasses.h" @@ -27,14 +29,10 @@ OptLevel::setup(bool isGPU, uint32_t OptLevel) // Add an appropriate DataLayout instance for this module. #if defined(LEGACY_COMPLIB) Passes().add(new DataLayout(module_)); -#else - Passes().add(new DataLayoutPass()); -#endif fpasses_ = new FunctionPassManager(module_); -#if defined(LEGACY_COMPLIB) fpasses_->add(new DataLayout(module_)); #else - fpasses_->add(new DataLayoutPass()); + fpasses_ = new legacy::FunctionPassManager(module_); #endif PassManagerBuilder Builder; @@ -110,7 +108,6 @@ OptLevel::run(aclBinary *elf) Error); if (TheTarget) { llvm::TargetOptions targetOptions; - targetOptions.NoFramePointerElim = false; targetOptions.StackAlignmentOverride = Options()->oVariables->CPUStackAlignment; #ifdef WITH_TARGET_HSAIL if (Options()->libraryType_ == amd::GPU_Library_HSAIL) @@ -118,8 +115,14 @@ OptLevel::run(aclBinary *elf) #endif targetOptions.LessPreciseFPMADOption = Options()->oVariables->MadEnable || Options()->oVariables->EnableMAD; - targetOptions.NoInfsFPMath = Options()->oVariables->FiniteMathOnly; - targetOptions.NoNaNsFPMath = Options()->oVariables->FiniteMathOnly; + targetOptions.NoInfsFPMath = targetOptions.NoNaNsFPMath + = Options()->oVariables->FiniteMathOnly; + for (auto &F : *module_) { + auto Attrs = F.getAttributes(); + Attrs = Attrs.addAttribute(F.getContext(), AttributeSet::FunctionIndex, + "no-frame-pointer-elim", "false"); + F.setAttributes(Attrs); + } llvm::CodeGenOpt::Level OLvl = CodeGenOpt::None; switch (Options()->oVariables->OptLevel) { @@ -152,7 +155,7 @@ OptLevel::run(aclBinary *elf) } std::unique_ptr TM(Machine); if (TM.get()) - TM->addAnalysisPasses(passes_); + fpasses_->add(createTargetTransformInfoWrapperPass(TM->getTargetIRAnalysis())); #endif if (Options()->oVariables->OptPrintLiveness) { diff --git a/rocclr/compiler/lib/backends/common/opt_level.hpp b/rocclr/compiler/lib/backends/common/opt_level.hpp index e7a8b761a7..a59b842e38 100644 --- a/rocclr/compiler/lib/backends/common/opt_level.hpp +++ b/rocclr/compiler/lib/backends/common/opt_level.hpp @@ -6,15 +6,28 @@ #include "top.hpp" #include "utils/options.hpp" #include "aclTypes.h" + +#if defined DEBUG +#undef DEBUG +#endif + +#if defined(LEGACY_COMPLIB) #include "llvm/PassManager.h" +#else +#include "llvm/IR/LegacyPassManager.h" +#endif #include "llvm/Analysis/Passes.h" namespace llvm { class Module; - namespace legacy { - class FunctionPassManager; - } }; // llvm namespace + +#if defined(LEGACY_COMPLIB) +#define LLVM_LEGACY_NAMESPACE llvm +#else +#define LLVM_LEGACY_NAMESPACE llvm::legacy +#endif + namespace amdcl { /*! \addtogroup Compiler Library @@ -37,13 +50,13 @@ namespace amdcl protected: void setup(bool isGPU, uint32_t OptLevel); void run(aclBinary *elf); - llvm::PassManager& Passes() { return passes_; } - llvm::FunctionPassManager& FPasses() { return (*fpasses_); } + LLVM_LEGACY_NAMESPACE::PassManager& Passes() { return passes_; } + LLVM_LEGACY_NAMESPACE::FunctionPassManager& FPasses() { return (*fpasses_); } amd::option::Options* Options() { return opts_; } llvm::Module* module_; private: - llvm::FunctionPassManager *fpasses_; - llvm::PassManager passes_; + LLVM_LEGACY_NAMESPACE::FunctionPassManager *fpasses_; + LLVM_LEGACY_NAMESPACE::PassManager passes_; amd::option::Options *opts_; }; // class OptLevel /*@}*/ diff --git a/rocclr/compiler/lib/backends/common/optimizer.cpp b/rocclr/compiler/lib/backends/common/optimizer.cpp index 6fa561e647..3d5f4bd18d 100644 --- a/rocclr/compiler/lib/backends/common/optimizer.cpp +++ b/rocclr/compiler/lib/backends/common/optimizer.cpp @@ -47,11 +47,11 @@ static OptLevel* getOptLevel(amd::option::Options* Options, bool isGPU) { int CPUOptimizer::preOptimizer(llvm::Module* M) { - llvm::PassManager Passes; #if defined(LEGACY_COMPLIB) + llvm::PassManager Passes; Passes.add(new llvm::DataLayout(M)); #else - Passes.add(new llvm::DataLayoutPass()); + llvm::legacy::PassManager Passes; #endif Passes.add(createAMDExportKernelNaturePass()); diff --git a/rocclr/compiler/lib/backends/common/spir.cpp b/rocclr/compiler/lib/backends/common/spir.cpp index 216f9b683e..77569fc5d1 100644 --- a/rocclr/compiler/lib/backends/common/spir.cpp +++ b/rocclr/compiler/lib/backends/common/spir.cpp @@ -27,7 +27,11 @@ #include "llvm/IR/Verifier.h" #endif #include "llvm/Pass.h" +#if defined(LEGACY_COMPLIB) #include "llvm/PassManager.h" +#else +#include "llvm/IR/LegacyPassManager.h" +#endif #include "llvm/ADT/SmallString.h" #include "llvm/Analysis/SPIRVerifier.h" #include "llvm/Bitcode/ReaderWriter.h" @@ -67,7 +71,11 @@ amdcl::SPIR::loadSPIR(std::string &spirBinary) log_ += errors; errors.clear(); } +#if defined(LEGACY_COMPLIB) FunctionPassManager FPM(bc); +#else + legacy::FunctionPassManager FPM(bc); +#endif if (Options()->oVariables->verifyHWSpir) { if (!isHSAILTarget(Elf()->target)) { verifySPIRModule(*bc, LLVMReturnStatusAction, State, false, &errors); @@ -106,11 +114,11 @@ amdcl::SPIR::loadBitcode(std::string &binary) bc->setDataLayout(LayoutStr); bc->setTargetTriple(familySet[Elf()->target.arch_id].triple); - llvm::PassManager SPIRPasses; #if defined(LEGACY_COMPLIB) + llvm::PassManager SPIRPasses; SPIRPasses.add(new llvm::DataLayout(bc)); #else - SPIRPasses.add(new llvm::DataLayoutPass()); + llvm::legacy::PassManager SPIRPasses; #endif SPIRPasses.add(createSPIRLoader(/*demangleBuiltin=*/ true)); SPIRPasses.run(*bc); diff --git a/rocclr/compiler/lib/backends/common/v0_8/if_acl.cpp b/rocclr/compiler/lib/backends/common/v0_8/if_acl.cpp index c5fe2bcda7..955fde6cae 100644 --- a/rocclr/compiler/lib/backends/common/v0_8/if_acl.cpp +++ b/rocclr/compiler/lib/backends/common/v0_8/if_acl.cpp @@ -16,6 +16,11 @@ #include "compiler_stage.hpp" #include "frontend.hpp" #include "spir.hpp" + +#if defined DEBUG +#undef DEBUG +#endif + #include "codegen.hpp" #include "library.hpp" #include "linker.hpp" @@ -23,7 +28,6 @@ #include "amdil_be.hpp" #include "hsail_be.hpp" #include "x86_be.hpp" -#include "bif/bifbase.hpp" #include "os/os.hpp" #include "utils/bif_section_labels.hpp" #include "utils/libUtils.h" @@ -71,6 +75,8 @@ #include "llvm/ExecutionEngine/ExecutionEngine.h" #include "llvm/ExecutionEngine/JITEventListener.h" #include "llvm/ExecutionEngine/RuntimeDyld.h" + +#include "bif/bifbase.hpp" #include #include #include @@ -115,7 +121,6 @@ if_aclCompilerInit(aclCompiler *cl, aclBinary *bin, llvm::initializeIPO(Registry); llvm::initializeInstrumentation(Registry); llvm::initializeAnalysis(Registry); - llvm::initializeIPA(Registry); llvm::initializeCodeGen(Registry); llvm::initializeTarget(Registry); #if defined(LEGACY_COMPLIB) @@ -310,7 +315,7 @@ RSLLVMIRToModule( #else std::unique_ptr Buffer = llvm::MemoryBuffer::getMemBufferCopy(llvm::StringRef(llvmBinary), "input.bc"); - llvm::ErrorOr ErrOrM(nullptr); + llvm::ErrorOr> ErrOrM(nullptr); #endif if (llvm::isBitcode((const unsigned char *)Buffer->getBufferStart(), @@ -325,13 +330,13 @@ RSLLVMIRToModule( #if defined(LEGACY_COMPLIB) if (M == NULL) { #else - if (!ErrOrM || ErrOrM.get() == nullptr) { + if (ErrOrM.getError()) { #endif if (error != NULL) (*error) = ACL_INVALID_BINARY; return NULL; } #if !defined(LEGACY_COMPLIB) - llvm::Module *M = ErrOrM.get(); + auto M = ErrOrM.get().release(); #endif amdcl::CompilerStage *cs = reinterpret_cast(ald); aclDevType arch_id = cs->Elf()->target.arch_id; @@ -352,7 +357,11 @@ RSLLVMIRToModule( const char * LayoutStr = is64BitTarget(cs->Elf()->target) ? DATA_LAYOUT_64BIT : DATA_LAYOUT_32BIT; M->setDataLayout(LayoutStr); +#if defined(LEGACY_COMPLIB) llvm::PassManager TransformPasses; +#else + llvm::legacy::PassManager TransformPasses; +#endif TransformPasses.add(llvm::createOpenCLIRTransform()); if (!TransformPasses.run(*M)) { if (error != NULL) (*error) = ACL_FRONTEND_FAILURE; @@ -458,7 +467,6 @@ SPIRVToModule( llvm::SmallVector array; llvm::raw_svector_ostream outstream(array); llvm::WriteBitcodeToFile(reinterpret_cast(llMod), outstream); - outstream.flush(); auto errCode = cl->clAPI.insSec(cl, bin, &array[0], array.size(), aclLLVMIR); if (error != nullptr) (*error) = errCode; if (errCode != ACL_SUCCESS) @@ -624,10 +632,10 @@ OCLLinkPhase( Opts->getLLVMArgv(), "OpenCL"); // LLVM Link phase - std::vector libvec; + std::vector> libvec; for (unsigned x = 0; x < numLibs; ++x) { if (libs[x] != NULL) { - libvec.push_back(reinterpret_cast(libs[x])); + libvec.push_back(std::unique_ptr(reinterpret_cast(libs[x]))); } } int ret = aclLink->link(reinterpret_cast(llvmBin), libvec); @@ -1718,24 +1726,12 @@ if_aclLink(aclCompiler *cl, case ACL_TYPE_LLVMIR_BINARY: case ACL_TYPE_RSLLVMIR_BINARY: { -#if 1 || LLVM_TRUNK_INTEGRATION_CL >= 7710 llvm::SmallVector array; llvm::raw_svector_ostream outstream(array); llvm::WriteBitcodeToFile(reinterpret_cast(dst_module), outstream); cl->clAPI.remSec(cl, src_bin, aclLLVMIR); - outstream.flush(); error_code = cl->clAPI.insSec(cl, src_bin, &array[0], array.size(), aclLLVMIR); -#else - std::vector array; - array.reserve(4096); - llvm::BitstreamWriter stream(array); - llvm::WriteBitcodeToStream(reinterpret_cast(dst_module), - stream); - cl->clAPI.remSec(cl, src_bin, aclLLVMIR); - error_code = cl->clAPI.insSec(cl, src_bin, - &array[0], array.size(), aclLLVMIR); -#endif if (dst_module != NULL && dst_module != module) { delete reinterpret_cast(dst_module); } @@ -3161,7 +3157,7 @@ static llvm::RuntimeDyld* GetOrCreateDyld(llvm::object::ObjectFile* obj) { return DI->second; OCLMCJITMemoryManager *memMgr = new OCLMCJITMemoryManager(); MemMgrTable.insert(std::make_pair(obj, memMgr)); - llvm::RuntimeDyld *rtdyld = new llvm::RuntimeDyld(memMgr); + llvm::RuntimeDyld *rtdyld = new llvm::RuntimeDyld(*memMgr, *memMgr); DyLdTable.insert(std::make_pair(obj, rtdyld)); return rtdyld; } @@ -3347,14 +3343,13 @@ if_aclJITObjectImageIterateSymbols(aclJITObjectImage image, #else llvm::object::ObjectFile* objectImage = reinterpret_cast(image); llvm::RuntimeDyld *rtdyld = GetOrCreateDyld(objectImage); - std::error_code err; - llvm::StringRef name; - for (const llvm::object::SymbolRef &S: objectImage->symbols()) { - std::error_code err = S.getName(name); - assert (!err); - uint64_t address; - address = (uint64_t) rtdyld->getSymbolLoadAddress(name); - jit_callback(name.data(), (const void*)address, data); + for (const auto &S: objectImage->symbols()) { + auto Ret = S.getName(); + if (!Ret) { + auto InternalSymbol = rtdyld->getSymbol(Ret.get()); + uint64_t address = (uint64_t)(InternalSymbol ? InternalSymbol.getAddress() : 0); + jit_callback(Ret.get().data(), (const void*)address, data); + } } #endif return ACL_SUCCESS; diff --git a/rocclr/compiler/lib/complibdefs b/rocclr/compiler/lib/complibdefs index d0cde67b64..d234807591 100644 --- a/rocclr/compiler/lib/complibdefs +++ b/rocclr/compiler/lib/complibdefs @@ -79,7 +79,7 @@ ifdef ATI_OS_WINDOWS GCXXOPTS += /Ob1 endif - GCXXOPTS += -wd4985 -wd4355 -wd4800 -wd4291 + GCXXOPTS += -wd4985 -wd4355 -wd4800 -wd4291 -wd4624 -wd4141 GCPPFLAGS += $(DEFSWITCH) _SCL_SECURE_NO_WARNINGS @@ -90,7 +90,7 @@ ifdef ATI_OS_LINUX GCPPFLAGS += $(DEFSWITCH) __STDC_LIMIT_MACROS GCPPFLAGS += $(DEFSWITCH) __STDC_CONSTANT_MACROS - GCXXOPTS += -fno-rtti + GCXXOPTS += -fno-rtti -Wno-sign-compare endif ifeq ($(OPENCL_USE_ONE_SC),1)