Skip to content

Commit

Permalink
Merge branch 'master' into cmake-modern
Browse files Browse the repository at this point in the history
# Conflicts:
#	.travis.yml
#	test/scripts/build_travis.sh
  • Loading branch information
alexreinking committed May 12, 2020
2 parents 4331f8c + 80c8285 commit 7e11d4c
Show file tree
Hide file tree
Showing 14 changed files with 448 additions and 283 deletions.
52 changes: 0 additions & 52 deletions .travis.yml

This file was deleted.

17 changes: 14 additions & 3 deletions src/BoundsInference.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1068,6 +1068,7 @@ class BoundsInference : public IRMutator {
// because e.g. B could be double-resolution (as happens when fusing yuv computations), so this
// is not just a matter of giving A's box B's name as an alias.
map<string, Box> boxes_for_fused_group;
map<string, Function> stage_name_to_func;
if (!no_pipelines && producing >= 0 && !f.has_extern_definition()) {
Scope<Interval> empty_scope;
size_t last_dot = op->name.rfind('.');
Expand All @@ -1089,13 +1090,22 @@ class BoundsInference : public IRMutator {

if (fused_with_f.empty()) {
boxes_for_fused_group[stage_name] = box_provided(body, stages[producing].name, empty_scope, func_bounds);
stage_name_to_func[stage_name] = f;
internal_assert((int)boxes_for_fused_group[stage_name].size() == f.dimensions());
} else {
auto boxes = boxes_provided(body, empty_scope, func_bounds);
boxes_for_fused_group[stage_name] = boxes[stages[producing].name];

stage_name_to_func[stage_name] = f;
internal_assert((int)boxes_for_fused_group[stage_name].size() == f.dimensions());
for (const auto &fused : fused_with_f) {
boxes_for_fused_group[fused.first + ".s" + std::to_string(fused.second)] = boxes[fused.first];
string fused_stage_name = fused.first + ".s" + std::to_string(fused.second);
boxes_for_fused_group[fused_stage_name] = boxes[fused.first];
for (const auto &fn : funcs) {
if (fn.name() == fused.first) {
stage_name_to_func[fused_stage_name] = fn;
break;
}
}
}
}
}
Expand Down Expand Up @@ -1132,9 +1142,10 @@ class BoundsInference : public IRMutator {
// Finally, define the production bounds for the thing
// we're producing.
if (producing >= 0 && !inner_productions.empty()) {
const vector<string> &f_args = f.args();
for (const auto &b : boxes_for_fused_group) {
const vector<string> &f_args = stage_name_to_func[b.first].args();
const auto &box = b.second;
internal_assert(f_args.size() == box.size());
for (size_t i = 0; i < box.size(); i++) {
internal_assert(box[i].is_bounded());
string var = b.first + "." + f_args[i];
Expand Down
43 changes: 19 additions & 24 deletions src/CompilerLogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ JSONCompilerLogger::JSONCompilerLogger(
obfuscate_exprs(obfuscate_exprs) {
}

void JSONCompilerLogger::record_matched_simplifier_rule(const std::string &rulename) {
matched_simplifier_rules[rulename] += 1;
void JSONCompilerLogger::record_matched_simplifier_rule(const std::string &rulename, Expr expr) {
matched_simplifier_rules[rulename].emplace_back(std::move(expr));
}

void JSONCompilerLogger::record_non_monotonic_loop_var(const std::string &loop_var, Expr expr) {
Expand All @@ -122,18 +122,14 @@ void JSONCompilerLogger::record_compilation_time(Phase phase, double duration) {
void JSONCompilerLogger::obfuscate() {
{
std::map<std::string, std::vector<Expr>> n;
int i = 0;
for (const auto &it : non_monotonic_loop_vars) {
std::string loop_name = "loop" + std::to_string(i++);
for (const auto &it : matched_simplifier_rules) {
std::string rule = it.first;
for (const auto &e : it.second) {
// Create a new obfuscater for every Expr, but take pains to ensure
// that the loop var has a distinct name. (Note that for nested loops,
// loop vars of enclosing loops will be treated like any other var.)
ObfuscateNames obfuscater({{it.first, loop_name}});
n[loop_name].emplace_back(obfuscater.mutate(e));
ObfuscateNames obfuscater;
n[rule].emplace_back(obfuscater.mutate(e));
}
}
non_monotonic_loop_vars = n;
matched_simplifier_rules = n;
}
{
std::vector<std::pair<Expr, Expr>> n;
Expand Down Expand Up @@ -185,7 +181,10 @@ std::ostream &emit_value(std::ostream &o, const VALUE &value) {

template<>
std::ostream &emit_value<std::string>(std::ostream &o, const std::string &value) {
o << "\"" << value << "\"";
std::string v = value;
v = replace_all(v, "\\", "\\\\");
v = replace_all(v, "\"", "\\\"");
o << "\"" << v << "\"";
return o;
}

Expand Down Expand Up @@ -283,21 +282,17 @@ std::ostream &JSONCompilerLogger::emit_to_stream(std::ostream &o) {
}

if (!matched_simplifier_rules.empty()) {
using P = std::pair<std::string, int64_t>;
emit_object_key_open(o, indent, "matched_simplifier_rules");

// Sort these in descending order by usage,
// just to make casual reading of the output easier
struct Compare {
bool operator()(const P &a, const P &b) const {
return a.second > b.second;
}
};

std::set<P, Compare> sorted;
int commas_to_emit = (int)matched_simplifier_rules.size() - 1;
for (const auto &it : matched_simplifier_rules) {
sorted.emplace(it.first, it.second);
const auto &loop_var = it.first;
emit_key(o, indent + 1, loop_var);
emit_eol(o, false);
emit_list(o, indent + 1, exprs_to_strings(it.second), (commas_to_emit-- > 0));
}
emit_pairs(o, indent, "matched_simplifier_rules", sorted);

emit_object_key_close(o, indent);
}

if (!non_monotonic_loop_vars.empty()) {
Expand Down
9 changes: 5 additions & 4 deletions src/CompilerLogger.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class CompilerLogger {

/** Record when a particular simplifier rule matches.
*/
virtual void record_matched_simplifier_rule(const std::string &rulename) = 0;
virtual void record_matched_simplifier_rule(const std::string &rulename, Expr expr) = 0;

/** Record when an expression is non-monotonic in a loop variable.
*/
Expand Down Expand Up @@ -86,7 +86,7 @@ class JSONCompilerLogger : public CompilerLogger {
const std::string &generator_args,
bool obfuscate_exprs);

void record_matched_simplifier_rule(const std::string &rulename) override;
void record_matched_simplifier_rule(const std::string &rulename, Expr expr) override;
void record_non_monotonic_loop_var(const std::string &loop_var, Expr expr) override;
void record_failed_to_prove(Expr failed_to_prove, Expr original_expr) override;
void record_object_code_size(uint64_t bytes) override;
Expand All @@ -102,12 +102,13 @@ class JSONCompilerLogger : public CompilerLogger {
const std::string generator_args;
const bool obfuscate_exprs{false};

std::map<std::string, int64_t> matched_simplifier_rules;
// Maps from string representing rewrite rule -> list of Exprs that matched that rule
std::map<std::string, std::vector<Expr>> matched_simplifier_rules;

// Maps loop_var -> list of Exprs that were nonmonotonic for that loop_var
std::map<std::string, std::vector<Expr>> non_monotonic_loop_vars;

// List of (unprovable simplfied Expr, original version of that Expr passed to can_prove()).
// List of (unprovable simplified Expr, original version of that Expr passed to can_prove()).
std::vector<std::pair<Expr, Expr>> failed_to_prove_exprs;

// Total code size generated, in bytes.
Expand Down
Loading

0 comments on commit 7e11d4c

Please sign in to comment.