Skip to content

Commit 7c30bff

Browse files
authored
Merge pull request #23728 from gottesmm/pr-7170ab2c9d2de844f971998f8c079c11a6f065b9
2 parents f8e4c75 + db13769 commit 7c30bff

File tree

5 files changed

+115
-66
lines changed

5 files changed

+115
-66
lines changed

include/swift/SILOptimizer/PassManager/Passes.def

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,8 @@ PASS(UnsafeGuaranteedPeephole, "unsafe-guaranteed-peephole",
289289
"SIL retain/release Peephole Removal for Builtin.unsafeGuaranteed")
290290
PASS(UsePrespecialized, "use-prespecialized",
291291
"Use Pre-Specialized Functions")
292-
PASS(ValueOwnershipKindDumper, "value-ownership-kind-dumper",
293-
"Print Value Ownership Kind for Testing")
292+
PASS(OwnershipDumper, "ownership-dumper",
293+
"Print Ownership information for Testing")
294294
PASS(SemanticARCOpts, "semantic-arc-opts",
295295
"Semantic ARC Optimization")
296296
PASS(MarkUninitializedFixup, "mark-uninitialized-fixup",

lib/SILOptimizer/UtilityPasses/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@ silopt_register_sources(
2727
SideEffectsDumper.cpp
2828
SimplifyUnreachableContainingBlocks.cpp
2929
StripDebugInfo.cpp
30-
ValueOwnershipKindDumper.cpp
30+
OwnershipDumper.cpp
3131
)
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
//===--- OwnershipDumper.cpp ----------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2018 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+
/// \file
14+
///
15+
/// This is a simple utility pass that dumps the ValueOwnershipKind of all
16+
/// SILValue in a module. It is meant to trigger assertions and verification of
17+
/// these values.
18+
///
19+
//===----------------------------------------------------------------------===//
20+
21+
#include "swift/SIL/SILFunction.h"
22+
#include "swift/SIL/SILInstruction.h"
23+
#include "swift/SILOptimizer/PassManager/Passes.h"
24+
#include "swift/SILOptimizer/PassManager/Transforms.h"
25+
26+
using namespace swift;
27+
28+
//===----------------------------------------------------------------------===//
29+
// Implementation
30+
//===----------------------------------------------------------------------===//
31+
32+
static void dumpInstruction(SILInstruction &ii) {
33+
llvm::outs() << "Visiting: " << ii;
34+
35+
auto ops = ii.getAllOperands();
36+
if (!ops.empty()) {
37+
llvm::outs() << "Operand Ownership Map:\n";
38+
for (const auto &op : ops) {
39+
llvm::outs() << "Op #: " << op.getOperandNumber() << "\n"
40+
<< "Ownership Map: " << op.getOwnershipKindMap();
41+
}
42+
}
43+
44+
// If the instruction doesn't have any results, bail.
45+
auto results = ii.getResults();
46+
if (!results.empty()) {
47+
llvm::outs() << "Results Ownership Kinds:\n";
48+
for (auto v : results) {
49+
auto kind = v.getOwnershipKind();
50+
llvm::outs() << "Result: " << v;
51+
llvm::outs() << "Kind: " << kind << "\n";
52+
}
53+
}
54+
}
55+
56+
//===----------------------------------------------------------------------===//
57+
// Top Level Entrypoint
58+
//===----------------------------------------------------------------------===//
59+
60+
namespace {
61+
62+
class OwnershipDumper : public SILFunctionTransform {
63+
void run() override {
64+
SILFunction *f = getFunction();
65+
llvm::outs() << "*** Dumping Function: '" << f->getName() << "'\n";
66+
for (auto &bb : *f) {
67+
// We only dump instructions right now.
68+
for (auto &ii : bb) {
69+
dumpInstruction(ii);
70+
}
71+
}
72+
}
73+
};
74+
75+
} // end anonymous namespace
76+
77+
SILTransform *swift::createOwnershipDumper() { return new OwnershipDumper(); }

lib/SILOptimizer/UtilityPasses/ValueOwnershipKindDumper.cpp

Lines changed: 0 additions & 63 deletions
This file was deleted.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// RUN: %target-sil-opt -ownership-dumper %s -o /dev/null | %FileCheck %s
2+
3+
sil_stage canonical
4+
5+
import Builtin
6+
7+
class Klass {}
8+
9+
// CHECK-LABEL: Dumping Function: 'foo'
10+
// CHECK: Visiting: %1 = unchecked_ref_cast %0 : $Builtin.NativeObject to $Klass
11+
// CHECK: Operand Ownership Map:
12+
// CHECK: Op #: 0
13+
// CHECK: Ownership Map: -- OperandOwnershipKindMap --
14+
// CHECK: unowned: No.
15+
// CHECK: owned: Yes. Liveness: MustBeInvalidated
16+
// CHECK: guaranteed: No.
17+
// CHECK: any: Yes. Liveness: MustBeLive
18+
// CHECK: Results Ownership Kinds:
19+
// CHECK: Result: %1 = unchecked_ref_cast %0 : $Builtin.NativeObject to $Klass
20+
// CHECK: Kind: owned
21+
// CHECK: Visiting: return %1 : $Klass
22+
// CHECK: Operand Ownership Map:
23+
// CHECK: Op #: 0
24+
// CHECK: Ownership Map: -- OperandOwnershipKindMap --
25+
// CHECK: unowned: No.
26+
// CHECK: owned: Yes. Liveness: MustBeInvalidated
27+
// CHECK: guaranteed: No.
28+
// CHECK: any: Yes. Liveness: MustBeLive
29+
sil [ossa] @foo : $@convention(thin) (@owned Builtin.NativeObject) -> @owned Klass {
30+
bb0(%0 : @owned $Builtin.NativeObject):
31+
%1 = unchecked_ref_cast %0 : $Builtin.NativeObject to $Klass
32+
return %1 : $Klass
33+
}
34+
35+

0 commit comments

Comments
 (0)