Skip to content

Commit cb1d401

Browse files
committed
Add constraints for Attr parameters
1 parent 850ee56 commit cb1d401

File tree

4 files changed

+53
-1
lines changed

4 files changed

+53
-1
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
2+
//===----------------------------------------------------------------------===//
3+
//
4+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5+
// See https://llvm.org/LICENSE.txt for license information.
6+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7+
//
8+
//===----------------------------------------------------------------------===//
9+
//
10+
// This file defines the CIR dialect attributes constraints.
11+
//
12+
//===----------------------------------------------------------------------===//
13+
14+
#ifndef CLANG_CIR_DIALECT_IR_CIRATTRCONSTRAINTS_TD
15+
#define CLANG_CIR_DIALECT_IR_CIRATTRCONSTRAINTS_TD
16+
17+
include "mlir/IR/CommonAttrConstraints.td"
18+
19+
class CIR_IsAttrPred<code attr> : CPred<"::mlir::isa<" # attr # ">($_self)">;
20+
21+
class CIR_AttrConstraint<code attr, string summary = "">
22+
: Attr<CIR_IsAttrPred<attr>, summary>;
23+
24+
//===----------------------------------------------------------------------===//
25+
// IntAttr constraints
26+
//===----------------------------------------------------------------------===//
27+
28+
def CIR_AnyIntAttr : CIR_AttrConstraint<"::cir::IntAttr", "integer attribute">;
29+
30+
//===----------------------------------------------------------------------===//
31+
// FPAttr constraints
32+
//===----------------------------------------------------------------------===//
33+
34+
def CIR_AnyFPAttr : CIR_AttrConstraint<"::cir::FPAttr", "floating-point attribute">;
35+
36+
def CIR_AnyIntOrFloatAttr : AnyAttrOf<[CIR_AnyIntAttr, CIR_AnyFPAttr],
37+
"integer or floating point type"> {
38+
string cppType = "::mlir::TypedAttr";
39+
}
40+
41+
#endif // CLANG_CIR_DIALECT_IR_CIRATTRCONSTRAINTS_TD

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ include "mlir/IR/BuiltinAttributeInterfaces.td"
1717
include "mlir/IR/EnumAttr.td"
1818

1919
include "clang/CIR/Dialect/IR/CIRDialect.td"
20+
include "clang/CIR/Dialect/IR/CIRAttrConstraints.td"
2021

2122
//===----------------------------------------------------------------------===//
2223
// CIR Attrs
@@ -301,7 +302,9 @@ def ConstComplexAttr : CIR_Attr<"ConstComplex", "const_complex",
301302

302303
let parameters = (ins
303304
AttributeSelfTypeParameter<"", "cir::ComplexType">:$type,
304-
"mlir::TypedAttr":$real, "mlir::TypedAttr":$imag);
305+
CIR_AnyIntOrFloatAttr:$real,
306+
CIR_AnyIntOrFloatAttr:$imag
307+
);
305308

306309
let builders = [
307310
AttrBuilderWithInferredContext<(ins "cir::ComplexType":$type,

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ def CIR_ComplexType : CIR_Type<"Complex", "complex",
173173
CIR type that represents a C complex number. `cir.complex` models the C type
174174
`T _Complex`.
175175

176+
`cir.complex` type is not directly mapped to `std::complex`.
177+
176178
The type models complex values, per C99 6.2.5p11. It supports the C99
177179
complex float types as well as the GCC integer complex extensions.
178180

clang/include/clang/CIR/Dialect/IR/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,9 @@ mlir_tablegen(CIRTypeConstraints.h.inc -gen-type-constraint-decls)
2525
mlir_tablegen(CIRTypeConstraints.cpp.inc -gen-type-constraint-defs)
2626
add_public_tablegen_target(MLIRCIRTypeConstraintsIncGen)
2727
add_dependencies(mlir-headers MLIRCIRTypeConstraintsIncGen)
28+
29+
set(LLVM_TARGET_DEFINITIONS CIRAttrConstraints.td)
30+
mlir_tablegen(CIRAttrConstraints.h.inc -gen-type-constraint-decls)
31+
mlir_tablegen(CIRAttrConstraints.cpp.inc -gen-type-constraint-defs)
32+
add_public_tablegen_target(MLIRCIRAttrConstraintsIncGen)
33+
add_dependencies(mlir-headers MLIRCIRAttrConstraintsIncGen)

0 commit comments

Comments
 (0)