Skip to content

Commit edacd4c

Browse files
committed
Optimizer: convert the AccessDumper from a pass to a test
1 parent abc40b3 commit edacd4c

File tree

8 files changed

+141
-132
lines changed

8 files changed

+141
-132
lines changed

SwiftCompilerSources/Sources/Optimizer/PassManager/PassRegistration.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ private func registerSwiftPasses() {
151151
registerPass(aliasInfoDumper, { aliasInfoDumper.run($0) })
152152
registerPass(functionUsesDumper, { functionUsesDumper.run($0) })
153153
registerPass(silPrinterPass, { silPrinterPass.run($0) })
154-
registerPass(accessDumper, { accessDumper.run($0) })
155154
registerPass(deadEndBlockDumper, { deadEndBlockDumper.run($0) })
156155
registerPass(memBehaviorDumper, { memBehaviorDumper.run($0) })
157156
registerPass(rangeDumper, { rangeDumper.run($0) })

SwiftCompilerSources/Sources/Optimizer/TestPasses/AccessDumper.swift

Lines changed: 0 additions & 126 deletions
This file was deleted.

SwiftCompilerSources/Sources/Optimizer/TestPasses/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
swift_compiler_sources(Optimizer
1010
FunctionUsesDumper.swift
11-
AccessDumper.swift
1211
AliasInfoDumper.swift
1312
DeadEndBlockDumper.swift
1413
MemBehaviorDumper.swift

SwiftCompilerSources/Sources/SIL/Utilities/AccessUtils.swift

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -903,10 +903,124 @@ extension Function {
903903
}
904904
}
905905

906+
//===--------------------------------------------------------------------===//
907+
// Tests
908+
//===--------------------------------------------------------------------===//
909+
906910
let getAccessBaseTest = Test("swift_get_access_base") {
907911
function, arguments, context in
908912
let address = arguments.takeValue()
909913
print("Address: \(address)")
910914
let base = address.accessBase
911915
print("Base: \(base)")
912916
}
917+
918+
let accessPathTest = Test("access_path") {
919+
function, arguments, context in
920+
921+
// Prints access path information for memory accesses (`load` and `store`) instructions.
922+
// Also verifies that `AccessPath.isDistinct(from:)` is correct.
923+
924+
print("Accesses for \(function.name)")
925+
926+
for block in function.blocks {
927+
for instr in block.instructions {
928+
switch instr {
929+
case let st as StoreInst:
930+
printAccessInfo(address: st.destination)
931+
case let load as LoadInst:
932+
printAccessInfo(address: load.address)
933+
case let apply as ApplyInst:
934+
guard let callee = apply.referencedFunction else {
935+
break
936+
}
937+
if callee.name == "_isDistinct" {
938+
checkAliasInfo(forArgumentsOf: apply, expectDistinct: true)
939+
} else if callee.name == "_isNotDistinct" {
940+
checkAliasInfo(forArgumentsOf: apply, expectDistinct: false)
941+
}
942+
default:
943+
break
944+
}
945+
}
946+
}
947+
948+
print("End accesses for \(function.name)")
949+
}
950+
951+
private struct AccessStoragePathVisitor : ValueUseDefWalker {
952+
var walkUpCache = WalkerCache<Path>()
953+
mutating func rootDef(value: Value, path: SmallProjectionPath) -> WalkResult {
954+
print(" Storage: \(value)")
955+
print(" Path: \"\(path)\"")
956+
return .continueWalk
957+
}
958+
}
959+
960+
private func printAccessInfo(address: Value) {
961+
print("Value: \(address)")
962+
963+
let (ap, scope) = address.accessPathWithScope
964+
if let beginAccess = scope {
965+
print(" Scope: \(beginAccess)")
966+
} else {
967+
print(" Scope: base")
968+
}
969+
970+
let constAp = address.constantAccessPath
971+
if constAp == ap {
972+
print(" Base: \(ap.base)")
973+
print(" Path: \"\(ap.projectionPath)\"")
974+
} else {
975+
print(" nonconst-base: \(ap.base)")
976+
print(" nonconst-path: \"\(ap.projectionPath)\"")
977+
print(" const-base: \(constAp.base)")
978+
print(" const-path: \"\(constAp.projectionPath)\"")
979+
}
980+
981+
var arw = AccessStoragePathVisitor()
982+
if !arw.visitAccessStorageRoots(of: ap) {
983+
print(" no Storage paths")
984+
}
985+
}
986+
987+
private func checkAliasInfo(forArgumentsOf apply: ApplyInst, expectDistinct: Bool) {
988+
let address1 = apply.arguments[0]
989+
let address2 = apply.arguments[1]
990+
991+
checkIsDistinct(path1: address1.accessPath,
992+
path2: address2.accessPath,
993+
expectDistinct: expectDistinct,
994+
instruction: apply)
995+
996+
if !expectDistinct {
997+
// Also check all combinations with the constant variant of access paths.
998+
// Note: we can't do that for "isDistinct" because "isDistinct" might be more conservative in one of the variants.
999+
checkIsDistinct(path1: address1.constantAccessPath,
1000+
path2: address2.constantAccessPath,
1001+
expectDistinct: false,
1002+
instruction: apply)
1003+
checkIsDistinct(path1: address1.accessPath,
1004+
path2: address2.constantAccessPath,
1005+
expectDistinct: false,
1006+
instruction: apply)
1007+
checkIsDistinct(path1: address1.constantAccessPath,
1008+
path2: address2.accessPath,
1009+
expectDistinct: false,
1010+
instruction: apply)
1011+
}
1012+
}
1013+
1014+
private func checkIsDistinct(path1: AccessPath, path2: AccessPath, expectDistinct: Bool, instruction: Instruction) {
1015+
if path1.isDistinct(from: path2) != expectDistinct {
1016+
print("wrong isDistinct result of \(instruction)")
1017+
} else if path2.isDistinct(from: path1) != expectDistinct {
1018+
print("wrong reverse isDistinct result of \(instruction)")
1019+
} else {
1020+
return
1021+
}
1022+
1023+
print("in function")
1024+
print(instruction.parentFunction)
1025+
fatalError()
1026+
}

SwiftCompilerSources/Sources/SIL/Utilities/Test.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ public func registerTests() {
144144
parseTestSpecificationTest,
145145
smallProjectionPathTest,
146146
getAccessBaseTest,
147+
accessPathTest,
147148
borrowIntroducersTest,
148149
enclosingValuesTest,
149150
forwardingDefUseTest,

include/swift/SILOptimizer/PassManager/Passes.def

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,6 @@ PASS(DeadEndBlockDumper, "dump-deadendblocks",
7777
"Tests the DeadEndBlocks utility")
7878
PASS(EmbeddedWitnessCallSpecialization, "embedded-witness-call-specialization",
7979
"Mandatory witness method call specialization")
80-
PASS(AccessDumper, "dump-access",
81-
"Dump access information")
8280
PASS(ConstantCapturePropagation, "constant-capture-propagation",
8381
"Specialize closures with constant captures")
8482
PASS(ComputeEscapeEffects, "compute-escape-effects",

test/SILOptimizer/accessutils_raw.sil renamed to test/SILOptimizer/accessutils_raw_unit.sil

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-sil-opt %s -dump-access -o /dev/null | %FileCheck %s
1+
// RUN: %target-sil-opt %s -test-runner -o /dev/null | %FileCheck %s
22

33
// REQUIRES: swift_in_compiler
44

@@ -36,6 +36,7 @@ struct MoveOnlyPair: ~Copyable {
3636
// CHECK-NEXT: End accesses for testMarkUnresolvedNonCopyableValueInst
3737
sil [ossa] @testMarkUnresolvedNonCopyableValueInst : $@convention(thin) (@guaranteed List) -> () {
3838
bb0(%0 : @guaranteed $List):
39+
specify_test "access_path"
3940
%1 = alloc_box ${ var MoveOnlyPair }
4041
%2 = project_box %1 : ${ var MoveOnlyPair }, 0
4142
%3 = mark_unresolved_non_copyable_value [consumable_and_assignable] %2 : $*MoveOnlyPair

0 commit comments

Comments
 (0)