FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
WebKit/Source/JavaScriptCore/b3/air/AirCustom.cpp at main · WebKit/WebKit · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
WebKit
/
WebKit
Public
Notifications
You must be signed in to change notification settings
Fork
2.1k
Star
10.1k
Code
Pull requests
2.6k
Actions
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
WebKit
/
Source
/
JavaScriptCore
/
b3
/
air
/
AirCustom.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
262 lines (218 loc) · 8.9 KB
Breadcrumbs
WebKit
/
Source
/
JavaScriptCore
/
b3
/
air
/
AirCustom.cpp
Copy path
File metadata and controls
262 lines (218 loc) · 8.9 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
/*
* Copyright (C) 2016-2017 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#
include
"
config.h
"
#
include
"
AirCustom.h
"
#
if
ENABLE(B3_JIT)
#
include
"
AirCCallingConvention.h
"
#
include
"
AirInstInlines.h
"
#
include
"
B3CCallValue.h
"
#
include
"
B3ProcedureInlines.h
"
#
include
"
B3ValueInlines.h
"
#
include
"
CCallHelpers.h
"
namespace
JSC
{
namespace
B3
{
namespace
Air
{
bool
PatchCustom::isValidForm
(Inst& inst)
{
if
(inst.
args
().
size
() <
1
)
return
false
;
if
(!inst.
args
()[
0
].
isSpecial
())
return
false
;
if
(!inst.
args
()[
0
].
special
()->
isValid
(inst))
return
false
;
auto
clobberedEarly = inst.
extraEarlyClobberedRegs
().
filter
(
RegisterSet::allScalarRegisters
());
auto
clobberedLate = inst.
extraClobberedRegs
().
filter
(
RegisterSet::allScalarRegisters
());
bool
ok =
true
;
inst.
forEachTmp
(
[&] (Tmp& tmp, Arg::Role role, Bank, Width) {
if
(!tmp.
isReg
())
return
;
if
(
Arg::isLateDef
(role) ||
Arg::isLateUse
(role))
ok &= !clobberedLate.
contains
(tmp.
reg
(), IgnoreVectors);
else
ok &= !clobberedEarly.
contains
(tmp.
reg
(), IgnoreVectors);
});
return
ok;
}
bool
CCallCustom::isValidForm
(Inst& inst)
{
CCallValue* value = inst.
origin
->
as
<CCallValue>();
if
(!value)
return
false
;
if
(!inst.
args
()[
0
].
isSpecial
())
return
false
;
Special* special = inst.
args
()[
0
].
special
();
Code& code = special->
code
();
size_t
resultCount =
cCallResultCount
(code, value);
size_t
expectedArgCount = resultCount +
1
;
//
first Arg is always CCallSpecial.
for
(Value* child : value->
children
()) {
ASSERT
(!child->
type
().
isTuple
());
expectedArgCount +=
cCallArgumentRegisterCount
(child->
type
());
}
if
(inst.
args
().
size
() != expectedArgCount)
return
false
;
//
The arguments can only refer to the stack, tmps, or immediates.
for
(
unsigned
i = inst.
args
().
size
() -
1
; i; --i) {
Arg arg = inst.
args
()[i];
if
(!arg.
isTmp
() && !arg.
isStackMemory
() && !arg.
isSomeImm
())
return
false
;
}
//
Callee
if
(!inst.
args
()[
1
].
isGP
())
return
false
;
unsigned
offset =
2
;
//
If there is a result then it cannot be an immediate.
for
(
size_t
i =
0
; i < resultCount; ++i) {
if
(inst.
args
()[offset].
isSomeImm
())
return
false
;
if
(value->
type
().
isTuple
()) {
Type type = code.
proc
().
typeAtOffset
(value->
type
(), i);
if
(!inst.
args
()[offset].
canRepresent
(type))
return
false
;
}
else
if
(!inst.
args
()[offset].
canRepresent
(value))
return
false
;
offset++;
}
auto
checkNextArg = [&](Value* child) {
return
inst.
args
()[offset++].
canRepresent
(child);
};
for
(
unsigned
i =
1
; i < value->
numChildren
(); ++i) {
Value* child = value->
child
(i);
for
(
unsigned
j =
0
; j <
cCallArgumentRegisterCount
(child->
type
()); j++) {
if
(!
checkNextArg
(child))
return
false
;
}
}
return
true
;
}
MacroAssembler::Jump
CCallCustom::generate
(Inst& inst, CCallHelpers&, GenerationContext&)
{
dataLog
(
"
FATAL: Unlowered C call:
"
, inst,
"
\n
"
);
UNREACHABLE_FOR_PLATFORM
();
return
MacroAssembler::Jump
();
}
bool
ShuffleCustom::isValidForm
(Inst& inst)
{
if
(inst.
args
().
size
() %
3
)
return
false
;
//
A destination may only appear once. This requirement allows us to avoid the undefined behavior
//
of having a destination that is supposed to get multiple inputs simultaneously. It also
//
imposes some interesting constraints on the "shape" of the shuffle. If we treat a shuffle pair
//
as an edge and the Args as nodes, then the single-destination requirement means that the
//
shuffle graph consists of two kinds of subgraphs:
//
//
- Spanning trees. We call these shifts. They can be executed as a sequence of Move
//
instructions and don't usually require scratch registers.
//
//
- Closed loops. These loops consist of nodes that have one successor and one predecessor, so
//
there is no way to "get into" the loop from outside of it. These can be executed using swaps
//
or by saving one of the Args to a scratch register and executing it as a shift.
UncheckedKeyHashSet<Arg> dsts;
for
(
unsigned
i =
0
; i < inst.
args
().
size
(); ++i) {
Arg arg = inst.
args
()[i];
unsigned
mode = i %
3
;
if
(mode ==
2
) {
//
It's the width.
if
(!arg.
isWidthArg
())
return
false
;
continue
;
}
//
The source can be an immediate.
if
(!mode) {
if
(arg.
isSomeImm
())
continue
;
if
(!arg.
isCompatibleBank
(inst.
args
()[i +
1
]))
return
false
;
}
else
{
ASSERT
(mode ==
1
);
if
(!dsts.
add
(arg).
isNewEntry
)
return
false
;
}
if
(arg.
isTmp
() || arg.
isMemory
())
continue
;
return
false
;
}
//
No destination register may appear in any address expressions. The lowering can't handle it
//
and it's not useful for the way we end up using Shuffles. Normally, Shuffles only used for
//
stack addresses and non-stack registers.
for
(Arg& arg : inst.
args
()) {
if
(!arg.
isMemory
())
continue
;
bool
ok =
true
;
arg.
forEachTmpFast
(
[&] (Tmp tmp) {
if
(dsts.
contains
(tmp))
ok =
false
;
});
if
(!ok)
return
false
;
}
return
true
;
}
MacroAssembler::Jump
ShuffleCustom::generate
(Inst& inst, CCallHelpers&, GenerationContext&)
{
dataLog
(
"
FATAL: Unlowered shuffle:
"
, inst,
"
\n
"
);
UNREACHABLE_FOR_PLATFORM
();
return
MacroAssembler::Jump
();
}
bool
WasmBoundsCheckCustom::isValidForm
(Inst& inst)
{
if
(inst.
args
().
size
() <
2
|| inst.
args
().
size
() >
3
)
return
false
;
if
(!inst.
args
()[
0
].
isTmp
() && !inst.
args
()[
0
].
isSomeImm
())
return
false
;
if
(!(inst.
args
()[
1
].
isReg
() || inst.
args
()[
1
].
isTmp
() || inst.
args
()[
1
].
isSomeImm
()))
return
false
;
if
(inst.
args
().
size
() ==
3
)
return
inst.
args
()[
2
].
isTmp
() || inst.
args
()[
2
].
isReg
();
return
true
;
}
MacroAssembler::Jump
WasmBoundsCheckCustom::generate
(Inst& inst, CCallHelpers& jit, GenerationContext& context)
{
WasmBoundsCheckValue* value = inst.
origin
->
as
<WasmBoundsCheckValue>();
MacroAssembler::Jump overflowOOB { };
if
(inst.
args
().
size
() >
2
)
overflowOOB =
Inst
(Air::Branch64, value,
Arg::relCond
(MacroAssembler::Below), inst.
args
()[
0
], inst.
args
()[
2
]).
generate
(jit, context);
MacroAssembler::Jump outOfBounds =
Inst
(Air::Branch64, value,
Arg::relCond
(MacroAssembler::AboveOrEqual), inst.
args
()[
0
], inst.
args
()[
1
]).
generate
(jit, context);
context.
latePaths
.
append
(std::tuple {
value->
origin
(),
createSharedTask<GenerationContext::LatePathFunction>(
[outOfBounds, overflowOOB, value] (CCallHelpers& jit, Air::GenerationContext& context) {
if
(overflowOOB.
isSet
())
overflowOOB.
link
(&jit);
outOfBounds.
link
(&jit);
switch
(value->
boundsType
()) {
case
WasmBoundsCheckValue::Type::Pinned:
context.
code
->
wasmBoundsCheckGenerator
()->
run
(jit, value, value->
bounds
().
pinnedSize
);
break
;
case
WasmBoundsCheckValue::Type::Maximum:
context.
code
->
wasmBoundsCheckGenerator
()->
run
(jit, value, InvalidGPRReg);
break
;
}
})
});
//
We said we were not a terminal.
return
MacroAssembler::Jump
();
}
} } }
//
namespace JSC::B3::Air
#
endif
//
ENABLE(B3_JIT)
Back
|
FazBrowse Home
|
New Git URL