Skip to content
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
13 changes: 7 additions & 6 deletions include/swift/AST/AutoDiff.h
Original file line number Diff line number Diff line change
Expand Up @@ -243,12 +243,9 @@ struct SILAutoDiffIndices {
parameters->contains(parameterIndex);
}

void print(llvm::raw_ostream &s = llvm::outs()) const {
s << "(source=" << source << " parameters=(";
interleave(parameters->getIndices(),
[&s](unsigned p) { s << p; }, [&s]{ s << ' '; });
s << "))";
}
void print(llvm::raw_ostream &s = llvm::outs()) const;
LLVM_ATTRIBUTE_DEPRECATED(void dump() const LLVM_ATTRIBUTE_USED,
"only for use within the debugger");

std::string mangle() const {
std::string result = "src_" + llvm::utostr(source) + "_wrt_";
Expand Down Expand Up @@ -279,6 +276,10 @@ struct AutoDiffConfig {
GenericSignatureImpl *derivativeGenericSignature)
: parameterIndices(parameterIndices), resultIndices(resultIndices),
derivativeGenericSignature(derivativeGenericSignature) {}

void print(llvm::raw_ostream &s = llvm::outs()) const;
LLVM_ATTRIBUTE_DEPRECATED(void dump() const LLVM_ATTRIBUTE_USED,
"only for use within the debugger");
};

/// In conjunction with the original function declaration, identifies an
Expand Down
17 changes: 4 additions & 13 deletions include/swift/AST/IndexSubset.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,19 +201,10 @@ class IndexSubset : public llvm::FoldingSetNode {
id.AddInteger(index);
}

void print(llvm::raw_ostream &s = llvm::outs()) const {
s << '{';
interleave(range(capacity), [this, &s](unsigned i) { s << contains(i); },
[&s] { s << ", "; });
s << '}';
}

void dump(llvm::raw_ostream &s = llvm::errs()) const {
s << "(index_subset capacity=" << capacity << " indices=(";
interleave(getIndices(), [&s](unsigned i) { s << i; },
[&s] { s << ", "; });
s << "))";
}
void print(llvm::raw_ostream &s = llvm::outs()) const;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Todo: upstream IndexSubset changes to master.

LLVM_ATTRIBUTE_DEPRECATED(void dump(llvm::raw_ostream &s = llvm::errs())
const LLVM_ATTRIBUTE_USED,
"only for use within the debugger");

int findNext(int startIndex) const;
int findFirst() const { return findNext(-1); }
Expand Down
29 changes: 29 additions & 0 deletions lib/AST/AutoDiff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,35 @@ LinearDifferentiableFunctionTypeComponent(StringRef string) {
rawValue = *result;
}

void SILAutoDiffIndices::print(llvm::raw_ostream &s) const {
s << "(source=" << source << " parameters=(";
interleave(parameters->getIndices(),
[&s](unsigned p) { s << p; }, [&s]{ s << ' '; });
s << "))";
}

void SILAutoDiffIndices::dump() const {
print(llvm::errs());
llvm::errs() << '\n';
}

void AutoDiffConfig::print(llvm::raw_ostream &s) const {
s << "(parameters=";
parameterIndices->print(s);
s << " results=";
resultIndices->print(s);
if (derivativeGenericSignature) {
s << " where=";
derivativeGenericSignature->print(s);
}
s << ')';
}

void AutoDiffConfig::dump() const {
print(llvm::errs());
llvm::errs() << '\n';
}

// TODO(TF-874): This helper is inefficient and should be removed. Unwrapping at
// most once (for curried method types) is sufficient.
static void unwrapCurryLevels(AnyFunctionType *fnTy,
Expand Down
14 changes: 14 additions & 0 deletions lib/AST/IndexSubset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,20 @@ IndexSubset *IndexSubset::extendingCapacity(
return IndexSubset::get(ctx, indices);
}

void IndexSubset::print(llvm::raw_ostream &s) const {
s << '{';
interleave(range(capacity), [this, &s](unsigned i) { s << contains(i); },
[&s] { s << ", "; });
s << '}';
}

void IndexSubset::dump(llvm::raw_ostream &s) const {
s << "(index_subset capacity=" << capacity << " indices=(";
interleave(getIndices(), [&s](unsigned i) { s << i; },
[&s] { s << ", "; });
s << "))\n";
}

int IndexSubset::findNext(int startIndex) const {
assert(startIndex < (int)capacity && "Start index cannot be past the end");
unsigned bitWordIndex = 0, offset = 0;
Expand Down