File tree Expand file tree Collapse file tree 3 files changed +29
-0
lines changed
SwiftCompilerSources/Sources/Optimizer/PassManager
include/swift/SILOptimizer
lib/SILOptimizer/PassManager Expand file tree Collapse file tree 3 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -211,6 +211,16 @@ struct FunctionPassContext : MutatingContext {
211
211
return function. isDefinition
212
212
}
213
213
214
+ /// Looks up a function in the `Swift` module.
215
+ /// The `name` is the source name of the function and not the mangled name.
216
+ /// Returns nil if no such function or multiple matching functions are found.
217
+ func lookupStdlibFunction( name: StaticString ) -> Function ? {
218
+ return name. withUTF8Buffer { ( nameBuffer: UnsafeBufferPointer < UInt8 > ) in
219
+ let nameStr = llvm. StringRef ( nameBuffer. baseAddress, nameBuffer. count)
220
+ return _bridged. lookupStdlibFunction ( nameStr) . function
221
+ }
222
+ }
223
+
214
224
func erase( block: BasicBlock ) {
215
225
_bridged. eraseBlock ( block. bridged)
216
226
}
Original file line number Diff line number Diff line change @@ -425,6 +425,9 @@ struct BridgedPassContext {
425
425
: swift::SILModule::LinkingMode::LinkNormal);
426
426
}
427
427
428
+ SWIFT_IMPORT_UNSAFE
429
+ OptionalBridgedFunction lookupStdlibFunction (llvm::StringRef name) const ;
430
+
428
431
SWIFT_IMPORT_UNSAFE
429
432
swift::SubstitutionMap getContextSubstitutionMap (swift::SILType type) const {
430
433
auto *ntd = type.getASTType ()->getAnyNominal ();
Original file line number Diff line number Diff line change @@ -1525,6 +1525,22 @@ void BridgedPassContext::fixStackNesting(BridgedFunction function) const {
1525
1525
invocation->setNeedFixStackNesting (false );
1526
1526
}
1527
1527
1528
+ OptionalBridgedFunction BridgedPassContext::lookupStdlibFunction (llvm::StringRef name) const {
1529
+ swift::SILModule *mod = invocation->getPassManager ()->getModule ();
1530
+ SmallVector<ValueDecl *, 1 > results;
1531
+ mod->getASTContext ().lookupInSwiftModule (name, results);
1532
+ if (results.size () != 1 )
1533
+ return {nullptr };
1534
+
1535
+ auto *decl = dyn_cast<FuncDecl>(results.front ());
1536
+ if (!decl)
1537
+ return {nullptr };
1538
+
1539
+ SILDeclRef declRef (decl, SILDeclRef::Kind::Func);
1540
+ SILOptFunctionBuilder funcBuilder (*invocation->getTransform ());
1541
+ return {funcBuilder.getOrCreateFunction (SILLocation (decl), declRef, NotForDefinition)};
1542
+ }
1543
+
1528
1544
bool BridgedPassContext::enableSimplificationFor (BridgedInstruction inst) const {
1529
1545
// Fast-path check.
1530
1546
if (SimplifyInstructionTest.empty () && SILDisablePass.empty ())
You can’t perform that action at this time.
0 commit comments