Skip to content

Commit

Permalink
[consume-operator] Rename checker passes to have ConsumeOperator in t…
Browse files Browse the repository at this point in the history
…he name to reduce confusion with MoveChecking passes.

Just trying to eliminate potential confusion.
  • Loading branch information
gottesmm committed Jan 27, 2023
1 parent 8738c81 commit 3a53828
Show file tree
Hide file tree
Showing 14 changed files with 56 additions and 60 deletions.
10 changes: 4 additions & 6 deletions include/swift/SILOptimizer/PassManager/Passes.def
Original file line number Diff line number Diff line change
Expand Up @@ -440,18 +440,16 @@ PASS(MoveOnlyObjectChecker, "sil-move-only-object-checker",
"Pass that enforces move only invariants on raw SIL for objects")
PASS(MoveOnlyAddressChecker, "sil-move-only-address-checker",
"Pass that enforces move only invariants on raw SIL for addresses")
PASS(MoveKillsCopyableValuesChecker, "sil-move-kills-copyable-values-checker",
"Pass that checks that any copyable (non-move only) value that is passed "
"to _move do not have any uses later than the _move")
PASS(ConsumeOperatorCopyableValuesChecker, "sil-consume-operator-copyable-values-checker",
"Pass that performs checking of the consume operator for copyable values")
PASS(TrivialMoveOnlyTypeEliminator, "sil-trivial-move-only-type-eliminator",
"Pass that rewrites SIL to remove move only types from values of trivial type")
PASS(MoveOnlyTypeEliminator, "sil-move-only-type-eliminator",
"Pass that rewrites SIL to remove move only types from all values")
PASS(LexicalLifetimeEliminator, "sil-lexical-lifetime-eliminator",
"Pass that removes lexical lifetime markers from borrows and alloc stack")
PASS(MoveKillsCopyableAddressesChecker, "sil-move-kills-copyable-addresses-checker",
"Pass that checks that any copyable (non-move only) address that is passed "
"to _move do not have any uses later than the _move")
PASS(ConsumeOperatorCopyableAddressesChecker, "sil-consume-operator-copyable-addresses-checker",
"Pass that performs consume operator checking for copyable addresses")
PASS(DebugInfoCanonicalizer, "sil-onone-debuginfo-canonicalizer",
"Canonicalize debug info at -Onone by propagating debug info into coroutine funclets")
PASS(PartialApplySimplification, "partial-apply-simplification",
Expand Down
4 changes: 2 additions & 2 deletions lib/SILOptimizer/Mandatory/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ target_sources(swiftSILOptimizer PRIVATE
AddressLowering.cpp
CapturePromotion.cpp
ClosureLifetimeFixup.cpp
ConsumeOperatorCopyableAddressesChecker.cpp
ConsumeOperatorCopyableValuesChecker.cpp
PhiStorageOptimizer.cpp
ConstantPropagation.cpp
DebugInfoCanonicalizer.cpp
Expand All @@ -22,8 +24,6 @@ target_sources(swiftSILOptimizer PRIVATE
LowerHopToActor.cpp
MandatoryInlining.cpp
MovedAsyncVarDebugInfoPropagator.cpp
MoveKillsCopyableAddressesChecker.cpp
MoveKillsCopyableValuesChecker.cpp
MoveOnlyAddressChecker.cpp
MoveOnlyBorrowToDestructureTransform.cpp
MoveOnlyDeinitInsertion.cpp
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===--- MoveKillsCopyableAddressesChecker.cpp ----------------------------===//
//===--- ConsumeOperatorCopyableAddressChecker.cpp ------------------------===//
//
// This source file is part of the Swift.org open source project
//
Expand Down Expand Up @@ -133,7 +133,7 @@
///
//===----------------------------------------------------------------------===//

#define DEBUG_TYPE "sil-move-kills-copyable-addresses-checker"
#define DEBUG_TYPE "sil-consume-operator-copyable-addresses-checker"

#include "swift/AST/DiagnosticsSIL.h"
#include "swift/AST/Types.h"
Expand Down Expand Up @@ -171,8 +171,8 @@

using namespace swift;

static llvm::cl::opt<bool>
DisableUnhandledMoveDiagnostic("sil-disable-unknown-moveaddr-diagnostic");
static llvm::cl::opt<bool> DisableUnhandledConsumeOperator(
"sil-consume-operator-disable-unknown-moveaddr-diagnostic");

//===----------------------------------------------------------------------===//
// Utilities
Expand Down Expand Up @@ -245,9 +245,7 @@ struct ClosureOperandState {
/// points.
DebugValueInst *singleDebugValue = nullptr;

bool isUpwardsUse() const {
return result == DownwardScanResult::ClosureUse;
}
bool isUpwardsUse() const { return result == DownwardScanResult::ClosureUse; }

bool isUpwardsConsume() const {
return result == DownwardScanResult::ClosureConsume;
Expand Down Expand Up @@ -1552,9 +1550,9 @@ bool DataflowState::cleanupAllDestroyAddr(
// be defined before the value.
SILBuilderWithScope reinitBuilder((*reinit)->getNextInstruction());
reinitBuilder.setCurrentDebugScope(addressDebugInst->getDebugScope());
reinitBuilder.createDebugValue(
addressDebugInst.inst->getLoc(), address, *varInfo, false,
/*was moved*/ true);
reinitBuilder.createDebugValue(addressDebugInst.inst->getLoc(), address,
*varInfo, false,
/*was moved*/ true);
}
}
madeChange = true;
Expand Down Expand Up @@ -1914,7 +1912,7 @@ void DataflowState::init() {

namespace {

struct MoveKillsCopyableAddressesChecker {
struct ConsumeOperatorCopyableAddressesChecker {
SILFunction *fn;
UseState useState;
DataflowState dataflowState;
Expand All @@ -1924,8 +1922,8 @@ struct MoveKillsCopyableAddressesChecker {
applySiteToPromotedArgIndices;
SmallBlotSetVector<SILInstruction *, 8> closureConsumes;

MoveKillsCopyableAddressesChecker(SILFunction *fn,
SILOptFunctionBuilder &funcBuilder)
ConsumeOperatorCopyableAddressesChecker(SILFunction *fn,
SILOptFunctionBuilder &funcBuilder)
: fn(fn), useState(),
dataflowState(funcBuilder, useState, applySiteToPromotedArgIndices,
closureConsumes),
Expand All @@ -1951,7 +1949,7 @@ struct MoveKillsCopyableAddressesChecker {

} // namespace

void MoveKillsCopyableAddressesChecker::cloneDeferCalleeAndRewriteUses(
void ConsumeOperatorCopyableAddressesChecker::cloneDeferCalleeAndRewriteUses(
SmallVectorImpl<SILValue> &newArgs, const SmallBitVector &bitVector,
FullApplySite oldApplySite,
SmallBlotSetVector<SILInstruction *, 8> &postDominatingConsumingUsers) {
Expand Down Expand Up @@ -2012,7 +2010,7 @@ void MoveKillsCopyableAddressesChecker::cloneDeferCalleeAndRewriteUses(
oldApplySite->eraseFromParent();
}

bool MoveKillsCopyableAddressesChecker::performClosureDataflow(
bool ConsumeOperatorCopyableAddressesChecker::performClosureDataflow(
Operand *callerOperand, ClosureOperandState &calleeOperandState) {
auto fas = FullApplySite::isa(callerOperand->getUser());
auto *func = fas.getCalleeFunction();
Expand Down Expand Up @@ -2060,7 +2058,7 @@ bool MoveKillsCopyableAddressesChecker::performClosureDataflow(
// Returns true if we emitted a diagnostic and handled the single block
// case. Returns false if we visited all of the uses and seeded the UseState
// struct with the information needed to perform our interprocedural dataflow.
bool MoveKillsCopyableAddressesChecker::performSingleBasicBlockAnalysis(
bool ConsumeOperatorCopyableAddressesChecker::performSingleBasicBlockAnalysis(
SILValue address, DebugVarCarryingInst addressDebugInst,
MarkUnresolvedMoveAddrInst *mvi) {
// First scan downwards to make sure we are move out of this block.
Expand Down Expand Up @@ -2215,8 +2213,8 @@ bool MoveKillsCopyableAddressesChecker::performSingleBasicBlockAnalysis(
auto *next = interestingUser->getNextInstruction();
SILBuilderWithScope reinitBuilder(next);
reinitBuilder.setCurrentDebugScope(addressDebugInst->getDebugScope());
reinitBuilder.createDebugValue(addressDebugInst->getLoc(),
address, *varInfo, false,
reinitBuilder.createDebugValue(addressDebugInst->getLoc(), address,
*varInfo, false,
/*was moved*/ true);
}
}
Expand Down Expand Up @@ -2287,7 +2285,7 @@ bool MoveKillsCopyableAddressesChecker::performSingleBasicBlockAnalysis(
return false;
}

bool MoveKillsCopyableAddressesChecker::check(SILValue address) {
bool ConsumeOperatorCopyableAddressesChecker::check(SILValue address) {
auto accessPathWithBase = AccessPathWithBase::compute(address);
auto accessPath = accessPathWithBase.accessPath;

Expand Down Expand Up @@ -2384,8 +2382,8 @@ bool MoveKillsCopyableAddressesChecker::check(SILValue address) {
// Ok, we need to perform global dataflow for one of our moves. Initialize our
// dataflow state engine and then run the dataflow itself.
dataflowState.init();
bool result = dataflowState.process(
address, addressDebugInst, closureConsumes);
bool result =
dataflowState.process(address, addressDebugInst, closureConsumes);
return result;
}

Expand All @@ -2395,7 +2393,8 @@ bool MoveKillsCopyableAddressesChecker::check(SILValue address) {

namespace {

class MoveKillsCopyableAddressesCheckerPass : public SILFunctionTransform {
class ConsumeOperatorCopyableAddressesCheckerPass
: public SILFunctionTransform {
void run() override {
auto *fn = getFunction();
auto &astContext = fn->getASTContext();
Expand Down Expand Up @@ -2442,7 +2441,7 @@ class MoveKillsCopyableAddressesCheckerPass : public SILFunctionTransform {

SILOptFunctionBuilder funcBuilder(*this);

MoveKillsCopyableAddressesChecker checker(getFunction(), funcBuilder);
ConsumeOperatorCopyableAddressesChecker checker(getFunction(), funcBuilder);

bool madeChange = false;
while (!addressToProcess.empty()) {
Expand Down Expand Up @@ -2481,7 +2480,7 @@ class MoveKillsCopyableAddressesCheckerPass : public SILFunctionTransform {
// uses have been resolved appropriately.
//
// TODO: Emit specific diagnostics here (e.x.: _move of global).
if (DisableUnhandledMoveDiagnostic)
if (DisableUnhandledConsumeOperator)
return;

bool lateMadeChange = false;
Expand Down Expand Up @@ -2513,6 +2512,6 @@ class MoveKillsCopyableAddressesCheckerPass : public SILFunctionTransform {

} // anonymous namespace

SILTransform *swift::createMoveKillsCopyableAddressesChecker() {
return new MoveKillsCopyableAddressesCheckerPass();
SILTransform *swift::createConsumeOperatorCopyableAddressesChecker() {
return new ConsumeOperatorCopyableAddressesCheckerPass();
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===--- MoveKillsCopyableValuesChecker.cpp -------------------------------===//
//===--- ConsumeOperatorCopyableValuesChecker.cpp -------------------------===//
//
// This source file is part of the Swift.org open source project
//
Expand All @@ -10,7 +10,7 @@
//
//===----------------------------------------------------------------------===//

#define DEBUG_TYPE "sil-move-kills-copyable-values-checker"
#define DEBUG_TYPE "sil-consume-operator-copyable-values-checker"

#include "swift/AST/DiagnosticsSIL.h"
#include "swift/Basic/Defer.h"
Expand All @@ -34,8 +34,8 @@

using namespace swift;

static llvm::cl::opt<bool>
DisableUnhandledMoveDiagnostic("sil-disable-unknown-move-diagnostic");
static llvm::cl::opt<bool> DisableUnhandledMoveDiagnostic(
"sil-consume-operator-disable-unknown-move-diagnostic");

//===----------------------------------------------------------------------===//
// Diagnostic Utilities
Expand Down Expand Up @@ -152,8 +152,8 @@ bool CheckerLivenessInfo::compute() {
// Otherwise, try to update liveness for a borrowing operand
// use. This will make it so that we add the end_borrows of the
// liveness use. If we have a reborrow here, we will bail.
if (liveness.updateForBorrowingOperand(use)
!= InnerBorrowKind::Contained) {
if (liveness.updateForBorrowingOperand(use) !=
InnerBorrowKind::Contained) {
return false;
}
}
Expand Down Expand Up @@ -213,13 +213,13 @@ bool CheckerLivenessInfo::compute() {

namespace {

struct MoveKillsCopyableValuesChecker {
struct ConsumeOperatorCopyableValuesChecker {
SILFunction *fn;
CheckerLivenessInfo livenessInfo;
DominanceInfo *dominanceToUpdate;
SILLoopInfo *loopInfoToUpdate;

MoveKillsCopyableValuesChecker(SILFunction *fn)
ConsumeOperatorCopyableValuesChecker(SILFunction *fn)
: fn(fn), livenessInfo(), dominanceToUpdate(nullptr),
loopInfoToUpdate(nullptr) {}

Expand All @@ -245,7 +245,7 @@ static SourceLoc getSourceLocFromValue(SILValue value) {
llvm_unreachable("Do not know how to get source loc for value?!");
}

void MoveKillsCopyableValuesChecker::emitDiagnosticForMove(
void ConsumeOperatorCopyableValuesChecker::emitDiagnosticForMove(
SILValue borrowedValue, StringRef borrowedValueName, MoveValueInst *mvi) {
auto &astContext = fn->getASTContext();

Expand Down Expand Up @@ -399,7 +399,7 @@ void MoveKillsCopyableValuesChecker::emitDiagnosticForMove(
}
}

bool MoveKillsCopyableValuesChecker::check() {
bool ConsumeOperatorCopyableValuesChecker::check() {
SmallSetVector<SILValue, 32> valuesToCheck;

for (auto *arg : fn->getEntryBlock()->getSILFunctionArguments()) {
Expand Down Expand Up @@ -511,8 +511,7 @@ bool MoveKillsCopyableValuesChecker::check() {

static void emitUnsupportedUseCaseError(MoveValueInst *mvi) {
auto &astContext = mvi->getModule().getASTContext();
auto diag = diag::
sil_movekillscopyablevalue_move_applied_to_unsupported_move;
auto diag = diag::sil_movekillscopyablevalue_move_applied_to_unsupported_move;
diagnose(astContext, mvi->getLoc().getSourceLoc(), diag);
mvi->setAllowsDiagnostics(false);
}
Expand All @@ -523,7 +522,7 @@ static void emitUnsupportedUseCaseError(MoveValueInst *mvi) {

namespace {

class MoveKillsCopyableValuesCheckerPass : public SILFunctionTransform {
class ConsumeOperatorCopyableValuesCheckerPass : public SILFunctionTransform {
void run() override {
auto *fn = getFunction();

Expand All @@ -541,7 +540,7 @@ class MoveKillsCopyableValuesCheckerPass : public SILFunctionTransform {
LLVM_DEBUG(llvm::dbgs() << "*** Checking moved values in fn: "
<< getFunction()->getName() << '\n');

MoveKillsCopyableValuesChecker checker(getFunction());
ConsumeOperatorCopyableValuesChecker checker(getFunction());

// If we already had dominance or loop info generated, update them when
// splitting blocks.
Expand Down Expand Up @@ -590,6 +589,6 @@ class MoveKillsCopyableValuesCheckerPass : public SILFunctionTransform {

} // anonymous namespace

SILTransform *swift::createMoveKillsCopyableValuesChecker() {
return new MoveKillsCopyableValuesCheckerPass();
SILTransform *swift::createConsumeOperatorCopyableValuesChecker() {
return new ConsumeOperatorCopyableValuesCheckerPass();
}
8 changes: 4 additions & 4 deletions lib/SILOptimizer/PassManager/PassPipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,10 @@ static void addMandatoryDiagnosticOptPipeline(SILPassPipelinePlan &P) {
P.addMoveOnlyDeinitInsertion();
// Lower move only wrapped trivial types.
P.addTrivialMoveOnlyTypeEliminator();
// Check no uses after _move of a value in an address.
P.addMoveKillsCopyableAddressesChecker();
// No uses after _move of copyable value.
P.addMoveKillsCopyableValuesChecker();
// Check no uses after consume operator of a value in an address.
P.addConsumeOperatorCopyableAddressesChecker();
// No uses after consume operator of copyable value.
P.addConsumeOperatorCopyableValuesChecker();

//
// End Ownership Optimizations
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-sil-opt %s -enable-experimental-move-only -sil-move-kills-copyable-addresses-checker | %FileCheck %s
// RUN: %target-sil-opt %s -enable-experimental-move-only -sil-consume-operator-copyable-addresses-checker | %FileCheck %s

// REQUIRES: optimized_stdlib

Expand Down Expand Up @@ -152,4 +152,4 @@ bb3:
hop_to_executor %2 : $Optional<Builtin.Executor>
%47 = tuple ()
return %47 : $()
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-sil-opt -enable-experimental-move-only -enable-sil-verify-all -o - -sil-move-kills-copyable-addresses-checker -verify %s
// RUN: %target-sil-opt -enable-experimental-move-only -enable-sil-verify-all -o - -sil-consume-operator-copyable-addresses-checker -verify %s

// This file is meant for specific SIL patterns that may be hard to produce with
// the current swift frontend but have reproduced before and we want to make
Expand Down Expand Up @@ -36,4 +36,4 @@ bb0(%0 : @owned $Klass):
destroy_value %0 : $Klass
%23 = tuple ()
return %23 : $()
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-sil-opt -enable-experimental-move-only -enable-sil-verify-all -o - -sil-move-kills-copyable-values-checker -verify %s
// RUN: %target-sil-opt -enable-experimental-move-only -enable-sil-verify-all -o - -sil-consume-operator-copyable-values-checker -verify %s

// This file is meant for specific SIL patterns that may be hard to produce with
// the current swift frontend but have reproduced before and we want to make
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-sil-opt %s -enable-experimental-move-only -sil-move-kills-copyable-values-checker | %FileCheck %s
// RUN: %target-sil-opt %s -enable-experimental-move-only -sil-consume-operator-copyable-values-checker | %FileCheck %s

// REQUIRES: optimized_stdlib

Expand Down

0 comments on commit 3a53828

Please sign in to comment.