feat: first prototype of optimizers + alloca optimizer
This commit is contained in:
34
include/ir/optimize.hpp
Normal file
34
include/ir/optimize.hpp
Normal file
@@ -0,0 +1,34 @@
|
||||
#pragma once
|
||||
#include "ir/op.hpp"
|
||||
#include "prelude/linkedlist.hpp"
|
||||
|
||||
namespace IR {
|
||||
|
||||
class Optimizer
|
||||
{
|
||||
public:
|
||||
virtual bool Apply(DoubleLinkedList<Op*>& ops) = 0;
|
||||
};
|
||||
|
||||
class AllocOptimizer : public Optimizer
|
||||
{
|
||||
public:
|
||||
bool Apply(DoubleLinkedList<Op*>& ops) override
|
||||
{
|
||||
for (ListNode<Op*>* cur = ops.Begin(); cur != nullptr; )
|
||||
{
|
||||
auto op = cur->value;
|
||||
if (op->GetType() == OpType::ALLOCATE)
|
||||
{
|
||||
auto tmp = cur;
|
||||
cur = cur->next;
|
||||
ops.SpliceFront(tmp);
|
||||
} else {
|
||||
cur = cur->next;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user