https://github.com/xlauko created https://github.com/llvm/llvm-project/pull/246603
Define `CIR_AnyBitIntType` in `CIRTypeConstraints.td` and make `CIR_IsNotBitIntPred` its negation, so the positive and negative `_BitInt` checks share one predicate. ODS generates `cir::isBitIntType`, which replaces the hand-written helper added in #245456. The generated function asserts on a null type, so the four `dyn_cast<IntType>` sites that need the `IntType` go back to `intTy && intTy.isBitInt()`. `check-clang-cir` passes. Assisted-by: Claude Code (claude-sonnet-5-5). >From 5527e28f30cee31af6864ae092e06caf8e09571b Mon Sep 17 00:00:00 2001 From: Henrich Lauko <[email protected]> Date: Fri, 27 Nov 2026 10:11:04 +0000 Subject: [PATCH] [CIR][NFC] Generate isBitIntType from an ODS constraint Add CIR_AnyBitIntType and define CIR_IsNotBitIntPred as its negation, so the positive and negative _BitInt checks share one predicate. ODS now generates cir::isBitIntType, replacing the hand-written helper from #245456. Restore the dyn_cast<IntType> sites that need the IntType itself, since the generated function does not accept a null type. Assisted-by: Claude Code (claude-sonnet-5-5). --- clang/include/clang/CIR/Dialect/IR/CIRTypeConstraints.td | 8 +++++++- clang/include/clang/CIR/Dialect/IR/CIRTypes.h | 3 --- clang/lib/CIR/Dialect/IR/CIRTypes.cpp | 5 ----- clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp | 4 ++-- clang/lib/CIR/Lowering/LoweringHelpers.cpp | 5 +++-- 5 files changed, 12 insertions(+), 13 deletions(-) diff --git a/clang/include/clang/CIR/Dialect/IR/CIRTypeConstraints.td b/clang/include/clang/CIR/Dialect/IR/CIRTypeConstraints.td index 17c750f7c96d13..2e9eca9fc014df 100644 --- a/clang/include/clang/CIR/Dialect/IR/CIRTypeConstraints.td +++ b/clang/include/clang/CIR/Dialect/IR/CIRTypeConstraints.td @@ -129,7 +129,13 @@ def CIR_SInt128 : CIR_SInt<128>; // have a specified set of admissible bitwidths (8, 16, 32, 64). // _BitInt types are excluded even when their width matches a fundamental width. -def CIR_IsNotBitIntPred : CPred<"!$_self.getIsBitInt()">; +def CIR_IsBitIntPred : CPred<"$_self.getIsBitInt()">; +def CIR_IsNotBitIntPred : Neg<CIR_IsBitIntPred>; + +def CIR_AnyBitIntType + : CIR_ConfinedType<CIR_AnyIntType, [CIR_IsBitIntPred], "_BitInt type"> { + let cppFunctionName = "isBitIntType"; +} def CIR_AnyFundamentalIntType : CIR_ConfinedType<CIR_AnyIntType, diff --git a/clang/include/clang/CIR/Dialect/IR/CIRTypes.h b/clang/include/clang/CIR/Dialect/IR/CIRTypes.h index ba69e3945132ec..ded2921c608c6f 100644 --- a/clang/include/clang/CIR/Dialect/IR/CIRTypes.h +++ b/clang/include/clang/CIR/Dialect/IR/CIRTypes.h @@ -75,9 +75,6 @@ inline bool isNamedBitField(RecordMemberKind kind) { /// void, or abstract types. bool isSized(mlir::Type ty); -/// Returns true if the type is a `cir::IntType` representing a _BitInt. -bool isBitIntType(mlir::Type ty); - /// Returns the CIR floating-point type for the given semantics, or a null /// type if CIR has no type for it (e.g. PPCDoubleDouble or a Float8 format). /// Mirrors llvm::Type::getFloatingPointTy. diff --git a/clang/lib/CIR/Dialect/IR/CIRTypes.cpp b/clang/lib/CIR/Dialect/IR/CIRTypes.cpp index 9b23939cb49a6a..3db2edf638ca07 100644 --- a/clang/lib/CIR/Dialect/IR/CIRTypes.cpp +++ b/clang/lib/CIR/Dialect/IR/CIRTypes.cpp @@ -40,11 +40,6 @@ bool cir::isSized(mlir::Type ty) { return false; } -bool cir::isBitIntType(mlir::Type ty) { - auto intTy = mlir::dyn_cast_if_present<cir::IntType>(ty); - return intTy && intTy.isBitInt(); -} - cir::FPTypeInterface cir::getFloatingPointType(const llvm::fltSemantics &sem, mlir::MLIRContext *ctx) { switch (llvm::APFloat::SemanticsToEnum(sem)) { diff --git a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp index 245ce5096d461a..a1a907af86cc89 100644 --- a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp +++ b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp @@ -214,7 +214,7 @@ static mlir::Value emitFromMemory(mlir::ConversionPatternRewriter &rewriter, // Truncate the padded storage integer back to the _BitInt's literal width. if (auto intTy = mlir::dyn_cast<cir::IntType>(op.getType()); - cir::isBitIntType(intTy)) + intTy && intTy.isBitInt()) return castBitIntMemoryStorage(rewriter, dataLayout, intTy, value, /*toMemory=*/false); @@ -260,7 +260,7 @@ static mlir::Value emitToMemory(mlir::ConversionPatternRewriter &rewriter, // Sign/zero-extend the _BitInt value to its padded storage integer. if (auto intTy = mlir::dyn_cast<cir::IntType>(origType); - cir::isBitIntType(intTy)) + intTy && intTy.isBitInt()) return castBitIntMemoryStorage(rewriter, dataLayout, intTy, value, /*toMemory=*/true); diff --git a/clang/lib/CIR/Lowering/LoweringHelpers.cpp b/clang/lib/CIR/Lowering/LoweringHelpers.cpp index a2265ecae117b0..249f1b84bb6965 100644 --- a/clang/lib/CIR/Lowering/LoweringHelpers.cpp +++ b/clang/lib/CIR/Lowering/LoweringHelpers.cpp @@ -112,7 +112,7 @@ mlir::Type convertTypeForMemory(const mlir::TypeConverter &converter, // M/8 byte count (isSplitStorageBitInt), use a byte array instead so the // size stays exact. if (auto intTy = mlir::dyn_cast<cir::IntType>(type); - cir::isBitIntType(intTy)) { + intTy && intTy.isBitInt()) { if (isSplitStorageBitInt(intTy, dataLayout)) return mlir::LLVM::LLVMArrayType::get( mlir::IntegerType::get(type.getContext(), 8), @@ -130,7 +130,8 @@ mlir::Type convertTypeForLoadStore(const mlir::TypeConverter &converter, // A split-storage _BitInt's memory type is a byte array (see // convertTypeForMemory), but a load/store must still access the whole // integer as-is. - if (auto intTy = mlir::dyn_cast<cir::IntType>(type); cir::isBitIntType(intTy)) + if (auto intTy = mlir::dyn_cast<cir::IntType>(type); + intTy && intTy.isBitInt()) return mlir::IntegerType::get(type.getContext(), intTy.getStorageTypeWidth(dataLayout)); _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
