Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(83)

Unified Diff: src/IceInstMIPS32.cpp

Issue 2275883002: [SubZero] Branch optimization (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Tests added for branch optimization. Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/IceInstMIPS32.h ('k') | src/IceTargetLoweringMIPS32.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/IceInstMIPS32.cpp
diff --git a/src/IceInstMIPS32.cpp b/src/IceInstMIPS32.cpp
index d26190cb407db19ddbbb1e1fdd811062e9f75343..c61fc9f4c13f1f7bba69c2cd902de9f9f6aad1dd 100644
--- a/src/IceInstMIPS32.cpp
+++ b/src/IceInstMIPS32.cpp
@@ -200,6 +200,46 @@ InstMIPS32Br::InstMIPS32Br(Cfg *Func, const CfgNode *TargetTrue,
addSource(Src1);
}
+CondMIPS32::Cond InstMIPS32::getOppositeCondition(CondMIPS32::Cond Cond) {
+ return InstMIPS32CondAttributes[Cond].Opposite;
+}
+
+bool InstMIPS32Br::optimizeBranch(const CfgNode *NextNode) {
+ // If there is no next block, then there can be no fallthrough to optimize.
+ if (NextNode == nullptr)
+ return false;
+ // Intra-block conditional branches can't be optimized.
+ if (Label != nullptr)
+ return false;
+ // Unconditional branch to the next node can be removed.
+ if (isUnconditionalBranch() && getTargetFalse() == NextNode) {
+ assert(getTargetTrue() == nullptr);
+ setDeleted();
+ return true;
+ }
+ // If there is no fallthrough node, such as a non-default case label for a
+ // switch instruction, then there is no opportunity to optimize.
+ if (getTargetTrue() == nullptr)
+ return false;
+ // If the fallthrough is to the next node, set fallthrough to nullptr to
+ // indicate.
+ if (getTargetTrue() == NextNode) {
+ TargetTrue = nullptr;
+ return true;
+ }
+ // If TargetFalse is the next node, and TargetTrue is not nullptr
+ // then invert the branch condition, swap the targets, and set new
+ // fallthrough to nullptr.
+ if (getTargetFalse() == NextNode) {
+ assert(Predicate != CondMIPS32::AL);
+ setPredicate(getOppositeCondition(getPredicate()));
+ TargetFalse = getTargetTrue();
+ TargetTrue = nullptr;
+ return true;
+ }
+ return false;
+}
+
bool InstMIPS32Br::repointEdges(CfgNode *OldNode, CfgNode *NewNode) {
bool Found = false;
if (TargetFalse == OldNode) {
@@ -419,6 +459,11 @@ void InstMIPS32Br::emit(const Cfg *Func) const {
}
}
Str << getTargetFalse()->getAsmName();
+ if (getTargetTrue()) {
+ Str << "\n\t"
+ << "b"
+ << "\t" << getTargetTrue()->getAsmName();
+ }
}
}
}
@@ -439,6 +484,11 @@ void InstMIPS32Br::dump(const Cfg *Func) const {
dumpSources(Func);
Str << ", ";
Str << getTargetFalse()->getAsmName();
+ if (getTargetTrue()) {
+ Str << "\n\t"
+ << "b"
+ << "\t" << getTargetTrue()->getAsmName();
+ }
}
}
}
« no previous file with comments | « src/IceInstMIPS32.h ('k') | src/IceTargetLoweringMIPS32.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698