================ @@ -0,0 +1,81 @@ +//===----------------------------------------------------------------------===// +// +// 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 "PassDetail.h" +#include "mlir/Dialect/Func/IR/FuncOps.h" +#include "mlir/IR/PatternMatch.h" +#include "mlir/Support/LogicalResult.h" +#include "mlir/Transforms/DialectConversion.h" +#include "mlir/Transforms/GreedyPatternRewriteDriver.h" +#include "clang/CIR/Dialect/IR/CIRDialect.h" +#include "clang/CIR/Dialect/Passes.h" +#include "clang/CIR/MissingFeatures.h" +#include "llvm/Support/TimeProfiler.h" + +using namespace mlir; +using namespace cir; + +namespace { + +struct HoistAllocasPass : public HoistAllocasBase<HoistAllocasPass> { + + HoistAllocasPass() = default; + void runOnOperation() override; +}; + +static void process(mlir::ModuleOp mod, cir::FuncOp func) { + if (func.getRegion().empty()) + return; + + // Hoist all static allocas to the entry block. + mlir::Block &entryBlock = func.getRegion().front(); + llvm::SmallVector<cir::AllocaOp> allocas; + func.getBody().walk([&](cir::AllocaOp alloca) { ---------------- mmha wrote:
You create a `SmallVector` of `AllocaOp`s here only to iterate that list again right below. Can you merge these two loops? It would save us the creation of that vector. https://github.com/llvm/llvm-project/pull/132468 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits