| Differences between
and this patch
- Source/JavaScriptCore/ChangeLog +78 lines
Lines 1-3 Source/JavaScriptCore/ChangeLog_sec1
1
2013-03-31  Filip Pizlo  <fpizlo@apple.com>
2
3
        fourthTier: FTL JIT should supply TBAA meta-data to LLVM
4
        https://bugs.webkit.org/show_bug.cgi?id=113656
5
6
        Reviewed by NOBODY (OOPS!).
7
        
8
        Work in progress.
9
10
        * ftl/FTLAbstractHeap.cpp: Added.
11
        (FTL):
12
        (JSC::FTL::AbstractHeap::tbaaMetadataSlow):
13
        (JSC::FTL::AbstractHeap::decorateInstruction):
14
        (JSC::FTL::IndexedAbstractHeap::IndexedAbstractHeap):
15
        (JSC::FTL::IndexedAbstractHeap::~IndexedAbstractHeap):
16
        (JSC::FTL::IndexedAbstractHeap::atSlow):
17
        (JSC::FTL::IndexedAbstractHeap::initialize):
18
        (JSC::FTL::AbsoluteAbstractHeap::AbsoluteAbstractHeap):
19
        (JSC::FTL::AbsoluteAbstractHeap::~AbsoluteAbstractHeap):
20
        * ftl/FTLAbstractHeap.h: Added.
21
        (FTL):
22
        (AbstractHeap):
23
        (JSC::FTL::AbstractHeap::AbstractHeap):
24
        (JSC::FTL::AbstractHeap::isInitialized):
25
        (JSC::FTL::AbstractHeap::initialize):
26
        (JSC::FTL::AbstractHeap::parent):
27
        (JSC::FTL::AbstractHeap::heapName):
28
        (JSC::FTL::AbstractHeap::tbaaMetadata):
29
        (AbstractField):
30
        (JSC::FTL::AbstractField::AbstractField):
31
        (JSC::FTL::AbstractField::initialize):
32
        (JSC::FTL::AbstractField::offset):
33
        (IndexedAbstractHeap):
34
        (JSC::FTL::IndexedAbstractHeap::atAnyIndex):
35
        (JSC::FTL::IndexedAbstractHeap::at):
36
        (JSC::FTL::IndexedAbstractHeap::operator[]):
37
        (JSC::FTL::IndexedAbstractHeap::returnInitialized):
38
        (JSC::FTL::IndexedAbstractHeap::MyHashTraits::constructDeletedValue):
39
        (JSC::FTL::IndexedAbstractHeap::MyHashTraits::isDeletedValue):
40
        (AbsoluteAbstractHeap):
41
        (JSC::FTL::AbsoluteAbstractHeap::atAnyAddress):
42
        (JSC::FTL::AbsoluteAbstractHeap::at):
43
        (JSC::FTL::AbsoluteAbstractHeap::operator[]):
44
        * ftl/FTLAbstractHeapRepository.cpp: Added.
45
        (FTL):
46
        (JSC::FTL::AbstractHeapRepository::AbstractHeapRepository):
47
        (JSC::FTL::AbstractHeapRepository::~AbstractHeapRepository):
48
        * ftl/FTLAbstractHeapRepository.h: Added.
49
        (FTL):
50
        (AbstractHeapRepository):
51
        * ftl/FTLLowerDFGToLLVM.cpp:
52
        (JSC::FTL::LowerDFGToLLVM::lower):
53
        (JSC::FTL::LowerDFGToLLVM::addressFor):
54
        (JSC::FTL::LowerDFGToLLVM::payloadFor):
55
        (JSC::FTL::LowerDFGToLLVM::tagFor):
56
        (LowerDFGToLLVM):
57
        * ftl/FTLOutput.h:
58
        (FTL):
59
        (JSC::FTL::Output::Output):
60
        (JSC::FTL::Output::initialize):
61
        (JSC::FTL::Output::load):
62
        (JSC::FTL::Output::store):
63
        (Output):
64
        (JSC::FTL::Output::load32):
65
        (JSC::FTL::Output::load64):
66
        (JSC::FTL::Output::loadPtr):
67
        (JSC::FTL::Output::store32):
68
        (JSC::FTL::Output::store64):
69
        (JSC::FTL::Output::storePtr):
70
        (JSC::FTL::Output::address):
71
        * ftl/FTLTypedPointer.h: Added.
72
        (FTL):
73
        (TypedPointer):
74
        (JSC::FTL::TypedPointer::TypedPointer):
75
        (JSC::FTL::TypedPointer::operator!):
76
        (JSC::FTL::TypedPointer::heap):
77
        (JSC::FTL::TypedPointer::value):
78
1
2013-03-29  Filip Pizlo  <fpizlo@apple.com>
79
2013-03-29  Filip Pizlo  <fpizlo@apple.com>
2
80
3
        fourthTier: FTL JIT should be able to compile the Marsaglia random number generator
