Skip to content

Commit 5e1816b

Browse files
Merge pull request #4774 from swiftwasm/main
[pull] swiftwasm from main
2 parents 9f6a375 + 590caf9 commit 5e1816b

37 files changed

+1502
-160
lines changed

SwiftCompilerSources/CMakeLists.txt

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -230,18 +230,28 @@ else()
230230

231231
add_subdirectory(Sources)
232232

233-
# This is a hack to get correct dependencies from imported C++ headers:
234-
# step 1: generate a dummy source file, which just includes all headers defined in include/swift/module.modulemap
235-
add_custom_command(
236-
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/HeaderDependencies.cpp"
237-
COMMAND
238-
"sed"
239-
-n -e "/header/!d" -e "s/.*header/#include/" -e "w ${CMAKE_CURRENT_BINARY_DIR}/HeaderDependencies.cpp"
240-
"${CMAKE_CURRENT_SOURCE_DIR}/../include/swift/module.modulemap"
241-
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/../include/swift/module.modulemap"
242-
COMMENT "Generate HeaderDependencies.cpp"
243-
)
244-
233+
# TODO: generate this dynamically through the modulemap; this cannot use `sed`
234+
# as that is not available on all paltforms (e.g. Windows).
235+
#
236+
# step 1: generate a dummy source file, which just includes all headers
237+
# defined in include/swift/module.modulemap
238+
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/HeaderDependencies.cpp"
239+
"
240+
#include \"Basic/BridgedSwiftObject.h\"
241+
#include \"Basic/BasicBridging.h\"
242+
#include \"Basic/SourceLoc.h\"
243+
244+
#include \"AST/ASTBridging.h\"
245+
#include \"AST/DiagnosticEngine.h\"
246+
#include \"AST/DiagnosticConsumer.h\"
247+
248+
#include \"SIL/SILBridging.h\"
249+
250+
#include \"SILOptimizer/OptimizerBridging.h\"
251+
252+
#include \"Parse/RegexParserBridging.h\"
253+
")
254+
245255
# step 2: build a library containing that source file. This library depends on all the included header files.
246256
# The swift modules can now depend on that target.
247257
# Note that this library is unused, i.e. not linked to anything.
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
//===--- AccessDumper.swift - Dump access information --------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2022 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+
import SIL
14+
15+
/// Dumps access information for memory accesses (`load` and `store`)
16+
/// instructions.
17+
///
18+
/// This pass is used for testing `AccessUtils`.
19+
let accessDumper = FunctionPass(name: "dump-access", {
20+
(function: Function, context: PassContext) in
21+
print("Accesses for \(function.name)")
22+
23+
var apw = AccessPathWalker()
24+
var arw = AccessStoragePathVisitor()
25+
for block in function.blocks {
26+
for instr in block.instructions {
27+
switch instr {
28+
case let st as StoreInst:
29+
printAccessInfo(st.destinationOperand.value, &apw, &arw, context)
30+
case let load as LoadInst:
31+
printAccessInfo(load.operand, &apw, &arw, context)
32+
default:
33+
break
34+
}
35+
}
36+
}
37+
38+
print("End accesses for \(function.name)")
39+
})
40+
41+
private struct AccessStoragePathVisitor : AccessStoragePathWalker {
42+
var walkUpCache = WalkerCache<Path>()
43+
mutating func visit(access: AccessStoragePath) {
44+
print(" Storage: \(access.storage)")
45+
print(" Path: \"\(access.path)\"")
46+
}
47+
}
48+
49+
private func printAccessInfo(_ value: Value, _ apw: inout AccessPathWalker, _ aspw: inout AccessStoragePathVisitor,
50+
_ ctx: PassContext) {
51+
print("Value: \(value)")
52+
let (ap, scope) = apw.getAccessPathWithScope(of: value)
53+
if let scope = scope {
54+
switch scope {
55+
case let .scope(ba):
56+
print(" Scope: \(ba)")
57+
case .base(_):
58+
print(" Scope: base")
59+
}
60+
}
61+
62+
if let ap = ap {
63+
print(" Base: \(ap.base)")
64+
print(" Path: \"\(ap.projectionPath)\"")
65+
66+
aspw.getAccessStorage(for: ap)
67+
}
68+
}

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/CMakeLists.txt

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

99
swift_compiler_sources(Optimizer
1010
AssumeSingleThreaded.swift
11+
AccessDumper.swift
1112
ComputeEffects.swift
1213
EscapeInfoDumper.swift
1314
ObjCBridgingOptimization.swift

SwiftCompilerSources/Sources/Optimizer/PassManager/PassRegistration.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ private func registerSwiftPasses() {
4242
registerPass(mergeCondFailsPass, { mergeCondFailsPass.run($0) })
4343
registerPass(escapeInfoDumper, { escapeInfoDumper.run($0) })
4444
registerPass(addressEscapeInfoDumper, { addressEscapeInfoDumper.run($0) })
45+
registerPass(accessDumper, { accessDumper.run($0) })
4546
registerPass(computeEffects, { computeEffects.run($0) })
4647
registerPass(objCBridgingOptimization, { objCBridgingOptimization.run($0) })
4748
registerPass(stackPromotion, { stackPromotion.run($0) })

0 commit comments

Comments
 (0)