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