Skip to content

Commit 9f79374

Browse files
authored
[CIR] Separate CIR EnumAttr definitions to be includable without the rest of attributes (#148850)
This change allows enum definition classes to be included in type definitions without creating cyclic dependencies between CIRTypes.td and CIRAttrs.td, since attributes already include CIRTypes.td. In the pull request mentioned below, this is used to define the AddressSpace enum alongside PointerType. Additionally, this introduces `DefaultValuedEnumParameter`. This mirrors some parts of incubator change from llvm/clangir#1733
1 parent 67aee6b commit 9f79374

File tree

2 files changed

+40
-17
lines changed

2 files changed

+40
-17
lines changed

clang/include/clang/CIR/Dialect/IR/CIRAttrs.td

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
#define CLANG_CIR_DIALECT_IR_CIRATTRS_TD
1515

1616
include "mlir/IR/BuiltinAttributeInterfaces.td"
17-
include "mlir/IR/EnumAttr.td"
1817

19-
include "clang/CIR/Dialect/IR/CIRDialect.td"
2018
include "clang/CIR/Dialect/IR/CIRAttrConstraints.td"
19+
include "clang/CIR/Dialect/IR/CIRDialect.td"
20+
include "clang/CIR/Dialect/IR/CIREnumAttr.td"
2121

2222
//===----------------------------------------------------------------------===//
2323
// CIR Attrs
@@ -42,21 +42,6 @@ class CIR_TypedAttr<string name, string attrMnemonic, list<Trait> traits = []>
4242
let assemblyFormat = [{}];
4343
}
4444

45-
class CIR_I32EnumAttr<string name, string summary, list<I32EnumAttrCase> cases>
46-
: I32EnumAttr<name, summary, cases> {
47-
let cppNamespace = "::cir";
48-
}
49-
50-
class CIR_I64EnumAttr<string name, string summary, list<I64EnumAttrCase> cases>
51-
: I64EnumAttr<name, summary, cases> {
52-
let cppNamespace = "::cir";
53-
}
54-
55-
class CIR_EnumAttr<EnumAttrInfo info, string name = "", list<Trait> traits = []>
56-
: EnumAttr<CIR_Dialect, info, name, traits> {
57-
let assemblyFormat = "`<` $value `>`";
58-
}
59-
6045
class CIRUnitAttr<string name, string attrMnemonic, list<Trait> traits = []>
6146
: CIR_Attr<name, attrMnemonic, traits> {
6247
let returnType = "bool";
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
// This file defines the CIR dialect enum base classes
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef CLANG_CIR_DIALECT_IR_CIRENUMATTR_TD
14+
#define CLANG_CIR_DIALECT_IR_CIRENUMATTR_TD
15+
16+
include "mlir/IR/EnumAttr.td"
17+
18+
class CIR_I32EnumAttr<string name, string summary, list<I32EnumAttrCase> cases>
19+
: I32EnumAttr<name, summary, cases> {
20+
let cppNamespace = "::cir";
21+
}
22+
23+
class CIR_I64EnumAttr<string name, string summary, list<I64EnumAttrCase> cases>
24+
: I64EnumAttr<name, summary, cases> {
25+
let cppNamespace = "::cir";
26+
}
27+
28+
class CIR_EnumAttr<EnumAttrInfo info, string name = "", list<Trait> traits = []>
29+
: EnumAttr<CIR_Dialect, info, name, traits> {
30+
let assemblyFormat = "`<` $value `>`";
31+
}
32+
33+
class CIR_DefaultValuedEnumParameter<EnumAttrInfo info, string value = "">
34+
: EnumParameter<info> {
35+
let defaultValue = value;
36+
}
37+
38+
#endif // CLANG_CIR_DIALECT_IR_CIRENUMATTR_TD

0 commit comments

Comments
 (0)