Skip to content

Commit a21a8bf

Browse files
committed
xe: ir: refactor stmt_seq_t to use vector
1 parent 15b31ce commit a21a8bf

File tree

3 files changed

+35
-21
lines changed

3 files changed

+35
-21
lines changed

src/gpu/intel/jit/ir/core.cpp

+4-8
Original file line numberDiff line numberDiff line change
@@ -582,17 +582,13 @@ void ir_visitor_t::_visit(const stmt_group_t &obj) {
582582
}
583583

584584
object_t ir_mutator_t::_mutate(const stmt_seq_t &obj) {
585-
auto head = mutate(obj.head);
586-
auto tail = mutate(obj.tail);
587-
588-
if (head.is_same(obj.head) && tail.is_same(obj.tail)) return obj;
589-
590-
return stmt_seq_t::make(head, tail);
585+
auto vec = mutate(obj.vec);
586+
if (ir_utils::is_same(vec, obj.vec)) return obj;
587+
return stmt_seq_t::make(vec);
591588
}
592589

593590
void ir_visitor_t::_visit(const stmt_seq_t &obj) {
594-
visit(obj.head);
595-
visit(obj.tail);
591+
visit(obj.vec);
596592
}
597593

598594
object_t ir_mutator_t::_mutate(const store_t &obj) {

src/gpu/intel/jit/ir/core.hpp

+29-11
Original file line numberDiff line numberDiff line change
@@ -2426,42 +2426,60 @@ class stmt_group_t : public stmt_impl_t {
24262426
: stmt_impl_t(_type_info()), label(label), body(body) {}
24272427
};
24282428

2429-
// Statement sequence, allows combining two statements.
2429+
// Statement sequence, allows combining multiple statements.
24302430
// C++ equivalent:
24312431
// {
2432-
// head;
2433-
// tail;
2432+
// vec[0];
2433+
// vec[1];
2434+
// ...
24342435
// }
24352436
class stmt_seq_t : public stmt_impl_t {
24362437
public:
24372438
IR_DECL_STMT_TYPE_ID(stmt_seq_t)
24382439

2440+
static stmt_t make(const std::vector<stmt_t> &vec) {
2441+
return stmt_t(new stmt_seq_t(vec));
2442+
}
2443+
24392444
static stmt_t make(const stmt_t &head, const stmt_t &tail) {
2440-
return stmt_t(new stmt_seq_t(head, tail));
2445+
return head.append(tail);
24412446
}
24422447

24432448
bool is_equal(const object_impl_t &obj) const override {
24442449
if (!obj.is<self_type>()) return false;
24452450
auto &other = obj.as<self_type>();
24462451

2447-
return head.is_equal(other.head) && tail.is_equal(other.tail);
2452+
return ir_utils::is_equal(vec, other.vec);
24482453
}
24492454

2450-
size_t get_hash() const override { return ir_utils::get_hash(head, tail); }
2455+
size_t get_hash() const override { return ir_utils::get_hash(vec); }
24512456

24522457
IR_DECLARE_TRAVERSERS()
24532458

2454-
stmt_t head;
2455-
stmt_t tail;
2459+
std::vector<stmt_t> vec;
24562460

24572461
private:
2458-
stmt_seq_t(const stmt_t &head, const stmt_t &tail)
2459-
: stmt_impl_t(_type_info()), head(head), tail(tail) {}
2462+
stmt_seq_t(const std::vector<stmt_t> &vec)
2463+
: stmt_impl_t(_type_info()), vec(vec) {}
24602464
};
24612465

24622466
inline stmt_t stmt_t::append(const stmt_t &s) const {
24632467
if (is_empty()) return s;
2464-
return stmt_seq_t::make(*this, s);
2468+
if (s.is_empty()) return *this;
2469+
auto *seq1 = this->as_ptr<stmt_seq_t>();
2470+
auto *seq2 = s.as_ptr<stmt_seq_t>();
2471+
std::vector<stmt_t> vec;
2472+
if (seq1) {
2473+
vec.insert(vec.end(), seq1->vec.begin(), seq1->vec.end());
2474+
} else {
2475+
vec.push_back(*this);
2476+
}
2477+
if (seq2) {
2478+
vec.insert(vec.end(), seq2->vec.begin(), seq2->vec.end());
2479+
} else {
2480+
vec.push_back(s);
2481+
}
2482+
return stmt_seq_t::make(vec);
24652483
}
24662484

24672485
// Function call attribute.

src/gpu/intel/jit/ir/ir.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,8 @@ class ir_printer_t : public ir_visitor_t {
210210
}
211211

212212
void _visit(const stmt_seq_t &obj) override {
213-
visit(obj.head);
214-
visit(obj.tail);
213+
for (auto &s : obj.vec)
214+
visit(s);
215215
}
216216

217217
void _visit(const store_t &obj) override {

0 commit comments

Comments
 (0)