Skip to content

Design representation for OpenCL builtin types and other types lowered to llvm::TargetExtType #802

@seven-mile

Description

@seven-mile

In the original SPIR-V CodeGen, llvm::TargetExtType is employed for OpenCL built-in types like pipe and image, which encapsulate certain type-specific parameters. This design choice is discussed in the RFC Adding opaque types to LLVM IR.

Opaque types are a new kind of fundamental LLVM type. The C++ API for this type, at least as far as type creation looks, would be as follows:

class OpaqueType : public Type {
public:
  static void get(LLVMContext &Ctx, StringRef Name);
  static void get(LLVMContext &Ctx, StringRef Name,
                  ArrayRef<Type *> Types, ArrayRef<unsigned> Parameters);
};

In LLVM IR terms, this would be written as:

opaque(“spirv.Image”, void, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0)
opaque(“spirv.Queue”)

The use of TargetExtType, or the previously known OpaqueType, is quite limited within LLVM until now, primarily involving OpenCL/SPIR-V and Arm's scalable vector extension. It's important to consider the appropriate level of abstraction for these types collectively, as the LLVM community has done.

From LLVM's standpoint, the goal is to maintain a clean type system. These target-specific types function similarly to pointers or unique handles, with the main purpose being to distinguish them from standard types like word-sized integers. This perspective is also relevant for ClangIR. However, we should proceed with caution when introducing an LLVM equivalent in ClangIR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    IR designConsiderations around the design of ClangIRenhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions