Skip to content

AOTIR: Initial implementation #730

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 24 commits into from
Feb 23, 2021
Merged

AOTIR: Initial implementation #730

merged 24 commits into from
Feb 23, 2021

Conversation

skmp
Copy link
Contributor

@skmp skmp commented Jan 30, 2021

Overview

This adds IR caching support. In FEXLoader, --aotir-capture will catpure ir during execution and generate ~/.fex-emu/aotir/<module>-<pathhash>-<optoptions> for all elfs loaded by the process, and --aotir-load will load them.

Currently, only one process can update the aotir cache, so programs that fork won't work well with--aotir-capture

IR Caches hash verify the guest code (usting some fasthash), though we likely want to use native CRC support in arm for faster hashing.

IR Caches are also relocated on use.

I've successfully run clang, clang++, FTL, gnome-calculator and gnome-text-editor. Load time speedup is 2x to 3x vs non-cached.

IR Loading is done via c++ streams, and could be much further optimized.

To append to the cache, both --aotir-load and --aotir-capture need to be passed to FEXLoader.

This also includes a fix for exit_group, which GLib programs need to exit cleanly.

Details

  • Adds --aotir-capture and --aotir-load
  • Introduces a new IR Op, EntrypointOffset to handle relocations
  • Makes IRListView non-templated
  • Adds AOTCache to Context/Core.cpp
  • Adds Addr -> File mappings to Context/Core.cpp
  • Adds AddNamedRegion and RemoveNamedRegion to Context/Core.cpp to keep track of addr -> file mappings
  • Adds WriteAOTIRCache and SetAOTIRLoader
  • Changes OP_THUNK to use sha256 hashes instead of strings, so that it can be serialized
  • Adds IsShared to RAData and IRListView, updates deleters, so that data from AOTIR can be imported directly to the thread local lists
  • Refactors IRLists and RALists and DebugData to LocalIRCache

Todo

  • Fix memory ownership and double free issues
  • Add InlineEntrypointOffset an for ExitFunction
  • Support OP_THUNK (needs to be serialized differently)

Follow ups

Future work

  • AOTIR static generator
  • Optimize cache loading via mmap

@@ -209,8 +210,10 @@ class JITCore final : public CPUBackend, public Xbyak::CodeGenerator {

///< ALU Ops
DEF_OP(TruncElementPair);
DEF_OP(Constant);
DEF_OP(Constant);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing whitespace

@@ -535,6 +537,8 @@ namespace FEXCore::IR {
for (uint8_t i = 0; i < NumArgs; ++i) {
if (IROp->Args[i].IsInvalid()) continue;
if (IR->GetOp<IROp_Header>(IROp->Args[i])->Op == OP_INLINECONSTANT) continue;
if (IR->GetOp<IROp_Header>(IROp->Args[i])->Op == OP_INLINEENTRYPOINTOFFSET) continue;
if (IR->GetOp<IROp_Header>(IROp->Args[i])->Op == OP_IRHEADER) continue;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be based on an IR.json property. Can be done in a follow up ticket

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants