Skip to content

Commit

Permalink
Remove !cir.f128 and !cir.ppc_doubledouble
Browse files Browse the repository at this point in the history
  • Loading branch information
Lancern committed Apr 16, 2024
1 parent 45b5af1 commit d6e918a
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 78 deletions.
18 changes: 2 additions & 16 deletions clang/include/clang/CIR/Dialect/IR/CIRTypes.td
Original file line number Diff line number Diff line change
Expand Up @@ -173,29 +173,15 @@ def CIR_FP80 : CIR_FloatType<"FP80", "f80"> {
}];
}

def CIR_FP128 : CIR_FloatType<"FP128", "f128"> {
let summary = "CIR type that represents IEEE-754 binary128 format";
let description = [{
Floating-point type that represents the IEEE-754 binary128 format";.
}];
}

def CIR_PPCDoubleDouble : CIR_FloatType<"PPCDoubleDouble", "ppc_doubledouble"> {
let summary = "CIR type that represents PowerPC double-double format";
let description = [{
Floating-point type that represents the PowerPC double-double format.
}];
}

def CIR_LongDouble : CIR_FloatType<"LongDouble", "long_double"> {
let summary = "CIR extended-precision float type";
let description = [{
Floating-point type that represents the `long double` type in C/C++.

The underlying floating-point format of a long double value depends on the
implementation. The `underlying` parameter specifies the CIR floating-point
type that corresponds to this format. It can be one of `!cir.double`,
`!cir.f80`, `!cir.f128`, or `!cir.ppc_doubledouble`.
type that corresponds to this format. For now, it can only be either
`!cir.double` or `!cir.fp80`.
}];

let parameters = (ins "mlir::Type":$underlying);
Expand Down
5 changes: 2 additions & 3 deletions clang/lib/CIR/CodeGen/CIRGenBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -380,10 +380,9 @@ class CIRGenBuilderTy : public CIRBaseBuilderTy {
if (&format == &llvm::APFloat::x87DoubleExtended())
return mlir::cir::LongDoubleType::get(getContext(), typeCache.FP80Ty);
if (&format == &llvm::APFloat::IEEEquad())
return mlir::cir::LongDoubleType::get(getContext(), typeCache.FP128Ty);
llvm_unreachable("NYI");
if (&format == &llvm::APFloat::PPCDoubleDouble())
return mlir::cir::LongDoubleType::get(getContext(),
typeCache.PPCDoubleDoubleTy);
llvm_unreachable("NYI");

llvm_unreachable("unsupported long double format");
}
Expand Down
3 changes: 0 additions & 3 deletions clang/lib/CIR/CodeGen/CIRGenModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,6 @@ CIRGenModule::CIRGenModule(mlir::MLIRContext &context,
FloatTy = ::mlir::cir::SingleType::get(builder.getContext());
DoubleTy = ::mlir::cir::DoubleType::get(builder.getContext());
FP80Ty = ::mlir::cir::FP80Type::get(builder.getContext());
FP128Ty = ::mlir::cir::FP128Type::get(builder.getContext());
PPCDoubleDoubleTy =
::mlir::cir::PPCDoubleDoubleType::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.

Expand Down
2 changes: 0 additions & 2 deletions clang/lib/CIR/CodeGen/CIRGenTypeCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ struct CIRGenTypeCache {
mlir::cir::SingleType FloatTy;
mlir::cir::DoubleType DoubleTy;
mlir::cir::FP80Type FP80Ty;
mlir::cir::FP128Type FP128Ty;
mlir::cir::PPCDoubleDoubleType PPCDoubleDoubleTy;

/// int
mlir::Type UIntTy;
Expand Down
45 changes: 1 addition & 44 deletions clang/lib/CIR/Dialect/IR/CIRTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -724,49 +724,6 @@ FP80Type::getPreferredAlignment(const ::mlir::DataLayout &dataLayout,
return 16;
}

const llvm::fltSemantics &FP128Type::getFloatSemantics() const {
return llvm::APFloat::IEEEquad();
}

llvm::TypeSize
FP128Type::getTypeSizeInBits(const mlir::DataLayout &dataLayout,
mlir::DataLayoutEntryListRef params) const {
return llvm::TypeSize::getFixed(getWidth());
}

uint64_t FP128Type::getABIAlignment(const mlir::DataLayout &dataLayout,
mlir::DataLayoutEntryListRef params) const {
return (uint64_t)(getWidth() / 8);
}

uint64_t
FP128Type::getPreferredAlignment(const ::mlir::DataLayout &dataLayout,
::mlir::DataLayoutEntryListRef params) const {
return (uint64_t)(getWidth() / 8);
}

const llvm::fltSemantics &PPCDoubleDoubleType::getFloatSemantics() const {
return llvm::APFloat::PPCDoubleDouble();
}

llvm::TypeSize PPCDoubleDoubleType::getTypeSizeInBits(
const mlir::DataLayout &dataLayout,
mlir::DataLayoutEntryListRef params) const {
return llvm::TypeSize::getFixed(getWidth());
}

uint64_t PPCDoubleDoubleType::getABIAlignment(
const mlir::DataLayout &dataLayout,
mlir::DataLayoutEntryListRef params) const {
return (uint64_t)(getWidth() / 8);
}

uint64_t PPCDoubleDoubleType::getPreferredAlignment(
const ::mlir::DataLayout &dataLayout,
::mlir::DataLayoutEntryListRef params) const {
return (uint64_t)(getWidth() / 8);
}

const llvm::fltSemantics &LongDoubleType::getFloatSemantics() const {
return getUnderlying()
.cast<mlir::cir::CIRFPTypeInterface>()
Expand Down Expand Up @@ -799,7 +756,7 @@ uint64_t LongDoubleType::getPreferredAlignment(
LogicalResult
LongDoubleType::verify(function_ref<InFlightDiagnostic()> emitError,
mlir::Type underlying) {
if (!underlying.isa<DoubleType, FP80Type, FP128Type, PPCDoubleDoubleType>()) {
if (!underlying.isa<DoubleType, FP80Type>()) {
emitError() << "invalid underlying type for long double";
return failure();
}
Expand Down
7 changes: 0 additions & 7 deletions clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3129,13 +3129,6 @@ void prepareTypeConverter(mlir::LLVMTypeConverter &converter,
converter.addConversion([&](mlir::cir::FP80Type type) -> mlir::Type {
return mlir::FloatType::getF80(type.getContext());
});
converter.addConversion([&](mlir::cir::FP128Type type) -> mlir::Type {
return mlir::FloatType::getF128(type.getContext());
});
converter.addConversion(
[&](mlir::cir::PPCDoubleDoubleType type) -> mlir::Type {
return mlir::LLVM::LLVMPPCFP128Type::get(type.getContext());
});
converter.addConversion([&](mlir::cir::LongDoubleType type) -> mlir::Type {
return converter.convertType(type.getUnderlying());
});
Expand Down
29 changes: 29 additions & 0 deletions clang/test/CIR/CodeGen/builtin-floating-point.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -ffast-math -fclangir-enable -emit-cir %s -o - | FileCheck %s
// RUN: %clang_cc1 -triple aarch64-apple-darwin-macho -ffast-math -fclangir-enable -emit-cir %s -o - | FileCheck %s --check-prefix=AARCH64

// ceil

Expand All @@ -18,6 +19,7 @@ long double my_ceill(long double f) {
return __builtin_ceill(f);
// CHECK: cir.func @my_ceill
// CHECK: {{.+}} = cir.ceil {{.+}} : !cir.long_double<!cir.f80>
// AARCH64: {{.+}} = cir.ceil {{.+}} : !cir.long_double<!cir.double>
}

float ceilf(float);
Expand All @@ -40,6 +42,7 @@ long double call_ceill(long double f) {
return ceill(f);
// CHECK: cir.func @call_ceill
// CHECK: {{.+}} = cir.ceil {{.+}} : !cir.long_double<!cir.f80>
// AARCH64: {{.+}} = cir.ceil {{.+}} : !cir.long_double<!cir.double>
}

// cos
Expand All @@ -60,6 +63,7 @@ long double my_cosl(long double f) {
return __builtin_cosl(f);
// CHECK: cir.func @my_cosl
// CHECK: {{.+}} = cir.cos {{.+}} : !cir.long_double<!cir.f80>
// AARCH64: {{.+}} = cir.cos {{.+}} : !cir.long_double<!cir.double>
}

float cosf(float);
Expand All @@ -82,6 +86,7 @@ long double call_cosl(long double f) {
return cosl(f);
// CHECK: cir.func @call_cosl
// CHECK: {{.+}} = cir.cos {{.+}} : !cir.long_double<!cir.f80>
// AARCH64: {{.+}} = cir.cos {{.+}} : !cir.long_double<!cir.double>
}

// exp
Expand All @@ -102,6 +107,7 @@ long double my_expl(long double f) {
return __builtin_expl(f);
// CHECK: cir.func @my_expl
// CHECK: {{.+}} = cir.exp {{.+}} : !cir.long_double<!cir.f80>
// AARCH64: {{.+}} = cir.exp {{.+}} : !cir.long_double<!cir.double>
}

float expf(float);
Expand All @@ -124,6 +130,7 @@ long double call_expl(long double f) {
return expl(f);
// CHECK: cir.func @call_expl
// CHECK: {{.+}} = cir.exp {{.+}} : !cir.long_double<!cir.f80>
// AARCH64: {{.+}} = cir.exp {{.+}} : !cir.long_double<!cir.double>
}

// exp2
Expand All @@ -144,6 +151,7 @@ long double my_exp2l(long double f) {
return __builtin_exp2l(f);
// CHECK: cir.func @my_exp2l
// CHECK: {{.+}} = cir.exp2 {{.+}} : !cir.long_double<!cir.f80>
// AARCH64: {{.+}} = cir.exp2 {{.+}} : !cir.long_double<!cir.double>
}

float exp2f(float);
Expand All @@ -166,6 +174,7 @@ long double call_exp2l(long double f) {
return exp2l(f);
// CHECK: cir.func @call_exp2l
// CHECK: {{.+}} = cir.exp2 {{.+}} : !cir.long_double<!cir.f80>
// AARCH64: {{.+}} = cir.exp2 {{.+}} : !cir.long_double<!cir.double>
}

// floor
Expand All @@ -186,6 +195,7 @@ long double my_floorl(long double f) {
return __builtin_floorl(f);
// CHECK: cir.func @my_floorl
// CHECK: {{.+}} = cir.floor {{.+}} : !cir.long_double<!cir.f80>
// AARCH64: {{.+}} = cir.floor {{.+}} : !cir.long_double<!cir.double>
}

float floorf(float);
Expand All @@ -208,6 +218,7 @@ long double call_floorl(long double f) {
return floorl(f);
// CHECK: cir.func @call_floorl
// CHECK: {{.+}} = cir.floor {{.+}} : !cir.long_double<!cir.f80>
// AARCH64: {{.+}} = cir.floor {{.+}} : !cir.long_double<!cir.double>
}

// log
Expand All @@ -228,6 +239,7 @@ long double my_logl(long double f) {
return __builtin_logl(f);
// CHECK: cir.func @my_logl
// CHECK: {{.+}} = cir.log {{.+}} : !cir.long_double<!cir.f80>
// AARCH64: {{.+}} = cir.log {{.+}} : !cir.long_double<!cir.double>
}

float logf(float);
Expand All @@ -250,6 +262,7 @@ long double call_logl(long double f) {
return logl(f);
// CHECK: cir.func @call_logl
// CHECK: {{.+}} = cir.log {{.+}} : !cir.long_double<!cir.f80>
// AARCH64: {{.+}} = cir.log {{.+}} : !cir.long_double<!cir.double>
}

// log10
Expand All @@ -270,6 +283,7 @@ long double my_log10l(long double f) {
return __builtin_log10l(f);
// CHECK: cir.func @my_log10l
// CHECK: {{.+}} = cir.log10 {{.+}} : !cir.long_double<!cir.f80>
// AARCH64: {{.+}} = cir.log10 {{.+}} : !cir.long_double<!cir.double>
}

float log10f(float);
Expand All @@ -292,6 +306,7 @@ long double call_log10l(long double f) {
return log10l(f);
// CHECK: cir.func @call_log10l
// CHECK: {{.+}} = cir.log10 {{.+}} : !cir.long_double<!cir.f80>
// AARCH64: {{.+}} = cir.log10 {{.+}} : !cir.long_double<!cir.double>
}

// log2
Expand All @@ -312,6 +327,7 @@ long double my_log2l(long double f) {
return __builtin_log2l(f);
// CHECK: cir.func @my_log2l
// CHECK: {{.+}} = cir.log2 {{.+}} : !cir.long_double<!cir.f80>
// AARCH64: {{.+}} = cir.log2 {{.+}} : !cir.long_double<!cir.double>
}

float log2f(float);
Expand All @@ -334,6 +350,7 @@ long double call_log2l(long double f) {
return log2l(f);
// CHECK: cir.func @call_log2l
// CHECK: {{.+}} = cir.log2 {{.+}} : !cir.long_double<!cir.f80>
// AARCH64: {{.+}} = cir.log2 {{.+}} : !cir.long_double<!cir.double>
}

// nearbyint
Expand All @@ -354,6 +371,7 @@ long double my_nearbyintl(long double f) {
return __builtin_nearbyintl(f);
// CHECK: cir.func @my_nearbyintl
// CHECK: {{.+}} = cir.nearbyint {{.+}} : !cir.long_double<!cir.f80>
// AARCH64: {{.+}} = cir.nearbyint {{.+}} : !cir.long_double<!cir.double>
}

float nearbyintf(float);
Expand All @@ -376,6 +394,7 @@ long double call_nearbyintl(long double f) {
return nearbyintl(f);
// CHECK: cir.func @call_nearbyintl
// CHECK: {{.+}} = cir.nearbyint {{.+}} : !cir.long_double<!cir.f80>
// AARCH64: {{.+}} = cir.nearbyint {{.+}} : !cir.long_double<!cir.double>
}

// rint
Expand All @@ -396,6 +415,7 @@ long double my_rintl(long double f) {
return __builtin_rintl(f);
// CHECK: cir.func @my_rintl
// CHECK: {{.+}} = cir.rint {{.+}} : !cir.long_double<!cir.f80>
// AARCH64: {{.+}} = cir.rint {{.+}} : !cir.long_double<!cir.double>
}

float rintf(float);
Expand All @@ -418,6 +438,7 @@ long double call_rintl(long double f) {
return rintl(f);
// CHECK: cir.func @call_rintl
// CHECK: {{.+}} = cir.rint {{.+}} : !cir.long_double<!cir.f80>
// AARCH64: {{.+}} = cir.rint {{.+}} : !cir.long_double<!cir.double>
}

// round
Expand All @@ -438,6 +459,7 @@ long double my_roundl(long double f) {
return __builtin_roundl(f);
// CHECK: cir.func @my_roundl
// CHECK: {{.+}} = cir.round {{.+}} : !cir.long_double<!cir.f80>
// AARCH64: {{.+}} = cir.round {{.+}} : !cir.long_double<!cir.double>
}

float roundf(float);
Expand All @@ -460,6 +482,7 @@ long double call_roundl(long double f) {
return roundl(f);
// CHECK: cir.func @call_roundl
// CHECK: {{.+}} = cir.round {{.+}} : !cir.long_double<!cir.f80>
// AARCH64: {{.+}} = cir.round {{.+}} : !cir.long_double<!cir.double>
}

// sin
Expand All @@ -480,6 +503,7 @@ long double my_sinl(long double f) {
return __builtin_sinl(f);
// CHECK: cir.func @my_sinl
// CHECK: {{.+}} = cir.sin {{.+}} : !cir.long_double<!cir.f80>
// AARCH64: {{.+}} = cir.sin {{.+}} : !cir.long_double<!cir.double>
}

float sinf(float);
Expand All @@ -502,6 +526,7 @@ long double call_sinl(long double f) {
return sinl(f);
// CHECK: cir.func @call_sinl
// CHECK: {{.+}} = cir.sin {{.+}} : !cir.long_double<!cir.f80>
// AARCH64: {{.+}} = cir.sin {{.+}} : !cir.long_double<!cir.double>
}

// sqrt
Expand All @@ -522,6 +547,7 @@ long double my_sqrtl(long double f) {
return __builtin_sqrtl(f);
// CHECK: cir.func @my_sqrtl
// CHECK: {{.+}} = cir.sqrt {{.+}} : !cir.long_double<!cir.f80>
// AARCH64: {{.+}} = cir.sqrt {{.+}} : !cir.long_double<!cir.double>
}

float sqrtf(float);
Expand All @@ -544,6 +570,7 @@ long double call_sqrtl(long double f) {
return sqrtl(f);
// CHECK: cir.func @call_sqrtl
// CHECK: {{.+}} = cir.sqrt {{.+}} : !cir.long_double<!cir.f80>
// AARCH64: {{.+}} = cir.sqrt {{.+}} : !cir.long_double<!cir.double>
}

// trunc
Expand All @@ -564,6 +591,7 @@ long double my_truncl(long double f) {
return __builtin_truncl(f);
// CHECK: cir.func @my_truncl
// CHECK: {{.+}} = cir.trunc {{.+}} : !cir.long_double<!cir.f80>
// AARCH64: {{.+}} = cir.trunc {{.+}} : !cir.long_double<!cir.double>
}

float truncf(float);
Expand All @@ -586,4 +614,5 @@ long double call_truncl(long double f) {
return truncl(f);
// CHECK: cir.func @call_truncl
// CHECK: {{.+}} = cir.trunc {{.+}} : !cir.long_double<!cir.f80>
// AARCH64: {{.+}} = cir.trunc {{.+}} : !cir.long_double<!cir.double>
}
7 changes: 7 additions & 0 deletions clang/test/CIR/IR/invalid.cir
Original file line number Diff line number Diff line change
Expand Up @@ -1042,3 +1042,10 @@ cir.func @bad_fetch(%x: !cir.ptr<!cir.float>, %y: !cir.float) -> () {
%12 = cir.atomic.fetch(xor, %x : !cir.ptr<!cir.float>, %y : !cir.float, seq_cst) : !cir.float
cir.return
}

// -----

// expected-error@+1 {{invalid underlying type for long double}}
cir.func @bad_long_double(%arg0 : !cir.long_double<!cir.float>) -> () {
cir.return
}
4 changes: 1 addition & 3 deletions clang/test/CIR/Lowering/float.cir
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ module {
// CHECK: %{{.+}} = llvm.mlir.constant(1.000000e+00 : f32) : f32
%2 = cir.const(#cir.fp<1.0> : !cir.double) : !cir.double
// CHECK: %{{.+}} = llvm.mlir.constant(1.000000e+00 : f64) : f64
%3 = cir.const(#cir.fp<1.0> : !cir.long_double<!cir.f128>) : !cir.long_double<!cir.f128>
// CHECK: %{{.+}} = llvm.mlir.constant(1.000000e+00 : f128) : f128
%4 = cir.const(#cir.fp<1.0> : !cir.long_double<!cir.f80>) : !cir.long_double<!cir.f80>
%3 = cir.const(#cir.fp<1.0> : !cir.long_double<!cir.f80>) : !cir.long_double<!cir.f80>
// CHECK: %{{.+}} = llvm.mlir.constant(1.000000e+00 : f80) : f80
// %5 = cir.const(1.0 : bf16) : bf16
// DISABLED-CHECK: %{{.+}} = llvm.mlir.constant(1.000000e+00 : bf16) : bf16
Expand Down

0 comments on commit d6e918a

Please sign in to comment.