Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
Original file line number Diff line number Diff line change
Expand Up @@ -444,17 +444,17 @@ def FPAttr : CIR_Attr<"FP", "fp", [TypedAttrInterface]> {
value of the specified floating-point type. Supporting only CIR FP types.
}];
let parameters = (ins
AttributeSelfTypeParameter<"", "::cir::CIRFPTypeInterface">:$type,
AttributeSelfTypeParameter<"", "::cir::FPTypeInterface">:$type,
APFloatParameter<"">:$value
);
let builders = [
AttrBuilderWithInferredContext<(ins "mlir::Type":$type,
"const llvm::APFloat &":$value), [{
return $_get(type.getContext(), mlir::cast<CIRFPTypeInterface>(type), value);
return $_get(type.getContext(), mlir::cast<FPTypeInterface>(type), value);
}]>,
AttrBuilder<(ins "mlir::Type":$type,
"const llvm::APFloat &":$value), [{
return $_get($_ctxt, mlir::cast<CIRFPTypeInterface>(type), value);
return $_get($_ctxt, mlir::cast<FPTypeInterface>(type), value);
}]>,
];
let extraClassDeclaration = [{
Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/CIR/Dialect/IR/CIRTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "mlir/Interfaces/DataLayoutInterfaces.h"
#include "clang/CIR/Dialect/IR/CIROpsEnums.h"
#include "clang/CIR/Interfaces/ASTAttrInterfaces.h"
#include "clang/CIR/Interfaces/CIRFPTypeInterface.h"
#include "clang/CIR/Interfaces/CIRTypeInterfaces.h"

namespace cir {
namespace detail {
Expand Down
4 changes: 2 additions & 2 deletions clang/include/clang/CIR/Dialect/IR/CIRTypes.td
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
include "clang/CIR/Dialect/IR/CIRDialect.td"
include "clang/CIR/Dialect/IR/CIRTypeConstraints.td"
include "clang/CIR/Interfaces/ASTAttrInterfaces.td"
include "clang/CIR/Interfaces/CIRFPTypeInterface.td"
include "clang/CIR/Interfaces/CIRTypeInterfaces.td"
include "mlir/Interfaces/DataLayoutInterfaces.td"
include "mlir/IR/AttrTypeBase.td"
include "mlir/IR/EnumAttr.td"
Expand Down Expand Up @@ -82,7 +82,7 @@ def CIR_IntType : CIR_Type<"Int", "int",

class CIR_FloatType<string name, string mnemonic> : CIR_Type<name, mnemonic, [
DeclareTypeInterfaceMethods<DataLayoutTypeInterface>,
DeclareTypeInterfaceMethods<CIRFPTypeInterface>
DeclareTypeInterfaceMethods<CIR_FPTypeInterface>
]>;

def CIR_Single : CIR_FloatType<"Single", "float"> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
//===- CIRFPTypeInterface.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.
// Defines cir type interfaces.
//
//===----------------------------------------------------------------------===//

#ifndef CLANG_INTERFACES_CIR_CIR_FPTYPEINTERFACE_H
#define CLANG_INTERFACES_CIR_CIR_FPTYPEINTERFACE_H
#ifndef CLANG_CIR_INTERFACES_CIRTYPEINTERFACES_H
#define CLANG_CIR_INTERFACES_CIRTYPEINTERFACES_H

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

/// Include the tablegen'd interface declarations.
#include "clang/CIR/Interfaces/CIRFPTypeInterface.h.inc"
#include "clang/CIR/Interfaces/CIRTypeInterfaces.h.inc"

#endif // CLANG_INTERFACES_CIR_CIR_FPTYPEINTERFACE_H
#endif // CLANG_CIR_INTERFACES_CIRTYPEINTERFACES_H
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
//===- CIRFPTypeInterface.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
//
//===----------------------------------------------------------------------===//
//
// Defines cir type interfaces.
//
//===----------------------------------------------------------------------===//

#ifndef MLIR_CIR_INTERFACES_CIR_FP_TYPE_INTERFACE
#define MLIR_CIR_INTERFACES_CIR_FP_TYPE_INTERFACE
#ifndef CLANG_CIR_INTERFACES_CIRTYPEINTERFACES_TD
#define CLANG_CIR_INTERFACES_CIRTYPEINTERFACES_TD

include "mlir/IR/OpBase.td"

def CIRFPTypeInterface : TypeInterface<"CIRFPTypeInterface"> {
def CIR_FPTypeInterface : TypeInterface<"FPTypeInterface"> {
let description = [{
Contains helper functions to query properties about a floating-point type.
}];
Expand Down Expand Up @@ -49,4 +53,4 @@ def CIRFPTypeInterface : TypeInterface<"CIRFPTypeInterface"> {
];
}

#endif // MLIR_CIR_INTERFACES_CIR_FP_TYPE_INTERFACE
#endif // CLANG_CIR_INTERFACES_CIRTYPEINTERFACES_TD
2 changes: 1 addition & 1 deletion clang/include/clang/CIR/Interfaces/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ endfunction()
add_clang_mlir_attr_interface(ASTAttrInterfaces)
add_clang_mlir_op_interface(CIROpInterfaces)
add_clang_mlir_op_interface(CIRLoopOpInterface)
add_clang_mlir_type_interface(CIRFPTypeInterface)
add_clang_mlir_type_interface(CIRTypeInterfaces)
2 changes: 1 addition & 1 deletion clang/lib/CIR/CodeGen/CIRGenBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy {

bool isSized(mlir::Type ty) {
if (mlir::isa<cir::PointerType, cir::RecordType, cir::ArrayType,
cir::BoolType, cir::IntType, cir::CIRFPTypeInterface,
cir::BoolType, cir::IntType, cir::FPTypeInterface,
cir::ComplexType>(ty))
return true;
if (mlir::isa<cir::VectorType>(ty)) {
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "CIRGenCstEmitter.h"
#include "CIRGenFunction.h"
#include "clang/Basic/LangOptions.h"
#include "clang/CIR/Interfaces/CIRFPTypeInterface.h"
#include "clang/CIR/Interfaces/CIRTypeInterfaces.h"
#include "clang/CIR/MissingFeatures.h"

#include "mlir/IR/Location.h"
Expand Down Expand Up @@ -844,7 +844,7 @@ ComplexExprEmitter::VisitImaginaryLiteral(const ImaginaryLiteral *IL) {
auto ImagValue = cast<IntegerLiteral>(IL->getSubExpr())->getValue();
RealValueAttr = cir::IntAttr::get(ElementTy, 0);
ImagValueAttr = cir::IntAttr::get(ElementTy, ImagValue);
} else if (mlir::isa<cir::CIRFPTypeInterface>(ElementTy)) {
} else if (mlir::isa<cir::FPTypeInterface>(ElementTy)) {
auto ImagValue = cast<FloatingLiteral>(IL->getSubExpr())->getValue();
RealValueAttr = cir::FPAttr::get(
ElementTy, llvm::APFloat::getZero(ImagValue.getSemantics()));
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/CIR/CodeGen/CIRGenExprConst.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1916,7 +1916,7 @@ mlir::Attribute ConstantEmitter::tryEmitPrivate(const APValue &Value,
assert(0 && "not implemented");
else {
mlir::Type ty = CGM.convertType(DestType);
assert(mlir::isa<cir::CIRFPTypeInterface>(ty) &&
assert(mlir::isa<cir::FPTypeInterface>(ty) &&
"expected floating-point type");
return CGM.getBuilder().getAttr<cir::FPAttr>(ty, Init);
}
Expand Down Expand Up @@ -2022,7 +2022,7 @@ mlir::Attribute ConstantEmitter::tryEmitPrivate(const APValue &Value,
builder.getAttr<cir::IntAttr>(complexElemTy, imag));
}

assert(isa<cir::CIRFPTypeInterface>(complexElemTy) &&
assert(isa<cir::FPTypeInterface>(complexElemTy) &&
"expected floating-point type");
llvm::APFloat real = Value.getComplexFloatReal();
llvm::APFloat imag = Value.getComplexFloatImag();
Expand Down
15 changes: 7 additions & 8 deletions clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,7 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
}
mlir::Value VisitFloatingLiteral(const FloatingLiteral *E) {
mlir::Type Ty = CGF.convertType(E->getType());
assert(mlir::isa<cir::CIRFPTypeInterface>(Ty) &&
"expect floating-point type");
assert(mlir::isa<cir::FPTypeInterface>(Ty) && "expect floating-point type");
return Builder.create<cir::ConstantOp>(
CGF.getLoc(E->getExprLoc()),
Builder.getAttr<cir::FPAttr>(Ty, E->getValue()));
Expand Down Expand Up @@ -1047,7 +1046,7 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
if (SrcType->isHalfType() &&
!CGF.getContext().getLangOpts().NativeHalfType) {
// Cast to FP using the intrinsic if the half type itself isn't supported.
if (mlir::isa<cir::CIRFPTypeInterface>(DstTy)) {
if (mlir::isa<cir::FPTypeInterface>(DstTy)) {
if (CGF.getContext().getTargetInfo().useFP16ConversionIntrinsics())
llvm_unreachable("cast via llvm.convert.from.fp16 is NYI");
} else {
Expand Down Expand Up @@ -1118,7 +1117,7 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
if (DstType->isHalfType() &&
!CGF.getContext().getLangOpts().NativeHalfType) {
// Make sure we cast in a single step if from another FP type.
if (mlir::isa<cir::CIRFPTypeInterface>(SrcTy)) {
if (mlir::isa<cir::FPTypeInterface>(SrcTy)) {
// Use the intrinsic if the half type itself isn't supported
// (as opposed to operations on half, available with NativeHalfType).
if (CGF.getContext().getTargetInfo().useFP16ConversionIntrinsics())
Expand Down Expand Up @@ -2118,20 +2117,20 @@ mlir::Value ScalarExprEmitter::emitScalarCast(mlir::Value Src, QualType SrcType,
llvm_unreachable("NYI: signed bool");
if (CGF.getBuilder().isInt(DstTy)) {
CastKind = cir::CastKind::bool_to_int;
} else if (mlir::isa<cir::CIRFPTypeInterface>(DstTy)) {
} else if (mlir::isa<cir::FPTypeInterface>(DstTy)) {
CastKind = cir::CastKind::bool_to_float;
} else {
llvm_unreachable("Internal error: Cast to unexpected type");
}
} else if (CGF.getBuilder().isInt(SrcTy)) {
if (CGF.getBuilder().isInt(DstTy)) {
CastKind = cir::CastKind::integral;
} else if (mlir::isa<cir::CIRFPTypeInterface>(DstTy)) {
} else if (mlir::isa<cir::FPTypeInterface>(DstTy)) {
CastKind = cir::CastKind::int_to_float;
} else {
llvm_unreachable("Internal error: Cast to unexpected type");
}
} else if (mlir::isa<cir::CIRFPTypeInterface>(SrcTy)) {
} else if (mlir::isa<cir::FPTypeInterface>(SrcTy)) {
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
Expand All @@ -2141,7 +2140,7 @@ mlir::Value ScalarExprEmitter::emitScalarCast(mlir::Value Src, QualType SrcType,
if (Builder.getIsFPConstrained())
llvm_unreachable("NYI");
CastKind = cir::CastKind::float_to_int;
} else if (mlir::isa<cir::CIRFPTypeInterface>(DstTy)) {
} else if (mlir::isa<cir::FPTypeInterface>(DstTy)) {
// TODO: split this to createFPExt/createFPTrunc
return Builder.createFloatingCast(Src, FullDstTy);
} else {
Expand Down
8 changes: 4 additions & 4 deletions clang/lib/CIR/Dialect/IR/CIRAttrs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ static void printFloatLiteral(mlir::AsmPrinter &p, llvm::APFloat value,
static mlir::ParseResult
parseFloatLiteral(mlir::AsmParser &parser,
mlir::FailureOr<llvm::APFloat> &value,
cir::CIRFPTypeInterface fpType);
cir::FPTypeInterface fpType);

static mlir::ParseResult parseConstPtr(mlir::AsmParser &parser,
mlir::IntegerAttr &value);
Expand Down Expand Up @@ -276,7 +276,7 @@ static void printFloatLiteral(AsmPrinter &p, APFloat value, Type ty) {

static ParseResult parseFloatLiteral(AsmParser &parser,
FailureOr<APFloat> &value,
CIRFPTypeInterface fpType) {
cir::FPTypeInterface fpType) {

APFloat parsedValue(0.0);
if (parser.parseFloat(fpType.getFloatSemantics(), parsedValue))
Expand All @@ -289,11 +289,11 @@ static ParseResult parseFloatLiteral(AsmParser &parser,
FPAttr FPAttr::getZero(Type type) {
return get(type,
APFloat::getZero(
mlir::cast<CIRFPTypeInterface>(type).getFloatSemantics()));
mlir::cast<cir::FPTypeInterface>(type).getFloatSemantics()));
}

LogicalResult FPAttr::verify(function_ref<InFlightDiagnostic()> emitError,
CIRFPTypeInterface fpType, APFloat value) {
cir::FPTypeInterface fpType, APFloat value) {
if (APFloat::SemanticsToEnum(fpType.getFloatSemantics()) !=
APFloat::SemanticsToEnum(value.getSemantics()))
return emitError() << "floating-point semantics mismatch";
Expand Down
16 changes: 8 additions & 8 deletions clang/lib/CIR/Dialect/IR/CIRDialect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -579,13 +579,13 @@ LogicalResult cir::CastOp::verify() {
return success();
}
case cir::CastKind::floating: {
if (!mlir::isa<cir::CIRFPTypeInterface>(srcType) ||
!mlir::isa<cir::CIRFPTypeInterface>(resType))
if (!mlir::isa<cir::FPTypeInterface>(srcType) ||
!mlir::isa<cir::FPTypeInterface>(resType))
return emitOpError() << "requires !cir.float type for source and result";
return success();
}
case cir::CastKind::float_to_int: {
if (!mlir::isa<cir::CIRFPTypeInterface>(srcType))
if (!mlir::isa<cir::FPTypeInterface>(srcType))
return emitOpError() << "requires !cir.float type for source";
if (!mlir::dyn_cast<cir::IntType>(resType))
return emitOpError() << "requires !cir.int type for result";
Expand All @@ -606,7 +606,7 @@ LogicalResult cir::CastOp::verify() {
return success();
}
case cir::CastKind::float_to_bool: {
if (!mlir::isa<cir::CIRFPTypeInterface>(srcType))
if (!mlir::isa<cir::FPTypeInterface>(srcType))
return emitOpError() << "requires !cir.float type for source";
if (!mlir::isa<cir::BoolType>(resType))
return emitOpError() << "requires !cir.bool type for result";
Expand All @@ -622,14 +622,14 @@ LogicalResult cir::CastOp::verify() {
case cir::CastKind::int_to_float: {
if (!mlir::isa<cir::IntType>(srcType))
return emitOpError() << "requires !cir.int type for source";
if (!mlir::isa<cir::CIRFPTypeInterface>(resType))
if (!mlir::isa<cir::FPTypeInterface>(resType))
return emitOpError() << "requires !cir.float type for result";
return success();
}
case cir::CastKind::bool_to_float: {
if (!mlir::isa<cir::BoolType>(srcType))
return emitOpError() << "requires !cir.bool type for source";
if (!mlir::isa<cir::CIRFPTypeInterface>(resType))
if (!mlir::isa<cir::FPTypeInterface>(resType))
return emitOpError() << "requires !cir.float type for result";
return success();
}
Expand All @@ -643,7 +643,7 @@ LogicalResult cir::CastOp::verify() {
return success();
}
case cir::CastKind::float_to_complex: {
if (!mlir::isa<cir::CIRFPTypeInterface>(srcType))
if (!mlir::isa<cir::FPTypeInterface>(srcType))
return emitOpError() << "requires !cir.float type for source";
auto resComplexTy = mlir::dyn_cast<cir::ComplexType>(resType);
if (!resComplexTy)
Expand All @@ -666,7 +666,7 @@ LogicalResult cir::CastOp::verify() {
auto srcComplexTy = mlir::dyn_cast<cir::ComplexType>(srcType);
if (!srcComplexTy)
return emitOpError() << "requires !cir.complex type for source";
if (!mlir::isa<cir::CIRFPTypeInterface>(resType))
if (!mlir::isa<cir::FPTypeInterface>(resType))
return emitOpError() << "requires !cir.float type for result";
if (srcComplexTy.getElementType() != resType)
return emitOpError() << "requires source element type match result type";
Expand Down
5 changes: 2 additions & 3 deletions clang/lib/CIR/Dialect/IR/CIRTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include "mlir/Support/LogicalResult.h"

#include "clang/CIR/Interfaces/ASTAttrInterfaces.h"
#include "clang/CIR/Interfaces/CIRFPTypeInterface.h"
#include "clang/CIR/Interfaces/CIRTypeInterfaces.h"
#include "llvm/ADT/APFloat.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallVector.h"
Expand Down Expand Up @@ -732,8 +732,7 @@ uint64_t FP128Type::getABIAlignment(const mlir::DataLayout &dataLayout,
}

const llvm::fltSemantics &LongDoubleType::getFloatSemantics() const {
return mlir::cast<cir::CIRFPTypeInterface>(getUnderlying())
.getFloatSemantics();
return mlir::cast<cir::FPTypeInterface>(getUnderlying()).getFloatSemantics();
}

llvm::TypeSize
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/CIR/Dialect/Transforms/LoweringPrepare.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ static mlir::Value buildComplexBinOpLibCall(
llvm::StringRef (*libFuncNameGetter)(llvm::APFloat::Semantics),
mlir::Location loc, cir::ComplexType ty, mlir::Value lhsReal,
mlir::Value lhsImag, mlir::Value rhsReal, mlir::Value rhsImag) {
auto elementTy = mlir::cast<cir::CIRFPTypeInterface>(ty.getElementType());
auto elementTy = mlir::cast<cir::FPTypeInterface>(ty.getElementType());

auto libFuncName = libFuncNameGetter(
llvm::APFloat::SemanticsToEnum(elementTy.getFloatSemantics()));
Expand Down Expand Up @@ -807,7 +807,7 @@ static mlir::Value lowerComplexDiv(LoweringPreparePass &pass,
mlir::Value lhsReal, mlir::Value lhsImag,
mlir::Value rhsReal, mlir::Value rhsImag) {
auto ty = op.getType();
if (mlir::isa<cir::CIRFPTypeInterface>(ty.getElementType())) {
if (mlir::isa<cir::FPTypeInterface>(ty.getElementType())) {
auto range = op.getRange();
if (range == cir::ComplexRangeKind::Improved ||
(range == cir::ComplexRangeKind::Promoted && !op.getPromoted()))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
//====- CIRFPTypeInterface.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/CIRFPTypeInterface.h"
#include "clang/CIR/Interfaces/CIRTypeInterfaces.h"

using namespace cir;

/// Include the generated interfaces.
#include "clang/CIR/Interfaces/CIRFPTypeInterface.cpp.inc"
#include "clang/CIR/Interfaces/CIRTypeInterfaces.cpp.inc"
4 changes: 2 additions & 2 deletions clang/lib/CIR/Interfaces/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ add_clang_library(MLIRCIRInterfaces
ASTAttrInterfaces.cpp
CIROpInterfaces.cpp
CIRLoopOpInterface.cpp
CIRFPTypeInterface.cpp
CIRTypeInterfaces.cpp

ADDITIONAL_HEADER_DIRS
${MLIR_MAIN_INCLUDE_DIR}/mlir/Interfaces

DEPENDS
MLIRCIRASTAttrInterfacesIncGen
MLIRCIREnumsGen
MLIRCIRFPTypeInterfaceIncGen
MLIRCIRTypeInterfacesIncGen
MLIRCIRLoopOpInterfaceIncGen
MLIRCIROpInterfacesIncGen

Expand Down
Loading
Loading