Title: [196616] trunk/Source/_javascript_Core
Revision
196616
Author
[email protected]
Date
2016-02-15 20:51:20 -0800 (Mon, 15 Feb 2016)

Log Message

[JSC] BranchAdd can override arguments of its stackmap
https://bugs.webkit.org/show_bug.cgi?id=154274

Patch by Benjamin Poulain <[email protected]> on 2016-02-15
Reviewed by Filip Pizlo.

With the 3 operands BranchAdd added in r196513, we can run into
a register allocation such that the destination register is also
used by a value in the stack map.

It use to be that BranchAdd was a 2 operand instruction.
In that form, the destination is also one of the source and
can be recovered through Sub. There is no conflict between
destination and the stackmap.

After r196513, the destination has its own value. It is uncommon
on x86 because of the aggressive aliasing but that can happen.
On ARM, that's a standard form since there is no need for aliasing.

Since the arguments of the stackmap are of type EarlyUse,
they appeared as not interfering with the destination. When the register
allocator gives the same register to the destination and something in
the stack map, the result of BranchAdd destroys the value kept alive
for the stackmap.

In this patch, I introduce a concept very similar to ForceLateUse
to keep the argument of the stackmap live in CheckAdd. The new
role is "ForceLateUseUnlessRecoverable".

In this mode, anything that is not also an input argument becomes
LateUse. As such, it interferes with the destination of CheckAdd.
The arguments are recovered by the slow patch of CheckAdd. They
remain Early use.

This new modes ensure that destination can be aliased to the source
when that's useful, while making sure it is not aliased with another
value that needs to be live on exit.

* b3/B3CheckSpecial.cpp:
(JSC::B3::CheckSpecial::forEachArg):
* b3/B3LowerToAir.cpp:
(JSC::B3::Air::LowerToAir::lower):
* b3/B3PatchpointSpecial.cpp:
(JSC::B3::PatchpointSpecial::forEachArg):
* b3/B3StackmapSpecial.cpp:
(JSC::B3::StackmapSpecial::forEachArgImpl):
(WTF::printInternal):
* b3/B3StackmapSpecial.h:
* b3/B3StackmapValue.h:

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (196615 => 196616)


--- trunk/Source/_javascript_Core/ChangeLog	2016-02-16 04:41:58 UTC (rev 196615)
+++ trunk/Source/_javascript_Core/ChangeLog	2016-02-16 04:51:20 UTC (rev 196616)
@@ -1,3 +1,54 @@
+2016-02-15  Benjamin Poulain  <[email protected]>
+
+        [JSC] BranchAdd can override arguments of its stackmap
+        https://bugs.webkit.org/show_bug.cgi?id=154274
+
+        Reviewed by Filip Pizlo.
+
+        With the 3 operands BranchAdd added in r196513, we can run into
+        a register allocation such that the destination register is also
+        used by a value in the stack map.
+
+        It use to be that BranchAdd was a 2 operand instruction.
+        In that form, the destination is also one of the source and
+        can be recovered through Sub. There is no conflict between
+        destination and the stackmap.
+
+        After r196513, the destination has its own value. It is uncommon
+        on x86 because of the aggressive aliasing but that can happen.
+        On ARM, that's a standard form since there is no need for aliasing.
+
+        Since the arguments of the stackmap are of type EarlyUse,
+        they appeared as not interfering with the destination. When the register
+        allocator gives the same register to the destination and something in
+        the stack map, the result of BranchAdd destroys the value kept alive
+        for the stackmap.
+
+        In this patch, I introduce a concept very similar to ForceLateUse
+        to keep the argument of the stackmap live in CheckAdd. The new
+        role is "ForceLateUseUnlessRecoverable".
+
+        In this mode, anything that is not also an input argument becomes
+        LateUse. As such, it interferes with the destination of CheckAdd.
+        The arguments are recovered by the slow patch of CheckAdd. They
+        remain Early use.
+
+        This new modes ensure that destination can be aliased to the source
+        when that's useful, while making sure it is not aliased with another
+        value that needs to be live on exit.
+
+        * b3/B3CheckSpecial.cpp:
+        (JSC::B3::CheckSpecial::forEachArg):
+        * b3/B3LowerToAir.cpp:
+        (JSC::B3::Air::LowerToAir::lower):
+        * b3/B3PatchpointSpecial.cpp:
+        (JSC::B3::PatchpointSpecial::forEachArg):
+        * b3/B3StackmapSpecial.cpp:
+        (JSC::B3::StackmapSpecial::forEachArgImpl):
+        (WTF::printInternal):
+        * b3/B3StackmapSpecial.h:
+        * b3/B3StackmapValue.h:
+
 2016-02-15  Joseph Pecoraro  <[email protected]>
 
         Web Inspector: Web Workers have no access to console for debugging

Modified: trunk/Source/_javascript_Core/b3/B3CheckSpecial.cpp (196615 => 196616)


--- trunk/Source/_javascript_Core/b3/B3CheckSpecial.cpp	2016-02-16 04:41:58 UTC (rev 196615)
+++ trunk/Source/_javascript_Core/b3/B3CheckSpecial.cpp	2016-02-16 04:51:20 UTC (rev 196616)
@@ -113,7 +113,11 @@
             unsigned index = &arg - &hidden.args[0];
             callback(inst.args[1 + index], role, type, width);
         });
-    forEachArgImpl(numB3Args(inst), m_numCheckArgs + 1, inst, m_stackmapRole, callback);
+
+    Optional<unsigned> firstRecoverableIndex;
+    if (m_checkOpcode == BranchAdd32 || m_checkOpcode == BranchAdd64)
+        firstRecoverableIndex = 1;
+    forEachArgImpl(numB3Args(inst), m_numCheckArgs + 1, inst, m_stackmapRole, firstRecoverableIndex, callback);
 }
 
 bool CheckSpecial::isValid(Inst& inst)

