Skip to content

Commit fd85e0e

Browse files
committed
SILLocation: remove unused flag bits.
PointsToStartBit: was never set. IsInTopLevel: was never checked (except for SIL printing)
1 parent 9faf023 commit fd85e0e

File tree

4 files changed

+12
-52
lines changed

4 files changed

+12
-52
lines changed

include/swift/SIL/SILLocation.h

Lines changed: 6 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -153,21 +153,12 @@ class SILLocation {
153153
/// code block.
154154
AutoGeneratedBit = 5,
155155

156-
/// Used to redefine the default source location used to
157-
/// represent this SILLocation. For example, when the host instruction
158-
/// is known to correspond to the beginning or the end of the source
159-
/// range of the ASTNode.
160-
PointsToStartBit = 6,
161-
PointsToEndBit = 7,
162-
163-
/// Used to notify that this instruction belongs to the top-
164-
/// level (module) scope.
165-
///
166-
/// FIXME: If Module becomes a Decl, this could be removed.
167-
IsInTopLevel = 8,
156+
/// The location correspond to the end (instead of the beginning) of the
157+
/// source range of the ASTNode.
158+
PointsToEndBit = 6,
168159

169160
/// Marks this instruction as belonging to the function prologue.
170-
IsInPrologue = 9
161+
IsInPrologue = 7
171162
};
172163

173164
template <typename T>
@@ -314,21 +305,10 @@ class SILLocation {
314305
return decodeDebugLoc(SM).Line == 0;
315306
}
316307

317-
/// Changes the default source location position to point to start of
318-
/// the AST node.
319-
void pointToStart() { KindData |= (1 << PointsToStartBit); }
320-
321308
/// Changes the default source location position to point to the end of
322309
/// the AST node.
323310
void pointToEnd() { KindData |= (1 << PointsToEndBit); }
324311

325-
/// Mark this location as the location corresponding to the top-level
326-
/// (module-level) code.
327-
void markAsInTopLevel() { KindData |= (1 << IsInTopLevel); }
328-
329-
/// Check is this location is associated with the top level/module.
330-
bool isInTopLevel() const { return KindData & (1 << IsInTopLevel); }
331-
332312
/// Mark this location as being part of the function
333313
/// prologue, which means that it deals with setting up the stack
334314
/// frame. The first breakpoint location in a function is at the end
@@ -360,10 +340,6 @@ class SILLocation {
360340
setStorageKind(DebugInfoKind);
361341
}
362342

