feat: first prototype of optimizers + alloca optimizer

This commit is contained in:
2026-01-01 22:08:43 +01:00
parent 8a2d98e69e
commit 0b9cb7e7d9
12 changed files with 274 additions and 40 deletions

34
include/ir/optimize.hpp Normal file
View 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;
}
};
}