81
        fourthTier: FTL JIT should be able to compile the Marsaglia random number generator
- Source/JavaScriptCore/ftl/FTLAbstractHeap.cpp +150 lines
Line 0 Source/JavaScriptCore/ftl/FTLAbstractHeap.cpp_sec1
1
/*
2
 * Copyright (C) 2013 Apple Inc. All rights reserved.
3
 *
4
 * Redistribution and use in source and binary forms, with or without
5
 * modification, are permitted provided that the following conditions
6
 * are met:
7
 * 1. Redistributions of source code must retain the above copyright
8
 *    notice, this list of conditions and the following disclaimer.
9
 * 2. Redistributions in binary form must reproduce the above copyright
10
 *    notice, this list of conditions and the following disclaimer in the
11
 *    documentation and/or other materials provided with the distribution.
12
 *
13
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
17
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
24
 */
25
26
#include "config.h"
27
#include "FTLAbstractHeap.h"
28
29
#if ENABLE(FTL_JIT)
30
31
#include "FTLAbbreviations.h"
32
33
namespace JSC { namespace FTL {
34
35
LValue AbstractHeap::tbaaMetadataSlow(const AbstractHeapRepository& repository) const
36
{
37
    LValue arguments[] = { LLVMMDString(m_heapName, strlen(m_heapName)), m_parent.tbaaMetadata(repository) };
38
    m_tbaaMetadata = LLVMMDMode(arguments, 2);
39
    return m_tbaaMetadata;
40
}
41
42
void AbstractHeap::decorateInstruction(LValue instruction, const AbstractHeapRepository& repository) const
43
{
44
    LLVMSetMetadata(instruction, repository.m_tbaaKind, tbaaMetadata());
45
}
46
47
IndexedAbstractHeap::IndexedAbstractHeap(AbstractHeap* parent, const char* heapName, size_t elementSize)
48
    : m_heapForAnyIndex(parent, heapName)
49
    , m_heapNameLength(strlen(heapName))
50
    , m_elementSize(elementSize)
51
{
52
}
53
54
IndexedAbstractHeap::~IndexedAbstractHeap()
55
{
56
}
57
58
const AbstractField& IndexedAbstractHeap::atSlow(ptrdiff_t index) const
59
{
60
    ASSERT(static_cast<size_t>(index) >= m_smallIndices.size());
61
    
62
    if (UNLIKELY(!m_largeIndices))
63
        m_largeIndices = adoptPtr(new MapType());
64
    
65
    MapType::const_iterator iter = m_largeIndices->find(index);
66
    if (iter != m_largeIndices->end())
67
        return iter->value.get();
68
    
69
    OwnPtr<AbstractField> field = adoptPtr(new AbstractField());
70
    AbstractField* result = field.get();
71
    initialize(*result, index);
72
    m_largeIndices.add(index, field.release());
73
    return result;
74
}
75
76
void IndexedAbstractHeap::initialize(AbstractField& field, ptrdiff_t signedIndex) const
77
{
78
    // Build up a name of the form:
79
    //
80
    //    heapName_hexIndex
81
    //
82
    // or:
83
    //
84
    //    heapName_neg_hexIndex
85
    //
86
    // For example if you access an indexed heap called FooBar at index 5, you'll
87
    // get:
88
    //
89
    //    FooBar_5
90
    //
91
    // Or if you access an indexed heap called Blah at index -10, you'll get:
92
    //
93
    //    Blah_neg_A
94
    //
95
    // This is important because LLVM uses the string to distinguish the types.
96
    
97
    bool negative;
98
    size_t index;
99
    if (signedIndex < 0) {
100
        negative = true;
101
        index = -signedIndex;
102
    } else {
103
        negative = false;
104
        index = signedIndex;
105
    }
106
    
107
    for (unsigned power = 4; power <= sizeof(void*) * 8; power += 4) {
108
        // The crazy way of testing of index >= 2 ** power
109
        // (where I use ** to denote pow()).
110
        if ((index >> 1) >> (power - 1))
111
            continue;
112
        
113
        unsigned numHexlets = power >> 2;
114
        
115
        size_t stringLength = m_heapNameLength + (negative ? 5 : 1) + numHexlets;
116
        char* characters;
117
        m_largeIndexNames.append(CString::newUninitialized(stringLength, characters));
118
        
119
        memcpy(characers, m_heapName, m_heapNameLength);
120
        if (negative)
121
            memcpy(characters + m_heapNameLength, "_neg_", 5);
122
        else
123
            characters[m_heapNameLength] = '_';
124
        
125
        size_t accumulator = index;
126
        for (unsigned i = 0; i < numHexlets; ++i) {
127
            characters[stringLength - i - 1] = ("0123456789ABCDEF")[accumulator & 0xF];
128
            accumulator >>= 4;
129
        }
130
        
131
        field.initialize(&m_heapForAnyIndex, characters, signedIndex * m_elementSize);
132
        return;
133
    }
134
    
135
    RELEASE_ASSERT_NOT_REACHED();
136
}
137
138
AbsoluteAbstractHeap::AbsoluteAbstractHeap(AbstractHeap* heap, const char* heapName)
139
    : m_indexedHeap(heap, heapName, 1)
140
{
141
}
142
143
AbsoluteAbstractHeap::~AbsoluteAbstractHeap()
144
{
145
}
146
147
} } // namespace JSC::FTL
148
149
#endif // ENABLE(FTL_JIT)
150
- Source/JavaScriptCore/ftl/FTLAbstractHeap.h +201 lines
Line 0 Source/JavaScriptCore/ftl/FTLAbstractHeap.h_sec1
1
/*
2
 * Copyright (C) 2013 Apple Inc. All rights reserved.
3
 *
4
 * Redistribution and use in source and binary forms, with or without
5
 * modification, are permitted provided that the following conditions
6
 * are met:
7
 * 1. Redistributions of source code must retain the above copyright
8
 *    notice, this list of conditions and the following disclaimer.
9
 * 2. Redistributions in binary form must reproduce the above copyright
10
 *    notice, this list of conditions and the following disclaimer in the
11
 *    documentation and/or other materials provided with the distribution.
12
 *
13
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
17
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
24
 */
