Unverified Commit 36ce2e24 by Krzysztof Parzyszek Committed by GitHub

[LLVM] Use llvm::Align with LLVM 11+ to avoid warnings (#5264)

LLVM 11 is introducing a separate class to represent alignment.
The functions in IRBuilder that create aligned loads and stores,
and which accept the alignment as an unsigned value have been
deprecated (and now cause warnings to be emitted).
parent e11a6092
...@@ -370,7 +370,11 @@ llvm::GlobalVariable* CodeGenCPU::InitContextPtr( ...@@ -370,7 +370,11 @@ llvm::GlobalVariable* CodeGenCPU::InitContextPtr(
llvm::Value* CodeGenCPU::GetContextPtr(llvm::GlobalVariable* gv) { llvm::Value* CodeGenCPU::GetContextPtr(llvm::GlobalVariable* gv) {
CHECK(gv != nullptr); CHECK(gv != nullptr);
#if TVM_LLVM_VERSION >= 110
llvm::LoadInst* faddr = builder_->CreateAlignedLoad(gv, llvm::Align(gv->getAlignment()));
#else
llvm::LoadInst* faddr = builder_->CreateAlignedLoad(gv, gv->getAlignment()); llvm::LoadInst* faddr = builder_->CreateAlignedLoad(gv, gv->getAlignment());
#endif
faddr->setMetadata( faddr->setMetadata(
"tbaa", "tbaa",
md_builder_->createTBAAStructTagNode(md_tbaa_ctx_ptr_, md_tbaa_ctx_ptr_, 0)); md_builder_->createTBAAStructTagNode(md_tbaa_ctx_ptr_, md_tbaa_ctx_ptr_, 0));
...@@ -642,7 +646,11 @@ llvm::Value* CodeGenCPU::GetPackedFuncHandle(const std::string& fname) { ...@@ -642,7 +646,11 @@ llvm::Value* CodeGenCPU::GetPackedFuncHandle(const std::string& fname) {
*ctx_, "handle_init", function_); *ctx_, "handle_init", function_);
BasicBlock* end_block = BasicBlock::Create( BasicBlock* end_block = BasicBlock::Create(
*ctx_, "handle_init_end", function_); *ctx_, "handle_init_end", function_);
#if TVM_LLVM_VERSION >= 110
llvm::Value* handle = builder_->CreateAlignedLoad(hptr, llvm::Align(align));
#else
llvm::Value* handle = builder_->CreateAlignedLoad(hptr, align); llvm::Value* handle = builder_->CreateAlignedLoad(hptr, align);
#endif
llvm::Value* handle_not_null = builder_->CreateICmpNE( llvm::Value* handle_not_null = builder_->CreateICmpNE(
handle, llvm::Constant::getNullValue(t_tvm_func_handle_)); handle, llvm::Constant::getNullValue(t_tvm_func_handle_));
builder_->CreateCondBr( builder_->CreateCondBr(
...@@ -652,15 +660,24 @@ llvm::Value* CodeGenCPU::GetPackedFuncHandle(const std::string& fname) { ...@@ -652,15 +660,24 @@ llvm::Value* CodeGenCPU::GetPackedFuncHandle(const std::string& fname) {
llvm::Value* out = WithFunctionEntry([&]() { llvm::Value* out = WithFunctionEntry([&]() {
return builder_->CreateAlloca(t_tvm_func_handle_); return builder_->CreateAlloca(t_tvm_func_handle_);
}); });
#if TVM_LLVM_VERSION >= 110
llvm::LoadInst* ctx = builder_->CreateAlignedLoad(
gv_mod_ctx_, llvm::Align(gv_mod_ctx_->getAlignment()));
#else
llvm::LoadInst* ctx = builder_->CreateAlignedLoad( llvm::LoadInst* ctx = builder_->CreateAlignedLoad(
gv_mod_ctx_, gv_mod_ctx_->getAlignment()); gv_mod_ctx_, gv_mod_ctx_->getAlignment());
#endif
ctx->setMetadata( ctx->setMetadata(
"tbaa", "tbaa",
md_builder_->createTBAAStructTagNode(md_tbaa_ctx_ptr_, md_tbaa_ctx_ptr_, 0)); md_builder_->createTBAAStructTagNode(md_tbaa_ctx_ptr_, md_tbaa_ctx_ptr_, 0));
llvm::Value* retcode = builder_->CreateCall( llvm::Value* retcode = builder_->CreateCall(
RuntimeTVMGetFuncFromEnv(), {ctx, GetConstString(fname), out}); RuntimeTVMGetFuncFromEnv(), {ctx, GetConstString(fname), out});
init_block = CheckCallSuccess(retcode); init_block = CheckCallSuccess(retcode);
#if TVM_LLVM_VERSION >= 110
llvm::Value* loaded_handle = builder_->CreateAlignedLoad(out, llvm::Align(align));
#else
llvm::Value* loaded_handle = builder_->CreateAlignedLoad(out, align); llvm::Value* loaded_handle = builder_->CreateAlignedLoad(out, align);
#endif
// Store the handle // Store the handle
builder_->CreateStore(loaded_handle, hptr); builder_->CreateStore(loaded_handle, hptr);
builder_->CreateBr(end_block); builder_->CreateBr(end_block);
...@@ -697,10 +714,13 @@ CodeGenCPU::MakeCallPacked(const Array<PrimExpr> &args, llvm::Value **rvalue, ...@@ -697,10 +714,13 @@ CodeGenCPU::MakeCallPacked(const Array<PrimExpr> &args, llvm::Value **rvalue,
RuntimeTVMFuncCall(), {handle, arg_value, arg_tcode, ConstInt32(nargs), RuntimeTVMFuncCall(), {handle, arg_value, arg_tcode, ConstInt32(nargs),
ret_value, *ret_tcode})); ret_value, *ret_tcode}));
DataType r_api_type = tir::APIType(r_type); DataType r_api_type = tir::APIType(r_type);
*rvalue = builder_->CreateAlignedLoad( llvm::Value* load_ptr = builder_->CreatePointerCast(
builder_->CreatePointerCast( ret_value, DTypeToLLVMType(r_api_type)->getPointerTo());
ret_value, DTypeToLLVMType(r_api_type)->getPointerTo()), #if TVM_LLVM_VERSION >= 110
8); *rvalue = builder_->CreateAlignedLoad(load_ptr, llvm::Align(8));
#else
*rvalue = builder_->CreateAlignedLoad(load_ptr, 8);
#endif
*rvalue = CreateCast(r_api_type, r_type, *rvalue); *rvalue = CreateCast(r_api_type, r_type, *rvalue);
return end_block; return end_block;
} }
...@@ -732,7 +752,11 @@ llvm::Value *CodeGenCPU::CreateCallTracePacked(const CallNode *op) { ...@@ -732,7 +752,11 @@ llvm::Value *CodeGenCPU::CreateCallTracePacked(const CallNode *op) {
// traced value. // traced value.
BasicBlock *continue_block = BasicBlock *continue_block =
BasicBlock::Create(*ctx_, "continue_block", function_); BasicBlock::Create(*ctx_, "continue_block", function_);
#if TVM_LLVM_VERSION >= 110
llvm::Value *ret_tcode_value = builder_->CreateAlignedLoad(ret_tcode, llvm::Align(8));
#else
llvm::Value *ret_tcode_value = builder_->CreateAlignedLoad(ret_tcode, 8); llvm::Value *ret_tcode_value = builder_->CreateAlignedLoad(ret_tcode, 8);
#endif
// Check the ret_type_code and create cmp instruction. // Check the ret_type_code and create cmp instruction.
llvm::Value *cmp = builder_->CreateICmpNE( llvm::Value *cmp = builder_->CreateICmpNE(
ret_tcode_value, llvm::ConstantInt::get(t_int_, kTVMNullptr)); ret_tcode_value, llvm::ConstantInt::get(t_int_, kTVMNullptr));
......
...@@ -980,7 +980,12 @@ llvm::Value* CodeGenLLVM::VisitExpr_(const LoadNode* op) { ...@@ -980,7 +980,12 @@ llvm::Value* CodeGenLLVM::VisitExpr_(const LoadNode* op) {
int alignment, native_bits; int alignment, native_bits;
GetAlignment(t, op->buffer_var.get(), op->index, &alignment, &native_bits); GetAlignment(t, op->buffer_var.get(), op->index, &alignment, &native_bits);
llvm::Value* ptr = CreateBufferPtr(t, buffer, index); llvm::Value* ptr = CreateBufferPtr(t, buffer, index);
#if TVM_LLVM_VERSION >= 110
llvm::LoadInst* load =
builder_->CreateAlignedLoad(ptr, llvm::Align(alignment), is_volatile);
#else
llvm::LoadInst* load = builder_->CreateAlignedLoad(ptr, alignment, is_volatile); llvm::LoadInst* load = builder_->CreateAlignedLoad(ptr, alignment, is_volatile);
#endif
AddAliasInfo(load, op->buffer_var.get(), op->index, t); AddAliasInfo(load, op->buffer_var.get(), op->index, t);
return load; return load;
} else { } else {
...@@ -996,7 +1001,12 @@ llvm::Value* CodeGenLLVM::VisitExpr_(const LoadNode* op) { ...@@ -996,7 +1001,12 @@ llvm::Value* CodeGenLLVM::VisitExpr_(const LoadNode* op) {
t.element_of(), buffer, MakeValue(ramp->base)); t.element_of(), buffer, MakeValue(ramp->base));
ptr = builder_->CreatePointerCast( ptr = builder_->CreatePointerCast(
ptr, DTypeToLLVMType(t)->getPointerTo(addrspace)); ptr, DTypeToLLVMType(t)->getPointerTo(addrspace));
#if TVM_LLVM_VERSION >= 110
llvm::LoadInst* load = builder_->CreateAlignedLoad(
ptr, llvm::Align(alignment), is_volatile);
#else
llvm::LoadInst* load = builder_->CreateAlignedLoad(ptr, alignment, is_volatile); llvm::LoadInst* load = builder_->CreateAlignedLoad(ptr, alignment, is_volatile);
#endif
AddAliasInfo(load, op->buffer_var.get(), op->index, t); AddAliasInfo(load, op->buffer_var.get(), op->index, t);
return load; return load;
} }
...@@ -1007,8 +1017,13 @@ llvm::Value* CodeGenLLVM::VisitExpr_(const LoadNode* op) { ...@@ -1007,8 +1017,13 @@ llvm::Value* CodeGenLLVM::VisitExpr_(const LoadNode* op) {
llvm::Value* ret = llvm::UndefValue::get(DTypeToLLVMType(t)); llvm::Value* ret = llvm::UndefValue::get(DTypeToLLVMType(t));
auto f = [&](int i, llvm::Value* index) { auto f = [&](int i, llvm::Value* index) {
llvm::Value* ptr = CreateBufferPtr(t.element_of(), buffer, index); llvm::Value* ptr = CreateBufferPtr(t.element_of(), buffer, index);
#if TVM_LLVM_VERSION >= 110
llvm::LoadInst* load = builder_->CreateAlignedLoad(
ptr, llvm::Align(basic_align), is_volatile);
#else
llvm::LoadInst* load = builder_->CreateAlignedLoad( llvm::LoadInst* load = builder_->CreateAlignedLoad(
ptr, basic_align, is_volatile); ptr, basic_align, is_volatile);
#endif
ret = builder_->CreateInsertElement(ret, load, ConstInt32(i)); ret = builder_->CreateInsertElement(ret, load, ConstInt32(i));
AddAliasInfo(load, op->buffer_var.get(), PrimExpr(), t); AddAliasInfo(load, op->buffer_var.get(), PrimExpr(), t);
}; };
...@@ -1077,7 +1092,12 @@ void CodeGenLLVM::VisitStmt_(const StoreNode* op) { ...@@ -1077,7 +1092,12 @@ void CodeGenLLVM::VisitStmt_(const StoreNode* op) {
int alignment, native_bits; int alignment, native_bits;
GetAlignment(t, op->buffer_var.get(), op->index, &alignment, &native_bits); GetAlignment(t, op->buffer_var.get(), op->index, &alignment, &native_bits);
llvm::Value* ptr = CreateBufferPtr(t, buffer, index); llvm::Value* ptr = CreateBufferPtr(t, buffer, index);
#if TVM_LLVM_VERSION >= 110
llvm::StoreInst* store =
builder_->CreateAlignedStore(value, ptr, llvm::Align(alignment), is_volatile);
#else
llvm::StoreInst* store = builder_->CreateAlignedStore(value, ptr, alignment, is_volatile); llvm::StoreInst* store = builder_->CreateAlignedStore(value, ptr, alignment, is_volatile);
#endif
AddAliasInfo(store, op->buffer_var.get(), op->index, op->value.dtype()); AddAliasInfo(store, op->buffer_var.get(), op->index, op->value.dtype());
return; return;
} else { } else {
...@@ -1092,7 +1112,12 @@ void CodeGenLLVM::VisitStmt_(const StoreNode* op) { ...@@ -1092,7 +1112,12 @@ void CodeGenLLVM::VisitStmt_(const StoreNode* op) {
llvm::Value* ptr = CreateBufferPtr( llvm::Value* ptr = CreateBufferPtr(
t.element_of(), buffer, MakeValue(ramp->base)); t.element_of(), buffer, MakeValue(ramp->base));
ptr = builder_->CreatePointerCast(ptr, DTypeToLLVMType(t)->getPointerTo(addrspace)); ptr = builder_->CreatePointerCast(ptr, DTypeToLLVMType(t)->getPointerTo(addrspace));
#if TVM_LLVM_VERSION >= 110
llvm::StoreInst* store =
builder_->CreateAlignedStore(value, ptr, llvm::Align(alignment), is_volatile);
#else
llvm::StoreInst* store = builder_->CreateAlignedStore(value, ptr, alignment, is_volatile); llvm::StoreInst* store = builder_->CreateAlignedStore(value, ptr, alignment, is_volatile);
#endif
AddAliasInfo(store, op->buffer_var.get(), op->index, op->value.dtype()); AddAliasInfo(store, op->buffer_var.get(), op->index, op->value.dtype());
return; return;
} }
...@@ -1103,9 +1128,15 @@ void CodeGenLLVM::VisitStmt_(const StoreNode* op) { ...@@ -1103,9 +1128,15 @@ void CodeGenLLVM::VisitStmt_(const StoreNode* op) {
int basic_align = t.bits() / 8; int basic_align = t.bits() / 8;
auto f = [&](int i, llvm::Value* index) { auto f = [&](int i, llvm::Value* index) {
llvm::Value* ptr = CreateBufferPtr(t.element_of(), buffer, index); llvm::Value* ptr = CreateBufferPtr(t.element_of(), buffer, index);
#if TVM_LLVM_VERSION >= 110
llvm::StoreInst* store = builder_->CreateAlignedStore(
builder_->CreateExtractElement(value, i),
ptr, llvm::Align(basic_align), is_volatile);
#else
llvm::StoreInst* store = builder_->CreateAlignedStore( llvm::StoreInst* store = builder_->CreateAlignedStore(
builder_->CreateExtractElement(value, i), builder_->CreateExtractElement(value, i),
ptr, basic_align, is_volatile); ptr, basic_align, is_volatile);
#endif
AddAliasInfo(store, op->buffer_var.get(), PrimExpr(), op->value.dtype()); AddAliasInfo(store, op->buffer_var.get(), PrimExpr(), op->value.dtype());
}; };
this->Scalarize(op->index, f); this->Scalarize(op->index, f);
......
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