Skip to content

Commit b22961d

Browse files
authored
[CIR] Refactor type interfaces (#1713)
- Generalizes CIRFPTypeInterface files to CIRTypeInterfaces for future type interfaces additions. - Renames CIRFPTypeInterface to FPTypeInterface. - Fixes FPTypeInterface tablegen prefix.
1 parent f87bee5 commit b22961d

File tree

19 files changed

+71
-69
lines changed

19 files changed

+71
-69
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -444,17 +444,17 @@ def FPAttr : CIR_Attr<"FP", "fp", [TypedAttrInterface]> {
444444
value of the specified floating-point type. Supporting only CIR FP types.
445445
}];
446446
let parameters = (ins
447-
AttributeSelfTypeParameter<"", "::cir::CIRFPTypeInterface">:$type,
447+
AttributeSelfTypeParameter<"", "::cir::FPTypeInterface">:$type,
448448
APFloatParameter<"">:$value
449449
);
450450
let builders = [
451451
AttrBuilderWithInferredContext<(ins "mlir::Type":$type,
452452
"const llvm::APFloat &":$value), [{
453-
return $_get(type.getContext(), mlir::cast<CIRFPTypeInterface>(type), value);
453+
return $_get(type.getContext(), mlir::cast<FPTypeInterface>(type), value);
454454
}]>,
455455
AttrBuilder<(ins "mlir::Type":$type,
456456
"const llvm::APFloat &":$value), [{
457-
return $_get($_ctxt, mlir::cast<CIRFPTypeInterface>(type), value);
457+
return $_get($_ctxt, mlir::cast<FPTypeInterface>(type), value);
458458
}]>,
459459
];
460460
let extraClassDeclaration = [{

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#include "mlir/Interfaces/DataLayoutInterfaces.h"
1919
#include "clang/CIR/Dialect/IR/CIROpsEnums.h"
2020
#include "clang/CIR/Interfaces/ASTAttrInterfaces.h"
21-
#include "clang/CIR/Interfaces/CIRFPTypeInterface.h"
21+
#include "clang/CIR/Interfaces/CIRTypeInterfaces.h"
2222

2323
namespace cir {
2424
namespace detail {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
include "clang/CIR/Dialect/IR/CIRDialect.td"
1717
include "clang/CIR/Dialect/IR/CIRTypeConstraints.td"
1818
include "clang/CIR/Interfaces/ASTAttrInterfaces.td"
19-
include "clang/CIR/Interfaces/CIRFPTypeInterface.td"
19+
include "clang/CIR/Interfaces/CIRTypeInterfaces.td"
2020
include "mlir/Interfaces/DataLayoutInterfaces.td"
2121
include "mlir/IR/AttrTypeBase.td"
2222
include "mlir/IR/EnumAttr.td"
@@ -82,7 +82,7 @@ def CIR_IntType : CIR_Type<"Int", "int",
8282

8383
class CIR_FloatType<string name, string mnemonic> : CIR_Type<name, mnemonic, [
8484
DeclareTypeInterfaceMethods<DataLayoutTypeInterface>,
85-
DeclareTypeInterfaceMethods<CIRFPTypeInterface>
85+
DeclareTypeInterfaceMethods<CIR_FPTypeInterface>
8686
]>;
8787

8888
def CIR_Single : CIR_FloatType<"Single", "float"> {
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
//===- CIRFPTypeInterface.h - Interface for CIR FP types -------*- C++ -*-===//
1+
//===---------------------------------------------------------------------===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
77
//===---------------------------------------------------------------------===//
88
//
9-
// Defines the interface to generically handle CIR floating-point types.
9+
// Defines cir type interfaces.
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
#ifndef CLANG_INTERFACES_CIR_CIR_FPTYPEINTERFACE_H
14-
#define CLANG_INTERFACES_CIR_CIR_FPTYPEINTERFACE_H
13+
#ifndef CLANG_CIR_INTERFACES_CIRTYPEINTERFACES_H
14+
#define CLANG_CIR_INTERFACES_CIRTYPEINTERFACES_H
1515

1616
#include "mlir/IR/Types.h"
1717
#include "llvm/ADT/APFloat.h"
1818

1919
/// Include the tablegen'd interface declarations.
20-
#include "clang/CIR/Interfaces/CIRFPTypeInterface.h.inc"
20+
#include "clang/CIR/Interfaces/CIRTypeInterfaces.h.inc"
2121

22-
#endif // CLANG_INTERFACES_CIR_CIR_FPTYPEINTERFACE_H
22+
#endif // CLANG_CIR_INTERFACES_CIRTYPEINTERFACES_H

clang/include/clang/CIR/Interfaces/CIRFPTypeInterface.td renamed to clang/include/clang/CIR/Interfaces/CIRTypeInterfaces.td

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
1-
//===- CIRFPTypeInterface.td - CIR FP Interface Definitions -----*- C++ -*-===//
1+
//===----------------------------------------------------------------------===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
77
//===----------------------------------------------------------------------===//
8+
//
9+
// Defines cir type interfaces.
10+
//
11+
//===----------------------------------------------------------------------===//
812

9-
#ifndef MLIR_CIR_INTERFACES_CIR_FP_TYPE_INTERFACE
10-
#define MLIR_CIR_INTERFACES_CIR_FP_TYPE_INTERFACE
13+
#ifndef CLANG_CIR_INTERFACES_CIRTYPEINTERFACES_TD
14+
#define CLANG_CIR_INTERFACES_CIRTYPEINTERFACES_TD
1115

1216
include "mlir/IR/OpBase.td"
1317

14-
def CIRFPTypeInterface : TypeInterface<"CIRFPTypeInterface"> {
18+
def CIR_FPTypeInterface : TypeInterface<"FPTypeInterface"> {
1519
let description = [{
1620
Contains helper functions to query properties about a floating-point type.
1721
}];
@@ -49,4 +53,4 @@ def CIRFPTypeInterface : TypeInterface<"CIRFPTypeInterface"> {
4953
];
5054
}
5155

52-
#endif // MLIR_CIR_INTERFACES_CIR_FP_TYPE_INTERFACE
56+
#endif // CLANG_CIR_INTERFACES_CIRTYPEINTERFACES_TD

clang/include/clang/CIR/Interfaces/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ endfunction()
3131
add_clang_mlir_attr_interface(ASTAttrInterfaces)
3232
add_clang_mlir_op_interface(CIROpInterfaces)
3333
add_clang_mlir_op_interface(CIRLoopOpInterface)
34-
add_clang_mlir_type_interface(CIRFPTypeInterface)
34+
add_clang_mlir_type_interface(CIRTypeInterfaces)

clang/lib/CIR/CodeGen/CIRGenBuilder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy {
529529

530530
bool isSized(mlir::Type ty) {
531531
if (mlir::isa<cir::PointerType, cir::RecordType, cir::ArrayType,
532-
cir::BoolType, cir::IntType, cir::CIRFPTypeInterface,
532+
cir::BoolType, cir::IntType, cir::FPTypeInterface,
533533
cir::ComplexType>(ty))
534534
return true;
535535
if (mlir::isa<cir::VectorType>(ty)) {

clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include "CIRGenCstEmitter.h"
33
#include "CIRGenFunction.h"
44
#include "clang/Basic/LangOptions.h"
5-
#include "clang/CIR/Interfaces/CIRFPTypeInterface.h"
5+
#include "clang/CIR/Interfaces/CIRTypeInterfaces.h"
66
#include "clang/CIR/MissingFeatures.h"
77

88
#include "mlir/IR/Location.h"
@@ -844,7 +844,7 @@ ComplexExprEmitter::VisitImaginaryLiteral(const ImaginaryLiteral *IL) {
844844
auto ImagValue = cast<IntegerLiteral>(IL->getSubExpr())->getValue();
845845
RealValueAttr = cir::IntAttr::get(ElementTy, 0);
846846
ImagValueAttr = cir::IntAttr::get(ElementTy, ImagValue);
847-
} else if (mlir::isa<cir::CIRFPTypeInterface>(ElementTy)) {
847+
} else if (mlir::isa<cir::FPTypeInterface>(ElementTy)) {
848848
auto ImagValue = cast<FloatingLiteral>(IL->getSubExpr())->getValue();
849849
RealValueAttr = cir::FPAttr::get(
850850
ElementTy, llvm::APFloat::getZero(ImagValue.getSemantics()));

clang/lib/CIR/CodeGen/CIRGenExprConst.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1916,7 +1916,7 @@ mlir::Attribute ConstantEmitter::tryEmitPrivate(const APValue &Value,
19161916
assert(0 && "not implemented");
19171917
else {
19181918
mlir::Type ty = CGM.convertType(DestType);
1919-
assert(mlir::isa<cir::CIRFPTypeInterface>(ty) &&
1919+
assert(mlir::isa<cir::FPTypeInterface>(ty) &&
19201920
"expected floating-point type");
19211921
return CGM.getBuilder().getAttr<cir::FPAttr>(ty, Init);
19221922
}
@@ -2022,7 +2022,7 @@ mlir::Attribute ConstantEmitter::tryEmitPrivate(const APValue &Value,
20222022
builder.getAttr<cir::IntAttr>(complexElemTy, imag));
20232023
}
20242024

2025-
assert(isa<cir::CIRFPTypeInterface>(complexElemTy) &&
2025+
assert(isa<cir::FPTypeInterface>(complexElemTy) &&
20262026
"expected floating-point type");
20272027
llvm::APFloat real = Value.getComplexFloatReal();
20282028
llvm::APFloat imag = Value.getComplexFloatImag();

clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,7 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
183183
}
184184
mlir::Value VisitFloatingLiteral(const FloatingLiteral *E) {
185185
mlir::Type Ty = CGF.convertType(E->getType());
186-
assert(mlir::isa<cir::CIRFPTypeInterface>(Ty) &&
187-
"expect floating-point type");
186+
assert(mlir::isa<cir::FPTypeInterface>(Ty) && "expect floating-point type");
188187
return Builder.create<cir::ConstantOp>(
189188
CGF.getLoc(E->getExprLoc()),
190189
Builder.getAttr<cir::FPAttr>(Ty, E->getValue()));
@@ -1047,7 +1046,7 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
10471046
if (SrcType->isHalfType() &&
10481047
!CGF.getContext().getLangOpts().NativeHalfType) {
10491048
// Cast to FP using the intrinsic if the half type itself isn't supported.
1050-
if (mlir::isa<cir::CIRFPTypeInterface>(DstTy)) {
1049+
if (mlir::isa<cir::FPTypeInterface>(DstTy)) {
10511050
if (CGF.getContext().getTargetInfo().useFP16ConversionIntrinsics())
10521051
llvm_unreachable("cast via llvm.convert.from.fp16 is NYI");
10531052
} else {
@@ -1118,7 +1117,7 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
11181117
if (DstType->isHalfType() &&
11191118
!CGF.getContext().getLangOpts().NativeHalfType) {
11201119
// Make sure we cast in a single step if from another FP type.
1121-
if (mlir::isa<cir::CIRFPTypeInterface>(SrcTy)) {
1120+
if (mlir::isa<cir::FPTypeInterface>(SrcTy)) {
11221121
// Use the intrinsic if the half type itself isn't supported
11231122
// (as opposed to operations on half, available with NativeHalfType).
11241123
if (CGF.getContext().getTargetInfo().useFP16ConversionIntrinsics())
@@ -2118,20 +2117,20 @@ mlir::Value ScalarExprEmitter::emitScalarCast(mlir::Value Src, QualType SrcType,
21182117
llvm_unreachable("NYI: signed bool");
21192118
if (CGF.getBuilder().isInt(DstTy)) {
21202119
CastKind = cir::CastKind::bool_to_int;
2121-
} else if (mlir::isa<cir::CIRFPTypeInterface>(DstTy)) {
2120+
} else if (mlir::isa<cir::FPTypeInterface>(DstTy)) {
21222121
CastKind = cir::CastKind::bool_to_float;
21232122
} else {
21242123
llvm_unreachable("Internal error: Cast to unexpected type");
21252124
}
21262125
} else if (CGF.getBuilder().isInt(SrcTy)) {
21272126
if (CGF.getBuilder().isInt(DstTy)) {
21282127
CastKind = cir::CastKind::integral;
2129-
} else if (mlir::isa<cir::CIRFPTypeInterface>(DstTy)) {
2128+
} else if (mlir::isa<cir::FPTypeInterface>(DstTy)) {
21302129
CastKind = cir::CastKind::int_to_float;
21312130
} else {
21322131
llvm_unreachable("Internal error: Cast to unexpected type");
21332132
}
2134-
} else if (mlir::isa<cir::CIRFPTypeInterface>(SrcTy)) {
2133+
} else if (mlir::isa<cir::FPTypeInterface>(SrcTy)) {
21352134
if (CGF.getBuilder().isInt(DstTy)) {
21362135
// If we can't recognize overflow as undefined behavior, assume that
21372136
// overflow saturates. This protects against normal optimizations if we
@@ -2141,7 +2140,7 @@ mlir::Value ScalarExprEmitter::emitScalarCast(mlir::Value Src, QualType SrcType,
21412140
if (Builder.getIsFPConstrained())
21422141
llvm_unreachable("NYI");
21432142
CastKind = cir::CastKind::float_to_int;
2144-
} else if (mlir::isa<cir::CIRFPTypeInterface>(DstTy)) {
2143+
} else if (mlir::isa<cir::FPTypeInterface>(DstTy)) {
21452144
// TODO: split this to createFPExt/createFPTrunc
21462145
return Builder.createFloatingCast(Src, FullDstTy);
21472146
} else {

0 commit comments

Comments
 (0)