Changeset 260310 in webkit


Ignore:
Timestamp:
Apr 18, 2020 7:59:11 AM (4 years ago)
Author:
commit-queue@webkit.org
Message:

Fix code origin when lowering offlineasm instructions on MIPS/ARM64E
https://bugs.webkit.org/show_bug.cgi?id=207330

Patch by Angelos Oikonomopoulos <Angelos Oikonomopoulos> on 2020-04-18
Reviewed by Mark Lam.

Instruction operands are mapped to RegisterID in RegisterID.forName
and the operation is memoized. Therefore, we can't use the codeOrigin
of the operand at that point. Use the codeOrigin of the original
instruction instead.

  • offlineasm/arm64e.rb:
  • offlineasm/ast.rb:
  • offlineasm/mips.rb:
  • offlineasm/risc.rb:
Location:
trunk/Source/JavaScriptCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r260309 r260310  
     12020-04-18  Angelos Oikonomopoulos  <angelos@igalia.com>
     2
     3        Fix code origin when lowering offlineasm instructions on MIPS/ARM64E
     4        https://bugs.webkit.org/show_bug.cgi?id=207330
     5
     6        Reviewed by Mark Lam.
     7
     8        Instruction operands are mapped to RegisterID in RegisterID.forName
     9        and the operation is memoized. Therefore, we can't use the codeOrigin
     10        of the operand at that point. Use the codeOrigin of the original
     11        instruction instead.
     12
     13        * offlineasm/arm64e.rb:
     14        * offlineasm/ast.rb:
     15        * offlineasm/mips.rb:
     16        * offlineasm/risc.rb:
     17
    1182020-04-18  Angelos Oikonomopoulos  <angelos@igalia.com>
    219
  • trunk/Source/JavaScriptCore/offlineasm/arm64e.rb

    r245064 r260310  
    4545                if node.operands.size > 1
    4646                    if node.operands[1].is_a? RegisterID
    47                         tag = riscAsRegister(newList, postInstructions, node.operands[1], "p", false)
     47                        tag = riscLowerOperandToRegister(node, newList, postInstructions, 1, "p", false)
    4848                    else
    4949                        tag = Tmp.new(codeOrigin, :gpr)
    5050                        newList << Instruction.new(codeOrigin, "move", [node.operands[1], tag], annotation)
    5151                    end
    52                     operands = [riscAsRegister(newList, postInstructions, node.operands[0], "p", false), tag]
    53                     newList << Instruction.new(codeOrigin, node.opcode, operands, annotation)
     52                    operands = [
     53                        riscLowerOperandToRegister(node, newList, postInstructions, 0, "p", false),
     54                        tag
     55                    ]
     56                    newList << Instruction.cloneWithNewOperands(operands)
    5457                    wasHandled = true
    5558                end
     
    6568                    end
    6669                }
    67                 newList << Instruction.new(codeOrigin, node.opcode, newOperands, annotation)
     70                newList << Instruction.cloneWithNewOperands(newOperands)
    6871                wasHandled = true
    6972            end
  • trunk/Source/JavaScriptCore/offlineasm/ast.rb

    r259990 r260310  
    918918        @annotation = annotation
    919919    end
    920    
     920
     921    def cloneWithNewOperands(newOperands)
     922        Instruction.new(self.codeOrigin, self.opcode, newOperands, self.annotation)
     923    end
     924
    921925    def children
    922926        operands
  • trunk/Source/JavaScriptCore/offlineasm/mips.rb

    r260309 r260310  
    555555end
    556556
    557 def mipsAsRegister(preList, postList, operand, needRestore)
    558     tmp = MIPS_CALL_REG
    559     if operand.address?
    560         preList << Instruction.new(operand.codeOrigin, "loadp", [operand, MIPS_CALL_REG])
    561     elsif operand.is_a? LabelReference
    562         preList << Instruction.new(operand.codeOrigin, "la", [operand, MIPS_CALL_REG])
    563     elsif operand.register? and operand != MIPS_CALL_REG
    564         preList << Instruction.new(operand.codeOrigin, "move", [operand, MIPS_CALL_REG])
    565     else
    566         needRestore = false
    567         tmp = operand
    568     end
    569     if needRestore
    570         postList << Instruction.new(operand.codeOrigin, "move", [MIPS_GPSAVE_REG, MIPS_GP_REG])
    571     end
    572     tmp
     557class Instruction
     558    # Replace operands with a single register operand.
     559    # Note: in contrast to the risc version, this method drops all other operands.
     560    def mipsCloneWithOperandLowered(preList, postList, operandIndex, needRestore)
     561        operand = self.operands[operandIndex]
     562        tmp = MIPS_CALL_REG
     563        if operand.address?
     564            preList << Instruction.new(self.codeOrigin, "loadp", [operand, MIPS_CALL_REG])
     565        elsif operand.is_a? LabelReference
     566            preList << Instruction.new(self.codeOrigin, "la", [operand, MIPS_CALL_REG])
     567        elsif operand.register? and operand != MIPS_CALL_REG
     568            preList << Instruction.new(self.codeOrigin, "move", [operand, MIPS_CALL_REG])
     569        else
     570            needRestore = false
     571            tmp = operand
     572        end
     573        if needRestore
     574            postList << Instruction.new(self.codeOrigin, "move", [MIPS_GPSAVE_REG, MIPS_GP_REG])
     575        end
     576        cloneWithNewOperands([tmp])
     577    end
    573578end
    574579
     
    582587            case node.opcode
    583588            when "jmp"
    584                 newList << Instruction.new(node.codeOrigin,
    585                                            node.opcode,
    586                                            [mipsAsRegister(newList, [], node.operands[0], false)])
     589                newList << node.mipsCloneWithOperandLowered(newList, [], 0, false)
    587590            when "call"
    588                 newList << Instruction.new(node.codeOrigin,
    589                                            node.opcode,
    590                                            [mipsAsRegister(newList, postInstructions, node.operands[0], true)])
     591                newList << node.mipsCloneWithOperandLowered(newList, postInstructions, 0, true)
    591592            when "slt", "sltu"
    592                 newList << Instruction.new(node.codeOrigin,
    593                                            node.opcode,
    594                                            riscAsRegisters(newList, [], node.operands, "i"))
     593                newList << node.riscCloneWithOperandsLowered(newList, [], "i")
    595594            when "sltub", "sltb"
    596                 newList << Instruction.new(node.codeOrigin,
    597                                            node.opcode,
    598                                            riscAsRegisters(newList, [], node.operands, "b"))
     595                newList << node.riscCloneWithOperandsLowered(newList, [], "b")
    599596            when "andb"
    600597                newList << Instruction.new(node.codeOrigin,
    601598                                           "andi",
    602                                            riscAsRegisters(newList, [], node.operands, "b"))
     599                                           riscLowerOperandsToRegisters(node, newList, [], "b"),
     600                                           node.annotation)
    603601            when /^(bz|bnz|bs|bo)/
    604602                tl = $~.post_match == "" ? "i" : $~.post_match
    605                 newList << Instruction.new(node.codeOrigin,
    606                                            node.opcode,
    607                                            riscAsRegisters(newList, [], node.operands, tl))
     603                newList << node.riscCloneWithOperandsLowered(newList, [], tl)
    608604            else
    609605                newList << node
  • trunk/Source/JavaScriptCore/offlineasm/risc.rb

    r260246 r260310  
    429429#
    430430
    431 def riscAsRegister(preList, postList, operand, suffix, needStore)
     431def riscLowerOperandToRegister(insn, preList, postList, operandIndex, suffix, needStore)
     432    operand = insn.operands[operandIndex]
    432433    return operand unless operand.address?
    433    
    434     tmp = Tmp.new(operand.codeOrigin, if suffix == "d" then :fpr else :gpr end)
    435     preList << Instruction.new(operand.codeOrigin, "load" + suffix, [operand, tmp])
     434
     435    tmp = Tmp.new(insn.codeOrigin, if suffix == "d" then :fpr else :gpr end)
     436    preList << Instruction.new(insn.codeOrigin, "load" + suffix, [operand, tmp])
    436437    if needStore
    437         postList << Instruction.new(operand.codeOrigin, "store" + suffix, [tmp, operand])
     438        postList << Instruction.new(insn.codeOrigin, "store" + suffix, [tmp, operand])
    438439    end
    439440    tmp
    440441end
    441442
    442 def riscAsRegisters(preList, postList, operands, suffix)
     443def riscLowerOperandsToRegisters(insn, preList, postList, suffix)
    443444    newOperands = []
    444     operands.each_with_index {
     445    insn.operands.each_with_index {
    445446        | operand, index |
    446         newOperands << riscAsRegister(preList, postList, operand, suffix, index == operands.size - 1)
     447        newOperands << riscLowerOperandToRegister(insn, preList, postList, index, suffix, index == insn.operands.size - 1)
    447448    }
    448449    newOperands
     450end
     451
     452class Instruction
     453    def riscCloneWithOperandLowered(preList, postList, operandIndex, suffix, needStore)
     454        operand = riscLowerOperandToRegister(self, preList, postList, operandIndex, suffix, needStore)
     455        cloneWithNewOperands([operand])
     456    end
     457    def riscCloneWithOperandsLowered(preList, postList, suffix)
     458        operands = riscLowerOperandsToRegisters(self, preList, postList, suffix)
     459        cloneWithNewOperands(operands)
     460    end
    449461end
    450462
     
    465477            when "addi", "addis", "andi", "lshifti", "muli", "negi", "noti", "ori", "oris",
    466478                "rshifti", "urshifti", "subi", "subis", "xori", /^bi/, /^bti/, /^ci/, /^ti/
    467                 newList << Instruction.new(node.codeOrigin,
    468                                            node.opcode,
    469                                            riscAsRegisters(newList, postInstructions, node.operands, "i"),
    470                                            annotation)
     479                newList << node.riscCloneWithOperandsLowered(newList, postInstructions, "i")
    471480            when "orh"
    472                 newList << Instruction.new(node.codeOrigin,
    473                                            node.opcode,
    474                                            riscAsRegisters(newList, postInstructions, node.operands, "h"),
    475                                            annotation)
     481                newList << node.riscCloneWithOperandsLowered(newList, postInstructions, "h")
    476482            when "addp", "andp", "lshiftp", "mulp", "negp", "orp", "rshiftp", "urshiftp",
    477483                "subp", "xorp", /^bp/, /^btp/, /^cp/
    478                 newList << Instruction.new(node.codeOrigin,
    479                                            node.opcode,
    480                                            riscAsRegisters(newList, postInstructions, node.operands, "p"),
    481                                            annotation)
     484                newList << node.riscCloneWithOperandsLowered(newList, postInstructions, "p")
    482485            when "addq", "andq", "lshiftq", "mulq", "negq", "orq", "rshiftq", "urshiftq",
    483486                "subq", "xorq", /^bq/, /^btq/, /^cq/
    484                 newList << Instruction.new(node.codeOrigin,
    485                                            node.opcode,
    486                                            riscAsRegisters(newList, postInstructions, node.operands, "q"),
    487                                            annotation)
     487                newList << node.riscCloneWithOperandsLowered(newList, postInstructions, "q")
    488488            when "bbeq", "bbneq", "bba", "bbaeq", "bbb", "bbbeq", "btbz", "btbnz", "tbz", "tbnz",
    489489                "cbeq", "cbneq", "cba", "cbaeq", "cbb", "cbbeq"
    490                 newList << Instruction.new(node.codeOrigin,
    491                                            node.opcode,
    492                                            riscAsRegisters(newList, postInstructions, node.operands, "b"),
    493                                            annotation)
     490                newList << node.riscCloneWithOperandsLowered(newList, postInstructions, "b")
    494491            when "bbgt", "bbgteq", "bblt", "bblteq", "btbs", "tbs", "cbgt", "cbgteq", "cblt", "cblteq"
    495                 newList << Instruction.new(node.codeOrigin,
    496                                            node.opcode,
    497                                            riscAsRegisters(newList, postInstructions, node.operands, "bs"),
    498                                            annotation)
     492                newList << node.riscCloneWithOperandsLowered(newList, postInstructions, "bs")
    499493            when "addd", "divd", "subd", "muld", "sqrtd", /^bd/
    500                 newList << Instruction.new(node.codeOrigin,
    501                                            node.opcode,
    502                                            riscAsRegisters(newList, postInstructions, node.operands, "d"),
    503                                            annotation)
     494                newList << node.riscCloneWithOperandsLowered(newList, postInstructions, "d")
    504495            when "jmp", "call"
    505                 newList << Instruction.new(node.codeOrigin,
    506                                            node.opcode,
    507                                            [riscAsRegister(newList, postInstructions, node.operands[0], "p", false)],
    508                                            annotation)
     496                newList << node.riscCloneWithOperandLowered(newList, postInstructions, 0, "p", false)
    509497            else
    510498                newList << node
Note: See TracChangeset for help on using the changeset viewer.