preparing for release...

merge-requests/12/head
_xeroxz 3 years ago
parent 8a5bf9e8ab
commit a8fef83c95

@ -85,6 +85,19 @@ namespace vm
bool devirt_t::compile( std::vector< std::uint8_t > &obj ) bool devirt_t::compile( std::vector< std::uint8_t > &obj )
{ {
llvm::legacy::FunctionPassManager pass_mgr( llvm_module );
pass_mgr.add( llvm::createPromoteMemoryToRegisterPass() );
pass_mgr.add( llvm::createNewGVNPass() );
pass_mgr.add( llvm::createReassociatePass() );
pass_mgr.add( llvm::createDeadCodeEliminationPass() );
pass_mgr.add( llvm::createInstructionCombiningPass() );
for ( auto vmp_rtn : vmp_rtns )
{
pass_mgr.run( *vmp_rtn->llvm_fptr );
std::printf( "> opt rtn_0x%p\n", vmp_rtn->rtn_begin );
}
llvm::TargetOptions opt; llvm::TargetOptions opt;
llvm::SmallVector< char, 128 > buff; llvm::SmallVector< char, 128 > buff;
llvm::raw_svector_ostream dest( buff ); llvm::raw_svector_ostream dest( buff );

@ -8,25 +8,21 @@ namespace vm
llvm::Function *rdtsc_intrin = nullptr; llvm::Function *rdtsc_intrin = nullptr;
if ( !( rdtsc_intrin = rtn->llvm_module->getFunction( "rdtsc" ) ) ) if ( !( rdtsc_intrin = rtn->llvm_module->getFunction( "rdtsc" ) ) )
{ {
rdtsc_intrin = llvm::Function::Create( rdtsc_intrin = llvm::Function::Create( llvm::FunctionType::get( ir_builder->getVoidTy(), false ),
llvm::FunctionType::get( ir_builder->getVoidTy(), llvm::GlobalValue::LinkageTypes::ExternalLinkage, "rdtsc",
{ llvm::PointerType::get( ir_builder->getInt8Ty(), 0ull ) }, false ), *rtn->llvm_module );
llvm::GlobalValue::LinkageTypes::ExternalLinkage, "rdtsc", *rtn->llvm_module );
auto entry_block = llvm::BasicBlock::Create( ir_builder->getContext(), "", rdtsc_intrin ); auto entry_block = llvm::BasicBlock::Create( ir_builder->getContext(), "", rdtsc_intrin );
auto ib = ir_builder->GetInsertBlock(); auto ib = ir_builder->GetInsertBlock();
ir_builder->SetInsertPoint( entry_block ); ir_builder->SetInsertPoint( entry_block );
std::string asm_str( "rdtsc; sub rbp, 0x08; mov [rcx], edx; mov [rcx+0x04], eax; ret" ); // TODO: put RDTSC code here...
auto intrin = llvm::InlineAsm::get( llvm::FunctionType::get( ir_builder->getVoidTy(), false ), asm_str,
"", false, false, llvm::InlineAsm::AD_Intel );
ir_builder->CreateCall( intrin );
ir_builder->CreateRetVoid(); ir_builder->CreateRetVoid();
ir_builder->SetInsertPoint( ib ); ir_builder->SetInsertPoint( ib );
} }
auto &vmp_rtn = rtn->vmp_rtns.back(); auto &vmp_rtn = rtn->vmp_rtns.back();
ir_builder->CreateCall( rdtsc_intrin, { vmp_rtn->stack } ); ir_builder->CreateCall( rdtsc_intrin );
}; };
} }
Loading…
Cancel
Save