Skip to content

Commit 61c0a94

Browse files
authored
[CIR] Refactor type interfaces (#146044)
- Generalizes CIRFPTypeInterface files to CIRTypeInterfaces for future type interfaces additions. - Renames CIRFPTypeInterface to FPTypeInterface. - Fixes FPTypeInterface tablegen prefix. This mirrors incubator changes from llvm/clangir#1713
1 parent dc6d2b8 commit 61c0a94

18 files changed

+54
-58
lines changed

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,18 +160,17 @@ def FPAttr : CIR_Attr<"FP", "fp", [TypedAttrInterface]> {
160160
value of the specified floating-point type. Supporting only CIR FP types.
161161
}];
162162
let parameters = (ins
163-
AttributeSelfTypeParameter<"", "::cir::CIRFPTypeInterface">:$type,
163+
AttributeSelfTypeParameter<"", "::cir::FPTypeInterface">:$type,
164164
APFloatParameter<"">:$value
165165
);
166166
let builders = [
167167
AttrBuilderWithInferredContext<(ins "mlir::Type":$type,
168168
"const llvm::APFloat &":$value), [{
169-
return $_get(type.getContext(), mlir::cast<CIRFPTypeInterface>(type),
170-
value);
169+
return $_get(type.getContext(), mlir::cast<FPTypeInterface>(type), value);
171170
}]>,
172171
AttrBuilder<(ins "mlir::Type":$type,
173172
"const llvm::APFloat &":$value), [{
174-
return $_get($_ctxt, mlir::cast<CIRFPTypeInterface>(type), value);
173+
return $_get($_ctxt, mlir::cast<FPTypeInterface>(type), value);
175174
}]>,
176175
];
177176
let extraClassDeclaration = [{

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#include "mlir/IR/BuiltinAttributes.h"
1717
#include "mlir/IR/Types.h"
1818
#include "mlir/Interfaces/DataLayoutInterfaces.h"
19-
#include "clang/CIR/Interfaces/CIRFPTypeInterface.h"
19+
#include "clang/CIR/Interfaces/CIRTypeInterfaces.h"
2020

2121
namespace cir {
2222

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
include "clang/CIR/Dialect/IR/CIRDialect.td"
1717
include "clang/CIR/Dialect/IR/CIRTypeConstraints.td"
18-
include "clang/CIR/Interfaces/CIRFPTypeInterface.td"
18+
include "clang/CIR/Interfaces/CIRTypeInterfaces.td"
1919
include "mlir/Interfaces/DataLayoutInterfaces.td"
2020
include "mlir/IR/AttrTypeBase.td"
2121

@@ -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"> {

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@
66
//
77
//===---------------------------------------------------------------------===//
88
//
9-
// Defines the interface to generically handle CIR floating-point types.
9+
// Defines cir type interfaces.
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
#ifndef LLVM_CLANG_INCLUDE_CLANG_CIR_INTERFACES_CIRFPTYPEINTERFACE_H
14-
#define LLVM_CLANG_INCLUDE_CLANG_CIR_INTERFACES_CIRFPTYPEINTERFACE_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 // LLVM_CLANG_INCLUDE_CLANG_CIR_INTERFACES_CIRFPTYPEINTERFACE_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: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@
66
//
77
//===----------------------------------------------------------------------===//
88
//
9-
// Defines the interface to generically handle CIR floating-point types.
9+
// Defines cir type interfaces.
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
#ifndef LLVM_CLANG_INCLUDE_CLANG_CIR_INTERFACES_CIRFPTYPEINTERFACE_TD
14-
#define LLVM_CLANG_INCLUDE_CLANG_CIR_INTERFACES_CIRFPTYPEINTERFACE_TD
13+
#ifndef CLANG_CIR_INTERFACES_CIRTYPEINTERFACES_TD
14+
#define CLANG_CIR_INTERFACES_CIRTYPEINTERFACES_TD
1515

1616
include "mlir/IR/OpBase.td"
1717

18-
def CIRFPTypeInterface : TypeInterface<"CIRFPTypeInterface"> {
18+
def CIR_FPTypeInterface : TypeInterface<"FPTypeInterface"> {
1919
let description = [{
2020
Contains helper functions to query properties about a floating-point type.
2121
}];
@@ -53,4 +53,4 @@ def CIRFPTypeInterface : TypeInterface<"CIRFPTypeInterface"> {
5353
];
5454
}
5555

56-
#endif // LLVM_CLANG_INCLUDE_CLANG_CIR_INTERFACES_CIRFPTYPEINTERFACE_TD
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
@@ -21,4 +21,4 @@ endfunction()
2121

2222
add_clang_mlir_op_interface(CIROpInterfaces)
2323
add_clang_mlir_op_interface(CIRLoopOpInterface)
24-
add_clang_mlir_type_interface(CIRFPTypeInterface)
24+
add_clang_mlir_type_interface(CIRTypeInterfaces)

clang/lib/CIR/CodeGen/CIRGenBuilder.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ cir::ConstantOp CIRGenBuilderTy::getConstInt(mlir::Location loc, mlir::Type t,
6262
cir::ConstantOp
6363
clang::CIRGen::CIRGenBuilderTy::getConstFP(mlir::Location loc, mlir::Type t,
6464
llvm::APFloat fpVal) {
65-
assert(mlir::isa<cir::CIRFPTypeInterface>(t) &&
66-
"expected floating point type");
65+
assert(mlir::isa<cir::FPTypeInterface>(t) && "expected floating point type");
6766
return create<cir::ConstantOp>(loc, getAttr<cir::FPAttr>(t, fpVal));
6867
}
6968

clang/lib/CIR/CodeGen/CIRGenBuilder.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
#include "Address.h"
1313
#include "CIRGenTypeCache.h"
14-
#include "clang/CIR/Interfaces/CIRFPTypeInterface.h"
14+
#include "clang/CIR/Interfaces/CIRTypeInterfaces.h"
1515
#include "clang/CIR/MissingFeatures.h"
1616

1717
#include "clang/CIR/Dialect/Builder/CIRBaseBuilder.h"
@@ -141,8 +141,7 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy {
141141

142142
bool isSized(mlir::Type ty) {
143143
if (mlir::isa<cir::PointerType, cir::ArrayType, cir::BoolType, cir::IntType,
144-
cir::CIRFPTypeInterface, cir::ComplexType, cir::RecordType>(
145-
ty))
144+
cir::FPTypeInterface, cir::ComplexType, cir::RecordType>(ty))
146145
return true;
147146

148147
if (const auto vt = mlir::dyn_cast<cir::VectorType>(ty))

clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ ComplexExprEmitter::VisitImaginaryLiteral(const ImaginaryLiteral *il) {
195195
realValueAttr = cir::IntAttr::get(elementTy, 0);
196196
imagValueAttr = cir::IntAttr::get(elementTy, imagValue);
197197
} else {
198-
assert(mlir::isa<cir::CIRFPTypeInterface>(elementTy) &&
198+
assert(mlir::isa<cir::FPTypeInterface>(elementTy) &&
199199
"Expected complex element type to be floating-point");
200200

201201
llvm::APFloat imagValue =

clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,7 @@ mlir::Attribute ConstantEmitter::tryEmitPrivate(const APValue &value,
696696
}
697697

698698
mlir::Type ty = cgm.convertType(destType);
699-
assert(mlir::isa<cir::CIRFPTypeInterface>(ty) &&
699+
assert(mlir::isa<cir::FPTypeInterface>(ty) &&
700700
"expected floating-point type");
701701
return cgm.getBuilder().getAttr<cir::FPAttr>(ty, init);
702702
}
@@ -793,7 +793,7 @@ mlir::Attribute ConstantEmitter::tryEmitPrivate(const APValue &value,
793793
builder.getAttr<cir::IntAttr>(complexElemTy, imag));
794794
}
795795

796-
assert(isa<cir::CIRFPTypeInterface>(complexElemTy) &&
796+
assert(isa<cir::FPTypeInterface>(complexElemTy) &&
797797
"expected floating-point type");
798798
llvm::APFloat real = value.getComplexFloatReal();
799799
llvm::APFloat imag = value.getComplexFloatImag();

0 commit comments

Comments
 (0)