From 80aee2072a51cdf8ea809acd16ba8f1ca794c2dc Mon Sep 17 00:00:00 2001 From: Sirui Mu Date: Mon, 19 Feb 2024 21:17:08 +0800 Subject: [PATCH] Remove mlir::cir::FloatType and replace it with an interface --- .../include/clang/CIR/Dialect/IR/CIRAttrs.td | 2 +- clang/include/clang/CIR/Dialect/IR/CIRTypes.h | 38 +------------- .../include/clang/CIR/Dialect/IR/CIRTypes.td | 9 ++-- .../clang/CIR/Interfaces/CMakeLists.txt | 9 ++++ .../clang/CIR/Interfaces/FPTypeInterface.h | 22 ++++++++ .../clang/CIR/Interfaces/FPTypeInterface.td | 52 +++++++++++++++++++ clang/lib/CIR/CodeGen/CIRGenBuilder.h | 14 ++--- clang/lib/CIR/CodeGen/CIRGenExprConst.cpp | 3 +- clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp | 13 ++--- clang/lib/CIR/CodeGen/CIRGenModule.cpp | 4 +- clang/lib/CIR/Dialect/IR/CIRAttrs.cpp | 21 ++++---- clang/lib/CIR/Dialect/IR/CIRDialect.cpp | 12 ++--- clang/lib/CIR/Dialect/IR/CIRTypes.cpp | 39 +++----------- clang/lib/CIR/Interfaces/CMakeLists.txt | 2 + clang/lib/CIR/Interfaces/FPTypeInterface.cpp | 14 +++++ .../CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp | 16 +++--- 16 files changed, 158 insertions(+), 112 deletions(-) create mode 100644 clang/include/clang/CIR/Interfaces/FPTypeInterface.h create mode 100644 clang/include/clang/CIR/Interfaces/FPTypeInterface.td create mode 100644 clang/lib/CIR/Interfaces/FPTypeInterface.cpp diff --git a/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td b/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td index d02f3e2535da..aabdac38f6ca 100644 --- a/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td +++ b/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td @@ -220,7 +220,7 @@ def FPAttr : CIR_Attr<"FP", "fp", [TypedAttrInterface]> { }]>, ]; let extraClassDeclaration = [{ - static FPAttr getZero(mlir::cir::FloatType type); + static FPAttr getZero(mlir::Type type); }]; let genVerifyDecl = 1; let hasCustomAssemblyFormat = 1; diff --git a/clang/include/clang/CIR/Dialect/IR/CIRTypes.h b/clang/include/clang/CIR/Dialect/IR/CIRTypes.h index 6fa90b716e0f..0da0ff3b8dfb 100644 --- a/clang/include/clang/CIR/Dialect/IR/CIRTypes.h +++ b/clang/include/clang/CIR/Dialect/IR/CIRTypes.h @@ -16,46 +16,10 @@ #include "mlir/IR/BuiltinAttributes.h" #include "mlir/IR/Types.h" #include "mlir/Interfaces/DataLayoutInterfaces.h" +#include "clang/CIR/Interfaces/FPTypeInterface.h" #include "clang/CIR/Interfaces/ASTAttrInterfaces.h" -//===----------------------------------------------------------------------===// -// CIR FloatType -// -// The base type for all floating-point types. -//===----------------------------------------------------------------------===// - -namespace mlir { -namespace cir { - -class SingleType; -class DoubleType; - -class FloatType : public Type { -public: - using Type::Type; - - // Convenience factories. - static SingleType getSingle(MLIRContext *ctx); - static DoubleType getDouble(MLIRContext *ctx); - - /// Methods for support type inquiry through isa, cast, and dyn_cast. - static bool classof(Type type); - - /// Return the bitwidth of this float type. - unsigned getWidth() const; - - /// Return the width of the mantissa of this type. - /// The width includes the integer bit. - unsigned getFPMantissaWidth() const; - - /// Return the float semantics of this floating-point type. - const llvm::fltSemantics &getFloatSemantics() const; -}; - -} // namespace cir -} // namespace mlir - //===----------------------------------------------------------------------===// // CIR Dialect Tablegen'd Types //===----------------------------------------------------------------------===// diff --git a/clang/include/clang/CIR/Dialect/IR/CIRTypes.td b/clang/include/clang/CIR/Dialect/IR/CIRTypes.td index 730f9372eaeb..0c1c25321e7a 100644 --- a/clang/include/clang/CIR/Dialect/IR/CIRTypes.td +++ b/clang/include/clang/CIR/Dialect/IR/CIRTypes.td @@ -15,6 +15,7 @@ include "clang/CIR/Dialect/IR/CIRDialect.td" include "clang/CIR/Interfaces/ASTAttrInterfaces.td" +include "clang/CIR/Interfaces/FPTypeInterface.td" include "mlir/Interfaces/DataLayoutInterfaces.td" include "mlir/IR/AttrTypeBase.td" include "mlir/IR/EnumAttr.td" @@ -102,8 +103,10 @@ def SInt64 : SInt<64>; class CIR_FloatType : CIR_Type], - "::mlir::cir::FloatType"> {} + [ + DeclareTypeInterfaceMethods, + DeclareTypeInterfaceMethods, + ]> {} def CIR_Single : CIR_FloatType<"Single", "float"> { let summary = "CIR single-precision float type"; @@ -123,7 +126,7 @@ def CIR_Double : CIR_FloatType<"Double", "double"> { // Constraints -def CIR_AnyFloat: Type()">>; +def CIR_AnyFloat: AnyTypeOf<[CIR_Single, CIR_Double]>; //===----------------------------------------------------------------------===// // PointerType diff --git a/clang/include/clang/CIR/Interfaces/CMakeLists.txt b/clang/include/clang/CIR/Interfaces/CMakeLists.txt index c7132abca833..097766fab4cd 100644 --- a/clang/include/clang/CIR/Interfaces/CMakeLists.txt +++ b/clang/include/clang/CIR/Interfaces/CMakeLists.txt @@ -20,6 +20,15 @@ function(add_clang_mlir_op_interface interface) add_dependencies(mlir-generic-headers MLIR${interface}IncGen) endfunction() +function(add_clang_mlir_type_interface interface) + set(LLVM_TARGET_DEFINITIONS ${interface}.td) + mlir_tablegen(${interface}.h.inc -gen-type-interface-decls) + mlir_tablegen(${interface}.cpp.inc -gen-type-interface-defs) + add_public_tablegen_target(MLIRCIR${interface}IncGen) + add_dependencies(mlir-generic-headers MLIRCIR${interface}IncGen) +endfunction() + add_clang_mlir_attr_interface(ASTAttrInterfaces) add_clang_mlir_op_interface(CIROpInterfaces) add_clang_mlir_op_interface(CIRLoopOpInterface) +add_clang_mlir_type_interface(FPTypeInterface) diff --git a/clang/include/clang/CIR/Interfaces/FPTypeInterface.h b/clang/include/clang/CIR/Interfaces/FPTypeInterface.h new file mode 100644 index 000000000000..4f01726797dd --- /dev/null +++ b/clang/include/clang/CIR/Interfaces/FPTypeInterface.h @@ -0,0 +1,22 @@ +//===- FPTypeInterface.h - Interface for CIR FP types ----------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===---------------------------------------------------------------------===// +// +// Defines the interface to generically handle CIR floating-point types. +// +//===----------------------------------------------------------------------===// + +#ifndef CLANG_INTERFACES_CIR_FPTYPEINTERFACE_H +#define CLANG_INTERFACES_CIR_FPTYPEINTERFACE_H + +#include "mlir/IR/Types.h" +#include "llvm/ADT/APFloat.h" + +/// Include the tablegen'd interface declarations. +#include "clang/CIR/Interfaces/FPTypeInterface.h.inc" + +#endif // CLANG_INTERFACES_CIR_FPTYPEINTERFACE_H diff --git a/clang/include/clang/CIR/Interfaces/FPTypeInterface.td b/clang/include/clang/CIR/Interfaces/FPTypeInterface.td new file mode 100644 index 000000000000..2329d2d39545 --- /dev/null +++ b/clang/include/clang/CIR/Interfaces/FPTypeInterface.td @@ -0,0 +1,52 @@ +//===- FPTypeInterface.td - CIR FP Interface Definitions --------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef MLIR_CIR_INTERFACES_FP_TYPE_INTERFACE +#define MLIR_CIR_INTERFACES_FP_TYPE_INTERFACE + +include "mlir/IR/OpBase.td" + +def FPTypeInterface : TypeInterface<"FPTypeInterface"> { + let description = [{ + Contains helper functions to query properties about a floating-point type. + }]; + let cppNamespace = "::mlir::cir"; + + let methods = [ + InterfaceMethod<[{ + Returns the bit width of this floating-point type. + }], + /*retTy=*/"unsigned", + /*methodName=*/"getWidth", + /*args=*/(ins), + /*methodBody=*/"", + /*defaultImplementation=*/[{ + return llvm::APFloat::semanticsSizeInBits($_type.getFloatSemantics()); + }] + >, + InterfaceMethod<[{ + Return the mantissa width. + }], + /*retTy=*/"unsigned", + /*methodName=*/"getFPMantissaWidth", + /*args=*/(ins), + /*methodBody=*/"", + /*defaultImplementation=*/[{ + return llvm::APFloat::semanticsPrecision($_type.getFloatSemantics()); + }] + >, + InterfaceMethod<[{ + Return the float semantics of this floating-point type. + }], + /*retTy=*/"const llvm::fltSemantics &", + /*methodName=*/"getFloatSemantics" + >, + ]; +} + +#endif // MLIR_CIR_INTERFACES_FP_TYPE_INTERFACE diff --git a/clang/lib/CIR/CodeGen/CIRGenBuilder.h b/clang/lib/CIR/CodeGen/CIRGenBuilder.h index 068988e8a5df..e803018a3f3f 100644 --- a/clang/lib/CIR/CodeGen/CIRGenBuilder.h +++ b/clang/lib/CIR/CodeGen/CIRGenBuilder.h @@ -224,7 +224,9 @@ class CIRGenBuilderTy : public CIRBaseBuilderTy { mlir::TypedAttr getZeroInitAttr(mlir::Type ty) { if (ty.isa()) return mlir::cir::IntAttr::get(ty, 0); - if (auto fltType = ty.dyn_cast()) + if (auto fltType = ty.dyn_cast()) + return mlir::cir::FPAttr::getZero(fltType); + if (auto fltType = ty.dyn_cast()) return mlir::cir::FPAttr::getZero(fltType); if (auto arrTy = ty.dyn_cast()) return getZeroAttr(arrTy); @@ -343,13 +345,11 @@ class CIRGenBuilderTy : public CIRBaseBuilderTy { } bool isInt(mlir::Type i) { return i.isa(); } - mlir::cir::FloatType getLongDouble80BitsTy() const { - llvm_unreachable("NYI"); - } + mlir::Type getLongDouble80BitsTy() const { llvm_unreachable("NYI"); } /// Get the proper floating point type for the given semantics. - mlir::cir::FloatType getFloatTyForFormat(const llvm::fltSemantics &format, - bool useNativeHalf) const { + mlir::Type getFloatTyForFormat(const llvm::fltSemantics &format, + bool useNativeHalf) const { if (&format == &llvm::APFloat::IEEEhalf()) { llvm_unreachable("IEEEhalf float format is NYI"); } @@ -472,7 +472,7 @@ class CIRGenBuilderTy : public CIRBaseBuilderTy { bool isSized(mlir::Type ty) { if (ty.isa()) + mlir::cir::FPTypeInterface>()) return true; assert(0 && "Unimplemented size for type"); return false; diff --git a/clang/lib/CIR/CodeGen/CIRGenExprConst.cpp b/clang/lib/CIR/CodeGen/CIRGenExprConst.cpp index 665a5772313d..fe84d904f19f 100644 --- a/clang/lib/CIR/CodeGen/CIRGenExprConst.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenExprConst.cpp @@ -1479,7 +1479,8 @@ mlir::Attribute ConstantEmitter::tryEmitPrivate(const APValue &Value, assert(0 && "not implemented"); else { mlir::Type ty = CGM.getCIRType(DestType); - assert(ty.isa() && "expected floating-point type"); + assert(ty.isa() && + "expected floating-point type"); return CGM.getBuilder().getAttr(ty, Init); } } diff --git a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp index 02c9c51f0ff4..fa90aa1b18b1 100644 --- a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp @@ -165,7 +165,8 @@ class ScalarExprEmitter : public StmtVisitor { } mlir::Value VisitFloatingLiteral(const FloatingLiteral *E) { mlir::Type Ty = CGF.getCIRType(E->getType()); - assert(Ty.isa() && "expect floating-point type"); + assert(Ty.isa() && + "expect floating-point type"); return Builder.create( CGF.getLoc(E->getExprLoc()), Ty, Builder.getAttr(Ty, E->getValue())); @@ -1202,7 +1203,7 @@ mlir::Value ScalarExprEmitter::buildSub(const BinOpInfo &Ops) { llvm_unreachable("NYI"); assert(!UnimplementedFeature::cirVectorType()); - if (Ops.LHS.getType().isa()) { + if (Ops.LHS.getType().isa()) { CIRGenFunction::CIRGenFPOptionsRAII FPOptsRAII(CGF, Ops.FPFeatures); return Builder.createFSub(Ops.LHS, Ops.RHS); } @@ -1670,7 +1671,7 @@ mlir::Value ScalarExprEmitter::buildScalarCast( llvm_unreachable("NYI: signed bool"); if (CGF.getBuilder().isInt(DstTy)) { CastKind = mlir::cir::CastKind::bool_to_int; - } else if (DstTy.isa()) { + } else if (DstTy.isa()) { CastKind = mlir::cir::CastKind::bool_to_float; } else { llvm_unreachable("Internal error: Cast to unexpected type"); @@ -1678,12 +1679,12 @@ mlir::Value ScalarExprEmitter::buildScalarCast( } else if (CGF.getBuilder().isInt(SrcTy)) { if (CGF.getBuilder().isInt(DstTy)) { CastKind = mlir::cir::CastKind::integral; - } else if (DstTy.isa()) { + } else if (DstTy.isa()) { CastKind = mlir::cir::CastKind::int_to_float; } else { llvm_unreachable("Internal error: Cast to unexpected type"); } - } else if (SrcTy.isa()) { + } else if (SrcTy.isa()) { if (CGF.getBuilder().isInt(DstTy)) { // If we can't recognize overflow as undefined behavior, assume that // overflow saturates. This protects against normal optimizations if we @@ -1693,7 +1694,7 @@ mlir::Value ScalarExprEmitter::buildScalarCast( if (Builder.getIsFPConstrained()) llvm_unreachable("NYI"); CastKind = mlir::cir::CastKind::float_to_int; - } else if (DstTy.isa()) { + } else if (DstTy.isa()) { // TODO: split this to createFPExt/createFPTrunc return Builder.createFloatingCast(Src, DstTy); } else { diff --git a/clang/lib/CIR/CodeGen/CIRGenModule.cpp b/clang/lib/CIR/CodeGen/CIRGenModule.cpp index 21cd1557621e..8076cc2e99dd 100644 --- a/clang/lib/CIR/CodeGen/CIRGenModule.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenModule.cpp @@ -133,8 +133,8 @@ CIRGenModule::CIRGenModule(mlir::MLIRContext &context, // TODO: HalfTy // TODO: BFloatTy - FloatTy = ::mlir::cir::FloatType::getSingle(builder.getContext()); - DoubleTy = ::mlir::cir::FloatType::getDouble(builder.getContext()); + FloatTy = ::mlir::cir::SingleType::get(builder.getContext()); + DoubleTy = ::mlir::cir::DoubleType::get(builder.getContext()); // TODO(cir): perhaps we should abstract long double variations into a custom // cir.long_double type. Said type would also hold the semantics for lowering. diff --git a/clang/lib/CIR/Dialect/IR/CIRAttrs.cpp b/clang/lib/CIR/Dialect/IR/CIRAttrs.cpp index 3f812881310e..b07454ed9d07 100644 --- a/clang/lib/CIR/Dialect/IR/CIRAttrs.cpp +++ b/clang/lib/CIR/Dialect/IR/CIRAttrs.cpp @@ -302,9 +302,9 @@ LogicalResult IntAttr::verify(function_ref emitError, Attribute cir::FPAttr::parse(AsmParser &parser, Type odsType) { double value; - if (!odsType.isa()) + auto odsTypeFpInterface = odsType.dyn_cast(); + if (!odsTypeFpInterface) return {}; - auto ty = odsType.cast(); if (parser.parseLess()) return {}; @@ -318,28 +318,29 @@ Attribute cir::FPAttr::parse(AsmParser &parser, Type odsType) { auto losesInfo = false; APFloat convertedValue{value}; - convertedValue.convert(ty.getFloatSemantics(), llvm::RoundingMode::TowardZero, - &losesInfo); + convertedValue.convert(odsTypeFpInterface.getFloatSemantics(), + llvm::RoundingMode::TowardZero, &losesInfo); - return cir::FPAttr::get(ty, convertedValue); + return cir::FPAttr::get(odsType, convertedValue); } void cir::FPAttr::print(AsmPrinter &printer) const { printer << '<' << getValue() << '>'; } -cir::FPAttr cir::FPAttr::getZero(mlir::cir::FloatType type) { - return get(type, APFloat::getZero(type.getFloatSemantics())); +cir::FPAttr cir::FPAttr::getZero(mlir::Type type) { + return get(type, APFloat::getZero( + type.cast().getFloatSemantics())); } LogicalResult cir::FPAttr::verify(function_ref emitError, Type type, APFloat value) { - auto fltType = type.dyn_cast(); - if (!fltType) { + auto fltTypeInterface = type.dyn_cast(); + if (!fltTypeInterface) { emitError() << "expected floating-point type"; return failure(); } - if (APFloat::SemanticsToEnum(fltType.getFloatSemantics()) != + if (APFloat::SemanticsToEnum(fltTypeInterface.getFloatSemantics()) != APFloat::SemanticsToEnum(value.getSemantics())) { emitError() << "floating-point semantics mismatch"; return failure(); diff --git a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp index 0fa07f3335cd..403b71fc8b86 100644 --- a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp +++ b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp @@ -423,13 +423,13 @@ LogicalResult CastOp::verify() { return success(); } case cir::CastKind::floating: { - if (!srcType.isa() || - !resType.isa()) + if (!srcType.isa() || + !resType.isa()) return emitOpError() << "requries floating for source and result"; return success(); } case cir::CastKind::float_to_int: { - if (!srcType.isa()) + if (!srcType.isa()) return emitOpError() << "requires floating for source"; if (!resType.dyn_cast()) return emitOpError() << "requires !IntegerType for result"; @@ -450,7 +450,7 @@ LogicalResult CastOp::verify() { return success(); } case cir::CastKind::float_to_bool: { - if (!srcType.isa()) + if (!srcType.isa()) return emitOpError() << "requires float for source"; if (!resType.isa()) return emitOpError() << "requires !cir.bool for result"; @@ -466,14 +466,14 @@ LogicalResult CastOp::verify() { case cir::CastKind::int_to_float: { if (!srcType.isa()) return emitOpError() << "requires !cir.int for source"; - if (!resType.isa()) + if (!resType.isa()) return emitOpError() << "requires !cir.float for result"; return success(); } case cir::CastKind::bool_to_float: { if (!srcType.isa()) return emitOpError() << "requires !cir.bool for source"; - if (!resType.isa()) + if (!resType.isa()) return emitOpError() << "requires !cir.float for result"; return success(); } diff --git a/clang/lib/CIR/Dialect/IR/CIRTypes.cpp b/clang/lib/CIR/Dialect/IR/CIRTypes.cpp index 07d59ca02ed4..3c9564569b36 100644 --- a/clang/lib/CIR/Dialect/IR/CIRTypes.cpp +++ b/clang/lib/CIR/Dialect/IR/CIRTypes.cpp @@ -25,6 +25,7 @@ #include "mlir/Support/LogicalResult.h" #include "clang/CIR/Interfaces/ASTAttrInterfaces.h" +#include "llvm/ADT/APFloat.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/TypeSwitch.h" @@ -616,39 +617,11 @@ IntType::verify(llvm::function_ref emitError, } //===----------------------------------------------------------------------===// -// FloatType Definitions +// Floating-point type definitions //===----------------------------------------------------------------------===// -SingleType mlir::cir::FloatType::getSingle(MLIRContext *ctx) { - return SingleType::get(ctx); -} - -DoubleType mlir::cir::FloatType::getDouble(MLIRContext *ctx) { - return DoubleType::get(ctx); -} - -bool mlir::cir::FloatType::classof(Type type) { - return llvm::isa(type); -} - -unsigned mlir::cir::FloatType::getWidth() const { - if (llvm::isa(*this)) - return 32; - if (llvm::isa(*this)) - return 64; - llvm_unreachable("unknown floating-point type"); -} - -unsigned mlir::cir::FloatType::getFPMantissaWidth() const { - return APFloat::semanticsPrecision(getFloatSemantics()); -} - -const llvm::fltSemantics &mlir::cir::FloatType::getFloatSemantics() const { - if (llvm::isa(*this)) - return APFloat::IEEEsingle(); - if (llvm::isa(*this)) - return APFloat::IEEEdouble(); - llvm_unreachable("unknown floating-point type"); +const llvm::fltSemantics &SingleType::getFloatSemantics() const { + return llvm::APFloat::IEEEsingle(); } llvm::TypeSize @@ -669,6 +642,10 @@ SingleType::getPreferredAlignment(const ::mlir::DataLayout &dataLayout, return (uint64_t)(getWidth() / 8); } +const llvm::fltSemantics &DoubleType::getFloatSemantics() const { + return llvm::APFloat::IEEEdouble(); +} + llvm::TypeSize DoubleType::getTypeSizeInBits(const mlir::DataLayout &dataLayout, mlir::DataLayoutEntryListRef params) const { diff --git a/clang/lib/CIR/Interfaces/CMakeLists.txt b/clang/lib/CIR/Interfaces/CMakeLists.txt index 84322f4836e0..99883fc03e6b 100644 --- a/clang/lib/CIR/Interfaces/CMakeLists.txt +++ b/clang/lib/CIR/Interfaces/CMakeLists.txt @@ -2,6 +2,7 @@ add_clang_library(MLIRCIRInterfaces ASTAttrInterfaces.cpp CIROpInterfaces.cpp CIRLoopOpInterface.cpp + FPTypeInterface.cpp ADDITIONAL_HEADER_DIRS ${MLIR_MAIN_INCLUDE_DIR}/mlir/Interfaces @@ -10,6 +11,7 @@ add_clang_library(MLIRCIRInterfaces MLIRCIRASTAttrInterfacesIncGen MLIRCIROpInterfacesIncGen MLIRCIRLoopOpInterfaceIncGen + MLIRCIRFPTypeInterfaceIncGen LINK_LIBS ${dialect_libs} diff --git a/clang/lib/CIR/Interfaces/FPTypeInterface.cpp b/clang/lib/CIR/Interfaces/FPTypeInterface.cpp new file mode 100644 index 000000000000..f695d87befbf --- /dev/null +++ b/clang/lib/CIR/Interfaces/FPTypeInterface.cpp @@ -0,0 +1,14 @@ +//====- FPTypeInterface.cpp - Interface for floating-point types ----------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "clang/CIR/Interfaces/FPTypeInterface.h" + +using namespace mlir::cir; + +/// Include the generated interfaces. +#include "clang/CIR/Interfaces/FPTypeInterface.cpp.inc" diff --git a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp index b4e067e5fc90..7cb66f329438 100644 --- a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp +++ b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp @@ -561,8 +561,8 @@ class CIRCastOpLowering : public mlir::OpConversionPattern { auto dstTy = castOp.getResult().getType(); auto srcTy = castOp.getSrc().getType(); - if (!dstTy.isa() || - !srcTy.isa()) + if (!dstTy.isa() || + !srcTy.isa()) return castOp.emitError() << "NYI cast from " << srcTy << " to " << dstTy; @@ -571,7 +571,7 @@ class CIRCastOpLowering : public mlir::OpConversionPattern { getTypeConverter()->convertType(dstTy).cast(); auto getFloatWidth = [](mlir::Type ty) -> unsigned { - return ty.cast().getWidth(); + return ty.cast().getWidth(); }; if (getFloatWidth(srcTy) > getFloatWidth(dstTy)) @@ -984,7 +984,7 @@ lowerConstArrayAttr(mlir::cir::ConstArrayAttr constArr, if (type.isa()) return convertToDenseElementsAttr( constArr, dims, converter->convertType(type)); - if (type.isa()) + if (type.isa()) return convertToDenseElementsAttr( constArr, dims, converter->convertType(type)); @@ -1012,7 +1012,7 @@ class CIRConstantLowering attr = rewriter.getIntegerAttr( typeConverter->convertType(op.getType()), op.getValue().cast().getValue()); - } else if (op.getType().isa()) { + } else if (op.getType().isa()) { attr = rewriter.getFloatAttr( typeConverter->convertType(op.getType()), op.getValue().cast().getValue()); @@ -1603,7 +1603,7 @@ class CIRUnaryOpLowering } // Floating point unary operations: + - ++ -- - if (elementType.isa()) { + if (elementType.isa()) { switch (op.getKind()) { case mlir::cir::UnaryOpKind::Inc: { assert(!IsVector && "++ not allowed on vector types"); @@ -1682,7 +1682,7 @@ class CIRBinOpLowering : public mlir::OpConversionPattern { assert((op.getLhs().getType() == op.getRhs().getType()) && "inconsistent operands' types not supported yet"); mlir::Type type = op.getRhs().getType(); - assert((type.isa()) && "operand type not supported yet"); @@ -1903,7 +1903,7 @@ class CIRCmpOpLowering : public mlir::OpConversionPattern { auto kind = convertToICmpPredicate(cmpOp.getKind(), /* isSigned=*/false); llResult = rewriter.create( cmpOp.getLoc(), kind, adaptor.getLhs(), adaptor.getRhs()); - } else if (type.isa()) { + } else if (type.isa()) { auto kind = convertToFCmpPredicate(cmpOp.getKind()); llResult = rewriter.create( cmpOp.getLoc(), kind, adaptor.getLhs(), adaptor.getRhs());