Author: Arseniy Obolenskiy Date: 2026-11-17T22:09:14+01:00 New Revision: a58840831f16e82bbf722b74cf50dfced256e8f7
URL: https://github.com/llvm/llvm-project/commit/a58840831f16e82bbf722b74cf50dfced256e8f7 DIFF: https://github.com/llvm/llvm-project/commit/a58840831f16e82bbf722b74cf50dfced256e8f7.diff LOG: [CIR] Freeze maybe_undef call arguments (#234124) Added: clang/test/CIR/CodeGen/attr-maybeundef.cpp clang/test/CIR/Transforms/abi-lowering/maybe-undef-freeze.cir Modified: clang/include/clang/CodeGenUtils/CallUtils.h clang/lib/CIR/CodeGen/CIRGenCall.cpp clang/lib/CIR/Dialect/Transforms/TargetLowering/CIRABIRewriteContext.cpp clang/lib/CodeGen/CGCall.cpp clang/lib/CodeGenUtils/CallUtils.cpp Removed: ################################################################################ diff --git a/clang/include/clang/CodeGenUtils/CallUtils.h b/clang/include/clang/CodeGenUtils/CallUtils.h index 82f135f3be1e64..17110814d34591 100644 --- a/clang/include/clang/CodeGenUtils/CallUtils.h +++ b/clang/include/clang/CodeGenUtils/CallUtils.h @@ -55,6 +55,9 @@ CanQual<FunctionProtoType> getFormalType(const CXXMethodDecl *MD); /// promise never reach a function's arguments or return value. llvm::FPClassTest getNoFPClassTestMask(const LangOptions &LangOpts); +bool isArgumentMaybeUndef(const Decl *TargetDecl, unsigned NumRequiredArgs, + unsigned ArgNo); + } // namespace clang::CodeGenUtils #endif // LLVM_CLANG_CODEGENUTILS_CALLUTILS_H diff --git a/clang/lib/CIR/CodeGen/CIRGenCall.cpp b/clang/lib/CIR/CodeGen/CIRGenCall.cpp index 87c53ef8dfb94a..f93a9d60576f2a 100644 --- a/clang/lib/CIR/CodeGen/CIRGenCall.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenCall.cpp @@ -1374,6 +1374,11 @@ RValue CIRGenFunction::emitCall(const CIRGenFunctionInfo &funcInfo, assert(!cir::MissingFeatures::lowerAggregateLoadStore()); cirCallArgs[argNo] = builder.createLoad(argLoc, src); } + + if (CodeGenUtils::isArgumentMaybeUndef( + targetDecl, funcInfo.getNumRequiredArgs(), argNo)) + cirCallArgs[argNo] = + cir::FreezeOp::create(builder, loc, cirCallArgs[argNo]); } const CIRGenCallee &concreteCallee = callee.prepareConcreteCallee(*this); diff --git a/clang/lib/CIR/Dialect/Transforms/TargetLowering/CIRABIRewriteContext.cpp b/clang/lib/CIR/Dialect/Transforms/TargetLowering/CIRABIRewriteContext.cpp index 645b2bc74db34a..5a5a5c778b710b 100644 --- a/clang/lib/CIR/Dialect/Transforms/TargetLowering/CIRABIRewriteContext.cpp +++ b/clang/lib/CIR/Dialect/Transforms/TargetLowering/CIRABIRewriteContext.cpp @@ -1112,6 +1112,12 @@ static void eraseDeadRecordLoads(ArrayRef<cir::LoadOp> loads) { load->erase(); } +/// The old call, their only user, must already be erased. +static void eraseDeadFreezes(ArrayRef<cir::FreezeOp> freezes) { + for (cir::FreezeOp freeze : freezes) + freeze->erase(); +} + /// The store that spills indirect parameter \p blockArg, if the parameter's /// only use is that store. Null otherwise. static cir::StoreOp maybeFindParamSpill(mlir::BlockArgument blockArg) { @@ -2167,6 +2173,8 @@ CIRABIRewriteContext::rewriteCallSite(mlir::Operation *callOp, // Indirect argument passes or copies from the address the load read from. // The old call still uses them, so erase them only after it is gone. SmallVector<cir::LoadOp> deadRecordLoads; + // Erased before deadRecordLoads, since a freeze keeps its load alive. + SmallVector<cir::FreezeOp> deadFreezes; // Capture original arg types before building newArgs (an Indirect argument // changes the wire argument from T to !cir.ptr<T>, so we save the @@ -2187,12 +2195,33 @@ CIRABIRewriteContext::rewriteCallSite(mlir::Operation *callOp, // Recorded before the Ignore skip below, so an ignored first ellipsis // argument still marks where the ellipsis arguments begin in newArgs. std::optional<unsigned> ellipsisStart; + // Where each argument starts in newArgs, and the freezes to reapply there + // once every argument is rewritten. + SmallVector<unsigned> argBegin; + SmallVector<std::pair<unsigned, cir::FreezeOp>> refreezes; for (auto [idx, ac] : llvm::enumerate(fc.argInfos)) { if (idx == numDeclared) ellipsisStart = newArgs.size(); - if (ac.kind == ArgKind::Ignore) - continue; + argBegin.push_back(newArgs.size()); mlir::Value arg = argOperands[idx]; + auto freeze = arg.getDefiningOp<cir::FreezeOp>(); + if (freeze && !freeze->hasOneUse()) + freeze = {}; + if (ac.kind == ArgKind::Ignore) { + if (freeze) + deadFreezes.push_back(freeze); + continue; + } + + // Refreeze after the ABI rewrite, as classic CodeGen does, so padding is + // frozen too. Indirect freezes only the pointer, so keep non-load freezes. + if (freeze && ((ac.kind != ArgKind::Indirect && + ac.kind != ArgKind::IndirectAliased) || + freeze.getInput().getDefiningOp<cir::LoadOp>())) { + arg = freeze.getInput(); + deadFreezes.push_back(freeze); + refreezes.push_back({idx, freeze}); + } if (cir::RecordType flatTy = getFlattenedCoercedType(ac, dl)) { // Direct + canFlatten: pass one scalar call argument per field of the // ABI-coerced struct. A non-atomic record load is read in place or @@ -2362,6 +2391,11 @@ CIRABIRewriteContext::rewriteCallSite(mlir::Operation *callOp, newArgs.push_back(arg); } } + argBegin.push_back(newArgs.size()); + builder.setInsertionPoint(call); + for (auto [idx, freeze] : refreezes) + for (unsigned i = argBegin[idx]; i != argBegin[idx + 1]; ++i) + newArgs[i] = cir::FreezeOp::create(builder, freeze.getLoc(), newArgs[i]); unsigned numEllipsisArgs = ellipsisStart ? newArgs.size() - *ellipsisStart : 0; @@ -2378,6 +2412,7 @@ CIRABIRewriteContext::rewriteCallSite(mlir::Operation *callOp, origRetTy, origCallArgTypes, builder, dl, enableNoundefAttrs))) return mlir::failure(); + eraseDeadFreezes(deadFreezes); eraseDeadRecordLoads(deadRecordLoads); return mlir::success(); } @@ -2446,6 +2481,7 @@ CIRABIRewriteContext::rewriteCallSite(mlir::Operation *callOp, } call->erase(); + eraseDeadFreezes(deadFreezes); eraseDeadRecordLoads(deadRecordLoads); return mlir::success(); diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp index 5565d221bbaa13..ae73b16a42782d 100644 --- a/clang/lib/CodeGen/CGCall.cpp +++ b/clang/lib/CodeGen/CGCall.cpp @@ -2696,27 +2696,6 @@ static bool DetermineNoUndef(QualType QTy, CodeGenTypes &Types, return false; } -/// Check if the argument of a function has maybe_undef attribute. -static bool IsArgumentMaybeUndef(const Decl *TargetDecl, - unsigned NumRequiredArgs, unsigned ArgNo) { - const auto *FD = dyn_cast_or_null<FunctionDecl>(TargetDecl); - if (!FD) - return false; - - // Assume variadic arguments do not have maybe_undef attribute. - if (ArgNo >= NumRequiredArgs) - return false; - - // Check if argument has maybe_undef attribute. - if (ArgNo < FD->getNumParams()) { - const ParmVarDecl *Param = FD->getParamDecl(ArgNo); - if (Param && Param->hasAttr<MaybeUndefAttr>()) - return true; - } - - return false; -} - /// Test if it's legal to apply nofpclass for the given parameter type and it's /// lowered IR type. static bool canApplyNoFPClass(const ABIArgInfo &AI, QualType ParamType, @@ -5905,8 +5884,8 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo, unsigned FirstIRArg, NumIRArgs; std::tie(FirstIRArg, NumIRArgs) = IRFunctionArgs.getIRArgs(ArgNo); - bool ArgHasMaybeUndefAttr = - IsArgumentMaybeUndef(TargetDecl, CallInfo.getNumRequiredArgs(), ArgNo); + bool ArgHasMaybeUndefAttr = CodeGenUtils::isArgumentMaybeUndef( + TargetDecl, CallInfo.getNumRequiredArgs(), ArgNo); switch (ArgInfo.getKind()) { case ABIArgInfo::InAlloca: { diff --git a/clang/lib/CodeGenUtils/CallUtils.cpp b/clang/lib/CodeGenUtils/CallUtils.cpp index 06747f04955e9f..9844f60cd1ce55 100644 --- a/clang/lib/CodeGenUtils/CallUtils.cpp +++ b/clang/lib/CodeGenUtils/CallUtils.cpp @@ -7,6 +7,7 @@ //===----------------------------------------------------------------------===// #include "clang/CodeGenUtils/CallUtils.h" +#include "clang/AST/Attr.h" #include "clang/AST/ExprCXX.h" #include "clang/Basic/TargetCXXABI.h" @@ -27,6 +28,26 @@ llvm::FPClassTest getNoFPClassTestMask(const LangOptions &LangOpts) { return Mask; } +bool isArgumentMaybeUndef(const Decl *TargetDecl, unsigned NumRequiredArgs, + unsigned ArgNo) { + const auto *FD = dyn_cast_or_null<FunctionDecl>(TargetDecl); + if (!FD) + return false; + + // Assume variadic arguments do not have maybe_undef attribute. + if (ArgNo >= NumRequiredArgs) + return false; + + // Check if argument has maybe_undef attribute. + if (ArgNo < FD->getNumParams()) { + const ParmVarDecl *Param = FD->getParamDecl(ArgNo); + if (Param && Param->hasAttr<MaybeUndefAttr>()) + return true; + } + + return false; +} + EvaluationOrder getCallArgEvaluationOrder(const CallExpr *E) { // Note that we allow this to override the order dictated by the calling // convention on the MS ABI, which means that parameter destruction order is diff --git a/clang/test/CIR/CodeGen/attr-maybeundef.cpp b/clang/test/CIR/CodeGen/attr-maybeundef.cpp new file mode 100644 index 00000000000000..fede9565572def --- /dev/null +++ b/clang/test/CIR/CodeGen/attr-maybeundef.cpp @@ -0,0 +1,146 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir +// RUN: FileCheck --check-prefix=CIR --input-file=%t.cir %s +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o %t-cir.ll +// RUN: FileCheck --check-prefix=LLVM --input-file=%t-cir.ll %s +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm %s -o %t.ll +// RUN: FileCheck --check-prefix=LLVM --input-file=%t.ll %s + +#define __maybe_undef __attribute__((maybe_undef)) + +struct Pad { char c; int i; }; +struct Dbl { double a, b; }; +struct Big { int a[10]; }; +struct NT { NT(const NT &); int x; }; +struct E {}; + +void scalar(int a, int __maybe_undef b, int c); +void variadic(int __maybe_undef x, ...); +void coerced(Pad __maybe_undef p); +void flattened(Dbl __maybe_undef d); +void byval(Big __maybe_undef b); +void bitint(_BitInt(129) __maybe_undef x); +void indirect(NT __maybe_undef n); +void cfloat(_Complex float __maybe_undef c); +void cdouble(_Complex double __maybe_undef c); +void ignored(E __maybe_undef e); + +void test_scalar() { + int x, y, z; + scalar(x, y, z); + variadic(x, y); +} + +// CIR-LABEL: cir.func{{.*}} @_Z11test_scalarv() +// CIR: %[[X:.*]] = cir.load{{.*}} : !cir.ptr<!s32i>, !s32i +// CIR: %[[Y:.*]] = cir.load{{.*}} : !cir.ptr<!s32i>, !s32i +// CIR: %[[Z:.*]] = cir.load{{.*}} : !cir.ptr<!s32i>, !s32i +// CIR: %[[FY:.*]] = cir.freeze %[[Y]] : !s32i +// CIR-NEXT: cir.call @_Z6scalariii(%[[X]], %[[FY]], %[[Z]]) +// CIR: %[[X2:.*]] = cir.load{{.*}} : !cir.ptr<!s32i>, !s32i +// CIR: %[[Y2:.*]] = cir.load{{.*}} : !cir.ptr<!s32i>, !s32i +// CIR: %[[FX2:.*]] = cir.freeze %[[X2]] : !s32i +// CIR-NEXT: cir.call @_Z8variadiciz(%[[FX2]], %[[Y2]]) + +// LLVM-LABEL: define{{.*}} void @_Z11test_scalarv() +// LLVM: %[[X:.*]] = load i32 +// LLVM: %[[Y:.*]] = load i32 +// LLVM: %[[Z:.*]] = load i32 +// LLVM: %[[FY:.*]] = freeze i32 %[[Y]] +// LLVM-NEXT: call void @_Z6scalariii(i32 noundef %[[X]], i32 noundef %[[FY]], i32 noundef %[[Z]]) +// LLVM: %[[X2:.*]] = load i32 +// LLVM: %[[Y2:.*]] = load i32 +// LLVM: %[[FX2:.*]] = freeze i32 %[[X2]] +// LLVM-NEXT: call void (i32, ...) @_Z8variadiciz(i32 noundef %[[FX2]], i32 noundef %[[Y2]]) + +// The coerced value is frozen, so the padding bytes are frozen too. +void test_coerced(Pad p) { coerced(p); } + +// CIR-LABEL: cir.func{{.*}} @_Z12test_coerced3Pad( +// CIR: %[[V:.*]] = cir.load{{.*}} : !cir.ptr<!u64i>, !u64i +// CIR-NEXT: %[[F:.*]] = cir.freeze %[[V]] : !u64i +// CIR-NEXT: cir.call @_Z7coerced3Pad(%[[F]]) + +// LLVM-LABEL: define{{.*}} void @_Z12test_coerced3Pad( +// LLVM: %[[V:.*]] = load i64 +// LLVM-NEXT: %[[F:.*]] = freeze i64 %[[V]] +// LLVM-NEXT: call void @_Z7coerced3Pad(i64 %[[F]]) + +void test_flattened(Dbl d) { flattened(d); } + +// CIR-LABEL: cir.func{{.*}} @_Z14test_flattened3Dbl( +// CIR: %[[A:.*]] = cir.load{{.*}} : !cir.ptr<!cir.double>, !cir.double +// CIR: %[[B:.*]] = cir.load{{.*}} : !cir.ptr<!cir.double>, !cir.double +// CIR-NEXT: %[[FA:.*]] = cir.freeze %[[A]] : !cir.double +// CIR-NEXT: %[[FB:.*]] = cir.freeze %[[B]] : !cir.double +// CIR-NEXT: cir.call @_Z9flattened3Dbl(%[[FA]], %[[FB]]) + +// LLVM-LABEL: define{{.*}} void @_Z14test_flattened3Dbl( +// LLVM-DAG: %[[FA:.*]] = freeze double +// LLVM-DAG: %[[FB:.*]] = freeze double +// LLVM: call void @_Z9flattened3Dbl(double %[[FA]], double %[[FB]]) + +// Like classic CodeGen, an indirect argument freezes the pointer. +void test_byval(Big b) { byval(b); } + +// CIR-LABEL: cir.func{{.*}} @_Z10test_byval3Big( +// CIR: %[[F:.*]] = cir.freeze %{{.*}} : !cir.ptr<!rec_Big> +// CIR-NEXT: cir.call @_Z5byval3Big(%[[F]]) + +// LLVM-LABEL: define{{.*}} void @_Z10test_byval3Big( +// LLVM: %[[F:.*]] = freeze ptr %{{.*}} +// LLVM-NEXT: call void @_Z5byval3Big(ptr noundef byval(%struct.Big) align 8 %[[F]]) + +void test_bitint(_BitInt(129) x) { bitint(x); } + +// CIR-LABEL: cir.func{{.*}} @_Z11test_bitintDB129_( +// CIR: %[[F:.*]] = cir.freeze %{{.*}} : !cir.ptr< +// CIR-NEXT: cir.call @_Z6bitintDB129_(%[[F]]) + +// LLVM-LABEL: define{{.*}} void @_Z11test_bitintDB129_( +// LLVM: %[[F:.*]] = freeze ptr %{{.*}} +// LLVM: call void @_Z6bitintDB129_(ptr noundef byval([24 x i8]) align 8 %[[F]]) + +void test_indirect(NT &n) { indirect(n); } + +// CIR-LABEL: cir.func{{.*}} @_Z13test_indirectR2NT( +// CIR: cir.call @_ZN2NTC1ERKS_(%[[TMP:[0-9]+]], +// CIR-NEXT: %[[F:.*]] = cir.freeze %[[TMP]] : !cir.ptr<!rec_NT> +// CIR-NEXT: cir.call @_Z8indirect2NT(%[[F]]) + +// LLVM-LABEL: define{{.*}} void @_Z13test_indirectR2NT( +// LLVM: call void @_ZN2NTC1ERKS_(ptr {{.*}} %[[TMP:[^,]+]], +// LLVM-NEXT: %[[F:.*]] = freeze ptr %[[TMP]] +// LLVM-NEXT: call void @_Z8indirect2NT(ptr {{.*}} %[[F]]) + +void test_complex(_Complex float f, _Complex double d) { + cfloat(f); + cdouble(d); +} + +// CIR-LABEL: cir.func{{.*}} @_Z12test_complexCfCd( +// CIR: %[[V:.*]] = cir.load{{.*}} : !cir.ptr<!cir.vector<2 x !cir.float>>, !cir.vector<2 x !cir.float> +// CIR-NEXT: %[[F:.*]] = cir.freeze %[[V]] : !cir.vector<2 x !cir.float> +// CIR-NEXT: cir.call @_Z6cfloatCf(%[[F]]) +// CIR: %[[R:.*]] = cir.load{{.*}} : !cir.ptr<!cir.double>, !cir.double +// CIR: %[[I:.*]] = cir.load{{.*}} : !cir.ptr<!cir.double>, !cir.double +// CIR-NEXT: %[[FR:.*]] = cir.freeze %[[R]] : !cir.double +// CIR-NEXT: %[[FI:.*]] = cir.freeze %[[I]] : !cir.double +// CIR-NEXT: cir.call @_Z7cdoubleCd(%[[FR]], %[[FI]]) + +// LLVM-LABEL: define{{.*}} void @_Z12test_complexCfCd( +// LLVM: %[[V:.*]] = load <2 x float> +// LLVM-NEXT: %[[F:.*]] = freeze <2 x float> %[[V]] +// LLVM-NEXT: call void @_Z6cfloatCf(<2 x float> noundef %[[F]]) +// LLVM-DAG: %[[FR:.*]] = freeze double +// LLVM-DAG: %[[FI:.*]] = freeze double +// LLVM: call void @_Z7cdoubleCd(double noundef %[[FR]], double noundef %[[FI]]) + +void test_ignored(E e) { ignored(e); } + +// CIR-LABEL: cir.func{{.*}} @_Z12test_ignored1E( +// CIR-NOT: cir.freeze +// CIR: cir.call @_Z7ignored1E() + +// LLVM-LABEL: define{{.*}} void @_Z12test_ignored1E( +// LLVM-NOT: freeze +// LLVM: call void @_Z7ignored1E() diff --git a/clang/test/CIR/Transforms/abi-lowering/maybe-undef-freeze.cir b/clang/test/CIR/Transforms/abi-lowering/maybe-undef-freeze.cir new file mode 100644 index 00000000000000..8929a6aa1bbc91 --- /dev/null +++ b/clang/test/CIR/Transforms/abi-lowering/maybe-undef-freeze.cir @@ -0,0 +1,154 @@ +// RUN: cir-opt %s -cir-call-conv-lowering="classification-attr=test_classify" \ +// RUN: | FileCheck %s + +!s32i = !cir.int<s, 32> +!s64i = !cir.int<s, 64> +!rec_Pair = !cir.struct<"Pair" {data !s32i, data !s32i}> + +#coerce_pair_to_i64 = { + return = { kind = "direct" }, + args = [ { kind = "direct", coerced_type = !s64i } ] +} + +#indirect_pair = { + return = { kind = "direct" }, + args = [ { kind = "indirect", indirect_align = 4, byval = false } ] +} + +#byval_pair = { + return = { kind = "direct" }, + args = [ { kind = "indirect", indirect_align = 4, byval = true } ] +} + +#byref_pair = { + return = { kind = "direct" }, + args = [ { kind = "indirect_aliased", indirect_align = 4 } ] +} + +#ignore_pair = { + return = { kind = "direct" }, + args = [ { kind = "ignore" } ] +} + +#caller_no_args = { + return = { kind = "direct" }, + args = [ ] +} + +module attributes { + dlti.dl_spec = #dlti.dl_spec< + #dlti.dl_entry<i32, dense<32>: vector<2xi64>>, + #dlti.dl_entry<i64, dense<64>: vector<2xi64>>> +} { + + cir.func private @coerced(!rec_Pair) + requires_call_conv_lowering attributes { test_classify = #coerce_pair_to_i64 } + cir.func private @indirect(!rec_Pair) + requires_call_conv_lowering attributes { test_classify = #indirect_pair } + cir.func private @byval(!rec_Pair) + requires_call_conv_lowering attributes { test_classify = #byval_pair } + cir.func private @byref(!rec_Pair) + requires_call_conv_lowering attributes { test_classify = #byref_pair } + cir.func private @ignored(!rec_Pair) + requires_call_conv_lowering attributes { test_classify = #ignore_pair } + + cir.func @freeze_coerced() + requires_call_conv_lowering attributes { test_classify = #caller_no_args } { + %0 = cir.alloca "p" align(4) : !cir.ptr<!rec_Pair> + %1 = cir.load %0 : !cir.ptr<!rec_Pair>, !rec_Pair + %2 = cir.freeze %1 : !rec_Pair + cir.call @coerced(%2) : (!rec_Pair) -> () + cir.return + } + + // CHECK-LABEL: cir.func{{.*}} @freeze_coerced() + // CHECK: %[[P:.*]] = cir.alloca "p" {{.*}} : !cir.ptr<!rec_Pair> + // CHECK: %[[CAST:.*]] = cir.cast bitcast %[[P]] : !cir.ptr<!rec_Pair> -> !cir.ptr<!s64i> + // CHECK: %[[INT:.*]] = cir.load align(4) %[[CAST]] : !cir.ptr<!s64i>, !s64i + // CHECK-NEXT: %[[F:.*]] = cir.freeze %[[INT]] : !s64i + // CHECK-NEXT: cir.call @coerced(%[[F]]) : (!s64i) -> () + // CHECK-NOT: cir.freeze + + // The freeze no longer hides the load, so the call forwards its storage. + cir.func @freeze_indirect() + requires_call_conv_lowering attributes { test_classify = #caller_no_args } { + %0 = cir.alloca "p" align(4) : !cir.ptr<!rec_Pair> + %1 = cir.load %0 : !cir.ptr<!rec_Pair>, !rec_Pair + %2 = cir.freeze %1 : !rec_Pair + cir.call @indirect(%2) : (!rec_Pair) -> () + cir.return + } + + // CHECK-LABEL: cir.func{{.*}} @freeze_indirect() + // CHECK: %[[P:.*]] = cir.alloca "p" {{.*}} : !cir.ptr<!rec_Pair> + // CHECK-NEXT: %[[F:.*]] = cir.freeze %[[P]] : !cir.ptr<!rec_Pair> + // CHECK-NEXT: cir.call @indirect(%[[F]]) : (!cir.ptr<!rec_Pair> {{.*}}) -> () + // CHECK-NOT: cir.freeze + + // A byval slot stored from a frozen non-load value keeps the value frozen. + cir.func @freeze_byval_value() + requires_call_conv_lowering attributes { test_classify = #caller_no_args } { + %0 = cir.const #cir.poison : !rec_Pair + %1 = cir.freeze %0 : !rec_Pair + cir.call @byval(%1) : (!rec_Pair) -> () + cir.return + } + + // CHECK-LABEL: cir.func{{.*}} @freeze_byval_value() + // CHECK: %[[V:.*]] = cir.const #cir.poison : !rec_Pair + // CHECK-NEXT: %[[F:.*]] = cir.freeze %[[V]] : !rec_Pair + // CHECK: cir.store %[[F]], %[[SLOT:.*]] : !rec_Pair, !cir.ptr<!rec_Pair> + // CHECK-NEXT: cir.call @byval(%[[SLOT]]) + // CHECK-NOT: cir.freeze + + cir.func @freeze_byref_value() + requires_call_conv_lowering attributes { test_classify = #caller_no_args } { + %0 = cir.const #cir.poison : !rec_Pair + %1 = cir.freeze %0 : !rec_Pair + cir.call @byref(%1) : (!rec_Pair) -> () + cir.return + } + + // CHECK-LABEL: cir.func{{.*}} @freeze_byref_value() + // CHECK: %[[V:.*]] = cir.const #cir.poison : !rec_Pair + // CHECK-NEXT: %[[F:.*]] = cir.freeze %[[V]] : !rec_Pair + // CHECK: cir.store %[[F]], %[[SLOT:.*]] : !rec_Pair, !cir.ptr<!rec_Pair> + // CHECK-NEXT: cir.call @byref(%[[SLOT]]) + // CHECK-NOT: cir.freeze + + cir.func @freeze_ignored() + requires_call_conv_lowering attributes { test_classify = #caller_no_args } { + %0 = cir.alloca "p" align(4) : !cir.ptr<!rec_Pair> + %1 = cir.load %0 : !cir.ptr<!rec_Pair>, !rec_Pair + %2 = cir.freeze %1 : !rec_Pair + cir.call @ignored(%2) : (!rec_Pair) -> () + cir.return + } + + // CHECK-LABEL: cir.func{{.*}} @freeze_ignored() + // CHECK-NOT: cir.freeze + // CHECK: cir.call @ignored() : () -> () + // CHECK-NOT: cir.freeze + + // A shared freeze stays put, since all its uses must see one value. + cir.func @freeze_shared() + requires_call_conv_lowering attributes { test_classify = #caller_no_args } { + %0 = cir.alloca "p" align(4) : !cir.ptr<!rec_Pair> + %1 = cir.load %0 : !cir.ptr<!rec_Pair>, !rec_Pair + %2 = cir.freeze %1 : !rec_Pair + cir.call @coerced(%2) : (!rec_Pair) -> () + cir.call @coerced(%2) : (!rec_Pair) -> () + cir.return + } + + // CHECK-LABEL: cir.func{{.*}} @freeze_shared() + // CHECK: %[[V:.*]] = cir.load {{.*}} : !cir.ptr<!rec_Pair>, !rec_Pair + // CHECK-NEXT: %[[F:.*]] = cir.freeze %[[V]] : !rec_Pair + // CHECK: cir.store {{.*}}%[[F]], %{{.*}} : !rec_Pair, !cir.ptr<!rec_Pair> + // CHECK: %[[A:.*]] = cir.load {{.*}} : !cir.ptr<!s64i>, !s64i + // CHECK-NEXT: cir.call @coerced(%[[A]]) : (!s64i) -> () + // CHECK: cir.store {{.*}}%[[F]], %{{.*}} : !rec_Pair, !cir.ptr<!rec_Pair> + // CHECK: %[[B:.*]] = cir.load {{.*}} : !cir.ptr<!s64i>, !s64i + // CHECK-NEXT: cir.call @coerced(%[[B]]) : (!s64i) -> () + +} _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
