Skip to content

Commit

Permalink
Merge pull request #208 from frasercrmck/spirv-ll-rename-methods
Browse files Browse the repository at this point in the history
[spirv-ll] Rename a couple of getter methods for clarity
  • Loading branch information
frasercrmck authored Nov 14, 2023
2 parents eef1eb2 + 38482e6 commit 227ee3b
Show file tree
Hide file tree
Showing 7 changed files with 203 additions and 200 deletions.
4 changes: 2 additions & 2 deletions modules/compiler/spirv-ll/include/spirv-ll/module.h
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ class Module : public ModuleHeader {
/// @param[in] id The SPIR-V ID to fetch the value for.
///
/// @return A pointer to the Type or nullptr if not found.
llvm::Type *getType(spv::Id id) const;
llvm::Type *getLLVMType(spv::Id id) const;

/// @brief Get the `OpType` from the result type of an `OpCode`.
///
Expand Down Expand Up @@ -864,7 +864,7 @@ class Module : public ModuleHeader {
///
/// @return A pointer to the Op or nullptr if not found.
template <class Op = OpCode>
const Op *get(llvm::Type *ty) const {
const Op *getFromLLVMTy(llvm::Type *ty) const {
assert(!ty->isPointerTy() && "can't get the type of a pointer");
auto found = std::find_if(
Types.begin(), Types.end(),
Expand Down
23 changes: 12 additions & 11 deletions modules/compiler/spirv-ll/source/builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,10 @@ llvm::DIType *spirv_ll::Builder::getDIType(llvm::Type *type) {
name = "dbg_float_ty";
break;
case llvm::Type::PointerTyID: {
auto *opTy = module.get<OpType>(type);
auto *opTy = module.getFromLLVMTy<OpType>(type);
SPIRV_LL_ASSERT(opTy && opTy->isPointerType(), "Type is not a pointer");
llvm::DIType *elem_type =
getDIType(module.getType(opTy->getTypePointer()->Type()));
getDIType(module.getLLVMType(opTy->getTypePointer()->Type()));
return DIBuilder.createPointerType(elem_type, size, align);
}
default:
Expand Down Expand Up @@ -663,7 +663,8 @@ llvm::CallInst *spirv_ll::Builder::createImageAccessBuiltinCall(
llvm::ArrayRef<llvm::Value *> args,
llvm::ArrayRef<MangleInfo> argMangleInfo,
const spirv_ll::OpTypeVector *pixelTypeOp) {
llvm::Type *pixelElementType = module.getType(pixelTypeOp->ComponentType());
llvm::Type *pixelElementType =
module.getLLVMType(pixelTypeOp->ComponentType());
if (pixelElementType->isIntegerTy()) {
// We need to look up the int type by ID because searching by `llvm::Type`
// doesn't distinguish between signed and unsigned types, which can cause
Expand Down Expand Up @@ -700,7 +701,7 @@ llvm::CallInst *spirv_ll::Builder::createImageAccessBuiltinCall(
llvm::Value *spirv_ll::Builder::createOCLBuiltinCall(
OpenCLLIB::Entrypoints opcode, spv::Id resTyId,
llvm::ArrayRef<spv::Id> args) {
llvm::Type *resultType = module.getType(resTyId);
llvm::Type *resultType = module.getLLVMType(resTyId);
SPIRV_LL_ASSERT_PTR(resultType);

llvm::SmallVector<llvm::Value *, 4> argVals;
Expand Down Expand Up @@ -1099,7 +1100,7 @@ std::string spirv_ll::Builder::getMangledFunctionName(
llvm::Type *pointeeTy = nullptr;
auto *const spvPtrTy = module.get<OpType>(mangleInfo->id);
if (spvPtrTy->isPointerType()) {
pointeeTy = module.getType(spvPtrTy->getTypePointer()->Type());
pointeeTy = module.getLLVMType(spvPtrTy->getTypePointer()->Type());
#if LLVM_VERSION_LESS(17, 0)
} else if (spvPtrTy->isImageType() || spvPtrTy->isEventType() ||
spvPtrTy->isSamplerType()) {
Expand Down Expand Up @@ -1230,7 +1231,7 @@ std::string spirv_ll::Builder::getMangledTypeName(

auto const spvPointeeTy =
module.get<OpType>(mangleInfo->id)->getTypePointer()->Type();
auto *const elementTy = module.getType(spvPointeeTy);
auto *const elementTy = module.getLLVMType(spvPointeeTy);
std::string mangled = getMangledPointerPrefix(ty, mangleInfo->typeQuals);
auto pointeeMangleInfo = *mangleInfo;
pointeeMangleInfo.typeQuals = 0;
Expand Down Expand Up @@ -1318,9 +1319,9 @@ void spirv_ll::Builder::checkMemberDecorations(
nextType = multi_llvm::getVectorElementType(traversed.back());
break;
case llvm::Type::PointerTyID: {
auto *opTy = module.get<OpType>(traversed.back());
auto *opTy = module.getFromLLVMTy<OpType>(traversed.back());
SPIRV_LL_ASSERT(opTy && opTy->isPointerType(), "Type is not a pointer");
nextType = module.getType(opTy->getTypePointer()->Type());
nextType = module.getLLVMType(opTy->getTypePointer()->Type());
break;
}
default:
Expand Down Expand Up @@ -1364,7 +1365,7 @@ void spirv_ll::Builder::checkMemberDecorations(
// according to the spec, so this cast is safe.
uint32_t member =
cast<llvm::ConstantInt>(indexes[memberIndex])->getZExtValue();
auto structType = module.get<OpTypeStruct>(accessedStructType);
auto structType = module.getFromLLVMTy<OpTypeStruct>(accessedStructType);
const auto &memberDecorations =
module.getMemberDecorations(structType->IdResult(), member);
for (auto *opMemberDecorate : memberDecorations) {
Expand Down Expand Up @@ -1404,7 +1405,7 @@ void spirv_ll::Builder::generateSpecConstantOps() {

switch (op->Opcode()) {
case spv::OpFMod: {
llvm::Type *type = module.getType(op->IdResultType());
llvm::Type *type = module.getLLVMType(op->IdResultType());
SPIRV_LL_ASSERT_PTR(type);

llvm::Value *lhs = module.getValue(op->getValueAtOffset(firstArgIndex));
Expand All @@ -1426,7 +1427,7 @@ void spirv_ll::Builder::generateSpecConstantOps() {
{modResult, rhs}, {});
} break;
case spv::OpFRem: {
llvm::Type *type = module.getType(op->IdResultType());
llvm::Type *type = module.getLLVMType(op->IdResultType());
SPIRV_LL_ASSERT_PTR(type);

llvm::Value *lhs = module.getValue(op->getValueAtOffset(firstArgIndex));
Expand Down
Loading

0 comments on commit 227ee3b

Please sign in to comment.