Skip to content

Commit fb7b4a3

Browse files
committed
[region-isolation] Add verbose logging to PartitionUtils behind a flag.
One needs to pass in the explicit flag to enable this as well as -debug-flag=send-non-sendable. This makes it easier to debug the affect of applying specific partition ops.
1 parent c474f6c commit fb7b4a3

File tree

3 files changed

+51
-2
lines changed

3 files changed

+51
-2
lines changed

include/swift/SILOptimizer/Utils/PartitionUtils.h

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef SWIFT_PARTITIONUTILS_H
22
#define SWIFT_PARTITIONUTILS_H
33

4+
#include "swift/Basic/Defer.h"
45
#include "swift/Basic/LLVM.h"
56
#include "swift/SIL/SILInstruction.h"
67
#include "llvm/ADT/SmallVector.h"
@@ -13,6 +14,18 @@ namespace swift {
1314

1415
namespace PartitionPrimitives {
1516

17+
#ifndef NDEBUG
18+
extern bool REGIONBASEDISOLATION_ENABLE_VERBOSE_LOGGING;
19+
#define REGIONBASEDISOLATION_VERBOSE_LOG(...) \
20+
do { \
21+
if (REGIONBASEDISOLATION_ENABLE_VERBOSE_LOGGING) { \
22+
LLVM_DEBUG(__VA_ARGS__); \
23+
} \
24+
} while (0);
25+
#else
26+
#define REGIONBASEDISOLATION_VERBOSE_LOG(...)
27+
#endif
28+
1629
struct Element {
1730
unsigned num;
1831

@@ -391,11 +404,17 @@ class Partition {
391404
PartitionOp op,
392405
llvm::function_ref<void(const PartitionOp &, Element)> handleFailure =
393406
[](const PartitionOp &, Element) {},
394-
395407
ArrayRef<Element> nonconsumables = {},
396-
397408
llvm::function_ref<void(const PartitionOp &, Element)>
398409
handleConsumeNonConsumable = [](const PartitionOp &, Element) {}) {
410+
REGIONBASEDISOLATION_VERBOSE_LOG(llvm::dbgs() << "Applying: ";
411+
op.print(llvm::dbgs()));
412+
REGIONBASEDISOLATION_VERBOSE_LOG(llvm::dbgs() << " Before: ";
413+
print(llvm::dbgs()));
414+
SWIFT_DEFER {
415+
REGIONBASEDISOLATION_VERBOSE_LOG(llvm::dbgs() << " After: ";
416+
print(llvm::dbgs()));
417+
};
399418
switch (op.OpKind) {
400419
case PartitionOpKind::Assign:
401420
assert(op.OpArgs.size() == 2 &&

lib/SILOptimizer/Utils/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ target_sources(swiftSILOptimizer PRIVATE
2323
LoopUtils.cpp
2424
OptimizerStatsUtils.cpp
2525
PartialApplyCombiner.cpp
26+
PartitionUtils.cpp
2627
PerformanceInlinerUtils.cpp
2728
ShrinkBorrowScope.cpp
2829
SILInliner.cpp
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//===--- PartitionUtils.cpp -----------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#include "swift/SILOptimizer/Utils/PartitionUtils.h"
14+
#include "llvm/Support/CommandLine.h"
15+
16+
#ifndef NDEBUG
17+
18+
bool swift::PartitionPrimitives::REGIONBASEDISOLATION_ENABLE_VERBOSE_LOGGING;
19+
20+
static llvm::cl::opt<bool, true> // The parser
21+
RegionBasedIsolationVerboseLog(
22+
"sil-regionbasedisolation-verbose-log",
23+
llvm::cl::desc("Enable verbose logging for SIL region based isolation "
24+
"diagnostics"),
25+
llvm::cl::Hidden,
26+
llvm::cl::location(swift::PartitionPrimitives::
27+
REGIONBASEDISOLATION_ENABLE_VERBOSE_LOGGING));
28+
29+
#endif

0 commit comments

Comments
 (0)