Modified: trunk/Source/_javascript_Core/b3/B3LowerToAir.cpp (196615 => 196616)


--- trunk/Source/_javascript_Core/b3/B3LowerToAir.cpp	2016-02-16 04:41:58 UTC (rev 196615)
+++ trunk/Source/_javascript_Core/b3/B3LowerToAir.cpp	2016-02-16 04:51:20 UTC (rev 196616)
@@ -2120,6 +2120,7 @@
             switch (m_value->opcode()) {
             case CheckAdd:
                 opcode = opcodeForType(BranchAdd32, BranchAdd64, m_value->type());
+                stackmapRole = StackmapSpecial::ForceLateUseUnlessRecoverable;
                 commutativity = Commutative;
                 break;
             case CheckSub:

Modified: trunk/Source/_javascript_Core/b3/B3PatchpointSpecial.cpp (196615 => 196616)


--- trunk/Source/_javascript_Core/b3/B3PatchpointSpecial.cpp	2016-02-16 04:41:58 UTC (rev 196615)
+++ trunk/Source/_javascript_Core/b3/B3PatchpointSpecial.cpp	2016-02-16 04:51:20 UTC (rev 196616)
@@ -51,7 +51,7 @@
     if (inst.origin->type() != Void)
         callback(inst.args[argIndex++], Arg::Def, inst.origin->airType(), inst.origin->airWidth());
 
-    forEachArgImpl(0, argIndex, inst, SameAsRep, callback);
+    forEachArgImpl(0, argIndex, inst, SameAsRep, Nullopt, callback);
     argIndex += inst.origin->numChildren();
 
     for (unsigned i = inst.origin->as<PatchpointValue>()->numGPScratchRegisters; i--;)

Modified: trunk/Source/_javascript_Core/b3/B3StackmapSpecial.cpp (196615 => 196616)


--- trunk/Source/_javascript_Core/b3/B3StackmapSpecial.cpp	2016-02-16 04:41:58 UTC (rev 196615)
+++ trunk/Source/_javascript_Core/b3/B3StackmapSpecial.cpp	2016-02-16 04:51:20 UTC (rev 196616)
@@ -73,7 +73,8 @@
 
 void StackmapSpecial::forEachArgImpl(
     unsigned numIgnoredB3Args, unsigned numIgnoredAirArgs,
-    Inst& inst, RoleMode roleMode, const ScopedLambda<Inst::EachArgCallback>& callback)
+    Inst& inst, RoleMode roleMode, Optional<unsigned> firstRecoverableIndex,
+    const ScopedLambda<Inst::EachArgCallback>& callback)
 {
     StackmapValue* value = inst.origin->as<StackmapValue>();
     ASSERT(value);
@@ -89,6 +90,13 @@
 
         Arg::Role role;
         switch (roleMode) {
+        case ForceLateUseUnlessRecoverable:
+            ASSERT(firstRecoverableIndex);
+            if (arg != inst.args[*firstRecoverableIndex] && arg != inst.args[*firstRecoverableIndex + 1]) {
+                role = Arg::LateColdUse;
+                break;
+            }
+            FALLTHROUGH;
         case SameAsRep:
             switch (child.rep().kind()) {
             case ValueRep::WarmAny:
@@ -273,6 +281,9 @@
     case StackmapSpecial::SameAsRep:
         out.print("SameAsRep");
         return;
+    case StackmapSpecial::ForceLateUseUnlessRecoverable:
+        out.print("ForceLateUseUnlessRecoverable");
+        return;
     case StackmapSpecial::ForceLateUse:
         out.print("ForceLateUse");
         return;

Modified: trunk/Source/_javascript_Core/b3/B3StackmapSpecial.h (196615 => 196616)


--- trunk/Source/_javascript_Core/b3/B3StackmapSpecial.h	2016-02-16 04:41:58 UTC (rev 196615)
+++ trunk/Source/_javascript_Core/b3/B3StackmapSpecial.h	2016-02-16 04:51:20 UTC (rev 196616)
@@ -47,6 +47,7 @@
 
     enum RoleMode : int8_t {
         SameAsRep,
+        ForceLateUseUnlessRecoverable,
         ForceLateUse
     };
 
@@ -59,7 +60,8 @@
     // subclasses that implement that.
     void forEachArgImpl(
         unsigned numIgnoredB3Args, unsigned numIgnoredAirArgs,
-        Air::Inst&, RoleMode, const ScopedLambda<Air::Inst::EachArgCallback>&);
+        Air::Inst&, RoleMode, Optional<unsigned> firstRecoverableIndex,
+        const ScopedLambda<Air::Inst::EachArgCallback>&);
     
     bool isValidImpl(
         unsigned numIgnoredB3Args, unsigned numIgnoredAirArgs,

Modified: trunk/Source/_javascript_Core/b3/B3StackmapValue.h (196615 => 196616)


--- trunk/Source/_javascript_Core/b3/B3StackmapValue.h	2016-02-16 04:41:58 UTC (rev 196615)
+++ trunk/Source/_javascript_Core/b3/B3StackmapValue.h	2016-02-16 04:51:20 UTC (rev 196616)
@@ -91,6 +91,11 @@
     {
         appendVectorWithRep(vector, ValueRep::ColdAny);
     }
+    template<typename VectorType>
+    void appendLateColdAnys(const VectorType& vector)
+    {
+        appendVectorWithRep(vector, ValueRep::LateColdAny);
+    }
 
     // This is a helper for something you might do a lot of: append a value that should be constrained
     // to SomeRegister.
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to