From 5924520a5e72b2032983fcc1f12da03d33808156 Mon Sep 17 00:00:00 2001 From: Thomas Viehmann Date: Fri, 24 Apr 2020 15:48:51 +0200 Subject: [PATCH] misc fixes for ROCm (pointer lifetime, runtime::String refactor) --- src/target/llvm/codegen_amdgpu.cc | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/target/llvm/codegen_amdgpu.cc b/src/target/llvm/codegen_amdgpu.cc index 61121f67d111..8935809bc6f2 100644 --- a/src/target/llvm/codegen_amdgpu.cc +++ b/src/target/llvm/codegen_amdgpu.cc @@ -219,8 +219,10 @@ runtime::Module BuildAMDGPU(IRModule mod, std::string target) { << " -mattr=-code-object-v3 " << target.substr(4, target.length() - 4); std::unique_ptr tm = GetLLVMTargetMachine(config.str()); - std::unique_ptr cg(new CodeGenAMDGPU()); std::unique_ptr ctx(new llvm::LLVMContext()); + // careful: cg will hold a naked pointer reference to ctx, so it should + // have a shorter lifetime than the ctx. + std::unique_ptr cg(new CodeGenAMDGPU()); cg->Init("TVMAMDGPUModule", tm.get(), ctx.get(), false, false); @@ -233,10 +235,10 @@ runtime::Module BuildAMDGPU(IRModule mod, std::string target) { const auto *find_rocm_bitcodes = tvm::runtime::Registry::Get("tvm_callback_rocm_bitcode_path"); - Array bitcode_files = (*find_rocm_bitcodes)(); + Array bitcode_files = (*find_rocm_bitcodes)(); - for (auto &bitcode : bitcode_files) { - std::string path = bitcode.as()->value; + for (auto &bitcode_path : bitcode_files) { + std::string path = bitcode_path; llvm::SMDiagnostic err; std::unique_ptr mlib = llvm::parseIRFile(path, err, *ctx); if (mlib.get() == nullptr) {