Problem statement
There are a lot of frontends sitting on top of LLVM that have to
understand the ABI of their targets. They either independently develop
the code, partially copy it from Clang, try to follow the standards,
i.e, AAPCS and psABI, or try a mix of the options. IIRC, there were
even cases of inconsistencies between C-like compilers.
What are the subtle differences of AArch64 on Linux, Darwin, and
Windows and ARM64EC? Does ARM32 change the differences?
Does your toy language support bitfields?
Are you an expert for the differences between ARM and RISC-V scalable vectors?
Proposal
We could a new library to llvm/frontend, e.g., targetinfo with its own
type system. It already contains libraries for OpenMP and
OpenACC that are shared between Flang, Clang, and future MLIR-Clang.
class TargetInfo {
public:
virtual bool isCharSigned() = 0;
virtual size_t getSizeOf(Type *) = 0;
virtual size_t getAlignmentOf(Type *) = 0;
virtual bool isSupported(Type *) = 0;
// virtual XXX queryLockFreeAtomicCapabilities(...) = 0;
virtual CallWithLayoutAndCode getCall(FunctionType *signature, std::span<Type *> arguments) = 0;
};
extern llvm::Expected<std::unique_ptr<TargetInfo>>
getTargetInfo(llvm::Triple triple,
std::span<std::string> cpuFeatureFlags);
Odd options:
- -malign-double, -mno-align-double
- -m96bit-long-double, -m128bit-long-double
- …
Type System
TypeBuilder with builtins, pointers, enums, unions, bitfields, structs, functions, arrays, vectors, scalable vectors, …
It would be beneficial for at least MLIR-Clang, Flang, Rust, Swift, my
new toy language, and out-of-tree targets.
C API
For rust compiler, …
Recent PRs
Wrong cast of u16 to usize on aarch64
Initial support of lowering derived type passed by value
Make 128 bit integers be aligned to 8 bytes.
Add comdat
to globals when translating to LLVM IR on Windows