Skip to content

Commit 268309e

Browse files
committed
Add a function index
This radically simplifies the representation of function sets when analyzing the entire module's call graph at once.
1 parent 8c21aaf commit 268309e

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

include/swift/SIL/SILFunction.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,10 @@ class SILFunction
224224
/// For details see BasicBlockBitfield::bitfieldID;
225225
unsigned currentBitfieldID = 1;
226226

227+
/// Unique identifier for vector indexing and deterministic sorting.
228+
/// May be reused when zombie functions are recovered.
229+
unsigned index;
230+
227231
/// The function's set of semantics attributes.
228232
///
229233
/// TODO: Why is this using a std::string? Why don't we use uniqued
@@ -446,6 +450,8 @@ class SILFunction
446450
return SILFunctionConventions(fnType, getModule());
447451
}
448452

453+
unsigned getIndex() const { return index; }
454+
449455
SILProfiler *getProfiler() const { return Profiler; }
450456

451457
SILFunction *getDynamicallyReplacedFunction() const {

include/swift/SIL/SILModule.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,10 @@ class SILModule {
345345
/// The options passed into this SILModule.
346346
const SILOptions &Options;
347347

348+
/// The number of functions created in this module, which will be the index of
349+
/// the next function.
350+
unsigned nextFunctionIndex = 0;
351+
348352
/// Set if the SILModule was serialized already. It is used
349353
/// to ensure that the module is serialized only once.
350354
bool serialized;
@@ -449,6 +453,12 @@ class SILModule {
449453
/// Called after an instruction is moved from one function to another.
450454
void notifyMovedInstruction(SILInstruction *inst, SILFunction *fromFunction);
451455

456+
unsigned getNewFunctionIndex() { return nextFunctionIndex++; }
457+
458+
// This may be larger that the number of live functions in the 'functions'
459+
// linked list because it includes the indices of zombie functions.
460+
unsigned getNumFunctionIndices() const { return nextFunctionIndex; }
461+
452462
/// Set a serialization action.
453463
void setSerializeSILAction(ActionCallback SerializeSILAction);
454464
ActionCallback getSerializeSILAction() const;

lib/SIL/IR/SILFunction.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,9 @@ SILFunction::SILFunction(SILModule &Module, SILLinkage Linkage, StringRef Name,
150150
IsDynamicallyReplaceable_t isDynamic,
151151
IsExactSelfClass_t isExactSelfClass,
152152
IsDistributed_t isDistributed)
153-
: SwiftObjectHeader(functionMetatype),
154-
Module(Module), Availability(AvailabilityContext::alwaysAvailable()) {
153+
: SwiftObjectHeader(functionMetatype), Module(Module),
154+
index(Module.getNewFunctionIndex()),
155+
Availability(AvailabilityContext::alwaysAvailable()) {
155156
init(Linkage, Name, LoweredType, genericEnv, Loc, isBareSILFunction, isTrans,
156157
isSerialized, entryCount, isThunk, classSubclassScope, inlineStrategy,
157158
E, DebugScope, isDynamic, isExactSelfClass, isDistributed);

0 commit comments

Comments
 (0)