Skip to content

Commit

Permalink
[llvm] switch to use Align for llvm trunk (#4051)
Browse files Browse the repository at this point in the history
  • Loading branch information
yzhliu authored and zhiics committed Oct 4, 2019
1 parent 8111802 commit 59d8d40
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/codegen/llvm/codegen_amdgpu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ class CodeGenAMDGPU : public CodeGenLLVM {
LLVMType(op->type), ConstInt32(constant_size));
});
if (alloca->getAlignment() < static_cast<uint32_t>(info.alignment)) {
#if TVM_LLVM_VERSION >= 100
alloca->setAlignment(llvm::Align(info.alignment));
#else
alloca->setAlignment(info.alignment);
#endif
}
buf = alloca;
} else {
Expand All @@ -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;
}
}
Expand Down
16 changes: 16 additions & 0 deletions src/codegen/llvm/codegen_cpu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 8 additions & 0 deletions src/codegen/llvm/codegen_llvm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -1150,7 +1154,11 @@ void CodeGenLLVM::VisitStmt_(const Allocate* op) {
LLVMType(op->type), ConstInt32(constant_size));
});
if (alloca->getAlignment() < static_cast<uint32_t>(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;
Expand Down
8 changes: 8 additions & 0 deletions src/codegen/llvm/codegen_nvptx.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ class CodeGenNVPTX : public CodeGenLLVM {
LLVMType(op->type), ConstInt32(constant_size));
});
if (alloca->getAlignment() < static_cast<uint32_t>(info.alignment)) {
#if TVM_LLVM_VERSION >= 100
alloca->setAlignment(llvm::Align(info.alignment));
#else
alloca->setAlignment(info.alignment);
#endif
}
buf = alloca;
} else {
Expand All @@ -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;
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/codegen/llvm/llvm_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@
#include <llvm/Transforms/IPO/PassManagerBuilder.h>
#include <llvm/Transforms/IPO.h>

#if TVM_LLVM_VERSION >= 100
#include <llvm/Support/Alignment.h>
#endif
#include <llvm/Support/FileSystem.h>
#include <llvm/Support/MemoryBuffer.h>
#include <llvm/Support/raw_ostream.h>
Expand Down

0 comments on commit 59d8d40

Please sign in to comment.