Skip to content

Commit 33efbe2

Browse files
committed
Merge remote-tracking branch 'origin/main' into vplan-separate-vpirflags
2 parents ff1b1e9 + bc0c4db commit 33efbe2

File tree

119 files changed

+1910
-797
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

119 files changed

+1910
-797
lines changed

.ci/compute_projects_test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ def test_flang(self):
147147

148148
def test_invalid_subproject(self):
149149
env_variables = compute_projects.get_env_variables(
150-
[".ci/compute_projects.py"], "Linux"
150+
["third-party/benchmark/CMakeLists.txt"], "Linux"
151151
)
152152
self.assertEqual(env_variables["projects_to_build"], "")
153153
self.assertEqual(env_variables["project_check_targets"], "")
@@ -163,7 +163,7 @@ def test_top_level_file(self):
163163

164164
def test_exclude_runtiems_in_projects(self):
165165
env_variables = compute_projects.get_env_variables(
166-
[".ci/compute_projects.py", "libcxx/CMakeLists.txt"], "Linux"
166+
["libcxx/CMakeLists.txt"], "Linux"
167167
)
168168
self.assertEqual(env_variables["projects_to_build"], "")
169169
self.assertEqual(env_variables["project_check_targets"], "")
@@ -192,10 +192,10 @@ def test_ci(self):
192192
env_variables = compute_projects.get_env_variables(
193193
[".ci/compute_projects.py"], "Linux"
194194
)
195-
self.assertEqual(env_variables["projects_to_build"], "clang;lld;llvm;lldb")
195+
self.assertEqual(env_variables["projects_to_build"], "clang;lld;lldb;llvm")
196196
self.assertEqual(
197197
env_variables["project_check_targets"],
198-
"check-clang check-lld check-llvm check-lldb",
198+
"check-clang check-lld check-lldb check-llvm",
199199
)
200200
self.assertEqual(
201201
env_variables["runtimes_to_build"], "libcxx;libcxxabi;libunwind"

clang-tools-extra/clangd/index/SymbolCollector.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,7 +1201,7 @@ void SymbolCollector::addRef(SymbolID ID, const SymbolRef &SR) {
12011201
}
12021202

12031203
SymbolID SymbolCollector::getSymbolIDCached(const Decl *D) {
1204-
auto It = DeclToIDCache.try_emplace(D, SymbolID{});
1204+
auto It = DeclToIDCache.try_emplace(D);
12051205
if (It.second)
12061206
It.first->second = getSymbolID(D);
12071207
return It.first->second;
@@ -1210,7 +1210,7 @@ SymbolID SymbolCollector::getSymbolIDCached(const Decl *D) {
12101210
SymbolID SymbolCollector::getSymbolIDCached(const llvm::StringRef MacroName,
12111211
const MacroInfo *MI,
12121212
const SourceManager &SM) {
1213-
auto It = MacroToIDCache.try_emplace(MI, SymbolID{});
1213+
auto It = MacroToIDCache.try_emplace(MI);
12141214
if (It.second)
12151215
It.first->second = getSymbolID(MacroName, MI, SM);
12161216
return It.first->second;

clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -962,10 +962,8 @@ void RefLeakReport::findBindingToReport(CheckerContext &Ctx,
962962
// `AllocFirstBinding` to be one of them. In situations like this,
963963
// it would still be the easiest case to explain to our users.
964964
if (!AllVarBindings.empty() &&
965-
llvm::count_if(AllVarBindings,
966-
[this](const std::pair<const MemRegion *, SVal> Binding) {
967-
return Binding.first == AllocFirstBinding;
968-
}) == 0) {
965+
!llvm::is_contained(llvm::make_first_range(AllVarBindings),
966+
AllocFirstBinding)) {
969967
// Let's pick one of them at random (if there is something to pick from).
970968
AllocBindingToReport = AllVarBindings[0].first;
971969

clang/unittests/StaticAnalyzer/CallDescriptionTest.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,7 @@ class ResultMap {
3535

3636
public:
3737
ResultMap(std::initializer_list<std::pair<CallDescription, bool>> Data)
38-
: Found(0),
39-
Total(std::count_if(Data.begin(), Data.end(),
40-
[](const std::pair<CallDescription, bool> &Pair) {
41-
return Pair.second == true;
42-
})),
38+
: Found(0), Total(llvm::count(llvm::make_second_range(Data), true)),
4339
Impl(std::move(Data)) {}
4440

4541
const bool *lookup(const CallEvent &Call) {

flang/include/flang/Optimizer/Support/InitFIR.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "mlir/Dialect/Func/Extensions/InlinerExtension.h"
2626
#include "mlir/Dialect/LLVMIR/NVVMDialect.h"
2727
#include "mlir/Dialect/OpenACC/Transforms/Passes.h"
28+
#include "mlir/Dialect/SCF/Transforms/Passes.h"
2829
#include "mlir/InitAllDialects.h"
2930
#include "mlir/Pass/Pass.h"
3031
#include "mlir/Pass/PassRegistry.h"
@@ -103,6 +104,7 @@ inline void registerMLIRPassesForFortranTools() {
103104
mlir::registerPrintOpStatsPass();
104105
mlir::registerInlinerPass();
105106
mlir::registerSCCPPass();
107+
mlir::registerSCFPasses();
106108
mlir::affine::registerAffineScalarReplacementPass();
107109
mlir::registerSymbolDCEPass();
108110
mlir::registerLocationSnapshotPass();

flang/include/flang/Optimizer/Transforms/Passes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ std::unique_ptr<mlir::Pass>
7272
createArrayValueCopyPass(fir::ArrayValueCopyOptions options = {});
7373
std::unique_ptr<mlir::Pass> createMemDataFlowOptPass();
7474
std::unique_ptr<mlir::Pass> createPromoteToAffinePass();
75+
std::unique_ptr<mlir::Pass> createFIRToSCFPass();
7576
std::unique_ptr<mlir::Pass>
7677
createAddDebugInfoPass(fir::AddDebugInfoOptions options = {});
7778

flang/include/flang/Optimizer/Transforms/Passes.td

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,17 @@ def AffineDialectDemotion : Pass<"demote-affine", "::mlir::func::FuncOp"> {
7676
];
7777
}
7878

79+
def FIRToSCFPass : Pass<"fir-to-scf"> {
80+
let summary = "Convert FIR structured control flow ops to SCF dialect.";
81+
let description = [{
82+
Convert FIR structured control flow ops to SCF dialect.
83+
}];
84+
let constructor = "::fir::createFIRToSCFPass()";
85+
let dependentDialects = [
86+
"fir::FIROpsDialect", "mlir::scf::SCFDialect"
87+
];
88+
}
89+
7990
def AnnotateConstantOperands : Pass<"annotate-constant"> {
8091
let summary = "Annotate constant operands to all FIR operations";
8192
let description = [{

flang/lib/Optimizer/Transforms/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ add_flang_library(FIRTransforms
1616
CUFComputeSharedMemoryOffsetsAndSize.cpp
1717
ArrayValueCopy.cpp
1818
ExternalNameConversion.cpp
19+
FIRToSCF.cpp
1920
MemoryUtils.cpp
2021
MemoryAllocation.cpp
2122
StackArrays.cpp
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
//===-- FIRToSCF.cpp ------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "flang/Optimizer/Dialect/FIRDialect.h"
10+
#include "flang/Optimizer/Transforms/Passes.h"
11+
#include "mlir/Dialect/SCF/IR/SCF.h"
12+
#include "mlir/Transforms/DialectConversion.h"
13+
14+
namespace fir {
15+
#define GEN_PASS_DEF_FIRTOSCFPASS
16+
#include "flang/Optimizer/Transforms/Passes.h.inc"
17+
} // namespace fir
18+
19+
using namespace fir;
20+
using namespace mlir;
21+
22+
namespace {
23+
class FIRToSCFPass : public fir::impl::FIRToSCFPassBase<FIRToSCFPass> {
24+
public:
25+
void runOnOperation() override;
26+
};
27+
28+
struct DoLoopConversion : public OpRewritePattern<fir::DoLoopOp> {
29+
using OpRewritePattern<fir::DoLoopOp>::OpRewritePattern;
30+
31+
LogicalResult matchAndRewrite(fir::DoLoopOp doLoopOp,
32+
PatternRewriter &rewriter) const override {
33+
auto loc = doLoopOp.getLoc();
34+
bool hasFinalValue = doLoopOp.getFinalValue().has_value();
35+
36+
// Get loop values from the DoLoopOp
37+
auto low = doLoopOp.getLowerBound();
38+
auto high = doLoopOp.getUpperBound();
39+
assert(low && high && "must be a Value");
40+
auto step = doLoopOp.getStep();
41+
llvm::SmallVector<Value> iterArgs;
42+
if (hasFinalValue)
43+
iterArgs.push_back(low);
44+
iterArgs.append(doLoopOp.getIterOperands().begin(),
45+
doLoopOp.getIterOperands().end());
46+
47+
// fir.do_loop iterates over the interval [%l, %u], and the step may be
48+
// negative. But scf.for iterates over the interval [%l, %u), and the step
49+
// must be a positive value.
50+
// For easier conversion, we calculate the trip count and use a canonical
51+
// induction variable.
52+
auto diff = rewriter.create<arith::SubIOp>(loc, high, low);
53+
auto distance = rewriter.create<arith::AddIOp>(loc, diff, step);
54+
auto tripCount = rewriter.create<arith::DivSIOp>(loc, distance, step);
55+
auto zero = rewriter.create<arith::ConstantIndexOp>(loc, 0);
56+
auto one = rewriter.create<arith::ConstantIndexOp>(loc, 1);
57+
auto scfForOp =
58+
rewriter.create<scf::ForOp>(loc, zero, tripCount, one, iterArgs);
59+
60+
auto &loopOps = doLoopOp.getBody()->getOperations();
61+
auto resultOp = cast<fir::ResultOp>(doLoopOp.getBody()->getTerminator());
62+
auto results = resultOp.getOperands();
63+
Block *loweredBody = scfForOp.getBody();
64+
65+
loweredBody->getOperations().splice(loweredBody->begin(), loopOps,
66+
loopOps.begin(),
67+
std::prev(loopOps.end()));
68+
69+
rewriter.setInsertionPointToStart(loweredBody);
70+
Value iv =
71+
rewriter.create<arith::MulIOp>(loc, scfForOp.getInductionVar(), step);
72+
iv = rewriter.create<arith::AddIOp>(loc, low, iv);
73+
74+
if (!results.empty()) {
75+
rewriter.setInsertionPointToEnd(loweredBody);
76+
rewriter.create<scf::YieldOp>(resultOp->getLoc(), results);
77+
}
78+
doLoopOp.getInductionVar().replaceAllUsesWith(iv);
79+
rewriter.replaceAllUsesWith(doLoopOp.getRegionIterArgs(),
80+
hasFinalValue
81+
? scfForOp.getRegionIterArgs().drop_front()
82+
: scfForOp.getRegionIterArgs());
83+
84+
// Copy all the attributes from the old to new op.
85+
scfForOp->setAttrs(doLoopOp->getAttrs());
86+
rewriter.replaceOp(doLoopOp, scfForOp);
87+
return success();
88+
}
89+
};
90+
} // namespace
91+
92+
void FIRToSCFPass::runOnOperation() {
93+
RewritePatternSet patterns(&getContext());
94+
patterns.add<DoLoopConversion>(patterns.getContext());
95+
ConversionTarget target(getContext());
96+
target.addIllegalOp<fir::DoLoopOp>();
97+
target.markUnknownOpDynamicallyLegal([](Operation *) { return true; });
98+
if (failed(
99+
applyPartialConversion(getOperation(), target, std::move(patterns))))
100+
signalPassFailure();
101+
}
102+
103+
std::unique_ptr<Pass> fir::createFIRToSCFPass() {
104+
return std::make_unique<FIRToSCFPass>();
105+
}

0 commit comments

Comments
 (0)