Skip to content

[AutoDiff] Minor SILOptimizer changes. #30873

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 2 commits into from
Apr 8, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class AdjointValue final {
std::get<1>(elt).print(s);
},
[&s] { s << ", "; });
} else if (auto tupleType = getType().getAs<TupleType>()) {
} else if (getType().is<TupleType>()) {
s << "Tuple>(";
interleave(
base->value.aggregate,
Expand Down
12 changes: 8 additions & 4 deletions lib/SILOptimizer/Utils/Differentiation/LinearMapInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,11 @@ LinearMapInfo::createBranchingTraceDecl(SILBasicBlock *originalBB,
auto &file = getSynthesizedFile();
// Create a branching trace enum.
Mangle::ASTMangler mangler;
auto originalFnTy = original->getLoweredFunctionType();
auto numResults = originalFnTy->getNumResults() +
originalFnTy->getNumIndirectMutatingParameters();
auto *resultIndices = IndexSubset::get(
original->getASTContext(),
original->getLoweredFunctionType()->getNumResults(), indices.source);
original->getASTContext(), numResults, indices.source);
auto *parameterIndices = indices.parameters;
AutoDiffConfig config(parameterIndices, resultIndices, genericSig);
auto enumName = mangler.mangleAutoDiffGeneratedDeclaration(
Expand Down Expand Up @@ -193,9 +195,11 @@ LinearMapInfo::createLinearMapStruct(SILBasicBlock *originalBB,
auto &file = getSynthesizedFile();
// Create a linear map struct.
Mangle::ASTMangler mangler;
auto originalFnTy = original->getLoweredFunctionType();
auto numResults = originalFnTy->getNumResults() +
originalFnTy->getNumIndirectMutatingParameters();
auto *resultIndices = IndexSubset::get(
original->getASTContext(),
original->getLoweredFunctionType()->getNumResults(), indices.source);
original->getASTContext(), numResults, indices.source);
auto *parameterIndices = indices.parameters;
AutoDiffConfig config(parameterIndices, resultIndices, genericSig);
auto structName = mangler.mangleAutoDiffGeneratedDeclaration(
Expand Down
8 changes: 4 additions & 4 deletions lib/SILOptimizer/Utils/Differentiation/PullbackEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1676,14 +1676,14 @@ void PullbackEmitter::visitBeginBorrowInst(BeginBorrowInst *bbi) {
void PullbackEmitter::visitBeginAccessInst(BeginAccessInst *bai) {
// Check for non-differentiable writes.
if (bai->getAccessKind() == SILAccessKind::Modify) {
if (auto *gai = dyn_cast<GlobalAddrInst>(bai->getSource())) {
if (isa<GlobalAddrInst>(bai->getSource())) {
getContext().emitNondifferentiabilityError(
bai, getInvoker(),
diag::autodiff_cannot_differentiate_writes_to_global_variables);
errorOccurred = true;
return;
}
if (auto *pbi = dyn_cast<ProjectBoxInst>(bai->getSource())) {
if (isa<ProjectBoxInst>(bai->getSource())) {
getContext().emitNondifferentiabilityError(
bai, getInvoker(),
diag::autodiff_cannot_differentiate_writes_to_mutable_captures);
Expand Down Expand Up @@ -1904,7 +1904,7 @@ AdjointValue PullbackEmitter::accumulateAdjointsDirect(AdjointValue lhs,
SmallVector<AdjointValue, 8> newElements;
auto lhsTy = lhsVal->getType().getASTType();
auto lhsValCopy = builder.emitCopyValueOperation(loc, lhsVal);
if (auto *tupTy = lhsTy->getAs<TupleType>()) {
if (lhsTy->is<TupleType>()) {
auto elts = builder.createDestructureTuple(loc, lhsValCopy);
llvm::for_each(elts->getResults(),
[this](SILValue result) { recordTemporary(result); });
Expand All @@ -1913,7 +1913,7 @@ AdjointValue PullbackEmitter::accumulateAdjointsDirect(AdjointValue lhs,
newElements.push_back(accumulateAdjointsDirect(
makeConcreteAdjointValue(elts->getResult(i)), rhsElt, loc));
}
} else if (auto *structDecl = lhsTy->getStructOrBoundGenericStruct()) {
} else if (lhsTy->getStructOrBoundGenericStruct()) {
auto elts =
builder.createDestructureStruct(lhsVal.getLoc(), lhsValCopy);
llvm::for_each(elts->getResults(),
Expand Down