Skip to content

Commit 59e8390

Browse files
committed
Convert CmpIntNode to DSL inlinable
1 parent b9f0c18 commit 59e8390

File tree

2 files changed

+25
-25
lines changed

2 files changed

+25
-25
lines changed

src/main/java/org/truffleruby/core/array/ArrayNodes.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2073,36 +2073,37 @@ RubyArray sortEmpty(RubyArray array, Object unusedBlock) {
20732073
@Specialization(
20742074
guards = { "!isEmptyArray(array)", "isSmall(array)" },
20752075
limit = "storageStrategyLimit()")
2076-
RubyArray sortVeryShort(VirtualFrame frame, RubyArray array, Nil block,
2076+
static RubyArray sortVeryShort(VirtualFrame frame, RubyArray array, Nil block,
20772077
@Bind("array.getStore()") Object store,
20782078
@CachedLibrary("store") ArrayStoreLibrary stores,
20792079
@CachedLibrary(limit = "1") @Exclusive ArrayStoreLibrary newStores,
20802080
@Cached @Shared IntValueProfile arraySizeProfile,
20812081
@Cached @Exclusive DispatchNode compareDispatchNode,
2082-
@Cached CmpIntNode cmpIntNode) {
2082+
@Cached CmpIntNode cmpIntNode,
2083+
@Bind("this") Node node) {
20832084
final Object newStore = stores
20842085
.unsharedAllocator(store)
2085-
.allocate(getContext().getOptions().ARRAY_SMALL);
2086+
.allocate(getContext(node).getOptions().ARRAY_SMALL);
20862087
final int size = arraySizeProfile.profile(array.size);
20872088

20882089
// Copy with a exploded loop for PE
20892090

2090-
for (int i = 0; i < getContext().getOptions().ARRAY_SMALL; i++) {
2091+
for (int i = 0; i < getContext(node).getOptions().ARRAY_SMALL; i++) {
20912092
if (i < size) {
20922093
newStores.write(newStore, i, stores.read(store, i));
20932094
}
20942095
}
20952096

20962097
// Selection sort - written very carefully to allow PE
20972098

2098-
for (int i = 0; i < getContext().getOptions().ARRAY_SMALL; i++) {
2099+
for (int i = 0; i < getContext(node).getOptions().ARRAY_SMALL; i++) {
20992100
if (i < size) {
2100-
for (int j = i + 1; j < getContext().getOptions().ARRAY_SMALL; j++) {
2101+
for (int j = i + 1; j < getContext(node).getOptions().ARRAY_SMALL; j++) {
21012102
if (j < size) {
21022103
final Object a = newStores.read(newStore, i);
21032104
final Object b = newStores.read(newStore, j);
21042105
final Object comparisonResult = compareDispatchNode.call(b, "<=>", a);
2105-
if (cmpIntNode.executeCmpInt(comparisonResult, b, a) < 0) {
2106+
if (cmpIntNode.executeCmpInt(node, comparisonResult, b, a) < 0) {
21062107
newStores.write(newStore, j, a);
21072108
newStores.write(newStore, i, b);
21082109
}
@@ -2111,7 +2112,7 @@ RubyArray sortVeryShort(VirtualFrame frame, RubyArray array, Nil block,
21112112
}
21122113
}
21132114

2114-
return createArray(newStore, size);
2115+
return createArray(node, newStore, size);
21152116
}
21162117

21172118
@Specialization(

src/main/java/org/truffleruby/core/cast/CmpIntNode.java

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020

2121
package org.truffleruby.core.cast;
2222

23-
import com.oracle.truffle.api.dsl.Bind;
23+
import com.oracle.truffle.api.dsl.GenerateCached;
24+
import com.oracle.truffle.api.dsl.GenerateInline;
2425
import com.oracle.truffle.api.nodes.Node;
2526
import org.truffleruby.core.numeric.RubyBignum;
2627
import org.truffleruby.core.string.StringUtils;
@@ -35,21 +36,19 @@
3536
import org.truffleruby.language.objects.LogicalClassNode;
3637

3738
/** This is a port of MRI's rb_cmpint, as taken from RubyComparable and broken out into specialized nodes. */
39+
@GenerateInline
40+
@GenerateCached(false)
3841
public abstract class CmpIntNode extends RubyBaseNode {
3942

40-
public static CmpIntNode create() {
41-
return CmpIntNodeGen.create();
42-
}
43-
44-
public abstract int executeCmpInt(Object cmpResult, Object a, Object b);
43+
public abstract int executeCmpInt(Node node, Object cmpResult, Object a, Object b);
4544

4645
@Specialization
47-
int cmpInt(int value, Object receiver, Object other) {
46+
static int cmpInt(int value, Object receiver, Object other) {
4847
return value;
4948
}
5049

5150
@Specialization
52-
int cmpLong(long value, Object receiver, Object other) {
51+
static int cmpLong(long value, Object receiver, Object other) {
5352
if (value > 0) {
5453
return 1;
5554
}
@@ -62,30 +61,30 @@ int cmpLong(long value, Object receiver, Object other) {
6261
}
6362

6463
@Specialization
65-
int cmpBignum(RubyBignum value, Object receiver, Object other) {
64+
static int cmpBignum(RubyBignum value, Object receiver, Object other) {
6665
return value.value.signum();
6766
}
6867

6968
@Specialization
70-
int cmpNil(Nil nil, Object receiver, Object other) {
71-
throw new RaiseException(getContext(), coreExceptions().argumentError(formatMessage(receiver, other), this));
69+
static int cmpNil(Node node, Nil nil, Object receiver, Object other) {
70+
throw new RaiseException(getContext(node),
71+
coreExceptions(node).argumentError(formatMessage(receiver, other), node));
7272
}
7373

7474
@TruffleBoundary
75-
private String formatMessage(Object receiver, Object other) {
75+
private static String formatMessage(Object receiver, Object other) {
7676
return StringUtils.format(
7777
"comparison of %s with %s failed",
7878
LogicalClassNode.getUncached().execute(receiver).fields.getName(),
7979
LogicalClassNode.getUncached().execute(other).fields.getName());
8080
}
8181

8282
@Specialization(guards = { "!isRubyInteger(value)", "!isNil(value)" })
83-
static int cmpObject(Object value, Object receiver, Object other,
84-
@Cached DispatchNode gtNode,
85-
@Cached DispatchNode ltNode,
83+
static int cmpObject(Node node, Object value, Object receiver, Object other,
84+
@Cached(inline = false) DispatchNode gtNode,
85+
@Cached(inline = false) DispatchNode ltNode,
8686
@Cached BooleanCastNode gtCastNode,
87-
@Cached BooleanCastNode ltCastNode,
88-
@Bind("this") Node node) {
87+
@Cached BooleanCastNode ltCastNode) {
8988

9089
if (gtCastNode.execute(node, gtNode.call(value, ">", 0))) {
9190
return 1;

0 commit comments

Comments
 (0)