Skip to content

[CIR][CIRGen] Move CIRGen types into clang::CIRGen #1082

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 8, 2024

Conversation

smeenai
Copy link
Collaborator

@smeenai smeenai commented Nov 7, 2024

#1025 explains why we want to move
the CIR dialect from the mlir::cir to the cir namespace. To avoid
overloading the cir namespace too much afterwards, move all symbols
whose equivalents live inside the clang::CodeGen namespace to a new
clang::CIRGen namespace, so that we match the original CodeGen's
structure more closely.

There's some symbols that live under clang/include/clang/CIR whose
equivalents live in clang/lib/CodeGen and are in the clang::CodeGen
namespace. We have these symbols in a common location since they're also
used by lowering, so I've also left them in the cir namespace. Those
symbols are:

  • AArch64ABIKind
  • ABIArgInfo
  • FnInfoOpts
  • TypeEvaluationKind
  • X86AVXABILevel

This is a pretty large PR out of necessity. To make it slightly more
reviewable, I've split it out into three commits (which will be squashed
together when the PR lands):

  • The first commit manually switches places to the clang::CIRGen
    namespace. This has to be manual because we only want to move things
    selectively.
  • The second commit adjusts namespace prefixes to make builds work. I
    ran https://gist.github.com/smeenai/f4dd441fb61c53e835c4e6057f8c322f
    to make this change. The script is idempotent, and I added
    substitutions one at a time and reviewed each one afterwards (using
    git diff --color-words=.) to ensure only intended changes were being
    made.
  • The third commit runs git clang-format.

Because I went one-by-one with all my substitutions and checked each one
afterwards, I'm pretty confident in the validity of all the changes
(despite the size of the PR).

@lanza
Copy link
Member

lanza commented Nov 7, 2024

I scanned it. Makes sense to me tho we might miss something. If it passes tests I think it's reasonable.

@smeenai
Copy link
Collaborator Author

smeenai commented Nov 8, 2024

I'll wait for the upstream changes to get approved and then land this.

@smeenai smeenai force-pushed the users/smeenai/cirgen-namespace branch from c9c46ca to f2ec5f2 Compare November 8, 2024 18:45
@smeenai smeenai merged commit 3f66d51 into main Nov 8, 2024
6 checks passed
@smeenai smeenai deleted the users/smeenai/cirgen-namespace branch November 8, 2024 18:46
smeenai added a commit that referenced this pull request Nov 8, 2024
#1025 explains why we want to move
the CIR dialect from the `mlir::cir` to the `cir` namespace.

This is a large PR, and I've split it out into four commits (that'll be
squashed when landing). The first commit changes `mlir::cir` to `cir`
everywhere. This was originally done mechanically with:

```
find clang \( -name '*.h' -o -name '*.cpp' -o -name '*.td' \) -print0 | xargs -0 perl -pi -e 's/mlir::cir/cir/g'
find clang \( -name '*.h' -o -name '*.cpp' \) -print0 | xargs -0 perl -pi -e 's/::cir/cir/g'
find clang \( -name '*.h' -o -name '*.cpp' \) -print0 | xargs -0 perl -0777 -pi -e 's/namespace mlir \{\nnamespace cir \{/namespace cir {/g'
find clang \( -name '*.h' -o -name '*.cpp' \) -print0 | xargs -0 perl -0777 -pi -e 's!\} // namespace cir\n\} // namespace mlir!} // namespace cir!g'
```

It then required some manual fixups to address edge cases.

Code that lived under `mlir::cir` could refer to the `mlir` namespace
without qualification, but after the namespace change, we need to
explicitly qualify all our usages. This is done in the second commit via
https://gist.github.com/smeenai/996200fd45ad123bbf22b412d59479b6, which
is an idempotent script to add all qualifications. I added cases to the
script one at a time and reviewed each change afterwards to ensure we
were only making the intended modifications, so I feel pretty confident
in the end result. I also removed `using namespace llvm` from some
headers to avoid conflicts, which in turn required adding some `llvm::`
qualifiers as well.

