From: Wolfgang Bumiller Date: Sun, 1 Feb 2015 11:13:59 +0000 (+0100) Subject: Merge branch 'cleanup' of git://github.com/graphitemaster/gmqcc into cleanup X-Git-Tag: xonotic-v0.8.2~9 X-Git-Url: https://git.xonotic.org/?p=xonotic%2Fgmqcc.git;a=commitdiff_plain;h=fab640da4cc5ac00ae69d37c227dedca327b61f1;hp=-c Merge branch 'cleanup' of git://github.com/graphitemaster/gmqcc into cleanup --- fab640da4cc5ac00ae69d37c227dedca327b61f1 diff --combined fold.cpp index 658ec38,0f86117..f5a1b31 --- a/fold.cpp +++ b/fold.cpp @@@ -931,14 -931,14 +931,14 @@@ bool fold::generate(ir_builder *ir) // generate globals for immediate folded values ast_value *cur; for (auto &it : m_imm_float) - if (!ast_global_codegen((cur = it), ir, false)) goto err; + if (!(cur = it)->generateGlobal(ir, false)) goto err; for (auto &it : m_imm_vector) - if (!ast_global_codegen((cur = it), ir, false)) goto err; + if (!(cur = it)->generateGlobal(ir, false)) goto err; for (auto &it : m_imm_string) - if (!ast_global_codegen((cur = it), ir, false)) goto err; + if (!(cur = it)->generateGlobal(ir, false)) goto err; return true; err: - con_out("failed to generate global %s\n", cur->m_name); + con_out("failed to generate global %s\n", cur->m_name.c_str()); delete ir; return false; } @@@ -960,7 -960,7 +960,7 @@@ ast_expression *fold::constgen_float(qc if (!memcmp(&it->m_constval.vfloat, &value, sizeof(qcfloat_t))) return (ast_expression*)it; - ast_value *out = ast_value_new(ctx(), "#IMMEDIATE", TYPE_FLOAT); + ast_value *out = new ast_value(ctx(), "#IMMEDIATE", TYPE_FLOAT); out->m_cvq = CV_CONST; out->m_hasvalue = true; out->m_inexact = inexact; @@@ -976,7 -976,7 +976,7 @@@ ast_expression *fold::constgen_vector(v if (vec3_cmp(it->m_constval.vvec, value)) return (ast_expression*)it; - ast_value *out = ast_value_new(ctx(), "#IMMEDIATE", TYPE_VECTOR); + ast_value *out = new ast_value(ctx(), "#IMMEDIATE", TYPE_VECTOR); out->m_cvq = CV_CONST; out->m_hasvalue = true; out->m_constval.vvec = value; @@@ -997,10 -997,10 +997,10 @@@ ast_expression *fold::constgen_string(c if (translate) { char name[32]; util_snprintf(name, sizeof(name), "dotranslate_%zu", m_parser->translated++); - out = ast_value_new(ctx(), name, TYPE_STRING); + out = new ast_value(ctx(), name, TYPE_STRING); out->m_flags |= AST_FLAG_INCLUDE_DEF; /* def needs to be included for translatables */ } else { - out = ast_value_new(ctx(), "#IMMEDIATE", TYPE_STRING); + out = new ast_value(ctx(), "#IMMEDIATE", TYPE_STRING); } out->m_cvq = CV_CONST; @@@ -1014,10 -1014,6 +1014,10 @@@ return (ast_expression*)out; } +ast_expression *fold::constgen_string(const std::string &str, bool translate) { + return constgen_string(str.c_str(), translate); +} + typedef union { void (*callback)(void); sfloat_t (*binary)(sfloat_state_t *, sfloat_t, sfloat_t); @@@ -1073,11 -1069,11 +1073,11 @@@ ast_expression *fold::op_mul_vec(vec3_ if (!y && !z) { ast_expression *out; ++opts_optimizationcount[OPTIM_VECTOR_COMPONENTS]; - out = (ast_expression*)ast_member_new(ctx(), (ast_expression*)sel, set[0]-'x', nullptr); + out = ast_member::make(ctx(), (ast_expression*)sel, set[0]-'x', ""); out->m_keep_node = false; ((ast_member*)out)->m_rvalue = true; if (x != -1.0f) - return (ast_expression*)ast_binary_new(ctx(), INSTR_MUL_F, constgen_float(x, false), out); + return new ast_binary(ctx(), INSTR_MUL_F, constgen_float(x, false), out); } return nullptr; } @@@ -1185,7 -1181,7 +1185,7 @@@ ast_expression *fold::op_div(ast_value bool inexact = check_except_float(&sfloat_div, a, b); return constgen_float(immvalue_float(a) / immvalue_float(b), inexact); } else if (fold_can_1(b)) { - return (ast_expression*)ast_binary_new( + return new ast_binary( ctx(), INSTR_MUL_F, (ast_expression*)a, @@@ -1196,16 -1192,17 +1196,16 @@@ if (fold_can_2(a, b)) { return constgen_vector(vec3_mulvf(ctx(), immvalue_vector(a), 1.0f / immvalue_float(b))); } else { - return (ast_expression*)ast_binary_new( + return new ast_binary( ctx(), INSTR_MUL_VF, (ast_expression*)a, (fold_can_1(b)) ? (ast_expression*)constgen_float(1.0f / immvalue_float(b), false) - : (ast_expression*)ast_binary_new( - ctx(), - INSTR_DIV_F, - (ast_expression*)m_imm_float[1], - (ast_expression*)b + : new ast_binary(ctx(), + INSTR_DIV_F, + (ast_expression*)m_imm_float[1], + (ast_expression*)b ) ); } @@@ -1338,11 -1335,15 +1338,15 @@@ ast_expression *fold::op_cmp(ast_value float la = immvalue_float(a); float lb = immvalue_float(b); check_inexact_float(a, b); - return (ast_expression*)m_imm_float[!(ne ? la == lb : la != lb)]; - } if (isvector(a) && isvector(b)) { + return (ast_expression*)m_imm_float[ne ? la != lb : la == lb]; + } else if (isvector(a) && isvector(b)) { vec3_t la = immvalue_vector(a); vec3_t lb = immvalue_vector(b); - return (ast_expression*)m_imm_float[!(ne ? vec3_cmp(la, lb) : !vec3_cmp(la, lb))]; + bool compare = vec3_cmp(la, lb); + return (ast_expression*)m_imm_float[ne ? !compare : compare]; + } else if (isstring(a) && isstring(b)) { + bool compare = !strcmp(immvalue_string(a), immvalue_string(b)); + return (ast_expression*)m_imm_float[ne ? !compare : compare]; } } return nullptr; @@@ -1603,11 -1604,12 +1607,11 @@@ ast_expression *fold::binary(lex_ctx_t ast_expression *ret = superfluous(left, right, op); if (ret) return ret; - return (ast_expression*)ast_binary_new(ctx, op, left, right); + return new ast_binary(ctx, op, left, right); } 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)) { - ast_expression_codegen *cgen; ir_block *elide; ir_value *dummy; bool istrue = (immvalue_float(condval) != 0.0f && branch->m_on_true); @@@ -1623,9 -1625,9 +1627,9 @@@ return true; } - if (!(elide = ir_function_create_block(branch->m_context, func->m_ir_func, ast_function_label(func, ((istrue) ? "ontrue" : "onfalse"))))) + if (!(elide = ir_function_create_block(branch->m_context, func->m_ir_func, func->makeLabel((istrue) ? "ontrue" : "onfalse")))) return false; - if (!(*(cgen = path->m_codegen))((ast_expression*)path, func, false, &dummy)) + if (!path->codegen(func, false, &dummy)) return false; if (!ir_block_create_jump(func->m_curblock, branch->m_context, elide)) return false; diff --combined ir.cpp index 044b834,7f45899..d11bbb7 --- a/ir.cpp +++ b/ir.cpp @@@ -792,9 -792,6 +792,9 @@@ static void ir_instr_delete_quick(ir_in { self->m_phi.clear(); self->m_params.clear(); + self->_m_ops[0] = nullptr; + self->_m_ops[1] = nullptr; + self->_m_ops[2] = nullptr; delete self; } @@@ -3436,6 -3433,8 +3436,8 @@@ static bool ir_builder_gen_global(ir_bu { ir_value_code_setaddr(global, self->m_code->globals.size()); if (global->m_hasvalue) { + if (global->m_cvq == CV_CONST && global->m_reads.empty()) + return true; iptr = (int32_t*)&global->m_constval.ivec[0]; self->m_code->globals.push_back(*iptr); } else { @@@ -3451,6 -3450,8 +3453,8 @@@ { ir_value_code_setaddr(global, self->m_code->globals.size()); if (global->m_hasvalue) { + if (global->m_cvq == CV_CONST && global->m_reads.empty()) + return true; uint32_t load = code_genstring(self->m_code.get(), global->m_constval.vstring); self->m_code->globals.push_back(load); } else {