# HG changeset patch # User Frits van Bommel # Date 1236863337 -3600 # Node ID 8bf8b058944a05a7354b3a69af49b4401e31b108 # Parent b3a0cf072ed0e5284d00bbc300ce1f2fa9215228 Clean up asm code a bit. - Use vector instead of Array, reducing allocations. - Use vectors instead of deques since we only push_back and index. - Remove redundant typedefs of iterators. - Comment out unused variable (used only in commented-out GDC code). - A few whitespace changes. diff -r b3a0cf072ed0 -r 8bf8b058944a gen/asm-x86-32.h --- a/gen/asm-x86-32.h Thu Mar 12 14:08:57 2009 +0100 +++ b/gen/asm-x86-32.h Thu Mar 12 14:08:57 2009 +0100 @@ -459,12 +459,12 @@ /* Op_FfdR */ { D|rfp, 0, 0 }, /* Op_Ffd_P */ { D|mfp, 0, 0, FP_Types, Clb_ST, Next_Form, Op_FfdR_P }, // pop, fld so also 80 bit, " /* Op_FfdR_P */ { D|rfp, 0, 0, 0, Clb_ST, Next_Form, Op_FfdRR_P }, - /* Op_FfdRR_P */ { D|mfp|rfp,rfp,0, 0, Clb_ST }, + /* Op_FfdRR_P */ { D|mfp|rfp,rfp,0, 0, Clb_ST }, /* Op_Fd_P */ { D|mem, 0, 0, 0, Clb_ST }, // " /* Op_FdST */ { D|rfp, 0, 0 }, /* Op_FMath */ { mfp, 0, 0, FP_Types, Clb_ST, Next_Form, Op_FMath0 }, // and only single or double prec - /* Op_FMath0 */ { 0, 0, 0, 0, Clb_ST, Next_Form, Op_FMath2 }, - /* Op_FMath2 */ { D|rfp, rfp, 0, 0, Clb_ST, Next_Form, Op_FdST0ST1 }, + /* Op_FMath0 */ { 0, 0, 0, 0, Clb_ST, Next_Form, Op_FMath2 }, + /* Op_FMath2 */ { D|rfp, rfp, 0, 0, Clb_ST, Next_Form, Op_FdST0ST1 }, /* Op_FdSTiSTi */ { D|rfp, rfp, 0, }, /* Op_FdST0ST1 */ { 0, 0, 0, }, /* Op_FPMath */ { D|rfp, rfp, 0, 0, Clb_ST, Next_Form, Op_F0_P }, // pops @@ -1555,17 +1555,17 @@ else { insnTemplate->writestring ( ( char* ) fmt ); - insnTemplate->printf ( "<<%s%d>>", ( mode==Mode_Input ) ?"in":"out", asmcode->args.dim ); - asmcode->args.push ( new AsmArg ( type, e, mode ) ); + insnTemplate->printf ( "<<%s%d>>", ( mode==Mode_Input ) ?"in":"out", asmcode->args.size() ); + asmcode->args.push_back ( AsmArg ( type, e, mode ) ); } } void addOperand2 ( const char * fmtpre, const char * fmtpost, AsmArgType type, Expression * e, AsmCode * asmcode, AsmArgMode mode = Mode_Input ) { assert ( !sc->func->naked ); insnTemplate->writestring ( ( char* ) fmtpre ); - insnTemplate->printf ( "<<%s%d>>", ( mode==Mode_Input ) ?"in":"out", asmcode->args.dim ); + insnTemplate->printf ( "<<%s%d>>", ( mode==Mode_Input ) ?"in":"out", asmcode->args.size() ); insnTemplate->writestring ( ( char* ) fmtpost ); - asmcode->args.push ( new AsmArg ( type, e, mode ) ); + asmcode->args.push_back ( AsmArg ( type, e, mode ) ); } void addLabel ( char* id ) diff -r b3a0cf072ed0 -r 8bf8b058944a gen/asm-x86-64.h --- a/gen/asm-x86-64.h Thu Mar 12 14:08:57 2009 +0100 +++ b/gen/asm-x86-64.h Thu Mar 12 14:08:57 2009 +0100 @@ -533,12 +533,12 @@ /* Op_FfdR */ { D|rfp, 0, 0 }, /* Op_Ffd_P */ { D|mfp, 0, 0, FP_Types, Clb_ST, Next_Form, Op_FfdR_P }, // pop, fld so also 80 bit, " /* Op_FfdR_P */ { D|rfp, 0, 0, 0, Clb_ST, Next_Form, Op_FfdRR_P }, - /* Op_FfdRR_P */ { D|mfp|rfp,rfp,0, 0, Clb_ST }, + /* Op_FfdRR_P */ { D|mfp|rfp,rfp,0, 0, Clb_ST }, /* Op_Fd_P */ { D|mem, 0, 0, 0, Clb_ST }, // " /* Op_FdST */ { D|rfp, 0, 0 }, /* Op_FMath */ { mfp, 0, 0, FP_Types, Clb_ST, Next_Form, Op_FMath0 }, // and only single or double prec /* Op_FMath0 */ { 0, 0, 0, 0, Clb_ST, Next_Form, Op_FMath2 }, // pops - /* Op_FMath2 */ { D|rfp, rfp, 0, 0, Clb_ST, Next_Form, Op_FdST0ST1 }, // and only single or double prec + /* Op_FMath2 */ { D|rfp, rfp, 0, 0, Clb_ST, Next_Form, Op_FdST0ST1 }, // and only single or double prec /* Op_FdSTiSTi */ { D|rfp, rfp, 0, }, /* Op_FdST0ST1 */ { 0, 0, 0, }, /* Op_FPMath */ { D|rfp, rfp, 0, 0, Clb_ST, Next_Form, Op_F0_P }, // pops @@ -1677,17 +1677,17 @@ else { insnTemplate->writestring ( ( char* ) fmt ); - insnTemplate->printf ( "<<%s%d>>", ( mode==Mode_Input ) ?"in":"out", asmcode->args.dim ); - asmcode->args.push ( new AsmArg ( type, e, mode ) ); + insnTemplate->printf ( "<<%s%d>>", ( mode==Mode_Input ) ?"in":"out", asmcode->args.size() ); + asmcode->args.push_back ( AsmArg ( type, e, mode ) ); } } void addOperand2 ( const char * fmtpre, const char * fmtpost, AsmArgType type, Expression * e, AsmCode * asmcode, AsmArgMode mode = Mode_Input ) { assert ( !sc->func->naked ); insnTemplate->writestring ( ( char* ) fmtpre ); - insnTemplate->printf ( "<<%s%d>>", ( mode==Mode_Input ) ?"in":"out", asmcode->args.dim ); + insnTemplate->printf ( "<<%s%d>>", ( mode==Mode_Input ) ?"in":"out", asmcode->args.size() ); insnTemplate->writestring ( ( char* ) fmtpost ); - asmcode->args.push ( new AsmArg ( type, e, mode ) ); + asmcode->args.push_back ( AsmArg ( type, e, mode ) ); } void addLabel ( char* id ) diff -r b3a0cf072ed0 -r 8bf8b058944a gen/asmstmt.cpp --- a/gen/asmstmt.cpp Thu Mar 12 14:08:57 2009 +0100 +++ b/gen/asmstmt.cpp Thu Mar 12 14:08:57 2009 +0100 @@ -43,8 +43,8 @@ } AsmArgMode; struct AsmArg { + Expression * expr; AsmArgType type; - Expression * expr; AsmArgMode mode; AsmArg(AsmArgType type, Expression * expr, AsmArgMode mode) { this->type = type; @@ -56,7 +56,7 @@ struct AsmCode { char * insnTemplate; unsigned insnTemplateLen; - Array args; // of AsmArg + std::vector args; std::vector regs; unsigned dollarLabel; int clobbersMemory; @@ -212,25 +212,24 @@ static std::string memory_name = "memory"; AsmCode * code = (AsmCode *) asmcode; - std::deque input_values; - std::deque input_constraints; - std::deque output_values; - std::deque output_constraints; - std::deque clobbers; + std::vector input_values; + std::vector input_constraints; + std::vector output_values; + std::vector output_constraints; + std::vector clobbers; // FIXME - #define HOST_WIDE_INT long - HOST_WIDE_INT var_frame_offset; // "frame_offset" is a macro + //#define HOST_WIDE_INT long + //HOST_WIDE_INT var_frame_offset; // "frame_offset" is a macro bool clobbers_mem = code->clobbersMemory; int input_idx = 0; int n_outputs = 0; int arg_map[10]; - assert(code->args.dim <= 10); + assert(code->args.size() <= 10); - for (unsigned i = 0; i < code->args.dim; i++) { - AsmArg * arg = (AsmArg *) code->args.data[i]; - + std::vector::iterator arg = code->args.begin(); + for (unsigned i = 0; i < code->args.size(); i++, ++arg) { bool is_input = true; LLValue* arg_val = 0; std::string cns; @@ -290,12 +289,10 @@ if (is_input) { arg_map[i] = --input_idx; - //inputs.cons(tree_cons(NULL_TREE, cns, NULL_TREE), arg_val); input_values.push_back(arg_val); input_constraints.push_back(cns); } else { arg_map[i] = n_outputs++; - //outputs.cons(tree_cons(NULL_TREE, cns, NULL_TREE), arg_val); output_values.push_back(arg_val); output_constraints.push_back(cns); } @@ -310,18 +307,16 @@ assert(asmparser); for (int i = 0; i < code->regs.size(); i++) { if (code->regs[i]) { - //clobbers.cons(NULL_TREE, regInfo[i].gccName); clobbers.push_back(asmparser->getRegName(i)); } } if (clobbers_mem) clobbers.push_back(memory_name); - //clobbers.cons(NULL_TREE, memory_name); // } // Remap argument numbers - for (unsigned i = 0; i < code->args.dim; i++) { + for (unsigned i = 0; i < code->args.size(); i++) { if (arg_map[i] < 0) arg_map[i] = -arg_map[i] - 1 + n_outputs; } @@ -345,12 +340,12 @@ ++p; } + typedef std::vector::iterator It; if (Logger::enabled()) { Logger::println("final asm: %.*s", code->insnTemplateLen, code->insnTemplate); std::ostringstream ss; ss << "GCC-style output constraints: {"; - typedef std::deque::iterator It; for (It i = output_constraints.begin(), e = output_constraints.end(); i != e; ++i) { ss << " " << *i; } @@ -380,8 +375,7 @@ std::string llvmOutConstraints; std::string llvmInConstraints; int n = 0; - typedef std::deque::iterator it; - for(it i = output_constraints.begin(), e = output_constraints.end(); i != e; ++i, ++n) { + for(It i = output_constraints.begin(), e = output_constraints.end(); i != e; ++i, ++n) { // rewrite update constraint to in and out constraints if((*i)[0] == '+') { assert(*i == mrw_cns && "What else are we updating except memory?"); @@ -404,19 +398,19 @@ } asmblock->outputcount += n; - for(it i = input_constraints.begin(), e = input_constraints.end(); i != e; ++i) { + for(It i = input_constraints.begin(), e = input_constraints.end(); i != e; ++i) { llvmInConstraints += *i; llvmInConstraints += ","; } std::string clobstr; - for(it i = clobbers.begin(), e = clobbers.end(); i != e; ++i) { + for(It i = clobbers.begin(), e = clobbers.end(); i != e; ++i) { clobstr = "~{" + *i + "},"; asmblock->clobs.insert(clobstr); } if (Logger::enabled()) { - typedef std::deque::iterator It; + typedef std::vector::iterator It; { Logger::println("Output values:"); LOG_SCOPE