Basic DCE pass.
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
namespace alloy {
|
||||
namespace hir {
|
||||
|
||||
class FunctionBuilder;
|
||||
class Instr;
|
||||
class Label;
|
||||
|
||||
|
||||
@@ -374,14 +374,17 @@ void FunctionBuilder::Comment(const char* format, ...) {
|
||||
i->src2.value = i->src3.value = NULL;
|
||||
}
|
||||
|
||||
void FunctionBuilder::Nop() {
|
||||
const OpcodeInfo* FunctionBuilder::GetNopOpcode() const {
|
||||
STATIC_OPCODE(
|
||||
OPCODE_NOP,
|
||||
"nop",
|
||||
OPCODE_SIG_X,
|
||||
OPCODE_FLAG_IGNORE);
|
||||
return &opcode;
|
||||
}
|
||||
|
||||
Instr* i = AppendInstr(opcode, 0);
|
||||
void FunctionBuilder::Nop() {
|
||||
Instr* i = AppendInstr(*GetNopOpcode(), 0);
|
||||
i->src1.value = i->src2.value = i->src3.value = NULL;
|
||||
}
|
||||
|
||||
|
||||
@@ -55,6 +55,7 @@ public:
|
||||
|
||||
void Comment(const char* format, ...);
|
||||
|
||||
const OpcodeInfo* GetNopOpcode() const;
|
||||
void Nop();
|
||||
|
||||
// trace info/etc
|
||||
|
||||
@@ -47,3 +47,33 @@ void Instr::set_src3(Value* value) {
|
||||
src3.value = value;
|
||||
src3_use = value ? value->AddUse(block->arena, this) : NULL;
|
||||
}
|
||||
|
||||
void Instr::Remove() {
|
||||
if (dest) {
|
||||
XEASSERT(!dest->use_head);
|
||||
dest->def = NULL;
|
||||
}
|
||||
if (src1_use) {
|
||||
src1.value->RemoveUse(src1_use);
|
||||
src1_use = NULL;
|
||||
}
|
||||
if (src2_use) {
|
||||
src2.value->RemoveUse(src2_use);
|
||||
src2_use = NULL;
|
||||
}
|
||||
if (src3_use) {
|
||||
src3.value->RemoveUse(src3_use);
|
||||
src3_use = NULL;
|
||||
}
|
||||
|
||||
if (prev) {
|
||||
prev->next = next;
|
||||
} else {
|
||||
block->instr_head = next;
|
||||
}
|
||||
if (next) {
|
||||
next->prev = prev;
|
||||
} else {
|
||||
block->instr_tail = prev;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,6 +53,8 @@ public:
|
||||
void set_src1(Value* value);
|
||||
void set_src2(Value* value);
|
||||
void set_src3(Value* value);
|
||||
|
||||
void Remove();
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user