diff options
author | Jiaxun Yang <jiaxun.yang@flygoat.com> | 2020-05-12 12:40:07 +0800 |
---|---|---|
committer | Moonchild <moonchild@palemoon.org> | 2020-05-20 14:01:06 +0000 |
commit | c3a21acaee65f9fde0f76b635ce906ca9c901889 (patch) | |
tree | a63a7052aebf85979f97a1d673874b7f37660b7a /js/src/jit | |
parent | 3fb8648bed83c95f601d2c2e20962cbd08bc7dc7 (diff) | |
download | UXP-c3a21acaee65f9fde0f76b635ce906ca9c901889.tar UXP-c3a21acaee65f9fde0f76b635ce906ca9c901889.tar.gz UXP-c3a21acaee65f9fde0f76b635ce906ca9c901889.tar.lz UXP-c3a21acaee65f9fde0f76b635ce906ca9c901889.tar.xz UXP-c3a21acaee65f9fde0f76b635ce906ca9c901889.zip |
Bug 1271968 - IonMonkey: MIPS: Merge Assembler::bind.
Tag: #1542
Diffstat (limited to 'js/src/jit')
-rw-r--r-- | js/src/jit/mips-shared/Assembler-mips-shared.cpp | 81 | ||||
-rw-r--r-- | js/src/jit/mips-shared/Assembler-mips-shared.h | 3 | ||||
-rw-r--r-- | js/src/jit/mips32/Assembler-mips32.cpp | 81 | ||||
-rw-r--r-- | js/src/jit/mips32/Assembler-mips32.h | 5 | ||||
-rw-r--r-- | js/src/jit/mips64/Assembler-mips64.cpp | 82 | ||||
-rw-r--r-- | js/src/jit/mips64/Assembler-mips64.h | 5 |
6 files changed, 83 insertions, 174 deletions
diff --git a/js/src/jit/mips-shared/Assembler-mips-shared.cpp b/js/src/jit/mips-shared/Assembler-mips-shared.cpp index 8519bab4d..1b14ef0eb 100644 --- a/js/src/jit/mips-shared/Assembler-mips-shared.cpp +++ b/js/src/jit/mips-shared/Assembler-mips-shared.cpp @@ -1597,6 +1597,87 @@ AssemblerMIPSShared::bindLater(Label* label, wasm::TrapDesc target) } void +AssemblerMIPSShared::bind(InstImm* inst, uintptr_t branch, uintptr_t target) +{ + intptr_t offset = target - branch; + + // Generate the patchable mixed jump for call. + if (inst->extractOpcode() == ((uint32_t)op_jal >> OpcodeShift)) { + addMixedJump(BufferOffset(branch), ImmPtr((void*)target)); + return; + } + + // If encoded offset is 4, then the jump must be short + if (BOffImm16(inst[0]).decode() == 4) { + MOZ_ASSERT(BOffImm16::IsInRange(offset)); + inst[0].setBOffImm16(BOffImm16(offset)); + inst[1].makeNop(); + return; + } + + if (BOffImm16::IsInRange(offset)) { + inst[0].setBOffImm16(BOffImm16(offset)); + inst[1].makeNop(); + return; + } + + addMixedJump(BufferOffset(branch), ImmPtr((void*)target)); +} + +void +AssemblerMIPSShared::bind(RepatchLabel* label) +{ + BufferOffset dest = nextOffset(); + if (label->used() && !oom()) { + // If the label has a use, then change this use to refer to + // the bound label; + BufferOffset b(label->offset()); + InstImm* inst = (InstImm*)editSrc(b); + InstImm inst_beq = InstImm(op_beq, zero, zero, BOffImm16(0)); + intptr_t offset = dest.getOffset() - label->offset(); + + // If first instruction is j, then this is a mixed jump. + // If second instruction is lui, then this is a loop backedge. + if (inst[0].extractOpcode() == (uint32_t(op_j) >> OpcodeShift)) { + // For unconditional mixed branches generated by jumpWithPatch + addMixedJump(b, ImmPtr((void*)dest.getOffset()), MixedJumpPatch::PATCHABLE); + } else if (inst[1].extractOpcode() == (uint32_t(op_lui) >> OpcodeShift) || + BOffImm16::IsInRange(offset)) + { + // Handle code produced by: + // backedgeJump + MOZ_ASSERT(BOffImm16::IsInRange(offset)); + MOZ_ASSERT(inst[0].extractOpcode() == (uint32_t(op_beq) >> OpcodeShift) || + inst[0].extractOpcode() == (uint32_t(op_bne) >> OpcodeShift) || + inst[0].extractOpcode() == (uint32_t(op_blez) >> OpcodeShift) || + inst[0].extractOpcode() == (uint32_t(op_bgtz) >> OpcodeShift)); + inst[0].setBOffImm16(BOffImm16(offset)); + } else if (inst[0].encode() == inst_beq.encode()) { + // Handle open mixed unconditional jumps created by + // MacroAssemblerMIPSShared::ma_b(..., wasm::Trap, ...). + // We need to add it to mixed jumps array here. + // See MacroAssemblerMIPS::branchWithCode(). + MOZ_ASSERT(inst[1].encode() == NopInst); + addMixedJump(b, ImmPtr((void*)dest.getOffset()), MixedJumpPatch::PATCHABLE); + inst[0] = InstJump(op_j, JOffImm26(0)).encode(); + } else { + // Handle open mixed conditional jumps created by + // MacroAssemblerMIPSShared::ma_b(..., wasm::Trap, ...). + inst[0] = invertBranch(inst[0], BOffImm16(4 * sizeof(uint32_t))); + // No need for a "nop" here because we can clobber scratch. + // We need to add it to mixed jumps array here. + // See MacroAssemblerMIPS::branchWithCode(). + MOZ_ASSERT(inst[1].encode() == NopInst); + MOZ_ASSERT(inst[2].encode() == NopInst); + MOZ_ASSERT(inst[3].encode() == NopInst); + addMixedJump(b, ImmPtr((void*)dest.getOffset()), MixedJumpPatch::PATCHABLE); + inst[2] = InstJump(op_j, JOffImm26(0)).encode(); + } + } + label->bind(dest.getOffset()); +} + +void AssemblerMIPSShared::retarget(Label* label, Label* target) { if (label->used() && !oom()) { diff --git a/js/src/jit/mips-shared/Assembler-mips-shared.h b/js/src/jit/mips-shared/Assembler-mips-shared.h index 8fca6f5c2..bebf8ad57 100644 --- a/js/src/jit/mips-shared/Assembler-mips-shared.h +++ b/js/src/jit/mips-shared/Assembler-mips-shared.h @@ -1211,8 +1211,9 @@ class AssemblerMIPSShared : public AssemblerShared // label operations void bind(Label* label, BufferOffset boff = BufferOffset()); void bindLater(Label* label, wasm::TrapDesc target); - virtual void bind(InstImm* inst, uintptr_t branch, uintptr_t target) = 0; + void bind(InstImm* inst, uintptr_t branch, uintptr_t target); virtual void Bind(uint8_t* rawCode, CodeOffset* label, const void* address) = 0; + void bind(RepatchLabel* label); void bind(CodeOffset* label) { label->bind(currentOffset()); } diff --git a/js/src/jit/mips32/Assembler-mips32.cpp b/js/src/jit/mips32/Assembler-mips32.cpp index 461f8d813..89c7a8c44 100644 --- a/js/src/jit/mips32/Assembler-mips32.cpp +++ b/js/src/jit/mips32/Assembler-mips32.cpp @@ -296,87 +296,6 @@ Assembler::Bind(uint8_t* rawCode, CodeOffset* label, const void* address) } } -void -Assembler::bind(InstImm* inst, uintptr_t branch, uintptr_t target) -{ - int32_t offset = target - branch; - - // Generate the patchable mixed jump for call. - if (inst->extractOpcode() == ((uint32_t)op_jal >> OpcodeShift)) { - addMixedJump(BufferOffset(branch), ImmPtr((void*)target)); - return; - } - - // If encoded offset is 4, then the jump must be short - if (BOffImm16(inst[0]).decode() == 4) { - MOZ_ASSERT(BOffImm16::IsInRange(offset)); - inst[0].setBOffImm16(BOffImm16(offset)); - inst[1].makeNop(); - return; - } - - if (BOffImm16::IsInRange(offset)) { - inst[0].setBOffImm16(BOffImm16(offset)); - inst[1].makeNop(); - return; - } - - addMixedJump(BufferOffset(branch), ImmPtr((const void*)target)); -} - -void -Assembler::bind(RepatchLabel* label) -{ - BufferOffset dest = nextOffset(); - if (label->used() && !oom()) { - // If the label has a use, then change this use to refer to - // the bound label; - BufferOffset b(label->offset()); - InstImm* inst = (InstImm*)editSrc(b); - InstImm inst_beq = InstImm(op_beq, zero, zero, BOffImm16(0)); - uint32_t offset = dest.getOffset() - label->offset(); - - // If first instruction is j, then this is a mixed jump. - // If second instruction is lui, then this is a loop backedge. - if (inst[0].extractOpcode() == (uint32_t(op_j) >> OpcodeShift)) { - // For unconditional long branches generated by jumpWithPatch - addMixedJump(b, ImmPtr((void*)dest.getOffset()), MixedJumpPatch::PATCHABLE); - } else if (inst[1].extractOpcode() == (uint32_t(op_lui) >> OpcodeShift) || - BOffImm16::IsInRange(offset)) - { - // Handle code produced by: - // backedgeJump - MOZ_ASSERT(BOffImm16::IsInRange(offset)); - MOZ_ASSERT(inst[0].extractOpcode() == (uint32_t(op_beq) >> OpcodeShift) || - inst[0].extractOpcode() == (uint32_t(op_bne) >> OpcodeShift) || - inst[0].extractOpcode() == (uint32_t(op_blez) >> OpcodeShift) || - inst[0].extractOpcode() == (uint32_t(op_bgtz) >> OpcodeShift)); - inst[0].setBOffImm16(BOffImm16(offset)); - } else if (inst[0].encode() == inst_beq.encode()) { - // Handle open mixed unconditional jumps created by - // MacroAssemblerMIPSShared::ma_b(..., wasm::Trap, ...). - // We need to add it to mixed jumps array here. - // See MacroAssemblerMIPS::branchWithCode(). - MOZ_ASSERT(inst[1].encode() == NopInst); - addMixedJump(b, ImmPtr((void*)dest.getOffset()), MixedJumpPatch::PATCHABLE); - inst[0] = InstJump(op_j, JOffImm26(0)).encode(); - } else { - // Handle open mixed conditional jumps created by - // MacroAssemblerMIPSShared::ma_b(..., wasm::Trap, ...). - inst[0] = invertBranch(inst[0], BOffImm16(4 * sizeof(void*))); - // No need for a "nop" here because we can clobber scratch. - // We need to add it to mixed jumps array here. - // See MacroAssemblerMIPS::branchWithCode(). - MOZ_ASSERT(inst[1].encode() == NopInst); - MOZ_ASSERT(inst[2].encode() == NopInst); - MOZ_ASSERT(inst[3].encode() == NopInst); - addMixedJump(b, ImmPtr((void*)dest.getOffset()), MixedJumpPatch::PATCHABLE); - inst[2] = InstJump(op_j, JOffImm26(0)).encode(); - } - } - label->bind(dest.getOffset()); -} - uint32_t Assembler::PatchWrite_NearCallSize() { diff --git a/js/src/jit/mips32/Assembler-mips32.h b/js/src/jit/mips32/Assembler-mips32.h index a519b9876..2bfb61e8e 100644 --- a/js/src/jit/mips32/Assembler-mips32.h +++ b/js/src/jit/mips32/Assembler-mips32.h @@ -144,16 +144,11 @@ class Assembler : public AssemblerMIPSShared } public: - using AssemblerMIPSShared::bind; - - void bind(RepatchLabel* label); void Bind(uint8_t* rawCode, CodeOffset* label, const void* address); static void TraceJumpRelocations(JSTracer* trc, JitCode* code, CompactBufferReader& reader); static void TraceDataRelocations(JSTracer* trc, JitCode* code, CompactBufferReader& reader); - void bind(InstImm* inst, uintptr_t branch, uintptr_t target); - static uint32_t PatchWrite_NearCallSize(); static uint32_t ExtractLuiOriValue(Instruction* inst0, Instruction* inst1); diff --git a/js/src/jit/mips64/Assembler-mips64.cpp b/js/src/jit/mips64/Assembler-mips64.cpp index 6d7636309..a7254b825 100644 --- a/js/src/jit/mips64/Assembler-mips64.cpp +++ b/js/src/jit/mips64/Assembler-mips64.cpp @@ -228,88 +228,6 @@ Assembler::Bind(uint8_t* rawCode, CodeOffset* label, const void* address) } } -void -Assembler::bind(InstImm* inst, uintptr_t branch, uintptr_t target) -{ - int64_t offset = target - branch; - - // Generate the patchable mixed jump for call. - if (inst->extractOpcode() == ((uint32_t)op_jal >> OpcodeShift)) { - addMixedJump(BufferOffset(branch), ImmPtr((void*)target)); - return; - } - - // If encoded offset is 4, then the jump must be short - if (BOffImm16(inst[0]).decode() == 4) { - MOZ_ASSERT(BOffImm16::IsInRange(offset)); - inst[0].setBOffImm16(BOffImm16(offset)); - inst[1].makeNop(); - return; - } - - if (BOffImm16::IsInRange(offset)) { - inst[0].setBOffImm16(BOffImm16(offset)); - inst[1].makeNop(); - - return; - } - - addMixedJump(BufferOffset(branch), ImmPtr((void*)target)); -} - -void -Assembler::bind(RepatchLabel* label) -{ - BufferOffset dest = nextOffset(); - if (label->used() && !oom()) { - // If the label has a use, then change this use to refer to - // the bound label; - BufferOffset b(label->offset()); - InstImm* inst = (InstImm*)editSrc(b); - InstImm inst_beq = InstImm(op_beq, zero, zero, BOffImm16(0)); - uint64_t offset = dest.getOffset() - label->offset(); - - // If first instruction is j, then this is a mixed jump. - // If second instruction is lui, then this is a loop backedge. - if (inst[0].extractOpcode() == (uint32_t(op_j) >> OpcodeShift)) { - // For unconditional mixed branches generated by jumpWithPatch - addMixedJump(b, ImmPtr((void*)dest.getOffset()), MixedJumpPatch::PATCHABLE); - } else if (inst[1].extractOpcode() == (uint32_t(op_lui) >> OpcodeShift) || - BOffImm16::IsInRange(offset)) - { - // Handle code produced by: - // backedgeJump - MOZ_ASSERT(BOffImm16::IsInRange(offset)); - MOZ_ASSERT(inst[0].extractOpcode() == (uint32_t(op_beq) >> OpcodeShift) || - inst[0].extractOpcode() == (uint32_t(op_bne) >> OpcodeShift) || - inst[0].extractOpcode() == (uint32_t(op_blez) >> OpcodeShift) || - inst[0].extractOpcode() == (uint32_t(op_bgtz) >> OpcodeShift)); - inst[0].setBOffImm16(BOffImm16(offset)); - } else if (inst[0].encode() == inst_beq.encode()) { - // Handle open mixed unconditional jumps created by - // MacroAssemblerMIPSShared::ma_b(..., wasm::Trap, ...). - // We need to add it to mixed jumps array here. - // See MacroAssemblerMIPS64::branchWithCode(). - MOZ_ASSERT(inst[1].encode() == NopInst); - addMixedJump(b, ImmPtr((void*)dest.getOffset()), MixedJumpPatch::PATCHABLE); - inst[0] = InstJump(op_j, JOffImm26(0)).encode(); - } else { - // Handle open mixed conditional jumps created by - // MacroAssemblerMIPSShared::ma_b(..., wasm::Trap, ...). - inst[0] = invertBranch(inst[0], BOffImm16(4 * sizeof(uint32_t))); - // No need for a "nop" here because we can clobber scratch. - // We need to add it to mixed jumps array here. - // See MacroAssemblerMIPS64::branchWithCode(). - MOZ_ASSERT(inst[1].encode() == NopInst); - MOZ_ASSERT(inst[2].encode() == NopInst); - MOZ_ASSERT(inst[3].encode() == NopInst); - addMixedJump(b, ImmPtr((void*)dest.getOffset()), MixedJumpPatch::PATCHABLE); - inst[2] = InstJump(op_j, JOffImm26(0)).encode(); - } - } - label->bind(dest.getOffset()); -} - uint32_t Assembler::PatchWrite_NearCallSize() { diff --git a/js/src/jit/mips64/Assembler-mips64.h b/js/src/jit/mips64/Assembler-mips64.h index 5cb9d1239..6561ba6c4 100644 --- a/js/src/jit/mips64/Assembler-mips64.h +++ b/js/src/jit/mips64/Assembler-mips64.h @@ -143,16 +143,11 @@ class Assembler : public AssemblerMIPSShared static uintptr_t GetPointer(uint8_t*); - using AssemblerMIPSShared::bind; - - void bind(RepatchLabel* label); void Bind(uint8_t* rawCode, CodeOffset* label, const void* address); static void TraceJumpRelocations(JSTracer* trc, JitCode* code, CompactBufferReader& reader); static void TraceDataRelocations(JSTracer* trc, JitCode* code, CompactBufferReader& reader); - void bind(InstImm* inst, uintptr_t branch, uintptr_t target); - static uint32_t PatchWrite_NearCallSize(); static uint64_t ExtractLoad64Value(Instruction* inst0); |