https://github.com/jeanPerier updated https://github.com/llvm/llvm-project/pull/210930
>From 5ee248e30ecc9452f03908af00d58e8b1e74202e Mon Sep 17 00:00:00 2001 From: root <[email protected]> Date: Tue, 21 Jul 2026 02:05:38 -0700 Subject: [PATCH] [flang] Remove legacy stack-arrays and memory-allocation-opt passes The unified allocation-placement pass now supersedes both the heap-to-stack stack-arrays pass and the stack-to-heap memory-allocation-opt pass, and is the default in the FIR optimizer pipeline. Remove the two legacy passes: their TableGen definitions, the MemoryAllocation.cpp source, the memory-allocation-opt command-line options, the enable-allocation-placement fallback switch, and the addMemoryAllocationOpt pipeline helper. The pass-only portions of StackArrays.cpp are dropped while its analysis and rewrite pattern, now shared with allocation-placement, are kept. The legacy tests are retargeted onto allocation-placement to show it reproduces both prior behaviors: the stack-arrays tests use "stack-arrays=true", and the memory-allocation-opt tests use the default policy (runtime-sized and big constant-size temporaries go on the heap). --- flang/docs/fstack-arrays.md | 2 - .../flang/Optimizer/Passes/CommandLineOpts.h | 14 -- .../flang/Optimizer/Passes/Pipelines.h | 2 - .../flang/Optimizer/Transforms/Passes.td | 28 ---- .../lib/Optimizer/Passes/CommandLineOpts.cpp | 22 --- flang/lib/Optimizer/Passes/Pipelines.cpp | 12 +- flang/lib/Optimizer/Transforms/CMakeLists.txt | 2 - .../Optimizer/Transforms/MemoryAllocation.cpp | 150 ------------------ .../lib/Optimizer/Transforms/StackArrays.cpp | 71 --------- .../Fir/allocation-placement-pipeline.fir | 16 +- flang/test/Fir/memory-allocation-opt-2.fir | 7 +- .../memory-allocation-opt-do-concurrent.fir | 5 +- flang/test/Fir/memory-allocation-opt.fir | 17 +- .../stack-arrays-block-cfg-scope.fir | 2 +- flang/test/Transforms/stack-arrays-hlfir.f90 | 2 +- .../test/Transforms/stack-arrays-lifetime.fir | 2 +- .../Transforms/stack-arrays-nested-scope.fir | 2 +- flang/test/Transforms/stack-arrays-scope.f90 | 2 +- flang/test/Transforms/stack-arrays.fir | 2 +- 19 files changed, 33 insertions(+), 327 deletions(-) delete mode 100644 flang/lib/Optimizer/Transforms/MemoryAllocation.cpp diff --git a/flang/docs/fstack-arrays.md b/flang/docs/fstack-arrays.md index 038d361c2a465..7a87d7fffa885 100644 --- a/flang/docs/fstack-arrays.md +++ b/flang/docs/fstack-arrays.md @@ -223,5 +223,3 @@ target- or region-specific placement strategies to be layered on top. tune the "small array" byte-size threshold and the per-function stack budget. - `-disable-allocation-placement`: skip the pass entirely (no stack/heap rewriting). -- `-enable-allocation-placement=false`: fall back to the legacy `stack-arrays` - and `memory-allocation-opt` passes for A/B comparison. diff --git a/flang/include/flang/Optimizer/Passes/CommandLineOpts.h b/flang/include/flang/Optimizer/Passes/CommandLineOpts.h index 30397b77d1c4b..17e6cfd300e7b 100644 --- a/flang/include/flang/Optimizer/Passes/CommandLineOpts.h +++ b/flang/include/flang/Optimizer/Passes/CommandLineOpts.h @@ -16,14 +16,6 @@ #include "llvm/Passes/OptimizationLevel.h" #include "llvm/Support/CommandLine.h" -/// Shared option in tools to control whether dynamically sized array -/// allocations should always be on the heap. -extern llvm::cl::opt<bool> dynamicArrayStackToHeapAllocation; - -/// Shared option in tools to set a maximum value for the number of elements in -/// a compile-time sized array that can be allocated on the stack. -extern llvm::cl::opt<std::size_t> arrayStackAllocationThreshold; - /// Shared option in tools to ignore missing runtime type descriptor objects /// when translating FIR to LLVM. The resulting program will crash if the /// runtime needs the derived type descriptors, this is only a debug option to @@ -53,15 +45,9 @@ extern llvm::codegenoptions::DebugInfoKind noDebugInfo; /// Optimizer Passes extern llvm::cl::opt<bool> disableCfgConversion; extern llvm::cl::opt<bool> disableFirAliasTags; -extern llvm::cl::opt<bool> disableFirMao; extern llvm::cl::opt<bool> enableFirLICM; extern llvm::cl::opt<bool> useOldAliasTags; -/// Use the unified allocation-placement pass instead of the legacy stack-arrays -/// and memory-allocation-opt passes. Enabled by default; set to false to fall -/// back to the legacy passes. -extern llvm::cl::opt<bool> enableAllocationPlacement; - /// Skip the allocation-placement pass entirely (no stack/heap rewriting). extern llvm::cl::opt<bool> disableAllocationPlacement; diff --git a/flang/include/flang/Optimizer/Passes/Pipelines.h b/flang/include/flang/Optimizer/Passes/Pipelines.h index e8ead893dd089..6c356be7ac129 100644 --- a/flang/include/flang/Optimizer/Passes/Pipelines.h +++ b/flang/include/flang/Optimizer/Passes/Pipelines.h @@ -81,8 +81,6 @@ void addCanonicalizerPassWithoutRegionSimplification(mlir::OpPassManager &pm); void addCfgConversionPass(mlir::PassManager &pm, const MLIRToLLVMPassPipelineConfig &config); -void addMemoryAllocationOpt(mlir::PassManager &pm); - void addAllocationPlacement(mlir::PassManager &pm, bool stackArrays); void addCodeGenRewritePass(mlir::PassManager &pm, bool preserveDeclare); diff --git a/flang/include/flang/Optimizer/Transforms/Passes.td b/flang/include/flang/Optimizer/Transforms/Passes.td index ba29cd6df2eac..1eee04f6f3ff1 100644 --- a/flang/include/flang/Optimizer/Transforms/Passes.td +++ b/flang/include/flang/Optimizer/Transforms/Passes.td @@ -295,23 +295,6 @@ def SimplifyIntrinsics : Pass<"simplify-intrinsics", "mlir::ModuleOp"> { ]; } -def MemoryAllocationOpt : Pass<"memory-allocation-opt", "mlir::func::FuncOp"> { - let summary = "Convert stack to heap allocations and vice versa."; - let description = [{ - Convert stack allocations to heap allocations and vice versa based on - estimated size, lifetime, usage patterns, the call tree, etc. - }]; - let dependentDialects = [ "fir::FIROpsDialect" ]; - let options = [ - Option<"dynamicArrayOnHeap", "dynamic-array-on-heap", - "bool", /*default=*/"false", - "Allocate all arrays with runtime determined size on heap.">, - Option<"maxStackArraySize", "maximum-array-alloc-size", - "std::size_t", /*default=*/"~static_cast<std::size_t>(0)", - "Set maximum number of elements of an array allocated on the stack."> - ]; -} - def AllocationPlacement : Pass<"allocation-placement", "mlir::func::FuncOp"> { let summary = "Place array allocations on the stack or the heap by policy."; let description = [{ @@ -347,17 +330,6 @@ def ConstantArgumentGlobalisationOpt : Pass<"constant-argument-globalisation-opt let dependentDialects = [ "fir::FIROpsDialect" ]; } -def StackArrays : Pass<"stack-arrays", "mlir::func::FuncOp"> { - let summary = "Move local array allocations from heap memory into stack memory"; - let description = [{ - Convert heap allocations for arrays, even those of unknown size, into stack - allocations. - }]; - let dependentDialects = [ - "fir::FIROpsDialect", "mlir::DLTIDialect", "mlir::LLVM::LLVMDialect" - ]; -} - def StackReclaim : Pass<"stack-reclaim"> { let summary = "Insert stacksave/stackrestore in region with allocas"; let description = [{ diff --git a/flang/lib/Optimizer/Passes/CommandLineOpts.cpp b/flang/lib/Optimizer/Passes/CommandLineOpts.cpp index 2a78391a1780f..14aa3620d2571 100644 --- a/flang/lib/Optimizer/Passes/CommandLineOpts.cpp +++ b/flang/lib/Optimizer/Passes/CommandLineOpts.cpp @@ -22,17 +22,6 @@ using namespace llvm; cl::desc("enable " EODescription " pass"), \ cl::init(false), cl::Hidden) -cl::opt<bool> dynamicArrayStackToHeapAllocation( - "fdynamic-heap-array", - cl::desc("place all array allocations of dynamic size on the heap"), - cl::init(false), cl::Hidden); - -cl::opt<std::size_t> arrayStackAllocationThreshold( - "fstack-array-size", - cl::desc( - "place all array allocations more than <size> elements on the heap"), - cl::init(~static_cast<std::size_t>(0)), cl::Hidden); - cl::opt<bool> ignoreMissingTypeDescriptors( "ignore-missing-type-desc", cl::desc("ignore failures to find derived type descriptors when " @@ -51,9 +40,6 @@ codegenoptions::DebugInfoKind noDebugInfo{codegenoptions::NoDebugInfo}; /// Optimizer Passes DisableOption(CfgConversion, "cfg-conversion", "disable FIR to CFG pass"); -DisableOption(FirMao, "memory-allocation-opt", - "memory allocation optimization"); - DisableOption(FirAliasTags, "fir-alias-tags", "fir alias analysis"); cl::opt<bool> useOldAliasTags( "use-old-alias-tags", @@ -61,14 +47,6 @@ cl::opt<bool> useOldAliasTags( "the FIR alias tags pass"), cl::init(false), cl::Hidden); EnableOption(FirLICM, "fir-licm", "FIR loop invariant code motion"); -// Enabled by default: the unified allocation-placement pass supersedes the -// legacy stack-arrays and memory-allocation-opt passes. Pass -// -enable-allocation-placement=false to fall back to the legacy passes. -cl::opt<bool> enableAllocationPlacement( - "enable-allocation-placement", - cl::desc("use the unified array allocation-placement pass instead of the " - "legacy stack-arrays and memory-allocation-opt passes"), - cl::init(true), cl::Hidden); DisableOption(AllocationPlacement, "allocation-placement", "unified array allocation placement"); diff --git a/flang/lib/Optimizer/Passes/Pipelines.cpp b/flang/lib/Optimizer/Passes/Pipelines.cpp index d0b78040a77ab..771a2b1db0901 100644 --- a/flang/lib/Optimizer/Passes/Pipelines.cpp +++ b/flang/lib/Optimizer/Passes/Pipelines.cpp @@ -66,11 +66,6 @@ void addCfgConversionPass(mlir::PassManager &pm, pm, disableCfgConversion, [&]() { return createCFGConversion(options); }); } -void addMemoryAllocationOpt(mlir::PassManager &pm) { - addNestedPassConditionally<mlir::func::FuncOp>(pm, disableFirMao, [&]() { - return fir::createMemoryAllocationOpt( - {dynamicArrayStackToHeapAllocation, arrayStackAllocationThreshold}); - }); } void addAllocationPlacement(mlir::PassManager &pm, bool stackArrays) { @@ -226,12 +221,7 @@ void createDefaultFIROptimizerPassPipeline(mlir::PassManager &pm, pm.addPass(mlir::createCSEPass()); - if (enableAllocationPlacement) - fir::addAllocationPlacement(pm, pc.StackArrays); - else if (pc.StackArrays) - pm.addPass(fir::createStackArrays()); - else - fir::addMemoryAllocationOpt(pm); + fir::addAllocationPlacement(pm, pc.StackArrays); // FIR Inliner Callback pc.invokeFIRInlinerCallback(pm, pc.OptLevel); diff --git a/flang/lib/Optimizer/Transforms/CMakeLists.txt b/flang/lib/Optimizer/Transforms/CMakeLists.txt index 997dc22063138..88ecfba0d7888 100644 --- a/flang/lib/Optimizer/Transforms/CMakeLists.txt +++ b/flang/lib/Optimizer/Transforms/CMakeLists.txt @@ -34,7 +34,6 @@ add_flang_library(FIRTransforms FIRToSCF.cpp FIRToMemRef.cpp MemoryUtils.cpp - MemoryAllocation.cpp StackArrays.cpp MemRefDataFlowOpt.cpp SimplifyRegionLite.cpp @@ -48,7 +47,6 @@ add_flang_library(FIRTransforms LoopVersioning.cpp MIFOpConversion.cpp MemRefDataFlowOpt.cpp - MemoryAllocation.cpp MemoryUtils.cpp OptimizeArrayRepacking.cpp PolymorphicOpConversion.cpp diff --git a/flang/lib/Optimizer/Transforms/MemoryAllocation.cpp b/flang/lib/Optimizer/Transforms/MemoryAllocation.cpp deleted file mode 100644 index fd1d566ca2825..0000000000000 --- a/flang/lib/Optimizer/Transforms/MemoryAllocation.cpp +++ /dev/null @@ -1,150 +0,0 @@ -//===- MemoryAllocation.cpp -----------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#include "flang/Optimizer/Dialect/FIRDialect.h" -#include "flang/Optimizer/Dialect/FIROps.h" -#include "flang/Optimizer/Dialect/FIRType.h" -#include "flang/Optimizer/Transforms/MemoryUtils.h" -#include "flang/Optimizer/Transforms/Passes.h" -#include "mlir/Dialect/Func/IR/FuncOps.h" -#include "mlir/IR/Diagnostics.h" -#include "mlir/Pass/Pass.h" -#include "mlir/Transforms/DialectConversion.h" - -namespace fir { -#define GEN_PASS_DEF_MEMORYALLOCATIONOPT -#include "flang/Optimizer/Transforms/Passes.h.inc" -} // namespace fir - -#define DEBUG_TYPE "flang-memory-allocation-opt" - -// Number of elements in an array does not determine where it is allocated. -static constexpr std::size_t unlimitedArraySize = ~static_cast<std::size_t>(0); - -/// Return `true` if this allocation is to remain on the stack (`fir.alloca`). -/// Otherwise the allocation should be moved to the heap (`fir.allocmem`). -static inline bool -keepStackAllocation(fir::AllocaOp alloca, - const fir::MemoryAllocationOptOptions &options) { - // Move all arrays and character with runtime determined size to the heap. - if (options.dynamicArrayOnHeap && alloca.isDynamic()) - return false; - // TODO: use data layout to reason in terms of byte size to cover all "big" - // entities, which may be scalar derived types. - if (auto seqTy = mlir::dyn_cast<fir::SequenceType>(alloca.getInType())) { - if (!fir::hasDynamicSize(seqTy)) { - std::int64_t numberOfElements = 1; - for (std::int64_t i : seqTy.getShape()) { - numberOfElements *= i; - // If the count is suspicious, then don't change anything here. - if (numberOfElements <= 0) - return true; - } - // If the number of elements exceeds the threshold, move the allocation to - // the heap. - if (static_cast<std::size_t>(numberOfElements) > - options.maxStackArraySize) { - return false; - } - } - } - return true; -} - -static mlir::Value genAllocmem(mlir::OpBuilder &builder, fir::AllocaOp alloca, - bool deallocPointsDominateAlloc) { - mlir::Type varTy = alloca.getInType(); - auto unpackName = [](std::optional<llvm::StringRef> opt) -> llvm::StringRef { - if (opt) - return *opt; - return {}; - }; - llvm::StringRef uniqName = unpackName(alloca.getUniqName()); - llvm::StringRef bindcName = unpackName(alloca.getBindcName()); - auto heap = fir::AllocMemOp::create(builder, alloca.getLoc(), varTy, uniqName, - bindcName, alloca.getTypeparams(), - alloca.getShape()); - LLVM_DEBUG(llvm::dbgs() << "memory allocation opt: replaced " << alloca - << " with " << heap << '\n'); - return heap; -} - -static void genFreemem(mlir::Location loc, mlir::OpBuilder &builder, - mlir::Value allocmem) { - [[maybe_unused]] auto free = fir::FreeMemOp::create(builder, loc, allocmem); - LLVM_DEBUG(llvm::dbgs() << "memory allocation opt: add free " << free - << " for " << allocmem << '\n'); -} - -/// This pass can reclassify memory allocations (fir.alloca, fir.allocmem) based -/// on heuristics and settings. The intention is to allow better performance and -/// workarounds for conditions such as environments with limited stack space. -/// -/// Currently, implements two conversions from stack to heap allocation. -/// 1. If a stack allocation is an array larger than some threshold value -/// make it a heap allocation. -/// 2. If a stack allocation is an array with a runtime evaluated size make -/// it a heap allocation. -namespace { -class MemoryAllocationOpt - : public fir::impl::MemoryAllocationOptBase<MemoryAllocationOpt> { -public: - MemoryAllocationOpt() { - // Set options with default values. (See Passes.td.) Note that the - // command-line options, e.g. dynamicArrayOnHeap, are not set yet. - options = {dynamicArrayOnHeap, maxStackArraySize}; - } - - MemoryAllocationOpt(bool dynOnHeap, std::size_t maxStackSize) { - // Set options with default values. (See Passes.td.) - options = {dynOnHeap, maxStackSize}; - } - - MemoryAllocationOpt(const fir::MemoryAllocationOptOptions &options) - : options{options} {} - - /// Override `options` if command-line options have been set. - inline void useCommandLineOptions() { - if (dynamicArrayOnHeap) - options.dynamicArrayOnHeap = dynamicArrayOnHeap; - if (maxStackArraySize != unlimitedArraySize) - options.maxStackArraySize = maxStackArraySize; - } - - void runOnOperation() override { - auto *context = &getContext(); - auto func = getOperation(); - mlir::RewritePatternSet patterns(context); - mlir::ConversionTarget target(*context); - - useCommandLineOptions(); - LLVM_DEBUG(llvm::dbgs() - << "dynamic arrays on heap: " << options.dynamicArrayOnHeap - << "\nmaximum number of elements of array on stack: " - << options.maxStackArraySize << '\n'); - - // If func is a declaration, skip it. - if (func.empty()) - return; - auto tryReplacing = [&](fir::AllocaOp alloca) { - bool res = !keepStackAllocation(alloca, options); - if (res) { - LLVM_DEBUG(llvm::dbgs() - << "memory allocation opt: found " << alloca << '\n'); - } - return res; - }; - mlir::IRRewriter rewriter(context); - fir::replaceAllocas(rewriter, func.getOperation(), tryReplacing, - genAllocmem, genFreemem); - } - -private: - fir::MemoryAllocationOptOptions options; -}; -} // namespace diff --git a/flang/lib/Optimizer/Transforms/StackArrays.cpp b/flang/lib/Optimizer/Transforms/StackArrays.cpp index 77861e67a07b1..10481e577d2da 100644 --- a/flang/lib/Optimizer/Transforms/StackArrays.cpp +++ b/flang/lib/Optimizer/Transforms/StackArrays.cpp @@ -38,11 +38,6 @@ #include "llvm/Support/raw_ostream.h" #include <optional> -namespace fir { -#define GEN_PASS_DEF_STACKARRAYS -#include "flang/Optimizer/Transforms/Passes.h.inc" -} // namespace fir - #define DEBUG_TYPE "stack-arrays" static llvm::cl::opt<std::size_t> maxAllocsPerFunc( @@ -129,20 +124,6 @@ class AllocationAnalysis mlir::LogicalResult processOperation(mlir::Operation *op) override; }; -class StackArraysPass : public fir::impl::StackArraysBase<StackArraysPass> { -public: - StackArraysPass() = default; - StackArraysPass(const StackArraysPass &pass); - - llvm::StringRef getDescription() const override; - - void runOnOperation() override; - -private: - Statistic runCount{this, "stackArraysRunCount", - "Number of heap allocations moved to the stack"}; -}; - } // namespace static void print(llvm::raw_ostream &os, AllocationState state) { @@ -735,55 +716,3 @@ void fir::AllocMemConversion::insertLifetimeMarkers( newAlloc->setAttr(attrName, rewriter.getUnitAttr()); } } - -StackArraysPass::StackArraysPass(const StackArraysPass &pass) - : fir::impl::StackArraysBase<StackArraysPass>(pass) {} - -llvm::StringRef StackArraysPass::getDescription() const { - return "Move heap allocated array temporaries to the stack"; -} - -void StackArraysPass::runOnOperation() { - mlir::func::FuncOp func = getOperation(); - - auto &analysis = getAnalysis<fir::StackArraysAnalysisWrapper>(); - const fir::StackArraysAnalysisWrapper::AllocMemMap *candidateOps = - analysis.getCandidateOps(func); - if (!candidateOps) { - signalPassFailure(); - return; - } - - if (candidateOps->empty()) - return; - runCount += candidateOps->size(); - - llvm::SmallVector<mlir::Operation *> opsToConvert; - opsToConvert.reserve(candidateOps->size()); - for (auto [op, _] : *candidateOps) - opsToConvert.push_back(op); - - mlir::MLIRContext &context = getContext(); - mlir::RewritePatternSet patterns(&context); - mlir::GreedyRewriteConfig config; - // prevent the pattern driver form merging blocks - config.setRegionSimplificationLevel( - mlir::GreedySimplifyRegionLevel::Disabled); - - auto module = func->getParentOfType<mlir::ModuleOp>(); - std::optional<mlir::DataLayout> dl = - module ? fir::support::getOrSetMLIRDataLayout( - module, /*allowDefaultLayout=*/false) - : std::nullopt; - std::optional<fir::KindMapping> kindMap; - if (module) - kindMap = fir::getKindMapping(module); - - patterns.insert<fir::AllocMemConversion>(&context, *candidateOps, dl, - kindMap); - if (mlir::failed(mlir::applyOpPatternsGreedily( - opsToConvert, std::move(patterns), config))) { - mlir::emitError(func->getLoc(), "error in stack arrays optimization\n"); - signalPassFailure(); - } -} diff --git a/flang/test/Fir/allocation-placement-pipeline.fir b/flang/test/Fir/allocation-placement-pipeline.fir index 30fbd7a8d9dd2..f6c241ff1041b 100644 --- a/flang/test/Fir/allocation-placement-pipeline.fir +++ b/flang/test/Fir/allocation-placement-pipeline.fir @@ -1,20 +1,14 @@ // Test that the default optimizer pipeline uses the unified // allocation-placement pass in place of the legacy stack-arrays / -// memory-allocation-opt passes, and that -enable-allocation-placement=false -// restores the legacy passes. +// memory-allocation-opt passes. -// RUN: tco %s --mlir-pass-statistics --mlir-pass-statistics-display=pipeline 2>&1 | FileCheck %s --check-prefix=NEW -// RUN: tco -enable-allocation-placement=false %s --mlir-pass-statistics --mlir-pass-statistics-display=pipeline 2>&1 | FileCheck %s --check-prefix=OLD +// RUN: tco %s --mlir-pass-statistics --mlir-pass-statistics-display=pipeline 2>&1 | FileCheck %s // REQUIRES: asserts -// NEW-NOT: MemoryAllocationOpt -// NEW: AllocationPlacement -// NEW-NOT: MemoryAllocationOpt - -// OLD-NOT: AllocationPlacement -// OLD: MemoryAllocationOpt -// OLD-NOT: AllocationPlacement +// CHECK-NOT: MemoryAllocationOpt +// CHECK-NOT: StackArrays +// CHECK: AllocationPlacement func.func @_QPfoo() { return diff --git a/flang/test/Fir/memory-allocation-opt-2.fir b/flang/test/Fir/memory-allocation-opt-2.fir index 2addb6ba8b999..d0e9a36588b0b 100644 --- a/flang/test/Fir/memory-allocation-opt-2.fir +++ b/flang/test/Fir/memory-allocation-opt-2.fir @@ -1,5 +1,8 @@ -// Test memory allocation pass for fir.alloca outside of function entry block -// RUN: fir-opt --memory-allocation-opt="dynamic-array-on-heap=true" %s | FileCheck %s +// Test allocation placement for fir.alloca outside of function entry block. +// The default (-fno-stack-arrays) policy sends every runtime-sized array to the +// heap, reproducing the legacy memory-allocation-opt "dynamic-array-on-heap" +// behavior together with its deallocation-point handling. +// RUN: fir-opt --allocation-placement %s | FileCheck %s func.func @test_loop() { %c1 = arith.constant 1 : index diff --git a/flang/test/Fir/memory-allocation-opt-do-concurrent.fir b/flang/test/Fir/memory-allocation-opt-do-concurrent.fir index 586eb8df28684..e5d72cd58f7ba 100644 --- a/flang/test/Fir/memory-allocation-opt-do-concurrent.fir +++ b/flang/test/Fir/memory-allocation-opt-do-concurrent.fir @@ -1,4 +1,7 @@ -// RUN: fir-opt --memory-allocation-opt="dynamic-array-on-heap=true" %s | FileCheck %s +// The default (-fno-stack-arrays) policy sends every runtime-sized array to the +// heap, reproducing the legacy memory-allocation-opt "dynamic-array-on-heap" +// behavior inside do_concurrent loops (with conditional allocations). +// RUN: fir-opt --allocation-placement %s | FileCheck %s func.func @test_do_concurrent() { %c1 = arith.constant 1 : index diff --git a/flang/test/Fir/memory-allocation-opt.fir b/flang/test/Fir/memory-allocation-opt.fir index cfbca2f83ef8e..0e8d52958fa18 100644 --- a/flang/test/Fir/memory-allocation-opt.fir +++ b/flang/test/Fir/memory-allocation-opt.fir @@ -1,15 +1,22 @@ -// RUN: fir-opt --memory-allocation-opt="dynamic-array-on-heap=true maximum-array-alloc-size=1024" %s | FileCheck %s +// The default (-fno-stack-arrays) allocation-placement policy sends big +// constant-size temporaries and runtime-sized arrays to the heap, reproducing +// the legacy memory-allocation-opt size-based heap placement. A data layout is +// required to compute the constant byte size of _QPs1. +// RUN: fir-opt --allocation-placement %s | FileCheck %s -// Test for size of array being too big. +module attributes {fir.defaultkind = "a1c4d8i4l4r4", fir.kindmap = "", llvm.data_layout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"} { + +// Test for size of array being too big: a big constant-size temporary goes on +// the heap. // CHECK-LABEL: func @_QPs1( -// CHECK: %[[mem:.*]] = fir.allocmem !fir.array<1000123xi32> {bindc_name = "array", uniq_name = "_QFs1Earray"} +// CHECK: %[[mem:.*]] = fir.allocmem !fir.array<1000123xi32> {bindc_name = "", uniq_name = ""} // CHECK: fir.call @_QPs3( // CHECK: fir.freemem %[[mem]] // CHECK-NEXT: return func.func @_QPs1() { - %0 = fir.alloca !fir.array<1000123xi32> {bindc_name = "array", uniq_name = "_QFs1Earray"} + %0 = fir.alloca !fir.array<1000123xi32> fir.call @_QPs3(%0) : (!fir.ref<!fir.array<1000123xi32>>) -> () return } @@ -31,4 +38,4 @@ func.func @_QPs2(%arg0: !fir.ref<i32>) { return } func.func private @_QPs3(!fir.ref<!fir.array<1000123xi32>>) - +} diff --git a/flang/test/Transforms/stack-arrays-block-cfg-scope.fir b/flang/test/Transforms/stack-arrays-block-cfg-scope.fir index a875e5fb56762..9519cd4673871 100644 --- a/flang/test/Transforms/stack-arrays-block-cfg-scope.fir +++ b/flang/test/Transforms/stack-arrays-block-cfg-scope.fir @@ -1,4 +1,4 @@ -// RUN: fir-opt --stack-arrays %s | FileCheck %s +// RUN: fir-opt --allocation-placement="stack-arrays=true" %s | FileCheck %s // Test that an allocmem in a sibling block is not hoisted to the // block where its size operand is defined. diff --git a/flang/test/Transforms/stack-arrays-hlfir.f90 b/flang/test/Transforms/stack-arrays-hlfir.f90 index e70a1d9b89216..f88eb5ba309bf 100644 --- a/flang/test/Transforms/stack-arrays-hlfir.f90 +++ b/flang/test/Transforms/stack-arrays-hlfir.f90 @@ -10,7 +10,7 @@ ! RUN: --bufferize-hlfir \ ! RUN: --convert-hlfir-to-fir \ ! RUN: --array-value-copy \ -! RUN: --stack-arrays \ +! RUN: --allocation-placement="stack-arrays=true" \ ! RUN: | FileCheck %s subroutine temp_array diff --git a/flang/test/Transforms/stack-arrays-lifetime.fir b/flang/test/Transforms/stack-arrays-lifetime.fir index 960ce9fad7b2d..021caedd89606 100644 --- a/flang/test/Transforms/stack-arrays-lifetime.fir +++ b/flang/test/Transforms/stack-arrays-lifetime.fir @@ -1,5 +1,5 @@ // Test insertion of llvm.lifetime for allocmem turn into alloca with constant size. -// RUN: fir-opt --stack-arrays -stack-arrays-lifetime %s | FileCheck %s +// RUN: fir-opt --allocation-placement="stack-arrays=true" -stack-arrays-lifetime %s | FileCheck %s module attributes {fir.defaultkind = "a1c4d8i4l4r4", fir.kindmap = "", llvm.data_layout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"} { diff --git a/flang/test/Transforms/stack-arrays-nested-scope.fir b/flang/test/Transforms/stack-arrays-nested-scope.fir index 18dd4020db22b..f8e046ec3c35a 100644 --- a/flang/test/Transforms/stack-arrays-nested-scope.fir +++ b/flang/test/Transforms/stack-arrays-nested-scope.fir @@ -1,4 +1,4 @@ -// RUN: fir-opt --stack-arrays %s | FileCheck %s +// RUN: fir-opt --allocation-placement="stack-arrays=true" %s | FileCheck %s // Test that an allocmem inside a fir.if is not hoisted past a // stackrestore when the size operand is shared across scopes. diff --git a/flang/test/Transforms/stack-arrays-scope.f90 b/flang/test/Transforms/stack-arrays-scope.f90 index ba2536ce91001..8669d5e4ed0b5 100644 --- a/flang/test/Transforms/stack-arrays-scope.f90 +++ b/flang/test/Transforms/stack-arrays-scope.f90 @@ -6,7 +6,7 @@ ! reusing a single size value, or CSE merging duplicates). ! RUN: %flang_fc1 -emit-fir -fstack-arrays %s -o - \ -! RUN: | fir-opt --stack-arrays \ +! RUN: | fir-opt --allocation-placement="stack-arrays=true" \ ! RUN: | FileCheck %s subroutine ss1(a) diff --git a/flang/test/Transforms/stack-arrays.fir b/flang/test/Transforms/stack-arrays.fir index 7a005c69a1b04..3e6f52de7b999 100644 --- a/flang/test/Transforms/stack-arrays.fir +++ b/flang/test/Transforms/stack-arrays.fir @@ -1,4 +1,4 @@ -// RUN: fir-opt --stack-arrays %s | FileCheck %s +// RUN: fir-opt --allocation-placement="stack-arrays=true" %s | FileCheck %s // Simplest transformation func.func @simple() { _______________________________________________ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
