Skip to content

Commit 2bb801f

Browse files
committed
[flang] Modifications to ieee_support_standard
Some Arm processors support exception halting control and some do not. An Arm executable will run on either type of processor, so it is effectively unknown at compile time whether or not this support will be available. ieee_support_halting is therefore implemented with a runtime check. The result of a call to ieee_support_standard depends in part on support for halting control. Update the ieee_support_standard implementation to check for support for halting control at runtime.
1 parent 5fd1888 commit 2bb801f

File tree

4 files changed

+28
-6
lines changed

4 files changed

+28
-6
lines changed

flang/docs/Extensions.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,15 @@ end
150150
have this capability. An Arm executable will run on either type of
151151
processor, so it is effectively unknown at compile time whether or
152152
not this support will be available at runtime. The standard requires
153-
that a call to intrinsic module procedure `IEEE_SUPPORT_HALTING` with
153+
that a call to intrinsic module procedure `ieee_support_halting` with
154154
a constant argument has a compile time constant result in `constant
155155
expression` and `specification expression` contexts. In compilations
156156
where this information is not known at compile time, f18 generates code
157157
to determine the absence or presence of this capability at runtime.
158-
A call to `IEEE_SUPPORT_HALTING` in contexts that the standard requires
159-
to be constant will generate a compilation error.
158+
A call to `ieee_support_halting` in contexts that the standard requires
159+
to be constant will generate a compilation error. `ieee_support_standard`
160+
depends in part on `ieee_support_halting`, so this also applies to
161+
`ieee_support_standard` calls.
160162

161163
## Extensions, deletions, and legacy features supported by default
162164

flang/include/flang/Optimizer/Builder/IntrinsicCall.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,8 @@ struct IntrinsicLibrary {
314314
fir::ExtendedValue genIeeeSupportHalting(mlir::Type,
315315
llvm::ArrayRef<fir::ExtendedValue>);
316316
mlir::Value genIeeeSupportRounding(mlir::Type, llvm::ArrayRef<mlir::Value>);
317+
fir::ExtendedValue genIeeeSupportStandard(mlir::Type,
318+
llvm::ArrayRef<fir::ExtendedValue>);
317319
template <mlir::arith::CmpIPredicate pred>
318320
mlir::Value genIeeeTypeCompare(mlir::Type, llvm::ArrayRef<mlir::Value>);
319321
mlir::Value genIeeeUnordered(mlir::Type, llvm::ArrayRef<mlir::Value>);

flang/lib/Evaluate/fold-logical.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -882,7 +882,7 @@ Expr<Type<TypeCategory::Logical, KIND>> FoldIntrinsicFunction(
882882
IeeeFeature::Flags)};
883883
} else if (name == "__builtin_ieee_support_halting") {
884884
if (!context.targetCharacteristics()
885-
.haltingSupportIsUnknownAtCompileTime()) {
885+
.haltingSupportIsUnknownAtCompileTime()) {
886886
return Expr<T>{context.targetCharacteristics().ieeeFeatures().test(
887887
IeeeFeature::Halting)};
888888
}
@@ -906,8 +906,12 @@ Expr<Type<TypeCategory::Logical, KIND>> FoldIntrinsicFunction(
906906
return Expr<T>{
907907
context.targetCharacteristics().ieeeFeatures().test(IeeeFeature::Sqrt)};
908908
} else if (name == "__builtin_ieee_support_standard") {
909-
return Expr<T>{context.targetCharacteristics().ieeeFeatures().test(
910-
IeeeFeature::Standard)};
909+
// ieee_support_standard depends in part on ieee_support_halting.
910+
if (!context.targetCharacteristics()
911+
.haltingSupportIsUnknownAtCompileTime()) {
912+
return Expr<T>{context.targetCharacteristics().ieeeFeatures().test(
913+
IeeeFeature::Standard)};
914+
}
911915
} else if (name == "__builtin_ieee_support_subnormal") {
912916
return Expr<T>{context.targetCharacteristics().ieeeFeatures().test(
913917
IeeeFeature::Subnormal)};

flang/lib/Optimizer/Builder/IntrinsicCall.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,7 @@ static constexpr IntrinsicHandler handlers[]{
458458
/*isElemental=*/false},
459459
{"ieee_support_halting", &I::genIeeeSupportHalting},
460460
{"ieee_support_rounding", &I::genIeeeSupportRounding},
461+
{"ieee_support_standard", &I::genIeeeSupportStandard},
461462
{"ieee_unordered", &I::genIeeeUnordered},
462463
{"ieee_value", &I::genIeeeValue},
463464
{"ieor", &I::genIeor},
@@ -5671,6 +5672,19 @@ IntrinsicLibrary::genIeeeSupportRounding(mlir::Type resultType,
56715672
loc, resultType, builder.create<mlir::arith::AndIOp>(loc, lbOk, ubOk));
56725673
}
56735674

5675+
// IEEE_SUPPORT_STANDARD
5676+
fir::ExtendedValue IntrinsicLibrary::genIeeeSupportStandard(
5677+
mlir::Type resultType, llvm::ArrayRef<fir::ExtendedValue> args) {
5678+
// Check if IEEE standard support is available, which reduces to checking
5679+
// if halting control is supported, as that is the only support component
5680+
// that may not be available.
5681+
assert(args.size() <= 1);
5682+
mlir::Value nearest = builder.createIntegerConstant(
5683+
loc, builder.getIntegerType(32), _FORTRAN_RUNTIME_IEEE_NEAREST);
5684+
return builder.createConvert(
5685+
loc, resultType, fir::runtime::genSupportHalting(builder, loc, nearest));
5686+
}
5687+
56745688
// IEEE_UNORDERED
56755689
mlir::Value
56765690
IntrinsicLibrary::genIeeeUnordered(mlir::Type resultType,

0 commit comments

Comments
 (0)