OLD | NEW |
1 //===- subzero/src/IceInstX8632.cpp - X86-32 instruction implementation ---===// | 1 //===- subzero/src/IceInstX8632.cpp - X86-32 instruction implementation ---===// |
2 // | 2 // |
3 // The Subzero Code Generator | 3 // The Subzero Code Generator |
4 // | 4 // |
5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
7 // | 7 // |
8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
9 // | 9 // |
10 // This file implements the InstX8632 and OperandX8632 classes, | 10 // This file implements the InstX8632 and OperandX8632 classes, |
11 // primarily the constructors and the dump()/emit() methods. | 11 // primarily the constructors and the dump()/emit() methods. |
12 // | 12 // |
13 //===----------------------------------------------------------------------===// | 13 //===----------------------------------------------------------------------===// |
14 | 14 |
15 #include "IceCfg.h" | 15 #include "IceCfg.h" |
16 #include "IceCfgNode.h" | 16 #include "IceCfgNode.h" |
17 #include "IceInst.h" | 17 #include "IceInst.h" |
18 #include "IceInstX8632.h" | 18 #include "IceInstX8632.h" |
19 #include "IceTargetLoweringX8632.h" | 19 #include "IceTargetLoweringX8632.h" |
20 #include "IceOperand.h" | 20 #include "IceOperand.h" |
21 | 21 |
22 namespace Ice { | 22 namespace Ice { |
23 | 23 |
24 namespace { | 24 namespace { |
25 | 25 |
26 const struct InstX8632BrAttributes_ { | 26 const struct InstX8632BrAttributes_ { |
| 27 InstX8632::BrCond Opposite; |
27 const char *DisplayString; | 28 const char *DisplayString; |
28 const char *EmitString; | 29 const char *EmitString; |
29 } InstX8632BrAttributes[] = { | 30 } InstX8632BrAttributes[] = { |
30 #define X(tag, dump, emit) \ | 31 #define X(tag, opp, dump, emit) \ |
31 { dump, emit } \ | 32 { InstX8632::opp, dump, emit } \ |
32 , | 33 , |
33 ICEINSTX8632BR_TABLE | 34 ICEINSTX8632BR_TABLE |
34 #undef X | 35 #undef X |
35 }; | 36 }; |
36 | 37 |
37 const struct InstX8632CmppsAttributes_ { | 38 const struct InstX8632CmppsAttributes_ { |
38 const char *EmitString; | 39 const char *EmitString; |
39 } InstX8632CmppsAttributes[] = { | 40 } InstX8632CmppsAttributes[] = { |
40 #define X(tag, emit) \ | 41 #define X(tag, emit) \ |
41 { emit } \ | 42 { emit } \ |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 InstX8632Label::InstX8632Label(Cfg *Func, TargetX8632 *Target) | 122 InstX8632Label::InstX8632Label(Cfg *Func, TargetX8632 *Target) |
122 : InstX8632(Func, InstX8632::Label, 0, NULL), | 123 : InstX8632(Func, InstX8632::Label, 0, NULL), |
123 Number(Target->makeNextLabelNumber()) {} | 124 Number(Target->makeNextLabelNumber()) {} |
124 | 125 |
125 IceString InstX8632Label::getName(const Cfg *Func) const { | 126 IceString InstX8632Label::getName(const Cfg *Func) const { |
126 char buf[30]; | 127 char buf[30]; |
127 snprintf(buf, llvm::array_lengthof(buf), "%u", Number); | 128 snprintf(buf, llvm::array_lengthof(buf), "%u", Number); |
128 return ".L" + Func->getFunctionName() + "$local$__" + buf; | 129 return ".L" + Func->getFunctionName() + "$local$__" + buf; |
129 } | 130 } |
130 | 131 |
131 InstX8632Br::InstX8632Br(Cfg *Func, CfgNode *TargetTrue, CfgNode *TargetFalse, | 132 InstX8632Br::InstX8632Br(Cfg *Func, const CfgNode *TargetTrue, |
132 InstX8632Label *Label, InstX8632::BrCond Condition) | 133 const CfgNode *TargetFalse, |
| 134 const InstX8632Label *Label, |
| 135 InstX8632::BrCond Condition) |
133 : InstX8632(Func, InstX8632::Br, 0, NULL), Condition(Condition), | 136 : InstX8632(Func, InstX8632::Br, 0, NULL), Condition(Condition), |
134 TargetTrue(TargetTrue), TargetFalse(TargetFalse), Label(Label) {} | 137 TargetTrue(TargetTrue), TargetFalse(TargetFalse), Label(Label) {} |
135 | 138 |
| 139 bool InstX8632Br::optimizeBranch(const CfgNode *NextNode) { |
| 140 // If there is no next block, then there can be no fallthrough to |
| 141 // optimize. |
| 142 if (NextNode == NULL) |
| 143 return false; |
| 144 // Intra-block conditional branches can't be optimized. |
| 145 if (Label) |
| 146 return false; |
| 147 // If there is no fallthrough node, such as a non-default case label |
| 148 // for a switch instruction, then there is no opportunity to |
| 149 // optimize. |
| 150 if (getTargetFalse() == NULL) |
| 151 return false; |
| 152 |
| 153 // Unconditional branch to the next node can be removed. |
| 154 if (Condition == Br_None && getTargetFalse() == NextNode) { |
| 155 assert(getTargetTrue() == NULL); |
| 156 setDeleted(); |
| 157 return true; |
| 158 } |
| 159 // If the fallthrough is to the next node, set fallthrough to NULL |
| 160 // to indicate. |
| 161 if (getTargetFalse() == NextNode) { |
| 162 TargetFalse = NULL; |
| 163 return true; |
| 164 } |
| 165 // If TargetTrue is the next node, and TargetFalse is non-NULL |
| 166 // (which was already tested above), then invert the branch |
| 167 // condition, swap the targets, and set new fallthrough to NULL. |
| 168 if (getTargetTrue() == NextNode) { |
| 169 assert(Condition != Br_None); |
| 170 Condition = InstX8632BrAttributes[Condition].Opposite; |
| 171 TargetTrue = getTargetFalse(); |
| 172 TargetFalse = NULL; |
| 173 return true; |
| 174 } |
| 175 return false; |
| 176 } |
| 177 |
136 InstX8632Call::InstX8632Call(Cfg *Func, Variable *Dest, Operand *CallTarget) | 178 InstX8632Call::InstX8632Call(Cfg *Func, Variable *Dest, Operand *CallTarget) |
137 : InstX8632(Func, InstX8632::Call, 1, Dest) { | 179 : InstX8632(Func, InstX8632::Call, 1, Dest) { |
138 HasSideEffects = true; | 180 HasSideEffects = true; |
139 addSource(CallTarget); | 181 addSource(CallTarget); |
140 } | 182 } |
141 | 183 |
142 InstX8632Cmov::InstX8632Cmov(Cfg *Func, Variable *Dest, Operand *Source, | 184 InstX8632Cmov::InstX8632Cmov(Cfg *Func, Variable *Dest, Operand *Source, |
143 InstX8632::BrCond Condition) | 185 InstX8632::BrCond Condition) |
144 : InstX8632(Func, InstX8632::Cmov, 2, Dest), Condition(Condition) { | 186 : InstX8632(Func, InstX8632::Cmov, 2, Dest), Condition(Condition) { |
145 // The final result is either the original Dest, or Source, so mark | 187 // The final result is either the original Dest, or Source, so mark |
(...skipping 1342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1488 } | 1530 } |
1489 Str << "("; | 1531 Str << "("; |
1490 if (Func) | 1532 if (Func) |
1491 Var->dump(Func); | 1533 Var->dump(Func); |
1492 else | 1534 else |
1493 Var->dump(Str); | 1535 Var->dump(Str); |
1494 Str << ")"; | 1536 Str << ")"; |
1495 } | 1537 } |
1496 | 1538 |
1497 } // end of namespace Ice | 1539 } // end of namespace Ice |
OLD | NEW |