mirror of
https://github.com/RPCS3/rpcs3.git
synced 2024-11-22 02:32:36 +01:00
LLVM: Use small code model
Global variables modified: __mptr: pointer to memory base addr __cptr: pointer to function map addr Use 32 bit pointers in function map
This commit is contained in:
parent
c100328a6f
commit
44bee7d0ba
@ -231,7 +231,7 @@ jit_compiler::jit_compiler(std::unique_ptr<llvm::Module>&& _module, std::unorder
|
||||
.setErrorStr(&result)
|
||||
.setMCJITMemoryManager(std::make_unique<MemoryManager>(std::move(table)))
|
||||
.setOptLevel(llvm::CodeGenOpt::Aggressive)
|
||||
.setCodeModel((u64)s_memory <= 0x60000000 ? llvm::CodeModel::Medium : llvm::CodeModel::Large) // TODO
|
||||
.setCodeModel((u64)s_memory <= 0x60000000 ? llvm::CodeModel::Small : llvm::CodeModel::Large) // TODO
|
||||
.setMCPU(llvm::sys::getHostCPUName())
|
||||
.create());
|
||||
|
||||
|
@ -57,14 +57,14 @@ cfg::map_entry<ppu_decoder_type> g_cfg_ppu_decoder(cfg::root.core, "PPU Decoder"
|
||||
const ppu_decoder<ppu_interpreter_precise> s_ppu_interpreter_precise;
|
||||
const ppu_decoder<ppu_interpreter_fast> s_ppu_interpreter_fast;
|
||||
|
||||
const auto s_ppu_compiled = static_cast<ppu_function_t*>(memory_helper::reserve_memory(0x200000000));
|
||||
const auto s_ppu_compiled = static_cast<u32*>(memory_helper::reserve_memory(0x100000000));
|
||||
|
||||
extern void ppu_register_function_at(u32 addr, ppu_function_t ptr)
|
||||
{
|
||||
if (g_cfg_ppu_decoder.get() == ppu_decoder_type::llvm)
|
||||
{
|
||||
memory_helper::commit_page_memory(s_ppu_compiled + addr / 4, sizeof(ppu_function_t));
|
||||
s_ppu_compiled[addr / 4] = ptr;
|
||||
memory_helper::commit_page_memory(s_ppu_compiled + addr / 4, sizeof(s_ppu_compiled[0]));
|
||||
s_ppu_compiled[addr / 4] = (u32)(std::uintptr_t)ptr;
|
||||
}
|
||||
}
|
||||
|
||||
@ -134,7 +134,7 @@ void PPUThread::cpu_task_main()
|
||||
{
|
||||
if (g_cfg_ppu_decoder.get() == ppu_decoder_type::llvm)
|
||||
{
|
||||
return s_ppu_compiled[pc / 4](*this);
|
||||
return reinterpret_cast<ppu_function_t>((std::uintptr_t)s_ppu_compiled[pc / 4])(*this);
|
||||
}
|
||||
|
||||
g_tls_log_prefix = []
|
||||
@ -451,15 +451,14 @@ extern void ppu_initialize(const std::string& name, const std::vector<ppu_functi
|
||||
|
||||
std::unordered_map<std::string, std::uintptr_t> link_table
|
||||
{
|
||||
{ "__memory", (u64)vm::g_base_addr },
|
||||
{ "__memptr", (u64)&vm::g_base_addr },
|
||||
{ "__mptr", (u64)&vm::g_base_addr },
|
||||
{ "__cptr", (u64)&s_ppu_compiled },
|
||||
{ "__trap", (u64)&ppu_trap },
|
||||
{ "__end", (u64)&ppu_unreachable },
|
||||
{ "__trace", (u64)&ppu_trace },
|
||||
{ "__hlecall", (u64)&ppu_execute_function },
|
||||
{ "__syscall", (u64)&ppu_execute_syscall },
|
||||
{ "__get_tbl", (u64)&get_timebased_time },
|
||||
{ "__call", (u64)s_ppu_compiled },
|
||||
{ "__lwarx", (u64)&ppu_lwarx },
|
||||
{ "__ldarx", (u64)&ppu_ldarx },
|
||||
{ "__stwcx", (u64)&ppu_stwcx },
|
||||
|
@ -71,7 +71,7 @@ PPUTranslator::PPUTranslator(LLVMContext& context, Module* module, u64 base, u64
|
||||
, m_pure_attr(AttributeSet::get(m_context, AttributeSet::FunctionIndex, {Attribute::NoUnwind, Attribute::ReadNone}))
|
||||
{
|
||||
// Memory base
|
||||
m_base = new GlobalVariable(*module, ArrayType::get(GetType<char>(), 0x100000000), false, GlobalValue::ExternalLinkage, 0, "__memory");
|
||||
m_base = new GlobalVariable(*module, ArrayType::get(GetType<char>(), 0x100000000)->getPointerTo(), true, GlobalValue::ExternalLinkage, 0, "__mptr");
|
||||
|
||||
// Thread context struct (TODO: safer member access)
|
||||
std::vector<Type*> thread_struct{ArrayType::get(GetType<char>(), OFFSET_32(PPUThread, GPR))};
|
||||
@ -84,7 +84,7 @@ PPUTranslator::PPUTranslator(LLVMContext& context, Module* module, u64 base, u64
|
||||
m_thread_type = StructType::create(m_context, thread_struct, "context_t");
|
||||
|
||||
// Callable
|
||||
m_call = new GlobalVariable(*module, ArrayType::get(FunctionType::get(GetType<void>(), {m_thread_type->getPointerTo()}, false)->getPointerTo(), 0x40000000), true, GlobalValue::ExternalLinkage, 0, "__call");
|
||||
m_call = new GlobalVariable(*module, ArrayType::get(GetType<u32>(), 0x40000000)->getPointerTo(), true, GlobalValue::ExternalLinkage, 0, "__cptr");
|
||||
}
|
||||
|
||||
PPUTranslator::~PPUTranslator()
|
||||
@ -125,6 +125,7 @@ Function* PPUTranslator::TranslateToIR(const ppu_function& info, be_t<u32>* bin,
|
||||
/* Create context variables */
|
||||
//m_thread = Call(m_thread_type->getPointerTo(), AttributeSet::get(m_context, AttributeSet::FunctionIndex, {Attribute::NoUnwind, Attribute::ReadOnly}), "__context", m_ir->getInt64(info.addr));
|
||||
m_thread = &*m_function->getArgumentList().begin();
|
||||
m_base_loaded = m_ir->CreateLoad(m_base);
|
||||
|
||||
// Non-volatile registers with special meaning (TODO)
|
||||
if (info.attr & ppu_attr::uses_r0) m_g_gpr[0] = m_ir->CreateConstGEP2_32(nullptr, m_thread, 0, 1 + 0, ".r0g");
|
||||
@ -319,8 +320,8 @@ void PPUTranslator::CallFunction(u64 target, bool tail, Value* indirect)
|
||||
{
|
||||
const auto addr = indirect ? indirect : (Value*)m_ir->getInt64(target);
|
||||
const auto pos = m_ir->CreateLShr(addr, 2, "", true);
|
||||
const auto ptr = m_ir->CreateGEP(m_call, {m_ir->getInt64(0), pos});
|
||||
m_ir->CreateCall(m_ir->CreateLoad(ptr), {m_thread});
|
||||
const auto ptr = m_ir->CreateGEP(m_ir->CreateLoad(m_call), {m_ir->getInt64(0), pos});
|
||||
m_ir->CreateCall(m_ir->CreateIntToPtr(m_ir->CreateLoad(ptr), FunctionType::get(GetType<void>(), {m_thread_type->getPointerTo()}, false)->getPointerTo()), {m_thread});
|
||||
}
|
||||
|
||||
if (!tail)
|
||||
@ -545,7 +546,7 @@ void PPUTranslator::UseCondition(Value* cond)
|
||||
|
||||
llvm::Value* PPUTranslator::GetMemory(llvm::Value* addr, llvm::Type* type)
|
||||
{
|
||||
return m_ir->CreateBitCast(m_ir->CreateGEP(m_base, {m_ir->getInt64(0), addr}), type->getPointerTo());
|
||||
return m_ir->CreateBitCast(m_ir->CreateGEP(m_base_loaded, {m_ir->getInt64(0), addr}), type->getPointerTo());
|
||||
}
|
||||
|
||||
Value* PPUTranslator::ReadMemory(Value* addr, Type* type, bool is_be, u32 align)
|
||||
|
@ -151,6 +151,7 @@ class PPUTranslator final //: public CPUTranslator
|
||||
|
||||
// Memory base
|
||||
llvm::Value* m_base;
|
||||
llvm::Value* m_base_loaded;
|
||||
|
||||
// Thread context
|
||||
llvm::Value* m_thread;
|
||||
|
Loading…
Reference in New Issue
Block a user