Merge pull request #57610 from kitaisreal/jit-add-assembly-printer

CHJIT add assembly printer
This commit is contained in:
János Benjamin Antal 2023-12-14 12:39:20 +01:00 committed by GitHub
commit fdfd1481df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -244,6 +244,31 @@ private:
}
};
#ifdef PRINT_ASSEMBLY
class AssemblyPrinter
{
public:
explicit AssemblyPrinter(llvm::TargetMachine &target_machine_)
: target_machine(target_machine_)
{
}
void print(llvm::Module & module)
{
llvm::legacy::PassManager pass_manager;
target_machine.Options.MCOptions.AsmVerbose = true;
if (target_machine.addPassesToEmitFile(pass_manager, llvm::errs(), nullptr, llvm::CodeGenFileType::CGFT_AssemblyFile))
throw Exception(ErrorCodes::CANNOT_COMPILE_CODE, "MachineCode cannot be printed");
pass_manager.run(module);
}
private:
llvm::TargetMachine & target_machine;
};
#endif
/** MemoryManager for module.
* Keep total allocated size during RuntimeDyld linker execution.
*/
@ -375,6 +400,11 @@ CHJIT::CompiledModule CHJIT::compileModule(std::unique_ptr<llvm::Module> module)
{
runOptimizationPassesOnModule(*module);
#ifdef PRINT_ASSEMBLY
AssemblyPrinter assembly_printer(*machine);
assembly_printer.print(*module);
#endif
auto buffer = compiler->compile(*module);
llvm::Expected<std::unique_ptr<llvm::object::ObjectFile>> object = llvm::object::ObjectFile::createObjectFile(*buffer);