Author: Henrich Lauko Date: 2026-11-15T11:43:11+01:00 New Revision: b141f612527e1b095dea470882bdc9075af3c135
URL: https://github.com/llvm/llvm-project/commit/b141f612527e1b095dea470882bdc9075af3c135 DIFF: https://github.com/llvm/llvm-project/commit/b141f612527e1b095dea470882bdc9075af3c135.diff LOG: [CIR][NFC] Add isVolatileOrAtomic() to cir.load and cir.store (#242709) Several places spell out `getIsVolatile() || getMemOrder()` to decide whether a load or store must stay as written. This names that check once on both ops and uses it in the load effects, mem2reg, `CIRSimplify` and the ABI rewriter. Assisted-by: Claude Code (claude-opus-5-5). Added: Modified: clang/include/clang/CIR/Dialect/IR/CIROps.td clang/lib/CIR/Dialect/IR/CIRDialect.cpp clang/lib/CIR/Dialect/IR/CIRMemorySlot.cpp clang/lib/CIR/Dialect/Transforms/CIRSimplify.cpp clang/lib/CIR/Dialect/Transforms/TargetLowering/CIRABIRewriteContext.cpp Removed: ################################################################################ diff --git a/clang/include/clang/CIR/Dialect/IR/CIROps.td b/clang/include/clang/CIR/Dialect/IR/CIROps.td index 93f4b8a90ca4f..289b7ed0d38b0 100644 --- a/clang/include/clang/CIR/Dialect/IR/CIROps.td +++ b/clang/include/clang/CIR/Dialect/IR/CIROps.td @@ -229,6 +229,15 @@ defvar CIR_FenvOpTraits = [ // dynamically via FenvOpTrait, so they must not inherit NoMemoryEffect. defvar CIR_DynamicMemoryEffects = 0; +// Declares isVolatileOrAtomic() on cir.load and cir.store. +defvar CIR_VolatileOrAtomicAccessDecl = [{ + /// Returns true if the access is volatile or atomic. Such an access must + /// stay as written: it cannot be removed, merged or reordered. + bool isVolatileOrAtomic() { + return getIsVolatile() || getMemOrder().has_value(); + } +}]; + //===----------------------------------------------------------------------===// // CastOp //===----------------------------------------------------------------------===// @@ -942,6 +951,8 @@ def CIR_LoadOp : CIR_Op<"load", [ }]> ]; + let extraClassDeclaration = CIR_VolatileOrAtomicAccessDecl; + // FIXME: add verifier. } @@ -1052,6 +1063,8 @@ def CIR_StoreOp : CIR_Op<"store", [ }]> ]; + let extraClassDeclaration = CIR_VolatileOrAtomicAccessDecl; + // FIXME: add verifier. } diff --git a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp index 6c976e64c96bc..e0107573819b1 100644 --- a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp +++ b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp @@ -4827,8 +4827,7 @@ getLoadEffects(OpOperand &addr, bool isVolatileOrAtomic, void cir::LoadOp::getEffects( SmallVectorImpl<MemoryEffects::EffectInstance> &effects) { - getLoadEffects(getAddrMutable(), getIsVolatile() || getMemOrder().has_value(), - effects); + getLoadEffects(getAddrMutable(), isVolatileOrAtomic(), effects); } void cir::GetBitfieldOp::getEffects( diff --git a/clang/lib/CIR/Dialect/IR/CIRMemorySlot.cpp b/clang/lib/CIR/Dialect/IR/CIRMemorySlot.cpp index 089303c0cbf2e..8bcfb4db6f513 100644 --- a/clang/lib/CIR/Dialect/IR/CIRMemorySlot.cpp +++ b/clang/lib/CIR/Dialect/IR/CIRMemorySlot.cpp @@ -73,8 +73,7 @@ bool cir::LoadOp::canUsesBeRemoved( if (blockingUses.size() != 1) return false; - // Volatile load or atomic load should not be removed. - if (getIsVolatile() || getMemOrder().has_value()) + if (isVolatileOrAtomic()) return false; Value blockingUse = (*blockingUses.begin())->get(); @@ -112,8 +111,7 @@ bool cir::StoreOp::canUsesBeRemoved( if (blockingUses.size() != 1) return false; - // Volatile store or atomic store should not be removed. - if (getIsVolatile() || getMemOrder().has_value()) + if (isVolatileOrAtomic()) return false; Value blockingUse = (*blockingUses.begin())->get(); diff --git a/clang/lib/CIR/Dialect/Transforms/CIRSimplify.cpp b/clang/lib/CIR/Dialect/Transforms/CIRSimplify.cpp index 6c8902692993f..12d7f2ac795dd 100644 --- a/clang/lib/CIR/Dialect/Transforms/CIRSimplify.cpp +++ b/clang/lib/CIR/Dialect/Transforms/CIRSimplify.cpp @@ -108,8 +108,7 @@ struct SimplifyConstantLoad final : public OpRewritePattern<LoadOp> { LogicalResult matchAndRewrite(LoadOp op, PatternRewriter &rewriter) const override { - // Volatile or atomic loads should not be simplified. - if (op.getIsVolatile() || op.getMemOrder()) + if (op.isVolatileOrAtomic()) return mlir::failure(); auto allocaOp = op.getAddr().getDefiningOp<cir::AllocaOp>(); @@ -120,7 +119,7 @@ struct SimplifyConstantLoad final : public OpRewritePattern<LoadOp> { findDominatingInitOp(allocaOp, op, domInfo.getDominanceInfo()); if (!initStoreOp) return mlir::failure(); - if (initStoreOp.getIsVolatile() || initStoreOp.getMemOrder()) { + if (initStoreOp.isVolatileOrAtomic()) { // We intentionally act conservatively here and we don't want to simplify // the load if the corresponding store is either volatile or atomic. return mlir::failure(); diff --git a/clang/lib/CIR/Dialect/Transforms/TargetLowering/CIRABIRewriteContext.cpp b/clang/lib/CIR/Dialect/Transforms/TargetLowering/CIRABIRewriteContext.cpp index ed36a6180dd67..3d5237519e6e6 100644 --- a/clang/lib/CIR/Dialect/Transforms/TargetLowering/CIRABIRewriteContext.cpp +++ b/clang/lib/CIR/Dialect/Transforms/TargetLowering/CIRABIRewriteContext.cpp @@ -657,7 +657,7 @@ mlir::Block *coercionSlotBlock(mlir::Operation *op) { /// load at all. static cir::LoadOp maybeGetSimpleLoad(mlir::Value val) { cir::LoadOp load = val.getDefiningOp<cir::LoadOp>(); - if (!load || load.getIsVolatile() || load.getMemOrder()) + if (!load || load.isVolatileOrAtomic()) return {}; return load; } _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
