Skip to content

Commit 5f162eb

Browse files
committed
[SIL] NFC: Shrink SILGlobalVariable by 16 bytes
1 parent 0838a65 commit 5f162eb

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

include/swift/SIL/SILGlobalVariable.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class SILGlobalVariable
5353

5454
/// The SIL location of the variable, which provides a link back to the AST.
5555
/// The variable only gets a location after it's been emitted.
56-
Optional<SILLocation> Location;
56+
const SILLocation Location;
5757

5858
/// The linkage of the global variable.
5959
unsigned Linkage : NumSILLinkageBits;
@@ -67,13 +67,16 @@ class SILGlobalVariable
6767
/// once (either in its declaration, or once later), making it immutable.
6868
unsigned IsLet : 1;
6969

70+
/// Whether or not this is a declaration.
71+
unsigned IsDeclaration : 1;
72+
73+
/// Whether or not there is a valid SILLocation.
74+
unsigned HasLocation : 1;
75+
7076
/// The VarDecl associated with this SILGlobalVariable. Must by nonnull for
7177
/// language-level global variables.
7278
VarDecl *VDecl;
7379

74-
/// Whether or not this is a declaration.
75-
bool IsDeclaration;
76-
7780
/// If this block is not empty, the global variable has a static initializer.
7881
///
7982
/// The last instruction of this block is the top-level value of the static
@@ -132,20 +135,17 @@ class SILGlobalVariable
132135

133136
VarDecl *getDecl() const { return VDecl; }
134137

135-
/// Initialize the source location of the function.
136-
void setLocation(SILLocation L) { Location = L; }
137-
138138
/// Check if the function has a location.
139139
/// FIXME: All functions should have locations, so this method should not be
140140
/// necessary.
141141
bool hasLocation() const {
142-
return Location.hasValue();
142+
return HasLocation;
143143
}
144144

145145
/// Get the source location of the function.
146146
SILLocation getLocation() const {
147-
assert(Location.hasValue());
148-
return Location.getValue();
147+
assert(HasLocation);
148+
return Location;
149149
}
150150

151151
/// Returns the value of the static initializer or null if the global has no

include/swift/SIL/SILLocation.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,8 @@ class SILLocation {
273273
assert(isASTNode());
274274
}
275275

276+
static SILLocation invalid() { return SILLocation(); }
277+
276278
/// Check if the location wraps an AST node or a valid SIL file
277279
/// location.
278280
///

lib/SIL/IR/SILGlobalVariable.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,9 @@ SILGlobalVariable::SILGlobalVariable(SILModule &Module, SILLinkage Linkage,
4848
: Module(Module),
4949
Name(Name),
5050
LoweredType(LoweredType),
51-
Location(Loc),
51+
Location(Loc.getValueOr(SILLocation::invalid())),
5252
Linkage(unsigned(Linkage)),
53+
HasLocation(Loc.hasValue()),
5354
VDecl(Decl) {
5455
setSerialized(isSerialized);
5556
IsDeclaration = isAvailableExternally(Linkage);

0 commit comments

Comments
 (0)