-
-int fold::cond(ir_value *condval, ast_function *func, ast_ifthen *branch) {
- if (isfloat(condval) && fold_can_1(condval) && OPTS_OPTIMIZATION(OPTIM_CONST_FOLD_DCE)) {
- ir_block *elide;
- ir_value *dummy;
- bool istrue = (immvalue_float(condval) != 0.0f && branch->m_on_true);
- bool isfalse = (immvalue_float(condval) == 0.0f && branch->m_on_false);
- ast_expression *path = (istrue) ? branch->m_on_true :
- (isfalse) ? branch->m_on_false : nullptr;
- if (!path) {
- /*
- * no path to take implies that the evaluation is if(0) and there
- * is no else block. so eliminate all the code.
- */
- ++opts_optimizationcount[OPTIM_CONST_FOLD_DCE];
- return true;
- }
-
- if (!(elide = ir_function_create_block(branch->m_context, func->m_ir_func, func->makeLabel((istrue) ? "ontrue" : "onfalse"))))
- return false;
- if (!path->codegen(func, false, &dummy))
- return false;
- if (!ir_block_create_jump(func->m_curblock, branch->m_context, elide))
- return false;
- /*
- * now the branch has been eliminated and the correct block for the constant evaluation
- * is expanded into the current block for the function.
- */
- func->m_curblock = elide;
- ++opts_optimizationcount[OPTIM_CONST_FOLD_DCE];
- return true;
- }
- return -1; /* nothing done */
-}
-
-int fold::cond_ternary(ir_value *condval, ast_function *func, ast_ternary *branch) {
- return cond(condval, func, (ast_ifthen*)branch);
-}
-
-int fold::cond_ifthen(ir_value *condval, ast_function *func, ast_ifthen *branch) {
- return cond(condval, func, branch);
-}