25
26
#ifndef FTLAbstractHeap_h
27
#define FTLAbstractHeap_h
28
29
#include <wtf/Platform.h>
30
31
#if ENABLE(FTL_JIT)
32
33
#include "FTLAbbreviations.h"
34
#include <wtf/FastAllocBase.h>
35
#include <wtf/FixedArray.h>
36
#include <wtf/HashMap.h>
37
#include <wtf/Noncopyable.h>
38
#include <wtf/OwnPtr.h>
39
40
namespace JSC { namespace FTL {
41
42
// The FTL JIT tries to aid LLVM's TBAA. The FTL's notion of how this
43
// happens is the AbstractHeap. AbstractHeaps are a simple type system
44
// with sub-typing.
45
46
class AbstractHeapRepository;
47
48
class AbstractHeap {
49
    WTF_MAKE_NONCOPYABLE(AbstractHeap); WTF_MAKE_FAST_ALLOCATED;
50
public:
51
    AbstractHeap()
52
        : m_parent(0)
53
        , m_heapName(0)
54
    {
55
    }
56
    
57
    AbstractHeap(AbstractHeap* parent, const char* heapName)
58
        : m_parent(parent)
59
        , m_heapName(heapName)
60
    {
61
    }
62
    
63
    bool isInitialized() const { return !!m_heapName; }
64
    
65
    void initialize(AbstractHeap* parent, const char* heapName)
66
    {
67
        m_parent = parent;
68
        m_heapName = heapName;
69
    }
70
71
    AbstractHeap* parent() const
72
    {
73
        ASSERT(isInitialized());
74
        return m_parent;
75
    }
76
    
77
    const char* heapName() const
78
    {
79
        ASSERT(isInitialized());
80
        return m_heapName;
81
    }
82
    
83
    LValue tbaaMetadata(const AbstractHeapRepository& repository) const
84
    {
85
        ASSERT(isInitialized());
86
        if (LIKELY(m_tbaaMetadata))
87
            return m_tbaaMetadata;
88
        return tbaaMetadataSlow(repository);
89
    }
90
    
91
    void decorateInstruction(LValue instruction, const AbstractHeapRepository&) const;
92
93
private:
94
    friend class AbstractHeapRepository;
95
    
96
    LValue tbaaMetadataSlow(const AbstractHeapRepository&) const;
97
    
98
    AbstractHeap* m_parent;
99
    const char* m_heapName;
100
    mutable LValue m_tbaaMetadata;
101
};
102
103
// Think of "AbstractField" as being an "AbstractHeapWithOffset". I would have named
104
// it the latter except that I don't like typing that much.
105
class AbstractField : AbstractHeap {
106
public:
107
    AbstractField()
108
    {
109
    }
110
    
111
    AbstractField(AbstractHeap* parent, const char* heapName, ptrdiff_t offset)
112
        : AbstractHeap(parent, heapName)
113
        , m_offset(offset)
114
    {
115
    }
116
    
117
    void initialize(AbstractHeap* parent, const char* heapName, ptrdiff_t offset)
118
    {
119
        AbstractHeap::initialize(parent, heapName);
120
        m_offset = offset;
121
    }
122
    
123
    ptrdiff_t offset() const
124
    {
125
        ASSERT(isInitialized());
126
        return m_offset;
127
    }
128
    
129
private:
130
    ptrdiff_t m_offset;
131
};
132
133
class IndexedAbstractHeap {
134
public:
135
    IndexedAbstractHeap(AbstractHeap* parent, const char* heapName, size_t elementSize);
136
    ~IndexedAbstractHeap();
137
    
138
    const AbstractHeap& atAnyIndex() const { return m_heapForAnyIndex; }
139
    
140
    const AbstractField& at(ptrdiff_t index)
141
    {
142
        if (static_cast<size_t>(index) < m_smallIndices.size())
143
            return returnInitialized(m_smallIndices[index], index);
144
        return atSlow(index);
145
    }
146
    
147
    const AbstractField& operator[](ptrdiff_t index) { return at(index); }
148
    
149
private:
150
    const AbstractField& returnInitialized(AbstractField& field, ptrdiff_t index)
151
    {
152
        if (UNLIKELY(!field.isInitialized()))
153
            initialize(field, index);
154
        return field;
155
    }
156
157
    const AbstractField& atSlow(ptrdiff_t index) const;
158
    void initialize(AbstractField& field, ptrdiff_t index) const;
159
160
    AbstractHeap m_heapForAnyIndex;
161
    size_t m_heapNameLength;
162
    size_t m_elementSize;
163
    FixedArray<AbstractField, 16> m_smallIndices;
164
    
165
    struct MyHashTraits : WTF::GenericHashTraits<ptrdiff_t> {
166
        static void constructDeletedValue(ptrdiff_t& slot) { slot = 1; }
167
        static bool isDeletedValue(ptrdiff_t value) { return value == 1; }
168
    };
169
    typedef HashMap<ptrdiff_t, OwnPtr<AbstractField>, WTF::IntHash<ptrdiff_t>, MyHashTraits> MapType;
170
    OwnPtr<MapType> m_largeIndices;
171
    Vector<CString, 16> largeIndexNames;
172
};
173
174
class AbsoluteAbstractHeap {
175
public:
176
    AbsoluteAbstractHeap(AbstractHeap* parent, const char* heapName);
177
    ~AbsoluteAbstractHeap();
178
    
179
    const AbstractHeap& atAnyAddress() const { m_indexedHeap.atAnyIndex(); }
180
    
181
    const AbstractHeap& at(void* address)
182
    {
183
        return m_indexedHeap.at(bitwise_cast<ptrdiff_t>(address));
184
    }
185
    
186
    const AbstractHeap& operator[](void* address) { return at(address); }
187
188
private:
189
    
190
    // The trick here is that the indexed heap is "indexed" by a pointer-width
191
    // integer. Pointers are themselves pointer-width integers. So we can reuse
192
    // all of the functionality.
193
    IndexedAbstractHeap m_indexedHeap;
194
}
195
196
} } // namespace JSC::FTL
197
198
#endif // ENABLE(FTL_JIT)
199
200
#endif // FTLAbstractHeap_h
201
- Source/JavaScriptCore/ftl/FTLAbstractHeapRepository.cpp +65 lines
Line 0 Source/JavaScriptCore/ftl/FTLAbstractHeapRepository.cpp_sec1
1
/*
2
 * Copyright (C) 2013 Apple Inc. All rights reserved.
3
 *
4
 * Redistribution and use in source and binary forms, with or without
5
 * modification, are permitted provided that the following conditions
6
 * are met:
7
 * 1. Redistributions of source code must retain the above copyright
8
 *    notice, this list of conditions and the following disclaimer.
9
 * 2. Redistributions in binary form must reproduce the above copyright
10
 *    notice, this list of conditions and the following disclaimer in the
11
 *    documentation and/or other materials provided with the distribution.
12
 *
13
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
17
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
24
 */
