Title: [260310] trunk/Source/_javascript_Core
Revision
260310
Author
[email protected]
Date
2020-04-18 07:59:11 -0700 (Sat, 18 Apr 2020)

Log Message

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

Patch by Angelos Oikonomopoulos <[email protected]> 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:

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (260309 => 260310)


--- trunk/Source/_javascript_Core/ChangeLog	2020-04-18 14:19:47 UTC (rev 260309)
+++ trunk/Source/_javascript_Core/ChangeLog	2020-04-18 14:59:11 UTC (rev 260310)
@@ -1,5 +1,22 @@
 2020-04-18  Angelos Oikonomopoulos  <[email protected]>
 
+        Fix code origin when lowering offlineasm instructions on MIPS/ARM64E
+        https://bugs.webkit.org/show_bug.cgi?id=207330
+
+        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:
+
+2020-04-18  Angelos Oikonomopoulos  <[email protected]>
+
         REGRESSION(r260246): It broke build on MIPS32 
         https://bugs.webkit.org/show_bug.cgi?id=210665
 

Modified: trunk/Source/_javascript_Core/offlineasm/arm64e.rb (260309 => 260310)


--- trunk/Source/_javascript_Core/offlineasm/arm64e.rb	2020-04-18 14:19:47 UTC (rev 260309)
+++ trunk/Source/_javascript_Core/offlineasm/arm64e.rb	2020-04-18 14:59:11 UTC (rev 260310)
@@ -44,13 +44,16 @@
             when "jmp", "call"
                 if node.operands.size > 1
                     if node.operands[1].is_a? RegisterID
-                        tag = riscAsRegister(newList, postInstructions, node.operands[1], "p", false)
+                        tag = riscLowerOperandToRegister(node, newList, postInstructions, 1, "p", false)
                     else
                         tag = Tmp.new(codeOrigin, :gpr)
                         newList << Instruction.new(codeOrigin, "move", [node.operands[1], tag], annotation)
                     end
-                    operands = [riscAsRegister(newList, postInstructions, node.operands[0], "p", false), tag]
-                    newList << Instruction.new(codeOrigin, node.opcode, operands, annotation)
+                    operands = [
+                        riscLowerOperandToRegister(node, newList, postInstructions, 0, "p", false),
+                        tag
+                    ]
+                    newList << Instruction.cloneWithNewOperands(operands)
                     wasHandled = true
                 end
             when "untagArrayPtr"
@@ -64,7 +67,7 @@
                         operand
                     end
                 }
-                newList << Instruction.new(codeOrigin, node.opcode, newOperands, annotation)
+                newList << Instruction.cloneWithNewOperands(newOperands)
                 wasHandled = true
             end
             newList += postInstructions if wasHandled

Modified: trunk/Source/_javascript_Core/offlineasm/ast.rb (260309 => 260310)


--- trunk/Source/_javascript_Core/offlineasm/ast.rb	2020-04-18 14:19:47 UTC (rev 260309)
+++ trunk/Source/_javascript_Core/offlineasm/ast.rb	2020-04-18 14:59:11 UTC (rev 260310)
@@ -917,7 +917,11 @@
         @operands = operands
         @annotation = annotation
     end
-    
+
+    def cloneWithNewOperands(newOperands)
+        Instruction.new(self.codeOrigin, self.opcode, newOperands, self.annotation)
+    end
+
     def children
         operands
     end

Modified: trunk/Source/_javascript_Core/offlineasm/mips.rb (260309 => 260310)


--- trunk/Source/_javascript_Core/offlineasm/mips.rb	2020-04-18 14:19:47 UTC (rev 260309)
+++ trunk/Source/_javascript_Core/offlineasm/mips.rb	2020-04-18 14:59:11 UTC (rev 260310)
@@ -554,22 +554,27 @@
     end
 end
 
-def mipsAsRegister(preList, postList, operand, needRestore)
-    tmp = MIPS_CALL_REG
-    if operand.address?
-        preList << Instruction.new(operand.codeOrigin, "loadp", [operand, MIPS_CALL_REG])
-    elsif operand.is_a? LabelReference
-        preList << Instruction.new(operand.codeOrigin, "la", [operand, MIPS_CALL_REG])
-    elsif operand.register? and operand != MIPS_CALL_REG
-        preList << Instruction.new(operand.codeOrigin, "move", [operand, MIPS_CALL_REG])
-    else
-        needRestore = false
-        tmp = operand
+class Instruction
+    # Replace operands with a single register operand.
+    # Note: in contrast to the risc version, this method drops all other operands.
+    def mipsCloneWithOperandLowered(preList, postList, operandIndex, needRestore)
+        operand = self.operands[operandIndex]
+        tmp = MIPS_CALL_REG
+        if operand.address?
+            preList << Instruction.new(self.codeOrigin, "loadp", [operand, MIPS_CALL_REG])
+        elsif operand.is_a? LabelReference
+            preList << Instruction.new(self.codeOrigin, "la", [operand, MIPS_CALL_REG])
+        elsif operand.register? and operand != MIPS_CALL_REG
+            preList << Instruction.new(self.codeOrigin, "move", [operand, MIPS_CALL_REG])
+        else
+            needRestore = false
+            tmp = operand
+        end
+        if needRestore
+            postList << Instruction.new(self.codeOrigin, "move", [MIPS_GPSAVE_REG, MIPS_GP_REG])
+        end
+        cloneWithNewOperands([tmp])
     end
-    if needRestore
-        postList << Instruction.new(operand.codeOrigin, "move", [MIPS_GPSAVE_REG, MIPS_GP_REG])
-    end
-    tmp
 end
 
 def mipsLowerMisplacedAddresses(list)
@@ -581,30 +586,21 @@
             annotation = node.annotation
             case node.opcode
             when "jmp"
-                newList << Instruction.new(node.codeOrigin,
-                                           node.opcode,
-                                           [mipsAsRegister(newList, [], node.operands[0], false)])
+                newList << node.mipsCloneWithOperandLowered(newList, [], 0, false)
             when "call"
-                newList << Instruction.new(node.codeOrigin,
-                                           node.opcode,
-                                           [mipsAsRegister(newList, postInstructions, node.operands[0], true)])
+                newList << node.mipsCloneWithOperandLowered(newList, postInstructions, 0, true)
             when "slt", "sltu"
-                newList << Instruction.new(node.codeOrigin,
-                                           node.opcode,
-                                           riscAsRegisters(newList, [], node.operands, "i"))
+                newList << node.riscCloneWithOperandsLowered(newList, [], "i")
             when "sltub", "sltb"
-                newList << Instruction.new(node.codeOrigin,
-                                           node.opcode,
-                                           riscAsRegisters(newList, [], node.operands, "b"))
+                newList << node.riscCloneWithOperandsLowered(newList, [], "b")
             when "andb"
                 newList << Instruction.new(node.codeOrigin,
                                            "andi",
-                                           riscAsRegisters(newList, [], node.operands, "b"))
+                                           riscLowerOperandsToRegisters(node, newList, [], "b"),
+                                           node.annotation)
             when /^(bz|bnz|bs|bo)/
                 tl = $~.post_match == "" ? "i" : $~.post_match
-                newList << Instruction.new(node.codeOrigin,
-                                           node.opcode,
-                                           riscAsRegisters(newList, [], node.operands, tl))
+                newList << node.riscCloneWithOperandsLowered(newList, [], tl)
             else
                 newList << node
             end

Modified: trunk/Source/_javascript_Core/offlineasm/risc.rb (260309 => 260310)


--- trunk/Source/_javascript_Core/offlineasm/risc.rb	2020-04-18 14:19:47 UTC (rev 260309)
+++ trunk/Source/_javascript_Core/offlineasm/risc.rb	2020-04-18 14:59:11 UTC (rev 260310)
@@ -428,26 +428,38 @@
 # addi tmp, bar
 #
 
-def riscAsRegister(preList, postList, operand, suffix, needStore)
+def riscLowerOperandToRegister(insn, preList, postList, operandIndex, suffix, needStore)
+    operand = insn.operands[operandIndex]
     return operand unless operand.address?
-    
-    tmp = Tmp.new(operand.codeOrigin, if suffix == "d" then :fpr else :gpr end)
-    preList << Instruction.new(operand.codeOrigin, "load" + suffix, [operand, tmp])
+
+    tmp = Tmp.new(insn.codeOrigin, if suffix == "d" then :fpr else :gpr end)
+    preList << Instruction.new(insn.codeOrigin, "load" + suffix, [operand, tmp])
     if needStore
-        postList << Instruction.new(operand.codeOrigin, "store" + suffix, [tmp, operand])
+        postList << Instruction.new(insn.codeOrigin, "store" + suffix, [tmp, operand])
     end
     tmp
 end
 
-def riscAsRegisters(preList, postList, operands, suffix)
+def riscLowerOperandsToRegisters(insn, preList, postList, suffix)
     newOperands = []
