-
Notifications
You must be signed in to change notification settings - Fork 183
Description
We currently define the CIR dialect under the mlir::cir namespace, which is a historical leftover from when CIR lived under MLIR instead of Clang (at the very start of the project). We also have a separate cir namespace to hold e.g. our lowering patterns. This is unfortunate, because in many source files you have
using namespace cir;
using namespace mlir;
using namespace mlir::cir;
And then cir:: becomes ambiguous between ::cir and mlir::cir, leading to various errors. You can leave off the using namespace, but typing out mlir::cir::FooOp everywhere is annoying and adds a bunch of noise IMO.
I'm proposing that we merge mlir::cir into cir instead. This matches Flang, which uses the fir namespace for its IR (and the hlfir namespace for its higher-level IR). It's also an easy change to perform mechanically, and cir:: is a small enough prefix that I'm happy to go either way on the using namespace afterwards. (Flang does a mix, but it seems to prefer spelling out fir:: explicitly.)
A small complication is that some names are common between the cir and mlir::cir namespaces, namely ABIInfo, RequiredArgs, and ReturnValueSlot. This is kinda surprising to me, and it seems like a good opportunity to disambiguate them instead of anything that should block the namespace merge.
As a follow-up, these symbols that live in cir have their corresponding symbols live under clang::CodeGen: https://gist.github.com/smeenai/8438fd01588109fcdbde5c8652781dc0. We should also probably move them to a corresponding namespace (e.g. clang::CIRGen) to match the original CodeGen better. That'll be less mechanical though, so I want it to be a separate step from the mlir::cir merging.
Some references, based on a rudimentary analysis of the demangled symbols from a CIR-enabled clang and flang-new:
- Top-level symbols under the
cirnamespace: https://gist.github.com/smeenai/e6751324254716b673de84cf2533038f - Top-level symbols under the
mlir::cirnamespace: https://gist.github.com/smeenai/0a0cf966cb86c9410d9ea98d94d6a7fe - Top-level symbols under the
firnamespace: https://gist.github.com/smeenai/100e4780e48e3966c87c8fd9621a71b4 - Top-level symbols under the
clang::CodeGennamespace: https://gist.github.com/smeenai/781d6cd37a95ca7b7f73fa1a3b6774aa
CCing some people who might have opinions on this: @bcardosolopes, @lanza, @dkolsen-pgi, @keryell, @Lancern