Skip to content

Swift Optimizer: add AccessUtils #60512

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 6 commits into from
Aug 12, 2022
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
//===--- AccessDumper.swift - Dump access information --------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2022 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
//
//===----------------------------------------------------------------------===//

import SIL

/// Dumps access information for memory accesses (`load` and `store`)
/// instructions.
///
/// This pass is used for testing `AccessUtils`.
let accessDumper = FunctionPass(name: "dump-access", {
(function: Function, context: PassContext) in
print("Accesses for \(function.name)")

var apw = AccessPathWalker()
var arw = AccessStoragePathVisitor()
for block in function.blocks {
for instr in block.instructions {
switch instr {
case let st as StoreInst:
printAccessInfo(st.destinationOperand.value, &apw, &arw, context)
case let load as LoadInst:
printAccessInfo(load.operand, &apw, &arw, context)
default:
break
}
}
}

print("End accesses for \(function.name)")
})

private struct AccessStoragePathVisitor : AccessStoragePathWalker {
var walkUpCache = WalkerCache<Path>()
mutating func visit(access: AccessStoragePath) {
print(" Storage: \(access.storage)")
print(" Path: \"\(access.path)\"")
}
}

private func printAccessInfo(_ value: Value, _ apw: inout AccessPathWalker, _ aspw: inout AccessStoragePathVisitor,
_ ctx: PassContext) {
print("Value: \(value)")
let (ap, scope) = apw.getAccessPathWithScope(of: value)
if let scope = scope {
switch scope {
case let .scope(ba):
print(" Scope: \(ba)")
case .base(_):
print(" Scope: base")
}
}

if let ap = ap {
print(" Base: \(ap.base)")
print(" Path: \"\(ap.projectionPath)\"")

aspw.getAccessStorage(for: ap)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

swift_compiler_sources(Optimizer
AssumeSingleThreaded.swift
AccessDumper.swift
ComputeEffects.swift
EscapeInfoDumper.swift
ObjCBridgingOptimization.swift
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ private func registerSwiftPasses() {
registerPass(mergeCondFailsPass, { mergeCondFailsPass.run($0) })
registerPass(escapeInfoDumper, { escapeInfoDumper.run($0) })
registerPass(addressEscapeInfoDumper, { addressEscapeInfoDumper.run($0) })
registerPass(accessDumper, { accessDumper.run($0) })
registerPass(computeEffects, { computeEffects.run($0) })
registerPass(objCBridgingOptimization, { objCBridgingOptimization.run($0) })
registerPass(stackPromotion, { stackPromotion.run($0) })
Expand Down
Loading