From cd79fa38fa4ff708849bbef0a3e5fa48b2969329 Mon Sep 17 00:00:00 2001 From: luyahan Date: Wed, 9 Sep 2020 11:51:10 +0900 Subject: [PATCH] Optimize li by constant - If meet the conditions, li a imm by constant - Add a flag to disable constant pool. --- .../riscv64/macro-assembler-riscv64.cc | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/codegen/riscv64/macro-assembler-riscv64.cc b/src/codegen/riscv64/macro-assembler-riscv64.cc index ed65f20baec3..b02499601227 100644 --- a/src/codegen/riscv64/macro-assembler-riscv64.cc +++ b/src/codegen/riscv64/macro-assembler-riscv64.cc @@ -1440,7 +1440,15 @@ void TurboAssembler::li(Register rd, Operand j, LiFlags mode) { DCHECK(!j.is_reg()); BlockTrampolinePoolScope block_trampoline_pool(this); if (!MustUseReg(j.rmode()) && mode == OPTIMIZE_SIZE) { - RV_li(rd, j.immediate()); + if (!FLAG_disable_constant_pool && li_count(j.immediate()) >= 4) { + // Ld a Address from a constant pool. + RecordEntry((uint64_t)j.immediate(), j.rmode()); + auipc(rd, 0); + // Record a value into constant pool. + ld(rd, rd, 0); + } else { + RV_li(rd, j.immediate()); + } } else if (MustUseReg(j.rmode())) { int64_t immediate; if (j.IsHeapObjectRequest()) { @@ -3092,7 +3100,7 @@ void TurboAssembler::StoreReturnAddressAndCall(Register target) { void TurboAssembler::Ret(Condition cond, Register rs, const Operand& rt) { Jump(ra, cond, rs, rt); - if(cond == al){ + if (cond == al) { ForceConstantPoolEmissionWithoutJump(); } } @@ -3614,12 +3622,16 @@ void MacroAssembler::JumpToExternalReference(const ExternalReference& builtin, } void MacroAssembler::JumpToInstructionStream(Address entry) { - //Ld a Address from a constant pool. - //Record a value into constant pool. - RecordEntry(entry, RelocInfo::OFF_HEAP_TARGET); - RecordRelocInfo(RelocInfo::OFF_HEAP_TARGET, entry); - auipc(kOffHeapTrampolineRegister, 0); - ld(kOffHeapTrampolineRegister, kOffHeapTrampolineRegister, 0); + // Ld a Address from a constant pool. + // Record a value into constant pool. + if (FLAG_disable_constant_pool) { + li(kOffHeapTrampolineRegister, Operand(entry, RelocInfo::OFF_HEAP_TARGET)); + } else { + RecordEntry(entry, RelocInfo::OFF_HEAP_TARGET); + RecordRelocInfo(RelocInfo::OFF_HEAP_TARGET, entry); + auipc(kOffHeapTrampolineRegister, 0); + ld(kOffHeapTrampolineRegister, kOffHeapTrampolineRegister, 0); + } Jump(kOffHeapTrampolineRegister); }