25
26
#include "config.h"
27
#include "FTLAbstractHeapRepository.h"
28
29
#if ENABLE(FTL_JIT)
30
31
namespace JSC { namespace FTL {
32
33
AbstractHeapRepository::AbstractHeapRepository()
34
    : root(0, "root")
35
36
#define ABSTRACT_HEAP_DECLARATION(name) , name(&root, #name)
37
    FOR_EACH_ABSTRACT_HEAP(ABSTRACT_HEAP_DECLARATION)
38
#undef ABSTRACT_HEAP_DECLARATION
39
40
#define ABSTRACT_FIELD_DECLARATION(name, offset) , name(&root, #name, offset)
41
    FOR_EACH_ABSTRACT_FIELD(ABSTRACT_FIELD_DECLARATION)
42
#undef ABSTRACT_FIELD_DECLARATION
43
    
44
#define INDEXED_ABSTRACT_HEAP_DECLARATION(name, size) , name(&root, #name, size)
45
    FOR_EACH_INDEXED_ABSTRACT_HEAP(INDEXED_ABSTRACT_HEAP_DECLARATION)
46
#undef INDEXED_ABSTRACT_HEAP_DECLARATION
47
    
48
#define ABSOLUTE_ABSTRACT_HEAP_DECLARATION(name) , name(&root, #name)
49
    FOR_EACH_ABSOLUTE_ABSTRACT_HEAP(ABSOLUTE_ABSTRACT_HEAP_DECLARATION)
50
#undef ABSOLUTE_ABSTRACT_HEAP_DECLARATION
51
52
    , m_tbaaKind(LLVMGetMDKindID("tbaa", strlen("tbaa")))
53
{
54
    LValue arguments[] = { LLVMMDString(root.m_heapName, strlen(root.m_heapName)) };
55
    root.m_tbaaMetadata = LLVMMDNode(&arguments, 1);
56
}
57
58
AbstractHeapRepository::~AbstractHeapRepository()
59
{
60
}
61
62
} } // namespace JSC::FTL
63
64
#endif // ENABLE(FTL_JIT)
65
- Source/JavaScriptCore/ftl/FTLAbstractHeapRepository.h +95 lines
Line 0 Source/JavaScriptCore/ftl/FTLAbstractHeapRepository.h_sec1
1
/*
2
 * Copyright (C) 2013 Apple Inc. All rights reserved.
3
 *
4
 * Redistribution and use in source and binary forms, with or without
5
 * modification, are permitted provided that the following conditions
6
 * are met:
7
 * 1. Redistributions of source code must retain the above copyright
8
 *    notice, this list of conditions and the following disclaimer.
9
 * 2. Redistributions in binary form must reproduce the above copyright
10
 *    notice, this list of conditions and the following disclaimer in the
11
 *    documentation and/or other materials provided with the distribution.
12
 *
13
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
17
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
24
 */
