Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
Pyston
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
Pyston
Commits
e790c693
Commit
e790c693
authored
Aug 23, 2016
by
Marius Wachtler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
moves the TypeRecorder ownership to the ICInfo
parent
afec0555
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
72 additions
and
85 deletions
+72
-85
src/asm_writing/icinfo.cpp
src/asm_writing/icinfo.cpp
+5
-5
src/asm_writing/icinfo.h
src/asm_writing/icinfo.h
+5
-4
src/asm_writing/rewriter.h
src/asm_writing/rewriter.h
+1
-0
src/codegen/baseline_jit.cpp
src/codegen/baseline_jit.cpp
+42
-37
src/codegen/baseline_jit.h
src/codegen/baseline_jit.h
+7
-7
src/codegen/patchpoints.cpp
src/codegen/patchpoints.cpp
+2
-4
src/codegen/patchpoints.h
src/codegen/patchpoints.h
+5
-11
src/codegen/type_recording.cpp
src/codegen/type_recording.cpp
+4
-13
src/codegen/type_recording.h
src/codegen/type_recording.h
+0
-2
src/runtime/ics.cpp
src/runtime/ics.cpp
+1
-2
No files found.
src/asm_writing/icinfo.cpp
View file @
e790c693
...
...
@@ -23,6 +23,7 @@
#include "asm_writing/assembler.h"
#include "asm_writing/mc_writer.h"
#include "codegen/patchpoints.h"
#include "codegen/type_recording.h"
#include "codegen/unwinding.h"
#include "core/common.h"
#include "core/options.h"
...
...
@@ -339,14 +340,12 @@ static llvm::DenseMap<AST*, ICInfo*> ics_by_ast_node;
ICInfo
::
ICInfo
(
void
*
start_addr
,
void
*
slowpath_rtn_addr
,
void
*
continue_addr
,
StackInfo
stack_info
,
int
size
,
llvm
::
CallingConv
::
ID
calling_conv
,
LiveOutSet
_live_outs
,
assembler
::
GenericRegister
return_register
,
TypeRecorder
*
type_recorder
,
std
::
vector
<
Location
>
ic_global_decref_locations
,
assembler
::
RegisterSet
allocatable_registers
)
std
::
vector
<
Location
>
ic_global_decref_locations
,
assembler
::
RegisterSet
allocatable_registers
)
:
next_slot_to_try
(
0
),
stack_info
(
stack_info
),
calling_conv
(
calling_conv
),
live_outs
(
std
::
move
(
_live_outs
)),
return_register
(
return_register
),
type_recorder
(
type_recorder
),
retry_in
(
0
),
retry_backoff
(
1
),
times_rewritten
(
0
),
...
...
@@ -416,7 +415,7 @@ std::unique_ptr<ICInfo> registerCompiledPatchpoint(uint8_t* start_addr, uint8_t*
ICInfo
*
icinfo
=
new
ICInfo
(
start_addr
,
slowpath_rtn_addr
,
continue_addr
,
stack_info
,
ic
->
size
,
ic
->
getCallingConvention
(),
std
::
move
(
live_outs
),
return_register
,
ic
->
type_recorder
,
decref_info
,
ic
->
allocatable_regs
);
std
::
move
(
live_outs
),
return_register
,
decref_info
,
ic
->
allocatable_regs
);
assert
(
!
ics_by_return_addr
.
count
(
slowpath_rtn_addr
));
ics_by_return_addr
[
slowpath_rtn_addr
]
=
icinfo
;
...
...
@@ -487,9 +486,10 @@ ICInfo* ICInfo::getICInfoForNode(AST* node) {
return
it
->
second
;
return
NULL
;
}
void
ICInfo
::
associateNodeWithICInfo
(
AST
*
node
)
{
void
ICInfo
::
associateNodeWithICInfo
(
AST
*
node
,
std
::
unique_ptr
<
TypeRecorder
>
type_recorder
)
{
assert
(
!
this
->
node
);
this
->
node
=
node
;
this
->
type_recorder
=
std
::
move
(
type_recorder
);
ics_by_ast_node
[
node
]
=
this
;
}
void
ICInfo
::
appendDecrefInfosTo
(
std
::
vector
<
DecrefInfo
>&
dest_decref_infos
)
{
...
...
src/asm_writing/icinfo.h
View file @
e790c693
...
...
@@ -93,7 +93,7 @@ private:
const
llvm
::
CallingConv
::
ID
calling_conv
;
LiveOutSet
live_outs
;
const
assembler
::
GenericRegister
return_register
;
TypeRecorder
*
const
type_recorder
;
std
::
unique_ptr
<
TypeRecorder
>
type_recorder
;
int
retry_in
,
retry_backoff
;
int
times_rewritten
;
assembler
::
RegisterSet
allocatable_registers
;
...
...
@@ -113,7 +113,7 @@ private:
public:
ICInfo
(
void
*
start_addr
,
void
*
slowpath_rtn_addr
,
void
*
continue_addr
,
StackInfo
stack_info
,
int
size
,
llvm
::
CallingConv
::
ID
calling_conv
,
LiveOutSet
live_outs
,
assembler
::
GenericRegister
return_register
,
TypeRecorder
*
type_recorder
,
std
::
vector
<
Location
>
ic_global_decref_locations
,
std
::
vector
<
Location
>
ic_global_decref_locations
,
assembler
::
RegisterSet
allocatable_registers
=
assembler
::
RegisterSet
::
stdAllocatable
());
~
ICInfo
();
void
*
const
start_addr
,
*
const
slowpath_rtn_addr
,
*
const
continue_addr
;
...
...
@@ -123,6 +123,7 @@ public:
llvm
::
CallingConv
::
ID
getCallingConvention
()
{
return
calling_conv
;
}
const
LiveOutSet
&
getLiveOuts
()
{
return
live_outs
;
}
TypeRecorder
*
getTypeRecorder
()
{
return
type_recorder
.
get
();
}
std
::
unique_ptr
<
ICSlotRewrite
>
startRewrite
(
const
char
*
debug_name
);
void
invalidate
(
ICSlotInfo
*
entry
);
...
...
@@ -145,7 +146,7 @@ public:
friend
class
ICSlotRewrite
;
static
ICInfo
*
getICInfoForNode
(
AST
*
node
);
void
associateNodeWithICInfo
(
AST
*
node
);
void
associateNodeWithICInfo
(
AST
*
node
,
std
::
unique_ptr
<
TypeRecorder
>
type_recorder
);
void
appendDecrefInfosTo
(
std
::
vector
<
DecrefInfo
>&
dest_decref_infos
);
};
...
...
@@ -179,7 +180,7 @@ public:
ICInfo
*
getICInfo
()
{
return
ic_entry
->
ic
;
}
int
getSlotSize
()
{
return
ic_entry
->
size
;
}
uint8_t
*
getSlotStart
()
{
return
ic_entry
->
start_addr
;
}
TypeRecorder
*
getTypeRecorder
()
{
return
getICInfo
()
->
type_recorder
;
}
TypeRecorder
*
getTypeRecorder
()
{
return
getICInfo
()
->
getTypeRecorder
()
;
}
assembler
::
GenericRegister
returnRegister
()
{
return
getICInfo
()
->
return_register
;
}
int
getScratchSize
()
{
return
getICInfo
()
->
stack_info
.
scratch_size
;
}
int
getScratchRspOffset
()
{
...
...
src/asm_writing/rewriter.h
View file @
e790c693
...
...
@@ -179,6 +179,7 @@ public:
RewriterVar
*
cmp
(
AST_TYPE
::
AST_TYPE
cmp_type
,
RewriterVar
*
other
,
Location
loc
=
Location
::
any
());
RewriterVar
*
toBool
(
Location
loc
=
Location
::
any
());
RefType
getType
()
const
{
return
reftype
;
}
RewriterVar
*
setType
(
RefType
type
);
RewriterVar
*
setNullable
(
bool
nullable
)
{
this
->
nullable
=
nullable
;
...
...
src/codegen/baseline_jit.cpp
View file @
e790c693
...
...
@@ -149,8 +149,8 @@ std::unique_ptr<JitFragmentWriter> JitCodeBlock::newFragment(CFGBlock* block, in
long
bytes_left
=
a
.
bytesLeft
()
+
patch_jump_offset
;
constexpr
assembler
::
RegisterSet
bjit_allocatable_regs
=
assembler
::
RegisterSet
::
stdAllocatable
()
|
additional_regs
;
std
::
unique_ptr
<
ICInfo
>
ic_info
(
new
ICInfo
(
fragment_start
,
nullptr
,
nullptr
,
stack_info
,
bytes_left
,
llvm
::
CallingConv
::
C
,
live_outs
,
assembler
::
RAX
,
0
,
std
::
vector
<
Location
>
(),
bjit_allocatable_regs
));
llvm
::
CallingConv
::
C
,
live_outs
,
assembler
::
RAX
,
std
::
vector
<
Location
>
()
,
bjit_allocatable_regs
));
std
::
unique_ptr
<
ICSlotRewrite
>
rewrite
=
ic_info
->
startRewrite
(
""
);
return
std
::
unique_ptr
<
JitFragmentWriter
>
(
...
...
@@ -227,7 +227,8 @@ RewriterVar* JitFragmentWriter::imm(void* val) {
}
RewriterVar
*
JitFragmentWriter
::
emitAugbinop
(
AST_expr
*
node
,
RewriterVar
*
lhs
,
RewriterVar
*
rhs
,
int
op_type
)
{
return
emitPPCall
((
void
*
)
augbinop
,
{
lhs
,
rhs
,
imm
(
op_type
)
},
2
*
320
,
node
).
first
->
setType
(
RefType
::
OWNED
);
return
emitPPCall
((
void
*
)
augbinop
,
{
lhs
,
rhs
,
imm
(
op_type
)
},
2
*
320
,
true
/* record type */
,
node
)
.
first
->
setType
(
RefType
::
OWNED
);
}
RewriterVar
*
JitFragmentWriter
::
emitApplySlice
(
RewriterVar
*
target
,
RewriterVar
*
lower
,
RewriterVar
*
upper
)
{
...
...
@@ -239,14 +240,13 @@ RewriterVar* JitFragmentWriter::emitApplySlice(RewriterVar* target, RewriterVar*
}
RewriterVar
*
JitFragmentWriter
::
emitBinop
(
AST_expr
*
node
,
RewriterVar
*
lhs
,
RewriterVar
*
rhs
,
int
op_type
)
{
return
emitPPCall
((
void
*
)
binop
,
{
lhs
,
rhs
,
imm
(
op_type
)
},
2
*
240
,
node
).
first
->
setType
(
RefType
::
OWNED
);
return
emitPPCall
((
void
*
)
binop
,
{
lhs
,
rhs
,
imm
(
op_type
)
},
2
*
240
,
true
/* record type */
,
node
)
.
first
->
setType
(
RefType
::
OWNED
);
}
RewriterVar
*
JitFragmentWriter
::
emitCallattr
(
AST_expr
*
node
,
RewriterVar
*
obj
,
BoxedString
*
attr
,
CallattrFlags
flags
,
const
llvm
::
ArrayRef
<
RewriterVar
*>
args
,
std
::
vector
<
BoxedString
*>*
keyword_names
)
{
TypeRecorder
*
type_recorder
=
getTypeRecorderForNode
(
node
);
#if ENABLE_BASELINEJIT_ICS
RewriterVar
*
attr_var
=
imm
(
attr
);
RewriterVar
*
flags_var
=
imm
(
flags
.
asInt
());
...
...
@@ -270,7 +270,7 @@ RewriterVar* JitFragmentWriter::emitCallattr(AST_expr* node, RewriterVar* obj, B
if
(
keyword_names
)
call_args
.
push_back
(
imm
(
keyword_names
));
return
emitPPCall
((
void
*
)
callattr
,
call_args
,
2
*
640
,
node
,
type_recorder
,
additional_uses
)
return
emitPPCall
((
void
*
)
callattr
,
call_args
,
2
*
640
,
true
/* record type */
,
node
,
additional_uses
)
.
first
->
setType
(
RefType
::
OWNED
);
#else
// We could make this faster but for now: keep it simple, stupid...
...
...
@@ -289,8 +289,6 @@ RewriterVar* JitFragmentWriter::emitCallattr(AST_expr* node, RewriterVar* obj, B
call_args
.
push_back
(
attr_var
);
call_args
.
push_back
(
flags_var
);
call_args
.
push_back
(
imm
(
type_recorder
));
if
(
args_array
)
call_args
.
push_back
(
args_array
);
if
(
keyword_names_var
)
...
...
@@ -305,7 +303,8 @@ RewriterVar* JitFragmentWriter::emitCompare(AST_expr* node, RewriterVar* lhs, Re
RewriterVar
*
cmp_result
=
lhs
->
cmp
(
op_type
==
AST_TYPE
::
IsNot
?
AST_TYPE
::
NotEq
:
AST_TYPE
::
Eq
,
rhs
);
return
call
(
false
,
(
void
*
)
boxBool
,
cmp_result
)
->
setType
(
RefType
::
OWNED
);
}
return
emitPPCall
((
void
*
)
compare
,
{
lhs
,
rhs
,
imm
(
op_type
)
},
2
*
240
,
node
).
first
->
setType
(
RefType
::
OWNED
);
return
emitPPCall
((
void
*
)
compare
,
{
lhs
,
rhs
,
imm
(
op_type
)
},
2
*
240
,
true
/* record type */
,
node
)
.
first
->
setType
(
RefType
::
OWNED
);
}
RewriterVar
*
JitFragmentWriter
::
emitCreateDict
()
{
...
...
@@ -388,7 +387,7 @@ RewriterVar* JitFragmentWriter::emitExceptionMatches(RewriterVar* v, RewriterVar
}
RewriterVar
*
JitFragmentWriter
::
emitGetAttr
(
RewriterVar
*
obj
,
BoxedString
*
s
,
AST_expr
*
node
)
{
return
emitPPCall
((
void
*
)
getattr
,
{
obj
,
imm
(
s
)
},
2
*
256
,
node
,
getTypeRecorderForNode
(
node
)
)
return
emitPPCall
((
void
*
)
getattr
,
{
obj
,
imm
(
s
)
},
2
*
256
,
true
/* record type */
,
node
)
.
first
->
setType
(
RefType
::
OWNED
);
}
...
...
@@ -433,7 +432,8 @@ RewriterVar* JitFragmentWriter::emitGetGlobal(BoxedString* s) {
}
RewriterVar
*
JitFragmentWriter
::
emitGetItem
(
AST_expr
*
node
,
RewriterVar
*
value
,
RewriterVar
*
slice
)
{
return
emitPPCall
((
void
*
)
getitem
,
{
value
,
slice
},
256
,
node
).
first
->
setType
(
RefType
::
OWNED
);
return
emitPPCall
((
void
*
)
getitem
,
{
value
,
slice
},
256
,
true
/* record type */
,
node
)
.
first
->
setType
(
RefType
::
OWNED
);
}
RewriterVar
*
JitFragmentWriter
::
emitGetLocal
(
InternedString
s
,
int
vreg
)
{
...
...
@@ -505,8 +505,6 @@ RewriterVar* JitFragmentWriter::emitRepr(RewriterVar* v) {
RewriterVar
*
JitFragmentWriter
::
emitRuntimeCall
(
AST_expr
*
node
,
RewriterVar
*
obj
,
ArgPassSpec
argspec
,
const
llvm
::
ArrayRef
<
RewriterVar
*>
args
,
std
::
vector
<
BoxedString
*>*
keyword_names
)
{
TypeRecorder
*
type_recorder
=
getTypeRecorderForNode
(
node
);
#if ENABLE_BASELINEJIT_ICS
RewriterVar
*
argspec_var
=
imm
(
argspec
.
asInt
());
RewriterVar
::
SmallVector
call_args
;
...
...
@@ -526,7 +524,7 @@ RewriterVar* JitFragmentWriter::emitRuntimeCall(AST_expr* node, RewriterVar* obj
if
(
keyword_names
)
call_args
.
push_back
(
imm
(
keyword_names
));
return
emitPPCall
((
void
*
)
runtimeCall
,
call_args
,
2
*
640
,
node
,
type_recorder
,
additional_uses
)
return
emitPPCall
((
void
*
)
runtimeCall
,
call_args
,
2
*
640
,
node
!=
NULL
/* record type */
,
node
,
additional_uses
)
.
first
->
setType
(
RefType
::
OWNED
);
#else
RewriterVar
*
argspec_var
=
imm
(
argspec
.
asInt
());
...
...
@@ -541,7 +539,6 @@ RewriterVar* JitFragmentWriter::emitRuntimeCall(AST_expr* node, RewriterVar* obj
RewriterVar
::
SmallVector
call_args
;
call_args
.
push_back
(
obj
);
call_args
.
push_back
(
argspec_var
);
call_args
.
push_back
(
imm
(
type_recorder
));
if
(
args_array
)
call_args
.
push_back
(
args_array
);
if
(
keyword_names_var
)
...
...
@@ -685,7 +682,7 @@ void JitFragmentWriter::emitReturn(RewriterVar* v) {
}
void
JitFragmentWriter
::
emitSetAttr
(
AST_expr
*
node
,
RewriterVar
*
obj
,
BoxedString
*
s
,
STOLEN
(
RewriterVar
*
)
attr
)
{
auto
rtn
=
emitPPCall
((
void
*
)
setattr
,
{
obj
,
imm
(
s
),
attr
},
2
*
256
,
node
);
auto
rtn
=
emitPPCall
((
void
*
)
setattr
,
{
obj
,
imm
(
s
),
attr
},
2
*
256
,
false
/* don't record type */
,
node
);
attr
->
refConsumed
(
rtn
.
second
);
}
...
...
@@ -864,7 +861,10 @@ std::pair<int, llvm::DenseSet<int>> JitFragmentWriter::finishCompilation() {
std
::
unique_ptr
<
ICInfo
>
pp
=
registerCompiledPatchpoint
(
start_addr
,
slowpath_start
,
initialization_info
.
continue_addr
,
slowpath_rtn_addr
,
pp_info
.
ic
.
get
(),
pp_info
.
stack_info
,
LiveOutSet
(),
std
::
move
(
pp_info
.
decref_infos
));
pp
->
associateNodeWithICInfo
(
pp_info
.
node
);
if
(
pp_info
.
node
)
pp
->
associateNodeWithICInfo
(
pp_info
.
node
,
std
::
move
(
pp_info
.
type_recorder
));
else
assert
(
!
pp_info
.
type_recorder
);
ic_infos
.
push_back
(
std
::
move
(
pp
));
}
...
...
@@ -926,11 +926,10 @@ uint64_t JitFragmentWriter::asUInt(InternedString s) {
#endif
std
::
pair
<
RewriterVar
*
,
RewriterAction
*>
JitFragmentWriter
::
emitPPCall
(
void
*
func_addr
,
llvm
::
ArrayRef
<
RewriterVar
*>
args
,
unsigned
short
pp_size
,
AST
*
ast_node
,
TypeRecorder
*
type_recorder
,
llvm
::
ArrayRef
<
RewriterVar
*>
additional_uses
)
{
JitFragmentWriter
::
emitPPCall
(
void
*
func_addr
,
llvm
::
ArrayRef
<
RewriterVar
*>
args
,
unsigned
short
pp_size
,
bool
should_record_type
,
AST
*
ast_node
,
llvm
::
ArrayRef
<
RewriterVar
*>
additional_uses
)
{
if
(
LOG_BJIT_ASSEMBLY
)
comment
(
"BJIT: emitPPCall() start"
);
RewriterVar
::
SmallVector
args_vec
(
args
.
begin
(),
args
.
end
());
#if ENABLE_BASELINEJIT_ICS
RewriterVar
*
result
=
createNewVar
();
...
...
@@ -942,6 +941,9 @@ JitFragmentWriter::emitPPCall(void* func_addr, llvm::ArrayRef<RewriterVar*> args
unsigned
char
num_additional
=
additional_uses
.
size
();
RewriterVar
**
args_array
=
args_array_ref
.
data
();
if
(
should_record_type
)
assert
(
ast_node
);
RewriterAction
*
call_action
=
addAction
([
this
,
result
,
func_addr
,
ast_node
,
args_array
,
args_size
,
pp_size
,
num_additional
]()
{
auto
all_args
=
llvm
::
makeArrayRef
(
args_array
,
args_size
+
num_additional
);
...
...
@@ -949,13 +951,12 @@ JitFragmentWriter::emitPPCall(void* func_addr, llvm::ArrayRef<RewriterVar*> args
this
->
_emitPPCall
(
result
,
func_addr
,
args
,
pp_size
,
ast_node
,
all_args
);
},
args_array_ref
,
ActionType
::
NORMAL
);
if
(
type_recorder
)
{
RewriterVar
*
type_recorder_var
=
imm
(
type_recorder
);
if
(
should_record_type
)
{
RewriterVar
*
obj_cls_var
=
result
->
getAttr
(
offsetof
(
Box
,
cls
));
addAction
([
=
]()
{
_emitRecordType
(
type_recorder_var
,
obj_cls_var
);
_emitRecordType
(
obj_cls_var
);
result
->
bumpUse
();
},
{
type_recorder_var
,
obj_cls_var
,
result
},
ActionType
::
NORMAL
);
},
{
obj_cls_var
,
result
},
ActionType
::
NORMAL
);
emitPendingCallsCheck
();
return
std
::
make_pair
(
result
,
call_action
);
...
...
@@ -965,6 +966,7 @@ JitFragmentWriter::emitPPCall(void* func_addr, llvm::ArrayRef<RewriterVar*> args
comment
(
"BJIT: emitPPCall() end"
);
return
std
::
make_pair
(
result
,
call_action
);
#else
RewriterVar
::
SmallVector
args_vec
(
args
.
begin
(),
args
.
end
());
assert
(
args_vec
.
size
()
<
7
);
RewriterVar
*
result
=
call
(
false
,
func_addr
,
args_vec
);
RewriterAction
*
call_action
=
getLastAction
();
...
...
@@ -979,12 +981,12 @@ void JitFragmentWriter::assertNameDefinedHelper(const char* id) {
assertNameDefined
(
0
,
id
,
UnboundLocalError
,
true
);
}
Box
*
JitFragmentWriter
::
callattrHelper
(
Box
*
obj
,
BoxedString
*
attr
,
CallattrFlags
flags
,
TypeRecorder
*
type_recorder
,
Box
**
args
,
std
::
vector
<
BoxedString
*>*
keyword_names
)
{
Box
*
JitFragmentWriter
::
callattrHelper
(
Box
*
obj
,
BoxedString
*
attr
,
CallattrFlags
flags
,
Box
**
args
,
std
::
vector
<
BoxedString
*>*
keyword_names
)
{
auto
arg_tuple
=
getTupleFromArgsArray
(
&
args
[
0
],
flags
.
argspec
.
totalPassed
());
Box
*
r
=
callattr
(
obj
,
attr
,
flags
,
std
::
get
<
0
>
(
arg_tuple
),
std
::
get
<
1
>
(
arg_tuple
),
std
::
get
<
2
>
(
arg_tuple
),
std
::
get
<
3
>
(
arg_tuple
),
keyword_names
);
return
r
ecordType
(
type_recorder
,
r
)
;
return
r
;
}
Box
*
JitFragmentWriter
::
createDictHelper
(
uint64_t
num
,
Box
**
keys
,
Box
**
values
)
{
...
...
@@ -1038,12 +1040,12 @@ BORROWED(Box*) JitFragmentWriter::notHelper(Box* b) {
return
b
->
nonzeroIC
()
?
Py_False
:
Py_True
;
}
Box
*
JitFragmentWriter
::
runtimeCallHelper
(
Box
*
obj
,
ArgPassSpec
argspec
,
TypeRecorder
*
type_recorder
,
Box
**
args
,
Box
*
JitFragmentWriter
::
runtimeCallHelper
(
Box
*
obj
,
ArgPassSpec
argspec
,
Box
**
args
,
std
::
vector
<
BoxedString
*>*
keyword_names
)
{
auto
arg_tuple
=
getTupleFromArgsArray
(
&
args
[
0
],
argspec
.
totalPassed
());
Box
*
r
=
runtimeCall
(
obj
,
argspec
,
std
::
get
<
0
>
(
arg_tuple
),
std
::
get
<
1
>
(
arg_tuple
),
std
::
get
<
2
>
(
arg_tuple
),
std
::
get
<
3
>
(
arg_tuple
),
keyword_names
);
return
r
ecordType
(
type_recorder
,
r
)
;
return
r
;
}
void
JitFragmentWriter
::
_emitGetLocal
(
RewriterVar
*
val_var
,
const
char
*
name
)
{
...
...
@@ -1160,7 +1162,7 @@ void JitFragmentWriter::_emitPPCall(RewriterVar* result, void* func_addr, llvm::
regs
|=
assembler
::
RegisterSet
(
reg
);
}
std
::
unique_ptr
<
ICSetupInfo
>
setup_info
(
ICSetupInfo
::
initialize
(
true
,
pp_size
,
ICSetupInfo
::
Generic
,
NULL
,
regs
));
std
::
unique_ptr
<
ICSetupInfo
>
setup_info
(
ICSetupInfo
::
initialize
(
true
,
pp_size
,
ICSetupInfo
::
Generic
,
regs
));
// calculate available scratch space
...
...
@@ -1179,8 +1181,8 @@ void JitFragmentWriter::_emitPPCall(RewriterVar* result, void* func_addr, llvm::
StackInfo
stack_info
(
pp_scratch_size
,
pp_scratch_location
);
auto
&&
decref_infos
=
getDecrefLocations
();
pp_infos
.
emplace_back
(
PPInfo
{
func_addr
,
pp_start
,
pp_end
,
std
::
move
(
setup_info
),
stack_info
,
ast_node
,
std
::
move
(
decref_infos
)
});
pp_infos
.
emplace_back
(
PPInfo
{
func_addr
,
pp_start
,
pp_end
,
std
::
move
(
setup_info
),
stack_info
,
ast_node
,
std
::
move
(
decref_infos
),
std
::
unique_ptr
<
TypeRecorder
>
(
)
});
assert
(
vars_by_location
.
count
(
assembler
::
RAX
)
==
0
);
result
->
initializeInReg
(
assembler
::
RAX
);
...
...
@@ -1193,11 +1195,15 @@ void JitFragmentWriter::_emitPPCall(RewriterVar* result, void* func_addr, llvm::
}
}
void
JitFragmentWriter
::
_emitRecordType
(
RewriterVar
*
type_recorder_var
,
RewriterVar
*
obj_cls_var
)
{
// This directly emits the instructions of the recordType() function.
void
JitFragmentWriter
::
_emitRecordType
(
RewriterVar
*
obj_cls_var
)
{
assert
(
!
pp_infos
.
back
().
type_recorder
);
TypeRecorder
*
type_recorder
=
new
TypeRecorder
;
pp_infos
.
back
().
type_recorder
.
reset
(
type_recorder
);
// This directly emits the instructions of the recordType() function.
assembler
::
Register
obj_cls_reg
=
obj_cls_var
->
getInReg
();
assembler
::
Register
type_recorder_reg
=
type_recorder_var
->
getInReg
(
Location
::
any
(),
true
,
obj_cls_reg
);
assembler
::
Register
type_recorder_reg
=
allocReg
(
Location
::
any
(),
obj_cls_reg
);
const_loader
.
loadConstIntoReg
((
uint64_t
)
type_recorder
,
type_recorder_reg
);
assembler
::
Indirect
last_seen_count
=
assembler
::
Indirect
(
type_recorder_reg
,
offsetof
(
TypeRecorder
,
last_count
));
assembler
::
Indirect
last_seen_indirect
=
assembler
::
Indirect
(
type_recorder_reg
,
offsetof
(
TypeRecorder
,
last_seen
));
...
...
@@ -1209,7 +1215,6 @@ void JitFragmentWriter::_emitRecordType(RewriterVar* type_recorder_var, Rewriter
}
assembler
->
incq
(
last_seen_count
);
type_recorder_var
->
bumpUse
();
obj_cls_var
->
bumpUse
();
}
...
...
src/codegen/baseline_jit.h
View file @
e790c693
...
...
@@ -251,6 +251,7 @@ private:
StackInfo
stack_info
;
AST
*
node
;
std
::
vector
<
Location
>
decref_infos
;
std
::
unique_ptr
<
TypeRecorder
>
type_recorder
;
};
llvm
::
SmallVector
<
PPInfo
,
8
>
pp_infos
;
...
...
@@ -349,13 +350,13 @@ private:
RewriterVar
*
emitCallWithAllocatedArgs
(
void
*
func_addr
,
const
llvm
::
ArrayRef
<
RewriterVar
*>
args
,
const
llvm
::
ArrayRef
<
RewriterVar
*>
additional_uses
);
std
::
pair
<
RewriterVar
*
,
RewriterAction
*>
emitPPCall
(
void
*
func_addr
,
llvm
::
ArrayRef
<
RewriterVar
*>
args
,
unsigned
short
pp_size
,
AST
*
ast_node
=
NULL
,
TypeRecorder
*
type_recorder
=
NULL
,
unsigned
short
pp_size
,
bool
should_record_type
=
false
,
AST
*
ast_node
=
NULL
,
llvm
::
ArrayRef
<
RewriterVar
*>
additional_uses
=
{});
static
void
assertNameDefinedHelper
(
const
char
*
id
);
static
Box
*
callattrHelper
(
Box
*
obj
,
BoxedString
*
attr
,
CallattrFlags
flags
,
TypeRecorder
*
type_recorder
,
Box
**
args
,
std
::
vector
<
BoxedString
*>*
keyword_names
);
static
Box
*
callattrHelper
(
Box
*
obj
,
BoxedString
*
attr
,
CallattrFlags
flags
,
Box
**
args
,
std
::
vector
<
BoxedString
*>*
keyword_names
);
static
Box
*
createDictHelper
(
uint64_t
num
,
Box
**
keys
,
Box
**
values
);
static
Box
*
createListHelper
(
uint64_t
num
,
Box
**
data
);
static
Box
*
createSetHelper
(
uint64_t
num
,
Box
**
data
);
...
...
@@ -364,15 +365,14 @@ private:
static
BORROWED
(
Box
*
)
hasnextHelper
(
Box
*
b
);
static
BORROWED
(
Box
*
)
nonzeroHelper
(
Box
*
b
);
static
BORROWED
(
Box
*
)
notHelper
(
Box
*
b
);
static
Box
*
runtimeCallHelper
(
Box
*
obj
,
ArgPassSpec
argspec
,
TypeRecorder
*
type_recorder
,
Box
**
args
,
std
::
vector
<
BoxedString
*>*
keyword_names
);
static
Box
*
runtimeCallHelper
(
Box
*
obj
,
ArgPassSpec
argspec
,
Box
**
args
,
std
::
vector
<
BoxedString
*>*
keyword_names
);
void
_emitGetLocal
(
RewriterVar
*
val_var
,
const
char
*
name
);
void
_emitJump
(
CFGBlock
*
b
,
RewriterVar
*
block_next
,
ExitInfo
&
exit_info
);
void
_emitOSRPoint
();
void
_emitPPCall
(
RewriterVar
*
result
,
void
*
func_addr
,
llvm
::
ArrayRef
<
RewriterVar
*>
args
,
unsigned
short
pp_size
,
AST
*
ast_node
,
llvm
::
ArrayRef
<
RewriterVar
*>
vars_to_bump
);
void
_emitRecordType
(
RewriterVar
*
type_recorder_var
,
RewriterVar
*
obj_cls_var
);
void
_emitRecordType
(
RewriterVar
*
obj_cls_var
);
void
_emitReturn
(
RewriterVar
*
v
);
void
_emitSideExit
(
STOLEN
(
RewriterVar
*
)
var
,
RewriterVar
*
val_constant
,
CFGBlock
*
next_block
,
RewriterVar
*
false_path
);
...
...
src/codegen/patchpoints.cpp
View file @
e790c693
...
...
@@ -45,10 +45,8 @@ int ICSetupInfo::totalSize() const {
static
std
::
vector
<
std
::
pair
<
std
::
unique_ptr
<
PatchpointInfo
>
,
void
*
/* addr of func to call */
>>
new_patchpoints
;
std
::
unique_ptr
<
ICSetupInfo
>
ICSetupInfo
::
initialize
(
bool
has_return_value
,
int
size
,
ICType
type
,
TypeRecorder
*
type_recorder
,
assembler
::
RegisterSet
allocatable_regs
)
{
auto
rtn
=
std
::
unique_ptr
<
ICSetupInfo
>
(
new
ICSetupInfo
(
type
,
size
,
has_return_value
,
type_recorder
,
allocatable_regs
));
auto
rtn
=
std
::
unique_ptr
<
ICSetupInfo
>
(
new
ICSetupInfo
(
type
,
size
,
has_return_value
,
allocatable_regs
));
// We use size == CALL_ONLY_SIZE to imply that the call isn't patchable
...
...
@@ -431,7 +429,7 @@ std::unique_ptr<ICSetupInfo> createHasnextIC() {
}
std
::
unique_ptr
<
ICSetupInfo
>
createDeoptIC
()
{
return
ICSetupInfo
::
initialize
(
true
,
0
,
ICSetupInfo
::
Deopt
,
NULL
);
return
ICSetupInfo
::
initialize
(
true
,
0
,
ICSetupInfo
::
Deopt
);
}
}
// namespace pyston
src/codegen/patchpoints.h
View file @
e790c693
...
...
@@ -65,19 +65,13 @@ public:
};
private:
ICSetupInfo
(
ICType
type
,
int
size
,
bool
has_return_value
,
TypeRecorder
*
type_recorder
,
assembler
::
RegisterSet
allocatable_regs
)
:
type
(
type
),
size
(
size
),
has_return_value
(
has_return_value
),
type_recorder
(
type_recorder
),
allocatable_regs
(
allocatable_regs
)
{}
ICSetupInfo
(
ICType
type
,
int
size
,
bool
has_return_value
,
assembler
::
RegisterSet
allocatable_regs
)
:
type
(
type
),
size
(
size
),
has_return_value
(
has_return_value
),
allocatable_regs
(
allocatable_regs
)
{}
public:
const
ICType
type
;
const
int
size
;
const
bool
has_return_value
;
TypeRecorder
*
const
type_recorder
;
assembler
::
RegisterSet
allocatable_regs
;
int
totalSize
()
const
;
...
...
@@ -97,9 +91,9 @@ public:
return
llvm
::
CallingConv
::
C
;
}
static
std
::
unique_ptr
<
ICSetupInfo
>
initialize
(
bool
has_return_value
,
int
size
,
ICType
type
,
TypeRecorder
*
type_recorder
=
NULL
,
assembler
::
RegisterSet
allocatable_regs
=
assembler
::
RegisterSet
::
stdAllocatable
());
static
std
::
unique_ptr
<
ICSetupInfo
>
initialize
(
bool
has_return_value
,
int
size
,
ICType
type
,
assembler
::
RegisterSet
allocatable_regs
=
assembler
::
RegisterSet
::
stdAllocatable
());
};
struct
PatchpointInfo
{
...
...
src/codegen/type_recording.cpp
View file @
e790c693
...
...
@@ -14,21 +14,12 @@
#include "codegen/type_recording.h"
#include <unordered_map>
#include "asm_writing/icinfo.h"
#include "core/options.h"
#include "core/types.h"
namespace
pyston
{
static
std
::
unordered_map
<
AST
*
,
std
::
unique_ptr
<
TypeRecorder
>>
type_recorders
;
TypeRecorder
*
getTypeRecorderForNode
(
AST
*
node
)
{
std
::
unique_ptr
<
TypeRecorder
>&
r
=
type_recorders
[
node
];
if
(
r
==
NULL
)
r
=
llvm
::
make_unique
<
TypeRecorder
>
();
return
r
.
get
();
}
Box
*
recordType
(
TypeRecorder
*
self
,
Box
*
obj
)
{
// The baseline JIT directly generates machine code for this function inside JitFragmentWriter::_emitRecordType.
// When changing this function one has to also change the bjit code.
...
...
@@ -52,11 +43,11 @@ Box* recordType(TypeRecorder* self, Box* obj) {
}
BoxedClass
*
predictClassFor
(
AST
*
node
)
{
auto
it
=
type_recorders
.
find
(
node
);
if
(
it
==
type_recorders
.
end
())
ICInfo
*
ic
=
ICInfo
::
getICInfoForNode
(
node
);
if
(
!
ic
||
!
ic
->
getTypeRecorder
())
return
NULL
;
return
i
t
->
second
->
predict
();
return
i
c
->
getTypeRecorder
()
->
predict
();
}
BoxedClass
*
TypeRecorder
::
predict
()
{
...
...
src/codegen/type_recording.h
View file @
e790c693
...
...
@@ -44,8 +44,6 @@ public:
friend
Box
*
recordType
(
TypeRecorder
*
,
Box
*
);
};
TypeRecorder
*
getTypeRecorderForNode
(
AST
*
node
);
BoxedClass
*
predictClassFor
(
AST
*
node
);
}
...
...
src/runtime/ics.cpp
View file @
e790c693
...
...
@@ -249,8 +249,7 @@ RuntimeIC::RuntimeIC(void* func_addr, int total_size) {
// printf("Allocated runtime IC at %p\n", addr);
std
::
unique_ptr
<
ICSetupInfo
>
setup_info
(
ICSetupInfo
::
initialize
(
true
,
patchable_size
,
ICSetupInfo
::
Generic
,
NULL
));
std
::
unique_ptr
<
ICSetupInfo
>
setup_info
(
ICSetupInfo
::
initialize
(
true
,
patchable_size
,
ICSetupInfo
::
Generic
));
uint8_t
*
pp_start
=
(
uint8_t
*
)
addr
+
PROLOGUE_SIZE
;
uint8_t
*
pp_end
=
pp_start
+
patchable_size
+
CALL_SIZE
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment