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
1e672eb3
Commit
1e672eb3
authored
Jan 20, 2015
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a FrameInfo object to all JIT'd frames
parent
c75e90df
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
84 additions
and
26 deletions
+84
-26
Makefile
Makefile
+4
-0
src/codegen/codegen.h
src/codegen/codegen.h
+1
-0
src/codegen/irgen/irgenerator.cpp
src/codegen/irgen/irgenerator.cpp
+25
-0
src/codegen/irgen/irgenerator.h
src/codegen/irgen/irgenerator.h
+4
-1
src/codegen/patchpoints.cpp
src/codegen/patchpoints.cpp
+16
-0
src/codegen/runtime_hooks.cpp
src/codegen/runtime_hooks.cpp
+3
-0
src/codegen/stackmaps.h
src/codegen/stackmaps.h
+6
-0
src/codegen/unwinding.cpp
src/codegen/unwinding.cpp
+11
-7
src/codegen/unwinding.h
src/codegen/unwinding.h
+3
-5
src/core/types.h
src/core/types.h
+8
-0
src/runtime/builtin_modules/builtins.cpp
src/runtime/builtin_modules/builtins.cpp
+0
-8
src/runtime/inline/link_forcer.cpp
src/runtime/inline/link_forcer.cpp
+3
-5
No files found.
Makefile
View file @
1e672eb3
...
...
@@ -969,6 +969,10 @@ test_cpp_ll:
$(CLANGPP_EXE)
$(TEST_DIR)
/test.cpp
-o
test.ll
-c
-O3
-emit-llvm
-S
-std
=
c++11
-g
less test.ll
rm
test.ll
bench_exceptions
:
$(CLANGPP_EXE)
$(TEST_DIR)
/bench_exceptions.cpp
-o
bench_exceptions
-O3
-std
=
c++11
zsh
-c
'ulimit -v
$(MAX_MEM_KB)
; ulimit -d
$(MAX_MEM_KB)
; time ./bench_exceptions'
rm
bench_exceptions
TEST_EXT_MODULE_NAMES
:=
basic_test descr_test slots_test
...
...
src/codegen/codegen.h
View file @
1e672eb3
...
...
@@ -70,6 +70,7 @@ struct GlobalState {
llvm
::
Type
*
llvm_class_type
,
*
llvm_class_type_ptr
;
llvm
::
Type
*
llvm_opaque_type
;
llvm
::
Type
*
llvm_str_type_ptr
;
llvm
::
Type
*
frame_info_type
;
llvm
::
Type
*
llvm_clfunction_type_ptr
,
*
llvm_closure_type_ptr
,
*
llvm_generator_type_ptr
;
llvm
::
Type
*
llvm_module_type_ptr
,
*
llvm_bool_type_ptr
;
llvm
::
Type
*
llvm_excinfo_type
;
...
...
src/codegen/irgen/irgenerator.cpp
View file @
1e672eb3
...
...
@@ -38,6 +38,7 @@
namespace
pyston
{
extern
"C"
void
dumpLLVM
(
llvm
::
Value
*
v
)
{
v
->
getType
()
->
dump
();
v
->
dump
();
}
...
...
@@ -71,6 +72,28 @@ llvm::Value* IRGenState::getScratchSpace(int min_bytes) {
return
scratch_space
;
}
llvm
::
Value
*
IRGenState
::
getFrameInfoVar
()
{
if
(
!
frame_info
)
{
llvm
::
BasicBlock
&
entry_block
=
getLLVMFunction
()
->
getEntryBlock
();
llvm
::
IRBuilder
<
true
>
builder
(
&
entry_block
);
if
(
entry_block
.
begin
()
!=
entry_block
.
end
())
builder
.
SetInsertPoint
(
&
entry_block
,
entry_block
.
getFirstInsertionPt
());
llvm
::
AllocaInst
*
al
=
builder
.
CreateAlloca
(
g
.
frame_info_type
,
NULL
,
"frame_info"
);
assert
(
al
->
isStaticAlloca
());
static_assert
(
offsetof
(
FrameInfo
,
exc_type
)
==
0
,
""
);
llvm
::
Value
*
exctype_gep
=
builder
.
CreateConstInBoundsGEP2_32
(
al
,
0
,
0
);
builder
.
CreateStore
(
embedConstantPtr
(
NULL
,
g
.
llvm_value_type_ptr
),
exctype_gep
);
frame_info
=
al
;
}
return
frame_info
;
}
ScopeInfo
*
IRGenState
::
getScopeInfo
()
{
return
getSourceInfo
()
->
getScopeInfo
();
}
...
...
@@ -2240,6 +2263,8 @@ public:
std
::
vector
<
llvm
::
Value
*>&
stackmap_args
)
override
{
int
initial_args
=
stackmap_args
.
size
();
stackmap_args
.
push_back
(
irstate
->
getFrameInfoVar
());
assert
(
INT
->
llvmType
()
==
g
.
i64
);
stackmap_args
.
push_back
(
getConstantInt
((
uint64_t
)
current_stmt
,
g
.
i64
));
pp
->
addFrameVar
(
"!current_stmt"
,
INT
);
...
...
src/codegen/irgen/irgenerator.h
View file @
1e672eb3
...
...
@@ -58,11 +58,13 @@ private:
llvm
::
MDNode
*
func_dbg_info
;
llvm
::
AllocaInst
*
scratch_space
;
llvm
::
Value
*
frame_info
;
int
scratch_size
;
public:
IRGenState
(
CompiledFunction
*
cf
,
SourceInfo
*
source_info
,
GCBuilder
*
gc
,
llvm
::
MDNode
*
func_dbg_info
)
:
cf
(
cf
),
source_info
(
source_info
),
gc
(
gc
),
func_dbg_info
(
func_dbg_info
),
scratch_space
(
NULL
),
scratch_size
(
0
)
{
:
cf
(
cf
),
source_info
(
source_info
),
gc
(
gc
),
func_dbg_info
(
func_dbg_info
),
scratch_space
(
NULL
),
frame_info
(
NULL
),
scratch_size
(
0
)
{
assert
(
cf
->
func
);
assert
(
!
cf
->
clfunc
);
// in this case don't need to pass in sourceinfo
}
...
...
@@ -76,6 +78,7 @@ public:
GCBuilder
*
getGC
()
{
return
gc
;
}
llvm
::
Value
*
getScratchSpace
(
int
min_bytes
);
llvm
::
Value
*
getFrameInfoVar
();
ConcreteCompilerType
*
getReturnType
()
{
assert
(
cf
->
spec
);
...
...
src/codegen/patchpoints.cpp
View file @
1e672eb3
...
...
@@ -63,6 +63,12 @@ int PatchpointInfo::patchpointSize() {
return
CALL_ONLY_SIZE
;
}
bool
StackMap
::
Record
::
Location
::
operator
==
(
const
StackMap
::
Record
::
Location
&
rhs
)
{
// TODO: this check is overly-strict. Some fields are not used depending
// on the value of type, and I don't think "flags" is used at all currently.
return
(
type
==
rhs
.
type
)
&&
(
flags
==
rhs
.
flags
)
&&
(
regnum
==
rhs
.
regnum
)
&&
(
offset
==
rhs
.
offset
);
}
void
PatchpointInfo
::
parseLocationMap
(
StackMap
::
Record
*
r
,
LocationMap
*
map
)
{
assert
(
r
->
locations
.
size
()
==
totalStackmapArgs
());
...
...
@@ -70,6 +76,16 @@ void PatchpointInfo::parseLocationMap(StackMap::Record* r, LocationMap* map) {
// printf("parsing pp %ld:\n", reinterpret_cast<int64_t>(this));
StackMap
::
Record
::
Location
frame_info_location
=
r
->
locations
[
cur_arg
];
cur_arg
++
;
// We could allow the frame_info to exist in a different location for each callsite,
// but in reality it will always live at a fixed stack offset.
if
(
map
->
frameInfoFound
())
{
assert
(
frame_info_location
==
map
->
frame_info_location
);
}
else
{
map
->
frame_info_location
=
frame_info_location
;
}
for
(
FrameVarInfo
&
frame_var
:
frame_vars
)
{
int
num_args
=
frame_var
.
type
->
numFrameArgs
();
...
...
src/codegen/runtime_hooks.cpp
View file @
1e672eb3
...
...
@@ -146,6 +146,9 @@ void initGlobalFuncs(GlobalState& g) {
g
.
llvm_excinfo_type
=
g
.
stdlib_module
->
getTypeByName
(
"struct.pyston::ExcInfo"
);
assert
(
g
.
llvm_excinfo_type
);
g
.
frame_info_type
=
g
.
stdlib_module
->
getTypeByName
(
"struct.pyston::FrameInfo"
);
assert
(
g
.
frame_info_type
);
#define GET(N) g.funcs.N = getFunc((void*)N, STRINGIFY(N))
g
.
funcs
.
printf
=
addFunc
((
void
*
)
printf
,
g
.
i8_ptr
,
true
);
...
...
src/codegen/stackmaps.h
View file @
1e672eb3
...
...
@@ -48,6 +48,8 @@ struct StackMap {
uint8_t
flags
;
uint16_t
regnum
;
int32_t
offset
;
bool
operator
==
(
const
Location
&
rhs
);
};
struct
__attribute__
((
__packed__
))
LiveOut
{
...
...
@@ -73,6 +75,10 @@ struct StackMap {
class
LocationMap
{
public:
std
::
vector
<
uint64_t
>
constants
;
StackMap
::
Record
::
Location
frame_info_location
;
bool
frameInfoFound
()
{
return
frame_info_location
.
type
!=
0
;
}
struct
LocationTable
{
struct
LocationEntry
{
uint64_t
_debug_pp_id
;
...
...
src/codegen/unwinding.cpp
View file @
1e672eb3
...
...
@@ -450,6 +450,17 @@ const LineInfo* getMostRecentLineInfo() {
return
lineInfoForFrame
(
*
frame
);
}
FrameInfo
*
getTopFrameInfo
()
{
std
::
unique_ptr
<
PythonFrameIterator
>
frame
=
getTopPythonFrame
();
if
(
frame
.
get_id
().
type
==
PythonFrameId
::
COMPILED
)
{
abort
();
}
else
if
(
frame
.
get_id
().
type
==
PythonFrameId
::
INTERPRETED
)
{
abort
();
}
else
{
abort
();
}
}
CompiledFunction
*
getTopCompiledFunction
()
{
return
getTopPythonFrame
()
->
getCF
();
}
...
...
@@ -460,13 +471,6 @@ BoxedModule* getCurrentModule() {
return
compiledFunction
->
clfunc
->
source
->
parent_module
;
}
ExecutionPoint
getExecutionPoint
()
{
auto
frame
=
getTopPythonFrame
();
auto
cf
=
frame
->
getCF
();
auto
current_stmt
=
frame
->
getCurrentStatement
();
return
ExecutionPoint
({.
cf
=
cf
,
.
current_stmt
=
current_stmt
});
}
BoxedDict
*
getLocals
(
bool
only_user_visible
)
{
for
(
PythonFrameIterator
&
frame_info
:
unwindPythonFrames
())
{
if
(
frame_info
.
getId
().
type
==
PythonFrameId
::
COMPILED
)
{
...
...
src/codegen/unwinding.h
View file @
1e672eb3
...
...
@@ -30,11 +30,9 @@ CompiledFunction* getCFForAddress(uint64_t addr);
class
BoxedDict
;
BoxedDict
*
getLocals
(
bool
only_user_visible
);
struct
ExecutionPoint
{
CompiledFunction
*
cf
;
AST_stmt
*
current_stmt
;
};
ExecutionPoint
getExecutionPoint
();
struct
FrameInfo
;
FrameInfo
*
getTopFrameInfo
();
}
#endif
src/core/types.h
View file @
1e672eb3
...
...
@@ -476,6 +476,14 @@ struct ExcInfo {
ExcInfo
(
Box
*
type
,
Box
*
value
,
Box
*
traceback
)
:
type
(
type
),
value
(
value
),
traceback
(
traceback
)
{}
bool
matches
(
BoxedClass
*
cls
)
const
;
};
struct
FrameInfo
{
// *Not the same semantics as CPython's frame->f_exc*
// In CPython, f_exc is the saved exc_info from the previous frame.
// In Pyston, exc is the frame-local value of sys.exc_info.
// - This makes frame entering+leaving faster at the expense of slower exceptions.
ExcInfo
exc
;
};
}
#endif
src/runtime/builtin_modules/builtins.cpp
View file @
1e672eb3
...
...
@@ -688,13 +688,6 @@ Box* locals() {
return
getLocals
(
true
/* filter */
);
}
Box
*
deopt
()
{
auto
locals
=
getLocals
(
false
/* filter */
);
auto
execution_point
=
getExecutionPoint
();
return
astInterpretFrom
(
execution_point
.
cf
,
execution_point
.
current_stmt
,
locals
);
}
Box
*
divmod
(
Box
*
lhs
,
Box
*
rhs
)
{
return
binopInternal
(
lhs
,
rhs
,
AST_TYPE
::
DivMod
,
false
,
NULL
);
}
...
...
@@ -1054,7 +1047,6 @@ void setupBuiltins() {
builtins_module
->
giveAttr
(
"globals"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
globals
,
UNKNOWN
,
0
,
0
,
false
,
false
)));
builtins_module
->
giveAttr
(
"locals"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
locals
,
UNKNOWN
,
0
,
0
,
false
,
false
)));
builtins_module
->
giveAttr
(
"deopt"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
deopt
,
UNKNOWN
,
0
,
0
,
false
,
false
)));
builtins_module
->
giveAttr
(
"iter"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
getiter
,
UNKNOWN
,
1
,
0
,
false
,
false
)));
...
...
src/runtime/inline/link_forcer.cpp
View file @
1e672eb3
...
...
@@ -35,13 +35,11 @@ static void forceLink(void* x) {
printf
(
"%p
\n
"
,
x
);
}
extern
"C"
void
__py_personality_v0
()
{
RELEASE_ASSERT
(
0
,
"not used"
);
}
namespace
_force
{
// Force the "FrameInfo" type to make it into the stdlib:
FrameInfo
*
_frame_info_forcer
;
#define FORCE(name) forceLink((void*)name)
void
force
()
{
FORCE
(
softspace
);
...
...
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