Skip to content

[AutoDiff] NFC: make LinearFunctionExtractInst inherit UnaryInstructionBase. #33418

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions include/swift/SIL/SILCloner.h
Original file line number Diff line number Diff line change
Expand Up @@ -2905,10 +2905,10 @@ template<typename ImplClass>
void SILCloner<ImplClass>::
visitLinearFunctionExtractInst(LinearFunctionExtractInst *Inst) {
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
recordClonedInstruction(
Inst, getBuilder().createLinearFunctionExtract(
getOpLocation(Inst->getLoc()), Inst->getExtractee(),
getOpValue(Inst->getFunctionOperand())));
recordClonedInstruction(Inst, getBuilder().createLinearFunctionExtract(
getOpLocation(Inst->getLoc()),
Inst->getExtractee(),
getOpValue(Inst->getOperand())));
}

template <typename ImplClass>
Expand Down
11 changes: 2 additions & 9 deletions include/swift/SIL/SILInstruction.h
Original file line number Diff line number Diff line change
Expand Up @@ -8364,14 +8364,11 @@ class DifferentiableFunctionExtractInst
/// representing a bundle of the original function and the transpose function,
/// extract the specified function.
class LinearFunctionExtractInst
: public InstructionBase<
SILInstructionKind::LinearFunctionExtractInst,
SingleValueInstruction> {
: public UnaryInstructionBase<SILInstructionKind::LinearFunctionExtractInst,
SingleValueInstruction> {
private:
/// The extractee.
LinearDifferentiableFunctionTypeComponent extractee;
/// The list containing the `@differentiable(linear)` function operand.
FixedOperandList<1> operands;

static SILType
getExtracteeType(SILValue function,
Expand All @@ -8387,10 +8384,6 @@ class LinearFunctionExtractInst
LinearDifferentiableFunctionTypeComponent getExtractee() const {
return extractee;
}

SILValue getFunctionOperand() const { return operands[0].get(); }
ArrayRef<Operand> getAllOperands() const { return operands.asArray(); }
MutableArrayRef<Operand> getAllOperands() { return operands.asArray(); }
};

/// DifferentiabilityWitnessFunctionInst - Looks up a differentiability witness
Expand Down
4 changes: 2 additions & 2 deletions lib/IRGen/IRGenSIL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1937,12 +1937,12 @@ void IRGenSILFunction::
visitLinearFunctionExtractInst(LinearFunctionExtractInst *i) {
unsigned structFieldOffset = i->getExtractee().rawValue;
unsigned fieldSize = 1;
auto fnRepr = i->getFunctionOperand()->getType().getFunctionRepresentation();
auto fnRepr = i->getOperand()->getType().getFunctionRepresentation();
if (fnRepr == SILFunctionTypeRepresentation::Thick) {
structFieldOffset *= 2;
fieldSize = 2;
}
auto diffFnExp = getLoweredExplosion(i->getFunctionOperand());
auto diffFnExp = getLoweredExplosion(i->getOperand());
assert(diffFnExp.size() == fieldSize * 2);
Explosion e;
e.add(diffFnExp.getRange(structFieldOffset, structFieldOffset + fieldSize));
Expand Down
2 changes: 1 addition & 1 deletion lib/IRGen/LoadableByAddress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2862,7 +2862,7 @@ bool LoadableByAddress::recreateConvInstr(SILInstruction &I,
case SILInstructionKind::LinearFunctionExtractInst: {
auto instr = cast<LinearFunctionExtractInst>(convInstr);
newInstr = convBuilder.createLinearFunctionExtract(
instr->getLoc(), instr->getExtractee(), instr->getFunctionOperand());
instr->getLoc(), instr->getExtractee(), instr->getOperand());
break;
}
default:
Expand Down
8 changes: 4 additions & 4 deletions lib/SIL/IR/SILInstructions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -762,10 +762,10 @@ getExtracteeType(

LinearFunctionExtractInst::LinearFunctionExtractInst(
SILModule &module, SILDebugLocation debugLoc,
LinearDifferentiableFunctionTypeComponent extractee, SILValue theFunction)
: InstructionBase(debugLoc,
getExtracteeType(theFunction, extractee, module)),
extractee(extractee), operands(this, theFunction) {}
LinearDifferentiableFunctionTypeComponent extractee, SILValue function)
: UnaryInstructionBase(debugLoc, function,
getExtracteeType(function, extractee, module)),
extractee(extractee) {}

SILType DifferentiabilityWitnessFunctionInst::getDifferentiabilityWitnessType(
SILModule &module, DifferentiabilityWitnessFunctionKind witnessKind,
Expand Down
2 changes: 1 addition & 1 deletion lib/SIL/IR/SILPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2397,7 +2397,7 @@ class SILPrinter : public SILInstructionVisitor<SILPrinter> {
break;
}
*this << "] ";
*this << getIDAndType(lfei->getFunctionOperand());
*this << getIDAndType(lfei->getOperand());
}

void visitDifferentiabilityWitnessFunctionInst(
Expand Down
2 changes: 1 addition & 1 deletion lib/SIL/Verifier/SILVerifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4730,7 +4730,7 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
}

void checkLinearFunctionExtractInst(LinearFunctionExtractInst *lfei) {
auto fnTy = lfei->getFunctionOperand()->getType().getAs<SILFunctionType>();
auto fnTy = lfei->getOperand()->getType().getAs<SILFunctionType>();
require(fnTy, "The function operand must have a function type");
require(fnTy->getDifferentiabilityKind() == DifferentiabilityKind::Linear,
"The function operand must be a '@differentiable(linear)' "
Expand Down
4 changes: 2 additions & 2 deletions lib/Serialization/SerializeSIL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2240,8 +2240,8 @@ void SILSerializer::writeSILInstruction(const SILInstruction &SI) {
}
case SILInstructionKind::LinearFunctionExtractInst: {
auto *lfei = cast<LinearFunctionExtractInst>(&SI);
auto operandRef = addValueRef(lfei->getFunctionOperand());
auto operandType = lfei->getFunctionOperand()->getType();
auto operandRef = addValueRef(lfei->getOperand());
auto operandType = lfei->getOperand()->getType();
auto operandTypeRef = S.addTypeRef(operandType.getASTType());
auto rawExtractee = (unsigned)lfei->getExtractee();
SILInstLinearFunctionExtractLayout::emitRecord(Out, ScratchRecord,
Expand Down