The third commit fixes a test, since an error message now contains the
mlir namespace. Similar tests in flang also have the namespace in their
error messages, so this is an expected change.

The fourth change runs `git clang-format`. Unfortunately, that doesn't
work for TableGen files, so we'll have a few instances of undesirable
formatting left there. I'll look into fixing that as a follow-up.

I validated the end result by examining the symbols in the built Clang
binary. There's nothing in the `mlir::cir` namespace anymore.
https://gist.github.com/smeenai/8438fd01588109fcdbde5c8652781dc0 had the
symbols which lived in `cir` and should have moved to `clang::CIRGen`,
and I validated that all the symbols were moved, with the exceptions
noted in #1082 and the duplicated
symbols noted in #1025.
lanza pushed a commit that referenced this pull request Mar 18, 2025
#1025 explains why we want to move
the CIR dialect from the `mlir::cir` to the `cir` namespace. To avoid
overloading the `cir` namespace too much afterwards, move all symbols
whose equivalents live inside the `clang::CodeGen` namespace to a new
`clang::CIRGen` namespace, so that we match the original CodeGen's
structure more closely.

There's some symbols that live under `clang/include/clang/CIR` whose
equivalents live in `clang/lib/CodeGen` and are in the `clang::CodeGen`
namespace. We have these symbols in a common location since they're also
used by lowering, so I've also left them in the `cir` namespace. Those
symbols are:
- AArch64ABIKind
- ABIArgInfo
- FnInfoOpts
- TypeEvaluationKind
- X86AVXABILevel

This is a pretty large PR out of necessity. To make it slightly more
reviewable, I've split it out into three commits (which will be squashed
together when the PR lands):
- The first commit manually switches places to the `clang::CIRGen`
  namespace. This has to be manual because we only want to move things
  selectively.
- The second commit adjusts namespace prefixes to make builds work. I
  ran https://gist.github.com/smeenai/f4dd441fb61c53e835c4e6057f8c322f
  to make this change. The script is idempotent, and I added
  substitutions one at a time and reviewed each one afterwards (using
  `git diff --color-words=.`) to ensure only intended changes were being
  made.
- The third commit runs `git clang-format`.

Because I went one-by-one with all my substitutions and checked each one
afterwards, I'm pretty confident in the validity of all the changes
(despite the size of the PR).
lanza pushed a commit that referenced this pull request Mar 18, 2025
#1025 explains why we want to move
the CIR dialect from the `mlir::cir` to the `cir` namespace.

This is a large PR, and I've split it out into four commits (that'll be
squashed when landing). The first commit changes `mlir::cir` to `cir`
everywhere. This was originally done mechanically with:

```
find clang \( -name '*.h' -o -name '*.cpp' -o -name '*.td' \) -print0 | xargs -0 perl -pi -e 's/mlir::cir/cir/g'
find clang \( -name '*.h' -o -name '*.cpp' \) -print0 | xargs -0 perl -pi -e 's/::cir/cir/g'
find clang \( -name '*.h' -o -name '*.cpp' \) -print0 | xargs -0 perl -0777 -pi -e 's/namespace mlir \{\nnamespace cir \{/namespace cir {/g'
find clang \( -name '*.h' -o -name '*.cpp' \) -print0 | xargs -0 perl -0777 -pi -e 's!\} // namespace cir\n\} // namespace mlir!} // namespace cir!g'
```

It then required some manual fixups to address edge cases.

Code that lived under `mlir::cir` could refer to the `mlir` namespace
without qualification, but after the namespace change, we need to
explicitly qualify all our usages. This is done in the second commit via
https://gist.github.com/smeenai/996200fd45ad123bbf22b412d59479b6, which
is an idempotent script to add all qualifications. I added cases to the
script one at a time and reviewed each change afterwards to ensure we
were only making the intended modifications, so I feel pretty confident
in the end result. I also removed `using namespace llvm` from some
headers to avoid conflicts, which in turn required adding some `llvm::`
qualifiers as well.

The third commit fixes a test, since an error message now contains the
mlir namespace. Similar tests in flang also have the namespace in their
error messages, so this is an expected change.

