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 1ee6dfd
Show file tree
Hide file tree
Showing 8 changed files with 13 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
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 1ee6dfd

Please sign in to comment.