1 #include "Qualify.h" 2 #include "IRMutator.h" 3 4 namespace Halide { 5 namespace Internal { 6 7 using std::string; 8 9 // Prefix all names in an expression with some string. 10 class QualifyExpr : public IRMutator { 11 using IRMutator::visit; 12 13 const string &prefix; 14 visit(const Variable * v)15 Expr visit(const Variable *v) override { 16 if (v->param.defined()) { 17 return v; 18 } else { 19 return Variable::make(v->type, prefix + v->name, v->reduction_domain); 20 } 21 } visit(const Let * op)22 Expr visit(const Let *op) override { 23 Expr value = mutate(op->value); 24 Expr body = mutate(op->body); 25 return Let::make(prefix + op->name, value, body); 26 } 27 28 public: QualifyExpr(const string & p)29 QualifyExpr(const string &p) 30 : prefix(p) { 31 } 32 }; 33 qualify(const string & prefix,const Expr & value)34Expr qualify(const string &prefix, const Expr &value) { 35 QualifyExpr q(prefix); 36 return q.mutate(value); 37 } 38 39 } // namespace Internal 40 } // namespace Halide 41