mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
SIL: store IRGenOptions in SILModule
SIL optimization passes can use the IRGen options to do target specific optimizations.
This commit is contained in:
@@ -29,6 +29,7 @@ class LangOptions;
|
||||
class ModuleDecl;
|
||||
class SILModule;
|
||||
class SILOptions;
|
||||
class IRGenOptions;
|
||||
|
||||
namespace Lowering {
|
||||
class TypeConverter;
|
||||
@@ -47,6 +48,7 @@ struct ASTLoweringDescriptor {
|
||||
llvm::PointerUnion<FileUnit *, ModuleDecl *> context;
|
||||
Lowering::TypeConverter &conv;
|
||||
const SILOptions &opts;
|
||||
const IRGenOptions *irgenOptions;
|
||||
|
||||
/// A specific set of SILDeclRefs to emit. If set, only these refs will be
|
||||
/// emitted. Otherwise the entire \c context will be emitted.
|
||||
@@ -74,15 +76,17 @@ struct ASTLoweringDescriptor {
|
||||
public:
|
||||
static ASTLoweringDescriptor
|
||||
forFile(FileUnit &sf, Lowering::TypeConverter &conv, const SILOptions &opts,
|
||||
Optional<SILRefsToEmit> refsToEmit = None) {
|
||||
return ASTLoweringDescriptor{&sf, conv, opts, refsToEmit};
|
||||
Optional<SILRefsToEmit> refsToEmit = None,
|
||||
const IRGenOptions *irgenOptions = nullptr) {
|
||||
return ASTLoweringDescriptor{&sf, conv, opts, irgenOptions, refsToEmit};
|
||||
}
|
||||
|
||||
static ASTLoweringDescriptor
|
||||
forWholeModule(ModuleDecl *mod, Lowering::TypeConverter &conv,
|
||||
const SILOptions &opts,
|
||||
Optional<SILRefsToEmit> refsToEmit = None) {
|
||||
return ASTLoweringDescriptor{mod, conv, opts, refsToEmit};
|
||||
Optional<SILRefsToEmit> refsToEmit = None,
|
||||
const IRGenOptions *irgenOptions = nullptr) {
|
||||
return ASTLoweringDescriptor{mod, conv, opts, irgenOptions, refsToEmit};
|
||||
}
|
||||
|
||||
/// Retrieves the files to generate SIL for. If the descriptor is configured
|
||||
|
||||
@@ -103,6 +103,7 @@ class AnyFunctionType;
|
||||
class ASTContext;
|
||||
class FileUnit;
|
||||
class FuncDecl;
|
||||
class IRGenOptions;
|
||||
class KeyPathPattern;
|
||||
class ModuleDecl;
|
||||
class SILUndef;
|
||||
@@ -353,6 +354,12 @@ private:
|
||||
/// The options passed into this SILModule.
|
||||
const SILOptions &Options;
|
||||
|
||||
/// IRGen options to be used by target specific SIL optimization passes.
|
||||
///
|
||||
/// Not null, if the module is created by the compiler itself (and not
|
||||
/// e.g. by lldb).
|
||||
const IRGenOptions *irgenOptions;
|
||||
|
||||
/// The number of functions created in this module, which will be the index of
|
||||
/// the next function.
|
||||
unsigned nextFunctionIndex = 0;
|
||||
@@ -382,7 +389,8 @@ private:
|
||||
#endif
|
||||
|
||||
SILModule(llvm::PointerUnion<FileUnit *, ModuleDecl *> context,
|
||||
Lowering::TypeConverter &TC, const SILOptions &Options);
|
||||
Lowering::TypeConverter &TC, const SILOptions &Options,
|
||||
const IRGenOptions *irgenOptions = nullptr);
|
||||
|
||||
SILModule(const SILModule&) = delete;
|
||||
void operator=(const SILModule&) = delete;
|
||||
@@ -537,7 +545,8 @@ public:
|
||||
/// single-file mode, and a ModuleDecl in whole-module mode.
|
||||
static std::unique_ptr<SILModule>
|
||||
createEmptyModule(llvm::PointerUnion<FileUnit *, ModuleDecl *> context,
|
||||
Lowering::TypeConverter &TC, const SILOptions &Options);
|
||||
Lowering::TypeConverter &TC, const SILOptions &Options,
|
||||
const IRGenOptions *irgenOptions = nullptr);
|
||||
|
||||
/// Get the Swift module associated with this SIL module.
|
||||
ModuleDecl *getSwiftModule() const { return TheSwiftModule; }
|
||||
@@ -570,6 +579,7 @@ public:
|
||||
bool isOptimizedOnoneSupportModule() const;
|
||||
|
||||
const SILOptions &getOptions() const { return Options; }
|
||||
const IRGenOptions *getIRGenOptionsOrNull() const { return irgenOptions; }
|
||||
|
||||
using iterator = FunctionListType::iterator;
|
||||
using const_iterator = FunctionListType::const_iterator;
|
||||
|
||||
@@ -179,12 +179,14 @@ namespace swift {
|
||||
/// SIL of all files in the module is present in the SILModule.
|
||||
std::unique_ptr<SILModule>
|
||||
performASTLowering(ModuleDecl *M, Lowering::TypeConverter &TC,
|
||||
const SILOptions &options);
|
||||
const SILOptions &options,
|
||||
const IRGenOptions *irgenOptions = nullptr);
|
||||
|
||||
/// Turn a source file into SIL IR.
|
||||
std::unique_ptr<SILModule>
|
||||
performASTLowering(FileUnit &SF, Lowering::TypeConverter &TC,
|
||||
const SILOptions &options);
|
||||
const SILOptions &options,
|
||||
const IRGenOptions *irgenOptions = nullptr);
|
||||
|
||||
using ModuleOrSourceFile = PointerUnion<ModuleDecl *, SourceFile *>;
|
||||
|
||||
|
||||
@@ -766,7 +766,9 @@ bool swift::performCompileStepsPostSema(CompilerInstance &Instance,
|
||||
const PrimarySpecificPaths PSPs =
|
||||
Instance.getPrimarySpecificPathsForWholeModuleOptimizationMode();
|
||||
SILOptions SILOpts = getSILOptions(PSPs);
|
||||
auto SM = performASTLowering(mod, Instance.getSILTypes(), SILOpts);
|
||||
IRGenOptions irgenOpts = Invocation.getIRGenOptions();
|
||||
auto SM = performASTLowering(mod, Instance.getSILTypes(), SILOpts,
|
||||
&irgenOpts);
|
||||
return performCompileStepsPostSILGen(Instance, std::move(SM), mod, PSPs,
|
||||
ReturnValue, observer);
|
||||
}
|
||||
@@ -779,8 +781,9 @@ bool swift::performCompileStepsPostSema(CompilerInstance &Instance,
|
||||
const PrimarySpecificPaths PSPs =
|
||||
Instance.getPrimarySpecificPathsForSourceFile(*PrimaryFile);
|
||||
SILOptions SILOpts = getSILOptions(PSPs);
|
||||
IRGenOptions irgenOpts = Invocation.getIRGenOptions();
|
||||
auto SM = performASTLowering(*PrimaryFile, Instance.getSILTypes(),
|
||||
SILOpts);
|
||||
SILOpts, &irgenOpts);
|
||||
result |= performCompileStepsPostSILGen(Instance, std::move(SM),
|
||||
PrimaryFile, PSPs, ReturnValue,
|
||||
observer);
|
||||
|
||||
@@ -1059,7 +1059,7 @@ GeneratedModule IRGenRequest::evaluate(Evaluator &evaluator,
|
||||
auto SILMod = std::unique_ptr<SILModule>(desc.SILMod);
|
||||
if (!SILMod) {
|
||||
auto loweringDesc = ASTLoweringDescriptor{
|
||||
desc.Ctx, desc.Conv, desc.SILOpts,
|
||||
desc.Ctx, desc.Conv, desc.SILOpts, nullptr,
|
||||
symsToEmit.map([](const auto &x) { return x.silRefsToEmit; })};
|
||||
SILMod = llvm::cantFail(Ctx.evaluator(LoweredSILRequest{loweringDesc}));
|
||||
|
||||
|
||||
@@ -90,9 +90,11 @@ class SILModule::SerializationCallback final
|
||||
};
|
||||
|
||||
SILModule::SILModule(llvm::PointerUnion<FileUnit *, ModuleDecl *> context,
|
||||
Lowering::TypeConverter &TC, const SILOptions &Options)
|
||||
Lowering::TypeConverter &TC, const SILOptions &Options,
|
||||
const IRGenOptions *irgenOptions)
|
||||
: Stage(SILStage::Raw), loweredAddresses(!Options.EnableSILOpaqueValues),
|
||||
indexTrieRoot(new IndexTrieNode()), Options(Options), serialized(false),
|
||||
indexTrieRoot(new IndexTrieNode()), Options(Options),
|
||||
irgenOptions(irgenOptions), serialized(false),
|
||||
regDeserializationNotificationHandlerForNonTransparentFuncOME(false),
|
||||
regDeserializationNotificationHandlerForAllFuncOME(false),
|
||||
prespecializedFunctionDeclsImported(false), SerializeSILAction(),
|
||||
@@ -203,8 +205,10 @@ void SILModule::checkForLeaksAfterDestruction() {
|
||||
|
||||
std::unique_ptr<SILModule> SILModule::createEmptyModule(
|
||||
llvm::PointerUnion<FileUnit *, ModuleDecl *> context,
|
||||
Lowering::TypeConverter &TC, const SILOptions &Options) {
|
||||
return std::unique_ptr<SILModule>(new SILModule(context, TC, Options));
|
||||
Lowering::TypeConverter &TC, const SILOptions &Options,
|
||||
const IRGenOptions *irgenOptions) {
|
||||
return std::unique_ptr<SILModule>(new SILModule(context, TC, Options,
|
||||
irgenOptions));
|
||||
}
|
||||
|
||||
ASTContext &SILModule::getASTContext() const {
|
||||
|
||||
@@ -2243,7 +2243,7 @@ ASTLoweringRequest::evaluate(Evaluator &evaluator,
|
||||
SILInstruction::resetInstructionCounts();
|
||||
|
||||
auto silMod = SILModule::createEmptyModule(desc.context, desc.conv,
|
||||
desc.opts);
|
||||
desc.opts, desc.irgenOptions);
|
||||
|
||||
// If all function bodies are being skipped there's no reason to do any
|
||||
// SIL generation.
|
||||
@@ -2285,15 +2285,18 @@ ASTLoweringRequest::evaluate(Evaluator &evaluator,
|
||||
|
||||
std::unique_ptr<SILModule>
|
||||
swift::performASTLowering(ModuleDecl *mod, Lowering::TypeConverter &tc,
|
||||
const SILOptions &options) {
|
||||
auto desc = ASTLoweringDescriptor::forWholeModule(mod, tc, options);
|
||||
const SILOptions &options,
|
||||
const IRGenOptions *irgenOptions) {
|
||||
auto desc = ASTLoweringDescriptor::forWholeModule(mod, tc, options,
|
||||
None, irgenOptions);
|
||||
return llvm::cantFail(
|
||||
mod->getASTContext().evaluator(ASTLoweringRequest{desc}));
|
||||
}
|
||||
|
||||
std::unique_ptr<SILModule>
|
||||
swift::performASTLowering(FileUnit &sf, Lowering::TypeConverter &tc,
|
||||
const SILOptions &options) {
|
||||
auto desc = ASTLoweringDescriptor::forFile(sf, tc, options);
|
||||
const SILOptions &options,
|
||||
const IRGenOptions *irgenOptions) {
|
||||
auto desc = ASTLoweringDescriptor::forFile(sf, tc, options, None, irgenOptions);
|
||||
return llvm::cantFail(sf.getASTContext().evaluator(ASTLoweringRequest{desc}));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user