Created
December 4, 2019 17:18
-
-
Save Zer0xFF/b59dba83ad23ef655d71401ca454bc0a to your computer and use it in GitHub Desktop.
CodeGen
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
bool CJitter::ConstantFolding2(StatementList& statements) | |
{ | |
bool changed = false; | |
for(auto statementIterator(statements.rbegin()); | |
statementIterator != statements.rend(); ++statementIterator) | |
{ | |
STATEMENT& outerStatement(*statementIterator); | |
if(outerStatement.op == OP_ADD) | |
{ | |
auto statementIterator0 = std::next(statementIterator); | |
if(statementIterator0 == statements.rend()) | |
break; | |
STATEMENT& innerStatement(*statementIterator0); | |
if(innerStatement.op == OP_ADD) | |
{ | |
if(outerStatement.dst->Equals(innerStatement.dst.get())) | |
{ | |
CSymbol* src2cst0 = dynamic_symbolref_cast(SYM_CONSTANT, innerStatement.src2); | |
CSymbol* src2cst1 = dynamic_symbolref_cast(SYM_CONSTANT, outerStatement.src2); | |
if(src2cst0 && src2cst1) | |
{ | |
uint32 result = src2cst0->m_valueLow + src2cst1->m_valueLow; | |
fprintf(stderr, "OPTIMSED %d + %d == %d\n", src2cst0->m_valueLow, src2cst1->m_valueLow, result); | |
innerStatement.src2 = MakeSymbolRef(MakeSymbol(SYM_CONSTANT, result)); | |
outerStatement.src2 = MakeSymbolRef(MakeSymbol(SYM_CONSTANT, 0)); | |
// statements.erase(std::next(statementIterator).base()); | |
changed = true; | |
// break; | |
} | |
} | |
} | |
} | |
} | |
return changed; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment