Skip to content

Commit 7e435fa

Browse files
committed
Add AccessPath support to the AccessedStorageDumper pass.
Add a flag: enable-accessed-storage-dump-uses
1 parent 1e9c4d1 commit 7e435fa

File tree

1 file changed

+45
-13
lines changed

1 file changed

+45
-13
lines changed

lib/SILOptimizer/UtilityPasses/AccessedStorageDumper.cpp

Lines changed: 45 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
//===--- AccessedStorageDumper.cpp - Dump accessed storage for functions ---===//
1+
//===--- AccessedStorageDumper.cpp - Dump accessed storage ----------------===//
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
@@ -17,24 +17,52 @@
1717
#include "swift/SIL/SILValue.h"
1818
#include "swift/SILOptimizer/PassManager/Passes.h"
1919
#include "swift/SILOptimizer/PassManager/Transforms.h"
20+
#include "llvm/Support/CommandLine.h"
2021
#include "llvm/Support/Debug.h"
2122

2223
using namespace swift;
2324

24-
static void dumpAccessedStorage(SILInstruction *inst) {
25-
visitAccessedAddress(
26-
inst,
27-
[&](Operand *operand) {
28-
inst->print(llvm::outs());
29-
findAccessedStorage(operand->get()).print(llvm::outs());
30-
}
31-
);
32-
}
25+
static llvm::cl::opt<bool> EnableDumpUses(
26+
"enable-accessed-storage-dump-uses", llvm::cl::init(false),
27+
llvm::cl::desc("With --sil-access-storage-dumper, dump all uses"));
3328

3429
namespace {
3530

3631
/// Dumps sorage information for each access.
3732
class AccessedStorageDumper : public SILModuleTransform {
33+
llvm::SmallVector<Operand *, 32> uses;
34+
35+
void dumpAccessedStorage(Operand *operand) {
36+
findAccessedStorage(operand->get()).print(llvm::outs());
37+
auto pathAndBase = AccessPathWithBase::compute(operand->get());
38+
pathAndBase.print(llvm::outs());
39+
40+
if (!pathAndBase.accessPath.isValid() || !EnableDumpUses)
41+
return;
42+
43+
uses.clear();
44+
pathAndBase.collectUses(uses, /*collectContainingUses*/ false);
45+
llvm::outs() << "Exact Uses {\n";
46+
for (auto *useOperand : uses) {
47+
llvm::outs() << *useOperand->getUser() << " ";
48+
auto usePathAndBase = AccessPathWithBase::compute(useOperand->get());
49+
usePathAndBase.accessPath.printPath(llvm::outs());
50+
assert(pathAndBase.accessPath.contains(usePathAndBase.accessPath)
51+
&& "access path does not contain use access path");
52+
}
53+
llvm::outs() << "}\n";
54+
uses.clear();
55+
pathAndBase.collectUses(uses, /*collectContainingUses*/ true);
56+
llvm::outs() << "Overlapping Uses {\n";
57+
for (auto *useOperand : uses) {
58+
llvm::outs() << *useOperand->getUser() << " ";
59+
auto usePathAndBase = AccessPathWithBase::compute(useOperand->get());
60+
usePathAndBase.accessPath.printPath(llvm::outs());
61+
assert(pathAndBase.accessPath.mayOverlap(usePathAndBase.accessPath)
62+
&& "access path does not contain use access path");
63+
}
64+
llvm::outs() << "}\n";
65+
}
3866

3967
void run() override {
4068
for (auto &fn : *getModule()) {
@@ -45,8 +73,12 @@ class AccessedStorageDumper : public SILModuleTransform {
4573
}
4674
for (auto &bb : fn) {
4775
for (auto &inst : bb) {
48-
if (inst.mayReadOrWriteMemory())
49-
dumpAccessedStorage(&inst);
76+
if (inst.mayReadOrWriteMemory()) {
77+
llvm::outs() << "###For MemOp: " << inst;
78+
visitAccessedAddress(&inst, [this](Operand *operand) {
79+
dumpAccessedStorage(operand);
80+
});
81+
}
5082
}
5183
}
5284
}

0 commit comments

Comments
 (0)