diff --git a/src/codegen/llvm/codegen_amdgpu.cc b/src/codegen/llvm/codegen_amdgpu.cc index 2784090870cb..58a2964c3d82 100644 --- a/src/codegen/llvm/codegen_amdgpu.cc +++ b/src/codegen/llvm/codegen_amdgpu.cc @@ -71,7 +71,11 @@ class CodeGenAMDGPU : public CodeGenLLVM { LLVMType(op->type), ConstInt32(constant_size)); }); if (alloca->getAlignment() < static_cast(info.alignment)) { +#if TVM_LLVM_VERSION >= 100 + alloca->setAlignment(llvm::Align(info.alignment)); +#else alloca->setAlignment(info.alignment); +#endif } buf = alloca; } else { @@ -84,7 +88,11 @@ class CodeGenAMDGPU : public CodeGenLLVM { llvm::GlobalVariable *global = new llvm::GlobalVariable( *module_, type, false, llvm::GlobalValue::PrivateLinkage, 0, ".shared", nullptr, llvm::GlobalValue::NotThreadLocal, shared_address_space); +#if TVM_LLVM_VERSION >= 100 + global->setAlignment(llvm::Align(info.alignment)); +#else global->setAlignment(info.alignment); +#endif buf = global; } } diff --git a/src/codegen/llvm/codegen_cpu.cc b/src/codegen/llvm/codegen_cpu.cc index fed032d4ae54..0ba0c584a590 100644 --- a/src/codegen/llvm/codegen_cpu.cc +++ b/src/codegen/llvm/codegen_cpu.cc @@ -236,7 +236,11 @@ void CodeGenCPU::AddMainFunction(const std::string& entry_func_name) { llvm::GlobalVariable *global = new llvm::GlobalVariable( *module_, type, true, llvm::GlobalValue::WeakAnyLinkage, 0, runtime::symbol::tvm_module_main); +#if TVM_LLVM_VERSION >= 100 + global->setAlignment(llvm::Align(1)); +#else global->setAlignment(1); +#endif global->setInitializer(llvm::ConstantDataArray::getString(*ctx_, entry_func_name)); } @@ -350,7 +354,11 @@ llvm::GlobalVariable* CodeGenCPU::InitContextPtr( *module_, p_type, false, llvm::GlobalValue::LinkOnceAnyLinkage, 0, name); +#if TVM_LLVM_VERSION >= 100 + gv->setAlignment(llvm::Align(data_layout_->getTypeAllocSize(p_type))); +#else gv->setAlignment(data_layout_->getTypeAllocSize(p_type)); +#endif gv->setInitializer(llvm::Constant::getNullValue(p_type)); gv->setDLLStorageClass(llvm::GlobalValue::DLLStorageClassTypes::DLLExportStorageClass); return gv; @@ -550,7 +558,11 @@ llvm::Value* CodeGenCPU::CreateStaticHandle() { *module_, t_void_p_, false, llvm::GlobalValue::PrivateLinkage, 0, "__tvm_static_handle"); +#if TVM_LLVM_VERSION >= 100 + gv->setAlignment(llvm::Align(data_layout_->getTypeAllocSize(t_void_p_))); +#else gv->setAlignment(data_layout_->getTypeAllocSize(t_void_p_)); +#endif gv->setInitializer(llvm::Constant::getNullValue(t_void_p_)); return gv; } @@ -610,7 +622,11 @@ llvm::Value* CodeGenCPU::GetPackedFuncHandle(const std::string& fname) { hptr = new llvm::GlobalVariable( *module_, t_tvm_func_handle_, false, llvm::GlobalValue::InternalLinkage, nullptr, ".tvm_func." + fname); +#if TVM_LLVM_VERSION >= 100 + hptr->setAlignment(llvm::Align(align)); +#else hptr->setAlignment(align); +#endif hptr->setInitializer(llvm::Constant::getNullValue(t_tvm_func_handle_)); func_handle_map_[fname] = hptr; } else { diff --git a/src/codegen/llvm/codegen_llvm.cc b/src/codegen/llvm/codegen_llvm.cc index 3a58963cc6e1..d009290bb2fe 100644 --- a/src/codegen/llvm/codegen_llvm.cc +++ b/src/codegen/llvm/codegen_llvm.cc @@ -595,7 +595,11 @@ llvm::Value* CodeGenLLVM::GetConstString(const std::string& str) { llvm::Type* type = llvm::ArrayType::get(t_char_, str.length() + 1); llvm::GlobalVariable *global = new llvm::GlobalVariable( *module_, type, true, llvm::GlobalValue::PrivateLinkage, 0, ".str"); +#if TVM_LLVM_VERSION >= 100 + global->setAlignment(llvm::Align(1)); +#else global->setAlignment(1); +#endif global->setInitializer(llvm::ConstantDataArray::getString(*ctx_, str)); llvm::Constant* zero = ConstInt32(0); llvm::Constant* indices[] = {zero, zero}; @@ -1150,7 +1154,11 @@ void CodeGenLLVM::VisitStmt_(const Allocate* op) { LLVMType(op->type), ConstInt32(constant_size)); }); if (alloca->getAlignment() < static_cast(info.alignment)) { +#if TVM_LLVM_VERSION >= 100 + alloca->setAlignment(llvm::Align(info.alignment)); +#else alloca->setAlignment(info.alignment); +#endif } info.alignment = alloca->getAlignment(); buf = alloca; diff --git a/src/codegen/llvm/codegen_nvptx.cc b/src/codegen/llvm/codegen_nvptx.cc index 290727fd9152..c343de147cf6 100644 --- a/src/codegen/llvm/codegen_nvptx.cc +++ b/src/codegen/llvm/codegen_nvptx.cc @@ -73,7 +73,11 @@ class CodeGenNVPTX : public CodeGenLLVM { LLVMType(op->type), ConstInt32(constant_size)); }); if (alloca->getAlignment() < static_cast(info.alignment)) { +#if TVM_LLVM_VERSION >= 100 + alloca->setAlignment(llvm::Align(info.alignment)); +#else alloca->setAlignment(info.alignment); +#endif } buf = alloca; } else { @@ -86,7 +90,11 @@ class CodeGenNVPTX : public CodeGenLLVM { llvm::GlobalVariable *global = new llvm::GlobalVariable( *module_, type, false, llvm::GlobalValue::PrivateLinkage, 0, ".shared", nullptr, llvm::GlobalValue::NotThreadLocal, shared_address_space); +#if TVM_LLVM_VERSION >= 100 + global->setAlignment(llvm::Align(info.alignment)); +#else global->setAlignment(info.alignment); +#endif buf = global; } } diff --git a/src/codegen/llvm/llvm_common.h b/src/codegen/llvm/llvm_common.h index 33ea8ebd19ad..78baf4131a57 100644 --- a/src/codegen/llvm/llvm_common.h +++ b/src/codegen/llvm/llvm_common.h @@ -55,6 +55,9 @@ #include #include +#if TVM_LLVM_VERSION >= 100 +#include +#endif #include #include #include