Prepping for basic block generation.
This commit is contained in:
parent
33e2bc01ee
commit
dad99769cb
|
@ -172,9 +172,9 @@ XEEMITTER(addx, 0x7C000214, XO )(LibjitEmitter& e, jit_function_t f, Ins
|
||||||
// // Note that we skip the zero handling block and just avoid the divide if
|
// // Note that we skip the zero handling block and just avoid the divide if
|
||||||
// // we are OE=0.
|
// // we are OE=0.
|
||||||
// BasicBlock* zero_bb = i.XO.OE ?
|
// BasicBlock* zero_bb = i.XO.OE ?
|
||||||
// BasicBlock::Create(*e.context(), "", e.gen_fn()) : NULL;
|
// BasicBlock::Create(*e.context(), "", e.fn()) : NULL;
|
||||||
// BasicBlock* nonzero_bb = BasicBlock::Create(*e.context(), "", e.gen_fn());
|
// BasicBlock* nonzero_bb = BasicBlock::Create(*e.context(), "", e.fn());
|
||||||
// BasicBlock* after_bb = BasicBlock::Create(*e.context(), "", e.gen_fn());
|
// BasicBlock* after_bb = BasicBlock::Create(*e.context(), "", e.fn());
|
||||||
// b.CreateCondBr(b.CreateICmpEQ(divisor, b.getInt32(0)),
|
// b.CreateCondBr(b.CreateICmpEQ(divisor, b.getInt32(0)),
|
||||||
// i.XO.OE ? zero_bb : after_bb, nonzero_bb);
|
// i.XO.OE ? zero_bb : after_bb, nonzero_bb);
|
||||||
//
|
//
|
||||||
|
@ -225,9 +225,9 @@ XEEMITTER(addx, 0x7C000214, XO )(LibjitEmitter& e, jit_function_t f, Ins
|
||||||
// // Note that we skip the zero handling block and just avoid the divide if
|
// // Note that we skip the zero handling block and just avoid the divide if
|
||||||
// // we are OE=0.
|
// // we are OE=0.
|
||||||
// BasicBlock* zero_bb = i.XO.OE ?
|
// BasicBlock* zero_bb = i.XO.OE ?
|
||||||
// BasicBlock::Create(*e.context(), "", e.gen_fn()) : NULL;
|
// BasicBlock::Create(*e.context(), "", e.fn()) : NULL;
|
||||||
// BasicBlock* nonzero_bb = BasicBlock::Create(*e.context(), "", e.gen_fn());
|
// BasicBlock* nonzero_bb = BasicBlock::Create(*e.context(), "", e.fn());
|
||||||
// BasicBlock* after_bb = BasicBlock::Create(*e.context(), "", e.gen_fn());
|
// BasicBlock* after_bb = BasicBlock::Create(*e.context(), "", e.fn());
|
||||||
// b.CreateCondBr(b.CreateICmpEQ(divisor, b.getInt32(0)),
|
// b.CreateCondBr(b.CreateICmpEQ(divisor, b.getInt32(0)),
|
||||||
// i.XO.OE ? zero_bb : after_bb, nonzero_bb);
|
// i.XO.OE ? zero_bb : after_bb, nonzero_bb);
|
||||||
//
|
//
|
||||||
|
@ -654,7 +654,7 @@ XEEMITTER(addx, 0x7C000214, XO )(LibjitEmitter& e, jit_function_t f, Ins
|
||||||
// std::vector<Type*> arg_types;
|
// std::vector<Type*> arg_types;
|
||||||
// arg_types.push_back(b.getInt32Ty());
|
// arg_types.push_back(b.getInt32Ty());
|
||||||
// Function* ctlz = Intrinsic::getDeclaration(
|
// Function* ctlz = Intrinsic::getDeclaration(
|
||||||
// e.gen_fn()->getParent(), Intrinsic::ctlz, arg_types);
|
// e.fn()->getParent(), Intrinsic::ctlz, arg_types);
|
||||||
// Value* count = b.CreateCall2(ctlz, v, b.getInt1(1));
|
// Value* count = b.CreateCall2(ctlz, v, b.getInt1(1));
|
||||||
//
|
//
|
||||||
// count = b.CreateZExt(count, b.getInt64Ty());
|
// count = b.CreateZExt(count, b.getInt64Ty());
|
||||||
|
|
|
@ -50,8 +50,8 @@ namespace libjit {
|
||||||
// if (!lk && reg == kXEPPCRegLR) {
|
// if (!lk && reg == kXEPPCRegLR) {
|
||||||
// BasicBlock* next_block = e.GetNextBasicBlock();
|
// BasicBlock* next_block = e.GetNextBasicBlock();
|
||||||
// BasicBlock* mismatch_bb = BasicBlock::Create(*e.context(), "lr_mismatch",
|
// BasicBlock* mismatch_bb = BasicBlock::Create(*e.context(), "lr_mismatch",
|
||||||
// e.gen_fn(), next_block);
|
// e.fn(), next_block);
|
||||||
// Value* lr_cmp = b.CreateICmpEQ(target, ++(e.gen_fn()->arg_begin()));
|
// Value* lr_cmp = b.CreateICmpEQ(target, ++(e.fn()->arg_begin()));
|
||||||
// // The return block will spill registers for us.
|
// // The return block will spill registers for us.
|
||||||
// b.CreateCondBr(lr_cmp, e.GetReturnBasicBlock(), mismatch_bb);
|
// b.CreateCondBr(lr_cmp, e.GetReturnBasicBlock(), mismatch_bb);
|
||||||
// b.SetInsertPoint(mismatch_bb);
|
// b.SetInsertPoint(mismatch_bb);
|
||||||
|
@ -85,7 +85,7 @@ namespace libjit {
|
||||||
|
|
||||||
// XEASSERTNOTNULL(fn_block->outgoing_function);
|
// XEASSERTNOTNULL(fn_block->outgoing_function);
|
||||||
// Function* target_fn = e.GetFunction(fn_block->outgoing_function);
|
// Function* target_fn = e.GetFunction(fn_block->outgoing_function);
|
||||||
// Function::arg_iterator args = e.gen_fn()->arg_begin();
|
// Function::arg_iterator args = e.fn()->arg_begin();
|
||||||
// Value* state_ptr = args;
|
// Value* state_ptr = args;
|
||||||
// BasicBlock* next_bb = e.GetNextBasicBlock();
|
// BasicBlock* next_bb = e.GetNextBasicBlock();
|
||||||
// if (!lk || !next_bb) {
|
// if (!lk || !next_bb) {
|
||||||
|
@ -215,7 +215,7 @@ namespace libjit {
|
||||||
// char name[32];
|
// char name[32];
|
||||||
// xesnprintfa(name, XECOUNT(name), "loc_%.8X_bcx", i.address);
|
// xesnprintfa(name, XECOUNT(name), "loc_%.8X_bcx", i.address);
|
||||||
// BasicBlock* next_block = e.GetNextBasicBlock();
|
// BasicBlock* next_block = e.GetNextBasicBlock();
|
||||||
// BasicBlock* branch_bb = BasicBlock::Create(*e.context(), name, e.gen_fn(),
|
// BasicBlock* branch_bb = BasicBlock::Create(*e.context(), name, e.fn(),
|
||||||
// next_block);
|
// next_block);
|
||||||
|
|
||||||
// b.CreateCondBr(ok, branch_bb, next_block);
|
// b.CreateCondBr(ok, branch_bb, next_block);
|
||||||
|
@ -281,7 +281,7 @@ namespace libjit {
|
||||||
// xesnprintfa(name, XECOUNT(name), "loc_%.8X_bcctrx", i.address);
|
// xesnprintfa(name, XECOUNT(name), "loc_%.8X_bcctrx", i.address);
|
||||||
// BasicBlock* next_block = e.GetNextBasicBlock();
|
// BasicBlock* next_block = e.GetNextBasicBlock();
|
||||||
// XEASSERTNOTNULL(next_block);
|
// XEASSERTNOTNULL(next_block);
|
||||||
// BasicBlock* branch_bb = BasicBlock::Create(*e.context(), name, e.gen_fn(),
|
// BasicBlock* branch_bb = BasicBlock::Create(*e.context(), name, e.fn(),
|
||||||
// next_block);
|
// next_block);
|
||||||
|
|
||||||
// b.CreateCondBr(ok, branch_bb, next_block);
|
// b.CreateCondBr(ok, branch_bb, next_block);
|
||||||
|
@ -364,7 +364,7 @@ namespace libjit {
|
||||||
// xesnprintfa(name, XECOUNT(name), "loc_%.8X_bclrx", i.address);
|
// xesnprintfa(name, XECOUNT(name), "loc_%.8X_bclrx", i.address);
|
||||||
// BasicBlock* next_block = e.GetNextBasicBlock();
|
// BasicBlock* next_block = e.GetNextBasicBlock();
|
||||||
// XEASSERTNOTNULL(next_block);
|
// XEASSERTNOTNULL(next_block);
|
||||||
// BasicBlock* branch_bb = BasicBlock::Create(*e.context(), name, e.gen_fn(),
|
// BasicBlock* branch_bb = BasicBlock::Create(*e.context(), name, e.fn(),
|
||||||
// next_block);
|
// next_block);
|
||||||
|
|
||||||
// b.CreateCondBr(ok, branch_bb, next_block);
|
// b.CreateCondBr(ok, branch_bb, next_block);
|
||||||
|
@ -455,27 +455,27 @@ namespace libjit {
|
||||||
// return 0;
|
// return 0;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// BasicBlock* after_bb = BasicBlock::Create(*e.context(), "", e.gen_fn(),
|
// BasicBlock* after_bb = BasicBlock::Create(*e.context(), "", e.fn(),
|
||||||
// e.GetNextBasicBlock());
|
// e.GetNextBasicBlock());
|
||||||
// BasicBlock* trap_bb = BasicBlock::Create(*e.context(), "", e.gen_fn(),
|
// BasicBlock* trap_bb = BasicBlock::Create(*e.context(), "", e.fn(),
|
||||||
// after_bb);
|
// after_bb);
|
||||||
|
|
||||||
// // Create the basic blocks (so we can chain).
|
// // Create the basic blocks (so we can chain).
|
||||||
// std::vector<BasicBlock*> bbs;
|
// std::vector<BasicBlock*> bbs;
|
||||||
// if (TO & (1 << 4)) {
|
// if (TO & (1 << 4)) {
|
||||||
// bbs.push_back(BasicBlock::Create(*e.context(), "", e.gen_fn(), trap_bb));
|
// bbs.push_back(BasicBlock::Create(*e.context(), "", e.fn(), trap_bb));
|
||||||
// }
|
// }
|
||||||
// if (TO & (1 << 3)) {
|
// if (TO & (1 << 3)) {
|
||||||
// bbs.push_back(BasicBlock::Create(*e.context(), "", e.gen_fn(), trap_bb));
|
// bbs.push_back(BasicBlock::Create(*e.context(), "", e.fn(), trap_bb));
|
||||||
// }
|
// }
|
||||||
// if (TO & (1 << 2)) {
|
// if (TO & (1 << 2)) {
|
||||||
// bbs.push_back(BasicBlock::Create(*e.context(), "", e.gen_fn(), trap_bb));
|
// bbs.push_back(BasicBlock::Create(*e.context(), "", e.fn(), trap_bb));
|
||||||
// }
|
// }
|
||||||
// if (TO & (1 << 1)) {
|
// if (TO & (1 << 1)) {
|
||||||
// bbs.push_back(BasicBlock::Create(*e.context(), "", e.gen_fn(), trap_bb));
|
// bbs.push_back(BasicBlock::Create(*e.context(), "", e.fn(), trap_bb));
|
||||||
// }
|
// }
|
||||||
// if (TO & (1 << 0)) {
|
// if (TO & (1 << 0)) {
|
||||||
// bbs.push_back(BasicBlock::Create(*e.context(), "", e.gen_fn(), trap_bb));
|
// bbs.push_back(BasicBlock::Create(*e.context(), "", e.fn(), trap_bb));
|
||||||
// }
|
// }
|
||||||
// bbs.push_back(after_bb);
|
// bbs.push_back(after_bb);
|
||||||
|
|
||||||
|
@ -525,7 +525,7 @@ namespace libjit {
|
||||||
// e.SpillRegisters();
|
// e.SpillRegisters();
|
||||||
// // TODO(benvanik): use @llvm.debugtrap? could make debugging better
|
// // TODO(benvanik): use @llvm.debugtrap? could make debugging better
|
||||||
// b.CreateCall2(e.gen_module()->getFunction("XeTrap"),
|
// b.CreateCall2(e.gen_module()->getFunction("XeTrap"),
|
||||||
// e.gen_fn()->arg_begin(),
|
// e.fn()->arg_begin(),
|
||||||
// b.getInt32(i.address));
|
// b.getInt32(i.address));
|
||||||
// b.CreateBr(after_bb);
|
// b.CreateBr(after_bb);
|
||||||
|
|
||||||
|
|
|
@ -117,10 +117,6 @@ jit_context_t LibjitEmitter::context() {
|
||||||
return context_;
|
return context_;
|
||||||
}
|
}
|
||||||
|
|
||||||
jit_type_t LibjitEmitter::fn_signature() {
|
|
||||||
return fn_signature_;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
int libjit_on_demand_compile(jit_function_t fn) {
|
int libjit_on_demand_compile(jit_function_t fn) {
|
||||||
LibjitEmitter* emitter = (LibjitEmitter*)jit_function_get_meta(fn, 0x1000);
|
LibjitEmitter* emitter = (LibjitEmitter*)jit_function_get_meta(fn, 0x1000);
|
||||||
|
@ -162,11 +158,11 @@ int LibjitEmitter::PrepareFunction(FunctionSymbol* symbol) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int LibjitEmitter::MakeFunction(FunctionSymbol* symbol, jit_function_t gen_fn) {
|
int LibjitEmitter::MakeFunction(FunctionSymbol* symbol, jit_function_t fn) {
|
||||||
fn_ = symbol;
|
symbol_ = symbol;
|
||||||
gen_fn_ = gen_fn;
|
fn_ = fn;
|
||||||
|
|
||||||
// fn_block_ = NULL;
|
// symbol_block_ = NULL;
|
||||||
// return_block_ = NULL;
|
// return_block_ = NULL;
|
||||||
// internal_indirection_block_ = NULL;
|
// internal_indirection_block_ = NULL;
|
||||||
// external_indirection_block_ = NULL;
|
// external_indirection_block_ = NULL;
|
||||||
|
@ -220,10 +216,10 @@ int LibjitEmitter::MakeFunction(FunctionSymbol* symbol, jit_function_t gen_fn) {
|
||||||
if (!result_code) {
|
if (!result_code) {
|
||||||
// TODO(benvanik): flag
|
// TODO(benvanik): flag
|
||||||
// pre
|
// pre
|
||||||
jit_dump_function(stdout, gen_fn_, symbol->name());
|
jit_dump_function(stdout, fn_, symbol->name());
|
||||||
jit_function_compile(gen_fn_);
|
jit_function_compile(fn_);
|
||||||
// post
|
// post
|
||||||
jit_dump_function(stdout, gen_fn_, symbol->name());
|
jit_dump_function(stdout, fn_, symbol->name());
|
||||||
}
|
}
|
||||||
|
|
||||||
return result_code;
|
return result_code;
|
||||||
|
@ -232,15 +228,15 @@ int LibjitEmitter::MakeFunction(FunctionSymbol* symbol, jit_function_t gen_fn) {
|
||||||
int LibjitEmitter::MakeUserFunction() {
|
int LibjitEmitter::MakeUserFunction() {
|
||||||
if (FLAGS_trace_user_calls) {
|
if (FLAGS_trace_user_calls) {
|
||||||
jit_value_t trace_args[] = {
|
jit_value_t trace_args[] = {
|
||||||
jit_value_get_param(gen_fn_, 0),
|
jit_value_get_param(fn_, 0),
|
||||||
jit_value_create_long_constant(gen_fn_, jit_type_ulong,
|
jit_value_create_long_constant(fn_, jit_type_ulong,
|
||||||
(jit_ulong)fn_->start_address),
|
(jit_ulong)symbol_->start_address),
|
||||||
jit_value_get_param(gen_fn_, 1),
|
jit_value_get_param(fn_, 1),
|
||||||
jit_value_create_long_constant(gen_fn_, jit_type_ulong,
|
jit_value_create_long_constant(fn_, jit_type_ulong,
|
||||||
(jit_ulong)fn_),
|
(jit_ulong)symbol_),
|
||||||
};
|
};
|
||||||
jit_insn_call_native(
|
jit_insn_call_native(
|
||||||
gen_fn_,
|
fn_,
|
||||||
"XeTraceUserCall",
|
"XeTraceUserCall",
|
||||||
global_exports_.XeTraceUserCall,
|
global_exports_.XeTraceUserCall,
|
||||||
global_export_signature_4_,
|
global_export_signature_4_,
|
||||||
|
@ -250,22 +246,22 @@ int LibjitEmitter::MakeUserFunction() {
|
||||||
|
|
||||||
// Emit.
|
// Emit.
|
||||||
//emitter_->GenerateBasicBlocks();
|
//emitter_->GenerateBasicBlocks();
|
||||||
jit_insn_return(gen_fn_, NULL);
|
jit_insn_return(fn_, NULL);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int LibjitEmitter::MakePresentImportFunction() {
|
int LibjitEmitter::MakePresentImportFunction() {
|
||||||
if (FLAGS_trace_kernel_calls) {
|
if (FLAGS_trace_kernel_calls) {
|
||||||
jit_value_t trace_args[] = {
|
jit_value_t trace_args[] = {
|
||||||
jit_value_get_param(gen_fn_, 0),
|
jit_value_get_param(fn_, 0),
|
||||||
jit_value_create_long_constant(gen_fn_, jit_type_ulong,
|
jit_value_create_long_constant(fn_, jit_type_ulong,
|
||||||
(jit_ulong)fn_->start_address),
|
(jit_ulong)symbol_->start_address),
|
||||||
jit_value_get_param(gen_fn_, 1),
|
jit_value_get_param(fn_, 1),
|
||||||
jit_value_create_long_constant(gen_fn_, jit_type_ulong,
|
jit_value_create_long_constant(fn_, jit_type_ulong,
|
||||||
(jit_ulong)fn_->kernel_export),
|
(jit_ulong)symbol_->kernel_export),
|
||||||
};
|
};
|
||||||
jit_insn_call_native(
|
jit_insn_call_native(
|
||||||
gen_fn_,
|
fn_,
|
||||||
"XeTraceKernelCall",
|
"XeTraceKernelCall",
|
||||||
global_exports_.XeTraceKernelCall,
|
global_exports_.XeTraceKernelCall,
|
||||||
global_export_signature_4_,
|
global_export_signature_4_,
|
||||||
|
@ -275,19 +271,19 @@ int LibjitEmitter::MakePresentImportFunction() {
|
||||||
|
|
||||||
// void shim(ppc_state*, shim_data*)
|
// void shim(ppc_state*, shim_data*)
|
||||||
jit_value_t shim_args[] = {
|
jit_value_t shim_args[] = {
|
||||||
jit_value_get_param(gen_fn_, 0),
|
jit_value_get_param(fn_, 0),
|
||||||
jit_value_create_long_constant(gen_fn_, jit_type_ulong,
|
jit_value_create_long_constant(fn_, jit_type_ulong,
|
||||||
(jit_ulong)fn_->kernel_export->function_data.shim_data),
|
(jit_ulong)symbol_->kernel_export->function_data.shim_data),
|
||||||
};
|
};
|
||||||
jit_insn_call_native(
|
jit_insn_call_native(
|
||||||
gen_fn_,
|
fn_,
|
||||||
fn_->kernel_export->name,
|
symbol_->kernel_export->name,
|
||||||
fn_->kernel_export->function_data.shim,
|
symbol_->kernel_export->function_data.shim,
|
||||||
shim_signature_,
|
shim_signature_,
|
||||||
shim_args, XECOUNT(shim_args),
|
shim_args, XECOUNT(shim_args),
|
||||||
0);
|
0);
|
||||||
|
|
||||||
jit_insn_return(gen_fn_, NULL);
|
jit_insn_return(fn_, NULL);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -295,15 +291,15 @@ int LibjitEmitter::MakePresentImportFunction() {
|
||||||
int LibjitEmitter::MakeMissingImportFunction() {
|
int LibjitEmitter::MakeMissingImportFunction() {
|
||||||
if (FLAGS_trace_kernel_calls) {
|
if (FLAGS_trace_kernel_calls) {
|
||||||
jit_value_t trace_args[] = {
|
jit_value_t trace_args[] = {
|
||||||
jit_value_get_param(gen_fn_, 0),
|
jit_value_get_param(fn_, 0),
|
||||||
jit_value_create_long_constant(gen_fn_, jit_type_ulong,
|
jit_value_create_long_constant(fn_, jit_type_ulong,
|
||||||
(jit_ulong)fn_->start_address),
|
(jit_ulong)symbol_->start_address),
|
||||||
jit_value_get_param(gen_fn_, 1),
|
jit_value_get_param(fn_, 1),
|
||||||
jit_value_create_long_constant(gen_fn_, jit_type_ulong,
|
jit_value_create_long_constant(fn_, jit_type_ulong,
|
||||||
(jit_ulong)fn_->kernel_export),
|
(jit_ulong)symbol_->kernel_export),
|
||||||
};
|
};
|
||||||
jit_insn_call_native(
|
jit_insn_call_native(
|
||||||
gen_fn_,
|
fn_,
|
||||||
"XeTraceKernelCall",
|
"XeTraceKernelCall",
|
||||||
global_exports_.XeTraceKernelCall,
|
global_exports_.XeTraceKernelCall,
|
||||||
global_export_signature_4_,
|
global_export_signature_4_,
|
||||||
|
@ -311,21 +307,21 @@ int LibjitEmitter::MakeMissingImportFunction() {
|
||||||
0);
|
0);
|
||||||
}
|
}
|
||||||
|
|
||||||
jit_insn_return(gen_fn_, NULL);
|
jit_insn_return(fn_, NULL);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
FunctionSymbol* LibjitEmitter::fn() {
|
FunctionSymbol* LibjitEmitter::symbol() {
|
||||||
|
return symbol_;
|
||||||
|
}
|
||||||
|
|
||||||
|
jit_function_t LibjitEmitter::fn() {
|
||||||
return fn_;
|
return fn_;
|
||||||
}
|
}
|
||||||
|
|
||||||
jit_function_t LibjitEmitter::gen_fn() {
|
//FunctionBlock* LibjitEmitter::symbol_block() {
|
||||||
return gen_fn_;
|
// return symbol_block_;
|
||||||
}
|
|
||||||
|
|
||||||
//FunctionBlock* LibjitEmitter::fn_block() {
|
|
||||||
// return fn_block_;
|
|
||||||
//}
|
//}
|
||||||
//
|
//
|
||||||
//void LibjitEmitter::PushInsertPoint() {
|
//void LibjitEmitter::PushInsertPoint() {
|
||||||
|
@ -345,7 +341,7 @@ jit_function_t LibjitEmitter::gen_fn() {
|
||||||
// IRBuilder<>& b = *builder_;
|
// IRBuilder<>& b = *builder_;
|
||||||
//
|
//
|
||||||
// // Always add an entry block.
|
// // Always add an entry block.
|
||||||
// BasicBlock* entry = BasicBlock::Create(*context_, "entry", gen_fn_);
|
// BasicBlock* entry = BasicBlock::Create(*context_, "entry", fn_);
|
||||||
// b.SetInsertPoint(entry);
|
// b.SetInsertPoint(entry);
|
||||||
//
|
//
|
||||||
// if (FLAGS_trace_user_calls) {
|
// if (FLAGS_trace_user_calls) {
|
||||||
|
@ -353,14 +349,14 @@ jit_function_t LibjitEmitter::gen_fn() {
|
||||||
// Value* traceUserCall = gen_module_->getFunction("XeTraceUserCall");
|
// Value* traceUserCall = gen_module_->getFunction("XeTraceUserCall");
|
||||||
// b.CreateCall4(
|
// b.CreateCall4(
|
||||||
// traceUserCall,
|
// traceUserCall,
|
||||||
// gen_fn_->arg_begin(),
|
// fn_->arg_begin(),
|
||||||
// b.getInt64(fn_->start_address),
|
// b.getInt64(symbol_->start_address),
|
||||||
// ++gen_fn_->arg_begin(),
|
// ++fn_->arg_begin(),
|
||||||
// b.getInt64((uint64_t)fn_));
|
// b.getInt64((uint64_t)symbol_));
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// // If this function is empty, abort!
|
// // If this function is empty, abort!
|
||||||
// if (!fn_->blocks.size()) {
|
// if (!symbol_->blocks.size()) {
|
||||||
// b.CreateRetVoid();
|
// b.CreateRetVoid();
|
||||||
// return;
|
// return;
|
||||||
// }
|
// }
|
||||||
|
@ -368,12 +364,12 @@ jit_function_t LibjitEmitter::gen_fn() {
|
||||||
// // Create a return block.
|
// // Create a return block.
|
||||||
// // This spills registers and returns. All non-tail returns should branch
|
// // This spills registers and returns. All non-tail returns should branch
|
||||||
// // here to do the return and ensure registers are spilled.
|
// // here to do the return and ensure registers are spilled.
|
||||||
// return_block_ = BasicBlock::Create(*context_, "return", gen_fn_);
|
// return_block_ = BasicBlock::Create(*context_, "return", fn_);
|
||||||
//
|
//
|
||||||
// // Pass 1 creates all of the blocks - this way we can branch to them.
|
// // Pass 1 creates all of the blocks - this way we can branch to them.
|
||||||
// // We also track registers used so that when know which ones to fill/spill.
|
// // We also track registers used so that when know which ones to fill/spill.
|
||||||
// for (std::map<uint32_t, FunctionBlock*>::iterator it = fn_->blocks.begin();
|
// for (std::map<uint32_t, FunctionBlock*>::iterator it = symbol_->blocks.begin();
|
||||||
// it != fn_->blocks.end(); ++it) {
|
// it != symbol_->blocks.end(); ++it) {
|
||||||
// FunctionBlock* block = it->second;
|
// FunctionBlock* block = it->second;
|
||||||
// XEIGNORE(PrepareBasicBlock(block));
|
// XEIGNORE(PrepareBasicBlock(block));
|
||||||
// }
|
// }
|
||||||
|
@ -382,8 +378,8 @@ jit_function_t LibjitEmitter::gen_fn() {
|
||||||
// SetupLocals();
|
// SetupLocals();
|
||||||
//
|
//
|
||||||
// // Pass 2 fills in instructions.
|
// // Pass 2 fills in instructions.
|
||||||
// for (std::map<uint32_t, FunctionBlock*>::iterator it = fn_->blocks.begin();
|
// for (std::map<uint32_t, FunctionBlock*>::iterator it = symbol_->blocks.begin();
|
||||||
// it != fn_->blocks.end(); ++it) {
|
// it != symbol_->blocks.end(); ++it) {
|
||||||
// FunctionBlock* block = it->second;
|
// FunctionBlock* block = it->second;
|
||||||
// GenerateBasicBlock(block);
|
// GenerateBasicBlock(block);
|
||||||
// }
|
// }
|
||||||
|
@ -400,7 +396,7 @@ jit_function_t LibjitEmitter::gen_fn() {
|
||||||
//
|
//
|
||||||
// // Setup initial register fill in the entry block.
|
// // Setup initial register fill in the entry block.
|
||||||
// // We can only do this once all the locals have been created.
|
// // We can only do this once all the locals have been created.
|
||||||
// b.SetInsertPoint(&gen_fn_->getEntryBlock());
|
// b.SetInsertPoint(&fn_->getEntryBlock());
|
||||||
// FillRegisters();
|
// FillRegisters();
|
||||||
// // Entry always falls through to the second block.
|
// // Entry always falls through to the second block.
|
||||||
// b.CreateBr(bbs_.begin()->second);
|
// b.CreateBr(bbs_.begin()->second);
|
||||||
|
@ -418,7 +414,7 @@ jit_function_t LibjitEmitter::gen_fn() {
|
||||||
// b.SetInsertPoint(external_indirection_block_);
|
// b.SetInsertPoint(external_indirection_block_);
|
||||||
// SpillRegisters();
|
// SpillRegisters();
|
||||||
// b.CreateCall3(indirect_branch,
|
// b.CreateCall3(indirect_branch,
|
||||||
// gen_fn_->arg_begin(),
|
// fn_->arg_begin(),
|
||||||
// b.CreateLoad(locals_.indirection_target),
|
// b.CreateLoad(locals_.indirection_target),
|
||||||
// b.CreateLoad(locals_.indirection_cia));
|
// b.CreateLoad(locals_.indirection_cia));
|
||||||
// b.CreateRetVoid();
|
// b.CreateRetVoid();
|
||||||
|
@ -445,7 +441,7 @@ jit_function_t LibjitEmitter::gen_fn() {
|
||||||
// // generation.
|
// // generation.
|
||||||
// char name[32];
|
// char name[32];
|
||||||
// xesnprintfa(name, XECOUNT(name), "loc_%.8X", block->start_address);
|
// xesnprintfa(name, XECOUNT(name), "loc_%.8X", block->start_address);
|
||||||
// BasicBlock* bb = BasicBlock::Create(*context_, name, gen_fn_);
|
// BasicBlock* bb = BasicBlock::Create(*context_, name, fn_);
|
||||||
// bbs_.insert(std::pair<uint32_t, BasicBlock*>(block->start_address, bb));
|
// bbs_.insert(std::pair<uint32_t, BasicBlock*>(block->start_address, bb));
|
||||||
//
|
//
|
||||||
// // Scan and disassemble each instruction in the block to get accurate
|
// // Scan and disassemble each instruction in the block to get accurate
|
||||||
|
@ -496,7 +492,7 @@ jit_function_t LibjitEmitter::gen_fn() {
|
||||||
// printf(" bb %.8X-%.8X:\n", block->start_address, block->end_address);
|
// printf(" bb %.8X-%.8X:\n", block->start_address, block->end_address);
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// fn_block_ = block;
|
// symbol_block_ = block;
|
||||||
// bb_ = bb;
|
// bb_ = bb;
|
||||||
//
|
//
|
||||||
// // Move the builder to this block and setup.
|
// // Move the builder to this block and setup.
|
||||||
|
@ -520,7 +516,7 @@ jit_function_t LibjitEmitter::gen_fn() {
|
||||||
// SpillRegisters();
|
// SpillRegisters();
|
||||||
// b.CreateCall3(
|
// b.CreateCall3(
|
||||||
// traceInstruction,
|
// traceInstruction,
|
||||||
// gen_fn_->arg_begin(),
|
// fn_->arg_begin(),
|
||||||
// b.getInt32(i.address),
|
// b.getInt32(i.address),
|
||||||
// b.getInt32(i.code));
|
// b.getInt32(i.code));
|
||||||
// }
|
// }
|
||||||
|
@ -530,7 +526,7 @@ jit_function_t LibjitEmitter::gen_fn() {
|
||||||
// SpillRegisters();
|
// SpillRegisters();
|
||||||
// b.CreateCall3(
|
// b.CreateCall3(
|
||||||
// invalidInstruction,
|
// invalidInstruction,
|
||||||
// gen_fn_->arg_begin(),
|
// fn_->arg_begin(),
|
||||||
// b.getInt32(i.address),
|
// b.getInt32(i.address),
|
||||||
// b.getInt32(i.code));
|
// b.getInt32(i.code));
|
||||||
// continue;
|
// continue;
|
||||||
|
@ -564,7 +560,7 @@ jit_function_t LibjitEmitter::gen_fn() {
|
||||||
// SpillRegisters();
|
// SpillRegisters();
|
||||||
// b.CreateCall3(
|
// b.CreateCall3(
|
||||||
// invalidInstruction,
|
// invalidInstruction,
|
||||||
// gen_fn_->arg_begin(),
|
// fn_->arg_begin(),
|
||||||
// b.getInt32(i.address),
|
// b.getInt32(i.address),
|
||||||
// b.getInt32(i.code));
|
// b.getInt32(i.code));
|
||||||
// }
|
// }
|
||||||
|
@ -579,7 +575,7 @@ jit_function_t LibjitEmitter::gen_fn() {
|
||||||
// // Hrm.
|
// // Hrm.
|
||||||
// // TODO(benvanik): assert this doesn't occur - means a bad sdb run!
|
// // TODO(benvanik): assert this doesn't occur - means a bad sdb run!
|
||||||
// XELOGCPU("SDB function scan error in %.8X: bb %.8X has unknown exit",
|
// XELOGCPU("SDB function scan error in %.8X: bb %.8X has unknown exit",
|
||||||
// fn_->start_address, block->start_address);
|
// symbol_->start_address, block->start_address);
|
||||||
// b.CreateRetVoid();
|
// b.CreateRetVoid();
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
|
@ -596,7 +592,7 @@ jit_function_t LibjitEmitter::gen_fn() {
|
||||||
//
|
//
|
||||||
//BasicBlock* LibjitEmitter::GetNextBasicBlock() {
|
//BasicBlock* LibjitEmitter::GetNextBasicBlock() {
|
||||||
// std::map<uint32_t, BasicBlock*>::iterator it = bbs_.find(
|
// std::map<uint32_t, BasicBlock*>::iterator it = bbs_.find(
|
||||||
// fn_block_->start_address);
|
// symbol_block_->start_address);
|
||||||
// ++it;
|
// ++it;
|
||||||
// if (it != bbs_.end()) {
|
// if (it != bbs_.end()) {
|
||||||
// return it->second;
|
// return it->second;
|
||||||
|
@ -628,18 +624,18 @@ jit_function_t LibjitEmitter::gen_fn() {
|
||||||
// // after we are done with all user instructions.
|
// // after we are done with all user instructions.
|
||||||
// if (!external_indirection_block_) {
|
// if (!external_indirection_block_) {
|
||||||
// // Setup locals in the entry block.
|
// // Setup locals in the entry block.
|
||||||
// b.SetInsertPoint(&gen_fn_->getEntryBlock());
|
// b.SetInsertPoint(&fn_->getEntryBlock());
|
||||||
// locals_.indirection_target = b.CreateAlloca(
|
// locals_.indirection_target = b.CreateAlloca(
|
||||||
// b.getInt64Ty(), 0, "indirection_target");
|
// b.getInt64Ty(), 0, "indirection_target");
|
||||||
// locals_.indirection_cia = b.CreateAlloca(
|
// locals_.indirection_cia = b.CreateAlloca(
|
||||||
// b.getInt64Ty(), 0, "indirection_cia");
|
// b.getInt64Ty(), 0, "indirection_cia");
|
||||||
//
|
//
|
||||||
// external_indirection_block_ = BasicBlock::Create(
|
// external_indirection_block_ = BasicBlock::Create(
|
||||||
// *context_, "external_indirection_block", gen_fn_, return_block_);
|
// *context_, "external_indirection_block", fn_, return_block_);
|
||||||
// }
|
// }
|
||||||
// if (likely_local && !internal_indirection_block_) {
|
// if (likely_local && !internal_indirection_block_) {
|
||||||
// internal_indirection_block_ = BasicBlock::Create(
|
// internal_indirection_block_ = BasicBlock::Create(
|
||||||
// *context_, "internal_indirection_block", gen_fn_, return_block_);
|
// *context_, "internal_indirection_block", fn_, return_block_);
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// PopInsertPoint();
|
// PopInsertPoint();
|
||||||
|
@ -653,10 +649,10 @@ jit_function_t LibjitEmitter::gen_fn() {
|
||||||
// XEASSERT(!lk);
|
// XEASSERT(!lk);
|
||||||
// b.CreateStore(target, locals_.indirection_target);
|
// b.CreateStore(target, locals_.indirection_target);
|
||||||
// b.CreateStore(b.getInt64(cia), locals_.indirection_cia);
|
// b.CreateStore(b.getInt64(cia), locals_.indirection_cia);
|
||||||
// Value* fn_ge_cmp = b.CreateICmpUGE(target, b.getInt64(fn_->start_address));
|
// Value* symbol_ge_cmp = b.CreateICmpUGE(target, b.getInt64(symbol_->start_address));
|
||||||
// Value* fn_l_cmp = b.CreateICmpULT(target, b.getInt64(fn_->end_address));
|
// Value* symbol_l_cmp = b.CreateICmpULT(target, b.getInt64(symbol_->end_address));
|
||||||
// Value* fn_target_cmp = b.CreateAnd(fn_ge_cmp, fn_l_cmp);
|
// Value* symbol_target_cmp = b.CreateAnd(symbol_ge_cmp, symbol_l_cmp);
|
||||||
// b.CreateCondBr(fn_target_cmp,
|
// b.CreateCondBr(symbol_target_cmp,
|
||||||
// internal_indirection_block_, external_indirection_block_);
|
// internal_indirection_block_, external_indirection_block_);
|
||||||
// return 0;
|
// return 0;
|
||||||
// }
|
// }
|
||||||
|
@ -678,7 +674,7 @@ jit_function_t LibjitEmitter::gen_fn() {
|
||||||
// // TODO(benvanik): keep function pointer lookup local.
|
// // TODO(benvanik): keep function pointer lookup local.
|
||||||
// Value* indirect_branch = gen_module_->getFunction("XeIndirectBranch");
|
// Value* indirect_branch = gen_module_->getFunction("XeIndirectBranch");
|
||||||
// b.CreateCall3(indirect_branch,
|
// b.CreateCall3(indirect_branch,
|
||||||
// gen_fn_->arg_begin(),
|
// fn_->arg_begin(),
|
||||||
// target,
|
// target,
|
||||||
// b.getInt64(cia));
|
// b.getInt64(cia));
|
||||||
//
|
//
|
||||||
|
@ -698,7 +694,7 @@ jit_function_t LibjitEmitter::gen_fn() {
|
||||||
// const char* name) {
|
// const char* name) {
|
||||||
// IRBuilder<>& b = *builder_;
|
// IRBuilder<>& b = *builder_;
|
||||||
// PointerType* pointerTy = PointerType::getUnqual(type);
|
// PointerType* pointerTy = PointerType::getUnqual(type);
|
||||||
// Function::arg_iterator args = gen_fn_->arg_begin();
|
// Function::arg_iterator args = fn_->arg_begin();
|
||||||
// Value* state_ptr = args;
|
// Value* state_ptr = args;
|
||||||
// Value* address = b.CreateInBoundsGEP(state_ptr, b.getInt32(offset));
|
// Value* address = b.CreateInBoundsGEP(state_ptr, b.getInt32(offset));
|
||||||
// Value* ptr = b.CreatePointerCast(address, pointerTy);
|
// Value* ptr = b.CreatePointerCast(address, pointerTy);
|
||||||
|
@ -709,7 +705,7 @@ jit_function_t LibjitEmitter::gen_fn() {
|
||||||
// Value* value) {
|
// Value* value) {
|
||||||
// IRBuilder<>& b = *builder_;
|
// IRBuilder<>& b = *builder_;
|
||||||
// PointerType* pointerTy = PointerType::getUnqual(type);
|
// PointerType* pointerTy = PointerType::getUnqual(type);
|
||||||
// Function::arg_iterator args = gen_fn_->arg_begin();
|
// Function::arg_iterator args = fn_->arg_begin();
|
||||||
// Value* state_ptr = args;
|
// Value* state_ptr = args;
|
||||||
// Value* address = b.CreateInBoundsGEP(state_ptr, b.getInt32(offset));
|
// Value* address = b.CreateInBoundsGEP(state_ptr, b.getInt32(offset));
|
||||||
// Value* ptr = b.CreatePointerCast(address, pointerTy);
|
// Value* ptr = b.CreatePointerCast(address, pointerTy);
|
||||||
|
@ -768,7 +764,7 @@ jit_function_t LibjitEmitter::gen_fn() {
|
||||||
// IRBuilder<>& b = *builder_;
|
// IRBuilder<>& b = *builder_;
|
||||||
// // Insert into the entry block.
|
// // Insert into the entry block.
|
||||||
// PushInsertPoint();
|
// PushInsertPoint();
|
||||||
// b.SetInsertPoint(&gen_fn_->getEntryBlock());
|
// b.SetInsertPoint(&fn_->getEntryBlock());
|
||||||
// Value* v = b.CreateAlloca(type, 0, name);
|
// Value* v = b.CreateAlloca(type, 0, name);
|
||||||
// PopInsertPoint();
|
// PopInsertPoint();
|
||||||
// return v;
|
// return v;
|
||||||
|
@ -1137,8 +1133,8 @@ jit_function_t LibjitEmitter::gen_fn() {
|
||||||
//
|
//
|
||||||
// // Add runtime memory address checks, if needed.
|
// // Add runtime memory address checks, if needed.
|
||||||
// if (FLAGS_memory_address_verification) {
|
// if (FLAGS_memory_address_verification) {
|
||||||
// BasicBlock* invalid_bb = BasicBlock::Create(*context_, "", gen_fn_);
|
// BasicBlock* invalid_bb = BasicBlock::Create(*context_, "", fn_);
|
||||||
// BasicBlock* valid_bb = BasicBlock::Create(*context_, "", gen_fn_);
|
// BasicBlock* valid_bb = BasicBlock::Create(*context_, "", fn_);
|
||||||
//
|
//
|
||||||
// // The heap starts at 0x1000 - if we write below that we're boned.
|
// // The heap starts at 0x1000 - if we write below that we're boned.
|
||||||
// Value* gt = b.CreateICmpUGE(addr, b.getInt64(0x00001000));
|
// Value* gt = b.CreateICmpUGE(addr, b.getInt64(0x00001000));
|
||||||
|
@ -1148,7 +1144,7 @@ jit_function_t LibjitEmitter::gen_fn() {
|
||||||
// Value* access_violation = gen_module_->getFunction("XeAccessViolation");
|
// Value* access_violation = gen_module_->getFunction("XeAccessViolation");
|
||||||
// SpillRegisters();
|
// SpillRegisters();
|
||||||
// b.CreateCall3(access_violation,
|
// b.CreateCall3(access_violation,
|
||||||
// gen_fn_->arg_begin(),
|
// fn_->arg_begin(),
|
||||||
// b.getInt32(cia),
|
// b.getInt32(cia),
|
||||||
// addr);
|
// addr);
|
||||||
// b.CreateBr(valid_bb);
|
// b.CreateBr(valid_bb);
|
||||||
|
|
|
@ -28,13 +28,12 @@ public:
|
||||||
~LibjitEmitter();
|
~LibjitEmitter();
|
||||||
|
|
||||||
jit_context_t context();
|
jit_context_t context();
|
||||||
jit_type_t fn_signature();
|
|
||||||
|
|
||||||
int PrepareFunction(sdb::FunctionSymbol* symbol);
|
int PrepareFunction(sdb::FunctionSymbol* symbol);
|
||||||
int MakeFunction(sdb::FunctionSymbol* symbol, jit_function_t fn);
|
int MakeFunction(sdb::FunctionSymbol* symbol, jit_function_t fn);
|
||||||
|
|
||||||
sdb::FunctionSymbol* fn();
|
sdb::FunctionSymbol* symbol();
|
||||||
jit_function_t gen_fn();
|
jit_function_t fn();
|
||||||
sdb::FunctionBlock* fn_block();
|
sdb::FunctionBlock* fn_block();
|
||||||
|
|
||||||
void PushInsertPoint();
|
void PushInsertPoint();
|
||||||
|
@ -107,8 +106,8 @@ private:
|
||||||
jit_type_t global_export_signature_3_;
|
jit_type_t global_export_signature_3_;
|
||||||
jit_type_t global_export_signature_4_;
|
jit_type_t global_export_signature_4_;
|
||||||
|
|
||||||
sdb::FunctionSymbol* fn_;
|
sdb::FunctionSymbol* symbol_;
|
||||||
jit_function_t gen_fn_;
|
jit_function_t fn_;
|
||||||
sdb::FunctionBlock* fn_block_;
|
sdb::FunctionBlock* fn_block_;
|
||||||
// llvm::BasicBlock* return_block_;
|
// llvm::BasicBlock* return_block_;
|
||||||
// llvm::BasicBlock* internal_indirection_block_;
|
// llvm::BasicBlock* internal_indirection_block_;
|
||||||
|
|
Loading…
Reference in New Issue