Skip to content

Commit 3d5e27c

Browse files
Merge pull request #4476 from swiftwasm/main
[pull] swiftwasm from main
2 parents 3eb4108 + b04ba4b commit 3d5e27c

File tree

16 files changed

+285
-221
lines changed

16 files changed

+285
-221
lines changed

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/ReleaseDevirtualizer.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ let releaseDevirtualizerPass = FunctionPass(
4343
// these we know that they don't have associated objects, which are
4444
// _not_ released by the deinit method.
4545
if let deallocStackRef = instruction as? DeallocStackRefInst {
46+
if !context.continueWithNextSubpassRun(for: release) {
47+
return
48+
}
4649
tryDevirtualizeReleaseOfObject(context, release, deallocStackRef)
4750
lastRelease = nil
4851
continue

SwiftCompilerSources/Sources/Optimizer/PassManager/PassUtils.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ struct PassContext {
2222

2323
let _bridged: BridgedPassContext
2424

25+
func continueWithNextSubpassRun(for inst: Instruction? = nil) -> Bool {
26+
let bridgedInst = OptionalBridgedInstruction(obj: inst?.bridged.obj)
27+
return PassContext_continueWithNextSubpassRun(_bridged, bridgedInst) != 0
28+
}
29+
2530
var aliasAnalysis: AliasAnalysis {
2631
let bridgedAA = PassContext_getAliasAnalysis(_bridged)
2732
return AliasAnalysis(bridged: bridgedAA)

SwiftCompilerSources/Sources/Optimizer/Utilities/EscapeInfo.swift

Lines changed: 176 additions & 178 deletions
Large diffs are not rendered by default.

SwiftCompilerSources/Sources/SIL/Effects.swift

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,17 @@ public struct FunctionEffects : CustomStringConvertible, CustomReflectable {
185185
}
186186
}
187187

188-
public func canEscape(path: ArgumentEffect.Path) -> Bool {
188+
public func canEscape(argumentIndex: Int, path: ArgumentEffect.Path, analyzeAddresses: Bool) -> Bool {
189189
return !argumentEffects.contains(where: {
190-
if case .notEscaping = $0.kind,
191-
$0.selectedArg.matches(.argument(0), path) {
192-
return true
190+
if case .notEscaping = $0.kind, $0.selectedArg.value == .argument(argumentIndex) {
191+
192+
// Any address of a class property of an object, which is passed to the function, cannot
193+
// escape the function. Whereas a value stored in such a property could escape.
194+
let p = (analyzeAddresses ? path.popLastClassAndValuesFromTail() : path)
195+
196+
if p.matches(pattern: $0.selectedArg.pathPattern) {
197+
return true
198+
}
193199
}
194200
return false
195201
})

include/swift/Runtime/RuntimeFnWrappersGen.h

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
#define SWIFT_RUNTIME_RUNTIMEFNWRAPPERSGEN_H
1818

1919
#include "swift/SIL/RuntimeEffect.h"
20-
#include "llvm/IR/Module.h"
2120
#include "llvm/ADT/ArrayRef.h"
21+
#include "llvm/IR/Module.h"
2222

2323
namespace swift {
24-
24+
2525
class AvailabilityContext;
2626
class ASTContext;
2727

@@ -34,14 +34,12 @@ enum class RuntimeAvailability {
3434
/// Generate an llvm declaration for a runtime entry with a
3535
/// given name, return types, argument types, attributes and
3636
/// a calling convention.
37-
llvm::Constant *getRuntimeFn(llvm::Module &Module,
38-
llvm::Constant *&cache,
39-
char const *name,
40-
llvm::CallingConv::ID cc,
41-
RuntimeAvailability availability,
42-
llvm::ArrayRef<llvm::Type*> retTypes,
43-
llvm::ArrayRef<llvm::Type*> argTypes,
44-
llvm::ArrayRef<llvm::Attribute::AttrKind> attrs);
37+
llvm::Constant *getRuntimeFn(llvm::Module &Module, llvm::Constant *&cache,
38+
char const *name, llvm::CallingConv::ID cc,
39+
RuntimeAvailability availability,
40+
llvm::ArrayRef<llvm::Type *> retTypes,
41+
llvm::ArrayRef<llvm::Type *> argTypes,
42+
llvm::ArrayRef<llvm::Attribute::AttrKind> attrs);
4543

46-
} /* Namespace swift */
44+
} // namespace swift
4745
#endif

include/swift/SIL/SILBridging.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ void Function_register(SwiftMetatype metatype,
173173
FunctionCopyEffectsFn copyEffectsFn,
174174
FunctionGetEffectFlagsFn hasEffectsFn);
175175

176+
SwiftInt PassContext_continueWithNextSubpassRun(BridgedPassContext passContext,
177+
OptionalBridgedInstruction inst);
176178
void PassContext_notifyChanges(BridgedPassContext passContext,
177179
enum ChangeNotificationKind changeKind);
178180
void PassContext_eraseInstruction(BridgedPassContext passContext,

include/swift/SIL/SILBridgingUtils.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ template <class I = SILInstruction> I *castToInst(BridgedInstruction inst) {
5858
return cast<I>(static_cast<SILNode *>(inst.obj)->castToInstruction());
5959
}
6060

61+
template <class I = SILInstruction> I *castToInst(OptionalBridgedInstruction inst) {
62+
if (!inst.obj)
63+
return nullptr;
64+
return cast<I>(static_cast<SILNode *>(inst.obj)->castToInstruction());
65+
}
66+
6167
inline SILBasicBlock *castToBasicBlock(BridgedBasicBlock block) {
6268
return static_cast<SILBasicBlock *>(block.obj);
6369
}

include/swift/SILOptimizer/PassManager/PassManager.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ class SwiftPassInvocation {
5050
/// Backlink to the pass manager.
5151
SILPassManager *passManager;
5252

53+
/// The current transform.
54+
SILTransform *transform = nullptr;
55+
5356
/// The currently optimized function.
5457
SILFunction *function = nullptr;
5558

@@ -76,6 +79,8 @@ class SwiftPassInvocation {
7679
passManager(passManager) {}
7780

7881
SILPassManager *getPassManager() const { return passManager; }
82+
83+
SILTransform *getTransform() const { return transform; }
7984

8085
SILFunction *getFunction() const { return function; }
8186

@@ -94,7 +99,7 @@ class SwiftPassInvocation {
9499
void notifyChanges(SILAnalysis::InvalidationKind invalidationKind);
95100

96101
/// Called by the pass manager before the pass starts running.
97-
void startFunctionPassRun(SILFunction *function);
102+
void startFunctionPassRun(SILFunctionTransform *transform);
98103

99104
/// Called by the SILCombiner before the instruction pass starts running.
100105
void startInstructionPassRun(SILInstruction *inst);

lib/IDE/ModuleInterfacePrinting.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -625,9 +625,7 @@ void swift::ide::printModuleInterface(
625625
return true;
626626
if (ImportedMod == TargetClangMod)
627627
return false;
628-
// FIXME: const-ness on the clang API.
629-
return ImportedMod->isSubModuleOf(
630-
const_cast<clang::Module*>(TargetClangMod));
628+
return ImportedMod->isSubModuleOf(TargetClangMod);
631629
};
632630

633631
if (auto ID = dyn_cast<ImportDecl>(D)) {

lib/SILOptimizer/PassManager/PassManager.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ void SILPassManager::runPassOnFunction(unsigned TransIdx, SILFunction *F) {
530530
assert(changeNotifications == SILAnalysis::InvalidationKind::Nothing
531531
&& "change notifications not cleared");
532532

533-
swiftPassInvocation.startFunctionPassRun(F);
533+
swiftPassInvocation.startFunctionPassRun(SFT);
534534

535535
// Run it!
536536
SFT->run();
@@ -1209,9 +1209,10 @@ void SwiftPassInvocation::freeBlockSet(BasicBlockSet *set) {
12091209
}
12101210
}
12111211

1212-
void SwiftPassInvocation::startFunctionPassRun(SILFunction *function) {
1213-
assert(!this->function && "a pass is already running");
1214-
this->function = function;
1212+
void SwiftPassInvocation::startFunctionPassRun(SILFunctionTransform *transform) {
1213+
assert(!this->function && !this->transform && "a pass is already running");
1214+
this->function = transform->getFunction();
1215+
this->transform = transform;
12151216
}
12161217

12171218
void SwiftPassInvocation::startInstructionPassRun(SILInstruction *inst) {
@@ -1221,8 +1222,9 @@ void SwiftPassInvocation::startInstructionPassRun(SILInstruction *inst) {
12211222

12221223
void SwiftPassInvocation::finishedFunctionPassRun() {
12231224
endPassRunChecks();
1224-
assert(function && "not running a pass");
1225+
assert(function && transform && "not running a pass");
12251226
function = nullptr;
1227+
transform = nullptr;
12261228
}
12271229

12281230
void SwiftPassInvocation::finishedInstructionPassRun() {
@@ -1282,6 +1284,14 @@ BridgedSlab PassContext_freeSlab(BridgedPassContext passContext,
12821284
return toBridgedSlab(inv->freeSlab(castToSlab(slab)));
12831285
}
12841286

1287+
SwiftInt PassContext_continueWithNextSubpassRun(BridgedPassContext passContext,
1288+
OptionalBridgedInstruction inst) {
1289+
SwiftPassInvocation *inv = castToPassInvocation(passContext);
1290+
SILInstruction *i = castToInst(inst);
1291+
return inv->getPassManager()->continueWithNextSubpassRun(i,
1292+
inv->getFunction(), inv->getTransform()) ? 1: 0;
1293+
}
1294+
12851295
void PassContext_notifyChanges(BridgedPassContext passContext,
12861296
enum ChangeNotificationKind changeKind) {
12871297
SwiftPassInvocation *inv = castToPassInvocation(passContext);

0 commit comments

Comments
 (0)