Commit b917c7a6 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Add the ability to use the LLVM "basic" register allocator

Controlled by the '-b' command-line flag.  That used to
be for "benchmark" mode but it looks like benchmark mode
has been broken for a while, so remove that.
parent d9e8427c
......@@ -86,7 +86,8 @@ For a full list, please check out the (Makefile)[https://github.com/dropbox/pyst
<dt>-v</dt>
<dd>Increase verbosity by 1</dd>
<dd>Pyston by default runs at verbosity 1, which contains a good amount of debugging information. Verbosity 0 contains no debugging information, and should produce the same results as other runtimes.</dd>
<dt>-s</dt>
<dd>Print out the internal stats at exit.</dd>
<dt>-n</dt>
<dd>Disable the Pyston interpreter. This is mostly used for debugging, to force the use of higher compilation tiers in situations they wouldn't typically be used.</dd>
......@@ -94,21 +95,20 @@ For a full list, please check out the (Makefile)[https://github.com/dropbox/pyst
<dt>-O</dt>
<dd>Force Pyston to always run at the highest compilation tier. This doesn't always produce the fastest running time due to the lack of type recording from lower compilation tiers, but similar to -n can help test the code generator.</dd>
<dt>-d</dt>
<dd>In addition to showing the generated LLVM IR, show the generated assembly code.</dd>
<dt>-i</dt>
<dd>Go into the repl after executing the given script.</dd>
<dt>-b</dt>
<dd>Benchmark mode: do whatever it would have been done, but do it 1000 times.</dd>
<dt>-p</dt>
<dd>Emit profiling information: at exit, Pyston will emit a dump of the code it generated for consumption by other tools.</dd>
<dt>-r</dt>
<dd>Use a stripped stdlib. When running pyston_dbg, the default is to use a stdlib with full debugging symbols enabled. Passing -r changes this behavior to load a slimmer, stripped stdlib.</dd>
<dt>-b</dt>
<dd>Experimental: use the LLVM "basic" register allocator.</dd>
<dt>-x</dt>
<dd>Experimental: use the pypa parser.</dd>
There are also some lesser-used flags; see src/jit.cpp for more details.
---
## Technical features
......
......@@ -123,7 +123,7 @@ make install
---
At this point you should be able to run `make check` (in the `~/pyston` directory) and pass the tests.
At this point you should be able to run `make check` (in the `~/pyston` directory) and pass the tests. See the main README for more information about available targets and options.
# Optional dependencies
......
......@@ -44,6 +44,11 @@
#include "core/util.h"
#include "runtime/types.h"
/*
* Include this file to force the linking of non-default algorithms, such as the "basic" register allocator
*/
#include "llvm/CodeGen/LinkAllCodegenComponents.h"
namespace pyston {
GlobalState g;
......@@ -265,26 +270,31 @@ void initCodegen() {
// signal(SIGFPE, &handle_sigfpe);
signal(SIGINT, &handle_sigint);
// There are some parts of llvm that are only configurable through command line args,
// so construct a fake argc/argv pair and pass it to the llvm command line machinery:
const char* llvm_args[] = {
"fake_name", "--enable-patchpoint-liveness",
std::vector<const char*> llvm_args = { "fake_name" };
llvm_args.push_back("--enable-patchpoint-liveness");
if (0) {
// Enabling and debugging fast-isel:
// llvm_args.push_back("--fast-isel");
// llvm_args.push_back("--fast-isel-verbose");
////llvm_args.push_back("--fast-isel-abort");
}
// Enabling and debugging fast-isel:
//"--fast-isel",
//"--fast-isel-verbose",
////"--fast-isel-abort",
#ifndef NDEBUG
//"--debug-only=debug-ir",
//"--debug-only=regalloc",
//"--debug-only=stackmaps",
// llvm_args.push_back("--debug-only=debug-ir");
// llvm_args.push_back("--debug-only=regalloc");
// llvm_args.push_back("--debug-only=stackmaps");
#endif
//"--print-after-all",
//"--print-machineinstrs",
//"--optimize-regalloc=false", // use the "fast" register allocator
};
int num_llvm_args = sizeof(llvm_args) / sizeof(llvm_args[0]);
llvm::cl::ParseCommandLineOptions(num_llvm_args, llvm_args, "<you should never see this>\n");
// llvm_args.push_back("--print-after-all");
// llvm_args.push_back("--print-machineinstrs");
if (USE_REGALLOC_BASIC)
llvm_args.push_back("--regalloc=basic");
llvm::cl::ParseCommandLineOptions(llvm_args.size(), &llvm_args[0], "<you should never see this>\n");
}
void teardownCodegen() {
......
......@@ -1221,15 +1221,6 @@ CompiledFunction* doCompile(SourceInfo* source, const OSREntryDescriptor* entry_
// fflush(stdout);
}
#ifndef NDEBUG
if (!BENCH) {
// Calling verifyFunction() confuses the profiler, which will end up attributing
// a large amount of runtime to it since the call stack looks very similar to
// the (expensive) case of compiling the function.
llvm::verifyFunction(*f);
}
#endif
irgen_us += _t2.split();
static StatCounter us_irgen("us_compiling_irgen");
us_irgen.log(irgen_us);
......
......@@ -28,13 +28,13 @@ int MAX_OPT_ITERATIONS = 1;
bool FORCE_OPTIMIZE = false;
bool SHOW_DISASM = false;
bool BENCH = false;
bool PROFILE = false;
bool DUMPJIT = false;
bool TRAP = false;
bool USE_STRIPPED_STDLIB = true; // always true
bool ENABLE_INTERPRETER = true;
bool ENABLE_PYPA_PARSER = false;
bool USE_REGALLOC_BASIC = false;
static bool _GLOBAL_ENABLE = 1;
bool ENABLE_ICS = 1 && _GLOBAL_ENABLE;
......
......@@ -30,8 +30,8 @@ inline int version_hex(int major, int minor, int micro, int level = 0, int seria
extern int MAX_OPT_ITERATIONS;
extern bool SHOW_DISASM, FORCE_OPTIMIZE, BENCH, PROFILE, DUMPJIT, TRAP, USE_STRIPPED_STDLIB, ENABLE_INTERPRETER,
ENABLE_PYPA_PARSER;
extern bool SHOW_DISASM, FORCE_OPTIMIZE, PROFILE, DUMPJIT, TRAP, USE_STRIPPED_STDLIB, ENABLE_INTERPRETER,
ENABLE_PYPA_PARSER, USE_REGALLOC_BASIC;
extern bool ENABLE_ICS, ENABLE_ICGENERICS, ENABLE_ICGETITEMS, ENABLE_ICSETITEMS, ENABLE_ICDELITEMS, ENABLE_ICBINEXPS,
ENABLE_ICNONZEROS, ENABLE_ICCALLSITES, ENABLE_ICSETATTRS, ENABLE_ICGETATTRS, ENALBE_ICDELATTRS, ENABLE_ICGETGLOBALS,
......
......@@ -72,9 +72,7 @@ int main(int argc, char** argv) {
SHOW_DISASM = true;
else if (code == 'i')
force_repl = true;
else if (code == 'b') {
BENCH = true;
} else if (code == 'n') {
else if (code == 'n') {
ENABLE_INTERPRETER = false;
} else if (code == 'p') {
PROFILE = true;
......@@ -84,6 +82,8 @@ int main(int argc, char** argv) {
stats = true;
} else if (code == 'r') {
USE_STRIPPED_STDLIB = true;
} else if (code == 'b') {
USE_REGALLOC_BASIC = true;
} else if (code == 'x') {
ENABLE_PYPA_PARSER = true;
} else if (code == '?')
......@@ -141,56 +141,15 @@ int main(int argc, char** argv) {
llvm::sys::path::remove_filename(path);
prependToSysPath(path.str());
int num_iterations = 1;
if (BENCH)
num_iterations = 1000;
try {
main_module = createAndRunModule("__main__", fn);
} catch (Box* b) {
std::string msg = formatException(b);
printLastTraceback();
fprintf(stderr, "%s\n", msg.c_str());
for (int i = 0; i < num_iterations; i++) {
try {
main_module = createAndRunModule("__main__", fn);
} catch (Box* b) {
std::string msg = formatException(b);
printLastTraceback();
fprintf(stderr, "%s\n", msg.c_str());
return 1;
}
}
}
if (repl && BENCH) {
if (!main_module) {
main_module = createModule("__main__", "<bench>");
} else {
main_module->fn = "<bench>";
return 1;
}
timeval start, end;
gettimeofday(&start, NULL);
const int MAX_RUNS = 1000;
const int MAX_TIME = 30;
int run = 0;
while (true) {
run++;
AST_Module* m = new AST_Module();
compileAndRunModule(m, main_module);
if (run >= MAX_RUNS) {
printf("Quitting after %d iterations\n", run);
break;
}
gettimeofday(&end, NULL);
if (end.tv_sec - start.tv_sec > MAX_TIME) {
printf("Quitting after %d seconds (%d iterations)\n", MAX_TIME, run);
break;
}
}
gettimeofday(&end, NULL);
long ms = 1000 * (end.tv_sec - start.tv_sec) + (end.tv_usec - start.tv_usec) / 1000;
printf("%ldms (%.2fms per)\n", ms, 1.0 * ms / run);
repl = force_repl;
}
if (repl) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment