clangir
clangir copied to clipboard
Create a common interface/trait for CIR global values
In the original codegen, Clang has a parent class GlobalValue
that can handle different types of child classes homogeneously (e.g. global variables, functions, etc.)
https://github.com/llvm/clangir/blob/097abd2f5256c6c54646a2e479d0d60934a6a367/llvm/include/llvm/IR/GlobalValue.h#L44
We often run into cases where we need to perform unnecessary casts to distinguish between global variables and functions because, despite both being global values, they do not share a common interface. Some examples:
https://github.com/llvm/clangir/blob/097abd2f5256c6c54646a2e479d0d60934a6a367/clang/lib/CIR/CodeGen/CIRGenModule.cpp#L1673-L1679
https://github.com/llvm/clangir/blob/e22533dabbf8961e2e4d4cf23ca5f2d6d24bec6c/clang/lib/CIR/CodeGen/CIRGenModule.cpp#L2034-L2042
Ideally, the CIRGenModule::getGlobalValue
methods should return something akin to a CIRGlobalValueInterafce
that allows us to handle these globals transparently for actions common to any global value.