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
14d377b9
Commit
14d377b9
authored
Jul 10, 2014
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix a PHI-handling bug in the interpreter
parent
d5fe4b7b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
4 deletions
+30
-4
src/codegen/irgen.cpp
src/codegen/irgen.cpp
+5
-0
src/codegen/irgen/irgenerator.cpp
src/codegen/irgen/irgenerator.cpp
+1
-1
src/codegen/llvm_interpreter.cpp
src/codegen/llvm_interpreter.cpp
+24
-3
No files found.
src/codegen/irgen.cpp
View file @
14d377b9
...
...
@@ -337,13 +337,18 @@ static void emitBBs(IRGenState* irstate, const char* bb_type, GuardList& out_gua
arg_num
++
;
if
(
arg_num
<
3
)
{
from_arg
=
func_args
[
arg_num
];
assert
(
from_arg
->
getType
()
==
p
.
second
->
llvmType
());
}
else
{
ASSERT
(
func_args
.
size
()
==
4
,
"%ld"
,
func_args
.
size
());
llvm
::
Value
*
ptr
=
entry_emitter
->
getBuilder
()
->
CreateConstGEP1_32
(
func_args
[
3
],
arg_num
-
3
);
if
(
p
.
second
==
INT
)
{
ptr
=
entry_emitter
->
getBuilder
()
->
CreateBitCast
(
ptr
,
g
.
i64
->
getPointerTo
());
}
else
if
(
p
.
second
==
BOOL
)
{
ptr
=
entry_emitter
->
getBuilder
()
->
CreateBitCast
(
ptr
,
g
.
i1
->
getPointerTo
());
}
else
if
(
p
.
second
==
FLOAT
)
{
ptr
=
entry_emitter
->
getBuilder
()
->
CreateBitCast
(
ptr
,
g
.
double_
->
getPointerTo
());
}
else
{
assert
(
p
.
second
->
llvmType
()
==
g
.
llvm_value_type_ptr
);
}
from_arg
=
entry_emitter
->
getBuilder
()
->
CreateLoad
(
ptr
);
assert
(
from_arg
->
getType
()
==
p
.
second
->
llvmType
());
...
...
src/codegen/irgen/irgenerator.cpp
View file @
14d377b9
...
...
@@ -1823,7 +1823,7 @@ private:
}
else
{
llvm
::
Value
*
ptr
=
emitter
.
getBuilder
()
->
CreateConstGEP1_32
(
arg_array
,
arg_num
-
3
);
if
(
var
->
getType
()
==
INT
)
{
if
(
var
->
getType
()
==
INT
||
var
->
getType
()
==
BOOL
)
{
val
=
emitter
.
getBuilder
()
->
CreateIntToPtr
(
val
,
g
.
llvm_value_type_ptr
);
}
else
if
(
var
->
getType
()
==
FLOAT
)
{
// val = emitter.getBuilder()->CreateBitCast(val, g.llvm_value_type_ptr);
...
...
src/codegen/llvm_interpreter.cpp
View file @
14d377b9
...
...
@@ -102,6 +102,12 @@ Val fetch(llvm::Value* v, const llvm::DataLayout& dl, const SymMap& symbols) {
case
llvm
:
:
Value
::
ConstantExprVal
:
{
llvm
::
ConstantExpr
*
ce
=
llvm
::
cast
<
llvm
::
ConstantExpr
>
(
v
);
if
(
ce
->
isCast
())
{
if
(
ce
->
getOpcode
()
==
llvm
::
Instruction
::
IntToPtr
&&
ce
->
getOperand
(
0
)
->
getType
()
==
g
.
i1
)
{
// inttoptr is specified to zero-extend
Val
o
=
fetch
(
ce
->
getOperand
(
0
),
dl
,
symbols
);
return
o
.
n
&
0x1
;
}
assert
(
width
(
ce
->
getOperand
(
0
),
dl
)
==
8
&&
width
(
ce
,
dl
)
==
8
);
Val
o
=
fetch
(
ce
->
getOperand
(
0
),
dl
,
symbols
);
...
...
@@ -305,6 +311,14 @@ Box* interpretFunction(llvm::Function* f, int nargs, Box* closure, Box* arg1, Bo
llvm
::
BasicBlock
*
prevblock
=
NULL
;
llvm
::
BasicBlock
*
curblock
=
&
f
->
getEntryBlock
();
// The symbol table at the end of the previous BB
// This is important for the following case:
// %a = phi [0, %l1], [1, %l2]
// %b = phi [0, %l1], [%a, %l2]
// The reference to %a in the definition of %b resolves to the *previous* value of %a,
// not the value of %a that we just set in the phi.
SymMap
prev_symbols
;
struct
{
Box
*
exc_obj
;
int64_t
exc_selector
;
...
...
@@ -516,8 +530,12 @@ Box* interpretFunction(llvm::Function* f, int nargs, Box* closure, Box* arg1, Bo
SET
(
fetch
(
bc
->
getOperand
(
0
),
dl
,
symbols
));
continue
;
}
else
if
(
llvm
::
IntToPtrInst
*
bc
=
llvm
::
dyn_cast
<
llvm
::
IntToPtrInst
>
(
inst
))
{
assert
(
width
(
bc
->
getOperand
(
0
),
dl
)
==
8
);
SET
(
fetch
(
bc
->
getOperand
(
0
),
dl
,
symbols
));
if
(
bc
->
getOperand
(
0
)
->
getType
()
==
g
.
i1
)
{
SET
(
fetch
(
bc
->
getOperand
(
0
),
dl
,
symbols
).
n
&
0xff
);
}
else
{
assert
(
width
(
bc
->
getOperand
(
0
),
dl
)
==
8
);
SET
(
fetch
(
bc
->
getOperand
(
0
),
dl
,
symbols
));
}
continue
;
//} else if (llvm::CallInst* ci = llvm::dyn_cast<llvm::CallInst>(inst)) {
}
else
if
(
llvm
::
isa
<
llvm
::
CallInst
>
(
inst
)
||
llvm
::
isa
<
llvm
::
InvokeInst
>
(
inst
))
{
...
...
@@ -662,6 +680,7 @@ Box* interpretFunction(llvm::Function* f, int nargs, Box* closure, Box* arg1, Bo
if
(
invoke
!=
nullptr
)
{
prevblock
=
curblock
;
curblock
=
invoke
->
getNormalDest
();
prev_symbols
=
symbols
;
}
}
catch
(
Box
*
e
)
{
if
(
VERBOSITY
(
"interpreter"
)
>=
2
)
{
...
...
@@ -673,6 +692,7 @@ Box* interpretFunction(llvm::Function* f, int nargs, Box* closure, Box* arg1, Bo
prevblock
=
curblock
;
curblock
=
invoke
->
getUnwindDest
();
prev_symbols
=
symbols
;
landingpad_value
.
exc_obj
=
e
;
landingpad_value
.
exc_selector
...
...
@@ -695,7 +715,7 @@ Box* interpretFunction(llvm::Function* f, int nargs, Box* closure, Box* arg1, Bo
continue
;
}
else
if
(
llvm
::
PHINode
*
phi
=
llvm
::
dyn_cast
<
llvm
::
PHINode
>
(
inst
))
{
assert
(
prevblock
);
SET
(
fetch
(
phi
->
getIncomingValueForBlock
(
prevblock
),
dl
,
symbols
));
SET
(
fetch
(
phi
->
getIncomingValueForBlock
(
prevblock
),
dl
,
prev_
symbols
));
continue
;
}
else
if
(
llvm
::
BranchInst
*
br
=
llvm
::
dyn_cast
<
llvm
::
BranchInst
>
(
inst
))
{
prevblock
=
curblock
;
...
...
@@ -709,6 +729,7 @@ Box* interpretFunction(llvm::Function* f, int nargs, Box* closure, Box* arg1, Bo
}
else
{
curblock
=
br
->
getSuccessor
(
0
);
}
prev_symbols
=
symbols
;
// if (VERBOSITY()) {
// printf("jumped to %s\n", curblock->getName().data());
//}
...
...
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