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
d817b297
Commit
d817b297
authored
Aug 05, 2016
by
Marius Wachtler
Committed by
GitHub
Aug 05, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1317 from undingen/delete_llvm_mod
delete the llvm module after code generation
parents
fca39ba9
d8f237b3
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
37 additions
and
28 deletions
+37
-28
src/codegen/compvars.cpp
src/codegen/compvars.cpp
+3
-2
src/codegen/irgen.cpp
src/codegen/irgen.cpp
+7
-7
src/codegen/irgen.h
src/codegen/irgen.h
+3
-3
src/codegen/irgen/hooks.cpp
src/codegen/irgen/hooks.cpp
+16
-10
src/codegen/irgen/irgenerator.cpp
src/codegen/irgen/irgenerator.cpp
+3
-2
src/codegen/irgen/irgenerator.h
src/codegen/irgen/irgenerator.h
+5
-3
src/core/types.h
src/core/types.h
+0
-1
No files found.
src/codegen/compvars.cpp
View file @
d817b297
...
@@ -637,7 +637,8 @@ _call(IREmitter& emitter, const OpInfo& info, llvm::Value* func, ExceptionStyle
...
@@ -637,7 +637,8 @@ _call(IREmitter& emitter, const OpInfo& info, llvm::Value* func, ExceptionStyle
// Don't use the IRBuilder since we want to specifically put this in the entry block so it only gets called
// Don't use the IRBuilder since we want to specifically put this in the entry block so it only gets called
// once.
// once.
// TODO we could take this further and use the same alloca for all function calls?
// TODO we could take this further and use the same alloca for all function calls?
llvm
::
Instruction
*
insertion_point
=
emitter
.
currentFunction
()
->
func
->
getEntryBlock
().
getFirstInsertionPt
();
llvm
::
Instruction
*
insertion_point
=
emitter
.
getBuilder
()
->
GetInsertBlock
()
->
getParent
()
->
getEntryBlock
().
getFirstInsertionPt
();
arg_array
=
new
llvm
::
AllocaInst
(
g
.
llvm_value_type_ptr
,
n_varargs
,
"arg_scratch"
,
insertion_point
);
arg_array
=
new
llvm
::
AllocaInst
(
g
.
llvm_value_type_ptr
,
n_varargs
,
"arg_scratch"
,
insertion_point
);
for
(
int
i
=
3
;
i
<
args
.
size
();
i
++
)
{
for
(
int
i
=
3
;
i
<
args
.
size
();
i
++
)
{
...
@@ -1928,7 +1929,7 @@ public:
...
@@ -1928,7 +1929,7 @@ public:
llvm
::
FunctionType
*
ft
=
llvm
::
FunctionType
::
get
(
cf
->
spec
->
rtn_type
->
llvmType
(),
arg_types
,
false
);
llvm
::
FunctionType
*
ft
=
llvm
::
FunctionType
::
get
(
cf
->
spec
->
rtn_type
->
llvmType
(),
arg_types
,
false
);
llvm
::
Value
*
linked_function
;
llvm
::
Value
*
linked_function
;
if
(
cf
->
func
)
// for JITed functions we need to make the desination address relocatable.
if
(
cf
->
md
->
source
)
// for JITed functions we need to make the desination address relocatable.
linked_function
=
embedRelocatablePtr
(
cf
->
code
,
ft
->
getPointerTo
());
linked_function
=
embedRelocatablePtr
(
cf
->
code
,
ft
->
getPointerTo
());
else
else
linked_function
=
embedConstantPtr
(
cf
->
code
,
ft
->
getPointerTo
());
linked_function
=
embedConstantPtr
(
cf
->
code
,
ft
->
getPointerTo
());
...
...
src/codegen/irgen.cpp
View file @
d817b297
...
@@ -1023,9 +1023,11 @@ static std::string getUniqueFunctionName(std::string nameprefix, EffortLevel eff
...
@@ -1023,9 +1023,11 @@ static std::string getUniqueFunctionName(std::string nameprefix, EffortLevel eff
return
os
.
str
();
return
os
.
str
();
}
}
CompiledFunction
*
doCompile
(
FunctionMetadata
*
md
,
SourceInfo
*
source
,
ParamNames
*
param_names
,
std
::
pair
<
CompiledFunction
*
,
llvm
::
Function
*>
doCompile
(
FunctionMetadata
*
md
,
SourceInfo
*
source
,
const
OSREntryDescriptor
*
entry_descriptor
,
EffortLevel
effort
,
ParamNames
*
param_names
,
ExceptionStyle
exception_style
,
FunctionSpecialization
*
spec
,
llvm
::
StringRef
nameprefix
)
{
const
OSREntryDescriptor
*
entry_descriptor
,
EffortLevel
effort
,
ExceptionStyle
exception_style
,
FunctionSpecialization
*
spec
,
llvm
::
StringRef
nameprefix
)
{
Timer
_t
(
"in doCompile"
);
Timer
_t
(
"in doCompile"
);
Timer
_t2
;
Timer
_t2
;
long
irgen_us
=
0
;
long
irgen_us
=
0
;
...
@@ -1096,8 +1098,6 @@ CompiledFunction* doCompile(FunctionMetadata* md, SourceInfo* source, ParamNames
...
@@ -1096,8 +1098,6 @@ CompiledFunction* doCompile(FunctionMetadata* md, SourceInfo* source, ParamNames
llvm
::
Function
*
f
=
llvm
::
Function
::
Create
(
ft
,
llvm
::
Function
::
ExternalLinkage
,
name
,
g
.
cur_module
);
llvm
::
Function
*
f
=
llvm
::
Function
::
Create
(
ft
,
llvm
::
Function
::
ExternalLinkage
,
name
,
g
.
cur_module
);
cf
->
func
=
f
;
// g.func_registry.registerFunction(f, g.cur_module);
// g.func_registry.registerFunction(f, g.cur_module);
llvm
::
MDNode
*
dbg_funcinfo
=
setupDebugInfo
(
source
,
f
,
nameprefix
);
llvm
::
MDNode
*
dbg_funcinfo
=
setupDebugInfo
(
source
,
f
,
nameprefix
);
...
@@ -1138,7 +1138,7 @@ CompiledFunction* doCompile(FunctionMetadata* md, SourceInfo* source, ParamNames
...
@@ -1138,7 +1138,7 @@ CompiledFunction* doCompile(FunctionMetadata* md, SourceInfo* source, ParamNames
RefcountTracker
refcounter
;
RefcountTracker
refcounter
;
IRGenState
irstate
(
md
,
cf
,
source
,
std
::
move
(
phis
),
param_names
,
getGCBuilder
(),
dbg_funcinfo
,
&
refcounter
);
IRGenState
irstate
(
md
,
cf
,
f
,
source
,
std
::
move
(
phis
),
param_names
,
getGCBuilder
(),
dbg_funcinfo
,
&
refcounter
);
emitBBs
(
&
irstate
,
types
,
entry_descriptor
,
blocks
);
emitBBs
(
&
irstate
,
types
,
entry_descriptor
,
blocks
);
assert
(
!
llvm
::
verifyFunction
(
*
f
,
&
llvm
::
errs
()));
assert
(
!
llvm
::
verifyFunction
(
*
f
,
&
llvm
::
errs
()));
...
@@ -1187,7 +1187,7 @@ CompiledFunction* doCompile(FunctionMetadata* md, SourceInfo* source, ParamNames
...
@@ -1187,7 +1187,7 @@ CompiledFunction* doCompile(FunctionMetadata* md, SourceInfo* source, ParamNames
g
.
cur_module
=
NULL
;
g
.
cur_module
=
NULL
;
return
cf
;
return
std
::
make_pair
(
cf
,
f
)
;
}
}
...
...
src/codegen/irgen.h
View file @
d817b297
...
@@ -137,9 +137,9 @@ extern const std::string PASSED_GENERATOR_NAME;
...
@@ -137,9 +137,9 @@ extern const std::string PASSED_GENERATOR_NAME;
InternedString
getIsDefinedName
(
InternedString
name
,
InternedStringPool
&
interned_strings
);
InternedString
getIsDefinedName
(
InternedString
name
,
InternedStringPool
&
interned_strings
);
bool
isIsDefinedName
(
llvm
::
StringRef
name
);
bool
isIsDefinedName
(
llvm
::
StringRef
name
);
CompiledFunction
*
doCompile
(
FunctionMetadata
*
md
,
SourceInfo
*
source
,
ParamNames
*
param_names
,
std
::
pair
<
CompiledFunction
*
,
llvm
::
Function
*>
const
OSREntryDescriptor
*
entry_descriptor
,
EffortLevel
effort
,
doCompile
(
FunctionMetadata
*
md
,
SourceInfo
*
source
,
ParamNames
*
param_names
,
const
OSREntryDescriptor
*
entry_descriptor
,
ExceptionStyle
exception_style
,
FunctionSpecialization
*
spec
,
llvm
::
StringRef
nameprefix
);
EffortLevel
effort
,
ExceptionStyle
exception_style
,
FunctionSpecialization
*
spec
,
llvm
::
StringRef
nameprefix
);
// A common pattern is to branch based off whether a variable is defined but only if it is
// A common pattern is to branch based off whether a variable is defined but only if it is
// potentially-undefined. If it is potentially-undefined, we have to generate control-flow
// potentially-undefined. If it is potentially-undefined, we have to generate control-flow
...
...
src/codegen/irgen/hooks.cpp
View file @
d817b297
...
@@ -157,23 +157,25 @@ LivenessAnalysis* SourceInfo::getLiveness() {
...
@@ -157,23 +157,25 @@ LivenessAnalysis* SourceInfo::getLiveness() {
return
liveness_info
.
get
();
return
liveness_info
.
get
();
}
}
static
void
compileIR
(
CompiledFunction
*
cf
,
EffortLevel
effort
)
{
static
void
compileIR
(
CompiledFunction
*
cf
,
llvm
::
Function
*
func
,
EffortLevel
effort
)
{
assert
(
cf
);
assert
(
cf
);
assert
(
cf
->
func
);
assert
(
func
);
void
*
compiled
=
NULL
;
void
*
compiled
=
NULL
;
cf
->
code
=
NULL
;
cf
->
code
=
NULL
;
{
{
Timer
_t
(
"to jit the IR"
);
Timer
_t
(
"to jit the IR"
);
llvm
::
Module
*
module
=
func
->
getParent
();
#if LLVMREV < 215967
#if LLVMREV < 215967
g
.
engine
->
addModule
(
cf
->
func
->
getParent
()
);
g
.
engine
->
addModule
(
module
);
#else
#else
g
.
engine
->
addModule
(
std
::
unique_ptr
<
llvm
::
Module
>
(
cf
->
func
->
getParent
()
));
g
.
engine
->
addModule
(
std
::
unique_ptr
<
llvm
::
Module
>
(
module
));
#endif
#endif
g
.
cur_cf
=
cf
;
g
.
cur_cf
=
cf
;
void
*
compiled
=
(
void
*
)
g
.
engine
->
getFunctionAddress
(
cf
->
func
->
getName
());
void
*
compiled
=
(
void
*
)
g
.
engine
->
getFunctionAddress
(
func
->
getName
());
g
.
cur_cf
=
NULL
;
g
.
cur_cf
=
NULL
;
assert
(
compiled
);
assert
(
compiled
);
ASSERT
(
compiled
==
cf
->
code
,
"cf->code should have gotten filled in"
);
ASSERT
(
compiled
==
cf
->
code
,
"cf->code should have gotten filled in"
);
...
@@ -185,9 +187,12 @@ static void compileIR(CompiledFunction* cf, EffortLevel effort) {
...
@@ -185,9 +187,12 @@ static void compileIR(CompiledFunction* cf, EffortLevel effort) {
num_jits
.
log
();
num_jits
.
log
();
if
(
VERBOSITY
()
>=
1
&&
us
>
100000
)
{
if
(
VERBOSITY
()
>=
1
&&
us
>
100000
)
{
printf
(
"Took %.1fs to compile %s
\n
"
,
us
*
0.000001
,
cf
->
func
->
getName
().
data
());
printf
(
"Took %.1fs to compile %s
\n
"
,
us
*
0.000001
,
func
->
getName
().
data
());
printf
(
"Has %ld basic blocks
\n
"
,
cf
->
func
->
getBasicBlockList
().
size
());
printf
(
"Has %ld basic blocks
\n
"
,
func
->
getBasicBlockList
().
size
());
}
}
g
.
engine
->
removeModule
(
module
);
delete
module
;
}
}
if
(
VERBOSITY
(
"irgen"
)
>=
2
)
{
if
(
VERBOSITY
(
"irgen"
)
>=
2
)
{
...
@@ -275,9 +280,11 @@ CompiledFunction* compileFunction(FunctionMetadata* f, FunctionSpecialization* s
...
@@ -275,9 +280,11 @@ CompiledFunction* compileFunction(FunctionMetadata* f, FunctionSpecialization* s
}
}
CompiledFunction
*
cf
CompiledFunction
*
cf
=
NULL
;
llvm
::
Function
*
func
=
NULL
;
std
::
tie
(
cf
,
func
)
=
doCompile
(
f
,
source
,
&
f
->
param_names
,
entry_descriptor
,
effort
,
exception_style
,
spec
,
name
->
s
());
=
doCompile
(
f
,
source
,
&
f
->
param_names
,
entry_descriptor
,
effort
,
exception_style
,
spec
,
name
->
s
());
compileIR
(
cf
,
effort
);
compileIR
(
cf
,
func
,
effort
);
f
->
addVersion
(
cf
);
f
->
addVersion
(
cf
);
...
@@ -684,7 +691,6 @@ std::unordered_set<CompiledFunction*> all_compiled_functions;
...
@@ -684,7 +691,6 @@ std::unordered_set<CompiledFunction*> all_compiled_functions;
CompiledFunction
::
CompiledFunction
(
FunctionMetadata
*
md
,
FunctionSpecialization
*
spec
,
void
*
code
,
EffortLevel
effort
,
CompiledFunction
::
CompiledFunction
(
FunctionMetadata
*
md
,
FunctionSpecialization
*
spec
,
void
*
code
,
EffortLevel
effort
,
ExceptionStyle
exception_style
,
const
OSREntryDescriptor
*
entry_descriptor
)
ExceptionStyle
exception_style
,
const
OSREntryDescriptor
*
entry_descriptor
)
:
md
(
md
),
:
md
(
md
),
func
(
NULL
),
effort
(
effort
),
effort
(
effort
),
exception_style
(
exception_style
),
exception_style
(
exception_style
),
spec
(
spec
),
spec
(
spec
),
...
...
src/codegen/irgen/irgenerator.cpp
View file @
d817b297
...
@@ -44,11 +44,12 @@ extern "C" void dumpLLVM(void* _v) {
...
@@ -44,11 +44,12 @@ extern "C" void dumpLLVM(void* _v) {
v
->
dump
();
v
->
dump
();
}
}
IRGenState
::
IRGenState
(
FunctionMetadata
*
md
,
CompiledFunction
*
cf
,
SourceInfo
*
source_info
,
IRGenState
::
IRGenState
(
FunctionMetadata
*
md
,
CompiledFunction
*
cf
,
llvm
::
Function
*
func
,
SourceInfo
*
source_info
,
std
::
unique_ptr
<
PhiAnalysis
>
phis
,
ParamNames
*
param_names
,
GCBuilder
*
gc
,
std
::
unique_ptr
<
PhiAnalysis
>
phis
,
ParamNames
*
param_names
,
GCBuilder
*
gc
,
llvm
::
MDNode
*
func_dbg_info
,
RefcountTracker
*
refcount_tracker
)
llvm
::
MDNode
*
func_dbg_info
,
RefcountTracker
*
refcount_tracker
)
:
md
(
md
),
:
md
(
md
),
cf
(
cf
),
cf
(
cf
),
func
(
func
),
source_info
(
source_info
),
source_info
(
source_info
),
phis
(
std
::
move
(
phis
)),
phis
(
std
::
move
(
phis
)),
param_names
(
param_names
),
param_names
(
param_names
),
...
@@ -61,7 +62,7 @@ IRGenState::IRGenState(FunctionMetadata* md, CompiledFunction* cf, SourceInfo* s
...
@@ -61,7 +62,7 @@ IRGenState::IRGenState(FunctionMetadata* md, CompiledFunction* cf, SourceInfo* s
vregs
(
NULL
),
vregs
(
NULL
),
stmt
(
NULL
),
stmt
(
NULL
),
scratch_size
(
0
)
{
scratch_size
(
0
)
{
assert
(
cf
->
func
);
assert
(
func
);
assert
(
cf
->
md
->
source
.
get
()
==
source_info
);
// I guess this is duplicate now
assert
(
cf
->
md
->
source
.
get
()
==
source_info
);
// I guess this is duplicate now
}
}
...
...
src/codegen/irgen/irgenerator.h
View file @
d817b297
...
@@ -63,6 +63,7 @@ private:
...
@@ -63,6 +63,7 @@ private:
// to md at the end of irgen.
// to md at the end of irgen.
FunctionMetadata
*
md
;
FunctionMetadata
*
md
;
CompiledFunction
*
cf
;
CompiledFunction
*
cf
;
llvm
::
Function
*
func
;
SourceInfo
*
source_info
;
SourceInfo
*
source_info
;
std
::
unique_ptr
<
PhiAnalysis
>
phis
;
std
::
unique_ptr
<
PhiAnalysis
>
phis
;
ParamNames
*
param_names
;
ParamNames
*
param_names
;
...
@@ -82,8 +83,9 @@ private:
...
@@ -82,8 +83,9 @@ private:
int
scratch_size
;
int
scratch_size
;
public:
public:
IRGenState
(
FunctionMetadata
*
md
,
CompiledFunction
*
cf
,
SourceInfo
*
source_info
,
std
::
unique_ptr
<
PhiAnalysis
>
phis
,
IRGenState
(
FunctionMetadata
*
md
,
CompiledFunction
*
cf
,
llvm
::
Function
*
func
,
SourceInfo
*
source_info
,
ParamNames
*
param_names
,
GCBuilder
*
gc
,
llvm
::
MDNode
*
func_dbg_info
,
RefcountTracker
*
refcount_tracker
);
std
::
unique_ptr
<
PhiAnalysis
>
phis
,
ParamNames
*
param_names
,
GCBuilder
*
gc
,
llvm
::
MDNode
*
func_dbg_info
,
RefcountTracker
*
refcount_tracker
);
~
IRGenState
();
~
IRGenState
();
CFG
*
getCFG
()
{
return
getSourceInfo
()
->
cfg
;
}
CFG
*
getCFG
()
{
return
getSourceInfo
()
->
cfg
;
}
...
@@ -93,7 +95,7 @@ public:
...
@@ -93,7 +95,7 @@ public:
ExceptionStyle
getExceptionStyle
()
{
return
cf
->
exception_style
;
}
ExceptionStyle
getExceptionStyle
()
{
return
cf
->
exception_style
;
}
llvm
::
Function
*
getLLVMFunction
()
{
return
cf
->
func
;
}
llvm
::
Function
*
getLLVMFunction
()
{
return
func
;
}
EffortLevel
getEffortLevel
()
{
return
cf
->
effort
;
}
EffortLevel
getEffortLevel
()
{
return
cf
->
effort
;
}
...
...
src/core/types.h
View file @
d817b297
...
@@ -335,7 +335,6 @@ struct CompiledFunction {
...
@@ -335,7 +335,6 @@ struct CompiledFunction {
private:
private:
public:
public:
FunctionMetadata
*
md
;
FunctionMetadata
*
md
;
llvm
::
Function
*
func
;
// the llvm IR object
// Some compilation settings:
// Some compilation settings:
EffortLevel
effort
;
EffortLevel
effort
;
...
...
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