Skip to content
Snippets Groups Projects
Commit 8ad0de48 authored by stepan's avatar stepan
Browse files

UnaryArithReduceNode: use nodes for getLengt and naCheck.enable to avoid interface calls

parent 0494c211
No related branches found
No related tags found
No related merge requests found
......@@ -33,6 +33,7 @@ import com.oracle.truffle.api.interop.TruffleObject;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.profiles.ConditionProfile;
import com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef;
import com.oracle.truffle.r.nodes.control.RLengthNode;
import com.oracle.truffle.r.runtime.RError;
import com.oracle.truffle.r.runtime.RRuntime;
import com.oracle.truffle.r.runtime.data.RComplex;
......@@ -43,6 +44,7 @@ import com.oracle.truffle.r.runtime.data.RTypes;
import com.oracle.truffle.r.runtime.data.model.RAbstractDoubleVector;
import com.oracle.truffle.r.runtime.data.model.RAbstractIntVector;
import com.oracle.truffle.r.runtime.data.model.RAbstractLogicalVector;
import com.oracle.truffle.r.runtime.data.nodes.EnableNACheckNode;
import com.oracle.truffle.r.runtime.data.nodes.VectorIterator;
import com.oracle.truffle.r.runtime.interop.ForeignArray2R;
import com.oracle.truffle.r.runtime.nodes.RBaseNode;
......@@ -201,11 +203,13 @@ public abstract class UnaryArithmeticReduceNode extends RBaseNode {
@Specialization
protected Object doIntVector(RAbstractIntVector operand, boolean naRm, boolean finite,
@Cached("create()") EnableNACheckNode enableNACheckNode,
@Cached("create()") RLengthNode lengthNode,
@Cached("create()") VectorIterator.Int iterator) {
RBaseNode.reportWork(this, operand.getLength());
RBaseNode.reportWork(this, lengthNode.executeInteger(operand));
boolean profiledNaRm = naRmProfile.profile(naRm || finite);
int result = semantics.getIntStart();
na.enable(operand);
enableNACheckNode.execute(na, operand);
int opCount = 0;
Object it = iterator.init(operand);
while (iterator.hasNext(operand, it)) {
......@@ -236,14 +240,16 @@ public abstract class UnaryArithmeticReduceNode extends RBaseNode {
@Specialization
protected double doDoubleVector(RAbstractDoubleVector operand, boolean naRm, boolean finite,
@Cached("create()") EnableNACheckNode enableNACheckNode,
@Cached("create()") RLengthNode lengthNode,
@Cached("create()") VectorIterator.Double iterator,
@Cached("createBinaryProfile()") ConditionProfile finiteProfile,
@Cached("createBinaryProfile()") ConditionProfile isInfiniteProfile) {
RBaseNode.reportWork(this, operand.getLength());
RBaseNode.reportWork(this, lengthNode.executeInteger(operand));
boolean profiledNaRm = naRmProfile.profile(naRm || finite);
boolean profiledFinite = finiteProfile.profile(finite);
double result = semantics.getDoubleStart();
na.enable(operand);
enableNACheckNode.execute(na, operand);
int opCount = 0;
Object it = iterator.init(operand);
......@@ -274,11 +280,13 @@ public abstract class UnaryArithmeticReduceNode extends RBaseNode {
@Specialization
protected Object doLogicalVector(RAbstractLogicalVector operand, boolean naRm, @SuppressWarnings("unused") boolean finite,
@Cached("create()") EnableNACheckNode enableNACheckNode,
@Cached("create()") RLengthNode lengthNode,
@Cached("create()") VectorIterator.Logical iterator) {
RBaseNode.reportWork(this, operand.getLength());
RBaseNode.reportWork(this, lengthNode.executeInteger(operand));
boolean profiledNaRm = naRmProfile.profile(naRm);
int result = semantics.getIntStart();
na.enable(operand);
enableNACheckNode.execute(na, operand);
int opCount = 0;
Object it = iterator.init(operand);
......
/*
* 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.dsl.Cached;
import com.oracle.truffle.api.dsl.Fallback;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.r.runtime.data.model.RAbstractVector;
import com.oracle.truffle.r.runtime.ops.na.NACheck;
public abstract class EnableNACheckNode extends Node {
public abstract void execute(NACheck check, RAbstractVector vector);
public static EnableNACheckNode create() {
return EnableNACheckNodeGen.create();
}
@Specialization(guards = "vector.getClass() == clazz", limit = "10")
public void doEnable(NACheck check, RAbstractVector vector,
@Cached("vector.getClass()") Class<? extends RAbstractVector> clazz) {
check.enable(clazz.cast(vector));
}
@Fallback
public void doEnable(NACheck check, RAbstractVector vector) {
check.enable(vector);
}
}
......@@ -189,8 +189,10 @@ abstract class GetNextNode extends VectorIteratorNodeAdapter {
@Fallback
protected Object doGeneric(RAbstractVector vector, IteratorData<?> iter) {
// we use fallback and extra node so that we do not have to explicitly check that the vector is not
// RVector, DSL generates fallback guard that compares the class with the all RVector subclasses
// we use fallback and extra node so that we do not have to explicitly check that the vector
// is not
// RVector, DSL generates fallback guard that compares the class with the all RVector
// subclasses
// used in the specializations above, "vector instanceof RVector" would not be a leaf-check.
if (getNextGenericNode == null) {
CompilerDirectives.transferToInterpreterAndInvalidate();
......@@ -199,7 +201,7 @@ abstract class GetNextNode extends VectorIteratorNodeAdapter {
return getNextGenericNode.execute(vector, iter);
}
static abstract class GetNextGenericNode extends Node {
abstract static class GetNextGenericNode extends Node {
public abstract Object execute(RAbstractVector vector, IteratorData<?> iter);
public static GetNextGenericNode create() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment