Skip to content

Commit 2ff3b3c

Browse files
authored
Merge pull request swiftlang#35646 from eeckstein/shrink-sillocation
SIL: shrink SILLocation and some refactoring
2 parents 9faf023 + 65208c0 commit 2ff3b3c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+690
-869
lines changed

include/swift/SIL/PrettyStackTrace.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
#include "swift/SIL/SILLocation.h"
2222
#include "swift/SIL/SILNode.h"
23+
#include "llvm/ADT/SmallString.h"
24+
#include "llvm/ADT/Twine.h"
2325
#include "llvm/Support/PrettyStackTrace.h"
2426

2527
namespace swift {

include/swift/SIL/SILInstruction.h

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -323,13 +323,17 @@ class SILInstruction : public llvm::ilist_node<SILInstruction> {
323323

324324
/// A backreference to the containing basic block. This is maintained by
325325
/// ilist_traits<SILInstruction>.
326-
SILBasicBlock *ParentBB;
326+
SILBasicBlock *ParentBB = nullptr;
327327

328-
/// This instruction's containing lexical scope and source location
329-
/// used for debug info and diagnostics.
330-
SILDebugLocation Location;
328+
/// This instruction's containing lexical scope for debug info.
329+
const SILDebugScope *debugScope = nullptr;
330+
331+
/// This instructions source location for diagnostics and debug info.
332+
///
333+
/// To reduce space, this is only the storage of the SILLocation. The
334+
/// location's kindAndFlags is stored in the SILNode inline bitfields.
335+
SILLocation::Storage locationStorage;
331336

332-
SILInstruction() = delete;
333337
void operator=(const SILInstruction &) = delete;
334338
void operator delete(void *Ptr, size_t) = delete;
335339

@@ -360,8 +364,7 @@ class SILInstruction : public llvm::ilist_node<SILInstruction> {
360364
SILInstructionResultArray getResultsImpl() const;
361365

362366
protected:
363-
SILInstruction(SILDebugLocation DebugLoc) :
364-
ParentBB(nullptr), Location(DebugLoc) {
367+
SILInstruction() {
365368
NumCreatedInstructions++;
366369
}
367370

@@ -423,14 +426,25 @@ class SILInstruction : public llvm::ilist_node<SILInstruction> {
423426
SILModule &getModule() const;
424427

425428
/// This instruction's source location (AST node).
426-
SILLocation getLoc() const;
427-
const SILDebugScope *getDebugScope() const;
428-
SILDebugLocation getDebugLocation() const { return Location; }
429+
SILLocation getLoc() const {
430+
return SILLocation(locationStorage,
431+
asSILNode()->Bits.SILInstruction.LocationKindAndFlags);
432+
}
433+
const SILDebugScope *getDebugScope() const { return debugScope; }
434+
SILDebugLocation getDebugLocation() const {
435+
return SILDebugLocation(getLoc(), debugScope);
436+
}
429437

430438
/// Sets the debug location.
431439
/// Note: Usually it should not be needed to use this function as the location
432440
/// is already set in when creating an instruction.
433-
void setDebugLocation(SILDebugLocation Loc) { Location = Loc; }
441+
void setDebugLocation(SILDebugLocation debugLoc) {
442+
debugScope = debugLoc.getScope();
443+
SILLocation loc = debugLoc.getLocation();
444+
asSILNode()->Bits.SILInstruction.LocationKindAndFlags =
445+
loc.kindAndFlags.packedKindAndFlags;
446+
locationStorage = loc.storage;
447+
}
434448

435449
/// This method unlinks 'self' from the containing basic block and deletes it.
436450
void eraseFromParent();
@@ -758,7 +772,9 @@ class NonSingleValueInstruction : public SILInstruction, public SILNode {
758772
friend struct SILNodeOffsetChecker;
759773
public:
760774
NonSingleValueInstruction(SILInstructionKind kind, SILDebugLocation loc)
761-
: SILInstruction(loc), SILNode((SILNodeKind)kind) {}
775+
: SILInstruction(), SILNode((SILNodeKind)kind) {
776+
setDebugLocation(loc);
777+
}
762778

763779
using SILInstruction::operator new;
764780
using SILInstruction::dumpInContext;
@@ -929,8 +945,9 @@ class SingleValueInstruction : public SILInstruction, public ValueBase {
929945
public:
930946
SingleValueInstruction(SILInstructionKind kind, SILDebugLocation loc,
931947
SILType type)
932-
: SILInstruction(loc),
933-
ValueBase(ValueKind(kind), type) {}
948+
: SILInstruction(), ValueBase(ValueKind(kind), type) {
949+
setDebugLocation(loc);
950+
}
934951

935952
using SILInstruction::operator new;
936953
using SILInstruction::dumpInContext;

0 commit comments

Comments
 (0)