Skip to content

Copy propagation redesign and the CanonicalizeBorrowScopes utility #38220

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
merged 12 commits into from
Jul 12, 2021
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
64 changes: 64 additions & 0 deletions include/swift/Basic/DAGNodeWorklist.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
//===--- DAGNodeWorklist.h --------------------------------------*- C++ -*-===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 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
//
//===----------------------------------------------------------------------===//

#ifndef SWIFT_BASIC_DAGNODEWORKLIST_H
#define SWIFT_BASIC_DAGNODEWORKLIST_H

#include "swift/Basic/LLVM.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallVector.h"

/// Worklist of pointer-like things that have an invalid default value. This not
/// only avoids duplicates in the worklist, but also avoids revisiting
/// already-popped nodes. This makes it suitable for DAG traversal. This can
/// also be used within hybrid worklist/recursive traversal by recording the
/// size of the worklist at each level of recursion.
///
/// The primary API has two methods: intialize() and pop(). Others are provided
/// for flexibility.
template <typename T, unsigned SmallSize> struct DAGNodeWorklist {
llvm::SmallPtrSet<T, SmallSize> nodeVisited;
llvm::SmallVector<T, SmallSize> nodeVector;

DAGNodeWorklist() = default;

DAGNodeWorklist(const DAGNodeWorklist &) = delete;

void initialize(T t) {
clear();
insert(t);
}

template <typename R> void initializeRange(R &&range) {
clear();
nodeVisited.insert(range.begin(), range.end());
nodeVector.append(range.begin(), range.end());
}

T pop() { return empty() ? T() : nodeVector.pop_back_val(); }

bool empty() const { return nodeVector.empty(); }

unsigned size() const { return nodeVector.size(); }

void clear() {
nodeVector.clear();
nodeVisited.clear();
}

void insert(T t) {
if (nodeVisited.insert(t).second)
nodeVector.push_back(t);
}
};

#endif // SWIFT_BASIC_DAGNODEWORKLIST_H
4 changes: 2 additions & 2 deletions include/swift/SIL/SILValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,8 @@ class ValueBase : public SILNode, public SILAllocated<ValueBase> {
/// For instruction results, this returns getDefiningInstruction(). For
/// arguments, this returns SILBasicBlock::begin() for the argument's parent
/// block. Returns nullptr for SILUndef.
///
/// FIXME: remove this redundant API from SILValue.
SILInstruction *getDefiningInsertionPoint();

// Const version of \see getDefiningInsertionPoint.
Expand Down Expand Up @@ -603,8 +605,6 @@ class SILValue {

/// If this SILValue is a result of an instruction, return its
/// defining instruction. Returns nullptr otherwise.
///
/// FIXME: remove this redundant API from SILValue.
SILInstruction *getDefiningInstruction() {
return Value->getDefiningInstruction();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@ class NonLocalAccessBlockAnalysis
virtual void verify(NonLocalAccessBlocks *accessBlocks) const override {
NonLocalAccessBlocks checkAccessBlocks(accessBlocks->function);
checkAccessBlocks.compute();
assert(checkAccessBlocks.accessBlocks == accessBlocks->accessBlocks);
assert(llvm::all_of(checkAccessBlocks.accessBlocks,
[&](SILBasicBlock *bb) {
return accessBlocks->accessBlocks.count(bb);
}));
})
};

Expand Down
Loading