Skip to content

[Proposal] Merge mlir::cir namespace into cir #1025

@smeenai

Description

@smeenai

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:

CCing some people who might have opinions on this: @bcardosolopes, @lanza, @dkolsen-pgi, @keryell, @Lancern

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions