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
4a53fb69
Commit
4a53fb69
authored
7 years ago
by
Lukas Stadler
Browse files
Options
Downloads
Patches
Plain Diff
add VectorReuse utility
parent
e2cdb905
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.runtime/src/com/oracle/truffle/r/runtime/data/nodes/VectorReuse.java
+121
-0
121 additions, 0 deletions
.../com/oracle/truffle/r/runtime/data/nodes/VectorReuse.java
with
121 additions
and
0 deletions
com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/nodes/VectorReuse.java
0 → 100644
+
121
−
0
View file @
4a53fb69
/*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package
com.oracle.truffle.r.runtime.data.nodes
;
import
com.oracle.truffle.api.CompilerDirectives
;
import
com.oracle.truffle.api.CompilerDirectives.TruffleBoundary
;
import
com.oracle.truffle.api.nodes.Node
;
import
com.oracle.truffle.r.runtime.data.RSharingAttributeStorage
;
import
com.oracle.truffle.r.runtime.data.model.RAbstractVector
;
public
final
class
VectorReuse
extends
Node
{
@Child
private
VectorAccess
access
;
private
final
boolean
isShareableClass
;
private
final
boolean
isTempOrNonShared
;
private
final
boolean
needsTemporary
;
protected
final
boolean
isGeneric
;
protected
final
Class
<?
extends
RAbstractVector
>
clazz
;
public
VectorReuse
(
RAbstractVector
vector
,
boolean
needsTemporary
,
boolean
isGeneric
)
{
this
.
isShareableClass
=
isGeneric
?
false
:
vector
instanceof
RSharingAttributeStorage
;
this
.
clazz
=
isGeneric
?
null
:
vector
.
getClass
();
this
.
needsTemporary
=
needsTemporary
;
this
.
isGeneric
=
isGeneric
;
this
.
isTempOrNonShared
=
isShareableClass
&&
isTempOrNonShared
(
vector
);
}
protected
RAbstractVector
cast
(
RAbstractVector
value
)
{
return
clazz
.
cast
(
value
);
}
public
VectorAccess
access
(
RAbstractVector
result
)
{
return
isGeneric
?
result
.
slowPathAccess
()
:
access
;
}
public
boolean
supports
(
RAbstractVector
value
)
{
assert
!
isGeneric
:
"cannot call 'supports' on generic vector reuse"
;
RSharingAttributeStorage
.
verify
(
value
);
if
(
value
.
getClass
()
!=
clazz
)
{
return
false
;
}
if
(
access
==
null
)
{
CompilerDirectives
.
transferToInterpreterAndInvalidate
();
access
=
insert
(
isTempOrNonShared
?
value
.
access
()
:
VectorAccess
.
createNew
(
value
.
getRType
()));
}
if
(!
isShareableClass
)
{
return
true
;
}
if
(
isTempOrNonShared
&&
!
access
.
supports
(
value
))
{
return
false
;
}
RSharingAttributeStorage
vector
=
(
RSharingAttributeStorage
)
cast
(
value
);
return
needsTemporary
?
vector
.
isTemporary
()
==
isTempOrNonShared
:
!
vector
.
isShared
()
==
isTempOrNonShared
;
}
@TruffleBoundary
private
static
RAbstractVector
copyVector
(
RAbstractVector
vector
)
{
return
vector
.
copy
();
}
private
boolean
isTempOrNonShared
(
RAbstractVector
vector
)
{
return
needsTemporary
?
((
RSharingAttributeStorage
)
vector
).
isTemporary
()
:
!((
RSharingAttributeStorage
)
vector
).
isShared
();
}
@SuppressWarnings
(
"unchecked"
)
public
<
T
extends
RAbstractVector
>
T
getResult
(
T
vector
)
{
RAbstractVector
result
;
if
(
isGeneric
)
{
RSharingAttributeStorage
.
verify
(
vector
);
if
(
vector
instanceof
RSharingAttributeStorage
&&
isTempOrNonShared
(
vector
))
{
result
=
vector
;
}
else
{
result
=
copyVector
(
vector
);
}
}
else
{
if
(!
isShareableClass
||
!
isTempOrNonShared
)
{
result
=
cast
(
vector
).
copy
();
}
else
{
result
=
cast
(
vector
);
}
}
return
(
T
)
result
;
}
public
static
VectorReuse
createTemporaryGeneric
()
{
return
new
VectorReuse
(
null
,
true
,
true
);
}
public
static
VectorReuse
createNonSharedGeneric
()
{
return
new
VectorReuse
(
null
,
false
,
true
);
}
public
static
VectorReuse
createTemporary
(
RAbstractVector
vector
)
{
return
new
VectorReuse
(
vector
,
true
,
false
);
}
public
static
VectorReuse
createNonShared
(
RAbstractVector
vector
)
{
return
new
VectorReuse
(
vector
,
false
,
false
);
}
}
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