Lines 74-80
namespace gbe
Link Here
|
74 |
const GenRegister& replacement) : |
74 |
const GenRegister& replacement) : |
75 |
insn(insn), intermedia(intermedia), replacement(replacement) |
75 |
insn(insn), intermedia(intermedia), replacement(replacement) |
76 |
{ |
76 |
{ |
77 |
assert(insn.opcode == SEL_OP_MOV || insn.opcode == SEL_OP_ADD); |
77 |
assert(insn.opcode == SEL_OP_MOV); |
|
|
78 |
assert(&(insn.src(0)) == &replacement); |
78 |
assert(&(insn.dst(0)) == &intermedia); |
79 |
assert(&(insn.dst(0)) == &intermedia); |
79 |
this->elements = CalculateElements(intermedia, insn.state.execWidth); |
80 |
this->elements = CalculateElements(intermedia, insn.state.execWidth); |
80 |
replacementOverwritten = false; |
81 |
replacementOverwritten = false; |
Lines 101-107
namespace gbe
Link Here
|
101 |
void doReplacement(ReplaceInfo* info); |
102 |
void doReplacement(ReplaceInfo* info); |
102 |
bool CanBeReplaced(const ReplaceInfo* info, const SelectionInstruction& insn, const GenRegister& var); |
103 |
bool CanBeReplaced(const ReplaceInfo* info, const SelectionInstruction& insn, const GenRegister& var); |
103 |
void cleanReplaceInfoMap(); |
104 |
void cleanReplaceInfoMap(); |
104 |
void doNegAddOptimization(SelectionInstruction &insn); |
|
|
105 |
|
105 |
|
106 |
SelectionBlock &bb; |
106 |
SelectionBlock &bb; |
107 |
const ir::Liveness::LiveOut& liveout; |
107 |
const ir::Liveness::LiveOut& liveout; |
Lines 159-171
namespace gbe
Link Here
|
159 |
|
159 |
|
160 |
void SelBasicBlockOptimizer::addToReplaceInfoMap(SelectionInstruction& insn) |
160 |
void SelBasicBlockOptimizer::addToReplaceInfoMap(SelectionInstruction& insn) |
161 |
{ |
161 |
{ |
162 |
assert(insn.opcode == SEL_OP_MOV || insn.opcode == SEL_OP_ADD); |
162 |
assert(insn.opcode == SEL_OP_MOV); |
163 |
GenRegister &src = insn.src(0); |
163 |
const GenRegister& src = insn.src(0); |
164 |
if (insn.opcode == SEL_OP_ADD) { |
|
|
165 |
if (src.file == GEN_IMMEDIATE_VALUE) |
166 |
src = insn.src(1); |
167 |
} |
168 |
|
169 |
const GenRegister& dst = insn.dst(0); |
164 |
const GenRegister& dst = insn.dst(0); |
170 |
if (src.type != dst.type || src.file != dst.file) |
165 |
if (src.type != dst.type || src.file != dst.file) |
171 |
return; |
166 |
return; |
Lines 254-282
namespace gbe
Link Here
|
254 |
|
249 |
|
255 |
if (insn.opcode == SEL_OP_MOV) |
250 |
if (insn.opcode == SEL_OP_MOV) |
256 |
addToReplaceInfoMap(insn); |
251 |
addToReplaceInfoMap(insn); |
257 |
|
|
|
258 |
doNegAddOptimization(insn); |
259 |
} |
252 |
} |
260 |
cleanReplaceInfoMap(); |
253 |
cleanReplaceInfoMap(); |
261 |
} |
254 |
} |
262 |
|
255 |
|
263 |
/* LLVM transform Mad(a, -b, c) to |
|
|
264 |
Add b, -b, 0 |
265 |
Mad val, a, b, c |
266 |
for Gen support negtive modifier, mad(a, -b, c) is native suppoted. |
267 |
Also it can be used for the same like instruction sequence. |
268 |
Do it just like a: mov b, -b, so it is a Mov operation like LocalCopyPropagation |
269 |
*/ |
270 |
void SelBasicBlockOptimizer::doNegAddOptimization(SelectionInstruction &insn) { |
271 |
if (insn.opcode == SEL_OP_ADD) { |
272 |
GenRegister src0 = insn.src(0); |
273 |
GenRegister src1 = insn.src(1); |
274 |
if ((src0.negation && src1.file == GEN_IMMEDIATE_VALUE && src1.value.f == 0.0f) || |
275 |
(src1.negation && src0.file == GEN_IMMEDIATE_VALUE && src0.value.f == 0.0f)) |
276 |
addToReplaceInfoMap(insn); |
277 |
} |
278 |
} |
279 |
|
280 |
void SelBasicBlockOptimizer::run() |
256 |
void SelBasicBlockOptimizer::run() |
281 |
{ |
257 |
{ |
282 |
for (size_t i = 0; i < MaxTries; ++i) { |
258 |
for (size_t i = 0; i < MaxTries; ++i) { |