-    operands.each_with_index {
+    insn.operands.each_with_index {
         | operand, index |
-        newOperands << riscAsRegister(preList, postList, operand, suffix, index == operands.size - 1)
+        newOperands << riscLowerOperandToRegister(insn, preList, postList, index, suffix, index == insn.operands.size - 1)
     }
     newOperands
 end
 
+class Instruction
+    def riscCloneWithOperandLowered(preList, postList, operandIndex, suffix, needStore)
+        operand = riscLowerOperandToRegister(self, preList, postList, operandIndex, suffix, needStore)
+        cloneWithNewOperands([operand])
+    end
+    def riscCloneWithOperandsLowered(preList, postList, suffix)
+        operands = riscLowerOperandsToRegisters(self, preList, postList, suffix)
+        cloneWithNewOperands(operands)
+    end
+end
+
 def riscLowerMisplacedAddresses(list)
     newList = []
     hasBackendSpecificLowering = Instruction.respond_to? "lowerMisplacedAddresses#{$activeBackend}"
@@ -464,48 +476,24 @@
             case node.opcode
             when "addi", "addis", "andi", "lshifti", "muli", "negi", "noti", "ori", "oris",
                 "rshifti", "urshifti", "subi", "subis", "xori", /^bi/, /^bti/, /^ci/, /^ti/
-                newList << Instruction.new(node.codeOrigin,
-                                           node.opcode,
-                                           riscAsRegisters(newList, postInstructions, node.operands, "i"),
-                                           annotation)
+                newList << node.riscCloneWithOperandsLowered(newList, postInstructions, "i")
             when "orh"
-                newList << Instruction.new(node.codeOrigin,
-                                           node.opcode,
-                                           riscAsRegisters(newList, postInstructions, node.operands, "h"),
-                                           annotation)
+                newList << node.riscCloneWithOperandsLowered(newList, postInstructions, "h")
             when "addp", "andp", "lshiftp", "mulp", "negp", "orp", "rshiftp", "urshiftp",
                 "subp", "xorp", /^bp/, /^btp/, /^cp/
-                newList << Instruction.new(node.codeOrigin,
-                                           node.opcode,
-                                           riscAsRegisters(newList, postInstructions, node.operands, "p"),
-                                           annotation)
+                newList << node.riscCloneWithOperandsLowered(newList, postInstructions, "p")
             when "addq", "andq", "lshiftq", "mulq", "negq", "orq", "rshiftq", "urshiftq",
                 "subq", "xorq", /^bq/, /^btq/, /^cq/
-                newList << Instruction.new(node.codeOrigin,
-                                           node.opcode,
-                                           riscAsRegisters(newList, postInstructions, node.operands, "q"),
-                                           annotation)
+                newList << node.riscCloneWithOperandsLowered(newList, postInstructions, "q")
             when "bbeq", "bbneq", "bba", "bbaeq", "bbb", "bbbeq", "btbz", "btbnz", "tbz", "tbnz",
                 "cbeq", "cbneq", "cba", "cbaeq", "cbb", "cbbeq"
-                newList << Instruction.new(node.codeOrigin,
-                                           node.opcode,
-                                           riscAsRegisters(newList, postInstructions, node.operands, "b"),
-                                           annotation)
+                newList << node.riscCloneWithOperandsLowered(newList, postInstructions, "b")
             when "bbgt", "bbgteq", "bblt", "bblteq", "btbs", "tbs", "cbgt", "cbgteq", "cblt", "cblteq"
-                newList << Instruction.new(node.codeOrigin,
-                                           node.opcode,
-                                           riscAsRegisters(newList, postInstructions, node.operands, "bs"),
-                                           annotation)
+                newList << node.riscCloneWithOperandsLowered(newList, postInstructions, "bs")
             when "addd", "divd", "subd", "muld", "sqrtd", /^bd/
-                newList << Instruction.new(node.codeOrigin,
-                                           node.opcode,
-                                           riscAsRegisters(newList, postInstructions, node.operands, "d"),
-                                           annotation)
+                newList << node.riscCloneWithOperandsLowered(newList, postInstructions, "d")
             when "jmp", "call"
-                newList << Instruction.new(node.codeOrigin,
-                                           node.opcode,
-                                           [riscAsRegister(newList, postInstructions, node.operands[0], "p", false)],
-                                           annotation)
+                newList << node.riscCloneWithOperandLowered(newList, postInstructions, 0, "p", false)
             else
                 newList << node
             end
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to