The fourth change runs `git clang-format`. Unfortunately, that doesn't
work for TableGen files, so we'll have a few instances of undesirable
formatting left there. I'll look into fixing that as a follow-up.

I validated the end result by examining the symbols in the built Clang
binary. There's nothing in the `mlir::cir` namespace anymore.
https://gist.github.com/smeenai/8438fd01588109fcdbde5c8652781dc0 had the
symbols which lived in `cir` and should have moved to `clang::CIRGen`,
and I validated that all the symbols were moved, with the exceptions
noted in #1082 and the duplicated
symbols noted in #1025.
xlauko pushed a commit to trailofbits/instafix-llvm that referenced this pull request Mar 28, 2025
llvm/clangir#1025 explains why we want to move
the CIR dialect from the `mlir::cir` to the `cir` namespace.

This is a large PR, and I've split it out into four commits (that'll be
squashed when landing). The first commit changes `mlir::cir` to `cir`
everywhere. This was originally done mechanically with:

```
find clang \( -name '*.h' -o -name '*.cpp' -o -name '*.td' \) -print0 | xargs -0 perl -pi -e 's/mlir::cir/cir/g'
find clang \( -name '*.h' -o -name '*.cpp' \) -print0 | xargs -0 perl -pi -e 's/::cir/cir/g'
find clang \( -name '*.h' -o -name '*.cpp' \) -print0 | xargs -0 perl -0777 -pi -e 's/namespace mlir \{\nnamespace cir \{/namespace cir {/g'
find clang \( -name '*.h' -o -name '*.cpp' \) -print0 | xargs -0 perl -0777 -pi -e 's!\} // namespace cir\n\} // namespace mlir!} // namespace cir!g'
```

It then required some manual fixups to address edge cases.

Code that lived under `mlir::cir` could refer to the `mlir` namespace
without qualification, but after the namespace change, we need to
explicitly qualify all our usages. This is done in the second commit via
https://gist.github.com/smeenai/996200fd45ad123bbf22b412d59479b6, which
is an idempotent script to add all qualifications. I added cases to the
script one at a time and reviewed each change afterwards to ensure we
were only making the intended modifications, so I feel pretty confident
in the end result. I also removed `using namespace llvm` from some
headers to avoid conflicts, which in turn required adding some `llvm::`
qualifiers as well.

The third commit fixes a test, since an error message now contains the
mlir namespace. Similar tests in flang also have the namespace in their
error messages, so this is an expected change.

The fourth change runs `git clang-format`. Unfortunately, that doesn't
work for TableGen files, so we'll have a few instances of undesirable
formatting left there. I'll look into fixing that as a follow-up.

I validated the end result by examining the symbols in the built Clang
binary. There's nothing in the `mlir::cir` namespace anymore.
https://gist.github.com/smeenai/8438fd01588109fcdbde5c8652781dc0 had the
symbols which lived in `cir` and should have moved to `clang::CIRGen`,
and I validated that all the symbols were moved, with the exceptions
noted in llvm/clangir#1082 and the duplicated
symbols noted in llvm/clangir#1025.
lanza pushed a commit to lanza/llvm-project that referenced this pull request Aug 9, 2025
llvm/clangir#1025 explains why we want to move
the CIR dialect from the `mlir::cir` to the `cir` namespace.

This is a large PR, and I've split it out into four commits (that'll be
squashed when landing). The first commit changes `mlir::cir` to `cir`
everywhere. This was originally done mechanically with:

```
find clang \( -name '*.h' -o -name '*.cpp' -o -name '*.td' \) -print0 | xargs -0 perl -pi -e 's/mlir::cir/cir/g'
find clang \( -name '*.h' -o -name '*.cpp' \) -print0 | xargs -0 perl -pi -e 's/::cir/cir/g'
find clang \( -name '*.h' -o -name '*.cpp' \) -print0 | xargs -0 perl -0777 -pi -e 's/namespace mlir \{\nnamespace cir \{/namespace cir {/g'
find clang \( -name '*.h' -o -name '*.cpp' \) -print0 | xargs -0 perl -0777 -pi -e 's!\} // namespace cir\n\} // namespace mlir!} // namespace cir!g'
```

