Skip to content

[ownership] Change OwnershipDumper to also dump ownership kind map pe… #23728

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions include/swift/SILOptimizer/PassManager/Passes.def
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,8 @@ PASS(UnsafeGuaranteedPeephole, "unsafe-guaranteed-peephole",
"SIL retain/release Peephole Removal for Builtin.unsafeGuaranteed")
PASS(UsePrespecialized, "use-prespecialized",
"Use Pre-Specialized Functions")
PASS(ValueOwnershipKindDumper, "value-ownership-kind-dumper",
"Print Value Ownership Kind for Testing")
PASS(OwnershipDumper, "ownership-dumper",
"Print Ownership information for Testing")
PASS(SemanticARCOpts, "semantic-arc-opts",
"Semantic ARC Optimization")
PASS(MarkUninitializedFixup, "mark-uninitialized-fixup",
Expand Down
2 changes: 1 addition & 1 deletion lib/SILOptimizer/UtilityPasses/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ silopt_register_sources(
SideEffectsDumper.cpp
SimplifyUnreachableContainingBlocks.cpp
StripDebugInfo.cpp
ValueOwnershipKindDumper.cpp
OwnershipDumper.cpp
)
77 changes: 77 additions & 0 deletions lib/SILOptimizer/UtilityPasses/OwnershipDumper.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
//===--- OwnershipDumper.cpp ----------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
///
/// \file
///
/// This is a simple utility pass that dumps the ValueOwnershipKind of all
/// SILValue in a module. It is meant to trigger assertions and verification of
/// these values.
///
//===----------------------------------------------------------------------===//

#include "swift/SIL/SILFunction.h"
#include "swift/SIL/SILInstruction.h"
#include "swift/SILOptimizer/PassManager/Passes.h"
#include "swift/SILOptimizer/PassManager/Transforms.h"

using namespace swift;

//===----------------------------------------------------------------------===//
// Implementation
//===----------------------------------------------------------------------===//

static void dumpInstruction(SILInstruction &ii) {
llvm::outs() << "Visiting: " << ii;

auto ops = ii.getAllOperands();
if (!ops.empty()) {
llvm::outs() << "Operand Ownership Map:\n";
for (const auto &op : ops) {
llvm::outs() << "Op #: " << op.getOperandNumber() << "\n"
<< "Ownership Map: " << op.getOwnershipKindMap();
}
}

// If the instruction doesn't have any results, bail.
auto results = ii.getResults();
if (!results.empty()) {
llvm::outs() << "Results Ownership Kinds:\n";
for (auto v : results) {
auto kind = v.getOwnershipKind();
llvm::outs() << "Result: " << v;
llvm::outs() << "Kind: " << kind << "\n";
}
}
}

//===----------------------------------------------------------------------===//
// Top Level Entrypoint
//===----------------------------------------------------------------------===//

namespace {

class OwnershipDumper : public SILFunctionTransform {
void run() override {
SILFunction *f = getFunction();
llvm::outs() << "*** Dumping Function: '" << f->getName() << "'\n";
for (auto &bb : *f) {
// We only dump instructions right now.
for (auto &ii : bb) {
dumpInstruction(ii);
}
}
}
};

} // end anonymous namespace

SILTransform *swift::createOwnershipDumper() { return new OwnershipDumper(); }
63 changes: 0 additions & 63 deletions lib/SILOptimizer/UtilityPasses/ValueOwnershipKindDumper.cpp

This file was deleted.

35 changes: 35 additions & 0 deletions test/SILOptimizer/ownership-kind-dumper.sil
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// RUN: %target-sil-opt -ownership-dumper %s -o /dev/null | %FileCheck %s

sil_stage canonical

import Builtin

class Klass {}

// CHECK-LABEL: Dumping Function: 'foo'
// CHECK: Visiting: %1 = unchecked_ref_cast %0 : $Builtin.NativeObject to $Klass
// CHECK: Operand Ownership Map:
// CHECK: Op #: 0
// CHECK: Ownership Map: -- OperandOwnershipKindMap --
// CHECK: unowned: No.
// CHECK: owned: Yes. Liveness: MustBeInvalidated
// CHECK: guaranteed: No.
// CHECK: any: Yes. Liveness: MustBeLive
// CHECK: Results Ownership Kinds:
// CHECK: Result: %1 = unchecked_ref_cast %0 : $Builtin.NativeObject to $Klass
// CHECK: Kind: owned
// CHECK: Visiting: return %1 : $Klass
// CHECK: Operand Ownership Map:
// CHECK: Op #: 0
// CHECK: Ownership Map: -- OperandOwnershipKindMap --
// CHECK: unowned: No.
// CHECK: owned: Yes. Liveness: MustBeInvalidated
// CHECK: guaranteed: No.
// CHECK: any: Yes. Liveness: MustBeLive
sil [ossa] @foo : $@convention(thin) (@owned Builtin.NativeObject) -> @owned Klass {
bb0(%0 : @owned $Builtin.NativeObject):
%1 = unchecked_ref_cast %0 : $Builtin.NativeObject to $Klass
return %1 : $Klass
}