more cleaning

This commit is contained in:
Philippe Tillet
2019-10-12 01:25:08 -04:00
parent 7d77f34db0
commit 6beef4be1f
4 changed files with 24 additions and 23 deletions

View File

@@ -42,21 +42,20 @@ struct segment {
class liveness {
private:
typedef std::map<ir::value*, slot_index> indices_map_t;
typedef std::map<layout_t*, segment> intervals_map_t;
public:
// constructor
liveness(layout *l): layouts_(l){ }
// accessors
const intervals_map_t& intervals() const { return intervals_; }
segment get_interval(layout_t* v) const { return intervals_.at(v); }
const intervals_map_t& get() const { return intervals_; }
segment get(layout_t* v) const { return intervals_.at(v); }
// run
void run(ir::module &mod);
private:
// analysis
layout *layouts_;
indices_map_t indices;
intervals_map_t intervals_;
};

View File

@@ -22,7 +22,7 @@ void allocation::run(ir::module &mod) {
typedef std::multimap<unsigned, segment> triples_map_type;
std::vector<layout_t*> I;
for(auto x: liveness_->intervals())
for(auto x: liveness_->get())
I.push_back(x.first);
std::vector<layout_t*> J = I;
@@ -37,7 +37,7 @@ void allocation::run(ir::module &mod) {
segment xh = h_it->second;
H.erase(h_it);
auto j_it = std::find_if(J.begin(), J.end(), [&](layout_t* JJ){
segment xj = liveness_->get_interval(JJ);
segment xj = liveness_->get(JJ);
bool res = xj.intersect(xh);
for(auto val: H)
res = res && !val.second.intersect(xj);
@@ -45,7 +45,7 @@ void allocation::run(ir::module &mod) {
});
if(j_it != J.end()){
unsigned size = (*j_it)->size;
segment xj = liveness_->get_interval(*j_it);
segment xj = liveness_->get(*j_it);
starts[*j_it] = w;
H.insert({w + size, segment{max(xh.start, xj.start), min(xh.end, xj.end)}});
if(xh.start < xj.start)
@@ -68,7 +68,7 @@ void allocation::run(ir::module &mod) {
unsigned NY = y->size;
segment XS = {X0, X0 + NX};
segment YS = {Y0, Y0 + NY};
if(liveness_->get_interval(x).intersect(liveness_->get_interval(y))
if(liveness_->get(x).intersect(liveness_->get(y))
&& XS.intersect(YS))
interferences[x].insert(y);
}

View File

@@ -188,17 +188,6 @@ layout_hmma_884_t::layout_hmma_884_t(size_t num_warps,
throw std::runtime_error("cannot create a kernel with this amount of warps");
}
inline bool is_loop_latch(ir::phi_node *phi, ir::instruction *terminator){
if(phi->get_parent() != terminator->get_parent())
return false;
if(auto *br = dynamic_cast<ir::cond_branch_inst*>(terminator))
return br->get_true_dest() == phi->get_parent()
|| br->get_false_dest() == phi->get_parent();
else if(dynamic_cast<ir::uncond_branch_inst*>(terminator))
return false;
else
throw std::runtime_error("unreachable");
}
@@ -230,6 +219,19 @@ layout_scanline_t::layout_scanline_t(size_t num_warps,
throw std::runtime_error("cannot create a kernel with this amount of warps");
}
inline bool is_loop_latch(ir::phi_node *phi, ir::instruction *terminator){
if(phi->get_parent() != terminator->get_parent())
return false;
if(auto *br = dynamic_cast<ir::cond_branch_inst*>(terminator))
return br->get_true_dest() == phi->get_parent()
|| br->get_false_dest() == phi->get_parent();
else if(dynamic_cast<ir::uncond_branch_inst*>(terminator))
return false;
else
throw std::runtime_error("unreachable");
}
void extract_double_bufferable(ir::value *v, std::shared_ptr<double_buffer_info_t>& res) {
auto* phi = dynamic_cast<ir::phi_node*>(v);
if(!phi || phi->get_num_incoming() != 2)
@@ -303,7 +305,7 @@ layout_shared_t::layout_shared_t(const layout_t *arg,
pad = 24 - shapes[row ? 1 : 0] % 32;
}
else if(order != arg->order) {
pad = 16;
pad = 4;
}
// size
@@ -316,6 +318,7 @@ layout_shared_t::layout_shared_t(const layout_t *arg,
size *= 2;
}
// layout factory method
void layout::create(size_t id, const std::vector<ir::value*>& values) {
auto it_hmma_c = std::find_if(values.begin(), values.end(), &is_hmma_c);
auto cmp = [](ir::value* x, ir::value *y) {

View File

@@ -17,13 +17,11 @@ namespace codegen{
namespace analysis{
// Entry point
void liveness::run(ir::module &mod) {
indices.clear();
intervals_.clear();
// Assigns index to each instruction
std::map<ir::value*, slot_index> indices;
for(ir::function *fn: mod.get_function_list()){
slot_index index = 0;
for(ir::basic_block *block: fn->blocks())
@@ -33,6 +31,7 @@ void liveness::run(ir::module &mod) {
}
}
// create live intervals
for(auto &x: layouts_->get_all()) {
layout_t* layout = x.second;
if(layout->type != SHARED)