Skip to content

Commit b6cff0b

Browse files
Gwen Mittertreinergmittert
authored andcommitted
Add a Flag to Force Type Layouts for Structs
Added ForceStructTypeLayouts. When enabled, IRGen will lower structs using the aligned group of TypeLayout rather than using TypeInfos. This potentially leads to a size increase as TypeInfos currently produce better code than the TypeLayout route.
1 parent 942b0e8 commit b6cff0b

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

include/swift/AST/IRGenOptions.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,10 @@ class IRGenOptions {
335335
/// vw functions instead of outlined copy/destroy functions.
336336
unsigned UseTypeLayoutValueHandling : 1;
337337

338+
/// Also force structs to be lowered to aligned group TypeLayouts rather than
339+
/// using TypeInfo entries.
340+
unsigned ForceStructTypeLayouts : 1;
341+
338342
/// Instrument code to generate profiling information.
339343
unsigned GenerateProfile : 1;
340344

@@ -413,7 +417,7 @@ class IRGenOptions {
413417
ForcePublicLinkage(false), LazyInitializeClassMetadata(false),
414418
LazyInitializeProtocolConformances(false), DisableLegacyTypeInfo(false),
415419
PrespecializeGenericMetadata(false), UseIncrementalLLVMCodeGen(true),
416-
UseTypeLayoutValueHandling(true),
420+
UseTypeLayoutValueHandling(true), ForceStructTypeLayouts(false),
417421
GenerateProfile(false), EnableDynamicReplacementChaining(false),
418422
DisableRoundTripDebugTypes(false), DisableDebuggerShadowCopies(false),
419423
DisableConcreteTypeMetadataMangledNameAccessors(false),

include/swift/Option/FrontendOptions.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,9 @@ def enable_type_layouts : Flag<["-"], "enable-type-layout">,
830830
def disable_type_layouts : Flag<["-"], "disable-type-layout">,
831831
HelpText<"Disable type layout based lowering">;
832832

833+
def force_struct_type_layouts : Flag<["-"], "force-struct-type-layouts">,
834+
HelpText<"Force type layout based lowering for structs">;
835+
833836
def disable_interface_lockfile : Flag<["-"], "disable-interface-lock">,
834837
HelpText<"Don't lock interface file when building module">;
835838

lib/Frontend/CompilerInvocation.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1724,6 +1724,9 @@ static bool ParseIRGenArgs(IRGenOptions &Opts, ArgList &Args,
17241724
Opts.UseTypeLayoutValueHandling = false;
17251725
}
17261726

1727+
Opts.ForceStructTypeLayouts = Args.hasArg(OPT_force_struct_type_layouts) &&
1728+
Opts.UseTypeLayoutValueHandling;
1729+
17271730
// This is set to true by default.
17281731
Opts.UseIncrementalLLVMCodeGen &=
17291732
!Args.hasArg(OPT_disable_incremental_llvm_codegeneration);

0 commit comments

Comments
 (0)