It then required some manual fixups to address edge cases.

Code that lived under `mlir::cir` could refer to the `mlir` namespace
without qualification, but after the namespace change, we need to
explicitly qualify all our usages. This is done in the second commit via
https://gist.github.com/smeenai/996200fd45ad123bbf22b412d59479b6, which
is an idempotent script to add all qualifications. I added cases to the
script one at a time and reviewed each change afterwards to ensure we
were only making the intended modifications, so I feel pretty confident
in the end result. I also removed `using namespace llvm` from some
headers to avoid conflicts, which in turn required adding some `llvm::`
qualifiers as well.

The third commit fixes a test, since an error message now contains the
mlir namespace. Similar tests in flang also have the namespace in their
error messages, so this is an expected change.

The fourth change runs `git clang-format`. Unfortunately, that doesn't
work for TableGen files, so we'll have a few instances of undesirable
formatting left there. I'll look into fixing that as a follow-up.

I validated the end result by examining the symbols in the built Clang
binary. There's nothing in the `mlir::cir` namespace anymore.
https://gist.github.com/smeenai/8438fd01588109fcdbde5c8652781dc0 had the
symbols which lived in `cir` and should have moved to `clang::CIRGen`,
and I validated that all the symbols were moved, with the exceptions
noted in llvm/clangir#1082 and the duplicated
symbols noted in llvm/clangir#1025.
lanza pushed a commit to lanza/llvm-project that referenced this pull request Aug 11, 2025
llvm/clangir#1025 explains why we want to move
the CIR dialect from the `mlir::cir` to the `cir` namespace.

This is a large PR, and I've split it out into four commits (that'll be
squashed when landing). The first commit changes `mlir::cir` to `cir`
everywhere. This was originally done mechanically with:

```
find clang \( -name '*.h' -o -name '*.cpp' -o -name '*.td' \) -print0 | xargs -0 perl -pi -e 's/mlir::cir/cir/g'
find clang \( -name '*.h' -o -name '*.cpp' \) -print0 | xargs -0 perl -pi -e 's/::cir/cir/g'
find clang \( -name '*.h' -o -name '*.cpp' \) -print0 | xargs -0 perl -0777 -pi -e 's/namespace mlir \{\nnamespace cir \{/namespace cir {/g'
find clang \( -name '*.h' -o -name '*.cpp' \) -print0 | xargs -0 perl -0777 -pi -e 's!\} // namespace cir\n\} // namespace mlir!} // namespace cir!g'
```

It then required some manual fixups to address edge cases.

Code that lived under `mlir::cir` could refer to the `mlir` namespace
without qualification, but after the namespace change, we need to
explicitly qualify all our usages. This is done in the second commit via
https://gist.github.com/smeenai/996200fd45ad123bbf22b412d59479b6, which
is an idempotent script to add all qualifications. I added cases to the
script one at a time and reviewed each change afterwards to ensure we
were only making the intended modifications, so I feel pretty confident
in the end result. I also removed `using namespace llvm` from some
headers to avoid conflicts, which in turn required adding some `llvm::`
qualifiers as well.

The third commit fixes a test, since an error message now contains the
mlir namespace. Similar tests in flang also have the namespace in their
error messages, so this is an expected change.

The fourth change runs `git clang-format`. Unfortunately, that doesn't
work for TableGen files, so we'll have a few instances of undesirable
formatting left there. I'll look into fixing that as a follow-up.

I validated the end result by examining the symbols in the built Clang
binary. There's nothing in the `mlir::cir` namespace anymore.
https://gist.github.com/smeenai/8438fd01588109fcdbde5c8652781dc0 had the
symbols which lived in `cir` and should have moved to `clang::CIRGen`,
and I validated that all the symbols were moved, with the exceptions
noted in llvm/clangir#1082 and the duplicated
symbols noted in llvm/clangir#1025.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants