Skip to content

Commit bf2ef39

Browse files
authored
[AutoDiff] NFC: make LinearFunctionExtractInst inherit UnaryInstructionBase. (#33418)
Remove ad-hoc operand list and operand getters.
1 parent f86b951 commit bf2ef39

File tree

8 files changed

+17
-24
lines changed

8 files changed

+17
-24
lines changed

include/swift/SIL/SILCloner.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2905,10 +2905,10 @@ template<typename ImplClass>
29052905
void SILCloner<ImplClass>::
29062906
visitLinearFunctionExtractInst(LinearFunctionExtractInst *Inst) {
29072907
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
2908-
recordClonedInstruction(
2909-
Inst, getBuilder().createLinearFunctionExtract(
2910-
getOpLocation(Inst->getLoc()), Inst->getExtractee(),
2911-
getOpValue(Inst->getFunctionOperand())));
2908+
recordClonedInstruction(Inst, getBuilder().createLinearFunctionExtract(
2909+
getOpLocation(Inst->getLoc()),
2910+
Inst->getExtractee(),
2911+
getOpValue(Inst->getOperand())));
29122912
}
29132913

29142914
template <typename ImplClass>

include/swift/SIL/SILInstruction.h

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8364,14 +8364,11 @@ class DifferentiableFunctionExtractInst
83648364
/// representing a bundle of the original function and the transpose function,
83658365
/// extract the specified function.
83668366
class LinearFunctionExtractInst
8367-
: public InstructionBase<
8368-
SILInstructionKind::LinearFunctionExtractInst,
8369-
SingleValueInstruction> {
8367+
: public UnaryInstructionBase<SILInstructionKind::LinearFunctionExtractInst,
8368+
SingleValueInstruction> {
83708369
private:
83718370
/// The extractee.
83728371
LinearDifferentiableFunctionTypeComponent extractee;
8373-
/// The list containing the `@differentiable(linear)` function operand.
8374-
FixedOperandList<1> operands;
83758372

83768373
static SILType
83778374
getExtracteeType(SILValue function,
@@ -8387,10 +8384,6 @@ class LinearFunctionExtractInst
83878384
LinearDifferentiableFunctionTypeComponent getExtractee() const {
83888385
return extractee;
83898386
}
8390-
8391-
SILValue getFunctionOperand() const { return operands[0].get(); }
8392-
ArrayRef<Operand> getAllOperands() const { return operands.asArray(); }
8393-
MutableArrayRef<Operand> getAllOperands() { return operands.asArray(); }
83948387
};
83958388

83968389
/// DifferentiabilityWitnessFunctionInst - Looks up a differentiability witness

lib/IRGen/IRGenSIL.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1937,12 +1937,12 @@ void IRGenSILFunction::
19371937
visitLinearFunctionExtractInst(LinearFunctionExtractInst *i) {
19381938
unsigned structFieldOffset = i->getExtractee().rawValue;
19391939
unsigned fieldSize = 1;
1940-
auto fnRepr = i->getFunctionOperand()->getType().getFunctionRepresentation();
1940+
auto fnRepr = i->getOperand()->getType().getFunctionRepresentation();
19411941
if (fnRepr == SILFunctionTypeRepresentation::Thick) {
19421942
structFieldOffset *= 2;
19431943
fieldSize = 2;
19441944
}
1945-
auto diffFnExp = getLoweredExplosion(i->getFunctionOperand());
1945+
auto diffFnExp = getLoweredExplosion(i->getOperand());
19461946
assert(diffFnExp.size() == fieldSize * 2);
19471947
Explosion e;
19481948
e.add(diffFnExp.getRange(structFieldOffset, structFieldOffset + fieldSize));

lib/IRGen/LoadableByAddress.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2862,7 +2862,7 @@ bool LoadableByAddress::recreateConvInstr(SILInstruction &I,
28622862
case SILInstructionKind::LinearFunctionExtractInst: {
28632863
auto instr = cast<LinearFunctionExtractInst>(convInstr);
28642864
newInstr = convBuilder.createLinearFunctionExtract(
2865-
instr->getLoc(), instr->getExtractee(), instr->getFunctionOperand());
2865+
instr->getLoc(), instr->getExtractee(), instr->getOperand());
28662866
break;
28672867
}
28682868
default:

lib/SIL/IR/SILInstructions.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -762,10 +762,10 @@ getExtracteeType(
762762

763763
LinearFunctionExtractInst::LinearFunctionExtractInst(
764764
SILModule &module, SILDebugLocation debugLoc,
765-
LinearDifferentiableFunctionTypeComponent extractee, SILValue theFunction)
766-
: InstructionBase(debugLoc,
767-
getExtracteeType(theFunction, extractee, module)),
768-
extractee(extractee), operands(this, theFunction) {}
765+
LinearDifferentiableFunctionTypeComponent extractee, SILValue function)
766+
: UnaryInstructionBase(debugLoc, function,
767+
getExtracteeType(function, extractee, module)),
768+
extractee(extractee) {}
769769

770770
SILType DifferentiabilityWitnessFunctionInst::getDifferentiabilityWitnessType(
771771
SILModule &module, DifferentiabilityWitnessFunctionKind witnessKind,

lib/SIL/IR/SILPrinter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2397,7 +2397,7 @@ class SILPrinter : public SILInstructionVisitor<SILPrinter> {
23972397
break;
23982398
}
23992399
*this << "] ";
2400-
*this << getIDAndType(lfei->getFunctionOperand());
2400+
*this << getIDAndType(lfei->getOperand());
24012401
}
24022402

24032403
void visitDifferentiabilityWitnessFunctionInst(

lib/SIL/Verifier/SILVerifier.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4730,7 +4730,7 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
47304730
}
47314731

47324732
void checkLinearFunctionExtractInst(LinearFunctionExtractInst *lfei) {
4733-
auto fnTy = lfei->getFunctionOperand()->getType().getAs<SILFunctionType>();
4733+
auto fnTy = lfei->getOperand()->getType().getAs<SILFunctionType>();
47344734
require(fnTy, "The function operand must have a function type");
47354735
require(fnTy->getDifferentiabilityKind() == DifferentiabilityKind::Linear,
47364736
"The function operand must be a '@differentiable(linear)' "

lib/Serialization/SerializeSIL.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2240,8 +2240,8 @@ void SILSerializer::writeSILInstruction(const SILInstruction &SI) {
22402240
}
22412241
case SILInstructionKind::LinearFunctionExtractInst: {
22422242
auto *lfei = cast<LinearFunctionExtractInst>(&SI);
2243-
auto operandRef = addValueRef(lfei->getFunctionOperand());
2244-
auto operandType = lfei->getFunctionOperand()->getType();
2243+
auto operandRef = addValueRef(lfei->getOperand());
2244+
auto operandType = lfei->getOperand()->getType();
22452245
auto operandTypeRef = S.addTypeRef(operandType.getASTType());
22462246
auto rawExtractee = (unsigned)lfei->getExtractee();
22472247
SILInstLinearFunctionExtractLayout::emitRecord(Out, ScratchRecord,

0 commit comments

Comments
 (0)