Skip to content
Snippets Groups Projects
Commit f7d0de6b authored by Lukas Stadler's avatar Lukas Stadler
Browse files

some more profiles

parent f072a6df
Branches
No related tags found
No related merge requests found
......@@ -22,8 +22,8 @@
*/
package com.oracle.truffle.r.nodes.builtin.base;
import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.numericValue;
import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.complexValue;
import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.numericValue;
import static com.oracle.truffle.r.runtime.RDispatch.MATH_GROUP_GENERIC;
import static com.oracle.truffle.r.runtime.builtins.RBehavior.PURE;
import static com.oracle.truffle.r.runtime.builtins.RBuiltinKind.PRIMITIVE;
......@@ -43,13 +43,13 @@ import com.oracle.truffle.r.runtime.data.RDoubleVector;
import com.oracle.truffle.r.runtime.data.RMissing;
import com.oracle.truffle.r.runtime.data.model.RAbstractDoubleVector;
import com.oracle.truffle.r.runtime.data.model.RAbstractIntVector;
import com.oracle.truffle.r.runtime.ops.na.NACheck;
import com.oracle.truffle.r.runtime.ops.na.NAProfile;
public class LogFunctions {
@RBuiltin(name = "log", kind = PRIMITIVE, parameterNames = {"x", "base"}, dispatch = MATH_GROUP_GENERIC, behavior = PURE)
public abstract static class Log extends RBuiltinNode {
private final NACheck naCheck = NACheck.create();
private final NAProfile naProfile = NAProfile.create();
private final BranchProfile nanProfile = BranchProfile.create();
@Override
......@@ -79,7 +79,7 @@ public class LogFunctions {
for (int i = 0; i < vector.getLength(); i++) {
int inputValue = vector.getDataAt(i);
double result = RRuntime.DOUBLE_NA;
if (!RRuntime.isNA(inputValue)) {
if (!naProfile.isNA(inputValue)) {
result = logb(inputValue, base);
}
resultVector[i] = result;
......@@ -101,8 +101,7 @@ public class LogFunctions {
}
private double logb(double x, double base) {
naCheck.enable(true);
if (naCheck.check(base)) {
if (naProfile.isNA(base)) {
return RRuntime.DOUBLE_NA;
}
......
......@@ -48,6 +48,7 @@ import com.oracle.truffle.r.runtime.nodes.RNode;
*/
abstract class BaseWriteVariableNode extends WriteVariableNode {
private final ConditionProfile isObjectProfile = ConditionProfile.createBinaryProfile();
private final ConditionProfile isCurrentProfile = ConditionProfile.createBinaryProfile();
private final ConditionProfile isShareableProfile = ConditionProfile.createBinaryProfile();
private final ConditionProfile isSharedProfile = ConditionProfile.createBinaryProfile();
......@@ -89,7 +90,7 @@ abstract class BaseWriteVariableNode extends WriteVariableNode {
// this comparison does not work consistently for boxing objects, so it's important
// to do the RShareable check first.
if (isCurrentProfile.profile(isCurrentValue(frame, frameSlot, value))) {
if (isCurrentValue(frame, frameSlot, value)) {
return value;
}
RShareable rShareable = (RShareable) shareableProfile.profile(value);
......@@ -112,9 +113,9 @@ abstract class BaseWriteVariableNode extends WriteVariableNode {
return value;
}
private static boolean isCurrentValue(Frame frame, FrameSlot frameSlot, Object value) {
private boolean isCurrentValue(Frame frame, FrameSlot frameSlot, Object value) {
try {
return frame.isObject(frameSlot) && frame.getObject(frameSlot) == value;
return isObjectProfile.profile(frame.isObject(frameSlot)) && isCurrentProfile.profile(frame.getObject(frameSlot) == value);
} catch (FrameSlotTypeException ex) {
throw RInternalError.shouldNotReachHere();
}
......
......@@ -44,6 +44,7 @@ final class PositionsCheckNode extends Node {
private final VectorLengthProfile selectedPositionsCountProfile = VectorLengthProfile.create();
private final VectorLengthProfile maxOutOfBoundsProfile = VectorLengthProfile.create();
private final ConditionProfile containsNAProfile = ConditionProfile.createBinaryProfile();
private final BranchProfile unsupportedProfile = BranchProfile.create();
private final boolean replace;
private final int positionsLength;
......@@ -64,10 +65,12 @@ final class PositionsCheckNode extends Node {
@ExplodeLoop
public boolean isSupported(Object[] positions) {
if (positionsCheck.length != positions.length) {
unsupportedProfile.enter();
return false;
}
for (int i = 0; i < positionsCheck.length; i++) {
if (!positionsCheck[i].isSupported(positions[i])) {
unsupportedProfile.enter();
return false;
}
}
......
......@@ -175,8 +175,12 @@ public final class UnaryMapNode extends RBaseNode {
return result;
}
private final ConditionProfile hasDimensionsProfile = ConditionProfile.createBinaryProfile();
private final ConditionProfile hasNamesProfile = ConditionProfile.createBinaryProfile();
private boolean containsMetadata(RAbstractVector vector) {
return vector instanceof RVector && (vector.hasDimensions() || vector.getAttributes() != null || vector.getNames(attrProfiles) != null || vector.getDimNames(attrProfiles) != null);
return vector instanceof RVector && (hasDimensionsProfile.profile(vector.hasDimensions()) || vector.getAttributes() != null || hasNamesProfile.profile(vector.getNames(attrProfiles) != null) ||
vector.getDimNames(attrProfiles) != null);
}
@TruffleBoundary
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment