-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8f91d90
commit 3f02789
Showing
11 changed files
with
380 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#include "checks_elimination.h" | ||
#include "analysis/domtree.h" | ||
#include "analysis/rpo.h" | ||
|
||
namespace compiler { | ||
|
||
void ChecksElimination::Run() { | ||
DomTreeSlow(graph_).Run(); | ||
auto rpo_vector = RpoInsts(graph_).Run()->GetVector(); | ||
|
||
VisitChecks(rpo_vector); | ||
} | ||
|
||
void ChecksElimination::VisitChecks(std::vector<Inst *> &rpo_vector) { | ||
for (auto inst : rpo_vector) { | ||
switch (inst->GetOpcode()) { | ||
case Opcode::NullCheck: | ||
VisitNullCheck(inst); | ||
break; | ||
case Opcode::BoundsCheck: | ||
VisitBoundCheck(inst); | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
} | ||
|
||
void ChecksElimination::VisitNullCheck(Inst *inst) { | ||
auto* input = inst->GetDataInput(0); | ||
for (auto* user : input->GetDataUsers()) { | ||
if (user->GetOpcode() == Opcode::NullCheck && | ||
user != inst && | ||
user->IsDominated(inst)) { | ||
user->ReplaceAllUsers(inst); | ||
} | ||
} | ||
} | ||
|
||
void ChecksElimination::VisitBoundCheck(Inst *inst) { | ||
auto* checked_value = inst->GetDataInput(0); | ||
auto* up_bound = inst->GetDataInput(1); | ||
for (auto* user : checked_value->GetDataUsers()) { | ||
if (user->GetOpcode() == Opcode::BoundsCheck && | ||
user != inst && | ||
user->GetDataInput(1) == up_bound && | ||
user->IsDominated(inst)) { | ||
user->ReplaceAllUsers(inst); | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#pragma once | ||
|
||
#include "vector" | ||
|
||
namespace compiler { | ||
|
||
class Graph; | ||
class Inst; | ||
|
||
class ChecksElimination | ||
{ | ||
public: | ||
ChecksElimination(Graph *graph): | ||
graph_(graph) {}; | ||
|
||
void Run(); | ||
|
||
private: | ||
void VisitChecks(std::vector<Inst *> &rpo); | ||
void VisitNullCheck(Inst *inst); | ||
void VisitBoundCheck(Inst *inst); | ||
|
||
private: | ||
Graph *graph_; | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.