Skip to content

Commit 85ff15a

Browse files
committed
Add indexTrieRoot to the SILModule to share across Analyses.
...and avoid reallocation. This is immediately necessary for LICM, in addition to its current uses. I suspect this could be used by many passes that work with addresses. RLE/DSE should absolutely migrate to it.
1 parent 38c8bbd commit 85ff15a

File tree

8 files changed

+21
-22
lines changed

8 files changed

+21
-22
lines changed

include/swift/SILOptimizer/Utils/IndexTrie.h renamed to include/swift/Basic/IndexTrie.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#ifndef SWIFT_SILOPTIMIZER_UTILS_INDEXTREE_H
1414
#define SWIFT_SILOPTIMIZER_UTILS_INDEXTREE_H
1515

16+
#include "swift/Basic/LLVM.h"
1617
#include "llvm/ADT/ArrayRef.h"
1718
#include "llvm/ADT/SmallVector.h"
1819
#include <algorithm>

include/swift/SIL/SILModule.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "swift/AST/Builtins.h"
2222
#include "swift/AST/SILLayout.h"
2323
#include "swift/AST/SILOptions.h"
24+
#include "swift/Basic/IndexTrie.h"
2425
#include "swift/Basic/LangOptions.h"
2526
#include "swift/Basic/ProfileCounter.h"
2627
#include "swift/Basic/Range.h"
@@ -256,6 +257,10 @@ class SILModule {
256257
/// The indexed profile data to be used for PGO, or nullptr.
257258
std::unique_ptr<llvm::IndexedInstrProfReader> PGOReader;
258259

260+
/// A trie of integer indices that gives pointer identity to a path of
261+
/// projections, shared between all functions in the module.
262+
std::unique_ptr<IndexTrieNode> indexTrieRoot;
263+
259264
/// The options passed into this SILModule.
260265
const SILOptions &Options;
261266

@@ -655,6 +660,8 @@ class SILModule {
655660
PGOReader = std::move(IPR);
656661
}
657662

663+
IndexTrieNode *getIndexTrieRoot() { return indexTrieRoot.get(); }
664+
658665
/// Can value operations (copies and destroys) on the given lowered type
659666
/// be performed in this module?
660667
bool isTypeABIAccessible(SILType type,

include/swift/SILOptimizer/Analysis/AccessSummaryAnalysis.h

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
#ifndef SWIFT_SILOPTIMIZER_ANALYSIS_ACCESS_SUMMARY_ANALYSIS_H_
2020
#define SWIFT_SILOPTIMIZER_ANALYSIS_ACCESS_SUMMARY_ANALYSIS_H_
2121

22+
#include "swift/Basic/IndexTrie.h"
2223
#include "swift/SIL/SILFunction.h"
2324
#include "swift/SIL/SILInstruction.h"
2425
#include "swift/SILOptimizer/Analysis/BottomUpIPAnalysis.h"
25-
#include "swift/SILOptimizer/Utils/IndexTrie.h"
2626
#include "llvm/ADT/DenseMap.h"
2727
#include "llvm/ADT/SmallVector.h"
2828

@@ -173,22 +173,13 @@ class AccessSummaryAnalysis : public BottomUpIPAnalysis {
173173

174174
llvm::SpecificBumpPtrAllocator<FunctionInfo> Allocator;
175175

176-
/// A trie of integer indices that gives pointer identity to a path of
177-
/// projections. This is shared between all functions in the module.
178-
std::unique_ptr<IndexTrieNode> SubPathTrie;
179-
180176
public:
181-
AccessSummaryAnalysis() : BottomUpIPAnalysis(SILAnalysisKind::AccessSummary) {
182-
SubPathTrie.reset(new IndexTrieNode());
183-
}
177+
AccessSummaryAnalysis()
178+
: BottomUpIPAnalysis(SILAnalysisKind::AccessSummary) {}
184179

185180
/// Returns a summary of the accesses performed by the given function.
186181
const FunctionSummary &getOrCreateSummary(SILFunction *Fn);
187182

188-
IndexTrieNode *getSubPathTrieRoot() {
189-
return SubPathTrie.get();
190-
}
191-
192183
/// Returns an IndexTrieNode that represents the single subpath accessed from
193184
/// BAI or the root if no such node exists.
194185
const IndexTrieNode *findSubPathAccessed(BeginAccessInst *BAI);

lib/SIL/IR/SILModule.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ class SILModule::SerializationCallback final
9494

9595
SILModule::SILModule(llvm::PointerUnion<FileUnit *, ModuleDecl *> context,
9696
Lowering::TypeConverter &TC, const SILOptions &Options)
97-
: Stage(SILStage::Raw), Options(Options), serialized(false),
97+
: Stage(SILStage::Raw), indexTrieRoot(new IndexTrieNode()),
98+
Options(Options), serialized(false),
9899
regDeserializationNotificationHandlerForNonTransparentFuncOME(false),
99100
regDeserializationNotificationHandlerForAllFuncOME(false),
100101
SerializeSILAction(), Types(TC) {

lib/SILOptimizer/Analysis/AccessSummaryAnalysis.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ void AccessSummaryAnalysis::processFunction(FunctionInfo *info,
4949
/// started by a begin_access and any flows of the arguments to other
5050
/// functions.
5151
void AccessSummaryAnalysis::processArgument(FunctionInfo *info,
52-
SILFunctionArgument *argument,
53-
ArgumentSummary &summary,
54-
FunctionOrder &order) {
52+
SILFunctionArgument *argument,
53+
ArgumentSummary &summary,
54+
FunctionOrder &order) {
5555
unsigned argumentIndex = argument->getIndex();
5656

5757
// Use a worklist to track argument uses to be processed.
@@ -77,7 +77,7 @@ void AccessSummaryAnalysis::processArgument(FunctionInfo *info,
7777
// call.
7878
if (!callee || callee->empty()) {
7979
summary.mergeWith(SILAccessKind::Modify, apply.getLoc(),
80-
getSubPathTrieRoot());
80+
apply.getModule().getIndexTrieRoot());
8181
continue;
8282
}
8383
unsigned operandNumber = operand->getOperandNumber();
@@ -468,7 +468,6 @@ AccessSummaryAnalysis::getOrCreateSummary(SILFunction *fn) {
468468
void AccessSummaryAnalysis::AccessSummaryAnalysis::invalidate() {
469469
FunctionInfos.clear();
470470
Allocator.DestroyAll();
471-
SubPathTrie.reset(new IndexTrieNode());
472471
}
473472

474473
void AccessSummaryAnalysis::invalidate(SILFunction *F, InvalidationKind K) {
@@ -526,7 +525,7 @@ getSingleAddressProjectionUser(SingleValueInstruction *I) {
526525

527526
const IndexTrieNode *
528527
AccessSummaryAnalysis::findSubPathAccessed(BeginAccessInst *BAI) {
529-
IndexTrieNode *SubPath = getSubPathTrieRoot();
528+
IndexTrieNode *SubPath = BAI->getModule().getIndexTrieRoot();
530529

531530
// For each single-user projection of BAI, construct or get a node
532531
// from the trie representing the index of the field or tuple element

lib/SILOptimizer/Mandatory/DiagnoseStaticExclusivity.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,7 @@ static void checkCaptureAccess(ApplySite Apply, AccessState &State) {
754754

755755
// The unknown argument access is considered a modify of the root subpath.
756756
auto argAccess = RecordedAccess(SILAccessKind::Modify, Apply.getLoc(),
757-
State.ASA->getSubPathTrieRoot());
757+
Apply.getModule().getIndexTrieRoot());
758758

759759
// Construct a conflicting RecordedAccess if one doesn't already exist.
760760
const AccessInfo &info = AccessIt->getSecond();

lib/SILOptimizer/Transforms/CopyPropagation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,12 @@
123123
/// ===----------------------------------------------------------------------===
124124

125125
#define DEBUG_TYPE "copy-propagation"
126+
#include "swift/Basic/IndexTrie.h"
126127
#include "swift/SIL/InstructionUtils.h"
127128
#include "swift/SIL/Projection.h"
128129
#include "swift/SILOptimizer/PassManager/Passes.h"
129130
#include "swift/SILOptimizer/PassManager/Transforms.h"
130131
#include "swift/SILOptimizer/Utils/CFGOptUtils.h"
131-
#include "swift/SILOptimizer/Utils/IndexTrie.h"
132132
#include "swift/SILOptimizer/Utils/InstOptUtils.h"
133133
#include "llvm/ADT/DenseMap.h"
134134
#include "llvm/ADT/Statistic.h"

lib/SILOptimizer/Transforms/DeadObjectElimination.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
//===----------------------------------------------------------------------===//
2525

2626
#define DEBUG_TYPE "dead-object-elim"
27+
#include "swift/Basic/IndexTrie.h"
2728
#include "swift/AST/ResilienceExpansion.h"
2829
#include "swift/SIL/BasicBlockUtils.h"
2930
#include "swift/SIL/DebugUtils.h"
@@ -38,7 +39,6 @@
3839
#include "swift/SILOptimizer/Analysis/ArraySemantic.h"
3940
#include "swift/SILOptimizer/PassManager/Passes.h"
4041
#include "swift/SILOptimizer/PassManager/Transforms.h"
41-
#include "swift/SILOptimizer/Utils/IndexTrie.h"
4242
#include "swift/SILOptimizer/Utils/InstOptUtils.h"
4343
#include "swift/SILOptimizer/Utils/SILSSAUpdater.h"
4444
#include "swift/SILOptimizer/Utils/ValueLifetime.h"

0 commit comments

Comments
 (0)