Skip to content

Commit 10ff55b

Browse files
authored
Merge pull request #70155 from eeckstein/refactoring
MemoryLifetimeVerifier: use CalleeCache instead of AliasAnalysis
2 parents 520e124 + 0897d8a commit 10ff55b

35 files changed

+1010
-881
lines changed

SwiftCompilerSources/Sources/Basic/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@
99
add_swift_compiler_module(Basic
1010
SOURCES
1111
SourceLoc.swift
12+
StringParser.swift
1213
Utils.swift)
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
//===--- StringParser.swift -----------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2023 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+
/// A simple utility to parse a string.
14+
public struct StringParser {
15+
private var s: Substring
16+
private let originalLength: Int
17+
18+
private mutating func consumeWhitespace() {
19+
s = s.drop { $0.isWhitespace }
20+
}
21+
22+
public init(_ string: String) {
23+
s = Substring(string)
24+
originalLength = string.count
25+
}
26+
27+
public mutating func isEmpty() -> Bool {
28+
consumeWhitespace()
29+
return s.isEmpty
30+
}
31+
32+
public mutating func consume(_ str: String) -> Bool {
33+
consumeWhitespace()
34+
if !s.starts(with: str) { return false }
35+
s = s.dropFirst(str.count)
36+
return true
37+
}
38+
39+
public mutating func consumeInt(withWhiteSpace: Bool = true) -> Int? {
40+
if withWhiteSpace {
41+
consumeWhitespace()
42+
}
43+
var intStr = ""
44+
s = s.drop {
45+
if $0.isNumber {
46+
intStr.append($0)
47+
return true
48+
}
49+
return false
50+
}
51+
return Int(intStr)
52+
}
53+
54+
public mutating func consumeIdentifier() -> String? {
55+
consumeWhitespace()
56+
var name = ""
57+
s = s.drop {
58+
if $0.isLetter {
59+
name.append($0)
60+
return true
61+
}
62+
return false
63+
}
64+
return name.isEmpty ? nil : name
65+
}
66+
67+
public func throwError(_ message: StaticString) throws -> Never {
68+
throw ParsingError(message: message, position: originalLength - s.count)
69+
}
70+
}
71+
72+
public struct ParsingError : Error {
73+
public let message: StaticString
74+
public let position: Int
75+
}

SwiftCompilerSources/Sources/Optimizer/Utilities/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ swift_compiler_sources(Optimizer
1212
EscapeUtils.swift
1313
OptUtils.swift
1414
ForwardingUtils.swift
15-
WalkUtils.swift
16-
AccessUtils.swift
1715
SSAUpdater.swift
1816
StaticInitCloner.swift
1917
Test.swift

SwiftCompilerSources/Sources/Optimizer/Utilities/OptUtils.swift

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -322,22 +322,6 @@ extension LoadInst {
322322
}
323323
}
324324

325-
extension SmallProjectionPath {
326-
/// Returns true if the path only contains projections which can be materialized as
327-
/// SIL struct or tuple projection instructions - for values or addresses.
328-
var isMaterializable: Bool {
329-
let (kind, _, subPath) = pop()
330-
switch kind {
331-
case .root:
332-
return true
333-
case .structField, .tupleField:
334-
return subPath.isMaterializable
335-
default:
336-
return false
337-
}
338-
}
339-
}
340-
341325
extension FunctionPassContext {
342326
/// Returns true if any blocks were removed.
343327
func removeDeadBlocks(in function: Function) -> Bool {

SwiftCompilerSources/Sources/SIL/CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@ add_swift_compiler_module(SIL
2222
Location.swift
2323
Operand.swift
2424
Registration.swift
25-
SmallProjectionPath.swift
25+
SILStage.swift
2626
SubstitutionMap.swift
2727
Type.swift
28-
Utils.swift
2928
Value.swift
3029
VTable.swift
3130
WitnessTable.swift)
31+
32+
add_subdirectory(Utilities)
33+

SwiftCompilerSources/Sources/SIL/Function.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,24 @@ final public class Function : CustomStringConvertible, HasShortDescription, Hash
374374
{ (f: BridgedFunction, observeRetains: Bool) -> BridgedMemoryBehavior in
375375
let e = f.function.getSideEffects()
376376
return e.getMemBehavior(observeRetains: observeRetains)
377+
},
378+
// argumentMayRead (used by the MemoryLifetimeVerifier)
379+
{ (f: BridgedFunction, bridgedArgOp: BridgedOperand, bridgedAddr: BridgedValue) -> Bool in
380+
let argOp = Operand(bridged: bridgedArgOp)
381+
let addr = bridgedAddr.value
382+
let applySite = argOp.instruction as! FullApplySite
383+
let addrPath = addr.accessPath
384+
let argIdx = argOp.index - ApplyOperands.firstArgumentIndex
385+
let calleeArgIdx = applySite.calleeArgIndex(callerArgIndex: argIdx)
386+
let convention = applySite.getArgumentConvention(calleeArgIndex: calleeArgIdx)
387+
assert(convention.isIndirectIn || convention.isInout)
388+
let argPath = argOp.value.accessPath
389+
assert(!argPath.isDistinct(from: addrPath))
390+
let path = argPath.getProjection(to: addrPath) ?? SmallProjectionPath()
391+
let effects = f.function.getSideEffects(forArgument: argOp.value.at(path),
392+
atIndex: calleeArgIdx,
393+
withConvention: convention)
394+
return effects.memory.read
377395
}
378396
)
379397
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//===--- SILStage.swift ---------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2023 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+
public enum SILStage: Int {
14+
/// "Raw" SIL, emitted by SILGen, but not yet run through guaranteed
15+
/// optimization and diagnostic passes.
16+
///
17+
/// Raw SIL does not have fully-constructed SSA and may contain undiagnosed
18+
/// dataflow errors.
19+
case raw
20+
21+
/// Canonical SIL, which has been run through at least the guaranteed
22+
/// optimization and diagnostic passes.
23+
///
24+
/// Canonical SIL has stricter invariants than raw SIL. It must not contain
25+
/// dataflow errors, and some instructions must be canonicalized to simpler
26+
/// forms.
27+
case canonical
28+
29+
/// Lowered SIL, which has been prepared for IRGen and will no longer
30+
/// be passed to canonical SIL transform passes.
31+
///
32+
/// In lowered SIL, the SILType of all SILValues is its SIL storage
33+
/// type. Explicit storage is required for all address-only and resilient
34+
/// types.
35+
///
36+
/// Generating the initial Raw SIL is typically referred to as lowering (from
37+
/// the AST). To disambiguate, refer to the process of generating the lowered
38+
/// stage of SIL as "address lowering".
39+
case lowered
40+
}

0 commit comments

Comments
 (0)