Skip to content

Commit

Permalink
Fix for top-of-tree LLVM (#8442)
Browse files Browse the repository at this point in the history
* Fix for top-of-tree LLVM

* format

* fixes

* Update CodeGen_Hexagon.cpp

* Update CodeGen_LLVM.cpp

* Update LLVM_Runtime_Linker.cpp
  • Loading branch information
steven-johnson authored Oct 19, 2024
1 parent 7ceddb4 commit 87e7d4c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/CodeGen_Hexagon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,11 @@ void CodeGen_Hexagon::init_module() {
llvm::Intrinsic::ID id = i.id;
internal_assert(id != llvm::Intrinsic::not_intrinsic);
// Get the real intrinsic.
#if LLVM_VERSION >= 200
llvm::Function *intrin = llvm::Intrinsic::getOrInsertDeclaration(module.get(), id);
#else
llvm::Function *intrin = llvm::Intrinsic::getDeclaration(module.get(), id);
#endif
halide_type_t ret_type = fix_lanes(i.ret_type);
arg_types.clear();
for (const auto &a : i.arg_types) {
Expand Down Expand Up @@ -1015,8 +1019,11 @@ Value *CodeGen_Hexagon::call_intrin_cast(llvm::Type *ret_ty, llvm::Function *F,

Value *CodeGen_Hexagon::call_intrin_cast(llvm::Type *ret_ty, int id,
vector<Value *> Ops) {
llvm::Function *intrin =
llvm::Intrinsic::getDeclaration(module.get(), (llvm::Intrinsic::ID)id);
#if LLVM_VERSION >= 200
llvm::Function *intrin = llvm::Intrinsic::getOrInsertDeclaration(module.get(), (llvm::Intrinsic::ID)id);
#else
llvm::Function *intrin = llvm::Intrinsic::getDeclaration(module.get(), (llvm::Intrinsic::ID)id);
#endif
return call_intrin_cast(ret_ty, intrin, std::move(Ops));
}

Expand Down Expand Up @@ -1182,9 +1189,11 @@ Value *CodeGen_Hexagon::shuffle_vectors(Value *a, Value *b,
if (max < a_elements) {
BitCastInst *a_cast = dyn_cast<BitCastInst>(a);
CallInst *a_call = dyn_cast<CallInst>(a_cast ? a_cast->getOperand(0) : a);
llvm::Function *vcombine = llvm::Intrinsic::getDeclaration(
module.get(),
INTRINSIC_128B(vcombine));
#if LLVM_VERSION >= 200
llvm::Function *vcombine = llvm::Intrinsic::getOrInsertDeclaration(module.get(), INTRINSIC_128B(vcombine));
#else
llvm::Function *vcombine = llvm::Intrinsic::getDeclaration(module.get(), INTRINSIC_128B(vcombine));
#endif
if (a_call && a_call->getCalledFunction() == vcombine) {
// Rewrite shuffle(vcombine(a, b), x) to shuffle(a, b)
return shuffle_vectors(
Expand Down
10 changes: 10 additions & 0 deletions src/CodeGen_LLVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2778,7 +2778,11 @@ void CodeGen_LLVM::visit(const Call *op) {
internal_assert(op->args.size() == 1);
std::vector<llvm::Type *> arg_type(1);
arg_type[0] = llvm_type_of(op->args[0].type());
#if LLVM_VERSION >= 200
llvm::Function *fn = llvm::Intrinsic::getOrInsertDeclaration(module.get(), llvm::Intrinsic::ctpop, arg_type);
#else
llvm::Function *fn = llvm::Intrinsic::getDeclaration(module.get(), llvm::Intrinsic::ctpop, arg_type);
#endif
Value *a = codegen(op->args[0]);
CallInst *call = builder->CreateCall(fn, a);
value = call;
Expand All @@ -2787,9 +2791,15 @@ void CodeGen_LLVM::visit(const Call *op) {
internal_assert(op->args.size() == 1);
std::vector<llvm::Type *> arg_type(1);
arg_type[0] = llvm_type_of(op->args[0].type());
#if LLVM_VERSION >= 200
llvm::Function *fn = llvm::Intrinsic::getOrInsertDeclaration(module.get(),
(op->is_intrinsic(Call::count_leading_zeros)) ? llvm::Intrinsic::ctlz : llvm::Intrinsic::cttz,
arg_type);
#else
llvm::Function *fn = llvm::Intrinsic::getDeclaration(module.get(),
(op->is_intrinsic(Call::count_leading_zeros)) ? llvm::Intrinsic::ctlz : llvm::Intrinsic::cttz,
arg_type);
#endif
llvm::Value *is_const_zero_poison = llvm::ConstantInt::getFalse(*context);
llvm::Value *args[2] = {codegen(op->args[0]), is_const_zero_poison};
CallInst *call = builder->CreateCall(fn, args);
Expand Down
4 changes: 4 additions & 0 deletions src/LLVM_Runtime_Linker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,11 @@ llvm::DataLayout get_data_layout_for_target(Target target) {
} else if (target.os == Target::Windows) {
return llvm::DataLayout("e-m:w-p:64:64-i32:32-i64:64-i128:128-n32:64-S128-Fn32");
} else {
#if LLVM_VERSION >= 200
return llvm::DataLayout("e-m:e-p270:32:32-p271:32:32-p272:64:64-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32");
#else
return llvm::DataLayout("e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32");
#endif
}
#else
if (target.os == Target::IOS) {
Expand Down

0 comments on commit 87e7d4c

Please sign in to comment.