This source file includes following definitions.
- visit
- unroll_loops
#include "UnrollLoops.h"
#include "IRMutator.h"
#include "IROperator.h"
#include "Simplify.h"
#include "Substitute.h"
using std::vector;
namespace Halide {
namespace Internal {
class UnrollLoops : public IRMutator {
using IRMutator::visit;
void visit(const For *for_loop) {
if (for_loop->for_type == ForType::Unrolled) {
Expr extent = simplify(for_loop->extent);
const IntImm *e = extent.as<IntImm>();
user_assert(e)
<< "Can only unroll for loops over a constant extent.\n"
<< "Loop over " << for_loop->name << " has extent " << extent << ".\n";
Stmt body = mutate(for_loop->body);
if (e->value == 1) {
user_warning << "Warning: Unrolling a for loop of extent 1: " << for_loop->name << "\n";
}
vector<Stmt> iters;
for (int i = 0; i < e->value; i++) {
iters.push_back(substitute(for_loop->name, for_loop->min + i, body));
}
stmt = Block::make(iters);
} else {
IRMutator::visit(for_loop);
}
}
};
Stmt unroll_loops(Stmt s) {
return UnrollLoops().mutate(s);
}
}
}