Skip to content

Commit

Permalink
Optimize li by constant
Browse files Browse the repository at this point in the history
- If meet the conditions, li a imm by constant
- Add a flag to disable constant pool.
  • Loading branch information
luyahan authored and obycode committed Sep 17, 2020
1 parent f91ac74 commit cd79fa3
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions src/codegen/riscv64/macro-assembler-riscv64.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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();
}
}
Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit cd79fa3

Please sign in to comment.