Skip to content

Commit 542a378

Browse files
committed
SIL: add FunctionRefInst::getReferencedFunction()
If we know that we have a FunctionRefInst (and not another variant of FunctionRefBaseInst), we know that getting the referenced function will not be null (in contrast to FunctionRefBaseInst::getReferencedFunctionOrNull). NFC
1 parent ffeb1d5 commit 542a378

26 files changed

+41
-54
lines changed

include/swift/SIL/SILCloner.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -967,7 +967,7 @@ template<typename ImplClass>
967967
void
968968
SILCloner<ImplClass>::visitFunctionRefInst(FunctionRefInst *Inst) {
969969
SILFunction *OpFunction =
970-
getOpFunction(Inst->getInitiallyReferencedFunction());
970+
getOpFunction(Inst->getReferencedFunction());
971971
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
972972
recordClonedInstruction(Inst, getBuilder().createFunctionRef(
973973
getOpLocation(Inst->getLoc()), OpFunction));

include/swift/SIL/SILInstruction.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2756,9 +2756,9 @@ class LiteralInst : public SingleValueInstruction {
27562756
};
27572757

27582758
class FunctionRefBaseInst : public LiteralInst {
2759+
protected:
27592760
SILFunction *f;
27602761

2761-
protected:
27622762
FunctionRefBaseInst(SILInstructionKind Kind, SILDebugLocation DebugLoc,
27632763
SILFunction *F, TypeExpansionContext context);
27642764

@@ -2819,6 +2819,9 @@ class FunctionRefInst : public FunctionRefBaseInst {
28192819
TypeExpansionContext context);
28202820

28212821
public:
2822+
/// Return the referenced function.
2823+
SILFunction *getReferencedFunction() const { return f; }
2824+
28222825
static bool classof(SILNodePointer node) {
28232826
return node->getKind() == SILNodeKind::FunctionRefInst;
28242827
}

include/swift/SIL/TypeSubstCloner.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class TypeSubstCloner : public SILClonerWithScopes<ImplClass> {
6969

7070
if (!Cloner.Inlining) {
7171
FunctionRefInst *FRI = dyn_cast<FunctionRefInst>(AI.getCallee());
72-
if (FRI && FRI->getInitiallyReferencedFunction() == AI.getFunction() &&
72+
if (FRI && FRI->getReferencedFunction() == AI.getFunction() &&
7373
Subs == Cloner.SubsMap) {
7474
// Handle recursions by replacing the apply to the callee with an
7575
// apply to the newly specialized function, but only if substitutions

lib/SIL/IR/Linker.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ void SILLinkerVisitor::visitPartialApplyInst(PartialApplyInst *PAI) {
175175
}
176176

177177
void SILLinkerVisitor::visitFunctionRefInst(FunctionRefInst *FRI) {
178-
maybeAddFunctionToWorklist(FRI->getInitiallyReferencedFunction());
178+
maybeAddFunctionToWorklist(FRI->getReferencedFunction());
179179
}
180180

181181
void SILLinkerVisitor::visitDynamicFunctionRefInst(

lib/SIL/IR/SILGlobalVariable.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ SILFunction *swift::getCalleeOfOnceCall(BuiltinInst *BI) {
241241
"Expected C function representation!");
242242

243243
if (auto *FR = dyn_cast<FunctionRefInst>(Callee))
244-
return FR->getReferencedFunctionOrNull();
244+
return FR->getReferencedFunction();
245245

246246
return nullptr;
247247
}

lib/SIL/IR/SILInstruction.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -475,8 +475,7 @@ namespace {
475475

476476
bool visitFunctionRefInst(const FunctionRefInst *RHS) {
477477
auto *X = cast<FunctionRefInst>(LHS);
478-
return X->getInitiallyReferencedFunction() ==
479-
RHS->getInitiallyReferencedFunction();
478+
return X->getReferencedFunction() == RHS->getReferencedFunction();
480479
}
481480
bool visitDynamicFunctionRefInst(const DynamicFunctionRefInst *RHS) {
482481
auto *X = cast<DynamicFunctionRefInst>(LHS);

lib/SIL/IR/SILPrinter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -957,7 +957,7 @@ class SILPrinter : public SILInstructionVisitor<SILPrinter> {
957957
void print(const SILInstruction *I) {
958958
if (auto *FRI = dyn_cast<FunctionRefInst>(I))
959959
*this << " // function_ref "
960-
<< demangleSymbol(FRI->getInitiallyReferencedFunction()->getName())
960+
<< demangleSymbol(FRI->getReferencedFunction()->getName())
961961
<< "\n";
962962
else if (auto *FRI = dyn_cast<DynamicFunctionRefInst>(I))
963963
*this << " // dynamic_function_ref "
@@ -1270,7 +1270,7 @@ class SILPrinter : public SILInstructionVisitor<SILPrinter> {
12701270
}
12711271

12721272
void visitFunctionRefInst(FunctionRefInst *FRI) {
1273-
FRI->getInitiallyReferencedFunction()->printName(PrintState.OS);
1273+
FRI->getReferencedFunction()->printName(PrintState.OS);
12741274
*this << " : " << FRI->getType();
12751275
}
12761276
void visitDynamicFunctionRefInst(DynamicFunctionRefInst *FRI) {

lib/SILOptimizer/Analysis/ArraySemantic.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ ArrayCallKind swift::getArraySemanticsKind(SILFunction *f) {
6666
static ParameterConvention
6767
getSelfParameterConvention(ApplyInst *SemanticsCall) {
6868
FunctionRefInst *FRI = cast<FunctionRefInst>(SemanticsCall->getCallee());
69-
SILFunction *F = FRI->getInitiallyReferencedFunction();
69+
SILFunction *F = FRI->getReferencedFunction();
7070
auto FnTy = F->getLoweredFunctionType();
7171

7272
return FnTy->getSelfParameter().getConvention();
@@ -78,7 +78,7 @@ bool swift::ArraySemanticsCall::isValidSignature() {
7878
assert(SemanticsCall && getKind() != ArrayCallKind::kNone &&
7979
"Need an array semantic call");
8080
FunctionRefInst *FRI = cast<FunctionRefInst>(SemanticsCall->getCallee());
81-
SILFunction *F = FRI->getInitiallyReferencedFunction();
81+
SILFunction *F = FRI->getReferencedFunction();
8282
auto FnTy = F->getLoweredFunctionType();
8383
auto &Mod = F->getModule();
8484

@@ -203,7 +203,7 @@ ArrayCallKind swift::ArraySemanticsCall::getKind() const {
203203
return ArrayCallKind::kNone;
204204

205205
auto F = cast<FunctionRefInst>(SemanticsCall->getCallee())
206-
->getInitiallyReferencedFunction();
206+
->getReferencedFunction();
207207

208208
return getArraySemanticsKind(F);
209209
}

lib/SILOptimizer/Analysis/BasicCalleeAnalysis.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ CalleeList CalleeCache::getCalleeListForCalleeKind(SILValue Callee) const {
256256

257257
case ValueKind::FunctionRefInst:
258258
return CalleeList(
259-
cast<FunctionRefInst>(Callee)->getInitiallyReferencedFunction());
259+
cast<FunctionRefInst>(Callee)->getReferencedFunction());
260260

261261
case ValueKind::DynamicFunctionRefInst:
262262
case ValueKind::PreviousDynamicFunctionRefInst:

lib/SILOptimizer/Analysis/DifferentiableActivityAnalysis.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ using namespace swift::autodiff;
2929

3030
static bool isWithoutDerivative(SILValue v) {
3131
if (auto *fnRef = dyn_cast<FunctionRefInst>(v))
32-
return fnRef->getReferencedFunctionOrNull()->hasSemanticsAttr(
32+
return fnRef->getReferencedFunction()->hasSemanticsAttr(
3333
"autodiff.nonvarying");
3434
return false;
3535
}

0 commit comments

Comments
 (0)