25
26
#ifndef FTLAbstractHeapRepository_h
27
#define FTLAbstractHeapRepository_h
28
29
#include <wtf/Platform.h>
30
31
#if ENABLE(FTL_JIT)
32
33
#include "FTLAbstractHeap.h"
34
35
namespace JSC { namespace FTL {
36
37
#define FOR_EACH_ABSTRACT_HEAP(macro) \
38
    macro(typedArrayHeap)
39
40
#define FOR_EACH_ABSTRACT_FIELD(macro) \
41
    macro(JSCell_structure, JSCell::structureOffset()) \
42
    macro(JSObject_butterfly, JSObject::butterflyOffset()) \
43
    macro(Butterfly_publicLength, Butterfly::offsetOfPublicLength())
44
45
#define FOR_EACH_INDEXED_ABSTRACT_HEAP(macro) \
46
    macro(variables, sizeof(Register)) \
47
    macro(properties, sizeof(EncodedJSValue)) /* indexed by identifierNumber */ \
48
    macro(indexedInt32Properties, sizeof(EncodedJSValue)) \
49
    macro(indexedDoubleProperties, sizeof(double)) \
50
    macro(indexedContiguousProperties, sizeof(EncodedJSValue)) \
51
    macro(indexedArrayStorageProperties, sizeof(EncodedJSValue))
52
    
53
#define FOR_EACH_ABSOLUTE_ABSTRACT_HEAP(macro) \
54
    macro(globalVariables, sizeof(Register))
55
    
56
// This class is meant to be cacheable between compilations, but it doesn't have to be.
57
// Doing so saves on creation of nodes. But clearing it will save memory.
58
59
class AbstractHeapRepository {
60
    WTF_MAKE_NONCOPYABLE(AbstractHeapRepository);
61
public:
62
    AbstractHeapRepository();
63
    ~AbstractHeapRepository();
64
    
65
    AbstractHeap root;
66
    
67
#define ABSTRACT_HEAP_DECLARATION(name) AbstractHeap name;
68
    FOR_EACH_ABSTRACT_HEAP(ABSTRACT_HEAP_DECLARATION)
69
#undef ABSTRACT_HEAP_DECLARATION
70
71
#define ABSTRACT_FIELD_DECLARATION(name, offset) AbstractField name;
72
    FOR_EACH_ABSTRACT_FIELD(ABSTRACT_FIELD_DECLARATION)
73
#undef ABSTRACT_FIELD_DECLARATION
74
    
75
#define INDEXED_ABSTRACT_HEAP_DECLARATION(name, size) IndexedAbstractHeap name;
76
    FOR_EACH_INDEXED_ABSTRACT_HEAP(INDEXED_ABSTRACT_HEAP_DECLARATION)
77
#undef INDEXED_ABSTRACT_HEAP_DECLARATION
78
    
79
#define ABSOLUTE_ABSTRACT_HEAP_DECLARATION(name) AbsoluteAbstractHeap name;
80
    FOR_EACH_ABSOLUTE_ABSTRACT_HEAP(ABSOLUTE_ABSTRACT_HEAP_DECLARATION)
81
#undef ABSOLUTE_ABSTRACT_HEAP_DECLARATION
82
83
private:
84
    friend class AbstractHeap;
85
    
86
    unsigned m_tbaaKind;
87
    
88
};
89
90
} } // namespace JSC::FTL
91
92
#endif // ENABLE(FTL_JIT)
93
94
#endif // FTLAbstractHeapRepository_h
95
- Source/JavaScriptCore/ftl/FTLLowerDFGToLLVM.cpp -5 / +7 lines
Lines 29-34 Source/JavaScriptCore/ftl/FTLLowerDFGToLLVM.cpp_sec1
29
#if ENABLE(FTL_JIT)
29
#if ENABLE(FTL_JIT)
30
30
31
#include "DFGAbstractState.h"
31
#include "DFGAbstractState.h"
32
#include "FTLAbstractHeapRepository.h"
32
#include "FTLOutput.h"
33
#include "FTLOutput.h"
33
#include "Operations.h"
34
#include "Operations.h"
34
35
Lines 68-74 public: Source/JavaScriptCore/ftl/FTLLowerDFGToLLVM.cpp_sec2
68
            m_ftlState.module, name.data(), functionType(m_out.int64, m_out.intPtr));
