Skip to content

Commit b18467a

Browse files
committed
Address PR review: remove FP skeleton features, lowering test and add OGCG and LLVM test
1 parent dfa4cd4 commit b18467a

File tree

10 files changed

+110
-363
lines changed

10 files changed

+110
-363
lines changed

clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -442,22 +442,6 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
442442
return createCast(cir::CastKind::ptr_to_bool, v, getBoolTy());
443443
}
444444

445-
// TODO(cir): the following function was introduced to keep in sync with LLVM
446-
// codegen. CIR does not have "zext" operations. It should eventually be
447-
// renamed or removed. For now, we just add whatever cast is required here.
448-
mlir::Value createZExtOrBitCast(mlir::Location loc, mlir::Value src,
449-
mlir::Type newTy) {
450-
auto srcTy = src.getType();
451-
452-
if (srcTy == newTy)
453-
return src;
454-
455-
if (mlir::isa<cir::BoolType>(srcTy) && mlir::isa<cir::IntType>(newTy))
456-
return createBoolToInt(src, newTy);
457-
458-
llvm_unreachable("unhandled extension cast");
459-
}
460-
461445
mlir::Value createBoolToInt(mlir::Value src, mlir::Type newTy) {
462446
return createCast(cir::CastKind::bool_to_int, src, newTy);
463447
}

clang/include/clang/CIR/Dialect/IR/CIROps.td

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3933,17 +3933,17 @@ def CIR_IsFPClassOp : CIR_Op<"is_fp_class"> {
39333933
The flags must be a compile time constant and the values are:
39343934

39353935
| Bit # | floating-point class |
3936-
| -------- | ------- |
3937-
| 0 | Signaling NaN |
3938-
| 1 | Quiet NaN |
3939-
| 2 | Negative infinity |
3940-
| 3 | Negative normal |
3941-
| 4 | Negative subnormal |
3942-
| 5 | Negative zero |
3943-
| 6 | Positive zero |
3944-
| 7 | Positive subnormal |
3945-
| 8 | Positive normal |
3946-
| 9 | Positive infinity |
3936+
| ----- | -------------------- |
3937+
| 0 | Signaling NaN |
3938+
| 1 | Quiet NaN |
3939+
| 2 | Negative infinity |
3940+
| 3 | Negative normal |
3941+
| 4 | Negative subnormal |
3942+
| 5 | Negative zero |
3943+
| 6 | Positive zero |
3944+
| 7 | Positive subnormal |
3945+
| 8 | Positive normal |
3946+
| 9 | Positive infinity |
39473947
}];
39483948

