Skip to content

Commit bafddcb

Browse files
committed
[GR-22742] Provide next and nextLoopCondition in VectorDataAccess
1 parent 2240154 commit bafddcb

31 files changed

+312
-92
lines changed

com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/AnyNA.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ protected byte anyNACached(RAbstractAtomicVector x, @SuppressWarnings("unused")
123123
// shortcut when we know there's no NAs
124124
if (!xDataLib.isComplete(xData)) {
125125
SeqIterator iter = xDataLib.iterator(xData);
126-
while (xDataLib.next(xData, iter)) {
126+
while (xDataLib.nextLoopCondition(xData, iter)) {
127127
if (xDataLib.isNextNA(xData, iter)) {
128128
return RRuntime.LOGICAL_TRUE;
129129
}
@@ -134,15 +134,15 @@ protected byte anyNACached(RAbstractAtomicVector x, @SuppressWarnings("unused")
134134
return RRuntime.LOGICAL_FALSE;
135135
case Double:
136136
SeqIterator iterDouble = xDataLib.iterator(xData);
137-
while (xDataLib.next(xData, iterDouble)) {
137+
while (xDataLib.nextLoopCondition(xData, iterDouble)) {
138138
if (nanCheck.checkNAorNaN(xDataLib.getNextDouble(xData, iterDouble))) {
139139
return RRuntime.LOGICAL_TRUE;
140140
}
141141
}
142142
break;
143143
case Complex:
144144
SeqIterator iterCmplx = xDataLib.iterator(xData);
145-
while (xDataLib.next(xData, iterCmplx)) {
145+
while (xDataLib.nextLoopCondition(xData, iterCmplx)) {
146146
RComplex val = xDataLib.getNextComplex(xData, iterCmplx);
147147
if (nanCheck.checkNAorNaN(val.getRealPart()) || nanCheck.checkNAorNaN(val.getImaginaryPart())) {
148148
return RRuntime.LOGICAL_TRUE;

com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/CumSum.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ protected RIntVector cumsumInt(RIntVector x,
113113
int[] array = new int[iter.getLength()];
114114
int prev = 0;
115115
WarningInfo warningInfo = new WarningInfo();
116-
while (xDataLib.next(xData, iter)) {
116+
while (xDataLib.nextLoopCondition(xData, iter)) {
117117
int value = xDataLib.getNextInt(xData, iter);
118118
if (naCheck.check(value)) {
119119
Arrays.fill(array, iter.getIndex(), array.length, RRuntime.INT_NA);
@@ -143,7 +143,7 @@ protected RDoubleVector cumsumDouble(RDoubleVector x,
143143
SeqIterator iter = xDataLib.iterator(xData);
144144
double[] array = new double[iter.getLength()];
145145
double prev = 0;
146-
while (xDataLib.next(xData, iter)) {
146+
while (xDataLib.nextLoopCondition(xData, iter)) {
147147
double value = xDataLib.getNextDouble(xData, iter);
148148
if (naCheck.check(value)) {
149149
Arrays.fill(array, iter.getIndex(), array.length, RRuntime.DOUBLE_NA);
@@ -168,8 +168,8 @@ protected RComplexVector cumsumComplex(RAbstractComplexVector x,
168168
naCheck.enable(xDataLib, xData);
169169
SeqIterator iter = xDataLib.iterator(xData);
170170
double[] array = new double[iter.getLength() * 2];
171-
RComplex prev = RDataFactory.createComplex(0, 0);
172-
while (xDataLib.next(xData, iter)) {
171+
RComplex prev = RComplex.valueOf(0, 0);
172+
while (xDataLib.nextLoopCondition(xData, iter)) {
173173
RComplex curr = xDataLib.getNextComplex(xData, iter);
174174
double real = curr.getRealPart();
175175
double imag = curr.getImaginaryPart();

com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Repeat.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ private RAbstractVector handleTimes(VectorDataLibrary xDataLib, Object xData, RA
310310
// iterate once over the times vector to determine result vector size
311311
int resultLength = 0;
312312
SeqIterator it = timesDataLib.iterator(timesData);
313-
while (timesDataLib.next(timesData, it)) {
313+
while (timesDataLib.nextLoopCondition(timesData, it)) {
314314
int t = timesDataLib.getNextInt(timesData, it);
315315
if (t < 0) {
316316
throw error(RError.Message.INVALID_ARGUMENT, "times");

com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Round.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ protected RDoubleVector round(RLogicalVector x, @SuppressWarnings("unused") doub
101101
Object xData = x.getData();
102102
VectorDataLibrary.SeqIterator xIt = xDataLib.iterator(xData);
103103
NACheck xnaCheck = xDataLib.getNACheck(xData);
104-
while (xDataLib.next(xData, xIt)) {
104+
while (xDataLib.nextLoopCondition(xData, xIt)) {
105105
byte val = xDataLib.getNextLogical(xData, xIt);
106106
result[xIt.getIndex()] = xnaCheck.check(val) ? RRuntime.DOUBLE_NA : val;
107107
}
@@ -116,7 +116,7 @@ protected RDoubleVector round(RIntVector x, @SuppressWarnings("unused") double d
116116
double[] data = new double[x.getLength()];
117117
Object xData = x.getData();
118118
VectorDataLibrary.SeqIterator xIt = xDataLib.iterator(xData);
119-
while (xDataLib.next(xData, xIt)) {
119+
while (xDataLib.nextLoopCondition(xData, xIt)) {
120120
// getNextDouble takes care of the int NA -> double NA conversion
121121
data[xIt.getIndex()] = xDataLib.getNextDouble(xData, xIt);
122122
}
@@ -133,7 +133,7 @@ protected RDoubleVector round(RDoubleVector x, double digits,
133133
VectorDataLibrary.SeqIterator xIt = xDataLib.iterator(xData);
134134
NACheck xnaCheck = xDataLib.getNACheck(xData);
135135
int digitsInt = (int) Math.round(digits);
136-
while (xDataLib.next(xData, xIt)) {
136+
while (xDataLib.nextLoopCondition(xData, xIt)) {
137137
double value = xDataLib.getNextDouble(xData, xIt);
138138
result[xIt.getIndex()] = xnaCheck.check(value) ? RRuntime.DOUBLE_NA : zeroDigitProfile.profile(digitsInt == 0) ? roundOp.op(value) : roundOp.opd(value, digitsInt);
139139
}

com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/vector/PositionCheckSubsetNode.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ protected RAbstractVector doInteger(PositionProfile profile, int dimensionLength
248248
int maxOutOfBoundsIndex = 0;
249249
Object positionsData = position.getData();
250250
SeqIterator it = positionLibrary.iterator(positionsData);
251-
while (positionLibrary.next(positionsData, it)) {
251+
while (positionLibrary.nextLoopCondition(positionsData, it)) {
252252
int positionValue = positionLibrary.getNextInt(positionsData, it);
253253
if (positionValue > 0) {
254254
seenPositiveProfile.enter();
@@ -319,7 +319,7 @@ private RAbstractVector eliminateZerosAndOutOfBounds(VectorDataLibrary posDataLi
319319
int newPositionIndex = 0;
320320
Object posData = position.getData();
321321
SeqIterator posIt = posDataLibrary.iterator(posData);
322-
while (posDataLibrary.next(posData, posIt)) {
322+
while (posDataLibrary.nextLoopCondition(posData, posIt)) {
323323
int positionValue = posDataLibrary.getNextInt(posData, posIt);
324324
if (zeroCount > 0 && positionValue == 0) {
325325
continue;
@@ -338,7 +338,7 @@ private static RAbstractVector transformNegative(PositionProfile statistics, int
338338
int allPositionsNum = dimLength;
339339
Object posData = position.getData();
340340
SeqIterator posIt = posDataLibrary.iterator(posData);
341-
while (posDataLibrary.next(posData, posIt)) {
341+
while (posDataLibrary.nextLoopCondition(posData, posIt)) {
342342
int pos = -posDataLibrary.getNextInt(posData, posIt);
343343
if (hasZeros && pos == 0) {
344344
continue;

com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/vector/WriteIndexedVectorNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ protected int doIntegerPosition(RandomAccessWriteIterator leftIter, VectorDataLi
377377
int rightIndex = rightBase;
378378

379379
SeqIterator it = positionLibrary.iterator(positionData);
380-
while (positionLibrary.next(positionData, it)) {
380+
while (positionLibrary.nextLoopCondition(positionData, it)) {
381381
int positionValue = positionLibrary.getNextInt(positionData, it);
382382
boolean isNA = getPositionNACheck().check(positionValue);
383383
if (isNA) {

com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/primitive/BinaryMapNode.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ protected void doScalarVector(BinaryMapFunctionNode node, @SuppressWarnings("unu
502502
Object leftData, VectorDataLibrary leftLib, SeqIterator leftIter,
503503
Object rightData, VectorDataLibrary rightLib, SeqIterator rightIter) {
504504
leftLib.next(leftData, leftIter);
505-
while (rightLib.next(rightData, rightIter)) {
505+
while (rightLib.nextLoopCondition(rightData, rightIter)) {
506506
resultLib.next(resultData, resultIter);
507507
indexedAction.perform(node, resultData, resultLib, resultIter, leftData, leftLib, leftIter, rightData, rightLib, rightIter);
508508
}
@@ -514,7 +514,7 @@ protected void doVectorScalar(BinaryMapFunctionNode node, @SuppressWarnings("unu
514514
Object leftData, VectorDataLibrary leftLib, SeqIterator leftIter,
515515
Object rightData, VectorDataLibrary rightLib, SeqIterator rightIter) {
516516
rightLib.next(rightData, rightIter);
517-
while (leftLib.next(leftData, leftIter)) {
517+
while (leftLib.nextLoopCondition(leftData, leftIter)) {
518518
resultLib.next(resultData, resultIter);
519519
indexedAction.perform(node, resultData, resultLib, resultIter, leftData, leftLib, leftIter, rightData, rightLib, rightIter);
520520
}
@@ -525,7 +525,7 @@ protected void doSameLength(BinaryMapFunctionNode node, @SuppressWarnings("unuse
525525
Object resultData, VectorDataLibrary resultLib, SeqWriteIterator resultIter,
526526
Object leftData, VectorDataLibrary leftLib, SeqIterator leftIter,
527527
Object rightData, VectorDataLibrary rightLib, SeqIterator rightIter) {
528-
while (leftLib.next(leftData, leftIter)) {
528+
while (leftLib.nextLoopCondition(leftData, leftIter)) {
529529
rightLib.next(rightData, rightIter);
530530
resultLib.next(resultData, resultIter);
531531
indexedAction.perform(node, resultData, resultLib, resultIter, leftData, leftLib, leftIter, rightData, rightLib, rightIter);
@@ -550,12 +550,12 @@ protected void doMultiplesLeft(BinaryMapFunctionNode node, int leftLength, int r
550550
rightIter.reset();
551551
if (smallRemainderProfile.profile((leftLength - leftIter.getIndex() - 1) >= rightLength)) {
552552
// we need at least rightLength more elements
553-
while (rightLib.next(rightData, rightIter) && leftLib.next(leftData, leftIter)) {
553+
while (rightLib.nextLoopCondition(rightData, rightIter) && leftLib.nextLoopCondition(leftData, leftIter)) {
554554
resultLib.next(resultData, resultIter);
555555
indexedAction.perform(node, resultData, resultLib, resultIter, leftData, leftLib, leftIter, rightData, rightLib, rightIter);
556556
}
557557
} else {
558-
while (rightLib.next(rightData, rightIter) && leftLib.next(leftData, leftIter)) {
558+
while (rightLib.nextLoopCondition(rightData, rightIter) && leftLib.nextLoopCondition(leftData, leftIter)) {
559559
resultLib.next(resultData, resultIter);
560560
indexedAction.perform(node, resultData, resultLib, resultIter, leftData, leftLib, leftIter, rightData, rightLib, rightIter);
561561
}
@@ -578,12 +578,12 @@ protected void doMultiplesRight(BinaryMapFunctionNode node, int leftLength, int
578578
leftIter.reset();
579579
if (smallRemainderProfile.profile((rightLength - rightIter.getIndex() - 1) >= leftLength)) {
580580
// we need at least leftLength more elements
581-
while (leftLib.next(leftData, leftIter) && rightLib.next(rightData, rightIter)) {
581+
while (leftLib.nextLoopCondition(leftData, leftIter) && rightLib.nextLoopCondition(rightData, rightIter)) {
582582
resultLib.next(resultData, resultIter);
583583
indexedAction.perform(node, resultData, resultLib, resultIter, leftData, leftLib, leftIter, rightData, rightLib, rightIter);
584584
}
585585
} else {
586-
while (leftLib.next(leftData, leftIter) && rightLib.next(rightData, rightIter)) {
586+
while (leftLib.nextLoopCondition(leftData, leftIter) && rightLib.nextLoopCondition(rightData, rightIter)) {
587587
resultLib.next(resultData, resultIter);
588588
indexedAction.perform(node, resultData, resultLib, resultIter, leftData, leftLib, leftIter, rightData, rightLib, rightIter);
589589
}

com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/DSLConfig.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ public static int getTypedVectorDataLibraryCacheSize() {
7676
return getCacheSize(3);
7777
}
7878

79+
public static int getGenericDataLibraryCacheSize() {
80+
return getCacheSize(5);
81+
}
82+
7983
/**
8084
* This method should be used to set any {@link InteropLibrary} cache size that can be
8185
* configured, i.e. it does not matter how large the cache is and it can even be zero. If used,

com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RDoubleArrayVectorData.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import com.oracle.truffle.api.library.ExportLibrary;
3131
import com.oracle.truffle.api.library.ExportMessage;
3232
import com.oracle.truffle.api.profiles.BranchProfile;
33+
import com.oracle.truffle.api.profiles.ConditionProfile;
3334
import com.oracle.truffle.api.profiles.LoopConditionProfile;
3435
import com.oracle.truffle.r.runtime.RRuntime;
3536
import com.oracle.truffle.r.runtime.RType;
@@ -136,9 +137,17 @@ public SeqIterator iterator(
136137
}
137138

138139
@ExportMessage
139-
public boolean next(SeqIterator it, boolean withWrap,
140+
@SuppressWarnings("static-method")
141+
public boolean nextImpl(SeqIterator it, boolean loopCondition,
140142
@Shared("SeqItLoopProfile") @Cached("createCountingProfile()") LoopConditionProfile loopProfile) {
141-
return it.next(loopProfile, withWrap);
143+
return it.next(loopCondition, loopProfile);
144+
}
145+
146+
@ExportMessage
147+
@SuppressWarnings("static-method")
148+
public void nextWithWrap(SeqIterator it,
149+
@Cached("createBinaryProfile()") ConditionProfile wrapProfile) {
150+
it.nextWithWrap(wrapProfile);
142151
}
143152

144153
@ExportMessage

com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RDoubleForeignObjData.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
package com.oracle.truffle.r.runtime.data;
2424

2525
import com.oracle.truffle.api.dsl.Cached;
26+
import com.oracle.truffle.api.dsl.Cached.Exclusive;
2627
import com.oracle.truffle.api.dsl.Cached.Shared;
2728
import com.oracle.truffle.api.interop.InteropLibrary;
2829
import com.oracle.truffle.api.interop.InvalidArrayIndexException;
@@ -130,9 +131,17 @@ public SeqIterator iterator(@Shared("naCheck") @Cached() NACheck naCheck,
130131
}
131132

132133
@ExportMessage
133-
public boolean next(SeqIterator it, boolean withWrap,
134+
@SuppressWarnings("static-method")
135+
public boolean nextImpl(SeqIterator it, boolean loopCondition,
134136
@Shared("SeqItLoopProfile") @Cached("createCountingProfile()") LoopConditionProfile loopProfile) {
135-
return it.next(loopProfile, withWrap);
137+
return it.next(loopCondition, loopProfile);
138+
}
139+
140+
@ExportMessage
141+
@SuppressWarnings("static-method")
142+
public void nextWithWrap(SeqIterator it,
143+
@Exclusive @Cached("createBinaryProfile()") ConditionProfile wrapProfile) {
144+
it.nextWithWrap(wrapProfile);
136145
}
137146

138147
@ExportMessage

0 commit comments

Comments
 (0)