Skip to content

Commit ca291fb

Browse files
committed
SIL: store IRGenOptions in SILModule
SIL optimization passes can use the IRGen options to do target specific optimizations.
1 parent 05dcba1 commit ca291fb

File tree

7 files changed

+46
-20
lines changed

7 files changed

+46
-20
lines changed

include/swift/AST/SILGenRequests.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class LangOptions;
2929
class ModuleDecl;
3030
class SILModule;
3131
class SILOptions;
32+
class IRGenOptions;
3233

3334
namespace Lowering {
3435
class TypeConverter;
@@ -47,6 +48,7 @@ struct ASTLoweringDescriptor {
4748
llvm::PointerUnion<FileUnit *, ModuleDecl *> context;
4849
Lowering::TypeConverter &conv;
4950
const SILOptions &opts;
51+
const IRGenOptions *irgenOptions;
5052

5153
/// A specific set of SILDeclRefs to emit. If set, only these refs will be
5254
/// emitted. Otherwise the entire \c context will be emitted.
@@ -74,15 +76,17 @@ struct ASTLoweringDescriptor {
7476
public:
7577
static ASTLoweringDescriptor
7678
forFile(FileUnit &sf, Lowering::TypeConverter &conv, const SILOptions &opts,
77-
Optional<SILRefsToEmit> refsToEmit = None) {
78-
return ASTLoweringDescriptor{&sf, conv, opts, refsToEmit};
79+
Optional<SILRefsToEmit> refsToEmit = None,
80+
const IRGenOptions *irgenOptions = nullptr) {
81+
return ASTLoweringDescriptor{&sf, conv, opts, irgenOptions, refsToEmit};
7982
}
8083

8184
static ASTLoweringDescriptor
8285
forWholeModule(ModuleDecl *mod, Lowering::TypeConverter &conv,
8386
const SILOptions &opts,
84-
Optional<SILRefsToEmit> refsToEmit = None) {
85-
return ASTLoweringDescriptor{mod, conv, opts, refsToEmit};
87+
Optional<SILRefsToEmit> refsToEmit = None,
88+
const IRGenOptions *irgenOptions = nullptr) {
89+
return ASTLoweringDescriptor{mod, conv, opts, irgenOptions, refsToEmit};
8690
}
8791

8892
/// Retrieves the files to generate SIL for. If the descriptor is configured

include/swift/SIL/SILModule.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ class AnyFunctionType;
103103
class ASTContext;
104104
class FileUnit;
105105
class FuncDecl;
106+
class IRGenOptions;
106107
class KeyPathPattern;
107108
class ModuleDecl;
108109
class SILUndef;
@@ -353,6 +354,12 @@ class SILModule {
353354
/// The options passed into this SILModule.
354355
const SILOptions &Options;
355356

357+
/// IRGen options to be used by target specific SIL optimization passes.
358+
///
359+
/// Not null, if the module is created by the compiler itself (and not
360+
/// e.g. by lldb).
361+
const IRGenOptions *irgenOptions;
362+
356363
/// The number of functions created in this module, which will be the index of
357364
/// the next function.
358365
unsigned nextFunctionIndex = 0;
@@ -382,7 +389,8 @@ class SILModule {
382389
#endif
383390

384391
SILModule(llvm::PointerUnion<FileUnit *, ModuleDecl *> context,
385-
Lowering::TypeConverter &TC, const SILOptions &Options);
392+
Lowering::TypeConverter &TC, const SILOptions &Options,
393+
const IRGenOptions *irgenOptions = nullptr);
386394

387395
SILModule(const SILModule&) = delete;
388396
void operator=(const SILModule&) = delete;
@@ -537,7 +545,8 @@ class SILModule {
537545
/// single-file mode, and a ModuleDecl in whole-module mode.
538546
static std::unique_ptr<SILModule>
539547
createEmptyModule(llvm::PointerUnion<FileUnit *, ModuleDecl *> context,
540-
Lowering::TypeConverter &TC, const SILOptions &Options);
548+
Lowering::TypeConverter &TC, const SILOptions &Options,
549+
const IRGenOptions *irgenOptions = nullptr);
541550

542551
/// Get the Swift module associated with this SIL module.
543552
ModuleDecl *getSwiftModule() const { return TheSwiftModule; }
@@ -570,6 +579,7 @@ class SILModule {
570579
bool isOptimizedOnoneSupportModule() const;
571580

572581
const SILOptions &getOptions() const { return Options; }
582+
const IRGenOptions *getIRGenOptionsOrNull() const { return irgenOptions; }
573583

574584
using iterator = FunctionListType::iterator;
575585
using const_iterator = FunctionListType::const_iterator;

include/swift/Subsystems.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,14 @@ namespace swift {
179179
/// SIL of all files in the module is present in the SILModule.
180180
std::unique_ptr<SILModule>
181181
performASTLowering(ModuleDecl *M, Lowering::TypeConverter &TC,
182-
const SILOptions &options);
182+
const SILOptions &options,
183+
const IRGenOptions *irgenOptions = nullptr);
183184

184185
/// Turn a source file into SIL IR.
185186
std::unique_ptr<SILModule>
186187
performASTLowering(FileUnit &SF, Lowering::TypeConverter &TC,
187-
const SILOptions &options);
188+
const SILOptions &options,
189+
const IRGenOptions *irgenOptions = nullptr);
188190

189191
using ModuleOrSourceFile = PointerUnion<ModuleDecl *, SourceFile *>;
190192

lib/FrontendTool/FrontendTool.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,9 @@ bool swift::performCompileStepsPostSema(CompilerInstance &Instance,
766766
const PrimarySpecificPaths PSPs =
767767
Instance.getPrimarySpecificPathsForWholeModuleOptimizationMode();
768768
SILOptions SILOpts = getSILOptions(PSPs);
769-
auto SM = performASTLowering(mod, Instance.getSILTypes(), SILOpts);
769+
IRGenOptions irgenOpts = Invocation.getIRGenOptions();
770+
auto SM = performASTLowering(mod, Instance.getSILTypes(), SILOpts,
771+
&irgenOpts);
770772
return performCompileStepsPostSILGen(Instance, std::move(SM), mod, PSPs,
771773
ReturnValue, observer);
772774
}
@@ -779,8 +781,9 @@ bool swift::performCompileStepsPostSema(CompilerInstance &Instance,
779781
const PrimarySpecificPaths PSPs =
780782
Instance.getPrimarySpecificPathsForSourceFile(*PrimaryFile);
781783
SILOptions SILOpts = getSILOptions(PSPs);
784+
IRGenOptions irgenOpts = Invocation.getIRGenOptions();
782785
auto SM = performASTLowering(*PrimaryFile, Instance.getSILTypes(),
783-
SILOpts);
786+
SILOpts, &irgenOpts);
784787
result |= performCompileStepsPostSILGen(Instance, std::move(SM),
785788
PrimaryFile, PSPs, ReturnValue,
786789
observer);

lib/IRGen/IRGen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1059,7 +1059,7 @@ GeneratedModule IRGenRequest::evaluate(Evaluator &evaluator,
10591059
auto SILMod = std::unique_ptr<SILModule>(desc.SILMod);
10601060
if (!SILMod) {
10611061
auto loweringDesc = ASTLoweringDescriptor{
1062-
desc.Ctx, desc.Conv, desc.SILOpts,
1062+
desc.Ctx, desc.Conv, desc.SILOpts, nullptr,
10631063
symsToEmit.map([](const auto &x) { return x.silRefsToEmit; })};
10641064
SILMod = llvm::cantFail(Ctx.evaluator(LoweredSILRequest{loweringDesc}));
10651065

lib/SIL/IR/SILModule.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,11 @@ class SILModule::SerializationCallback final
9090
};
9191

9292
SILModule::SILModule(llvm::PointerUnion<FileUnit *, ModuleDecl *> context,
93-
Lowering::TypeConverter &TC, const SILOptions &Options)
93+
Lowering::TypeConverter &TC, const SILOptions &Options,
94+
const IRGenOptions *irgenOptions)
9495
: Stage(SILStage::Raw), loweredAddresses(!Options.EnableSILOpaqueValues),
95-
indexTrieRoot(new IndexTrieNode()), Options(Options), serialized(false),
96+
indexTrieRoot(new IndexTrieNode()), Options(Options),
97+
irgenOptions(irgenOptions), serialized(false),
9698
regDeserializationNotificationHandlerForNonTransparentFuncOME(false),
9799
regDeserializationNotificationHandlerForAllFuncOME(false),
98100
prespecializedFunctionDeclsImported(false), SerializeSILAction(),
@@ -203,8 +205,10 @@ void SILModule::checkForLeaksAfterDestruction() {
203205

204206
std::unique_ptr<SILModule> SILModule::createEmptyModule(
205207
llvm::PointerUnion<FileUnit *, ModuleDecl *> context,
206-
Lowering::TypeConverter &TC, const SILOptions &Options) {
207-
return std::unique_ptr<SILModule>(new SILModule(context, TC, Options));
208+
Lowering::TypeConverter &TC, const SILOptions &Options,
209+
const IRGenOptions *irgenOptions) {
210+
return std::unique_ptr<SILModule>(new SILModule(context, TC, Options,
211+
irgenOptions));
208212
}
209213

210214
ASTContext &SILModule::getASTContext() const {

lib/SILGen/SILGen.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2243,7 +2243,7 @@ ASTLoweringRequest::evaluate(Evaluator &evaluator,
22432243
SILInstruction::resetInstructionCounts();
22442244

22452245
auto silMod = SILModule::createEmptyModule(desc.context, desc.conv,
2246-
desc.opts);
2246+
desc.opts, desc.irgenOptions);
22472247

22482248
// If all function bodies are being skipped there's no reason to do any
22492249
// SIL generation.
@@ -2285,15 +2285,18 @@ ASTLoweringRequest::evaluate(Evaluator &evaluator,
22852285

22862286
std::unique_ptr<SILModule>
22872287
swift::performASTLowering(ModuleDecl *mod, Lowering::TypeConverter &tc,
2288-
const SILOptions &options) {
2289-
auto desc = ASTLoweringDescriptor::forWholeModule(mod, tc, options);
2288+
const SILOptions &options,
2289+
const IRGenOptions *irgenOptions) {
2290+
auto desc = ASTLoweringDescriptor::forWholeModule(mod, tc, options,
2291+
None, irgenOptions);
22902292
return llvm::cantFail(
22912293
mod->getASTContext().evaluator(ASTLoweringRequest{desc}));
22922294
}
22932295

22942296
std::unique_ptr<SILModule>
22952297
swift::performASTLowering(FileUnit &sf, Lowering::TypeConverter &tc,
2296-
const SILOptions &options) {
2297-
auto desc = ASTLoweringDescriptor::forFile(sf, tc, options);
2298+
const SILOptions &options,
2299+
const IRGenOptions *irgenOptions) {
2300+
auto desc = ASTLoweringDescriptor::forFile(sf, tc, options, None, irgenOptions);
22982301
return llvm::cantFail(sf.getASTContext().evaluator(ASTLoweringRequest{desc}));
22992302
}

0 commit comments

Comments
 (0)