39493949
let arguments = (ins CIR_AnyFloatType:$src,

clang/include/clang/CIR/MissingFeatures.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,7 @@ struct MissingFeatures {
262262
static bool emitNullabilityCheck() { return false; }
263263
static bool emitTypeCheck() { return false; }
264264
static bool emitTypeMetadataCodeForVCall() { return false; }
265-
static bool fastMathGuard() { return false; }
266265
static bool fastMathFlags() { return false; }
267-
static bool fastMathFuncAttributes() { return false; }
268266

269267
static bool fpConstraints() { return false; }
270268
static bool generateDebugInfo() { return false; }

clang/lib/CIR/CodeGen/CIRGenBuilder.h

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -70,56 +70,6 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy {
7070
cir::ArrayType arrayTy) const {
7171
return cir::ConstArrayAttr::get(arrayTy, attrs);
7272
}
73-
//
74-
// Floating point specific helpers
75-
// -------------------------------
76-
//
77-
78-
/// Enable/Disable use of constrained floating point math. When enabled the
79-
/// CreateF<op>() calls instead create constrained floating point intrinsic
80-
/// calls. Fast math flags are unaffected by this setting.
81-
void setIsFPConstrained(bool isCon) {
82-
if (isCon)
83-
llvm_unreachable("Constrained FP NYI");
84-
isFpConstrained = isCon;
85-
}
86-
87-
/// Query for the use of constrained floating point math
88-
bool getIsFPConstrained() {
89-
if (isFpConstrained)
90-
llvm_unreachable("Constrained FP NYI");
91-
return isFpConstrained;
92-
}
93-
///
94-
/// Set the exception handling to be used with constrained floating point
95-
void setDefaultConstrainedExcept(cir::fp::ExceptionBehavior newExcept) {
96-
#ifndef NDEBUG
97-
std::optional<llvm::StringRef> exceptStr =
98-
cir::convertExceptionBehaviorToStr(newExcept);
99-
assert(exceptStr && "Garbage strict exception behavior!");
100-
#endif
101-
defaultConstrainedExcept = newExcept;
102-
}
103-
104-
/// Set the rounding mode handling to be used with constrained floating point
105-
void setDefaultConstrainedRounding(llvm::RoundingMode newRounding) {
106-
#ifndef NDEBUG
107-
std::optional<llvm::StringRef> roundingStr =
108-
cir::convertRoundingModeToStr(newRounding);
109-
assert(roundingStr && "Garbage strict rounding mode!");
110-
#endif
111-
defaultConstrainedRounding = newRounding;
112-
}
113-
114-
/// Get the exception handling used with constrained floating point
115-
cir::fp::ExceptionBehavior getDefaultConstrainedExcept() {
116-
return defaultConstrainedExcept;
117-
}
118-
119-
/// Get the rounding mode handling used with constrained floating point
120-
llvm::RoundingMode getDefaultConstrainedRounding() {
121-
return defaultConstrainedRounding;
122-
}
12373

12474
mlir::Attribute getConstRecordOrZeroAttr(mlir::ArrayAttr arrayAttr,
12575
bool packed = false,

clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp

Lines changed: 28 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,6 @@ using namespace clang;
2929
using namespace clang::CIRGen;
3030
using namespace llvm;
3131

32-
static mlir::Value tryUseTestFPKind(CIRGenFunction &cgf, unsigned BuiltinID,
33-
mlir::Value V) {
34-
if (cgf.getBuilder().getIsFPConstrained() &&
35-
cgf.getBuilder().getDefaultConstrainedExcept() != cir::fp::ebIgnore) {
36-
if (mlir::Value Result = cgf.getTargetHooks().testFPKind(
37-
V, BuiltinID, cgf.getBuilder(), cgf.cgm))
38-
return Result;
39-
}
40-
return nullptr;
41-
}
4232
static RValue emitLibraryCall(CIRGenFunction &cgf, const FunctionDecl *fd,
4333
const CallExpr *e, mlir::Operation *calleeValue) {
4434
CIRGenCallee callee = CIRGenCallee::forDirect(calleeValue, GlobalDecl(fd));
@@ -533,36 +523,31 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl &gd, unsigned builtinID,
533523
// if the floating-point value, specified by the first argument, falls into
534524
// any of data classes, specified by the second argument.
535525
case Builtin::BI__builtin_isnan: {
536-
CIRGenFunction::CIRGenFPOptionsRAII fpOptsRaii(*this, e);
526+
assert(!cir::MissingFeatures::cgFPOptionsRAII());
537527
mlir::Value v = emitScalarExpr(e->getArg(0));
538-
if (mlir::Value result = tryUseTestFPKind(*this, builtinID, v))
539-
return RValue::get(result);
528+
assert(!cir::MissingFeatures::fpConstraints());
540529
mlir::Location loc = getLoc(e->getBeginLoc());
541-
// FIXME: We should use builder.createZExt once createZExt is available.
542-
return RValue::get(builder.createZExtOrBitCast(
543-
loc, builder.createIsFPClass(loc, v, FPClassTest::fcNan),
530+
return RValue::get(builder.createBoolToInt(
531+
builder.createIsFPClass(loc, v, FPClassTest::fcNan),
544532
convertType(e->getType())));
545533
}
546534

547535
case Builtin::BI__builtin_issignaling: {
548-
CIRGenFunction::CIRGenFPOptionsRAII fpOptsRaii(*this, e);
536+
assert(!cir::MissingFeatures::cgFPOptionsRAII());
549537
mlir::Value v = emitScalarExpr(e->getArg(0));
550538
mlir::Location loc = getLoc(e->getBeginLoc());
551-
// FIXME: We should use builder.createZExt once createZExt is available.
552-
return RValue::get(builder.createZExtOrBitCast(
553-
loc, builder.createIsFPClass(loc, v, FPClassTest::fcSNan),
539+
return RValue::get(builder.createBoolToInt(
540+
builder.createIsFPClass(loc, v, FPClassTest::fcSNan),
554541
convertType(e->getType())));
555542
}
556543

557544
case Builtin::BI__builtin_isinf: {
558-
CIRGenFunction::CIRGenFPOptionsRAII fpOptsRaii(*this, e);
545+
assert(!cir::MissingFeatures::cgFPOptionsRAII());
559546
mlir::Value v = emitScalarExpr(e->getArg(0));
560-
if (mlir::Value result = tryUseTestFPKind(*this, builtinID, v))
561-
return RValue::get(result);
547+
assert(!cir::MissingFeatures::fpConstraints());
562548
mlir::Location loc = getLoc(e->getBeginLoc());
563-
// FIXME: We should use builder.createZExt once createZExt is available.
564-
return RValue::get(builder.createZExtOrBitCast(
565-
loc, builder.createIsFPClass(loc, v, FPClassTest::fcInf),
549+
return RValue::get(builder.createBoolToInt(
550+
builder.createIsFPClass(loc, v, FPClassTest::fcInf),
566551
convertType(e->getType())));
567552
}
568553

@@ -573,69 +558,62 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl &gd, unsigned builtinID,
573558
case Builtin::BIfinitel:
574559
case Builtin::BI__finitel:
575560
case Builtin::BI__builtin_isfinite: {
576-
CIRGenFunction::CIRGenFPOptionsRAII fpOptsRaii(*this, e);
561+
assert(!cir::MissingFeatures::cgFPOptionsRAII());
577562
mlir::Value v = emitScalarExpr(e->getArg(0));
578-
if (mlir::Value result = tryUseTestFPKind(*this, builtinID, v))
579-
return RValue::get(result);
563+
assert(!cir::MissingFeatures::fpConstraints());
580564
mlir::Location loc = getLoc(e->getBeginLoc());
581-
// FIXME: We should use builder.createZExt once createZExt is available.
582-
return RValue::get(builder.createZExtOrBitCast(
583-
loc, builder.createIsFPClass(loc, v, FPClassTest::fcFinite),
565+
return RValue::get(builder.createBoolToInt(
566+
builder.createIsFPClass(loc, v, FPClassTest::fcFinite),
584567
convertType(e->getType())));
585568
}
586569

587570
case Builtin::BI__builtin_isnormal: {
588-
CIRGenFunction::CIRGenFPOptionsRAII fpOptsRaii(*this, e);
571+
assert(!cir::MissingFeatures::cgFPOptionsRAII());
589572
mlir::Value v = emitScalarExpr(e->getArg(0));
590573
mlir::Location loc = getLoc(e->getBeginLoc());
591-
// FIXME: We should use builder.createZExt once createZExt is available.
592-
return RValue::get(builder.createZExtOrBitCast(
593-
loc, builder.createIsFPClass(loc, v, FPClassTest::fcNormal),
574+
return RValue::get(builder.createBoolToInt(
575+
builder.createIsFPClass(loc, v, FPClassTest::fcNormal),
594576
convertType(e->getType())));
595577
}
596578

597579
case Builtin::BI__builtin_issubnormal: {
598-
CIRGenFunction::CIRGenFPOptionsRAII fpOptsRaii(*this, e);
580+
assert(!cir::MissingFeatures::cgFPOptionsRAII());
599581
mlir::Value v = emitScalarExpr(e->getArg(0));
600582
mlir::Location loc = getLoc(e->getBeginLoc());
601-
// FIXME: We should use builder.createZExt once createZExt is available.
602-
return RValue::get(builder.createZExtOrBitCast(
603-
loc, builder.createIsFPClass(loc, v, FPClassTest::fcSubnormal),
583+
return RValue::get(builder.createBoolToInt(
584+
builder.createIsFPClass(loc, v, FPClassTest::fcSubnormal),
604585
convertType(e->getType())));
605586
}
606587

607588
case Builtin::BI__builtin_iszero: {
608-
CIRGenFunction::CIRGenFPOptionsRAII fpOptsRaii(*this, e);
589+
assert(!cir::MissingFeatures::cgFPOptionsRAII());
609590
mlir::Value v = emitScalarExpr(e->getArg(0));
610591
mlir::Location loc = getLoc(e->getBeginLoc());
611-
// FIXME: We should use builder.createZExt once createZExt is available.
612-
return RValue::get(builder.createZExtOrBitCast(
613-
loc, builder.createIsFPClass(loc, v, FPClassTest::fcZero),
592+
return RValue::get(builder.createBoolToInt(
593+
builder.createIsFPClass(loc, v, FPClassTest::fcZero),
614594
convertType(e->getType())));
615595
}
616596
case Builtin::BI__builtin_isfpclass: {
617597
Expr::EvalResult result;
618598
if (!e->getArg(1)->EvaluateAsInt(result, cgm.getASTContext()))
619599
break;
620600

621-
CIRGenFunction::CIRGenFPOptionsRAII fpOptsRaii(*this, e);
601+
assert(!cir::MissingFeatures::cgFPOptionsRAII());
622602
mlir::Value v = emitScalarExpr(e->getArg(0));
623603
uint64_t test = result.Val.getInt().getLimitedValue();
624604
mlir::Location loc = getLoc(e->getBeginLoc());
625605
//
626-
// // FIXME: We should use builder.createZExt once createZExt is available.
627-
return RValue::get(builder.createZExtOrBitCast(
628-
loc, builder.createIsFPClass(loc, v, test), convertType(e->getType())));
606+
return RValue::get(builder.createBoolToInt(
607+
builder.createIsFPClass(loc, v, test), convertType(e->getType())));
629608
}
630609
}
631610

632611
// If this is an alias for a lib function (e.g. __builtin_sin), emit
633612
// the call using the normal call path, but using the unmangled
634613
// version of the function name.
635-
if (getContext().BuiltinInfo.isLibFunction(builtinID)) {
614+
if (getContext().BuiltinInfo.isLibFunction(builtinID))
636615
return emitLibraryCall(*this, fd, e,
637616
cgm.getBuiltinLibFunction(fd, builtinID));
638-
}
639617

640618
// Some target-specific builtins can have aggregate return values, e.g.
641619
// __builtin_arm_mve_vld2q_u32. So if the result is an aggregate, force

clang/lib/CIR/CodeGen/CIRGenFunction.cpp

Lines changed: 0 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -817,22 +817,6 @@ void CIRGenFunction::emitDestructorBody(FunctionArgList &args) {
817817
cgm.errorNYI(dtor->getSourceRange(), "function-try-block destructor");
818818
}
819819

820-
// Map the LangOption for exception behavior into the corresponding enum in
821-
// the IR.
822-
static cir::fp::ExceptionBehavior
823-
toConstrainedExceptMd(LangOptions::FPExceptionModeKind kind) {
824-
switch (kind) {
825-
case LangOptions::FPE_Ignore:
826-
return cir::fp::ebIgnore;
827-
case LangOptions::FPE_MayTrap:
828-
return cir::fp::ebMayTrap;
829-
case LangOptions::FPE_Strict:
830-
return cir::fp::ebStrict;
831-
default:
832-
llvm_unreachable("Unsupported FP Exception Behavior");
833-
}
834-
}
835-
836820
/// Given a value of type T* that may not be to a complete object, construct
837821
/// an l-vlaue withi the natural pointee alignment of T.
838822
LValue CIRGenFunction::makeNaturalAlignPointeeAddrLValue(mlir::Value val,
@@ -1003,59 +987,6 @@ void CIRGenFunction::emitNullInitialization(mlir::Location loc, Address destPtr,
1003987
builder.createStore(loc, zeroValue, destPtr);
1004988
}
1005989

1006-
CIRGenFunction::CIRGenFPOptionsRAII::CIRGenFPOptionsRAII(CIRGenFunction &cgf,
1007-
const clang::Expr *e)
1008-
: cgf(cgf) {
1009-
constructorHelper(e->getFPFeaturesInEffect(cgf.getLangOpts()));
1010-
}
1011-
1012-
CIRGenFunction::CIRGenFPOptionsRAII::CIRGenFPOptionsRAII(CIRGenFunction &cgf,
1013-
FPOptions fpFeatures)
1014-
: cgf(cgf) {
1015-
constructorHelper(fpFeatures);
1016-
}
1017-
1018-
void CIRGenFunction::CIRGenFPOptionsRAII::constructorHelper(
1019-
FPOptions fpFeatures) {
1020-
oldFpFeatures = cgf.curFpFeatures;
1021-
cgf.curFpFeatures = fpFeatures;
1022-
1023-
oldExcept = cgf.builder.getDefaultConstrainedExcept();
1024-
oldRounding = cgf.builder.getDefaultConstrainedRounding();
1025-
1026-
if (oldFpFeatures == fpFeatures)
1027-
return;
1028-
1029-
// TODO(cir): create guard to restore fast math configurations.
1030-
assert(!cir::MissingFeatures::fastMathGuard());
1031-
1032-
llvm::RoundingMode newRoundingBehavior = fpFeatures.getRoundingMode();
1033-
// TODO(cir): override rounding behaviour once FM configs are guarded.
1034-
auto newExceptionBehavior =
1035-
toConstrainedExceptMd(static_cast<LangOptions::FPExceptionModeKind>(
1036-
fpFeatures.getExceptionMode()));
1037-
// TODO(cir): override exception behaviour once FM configs are guarded.
1038-
1039-
// TODO(cir): override FP flags once FM configs are guarded.
1040-
assert(!cir::MissingFeatures::fastMathFlags());
1041-
1042-
assert((cgf.curFuncDecl == nullptr || cgf.builder.getIsFPConstrained() ||
1043-
isa<CXXConstructorDecl>(cgf.curFuncDecl) ||
1044-
isa<CXXDestructorDecl>(cgf.curFuncDecl) ||
1045-
(newExceptionBehavior == cir::fp::ebIgnore &&
1046-
newRoundingBehavior == llvm::RoundingMode::NearestTiesToEven)) &&
1047-
"FPConstrained should be enabled on entire function");
1048-
1049-
// TODO(cir): mark CIR function with fast math attributes.
1050-
assert(!cir::MissingFeatures::fastMathFuncAttributes());
1051-
}
1052-
1053-
CIRGenFunction::CIRGenFPOptionsRAII::~CIRGenFPOptionsRAII() {
1054-
cgf.curFpFeatures = oldFpFeatures;
1055-
cgf.builder.setDefaultConstrainedExcept(oldExcept);
1056-
cgf.builder.setDefaultConstrainedRounding(oldRounding);
1057-
}
1058-
1059990
// TODO(cir): should be shared with LLVM codegen.
1060991
bool CIRGenFunction::shouldNullCheckClassCastValue(const CastExpr *ce) {
1061992
const Expr *e = ce->getSubExpr();

clang/lib/CIR/CodeGen/CIRGenFunction.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -177,20 +177,6 @@ class CIRGenFunction : public CIRGenTypeCache {
177177
/// Sanitizers enabled for this function.
178178
clang::SanitizerSet sanOpts;
179179

180-
class CIRGenFPOptionsRAII {
181-
public:
182-
CIRGenFPOptionsRAII(CIRGenFunction &cgf, FPOptions fpFeatures);
183-
CIRGenFPOptionsRAII(CIRGenFunction &cgf, const clang::Expr *e);
184-
~CIRGenFPOptionsRAII();
185-
186-
private:
187-
void constructorHelper(clang::FPOptions fpFeatures);
188-
CIRGenFunction &cgf;
189-
clang::FPOptions oldFpFeatures;
190-
cir::fp::ExceptionBehavior oldExcept;
191-
llvm::RoundingMode oldRounding;
192-
};
193-
clang::FPOptions curFpFeatures;
194180

195181
/// The symbol table maps a variable name to a value in the current scope.
196182
/// Entering a function creates a new scope, and the function arguments are

clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -649,9 +649,9 @@ mlir::LogicalResult CIRToLLVMASinOpLowering::matchAndRewrite(
649649
mlir::LogicalResult CIRToLLVMIsFPClassOpLowering::matchAndRewrite(
650650
cir::IsFPClassOp op, OpAdaptor adaptor,
651651
mlir::ConversionPatternRewriter &rewriter) const {
652-
auto src = adaptor.getSrc();
653-
auto flags = adaptor.getFlags();
654-
auto retTy = rewriter.getI1Type();
652+
mlir::Value src = adaptor.getSrc();
653+
uint32_t flags = adaptor.getFlags();
654+
mlir::IntegerType retTy = rewriter.getI1Type();
655655

656656
rewriter.replaceOpWithNewOp<mlir::LLVM::IsFPClass>(op, retTy, src, flags);
657657
return mlir::success();

0 commit comments

Comments
 (0)