diff --git a/include/swift/SILOptimizer/PassManager/Passes.def b/include/swift/SILOptimizer/PassManager/Passes.def index 24a58417355..00f198aa9d7 100644 --- a/include/swift/SILOptimizer/PassManager/Passes.def +++ b/include/swift/SILOptimizer/PassManager/Passes.def @@ -237,6 +237,8 @@ PASS(UnsafeGuaranteedPeephole, "unsafe-guaranteed-peephole", "Builtin.unsafeGuaranteed") PASS(UsePrespecialized, "use-prespecialized", "Use pre-specialized functions") +PASS(ValueOwnershipKindDumper, "value-ownership-kind-dumper", + "Print the value ownership kind of all ValueBase in a SILModule") PASS(BugReducerTester, "bug-reducer-tester", "Utility pass for testing sil-bug-reducer. Asserts when visits an apply that calls a specific function") PASS_RANGE(AllPasses, AADumper, BugReducerTester) diff --git a/lib/SIL/SILValue.cpp b/lib/SIL/SILValue.cpp index 853fa675665..08843dfec55 100644 --- a/lib/SIL/SILValue.cpp +++ b/lib/SIL/SILValue.cpp @@ -341,7 +341,8 @@ ValueOwnershipKindVisitor::visitSILUndef(SILUndef *Arg) { Optional ValueOwnershipKindVisitor::visitPHISILArgument(SILArgument *Arg) { - llvm_unreachable("unimplemented"); + // For now just return undef. + return ValueOwnershipKind::Undef; } Optional diff --git a/lib/SILOptimizer/UtilityPasses/CMakeLists.txt b/lib/SILOptimizer/UtilityPasses/CMakeLists.txt index 7dbbc421bf3..b1b91bea390 100644 --- a/lib/SILOptimizer/UtilityPasses/CMakeLists.txt +++ b/lib/SILOptimizer/UtilityPasses/CMakeLists.txt @@ -3,24 +3,25 @@ set(UTILITYPASSES_SOURCES UtilityPasses/BasicCalleePrinter.cpp UtilityPasses/BasicInstructionPropertyDumper.cpp UtilityPasses/BugReducerTester.cpp - UtilityPasses/CallerAnalysisPrinter.cpp UtilityPasses/CFGPrinter.cpp + UtilityPasses/CallerAnalysisPrinter.cpp UtilityPasses/ComputeDominanceInfo.cpp UtilityPasses/ComputeLoopInfo.cpp UtilityPasses/EpilogueARCMatcherDumper.cpp UtilityPasses/EpilogueRetainReleaseMatcherDumper.cpp UtilityPasses/EscapeAnalysisDumper.cpp UtilityPasses/FunctionOrderPrinter.cpp - UtilityPasses/InstCount.cpp UtilityPasses/IVInfoPrinter.cpp + UtilityPasses/InstCount.cpp + UtilityPasses/LSLocationPrinter.cpp UtilityPasses/Link.cpp UtilityPasses/LoopCanonicalizer.cpp UtilityPasses/LoopInfoPrinter.cpp UtilityPasses/LoopRegionPrinter.cpp - UtilityPasses/LSLocationPrinter.cpp UtilityPasses/MemBehaviorDumper.cpp UtilityPasses/RCIdentityDumper.cpp - UtilityPasses/SideEffectsDumper.cpp UtilityPasses/SILDebugInfoGenerator.cpp + UtilityPasses/SideEffectsDumper.cpp UtilityPasses/StripDebugInfo.cpp + UtilityPasses/ValueOwnershipKindDumper.cpp PARENT_SCOPE) diff --git a/lib/SILOptimizer/UtilityPasses/ValueOwnershipKindDumper.cpp b/lib/SILOptimizer/UtilityPasses/ValueOwnershipKindDumper.cpp new file mode 100644 index 00000000000..425296b23df --- /dev/null +++ b/lib/SILOptimizer/UtilityPasses/ValueOwnershipKindDumper.cpp @@ -0,0 +1,67 @@ +//===--- ValueOwnershipKindDumper.cpp -------------------------------------===// +// +// This source file is part of the Swift.org open source project +// +// Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See http://swift.org/LICENSE.txt for license information +// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors +// +//===----------------------------------------------------------------------===// +/// +/// 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; + +namespace { + +class ValueOwnershipKindDumper : public SILFunctionTransform { + + void run() override { + SILFunction *F = getFunction(); + SILModule &M = F->getModule(); + for (auto &BB : *F) { + // We only verify instructions right now. + for (auto &II : BB) { + // If the instruction doesn't have a value, bail. + if (!II.hasValue()) + continue; + SILValue V(&II); + llvm::outs() << "Visiting: " << II; + auto Kind = V.getOwnershipKind(); + if (!Kind.hasValue()) { + llvm_unreachable(" Error... has a value but no kind?!"); + } + llvm::outs() << " " << Kind.getValue() << "\n"; + if (Kind.getValue() == ValueOwnershipKind::Trivial) { + if (!V->getType().isTrivial(M)) { + llvm_unreachable("Error! Trivial ownership without trivial type\n"); + } + } else { + if (V->getType().isTrivial(M)) { + llvm_unreachable( + "Error! Non Trivial ownership with trivial type\n"); + } + } + } + } + } + + StringRef getName() override { return "Value Ownership Kind Dumper"; } +}; + +} // end anonymous namespace + +SILTransform *swift::createValueOwnershipKindDumper() { + return new ValueOwnershipKindDumper(); +}