Skip to content

Commit cd55abb

Browse files
authored
Merge pull request #38220 from atrick/rewrite-borrow-forward
Copy propagation redesign and the CanonicalizeBorrowScopes utility
2 parents 2894f05 + c3b1c58 commit cd55abb

20 files changed

+2240
-1000
lines changed

include/swift/Basic/DAGNodeWorklist.h

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
//===--- DAGNodeWorklist.h --------------------------------------*- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef SWIFT_BASIC_DAGNODEWORKLIST_H
14+
#define SWIFT_BASIC_DAGNODEWORKLIST_H
15+
16+
#include "swift/Basic/LLVM.h"
17+
#include "llvm/ADT/SmallPtrSet.h"
18+
#include "llvm/ADT/SmallVector.h"
19+
20+
/// Worklist of pointer-like things that have an invalid default value. This not
21+
/// only avoids duplicates in the worklist, but also avoids revisiting
22+
/// already-popped nodes. This makes it suitable for DAG traversal. This can
23+
/// also be used within hybrid worklist/recursive traversal by recording the
24+
/// size of the worklist at each level of recursion.
25+
///
26+
/// The primary API has two methods: intialize() and pop(). Others are provided
27+
/// for flexibility.
28+
template <typename T, unsigned SmallSize> struct DAGNodeWorklist {
29+
llvm::SmallPtrSet<T, SmallSize> nodeVisited;
30+
llvm::SmallVector<T, SmallSize> nodeVector;
31+
32+
DAGNodeWorklist() = default;
33+
34+
DAGNodeWorklist(const DAGNodeWorklist &) = delete;
35+
36+
void initialize(T t) {
37+
clear();
38+
insert(t);
39+
}
40+
41+
template <typename R> void initializeRange(R &&range) {
42+
clear();
43+
nodeVisited.insert(range.begin(), range.end());
44+
nodeVector.append(range.begin(), range.end());
45+
}
46+
47+
T pop() { return empty() ? T() : nodeVector.pop_back_val(); }
48+
49+
bool empty() const { return nodeVector.empty(); }
50+
51+
unsigned size() const { return nodeVector.size(); }
52+
53+
void clear() {
54+
nodeVector.clear();
55+
nodeVisited.clear();
56+
}
57+
58+
void insert(T t) {
59+
if (nodeVisited.insert(t).second)
60+
nodeVector.push_back(t);
61+
}
62+
};
63+
64+
#endif // SWIFT_BASIC_DAGNODEWORKLIST_H

include/swift/SIL/SILValue.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,8 @@ class ValueBase : public SILNode, public SILAllocated<ValueBase> {
478478
/// For instruction results, this returns getDefiningInstruction(). For
479479
/// arguments, this returns SILBasicBlock::begin() for the argument's parent
480480
/// block. Returns nullptr for SILUndef.
481+
///
482+
/// FIXME: remove this redundant API from SILValue.
481483
SILInstruction *getDefiningInsertionPoint();
482484

483485
// Const version of \see getDefiningInsertionPoint.
@@ -614,8 +616,6 @@ class SILValue {
614616

615617
/// If this SILValue is a result of an instruction, return its
616618
/// defining instruction. Returns nullptr otherwise.
617-
///
618-
/// FIXME: remove this redundant API from SILValue.
619619
SILInstruction *getDefiningInstruction() {
620620
return Value->getDefiningInstruction();
621621
}

include/swift/SILOptimizer/Analysis/NonLocalAccessBlockAnalysis.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,10 @@ class NonLocalAccessBlockAnalysis
8888
virtual void verify(NonLocalAccessBlocks *accessBlocks) const override {
8989
NonLocalAccessBlocks checkAccessBlocks(accessBlocks->function);
9090
checkAccessBlocks.compute();
91-
assert(checkAccessBlocks.accessBlocks == accessBlocks->accessBlocks);
91+
assert(llvm::all_of(checkAccessBlocks.accessBlocks,
92+
[&](SILBasicBlock *bb) {
93+
return accessBlocks->accessBlocks.count(bb);
94+
}));
9295
})
9396
};
9497

0 commit comments

Comments
 (0)