Skip to content

Commit

Permalink
Merge pull request #97 from frasercrmck/more-llvm17-fixes
Browse files Browse the repository at this point in the history
[compiler] Various fixes to compile (without warnings) with LLVM 17
  • Loading branch information
frasercrmck authored Aug 17, 2023
2 parents e77cf54 + c48b74a commit d1b467e
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -220,29 +220,26 @@ Function *RefSiG1BIMuxInfo::defineMuxBuiltin(compiler::utils::BuiltinID ID,
OverloadInfo);
}

Optional<unsigned> ParamIdx;
Optional<unsigned> WGFieldIdx;
unsigned ParamIdx = 1;
unsigned WGFieldIdx = ExecStateStruct::thread_id;

ParamIdx = 1;
WGFieldIdx = ExecStateStruct::thread_id;

assert(F && WGFieldIdx && ParamIdx);
assert(F);

auto SchedParams = getFunctionSchedulingParameters(*F);
assert(SchedParams.size() > *ParamIdx && "Missing scheduling parameters");
assert(SchedParams.size() > ParamIdx && "Missing scheduling parameters");

auto &Ctx = M.getContext();
auto *const uint_type = Type::getInt32Ty(Ctx);

auto *structTy = getExecStateStruct(M);
const auto &SchedParam = SchedParams[*ParamIdx];
const auto &SchedParam = SchedParams[ParamIdx];

auto *const ty = F->getReturnType();
IRBuilder<> ir(BasicBlock::Create(F->getContext(), "", F));

Value *rank = F->getArg(0);

SmallVector<Value *, 3> gep_indices{ir.getInt32(0), ir.getInt32(*WGFieldIdx)};
SmallVector<Value *, 3> gep_indices{ir.getInt32(0), ir.getInt32(WGFieldIdx)};
auto *const gep = ir.CreateGEP(structTy, SchedParam.ArgVal, gep_indices);

Value *thread_id = ir.CreateLoad(uint_type, gep);
Expand Down
2 changes: 1 addition & 1 deletion modules/compiler/source/base/source/program_metadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ ArgumentType llvmArgToArgumentType(const llvm::Argument *arg,
}

if (TyName == "spirv.Image") {
const auto type_name = metadata->getString();
[[maybe_unused]] const auto type_name = metadata->getString();
auto Dim =
TgtTy->getIntParameter(utils::tgtext::ImageTyDimensionalityIdx);
bool Arrayed = TgtTy->getIntParameter(utils::tgtext::ImageTyArrayedIdx) ==
Expand Down
3 changes: 3 additions & 0 deletions modules/compiler/source/base/source/target.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <compiler/utils/memory_buffer.h>
#include <llvm/Bitcode/BitcodeReader.h>
#include <llvm/IR/Module.h>
#include <multi_llvm/llvm_version.h>

#include "bakery.h"

Expand All @@ -31,7 +32,9 @@ BaseTarget::BaseTarget(const compiler::Info *compiler_info,
callback{callback} {}

Result BaseTarget::init(uint32_t builtins_capabilities) {
#if LLVM_VERSION_LESS(17, 0)
getLLVMContext().setOpaquePointers(true);
#endif
if (callback) {
auto diag_handler_callback_thunk = [](const llvm::DiagnosticInfo &DI,
void *user_data) {
Expand Down
5 changes: 3 additions & 2 deletions modules/compiler/spirv-ll/source/builder_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -919,12 +919,13 @@ cargo::optional<Error> Builder::create<OpConstantNull>(
if (llvm::cast<llvm::TargetExtType>(type)->getName() == "spirv.Event") {
constant = llvm::ConstantTargetNone::get(
llvm::cast<llvm::TargetExtType>(type));
break;
}
break;
[[fallthrough]];
#endif
default:
// TODO: the opencl types: device event, reservation ID and queue
llvm_unreachable("Unsupported type provided to OpConstantNull");
// TODO: the opencl types: event, device event, reservation ID and queue
}
constant->setName(module.getName(op->IdResult()));
module.addID(op->IdResult(), op, constant);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class StructTypeRemapper final : public llvm::ValueMapTypeRemapper {
return newStructType;
}
} else if (auto *ptrType = llvm::dyn_cast<llvm::PointerType>(srcType)) {
(void)ptrType;
#if LLVM_VERSION_LESS(17, 0)
// Nominally support opaque pointer remapping from LLVM 13 onwards.
if (ptrType->isOpaque()) {
Expand Down

0 comments on commit d1b467e

Please sign in to comment.