Skip to content

[SIL] NFC: Shrink SILGlobalVariable by 16 bytes #32135

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions include/swift/SIL/SILGlobalVariable.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class SILGlobalVariable

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

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

/// Whether or not this is a declaration.
unsigned IsDeclaration : 1;

/// Whether or not there is a valid SILLocation.
unsigned HasLocation : 1;

/// The VarDecl associated with this SILGlobalVariable. Must by nonnull for
/// language-level global variables.
VarDecl *VDecl;

/// Whether or not this is a declaration.
bool IsDeclaration;

/// If this block is not empty, the global variable has a static initializer.
///
/// The last instruction of this block is the top-level value of the static
Expand Down Expand Up @@ -132,20 +135,17 @@ class SILGlobalVariable

VarDecl *getDecl() const { return VDecl; }

/// Initialize the source location of the function.
void setLocation(SILLocation L) { Location = L; }

/// Check if the function has a location.
/// FIXME: All functions should have locations, so this method should not be
/// necessary.
bool hasLocation() const {
return Location.hasValue();
return HasLocation;
}

/// Get the source location of the function.
SILLocation getLocation() const {
assert(Location.hasValue());
return Location.getValue();
assert(HasLocation);
return Location;
}

/// Returns the value of the static initializer or null if the global has no
Expand Down
2 changes: 2 additions & 0 deletions include/swift/SIL/SILLocation.h
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,8 @@ class SILLocation {
assert(isASTNode());
}

static SILLocation invalid() { return SILLocation(); }

/// Check if the location wraps an AST node or a valid SIL file
/// location.
///
Expand Down
3 changes: 2 additions & 1 deletion lib/SIL/IR/SILGlobalVariable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ SILGlobalVariable::SILGlobalVariable(SILModule &Module, SILLinkage Linkage,
: Module(Module),
Name(Name),
LoweredType(LoweredType),
Location(Loc),
Location(Loc.getValueOr(SILLocation::invalid())),
Linkage(unsigned(Linkage)),
HasLocation(Loc.hasValue()),
VDecl(Decl) {
setSerialized(isSerialized);
IsDeclaration = isAvailableExternally(Linkage);
Expand Down