mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[semantic-sil] Add a new pass that dumps out the ownership of all SILValue in a function and performs some minor checks upon them.
rdar://29671437
This commit is contained in:
@@ -237,6 +237,8 @@ PASS(UnsafeGuaranteedPeephole, "unsafe-guaranteed-peephole",
|
|||||||
"Builtin.unsafeGuaranteed")
|
"Builtin.unsafeGuaranteed")
|
||||||
PASS(UsePrespecialized, "use-prespecialized",
|
PASS(UsePrespecialized, "use-prespecialized",
|
||||||
"Use pre-specialized functions")
|
"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",
|
PASS(BugReducerTester, "bug-reducer-tester",
|
||||||
"Utility pass for testing sil-bug-reducer. Asserts when visits an apply that calls a specific function")
|
"Utility pass for testing sil-bug-reducer. Asserts when visits an apply that calls a specific function")
|
||||||
PASS_RANGE(AllPasses, AADumper, BugReducerTester)
|
PASS_RANGE(AllPasses, AADumper, BugReducerTester)
|
||||||
|
|||||||
@@ -341,7 +341,8 @@ ValueOwnershipKindVisitor::visitSILUndef(SILUndef *Arg) {
|
|||||||
|
|
||||||
Optional<ValueOwnershipKind>
|
Optional<ValueOwnershipKind>
|
||||||
ValueOwnershipKindVisitor::visitPHISILArgument(SILArgument *Arg) {
|
ValueOwnershipKindVisitor::visitPHISILArgument(SILArgument *Arg) {
|
||||||
llvm_unreachable("unimplemented");
|
// For now just return undef.
|
||||||
|
return ValueOwnershipKind::Undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<ValueOwnershipKind>
|
Optional<ValueOwnershipKind>
|
||||||
|
|||||||
@@ -3,24 +3,25 @@ set(UTILITYPASSES_SOURCES
|
|||||||
UtilityPasses/BasicCalleePrinter.cpp
|
UtilityPasses/BasicCalleePrinter.cpp
|
||||||
UtilityPasses/BasicInstructionPropertyDumper.cpp
|
UtilityPasses/BasicInstructionPropertyDumper.cpp
|
||||||
UtilityPasses/BugReducerTester.cpp
|
UtilityPasses/BugReducerTester.cpp
|
||||||
UtilityPasses/CallerAnalysisPrinter.cpp
|
|
||||||
UtilityPasses/CFGPrinter.cpp
|
UtilityPasses/CFGPrinter.cpp
|
||||||
|
UtilityPasses/CallerAnalysisPrinter.cpp
|
||||||
UtilityPasses/ComputeDominanceInfo.cpp
|
UtilityPasses/ComputeDominanceInfo.cpp
|
||||||
UtilityPasses/ComputeLoopInfo.cpp
|
UtilityPasses/ComputeLoopInfo.cpp
|
||||||
UtilityPasses/EpilogueARCMatcherDumper.cpp
|
UtilityPasses/EpilogueARCMatcherDumper.cpp
|
||||||
UtilityPasses/EpilogueRetainReleaseMatcherDumper.cpp
|
UtilityPasses/EpilogueRetainReleaseMatcherDumper.cpp
|
||||||
UtilityPasses/EscapeAnalysisDumper.cpp
|
UtilityPasses/EscapeAnalysisDumper.cpp
|
||||||
UtilityPasses/FunctionOrderPrinter.cpp
|
UtilityPasses/FunctionOrderPrinter.cpp
|
||||||
UtilityPasses/InstCount.cpp
|
|
||||||
UtilityPasses/IVInfoPrinter.cpp
|
UtilityPasses/IVInfoPrinter.cpp
|
||||||
|
UtilityPasses/InstCount.cpp
|
||||||
|
UtilityPasses/LSLocationPrinter.cpp
|
||||||
UtilityPasses/Link.cpp
|
UtilityPasses/Link.cpp
|
||||||
UtilityPasses/LoopCanonicalizer.cpp
|
UtilityPasses/LoopCanonicalizer.cpp
|
||||||
UtilityPasses/LoopInfoPrinter.cpp
|
UtilityPasses/LoopInfoPrinter.cpp
|
||||||
UtilityPasses/LoopRegionPrinter.cpp
|
UtilityPasses/LoopRegionPrinter.cpp
|
||||||
UtilityPasses/LSLocationPrinter.cpp
|
|
||||||
UtilityPasses/MemBehaviorDumper.cpp
|
UtilityPasses/MemBehaviorDumper.cpp
|
||||||
UtilityPasses/RCIdentityDumper.cpp
|
UtilityPasses/RCIdentityDumper.cpp
|
||||||
UtilityPasses/SideEffectsDumper.cpp
|
|
||||||
UtilityPasses/SILDebugInfoGenerator.cpp
|
UtilityPasses/SILDebugInfoGenerator.cpp
|
||||||
|
UtilityPasses/SideEffectsDumper.cpp
|
||||||
UtilityPasses/StripDebugInfo.cpp
|
UtilityPasses/StripDebugInfo.cpp
|
||||||
|
UtilityPasses/ValueOwnershipKindDumper.cpp
|
||||||
PARENT_SCOPE)
|
PARENT_SCOPE)
|
||||||
|
|||||||
67
lib/SILOptimizer/UtilityPasses/ValueOwnershipKindDumper.cpp
Normal file
67
lib/SILOptimizer/UtilityPasses/ValueOwnershipKindDumper.cpp
Normal file
@@ -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();
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user