Skip to content

Commit

Permalink
Fix deprecation warnings for trunk LLVM (#5803)
Browse files Browse the repository at this point in the history
(1) Both the 'deprecated' and new, non-deprecated variants existed back to at least LLVM10, and the deprecated variant was commented as deprecated at that point as well; the change in LLVM13 is that they are now annotated with LLVM_ATTRIBUTE_DEPRECATED so we get compiler warnings (and thus errors).

(2) The fixes are simply replicating what the old, deprecated methods did internally.
  • Loading branch information
steven-johnson authored Mar 13, 2021
1 parent c3882a5 commit d523b83
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
6 changes: 3 additions & 3 deletions src/CodeGen_Internal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,20 +91,20 @@ void unpack_closure(const Closure &closure,
int idx = 0;
for (const auto &v : closure.vars) {
Value *ptr = builder->CreateConstInBoundsGEP2_32(type, src, 0, idx++);
LoadInst *load = builder->CreateLoad(ptr);
LoadInst *load = builder->CreateLoad(ptr->getType()->getPointerElementType(), ptr);
dst.push(v.first, load);
load->setName(v.first);
}
for (const auto &b : closure.buffers) {
{
Value *ptr = builder->CreateConstInBoundsGEP2_32(type, src, 0, idx++);
LoadInst *load = builder->CreateLoad(ptr);
LoadInst *load = builder->CreateLoad(ptr->getType()->getPointerElementType(), ptr);
dst.push(b.first, load);
load->setName(b.first);
}
{
Value *ptr = builder->CreateConstInBoundsGEP2_32(type, src, 0, idx++);
LoadInst *load = builder->CreateLoad(ptr);
LoadInst *load = builder->CreateLoad(ptr->getType()->getPointerElementType(), ptr);
dst.push(b.first + ".buffer", load);
load->setName(b.first + ".buffer");
}
Expand Down
20 changes: 10 additions & 10 deletions src/CodeGen_LLVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -905,14 +905,14 @@ llvm::Function *CodeGen_LLVM::add_argv_wrapper(llvm::Function *fn,
for (llvm::Function::arg_iterator i = fn->arg_begin(); i != fn->arg_end(); i++) {
// Get the address of the nth argument
llvm::Value *ptr = builder->CreateConstGEP1_32(arg_array, wrapper_args.size());
ptr = builder->CreateLoad(ptr);
ptr = builder->CreateLoad(ptr->getType()->getPointerElementType(), ptr);
if (i->getType() == halide_buffer_t_type->getPointerTo()) {
// Cast the argument to a halide_buffer_t *
wrapper_args.push_back(builder->CreatePointerCast(ptr, halide_buffer_t_type->getPointerTo()));
} else {
// Cast to the appropriate type and load
ptr = builder->CreatePointerCast(ptr, i->getType()->getPointerTo());
wrapper_args.push_back(builder->CreateLoad(ptr));
wrapper_args.push_back(builder->CreateLoad(ptr->getType()->getPointerElementType(), ptr));
}
}
debug(4) << "Creating call from wrapper to actual function\n";
Expand All @@ -923,7 +923,7 @@ llvm::Function *CodeGen_LLVM::add_argv_wrapper(llvm::Function *fn,
if (result_in_argv) {
llvm::Value *result_in_argv_ptr = builder->CreateConstGEP1_32(arg_array, wrapper_args.size());
if (fn->getReturnType() != void_t) {
result_in_argv_ptr = builder->CreateLoad(result_in_argv_ptr);
result_in_argv_ptr = builder->CreateLoad(result_in_argv_ptr->getType()->getPointerElementType(), result_in_argv_ptr);
// Cast to the appropriate type and store
result_in_argv_ptr = builder->CreatePointerCast(result_in_argv_ptr, fn->getReturnType()->getPointerTo());
builder->CreateStore(result, result_in_argv_ptr);
Expand Down Expand Up @@ -1901,7 +1901,7 @@ void CodeGen_LLVM::visit(const Load *op) {
if (op->type.is_scalar()) {
// Scalar loads
Value *ptr = codegen_buffer_pointer(op->name, op->type, op->index);
LoadInst *load = builder->CreateAlignedLoad(ptr, llvm::Align(op->type.bytes()));
LoadInst *load = builder->CreateAlignedLoad(ptr->getType()->getPointerElementType(), ptr, llvm::Align(op->type.bytes()));
add_tbaa_metadata(load, op->name, op->index);
value = load;
} else {
Expand Down Expand Up @@ -1996,7 +1996,7 @@ void CodeGen_LLVM::visit(const Load *op) {
value = UndefValue::get(llvm_type_of(op->type));
for (int i = 0; i < ramp->lanes; i++) {
Value *lane = ConstantInt::get(i32_t, i);
LoadInst *val = builder->CreateLoad(ptr);
LoadInst *val = builder->CreateLoad(ptr->getType()->getPointerElementType(), ptr);
add_tbaa_metadata(val, op->name, op->index);
value = builder->CreateInsertElement(value, val, lane);
ptr = builder->CreateInBoundsGEP(ptr, stride);
Expand All @@ -2011,7 +2011,7 @@ void CodeGen_LLVM::visit(const Load *op) {
for (int i = 0; i < op->type.lanes(); i++) {
Expr idx = extract_lane(op->index, i);
Value *ptr = codegen_buffer_pointer(op->name, op->type.element_of(), idx);
LoadInst *val = builder->CreateLoad(ptr);
LoadInst *val = builder->CreateLoad(ptr->getType()->getPointerElementType(), ptr);
add_tbaa_metadata(val, op->name, op->index);
vec = builder->CreateInsertElement(vec, val, ConstantInt::get(i32_t, i));
}
Expand All @@ -2023,7 +2023,7 @@ void CodeGen_LLVM::visit(const Load *op) {
for (int i = 0; i < op->type.lanes(); i++) {
Value *idx = builder->CreateExtractElement(index, ConstantInt::get(i32_t, i));
Value *ptr = codegen_buffer_pointer(op->name, op->type.element_of(), idx);
LoadInst *val = builder->CreateLoad(ptr);
LoadInst *val = builder->CreateLoad(ptr->getType()->getPointerElementType(), ptr);
add_tbaa_metadata(val, op->name, op->index);
vec = builder->CreateInsertElement(vec, val, ConstantInt::get(i32_t, i));
}
Expand Down Expand Up @@ -2315,7 +2315,7 @@ llvm::Value *CodeGen_LLVM::codegen_dense_vector_load(const Type &type, const std
load_inst = builder->CreateMaskedLoad(vec_ptr, align_bytes, slice_mask);
#endif
} else {
load_inst = builder->CreateAlignedLoad(vec_ptr, llvm::Align(align_bytes));
load_inst = builder->CreateAlignedLoad(vec_ptr->getType()->getPointerElementType(), vec_ptr, llvm::Align(align_bytes));
}
add_tbaa_metadata(load_inst, name, slice_index);
slices.push_back(load_inst);
Expand Down Expand Up @@ -2469,7 +2469,7 @@ void CodeGen_LLVM::codegen_atomic_store(const Store *op) {
Value *idx = builder->CreateExtractElement(vec_index, ConstantInt::get(i32_t, lane_id));
ptr = codegen_buffer_pointer(op->name, value_type.element_of(), idx);
}
LoadInst *orig = builder->CreateAlignedLoad(ptr, llvm::Align(value_type.bytes()));
LoadInst *orig = builder->CreateAlignedLoad(ptr->getType()->getPointerElementType(), ptr, llvm::Align(value_type.bytes()));
orig->setOrdering(AtomicOrdering::Monotonic);
add_tbaa_metadata(orig, op->name, op->index);
// Explicit fall through from the current block to the cas loop body.
Expand Down Expand Up @@ -3068,7 +3068,7 @@ void CodeGen_LLVM::visit(const Call *op) {
GlobalValue::PrivateLinkage,
ConstantPointerNull::get(base_fn->getType()),
global_name);
LoadInst *loaded_value = builder->CreateLoad(global);
LoadInst *loaded_value = builder->CreateLoad(global->getType()->getPointerElementType(), global);

BasicBlock *global_inited_bb = BasicBlock::Create(*context, "global_inited_bb", function);
BasicBlock *global_not_inited_bb = BasicBlock::Create(*context, "global_not_inited_bb", function);
Expand Down

0 comments on commit d523b83

Please sign in to comment.