363-
/// Check if the corresponding source code location definitely points
364-
/// to the start of the AST node.
365-
bool alwaysPointsToStart() const { return KindData & (1 << PointsToStartBit);}
366-
367343
/// Check if the corresponding source code location definitely points
368344
/// to the end of the AST node.
369345
bool alwaysPointsToEnd() const { return KindData & (1 << PointsToEndBit); }
@@ -507,11 +483,7 @@ class RegularLocation : public SILLocation {
507483
RegularLocation(DebugLoc L) : SILLocation(L, RegularKind) {}
508484

509485
/// Returns a location representing the module.
510-
static RegularLocation getModuleLocation() {
511-
RegularLocation Loc;
512-
Loc.markAsInTopLevel();
513-
return Loc;
514-
}
486+
static RegularLocation getModuleLocation() { return RegularLocation(); }
515487

516488
/// If the current value is of the specified AST unit type T,
517489
/// return it, otherwise return null.
@@ -717,9 +689,7 @@ class CleanupLocation : public SILLocation {
717689

718690
/// Returns a location representing a cleanup on the module level.
719691
static CleanupLocation getModuleCleanupLocation() {
720-
CleanupLocation Loc;
721-
Loc.markAsInTopLevel();
722-
return Loc;
692+
return CleanupLocation();
723693
}
724694

725695
private:

lib/SIL/IR/SILLocation.cpp

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "swift/AST/Expr.h"
1616
#include "swift/AST/Pattern.h"
1717
#include "swift/AST/Stmt.h"
18+
#include "swift/AST/Module.h"
1819
#include "swift/Basic/SourceManager.h"
1920
#include "llvm/Support/raw_ostream.h"
2021

@@ -40,8 +41,7 @@ SourceLoc SILLocation::getSourceLoc(ASTNodeTy N) const {
4041
if (N.isNull())
4142
return SourceLoc();
4243

43-
if (alwaysPointsToStart() ||
44-
alwaysPointsToEnd() ||
44+
if (alwaysPointsToEnd() ||
4545
is<CleanupLocation>() ||
4646
is<ImplicitReturnLocation>())
4747
return getEndSourceLoc(N);
@@ -158,9 +158,7 @@ void SILLocation::dump(const SourceManager &SM) const {
158158
print(llvm::errs(), SM);
159159

160160
if (isAutoGenerated()) llvm::errs() << ":auto";
161-
if (alwaysPointsToStart()) llvm::errs() << ":start";
162161
if (alwaysPointsToEnd()) llvm::errs() << ":end";
163-
if (isInTopLevel()) llvm::errs() << ":toplevel";
164162
if (isInPrologue()) llvm::errs() << ":prologue";
165163
if (isSILFile()) llvm::errs() << ":sil";
166164
if (hasDebugLoc()) {
@@ -189,9 +187,6 @@ InlinedLocation InlinedLocation::getInlinedLocation(SILLocation L) {
189187
if (L.isSILFile())
190188
return InlinedLocation(L.Loc.SILFileLoc, L.getSpecialFlags());
191189

192-
if (L.isInTopLevel())
193-
return InlinedLocation::getModuleLocation(L.getSpecialFlags());
194-
195190
if (L.isAutoGenerated()) {
196191
InlinedLocation IL;
197192
IL.markAutoGenerated();
@@ -214,9 +209,6 @@ MandatoryInlinedLocation::getMandatoryInlinedLocation(SILLocation L) {
214209
if (L.isSILFile())
215210
return MandatoryInlinedLocation(L.Loc.SILFileLoc, L.getSpecialFlags());
216211

217-
if (L.isInTopLevel())
218-
return MandatoryInlinedLocation::getModuleLocation(L.getSpecialFlags());
219-
220212
if (L.isDebugInfoLoc())
221213
return MandatoryInlinedLocation(L.getDebugInfoLoc(), L.getSpecialFlags());
222214

@@ -268,7 +260,7 @@ SILLocation ImplicitReturnLocation::getImplicitReturnLoc(SILLocation L) {
268260
assert(L.isASTNode<Expr>() ||
269261
L.isASTNode<ValueDecl>() ||
270262
L.isASTNode<PatternBindingDecl>() ||
271-
(L.isNull() && L.isInTopLevel()));
263+
L.isNull());
272264
L.setLocationKind(ImplicitReturnKind);
273265
return L;
274266
}

lib/SIL/IR/SILPrinter.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -921,9 +921,7 @@ class SILPrinter : public SILInstructionVisitor<SILPrinter> {
921921
PrintState.OS.PadToColumn(50);
922922
*this << "//";
923923
}
924-
if (L.isInTopLevel())
925-
*this << " top_level";
926-
else if (L.isAutoGenerated())
924+
if (L.isAutoGenerated())
927925
*this << " auto_gen";
928926
else
929927
*this << " no_loc";

test/SILGen/sil_locations_top_level.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ class TopLevelObjectTyWithoutDestructor {
1616
var topLevelObject2:TopLevelObjectTyWithoutDestructor
1717

1818
// CHECK-LABEL: sil [ossa] @main
19-
// CHECK: integer_literal ${{.*}}, 0, {{.*}} top_level
20-
// CHECK: return {{.*}} top_level
19+
// CHECK: integer_literal ${{.*}}, 0, {{.*}} auto_gen
20+
// CHECK: return {{.*}} auto_gen
2121

2222
// Check allocating initializer
2323
// CHECK-LABEL: sil_locations_top_level.TopLevelObjectTy.__allocating_init

0 commit comments

Comments
 (0)