Changeset 196616 in webkit


Ignore:
Timestamp:
Feb 15, 2016 8:51:20 PM (8 years ago)
Author:
commit-queue@webkit.org
Message:

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

Patch by Benjamin Poulain <bpoulain@apple.com> 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:
Location:
trunk/Source/JavaScriptCore
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r196594 r196616  
     12016-02-15  Benjamin Poulain  <bpoulain@apple.com>
     2
     3        [JSC] BranchAdd can override arguments of its stackmap
     4        https://bugs.webkit.org/show_bug.cgi?id=154274
     5
     6        Reviewed by Filip Pizlo.
     7
     8        With the 3 operands BranchAdd added in r196513, we can run into
     9        a register allocation such that the destination register is also
     10        used by a value in the stack map.
     11
     12        It use to be that BranchAdd was a 2 operand instruction.
     13        In that form, the destination is also one of the source and
     14        can be recovered through Sub. There is no conflict between
     15        destination and the stackmap.
     16
     17        After r196513, the destination has its own value. It is uncommon
     18        on x86 because of the aggressive aliasing but that can happen.
     19        On ARM, that's a standard form since there is no need for aliasing.
     20
     21        Since the arguments of the stackmap are of type EarlyUse,
     22        they appeared as not interfering with the destination. When the register
     23        allocator gives the same register to the destination and something in
     24        the stack map, the result of BranchAdd destroys the value kept alive
     25        for the stackmap.
     26
     27        In this patch, I introduce a concept very similar to ForceLateUse
     28        to keep the argument of the stackmap live in CheckAdd. The new
     29        role is "ForceLateUseUnlessRecoverable".
     30
     31        In this mode, anything that is not also an input argument becomes
     32        LateUse. As such, it interferes with the destination of CheckAdd.
     33        The arguments are recovered by the slow patch of CheckAdd. They
     34        remain Early use.
     35
     36        This new modes ensure that destination can be aliased to the source
     37        when that's useful, while making sure it is not aliased with another
     38        value that needs to be live on exit.
     39
     40        * b3/B3CheckSpecial.cpp:
     41        (JSC::B3::CheckSpecial::forEachArg):
     42        * b3/B3LowerToAir.cpp:
     43        (JSC::B3::Air::LowerToAir::lower):
     44        * b3/B3PatchpointSpecial.cpp:
     45        (JSC::B3::PatchpointSpecial::forEachArg):
     46        * b3/B3StackmapSpecial.cpp:
     47        (JSC::B3::StackmapSpecial::forEachArgImpl):
     48        (WTF::printInternal):
     49        * b3/B3StackmapSpecial.h:
     50        * b3/B3StackmapValue.h:
     51
    1522016-02-15  Joseph Pecoraro  <pecoraro@apple.com>
    253
  • trunk/Source/JavaScriptCore/b3/B3CheckSpecial.cpp

    r196573 r196616  
    114114            callback(inst.args[1 + index], role, type, width);
    115115        });
    116     forEachArgImpl(numB3Args(inst), m_numCheckArgs + 1, inst, m_stackmapRole, callback);
     116
     117    Optional<unsigned> firstRecoverableIndex;
     118    if (m_checkOpcode == BranchAdd32 || m_checkOpcode == BranchAdd64)
     119        firstRecoverableIndex = 1;
     120    forEachArgImpl(numB3Args(inst), m_numCheckArgs + 1, inst, m_stackmapRole, firstRecoverableIndex, callback);
    117121}
    118122
  • trunk/Source/JavaScriptCore/b3/B3LowerToAir.cpp

    r196513 r196616  
    21212121            case CheckAdd:
    21222122                opcode = opcodeForType(BranchAdd32, BranchAdd64, m_value->type());
     2123                stackmapRole = StackmapSpecial::ForceLateUseUnlessRecoverable;
    21232124                commutativity = Commutative;
    21242125                break;
  • trunk/Source/JavaScriptCore/b3/B3PatchpointSpecial.cpp

    r194542 r196616  
    5252        callback(inst.args[argIndex++], Arg::Def, inst.origin->airType(), inst.origin->airWidth());
    5353
    54     forEachArgImpl(0, argIndex, inst, SameAsRep, callback);
     54    forEachArgImpl(0, argIndex, inst, SameAsRep, Nullopt, callback);
    5555    argIndex += inst.origin->numChildren();
    5656
  • trunk/Source/JavaScriptCore/b3/B3StackmapSpecial.cpp

    r195139 r196616  
    7474void StackmapSpecial::forEachArgImpl(
    7575    unsigned numIgnoredB3Args, unsigned numIgnoredAirArgs,
    76     Inst& inst, RoleMode roleMode, const ScopedLambda<Inst::EachArgCallback>& callback)
     76    Inst& inst, RoleMode roleMode, Optional<unsigned> firstRecoverableIndex,
     77    const ScopedLambda<Inst::EachArgCallback>& callback)
    7778{
    7879    StackmapValue* value = inst.origin->as<StackmapValue>();
     
    9091        Arg::Role role;
    9192        switch (roleMode) {
     93        case ForceLateUseUnlessRecoverable:
     94            ASSERT(firstRecoverableIndex);
     95            if (arg != inst.args[*firstRecoverableIndex] && arg != inst.args[*firstRecoverableIndex + 1]) {
     96                role = Arg::LateColdUse;
     97                break;
     98            }
     99            FALLTHROUGH;
    92100        case SameAsRep:
    93101            switch (child.rep().kind()) {
     
    274282        out.print("SameAsRep");
    275283        return;
     284    case StackmapSpecial::ForceLateUseUnlessRecoverable:
     285        out.print("ForceLateUseUnlessRecoverable");
     286        return;
    276287    case StackmapSpecial::ForceLateUse:
    277288        out.print("ForceLateUse");
  • trunk/Source/JavaScriptCore/b3/B3StackmapSpecial.h

    r194542 r196616  
    4848    enum RoleMode : int8_t {
    4949        SameAsRep,
     50        ForceLateUseUnlessRecoverable,
    5051        ForceLateUse
    5152    };
     
    6061    void forEachArgImpl(
    6162        unsigned numIgnoredB3Args, unsigned numIgnoredAirArgs,
    62         Air::Inst&, RoleMode, const ScopedLambda<Air::Inst::EachArgCallback>&);
     63        Air::Inst&, RoleMode, Optional<unsigned> firstRecoverableIndex,
     64        const ScopedLambda<Air::Inst::EachArgCallback>&);
    6365   
    6466    bool isValidImpl(
  • trunk/Source/JavaScriptCore/b3/B3StackmapValue.h

    r196032 r196616  
    9292        appendVectorWithRep(vector, ValueRep::ColdAny);
    9393    }
     94    template<typename VectorType>
     95    void appendLateColdAnys(const VectorType& vector)
     96    {
     97        appendVectorWithRep(vector, ValueRep::LateColdAny);
     98    }
    9499
    95100    // This is a helper for something you might do a lot of: append a value that should be constrained
Note: See TracChangeset for help on using the changeset viewer.