Skip to content

Commit 5b40780

Browse files
committed
[GR-44033] Adopt DSL node inlining: IsBuiltinClassProfile.
PullRequest: graalpython/2615
2 parents 1747e28 + a876714 commit 5b40780

File tree

116 files changed

+2263
-1470
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

116 files changed

+2263
-1470
lines changed

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/builtins/modules/ClinicTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -67,7 +67,7 @@
6767
import com.oracle.graal.python.nodes.function.builtins.PythonBinaryClinicBuiltinNode;
6868
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentCastNode;
6969
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentClinicProvider;
70-
import com.oracle.graal.python.nodes.object.IsBuiltinClassProfile;
70+
import com.oracle.graal.python.nodes.object.BuiltinClassProfiles.IsBuiltinObjectProfile;
7171
import com.oracle.graal.python.runtime.exception.PException;
7272
import com.oracle.graal.python.test.PythonTests;
7373
import com.oracle.truffle.api.CallTarget;
@@ -203,7 +203,7 @@ public Object execute(VirtualFrame frame) {
203203
} catch (PException ex) {
204204
boolean expectTypeError = frame.getArguments().length >= 3 && (boolean) frame.getArguments()[2];
205205
if (expectTypeError) {
206-
ex.expect(PythonBuiltinClassType.TypeError, IsBuiltinClassProfile.getUncached());
206+
ex.expect(null, PythonBuiltinClassType.TypeError, IsBuiltinObjectProfile.getUncached());
207207
return T_TYPE_ERROR;
208208
} else {
209209
throw ex;

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/nodes/util/CastToJavaUnsignedLongNodeTests.java

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -40,23 +40,24 @@
4040
*/
4141
package com.oracle.graal.python.nodes.util;
4242

43+
import static com.oracle.graal.python.runtime.exception.PythonErrorType.OverflowError;
44+
import static com.oracle.graal.python.runtime.exception.PythonErrorType.TypeError;
45+
46+
import java.math.BigInteger;
47+
48+
import org.junit.After;
49+
import org.junit.Assert;
50+
import org.junit.Before;
51+
import org.junit.Test;
52+
4353
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
4454
import com.oracle.graal.python.builtins.objects.ints.PInt;
45-
import com.oracle.graal.python.nodes.object.IsBuiltinClassProfile;
55+
import com.oracle.graal.python.nodes.object.BuiltinClassProfiles.IsBuiltinObjectProfile;
4656
import com.oracle.graal.python.runtime.exception.PException;
4757
import com.oracle.graal.python.runtime.object.PythonObjectFactory;
4858
import com.oracle.graal.python.test.PythonTests;
4959
import com.oracle.truffle.api.frame.VirtualFrame;
5060
import com.oracle.truffle.api.nodes.RootNode;
51-
import org.junit.After;
52-
import org.junit.Assert;
53-
import org.junit.Before;
54-
import org.junit.Test;
55-
56-
import java.math.BigInteger;
57-
58-
import static com.oracle.graal.python.runtime.exception.PythonErrorType.OverflowError;
59-
import static com.oracle.graal.python.runtime.exception.PythonErrorType.TypeError;
6061

6162
public class CastToJavaUnsignedLongNodeTests {
6263
private static PythonObjectFactory factory = PythonObjectFactory.getUncached();
@@ -139,7 +140,7 @@ private static void expect(PythonBuiltinClassType errorType, Runnable test) {
139140
test.run();
140141
Assert.fail("Expected " + errorType.getName());
141142
} catch (PException e) {
142-
e.expect(errorType, IsBuiltinClassProfile.getUncached());
143+
e.expect(null, errorType, IsBuiltinObjectProfile.getUncached());
143144
}
144145
}
145146

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/datatype/PRangeTests.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2022, Oracle and/or its affiliates.
2+
* Copyright (c) 2017, 2023, Oracle and/or its affiliates.
33
* Copyright (c) 2013, Regents of the University of California
44
*
55
* All rights reserved.
@@ -35,7 +35,7 @@
3535
import com.oracle.graal.python.builtins.objects.range.PRange;
3636
import com.oracle.graal.python.lib.GetNextNode;
3737
import com.oracle.graal.python.lib.PyObjectGetIter;
38-
import com.oracle.graal.python.nodes.object.IsBuiltinClassProfile;
38+
import com.oracle.graal.python.nodes.object.BuiltinClassProfiles.IsBuiltinObjectProfile;
3939
import com.oracle.graal.python.runtime.exception.PException;
4040
import com.oracle.graal.python.runtime.object.PythonObjectFactory;
4141
import com.oracle.graal.python.test.PythonTests;
@@ -71,14 +71,14 @@ public void loopWithOnlyStop() throws UnexpectedResultException {
7171
Object iter = PyObjectGetIter.getUncached().execute(null, range);
7272
GetNextNode next = GetNextNode.create();
7373
testRoot.doInsert(next);
74-
IsBuiltinClassProfile errorProfile = IsBuiltinClassProfile.getUncached();
74+
IsBuiltinObjectProfile errorProfile = IsBuiltinObjectProfile.getUncached();
7575

7676
while (true) {
7777
try {
7878
int item = next.executeInt(null, iter);
7979
assertEquals(index, item);
8080
} catch (PException e) {
81-
e.expectStopIteration(errorProfile);
81+
e.expectStopIteration(null, errorProfile);
8282
break;
8383
}
8484
index++;
@@ -99,14 +99,14 @@ public void loopWithStep() throws UnexpectedResultException {
9999
Object iter = PyObjectGetIter.getUncached().execute(null, range);
100100
GetNextNode next = GetNextNode.create();
101101
testRoot.doInsert(next);
102-
IsBuiltinClassProfile errorProfile = IsBuiltinClassProfile.getUncached();
102+
IsBuiltinObjectProfile errorProfile = IsBuiltinObjectProfile.getUncached();
103103

104104
while (true) {
105105
try {
106106
int item = next.executeInt(null, iter);
107107
assertEquals(index, item);
108108
} catch (PException e) {
109-
e.expectStopIteration(errorProfile);
109+
e.expectStopIteration(null, errorProfile);
110110
break;
111111
}
112112
index += 2;

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ArrayModuleBuiltins.java

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2022, Oracle and/or its affiliates.
2+
* Copyright (c) 2017, 2023, Oracle and/or its affiliates.
33
* Copyright (c) 2013, Regents of the University of California
44
*
55
* All rights reserved.
@@ -70,7 +70,8 @@
7070
import com.oracle.graal.python.nodes.function.builtins.PythonClinicBuiltinNode;
7171
import com.oracle.graal.python.nodes.function.builtins.PythonVarargsBuiltinNode;
7272
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentClinicProvider;
73-
import com.oracle.graal.python.nodes.object.IsBuiltinClassProfile;
73+
import com.oracle.graal.python.nodes.object.BuiltinClassProfiles.InlineIsBuiltinClassProfile;
74+
import com.oracle.graal.python.nodes.object.BuiltinClassProfiles.IsBuiltinObjectProfile;
7475
import com.oracle.graal.python.nodes.util.SplitArgsNode;
7576
import com.oracle.graal.python.runtime.exception.PException;
7677
import com.oracle.graal.python.runtime.object.PythonObjectFactory;
@@ -81,7 +82,9 @@
8182
import com.oracle.graal.python.util.PythonUtils;
8283
import com.oracle.truffle.api.CompilerDirectives;
8384
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
85+
import com.oracle.truffle.api.dsl.Bind;
8486
import com.oracle.truffle.api.dsl.Cached;
87+
import com.oracle.truffle.api.dsl.Cached.Exclusive;
8588
import com.oracle.truffle.api.dsl.Fallback;
8689
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
8790
import com.oracle.truffle.api.dsl.ImportStatic;
@@ -116,19 +119,21 @@ abstract static class ArrayNode extends PythonVarargsBuiltinNode {
116119

117120
@Specialization(guards = "args.length == 1")
118121
Object array2(VirtualFrame frame, Object cls, Object[] args, PKeyword[] kwargs,
119-
@Cached IsBuiltinClassProfile isNotSubtypeProfile,
122+
@Bind("this") Node inliningTarget,
123+
@Exclusive @Cached InlineIsBuiltinClassProfile isNotSubtypeProfile,
120124
@Cached CastToTruffleStringCheckedNode cast,
121125
@Cached ArrayNodeInternal arrayNodeInternal) {
122-
checkKwargs(cls, kwargs, isNotSubtypeProfile);
126+
checkKwargs(cls, kwargs, inliningTarget, isNotSubtypeProfile);
123127
return arrayNodeInternal.execute(frame, cls, cast.cast(args[0], ErrorMessages.ARG_1_MUST_BE_UNICODE_NOT_P, args[0]), PNone.NO_VALUE);
124128
}
125129

126130
@Specialization(guards = "args.length == 2")
127131
Object array3(VirtualFrame frame, Object cls, Object[] args, PKeyword[] kwargs,
128-
@Cached IsBuiltinClassProfile isNotSubtypeProfile,
132+
@Bind("this") Node inliningTarget,
133+
@Exclusive @Cached InlineIsBuiltinClassProfile isNotSubtypeProfile,
129134
@Cached CastToTruffleStringCheckedNode cast,
130135
@Cached ArrayNodeInternal arrayNodeInternal) {
131-
checkKwargs(cls, kwargs, isNotSubtypeProfile);
136+
checkKwargs(cls, kwargs, inliningTarget, isNotSubtypeProfile);
132137
return arrayNodeInternal.execute(frame, cls, cast.cast(args[0], ErrorMessages.ARG_1_MUST_BE_UNICODE_NOT_P, args[0]), args[1]);
133138
}
134139

@@ -142,8 +147,8 @@ Object error(Object cls, Object[] args, PKeyword[] kwargs) {
142147
}
143148
}
144149

145-
private void checkKwargs(Object cls, PKeyword[] kwargs, IsBuiltinClassProfile isNotSubtypeProfile) {
146-
if (isNotSubtypeProfile.profileClass(cls, PythonBuiltinClassType.PArray)) {
150+
private void checkKwargs(Object cls, PKeyword[] kwargs, Node inliningTarget, InlineIsBuiltinClassProfile isNotSubtypeProfile) {
151+
if (isNotSubtypeProfile.profileIsBuiltinClass(inliningTarget, cls, PythonBuiltinClassType.PArray)) {
147152
if (kwargs.length != 0) {
148153
throw raise(TypeError, S_TAKES_NO_KEYWORD_ARGS, "array.array()");
149154
}
@@ -266,10 +271,11 @@ PArray arraySequenceInitializer(VirtualFrame frame, Object cls, TruffleString ty
266271

267272
@Specialization(guards = {"!isBytes(initializer)", "!isString(initializer)", "!isPSequence(initializer)"})
268273
PArray arrayIteratorInitializer(VirtualFrame frame, Object cls, TruffleString typeCode, Object initializer,
274+
@Bind("this") Node inliningTarget,
269275
@Cached PyObjectGetIter getIter,
270276
@Cached ArrayNodes.PutValueNode putValueNode,
271277
@Cached GetNextNode nextNode,
272-
@Cached IsBuiltinClassProfile errorProfile,
278+
@Cached IsBuiltinObjectProfile errorProfile,
273279
@Cached TruffleString.CodePointLengthNode lengthNode,
274280
@Cached TruffleString.CodePointAtIndexNode atIndexNode) {
275281
Object iter = getIter.execute(frame, initializer);
@@ -283,7 +289,7 @@ PArray arrayIteratorInitializer(VirtualFrame frame, Object cls, TruffleString ty
283289
try {
284290
nextValue = nextNode.execute(frame, iter);
285291
} catch (PException e) {
286-
e.expectStopIteration(errorProfile);
292+
e.expectStopIteration(inliningTarget, errorProfile);
287293
break;
288294
}
289295
try {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/AtexitModuleBuiltins.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -40,6 +40,9 @@
4040
*/
4141
package com.oracle.graal.python.builtins.modules;
4242

43+
import static com.oracle.graal.python.builtins.modules.io.IONodes.T_WRITE;
44+
import static com.oracle.graal.python.util.PythonUtils.toTruffleStringUncached;
45+
4346
import java.util.List;
4447

4548
import com.oracle.graal.python.builtins.Builtin;
@@ -56,8 +59,8 @@
5659
import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
5760
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
5861
import com.oracle.graal.python.nodes.function.builtins.PythonVarargsBuiltinNode;
62+
import com.oracle.graal.python.nodes.object.BuiltinClassProfiles.InlineIsBuiltinClassProfile;
5963
import com.oracle.graal.python.nodes.object.GetClassNode;
60-
import com.oracle.graal.python.nodes.object.IsBuiltinClassProfile;
6164
import com.oracle.graal.python.runtime.PythonContext;
6265
import com.oracle.graal.python.runtime.PythonContext.GetThreadStateNode;
6366
import com.oracle.graal.python.runtime.PythonContextFactory.GetThreadStateNodeGen;
@@ -73,9 +76,6 @@
7376
import com.oracle.truffle.api.frame.VirtualFrame;
7477
import com.oracle.truffle.api.nodes.RootNode;
7578

76-
import static com.oracle.graal.python.builtins.modules.io.IONodes.T_WRITE;
77-
import static com.oracle.graal.python.util.PythonUtils.toTruffleStringUncached;
78-
7979
@CoreFunctions(defineModule = "atexit")
8080
public class AtexitModuleBuiltins extends PythonBuiltins {
8181
@Override
@@ -120,7 +120,7 @@ public Object execute(VirtualFrame frame) {
120120
@TruffleBoundary
121121
private static void handleException(PythonContext context, PException e) {
122122
PBaseException pythonException = e.getEscapedException();
123-
if (!IsBuiltinClassProfile.profileClassSlowPath(GetClassNode.getUncached().execute(pythonException), PythonBuiltinClassType.SystemExit)) {
123+
if (!InlineIsBuiltinClassProfile.profileClassSlowPath(GetClassNode.getUncached().execute(pythonException), PythonBuiltinClassType.SystemExit)) {
124124
PyObjectCallMethodObjArgs callWrite = PyObjectCallMethodObjArgs.getUncached();
125125
callWrite.execute(null, context.getStderr(), T_WRITE, toTruffleStringUncached("Error in atexit._run_exitfuncs:\n"));
126126
try {

0 commit comments

Comments
 (0)