69
            m_ftlState.module, name.data(), functionType(m_out.int64, m_out.intPtr));
69
        setFunctionCallingConv(m_ftlState.function, LLVMCCallConv);
70
        setFunctionCallingConv(m_ftlState.function, LLVMCCallConv);
70
        
71
        
71
        m_out.initialize(m_ftlState.module, m_ftlState.function);
72
        m_out.initialize(m_ftlState.module, m_ftlState.function, m_heaps);
72
        
73
        
73
        m_prologue = appendBasicBlock(m_ftlState.function);
74
        m_prologue = appendBasicBlock(m_ftlState.function);
74
        m_out.appendTo(m_prologue);
75
        m_out.appendTo(m_prologue);
Lines 731-747 private: Source/JavaScriptCore/ftl/FTLLowerDFGToLLVM.cpp_sec3
731
        lowInt32(edge);
732
        lowInt32(edge);
732
    }
733
    }
733
    
734
    
734
    LValue addressFor(LValue base, int operand)
735
    LValue addressFor(LValue base, int operand, ptrdiff_t offset = 0)
735
    {
736
    {
736
        return m_out.add(base, m_out.constIntPtr(operand * sizeof(Register)));
737
        return m_out.address(base, m_heaps.variables[operand], offset);
737
    }
738
    }
738
    LValue payloadFor(LValue base, int operand)
739
    LValue payloadFor(LValue base, int operand)
739
    {
740
    {
740
        return m_out.add(base, m_out.constIntPtr(operand * sizeof(Register) + OBJECT_OFFSETOF(EncodedValueDescriptor, asBits.payload)));
741
        return addressFor(base, operand, OBJECT_OFFSETOF(EncodedValueDescriptor, asBits.payload));
741
    }
742
    }
742
    LValue tagFor(LValue base, int operand)
743
    LValue tagFor(LValue base, int operand)
743
    {
744
    {
744
        return m_out.add(base, m_out.constIntPtr(operand * sizeof(Register) + OBJECT_OFFSETOF(EncodedValueDescriptor, asBits.tag)));
745
        return addressFor(base, operand, OBJECT_OFFSETOF(EncodedValueDescriptor, asBits.tag));
745
    }
746
    }
746
    LValue addressFor(int operand)
747
    LValue addressFor(int operand)
