Adding gflags to handle command line flags.

It sucks, but is the best there is without using boost.
This commit is contained in:
Ben Vanik
2013-01-23 21:31:23 -08:00
parent 01fee047f7
commit 860a0739ec
14 changed files with 183 additions and 35 deletions

View File

@@ -26,6 +26,8 @@
#include <xenia/cpu/ppc.h>
#include <xenia/cpu/codegen/function_generator.h>
#include "cpu/cpu-private.h"
using namespace llvm;
using namespace xe;
@@ -234,15 +236,15 @@ void ModuleGenerator::BuildFunction(CodegenFunction* cgf) {
void ModuleGenerator::OptimizeFunction(Module* m, Function* fn) {
FunctionPassManager pm(m);
#if XE_OPTION(OPTIMIZED)
PassManagerBuilder pmb;
pmb.OptLevel = 3;
pmb.SizeLevel = 0;
pmb.Inliner = createFunctionInliningPass();
pmb.Vectorize = true;
pmb.LoopVectorize = true;
pmb.populateFunctionPassManager(pm);
#endif // XE_OPTION(OPTIMIZED)
if (FLAGS_optimize_ir_functions) {
PassManagerBuilder pmb;
pmb.OptLevel = 3;
pmb.SizeLevel = 0;
pmb.Inliner = createFunctionInliningPass();
pmb.Vectorize = true;
pmb.LoopVectorize = true;
pmb.populateFunctionPassManager(pm);
}
pm.add(createVerifierPass());
pm.run(*fn);
}

24
src/cpu/cpu-private.h Normal file
View File

@@ -0,0 +1,24 @@
/**
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2013 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
#ifndef XENIA_CPU_PRIVATE_H_
#define XENIA_CPU_PRIVATE_H_
#include <gflags/gflags.h>
DECLARE_string(dump_path);
DECLARE_bool(dump_module_bitcode);
DECLARE_bool(dump_module_map);
DECLARE_bool(optimize_ir_modules);
DECLARE_bool(optimize_ir_functions);
#endif // XENIA_CPU_PRIVATE_H_

26
src/cpu/cpu.cc Normal file
View File

@@ -0,0 +1,26 @@
/**
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2013 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
#include "cpu/cpu-private.h"
// Dumping:
DEFINE_string(dump_path, "build/",
"Directory that dump files are placed into.");
DEFINE_bool(dump_module_bitcode, true,
"Writes the module bitcode both before and after optimizations.");
DEFINE_bool(dump_module_map, true,
"Dumps the module symbol database.");
// Optimizations:
DEFINE_bool(optimize_ir_modules, true,
"Whether to run LLVM optimizations on modules.");
DEFINE_bool(optimize_ir_functions, true,
"Whether to run LLVM optimizations on functions.");

View File

@@ -31,6 +31,7 @@
#include <xenia/cpu/codegen/module_generator.h>
#include <xenia/cpu/sdb.h>
#include "cpu/cpu-private.h"
#include "cpu/xethunk/xethunk.h"
@@ -67,6 +68,8 @@ int ExecModule::Prepare() {
int result_code = 1;
std::string error_message;
char file_name[2048];
OwningPtr<MemoryBuffer> shared_module_buffer;
auto_ptr<Module> shared_module;
auto_ptr<raw_ostream> outs;
@@ -80,7 +83,7 @@ int ExecModule::Prepare() {
// Calculate a cache path based on the module, the CPU version, and other
// bits.
// TODO(benvanik): cache path calculation.
const char *cache_path = "build/generated.bc";
//const char *cache_path = "build/generated.bc";
// Check the cache to see if the bitcode exists.
// If it does, load that module directly. In the future we could also cache
@@ -104,6 +107,13 @@ int ExecModule::Prepare() {
// Analyze the module and add its symbols to the symbol database.
XEEXPECTZERO(sdb_->Analyze());
// Dump the symbol database.
if (FLAGS_dump_module_map) {
xesnprintf(file_name, XECOUNT(file_name),
"%s%s.map", FLAGS_dump_path.c_str(), module_->name());
sdb_->Write(file_name);
}
// Initialize the module.
gen_module_ = shared_ptr<Module>(
new Module(module_->name(), *context_.get()));
@@ -126,13 +136,18 @@ int ExecModule::Prepare() {
context_.get(), gen_module_.get()));
XEEXPECTZERO(codegen_->Generate());
gen_module_->dump();
// Write to cache.
outs = auto_ptr<raw_ostream>(new raw_fd_ostream(
cache_path, error_message, raw_fd_ostream::F_Binary));
XEEXPECTTRUE(error_message.empty());
WriteBitcodeToFile(gen_module_.get(), *outs);
// TODO(benvanik): cache stuff
// Dump pre-optimized module to disk.
if (FLAGS_dump_module_bitcode) {
xesnprintf(file_name, XECOUNT(file_name),
"%s%s-preopt.bc", FLAGS_dump_path.c_str(), module_->name());
outs = auto_ptr<raw_ostream>(new raw_fd_ostream(
file_name, error_message, raw_fd_ostream::F_Binary));
XEEXPECTTRUE(error_message.empty());
WriteBitcodeToFile(gen_module_.get(), *outs);
}
}
// Link optimizations.
@@ -143,19 +158,29 @@ int ExecModule::Prepare() {
// Run full module optimizations.
pm.add(new DataLayout(gen_module_.get()));
#if XE_OPTION(OPTIMIZED)
pm.add(createVerifierPass());
pmb.OptLevel = 3;
pmb.SizeLevel = 0;
pmb.Inliner = createFunctionInliningPass();
pmb.Vectorize = true;
pmb.LoopVectorize = true;
pmb.populateModulePassManager(pm);
pmb.populateLTOPassManager(pm, false, true);
#endif // XE_OPTION(OPTIMIZED)
if (FLAGS_optimize_ir_modules) {
pm.add(createVerifierPass());
pmb.OptLevel = 3;
pmb.SizeLevel = 0;
pmb.Inliner = createFunctionInliningPass();
pmb.Vectorize = true;
pmb.LoopVectorize = true;
pmb.populateModulePassManager(pm);
pmb.populateLTOPassManager(pm, false, true);
}
pm.add(createVerifierPass());
pm.run(*gen_module_);
// Dump post-optimized module to disk.
if (FLAGS_optimize_ir_modules && FLAGS_dump_module_bitcode) {
xesnprintf(file_name, XECOUNT(file_name),
"%s%s.bc", FLAGS_dump_path.c_str(), module_->name());
outs = auto_ptr<raw_ostream>(new raw_fd_ostream(
file_name, error_message, raw_fd_ostream::F_Binary));
XEEXPECTTRUE(error_message.empty());
WriteBitcodeToFile(gen_module_.get(), *outs);
}
// TODO(benvanik): experiment with LLD to see if we can write out a dll.
// Initialize the module.
@@ -225,6 +250,6 @@ int ExecModule::Uninit() {
}
void ExecModule::Dump() {
// sdb_->Dump();
// gen_module_->dump();
sdb_->Dump();
gen_module_->dump();
}

View File

@@ -241,6 +241,10 @@ int SymbolDatabase::GetAllFunctions(vector<FunctionSymbol*>& functions) {
return 0;
}
void SymbolDatabase::Write(const char* file_name) {
// TODO(benvanik): write to file.
}
void SymbolDatabase::Dump() {
uint32_t previous = 0;
for (SymbolMap::iterator it = symbols_.begin(); it != symbols_.end(); ++it) {

View File

@@ -1,6 +1,7 @@
# Copyright 2013 Ben Vanik. All Rights Reserved.
{
'sources': [
'cpu.cc',
'exec_module.cc',
'processor.cc',
'sdb.cc',