Bug 538538 - lirasm: don't run the optimizers, except when using --random (NJ-specific part). r=graydon,stejohns.

--HG--
extra : convert_revision : 7ab1e0842f7dd1807c11578a34e5e95884a7e6dc
This commit is contained in:
Nicholas Nethercote 2010-01-15 08:59:19 +11:00
parent dd81027128
commit 04deac1562
4 changed files with 48 additions and 30 deletions

View File

@ -247,8 +247,8 @@ public:
Lirasm(bool verbose);
~Lirasm();
void assemble(istream &in);
void assembleRandom(int nIns);
void assemble(istream &in, bool optimize);
void assembleRandom(int nIns, bool optimize);
bool lookupFunction(const string &name, CallInfo *&ci);
LirBuffer *mLirbuf;
@ -273,7 +273,7 @@ private:
class FragmentAssembler {
public:
FragmentAssembler(Lirasm &parent, const string &fragmentName);
FragmentAssembler(Lirasm &parent, const string &fragmentName, bool optimize);
~FragmentAssembler();
void assembleFragment(LirTokenStream &in,
@ -293,6 +293,7 @@ private:
Lirasm &mParent;
const string mFragName;
Fragment *mFragment;
bool optimize;
vector<CallInfo*> mCallInfos;
map<string, LIns*> mLabels;
LirWriter *mLir;
@ -482,8 +483,8 @@ dump_srecords(ostream &, Fragment *)
uint32_t
FragmentAssembler::sProfId = 0;
FragmentAssembler::FragmentAssembler(Lirasm &parent, const string &fragmentName)
: mParent(parent), mFragName(fragmentName),
FragmentAssembler::FragmentAssembler(Lirasm &parent, const string &fragmentName, bool optimize)
: mParent(parent), mFragName(fragmentName), optimize(optimize),
mBufWriter(NULL), mCseFilter(NULL), mExprFilter(NULL), mVerboseWriter(NULL)
{
mFragment = new Fragment(NULL verbose_only(, (mParent.mLogc.lcbits &
@ -493,8 +494,10 @@ FragmentAssembler::FragmentAssembler(Lirasm &parent, const string &fragmentName)
mParent.mFragments[mFragName].fragptr = mFragment;
mLir = mBufWriter = new LirBufWriter(mParent.mLirbuf);
mLir = mCseFilter = new CseFilter(mLir, mParent.mAlloc);
mLir = mExprFilter = new ExprFilter(mLir);
if (optimize) {
mLir = mCseFilter = new CseFilter(mLir, mParent.mAlloc);
mLir = mExprFilter = new ExprFilter(mLir);
}
#ifdef DEBUG
if (mParent.mVerbose) {
@ -746,7 +749,7 @@ FragmentAssembler::endFragment()
mFragment->lastIns =
mLir->insGuard(LIR_x, NULL, createGuardRecord(createSideExit()));
::compile(&mParent.mAssm, mFragment, mParent.mAlloc
::compile(&mParent.mAssm, mFragment, mParent.mAlloc, optimize
verbose_only(, mParent.mLabelMap));
if (mParent.mAssm.error() != nanojit::None) {
@ -1915,7 +1918,7 @@ Lirasm::lookupFunction(const string &name, CallInfo *&ci)
}
void
Lirasm::assemble(istream &in)
Lirasm::assemble(istream &in, bool optimize)
{
LirTokenStream ts(in);
bool first = true;
@ -1938,13 +1941,13 @@ Lirasm::assemble(istream &in)
if (!ts.eat(NEWLINE))
bad("extra junk after .begin " + name);
FragmentAssembler assembler(*this, name);
FragmentAssembler assembler(*this, name, optimize);
assembler.assembleFragment(ts, false, NULL);
first = false;
} else if (op == ".end") {
bad(".end without .begin");
} else if (first) {
FragmentAssembler assembler(*this, "main");
FragmentAssembler assembler(*this, "main", optimize);
assembler.assembleFragment(ts, true, &token);
break;
} else {
@ -1954,10 +1957,10 @@ Lirasm::assemble(istream &in)
}
void
Lirasm::assembleRandom(int nIns)
Lirasm::assembleRandom(int nIns, bool optimize)
{
string name = "main";
FragmentAssembler assembler(*this, name);
FragmentAssembler assembler(*this, name, optimize);
assembler.assembleRandomFragment(nIns);
}
@ -1999,7 +2002,8 @@ usageAndQuit(const string& progname)
" -h --help print this message\n"
" -v --verbose print LIR and assembly code\n"
" --execute execute LIR\n"
" --random [N] generate a random LIR block of size N (default=100)\n"
" --[no-]optimize enable or disable optimization of the LIR (default=off)\n"
" --random [N] generate a random LIR block of size N (default=1000)\n"
" i386-specific options:\n"
" --sse use SSE2 instructions\n"
" ARM-specific options:\n"
@ -2020,6 +2024,7 @@ struct CmdLineOptions {
string progname;
bool verbose;
bool execute;
bool optimize;
int random;
string filename;
};
@ -2031,6 +2036,7 @@ processCmdLine(int argc, char **argv, CmdLineOptions& opts)
opts.verbose = false;
opts.execute = false;
opts.random = 0;
opts.optimize = false;
// Architecture-specific options.
#if defined NANOJIT_IA32
@ -2050,6 +2056,10 @@ processCmdLine(int argc, char **argv, CmdLineOptions& opts)
opts.verbose = true;
else if (arg == "--execute")
opts.execute = true;
else if (arg == "--optimize")
opts.optimize = true;
else if (arg == "--no-optimize")
opts.optimize = false;
else if (arg == "--random") {
const int defaultSize = 100;
if (i == argc - 1) {
@ -2068,6 +2078,7 @@ processCmdLine(int argc, char **argv, CmdLineOptions& opts)
}
}
}
// Architecture-specific flags.
#if defined NANOJIT_IA32
else if (arg == "--sse") {
@ -2131,12 +2142,12 @@ main(int argc, char **argv)
Lirasm lasm(opts.verbose);
if (opts.random) {
lasm.assembleRandom(opts.random);
lasm.assembleRandom(opts.random, opts.optimize);
} else {
ifstream in(opts.filename.c_str());
if (!in)
errMsgAndQuit(opts.progname, "unable to open file " + opts.filename);
lasm.assemble(in);
lasm.assemble(in, opts.optimize);
}
Fragments::const_iterator i;

View File

@ -13,10 +13,13 @@ do
exit 1
fi
# If it has the special name "random.in", replace filename with --random.
# Treat "random.in" and "random-opt.in" specially.
if [ `basename $infile` = "random.in" ]
then
infile="--random 1000000"
elif [ `basename $infile` = "random-opt.in" ]
then
infile="--random 1000000 --optimize"
fi
if ./lirasm --execute $infile | tr -d '\r' > testoutput.txt && cmp -s testoutput.txt $outfile

View File

@ -1441,7 +1441,7 @@ namespace nanojit
* if showLiveRefs == true, also print the set of live expressions next to
* each instruction
*/
void live(LirFilter* in, Allocator& alloc, Fragment *frag, LogControl *logc)
void live(LirFilter* in, Allocator& alloc, Fragment *frag, LogControl *logc, bool optimize)
{
// traverse backwards to find live exprs and a few other stats.
@ -2119,7 +2119,7 @@ namespace nanojit
return out->insCall(ci, args);
}
void compile(Assembler* assm, Fragment* frag, Allocator& alloc verbose_only(, LabelMap* labels))
void compile(Assembler* assm, Fragment* frag, Allocator& alloc, bool optimize verbose_only(, LabelMap* labels))
{
verbose_only(
LogControl *logc = assm->_logc;
@ -2145,7 +2145,7 @@ namespace nanojit
logc->printf("===\n");
LirReader br(frag->lastIns);
StackFilter sf(&br, alloc, frag->lirbuf, frag->lirbuf->sp, frag->lirbuf->rp);
live(&sf, alloc, frag, logc);
live(&sf, alloc, frag, logc, optimize);
})
/* Set up the generic text output cache for the assembler */
@ -2178,29 +2178,31 @@ namespace nanojit
LirReader bufreader(frag->lastIns);
// Used to construct the pipeline
LirFilter* prev = &bufreader;
LirFilter* lir = &bufreader;
// The LIR passes through these filters as listed in this
// function, viz, top to bottom.
// INITIAL PRINTING
verbose_only( if (assm->_logc->lcbits & LC_ReadLIR) {
pp_init = new (alloc) ReverseLister(prev, alloc, frag->lirbuf->names, assm->_logc,
pp_init = new (alloc) ReverseLister(lir, alloc, frag->lirbuf->names, assm->_logc,
"Initial LIR");
prev = pp_init;
lir = pp_init;
})
// STACKFILTER
StackFilter stackfilter(prev, alloc, frag->lirbuf, frag->lirbuf->sp, frag->lirbuf->rp);
prev = &stackfilter;
if (optimize) {
StackFilter stackfilter(lir, alloc, frag->lirbuf, frag->lirbuf->sp, frag->lirbuf->rp);
lir = &stackfilter;
}
verbose_only( if (assm->_logc->lcbits & LC_AfterSF) {
pp_after_sf = new (alloc) ReverseLister(prev, alloc, frag->lirbuf->names, assm->_logc,
pp_after_sf = new (alloc) ReverseLister(lir, alloc, frag->lirbuf->names, assm->_logc,
"After StackFilter");
prev = pp_after_sf;
lir = pp_after_sf;
})
assm->assemble(frag, prev);
assm->assemble(frag, lir);
// If we were accumulating debug info in the various ReverseListers,
// call finish() to emit whatever contents they have accumulated.
@ -2383,6 +2385,8 @@ namespace nanojit
va_start(vargs, format);
vfprintf(stdout, format, vargs);
va_end(vargs);
// Flush every line immediately so that if crashes occur in generated
// code we won't lose any output.
fflush(stdout);
}

View File

@ -1504,8 +1504,8 @@ namespace nanojit
class Assembler;
void compile(Assembler *assm, Fragment *frag, Allocator& alloc verbose_only(, LabelMap*));
verbose_only(void live(LirFilter* in, Allocator& alloc, Fragment* frag, LogControl*);)
void compile(Assembler *assm, Fragment *frag, Allocator& alloc, bool optimize verbose_only(, LabelMap*));
verbose_only(void live(LirFilter* in, Allocator& alloc, Fragment* frag, LogControl*, bool optimize);)
class StackFilter: public LirFilter
{