Commit 0319f99d by Andrew Tulloch Committed by Tianqi Chen

[Cleanliness] [Easy] Make TVM leak-sanitizer and Wnon-virtual-dtor clean. (#2046)

parent add1f90e
......@@ -23,6 +23,7 @@ namespace codegen {
*/
class CodeGenSourceBase {
public:
virtual ~CodeGenSourceBase() = default;
/*!
* \brief Register constant value appeared in expresion tree
* This avoid generated a ssa id for each appearance of the value
......
......@@ -160,10 +160,10 @@ runtime::Module BuildAMDGPU(Array<LoweredFunc> funcs, std::string target) {
config << "-mtriple=amdgcn-amd-amdhsa-hcc -mcpu=gfx"
<< DetectROCMComputeVersion(target)
<< target.substr(4, target.length() - 4);
llvm::TargetMachine* tm = GetLLVMTargetMachine(config.str());
std::unique_ptr<llvm::TargetMachine> tm = GetLLVMTargetMachine(config.str());
std::unique_ptr<CodeGenAMDGPU> cg(new CodeGenAMDGPU());
std::unique_ptr<llvm::LLVMContext> ctx(new llvm::LLVMContext());
cg->Init(funcs[0]->name, tm, ctx.get(), false, false);
cg->Init(funcs[0]->name, tm.get(), ctx.get(), false, false);
for (LoweredFunc f : funcs) {
cg->AddFunction(f);
}
......
......@@ -171,10 +171,10 @@ runtime::Module BuildNVPTX(Array<LoweredFunc> funcs, std::string target) {
config << "-mtriple=nvptx64-nvidia-cuda -mcpu=sm_"
<< compute_ver
<< target.substr(5, target.length() - 5);
llvm::TargetMachine* tm = GetLLVMTargetMachine(config.str());
std::unique_ptr<llvm::TargetMachine> tm = GetLLVMTargetMachine(config.str());
std::unique_ptr<CodeGenNVPTX> cg(new CodeGenNVPTX());
std::unique_ptr<llvm::LLVMContext> ctx(new llvm::LLVMContext());
cg->Init(funcs[0]->name, tm, ctx.get(), false, false);
cg->Init(funcs[0]->name, tm.get(), ctx.get(), false, false);
for (LoweredFunc f : funcs) {
cg->AddFunction(f);
}
......
......@@ -114,7 +114,7 @@ void ParseLLVMTargetOptions(const std::string& target_str,
}
llvm::TargetMachine*
std::unique_ptr<llvm::TargetMachine>
GetLLVMTargetMachine(const std::string& target_str,
bool allow_null) {
std::string target_triple, mcpu, mattr;
......@@ -143,7 +143,7 @@ GetLLVMTargetMachine(const std::string& target_str,
}
llvm::TargetMachine* tm = target->createTargetMachine(
target_triple, mcpu, mattr, opt, llvm::Reloc::PIC_);
return tm;
return std::unique_ptr<llvm::TargetMachine>(tm);
}
} // namespace codegen
......
......@@ -78,7 +78,7 @@ void ParseLLVMTargetOptions(const std::string& target_str,
* \param allow_null Whether allow null to be returned.
* \return target machine
*/
llvm::TargetMachine*
std::unique_ptr<llvm::TargetMachine>
GetLLVMTargetMachine(const std::string& target_str, bool allow_null = false);
} // namespace codegen
......
......@@ -160,9 +160,9 @@ class LLVMModuleNode final : public runtime::ModuleNode {
bool system_lib = (target.find("-system-lib") != std::string::npos);
CHECK_NE(funcs.size(), 0U);
ctx_ = std::make_shared<llvm::LLVMContext>();
std::unique_ptr<CodeGenLLVM> cg = CodeGenLLVM::Create(tm_);
std::unique_ptr<CodeGenLLVM> cg = CodeGenLLVM::Create(tm_.get());
entry_func_ = funcs[0]->name;
cg->Init(funcs[0]->name, tm_, ctx_.get(), system_lib, system_lib);
cg->Init(funcs[0]->name, tm_.get(), ctx_.get(), system_lib, system_lib);
for (LoweredFunc f : funcs) {
cg->AddFunction(f);
}
......@@ -218,8 +218,8 @@ class LLVMModuleNode final : public runtime::ModuleNode {
builder.setMAttrs(mattrs);
}
builder.setTargetOptions(opt);
llvm::TargetMachine *tm = builder.selectTarget();
llvm::TargetMachine *tm_sys = GetLLVMTargetMachine("llvm");
auto tm = std::unique_ptr<llvm::TargetMachine>(builder.selectTarget());
std::unique_ptr<llvm::TargetMachine> tm_sys = GetLLVMTargetMachine("llvm");
if (tm_sys->getTargetTriple().getArch() != tm->getTargetTriple().getArch()) {
LOG(FATAL) << "Cannot run module, architecture mismatch "
<< " module=" << tm->getTargetTriple().str()
......@@ -231,7 +231,7 @@ class LLVMModuleNode final : public runtime::ModuleNode {
<< mptr_->getDataLayout().getStringRepresentation() << ")"
<< " and ExecutionEngine ("
<< layout.getStringRepresentation() << ")";
ee_ = builder.create(tm);
ee_ = builder.create(tm.release());
CHECK(ee_ != nullptr)
<< "Failed to initialize git engine for " << mptr_->getTargetTriple();
ee_->runStaticConstructorsDestructors(false);
......@@ -275,7 +275,7 @@ class LLVMModuleNode final : public runtime::ModuleNode {
// The raw pointer to the module.
llvm::Module* mptr_{nullptr};
// The target machine
llvm::TargetMachine* tm_{nullptr};
std::unique_ptr<llvm::TargetMachine> tm_{nullptr};
// The module, can be moved to ee if JIT is enabled.
std::unique_ptr<llvm::Module> module_;
// the context.
......
......@@ -16,6 +16,7 @@ namespace runtime {
*/
class DSLAPI {
public:
virtual ~DSLAPI() = default;
virtual void NodeFree(NodeHandle handle) const = 0;
virtual void NodeTypeKey2Index(const char* type_key,
......
......@@ -34,8 +34,11 @@ struct Registry::Manager {
}
static Manager* Global() {
static Manager inst;
return &inst;
// We deliberately leak the Manager instance, to avoid leak sanitizers
// complaining about the entries in Manager::fmap being leaked at program
// exit.
static Manager* inst = new Manager();
return inst;
}
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment