Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Q
QueryR
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Julien Lopez
QueryR
Commits
112a839d
Commit
112a839d
authored
9 years ago
by
Lukas Stadler
Browse files
Options
Downloads
Patches
Plain Diff
simplify AccessArgumentNode
parent
b379fa4d
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/AccessArgumentNode.java
+53
-50
53 additions, 50 deletions
...com/oracle/truffle/r/nodes/access/AccessArgumentNode.java
with
53 additions
and
50 deletions
com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/AccessArgumentNode.java
+
53
−
50
View file @
112a839d
...
...
@@ -26,9 +26,9 @@ import static com.oracle.truffle.r.nodes.function.opt.EagerEvalHelper.*;
import
com.oracle.truffle.api.*
;
import
com.oracle.truffle.api.CompilerDirectives.CompilationFinal
;
import
com.oracle.truffle.api.dsl.*
;
import
com.oracle.truffle.api.frame.*
;
import
com.oracle.truffle.api.nodes.*
;
import
com.oracle.truffle.api.utilities.*
;
import
com.oracle.truffle.r.nodes.*
;
import
com.oracle.truffle.r.nodes.access.variables.*
;
import
com.oracle.truffle.r.nodes.builtin.*
;
...
...
@@ -42,12 +42,13 @@ import com.oracle.truffle.r.runtime.data.RPromise.RPromiseFactory;
import
com.oracle.truffle.r.runtime.env.*
;
/**
* This {@link RNode} returns a function's argument specified by its formal index
(
*
{@link #getIndex()}). It is used to
populate a function's new frame right after the actual
*
function call and before the function's
actual body is executed.
* This {@link RNode} returns a function's argument specified by its formal index
. It is used to
* populate a function's new frame right after the actual
function call and before the function's
* actual body is executed.
*/
@NodeChild
(
value
=
"readArgNode"
,
type
=
ReadArgumentNode
.
class
)
public
abstract
class
AccessArgumentNode
extends
RNode
{
public
final
class
AccessArgumentNode
extends
RNode
{
@Child
private
ReadArgumentNode
readArgNode
;
@Child
private
PromiseHelperNode
promiseHelper
;
...
...
@@ -56,7 +57,9 @@ public abstract class AccessArgumentNode extends RNode {
*/
private
final
int
index
;
public
abstract
ReadArgumentNode
getReadArgNode
();
public
ReadArgumentNode
getReadArgNode
()
{
return
readArgNode
;
}
/**
* Used to cache {@link RPromise} evaluations.
...
...
@@ -68,23 +71,22 @@ public abstract class AccessArgumentNode extends RNode {
@CompilationFinal
private
boolean
deoptimized
;
@CompilationFinal
private
boolean
defaultArgCanBeOptimized
=
EagerEvalHelper
.
optConsts
()
||
EagerEvalHelper
.
optDefault
()
||
EagerEvalHelper
.
optExprs
();
private
final
ConditionProfile
isMissingProfile
=
ConditionProfile
.
createBinaryProfile
();
protected
AccessArgumentNode
(
int
index
)
{
this
.
index
=
index
;
this
.
readArgNode
=
new
ReadArgumentNode
(
index
);
}
public
void
setFormals
(
FormalArguments
formals
)
{
CompilerAsserts
.
neverPartOfCompilation
();
assert
this
.
formals
==
null
;
this
.
formals
=
formals
;
hasDefaultArg
=
formals
.
hasDefaultArgumentAt
(
getI
ndex
()
);
hasDefaultArg
=
formals
.
hasDefaultArgumentAt
(
i
ndex
);
}
/**
* @param index {@link #getIndex()}
* @return A fresh {@link AccessArgumentNode} for the given index
*/
public
static
AccessArgumentNode
create
(
int
index
)
{
return
AccessArgumentNode
Gen
.
create
(
index
,
new
ReadArgumentNode
(
index
)
);
return
new
AccessArgumentNode
(
index
);
}
@Override
...
...
@@ -92,34 +94,44 @@ public abstract class AccessArgumentNode extends RNode {
return
this
;
}
@Specialization
(
guards
=
{
"hasDefaultArg()"
})
protected
Object
doArgumentDefaultArg
(
VirtualFrame
frame
,
@SuppressWarnings
(
"unused"
)
RMissing
argMissing
)
{
assert
!(
getRootNode
()
instanceof
RBuiltinRootNode
)
:
getRootNode
();
Object
result
;
if
(
canBeOptimized
())
{
@Override
public
Object
execute
(
VirtualFrame
frame
)
{
return
doArgument
(
frame
,
readArgNode
.
execute
(
frame
));
}
@Override
public
NodeCost
getCost
()
{
return
hasDefaultArg
?
NodeCost
.
MONOMORPHIC
:
NodeCost
.
NONE
;
}
protected
Object
doArgument
(
VirtualFrame
frame
,
Object
arg
)
{
if
(
hasDefaultArg
&&
isMissingProfile
.
profile
(
arg
==
RMissing
.
instance
))
{
assert
!(
getRootNode
()
instanceof
RBuiltinRootNode
)
:
getRootNode
();
// Insert default value
checkPromiseFactory
();
if
(
checkInsertOptDefaultArg
())
{
result
=
optDefaultArgNode
.
execute
(
frame
);
// Update RArguments for S3 dispatch to work
RArguments
.
setArgument
(
frame
,
index
,
result
);
return
result
;
}
else
{
// Default arg cannot be optimized: Rewrite to default and assure that we don't take
// this path again
CompilerDirectives
.
transferToInterpreterAndInvalidate
();
defaultArgCanBeOptimized
=
false
;
Object
result
;
if
(
canBeOptimized
())
{
if
(
checkInsertOptDefaultArg
())
{
result
=
optDefaultArgNode
.
execute
(
frame
);
// Update RArguments for S3 dispatch to work
RArguments
.
setArgument
(
frame
,
index
,
result
);
return
result
;
}
else
{
/*
* Default arg cannot be optimized: Rewrite to default and assure that we don't
* take this path again
*/
CompilerDirectives
.
transferToInterpreterAndInvalidate
();
defaultArgCanBeOptimized
=
false
;
}
}
// Insert default value
result
=
factory
.
createPromise
(
frame
.
materialize
());
// Update RArguments for S3 dispatch to work
RArguments
.
setArgument
(
frame
,
index
,
result
);
return
result
;
}
// Insert default value
checkPromiseFactory
();
result
=
factory
.
createPromise
(
frame
.
materialize
());
RArguments
.
setArgument
(
frame
,
index
,
result
);
// Update RArguments for S3 dispatch to work
return
result
;
}
protected
boolean
hasDefaultArg
()
{
return
hasDefaultArg
;
return
arg
;
}
private
boolean
canBeOptimized
()
{
...
...
@@ -129,14 +141,14 @@ public abstract class AccessArgumentNode extends RNode {
private
void
checkPromiseFactory
()
{
if
(
factory
==
null
)
{
CompilerDirectives
.
transferToInterpreterAndInvalidate
();
Closure
defaultClosure
=
formals
.
getOrCreateClosure
(
formals
.
getDefaultArgumentAt
(
getI
ndex
()
));
Closure
defaultClosure
=
formals
.
getOrCreateClosure
(
formals
.
getDefaultArgumentAt
(
i
ndex
));
factory
=
RPromiseFactory
.
create
(
PromiseType
.
ARG_DEFAULT
,
defaultClosure
);
}
}
private
boolean
checkInsertOptDefaultArg
()
{
if
(
optDefaultArgNode
==
null
)
{
RNode
defaultArg
=
formals
.
getDefaultArgumentAt
(
getI
ndex
()
);
RNode
defaultArg
=
formals
.
getDefaultArgumentAt
(
i
ndex
);
RNode
arg
=
EagerEvalHelper
.
unfold
(
defaultArg
);
CompilerDirectives
.
transferToInterpreterAndInvalidate
();
...
...
@@ -157,15 +169,6 @@ public abstract class AccessArgumentNode extends RNode {
return
true
;
}
@Fallback
protected
Object
doArgument
(
Object
obj
)
{
return
obj
;
}
public
int
getIndex
()
{
return
index
;
}
protected
final
class
OptVariableDefaultPromiseNode
extends
OptVariablePromiseBaseNode
{
public
OptVariableDefaultPromiseNode
(
RPromiseFactory
factory
,
ReadVariableNode
rvn
)
{
...
...
@@ -187,12 +190,12 @@ public abstract class AccessArgumentNode extends RNode {
protected
Object
rewriteToAndExecuteFallback
(
VirtualFrame
frame
)
{
CompilerDirectives
.
transferToInterpreterAndInvalidate
();
deoptimized
=
true
;
return
doArgument
DefaultArg
(
frame
,
RMissing
.
instance
);
return
doArgument
(
frame
,
RMissing
.
instance
);
}
@Override
protected
Object
executeFallback
(
VirtualFrame
frame
)
{
return
doArgument
DefaultArg
(
frame
,
RMissing
.
instance
);
return
doArgument
(
frame
,
RMissing
.
instance
);
}
@Override
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment