Skip to content
Merged
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 @@ -37,6 +37,8 @@ public class ImInliner {
private final Set<ImFunction> inlinableFunctions = Sets.newLinkedHashSet();
private final Map<ImFunction, Integer> callCounts = Maps.newLinkedHashMap();
private final Map<ImFunction, Integer> funcSizes = Maps.newLinkedHashMap();
/** Inlining rewrites bodies and locals, leaving the signatures used for ordering intact. */
private final IdentityHashMap<ImFunction, String> functionSortKeys = new IdentityHashMap<>();
/** What the decision log reports for a caller which is not tracked in {@link #funcSizes}; never read by a decision. */
private final Map<ImFunction, Integer> untrackedCallerSizes = Maps.newIdentityHashMap();
/** The numbers the decision log gives its callees; never read by a decision. */
Expand Down Expand Up @@ -776,16 +778,9 @@ private ImStmts rewriteStmtForEarlyReturn(ImStmt s, ImVar doneVar, ImVar retVar)
}

private void rateInlinableFunctions() {
List<Map.Entry<ImFunction, ImFunction>> edges = new ArrayList<>(translator.getCalledFunctions().entries());
edges.sort((a, b) -> {
int c = functionSortKey(a.getKey()).compareTo(functionSortKey(b.getKey()));
if (c != 0) return c;
return functionSortKey(a.getValue()).compareTo(functionSortKey(b.getValue()));
});
for (Map.Entry<ImFunction, ImFunction> edge : edges) {
// For bloat control we need how often a function is used (incoming edges),
// not how many calls it performs itself (outgoing edges).
incCallCount(edge.getValue());
// Ratings read each callee's incoming count by key, so edge order is irrelevant.
for (ImFunction callee : translator.getCalledFunctions().values()) {
incCallCount(callee);
}
for (ImFunction f : sortedFunctions(inlinableFunctions)) {
int size = estimateSize(f);
Expand Down Expand Up @@ -1268,7 +1263,7 @@ private void collectInlinableFunctions() {
}
}
// Some call targets can survive in the call graph but not in prog/classes lists.
for (ImFunction f : sortedFunctions(translator.getCalledFunctions().values())) {
for (ImFunction f : sortedFunctions(new LinkedHashSet<>(translator.getCalledFunctions().values()))) {
if (isInlineCandidate(f)) {
inlinableFunctions.add(f);
}
Expand All @@ -1277,11 +1272,11 @@ private void collectInlinableFunctions() {

private List<ImFunction> sortedFunctions(Collection<ImFunction> functions) {
List<ImFunction> r = new ArrayList<>(functions);
r.sort(Comparator.comparing(this::functionSortKey));
r.sort(Comparator.comparing(f -> functionSortKeys.computeIfAbsent(f, ImInliner::functionSortKey)));
return r;
}

private String functionSortKey(ImFunction f) {
private static String functionSortKey(ImFunction f) {
if (f == null) {
return "";
}
Expand Down
Loading