747
    {
748
    {
Lines 761-766 private: Source/JavaScriptCore/ftl/FTLLowerDFGToLLVM.cpp_sec4
761
    
762
    
762
    Graph& m_graph;
763
    Graph& m_graph;
763
    State& m_ftlState;
764
    State& m_ftlState;
765
    AbstractHeapRepository m_heaps;
764
    Output m_out;
766
    Output m_out;
765
    
767
    
766
    LBasicBlock m_prologue;
768
    LBasicBlock m_prologue;
- Source/JavaScriptCore/ftl/FTLOutput.h -12 / +43 lines
Lines 31-36 Source/JavaScriptCore/ftl/FTLOutput.h_sec1
31
#if ENABLE(FTL_JIT)
31
#if ENABLE(FTL_JIT)
32
32
33
#include "FTLAbbreviations.h"
33
#include "FTLAbbreviations.h"
34
#include "FTLAbstractHeapRepository.h"
34
35
35
namespace JSC { namespace FTL {
36
namespace JSC { namespace FTL {
36
37
Lines 44-49 namespace JSC { namespace FTL { Source/JavaScriptCore/ftl/FTLOutput.h_sec2
44
//
45
//
45
// We say that a "pointer" is what LLVM considers to be a pointer-width integer.
46
// We say that a "pointer" is what LLVM considers to be a pointer-width integer.
46
//
47
//
48
// We say that a "typed pointer" is a pointer plus TBAA meta-data (i.e. an AbstractHeap).
49
//
47
// We say that "get" and "set" are what LLVM considers to be "load" and "store". Get
50
// We say that "get" and "set" are what LLVM considers to be "load" and "store". Get
48
// and set take references.
51
// and set take references.
49
//
52
//
Lines 67-73 public: Source/JavaScriptCore/ftl/FTLOutput.h_sec3
67
        , int32Zero(constInt(int32, 0, SignExtend))
70
        , int32Zero(constInt(int32, 0, SignExtend))
68
        , int64Zero(constInt(int64, 0, SignExtend))
71
        , int64Zero(constInt(int64, 0, SignExtend))
69
        , intPtrZero(constInt(intPtr, 0, SignExtend))
72
        , intPtrZero(constInt(intPtr, 0, SignExtend))
73
        , m_module(0)
70
        , m_function(0)
74
        , m_function(0)
75
        , m_heaps(0)
71
        , m_builder(LLVMCreateBuilder())
76
        , m_builder(LLVMCreateBuilder())
72
        , m_block(0)
77
        , m_block(0)
73
        , m_nextBlock(0)
78
        , m_nextBlock(0)
Lines 81-90 public: Source/JavaScriptCore/ftl/FTLOutput.h_sec4
81
        LLVMDisposeBuilder(m_builder);
86
        LLVMDisposeBuilder(m_builder);
82
    }
87
    }
83
    
88
    
84
    void initialize(LModule module, LValue function)
89
    void initialize(LModule module, LValue function, AbstractHeapRepository& heaps)
85
    {
90
    {
86
        m_module = module;
91
        m_module = module;
87
        m_function = function;
92
        m_function = function;
93
        m_heaps = &heaps;
88
    }
94
    }
89
    
95
    
90
    LBasicBlock appendTo(LBasicBlock block, LBasicBlock nextBlock)
96
    LBasicBlock appendTo(LBasicBlock block, LBasicBlock nextBlock)
Lines 139-158 public: Source/JavaScriptCore/ftl/FTLOutput.h_sec5
139
    LValue get(LValue reference) { return buildLoad(m_builder, reference); }
145
    LValue get(LValue reference) { return buildLoad(m_builder, reference); }
140
    void set(LValue value, LValue reference) { buildStore(m_builder, value, reference); }
146
    void set(LValue value, LValue reference) { buildStore(m_builder, value, reference); }
141
    
147
    
142
    LValue load(LValue pointer, ptrdiff_t offset, LType refType)
148
    LValue load(TypedPointer pointer, ptrdiff_t offset, LType refType)
143
    {
149
    {
144
        return get(buildIntToPtr(m_builder, offset ? add(pointer, constIntPtr(offset)) : pointer, refType));
150
        LValue result = get(buildIntToPtr(
145
    }
151
            m_builder,
146
    void store(LValue value, LValue pointer, ptrdiff_t offset, LType refType)
152
            offset ? add(pointer.value(), constIntPtr(offset)) : vpointer.value(),
153
            refType));
154
        pointer.heap().decorateInstruction(result, *m_heaps);
155
        return result;
156
    }
157
    void store(LValue value, TypedPointer pointer, ptrdiff_t offset, LType refType)
158
    {
159
        LValue result = set(buildIntToPtr(
160
            m_builder,
161
            offset ? add(pointer.value(), constIntPtr(offset)) : vpointer.value(),
162
            refType));
163
        pointer.heap().decorateInstruction(result, *m_heaps);
164
        return result;
165
    }
166
    
167
    LValue load32(TypedPointer pointer, ptrdiff_t offset = 0) { return load(pointer, offset, ref32); }
168
    LValue load64(TypedPointer pointer, ptrdiff_t offset = 0) { return load(pointer, offset, ref64); }
169
    LValue loadPtr(TypedPointer pointer, ptrdiff_t offset = 0) { return load(pointer, offset, refPtr); }
170
    void store32(LValue value, TypedPointer pointer, ptrdiff_t offset = 0) { store(value, pointer, offset, ref32); }
171
    void store64(LValue value, TypedPointer pointer, ptrdiff_t offset = 0) { store(value, pointer, offset, ref64); }
172
    void storePtr(LValue value, TypedPointer pointer, ptrdiff_t offset = 0) { store(value, pointer, offset, refPtr); }
173
        
174
    LValue load32(LValue base, const AbstractField& field, ptrdiff_t offset = 0) { return load32(TypedPointer(field, base), field.offset() + offset); }
175
    LValue load64(LValue base, const AbstractField& field, ptrdiff_t offset = 0) { return load64(TypedPointer(field, base), field.offset() + offset); }
176
    LValue loadPtr(LValue base, const AbstractField& field, ptrdiff_t offset = 0) { return loadPtr(TypedPointer(field, base), field.offset() + offset); }
177
    void store32(LValue value, LValue base, const AbstractField& field, ptrdiff_t offset = 0) { store32(value, TypedPointer(field, base), field.offset() + offset); }
178
    void store64(LValue value, LValue base, const AbstractField& field, ptrdiff_t offset = 0) { store64(value, TypedPointer(field, base), field.offset() + offset); }
179
    void storePtr(LValue value, LValue base, const AbstractField& field, ptrdiff_t offset = 0) { storePtr(value, TypedPointer(field, base), field.offset() + offset); }
180
    
181
    TypedPointer address(LValue base, const AbsractField& field, ptrdiff_t offset = 0)
147
    {
182
    {
148
        set(value, buildIntToPtr(m_builder, offset ? add(pointer, constIntPtr(offset)) : pointer, refType));
183
        offset += field.offset();
184
        return TypedPointer(field, offset ? m_out.add(base, constIntPtr(offset)) : base);
149
    }
185
    }
150
    LValue load32(LValue pointer, ptrdiff_t offset = 0) { return load(pointer, offset, ref32); }
151
    LValue load64(LValue pointer, ptrdiff_t offset = 0) { return load(pointer, offset, ref64); }
152
    LValue loadPtr(LValue pointer, ptrdiff_t offset = 0) { return load(pointer, offset, refPtr); }
153
    void store32(LValue value, LValue pointer, ptrdiff_t offset = 0) { store(value, pointer, offset, ref32); }
154
    void store64(LValue value, LValue pointer, ptrdiff_t offset = 0) { store(value, pointer, offset, ref64); }
155
    void storePtr(LValue value, LValue pointer, ptrdiff_t offset = 0) { store(value, pointer, offset, refPtr); }
156
    
186
    
157
    LValue equal(LValue left, LValue right) { return buildICmp(m_builder, LLVMIntEQ, left, right); }
187
    LValue equal(LValue left, LValue right) { return buildICmp(m_builder, LLVMIntEQ, left, right); }
158
    LValue notEqual(LValue left, LValue right) { return buildICmp(m_builder, LLVMIntNE, left, right); }
188
    LValue notEqual(LValue left, LValue right) { return buildICmp(m_builder, LLVMIntNE, left, right); }
Lines 221-226 public: Source/JavaScriptCore/ftl/FTLOutput.h_sec6
221
    
251
    
222
    LModule m_module;
252
    LModule m_module;
223
    LValue m_function;
253
    LValue m_function;
254
    AbstractHeapRepository* m_heaps;
224
    LBuilder m_builder;
255
    LBuilder m_builder;
225
    LBasicBlock m_block;
256
    LBasicBlock m_block;
226
    LBasicBlock m_nextBlock;
257
    LBasicBlock m_nextBlock;
- Source/JavaScriptCore/ftl/FTLTypedPointer.h +71 lines
Line 0 Source/JavaScriptCore/ftl/FTLTypedPointer.h_sec1
1
/*
2
 * Copyright (C) 2013 Apple Inc. All rights reserved.
3
 *
4
 * Redistribution and use in source and binary forms, with or without
5
 * modification, are permitted provided that the following conditions
6
 * are met:
7
 * 1. Redistributions of source code must retain the above copyright
8
 *    notice, this list of conditions and the following disclaimer.
9
 * 2. Redistributions in binary form must reproduce the above copyright
10
 *    notice, this list of conditions and the following disclaimer in the
11
 *    documentation and/or other materials provided with the distribution.
12
 *
13
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
17
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
24
 */
25
26
#ifndef FTLTypedPointer_h
27
#define FTLTypedPointer_h
28
29
#include <wtf/Platform.h>
30
31
#if ENABLE(FTL_JIT)
32
33
#include "FTLAbbreviations.h"
34
#include "FTLAbstractHeap.h"
35
36
namespace JSC { namespace FTL {
37
38
class TypedPointer {
39
public:
40
    TypedPointer()
41
        : m_heap(0)
42
        , m_value(0)
43
    {
44
    }
45
    
46
    TypedPointer(const AbstractHeap& heap, LValue value)
47
        : m_heap(&heap)
48
        , m_value(value)
49
    {
50
    }
51
    
52
    bool operator!() const
53
    {
54
        ASSERT(!m_heap == !m_value);
55
        return !m_heap;
56
    }
57
    
58
    const AbstractHeap& heap() const { return m_heap; }
59
    const LValue value() const { return m_value; }
60
61
private:
62
    const AbstractHeap* m_heap;
63
    LValue m_value;
64
};
65
66
} } // namespace JSC::FTL
67
68
#endif // ENABLE(FTL_JIT)
69
70
#endif // FTLTypedPointer_h
71

Return to Bug 113656