Skip to content

Commit 9f6291d

Browse files
committed
Simplify specializations in IOBaseBuiltins
1 parent fc0098f commit 9f6291d

File tree

1 file changed

+14
-16
lines changed
  • graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io

1 file changed

+14
-16
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/IOBaseBuiltins.java

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -114,19 +114,22 @@
114114
import com.oracle.graal.python.nodes.function.builtins.PythonBinaryClinicBuiltinNode;
115115
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
116116
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentClinicProvider;
117-
import com.oracle.graal.python.nodes.object.IsBuiltinClassProfile;
117+
import com.oracle.graal.python.nodes.object.BuiltinClassProfiles.IsBuiltinObjectProfile;
118118
import com.oracle.graal.python.nodes.object.IsNode;
119119
import com.oracle.graal.python.runtime.exception.PException;
120120
import com.oracle.graal.python.util.ArrayBuilder;
121+
import com.oracle.truffle.api.dsl.Bind;
121122
import com.oracle.truffle.api.dsl.Cached;
122123
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
123124
import com.oracle.truffle.api.dsl.ImportStatic;
124125
import com.oracle.truffle.api.dsl.NodeFactory;
125126
import com.oracle.truffle.api.dsl.Specialization;
126127
import com.oracle.truffle.api.frame.VirtualFrame;
127128
import com.oracle.truffle.api.library.CachedLibrary;
129+
import com.oracle.truffle.api.nodes.Node;
128130
import com.oracle.truffle.api.profiles.BranchProfile;
129131
import com.oracle.truffle.api.profiles.ConditionProfile;
132+
import com.oracle.truffle.api.profiles.InlinedConditionProfile;
130133
import com.oracle.truffle.api.strings.TruffleString;
131134

132135
@CoreFunctions(extendClasses = PythonBuiltinClassType.PIOBase)
@@ -382,9 +385,10 @@ Object next(VirtualFrame frame, PythonObject self,
382385
abstract static class WriteLinesNode extends PythonBinaryBuiltinNode {
383386
@Specialization
384387
static Object writeLines(VirtualFrame frame, PythonObject self, Object lines,
388+
@Bind("this") Node inliningTarget,
385389
@Cached CheckClosedNode checkClosedNode,
386390
@Cached GetNextNode getNextNode,
387-
@Cached IsBuiltinClassProfile errorProfile,
391+
@Cached IsBuiltinObjectProfile errorProfile,
388392
@Cached PyObjectCallMethodObjArgs callMethod,
389393
@Cached PyObjectGetIter getIter) {
390394
checkClosedNode.execute(frame, self);
@@ -394,7 +398,7 @@ static Object writeLines(VirtualFrame frame, PythonObject self, Object lines,
394398
try {
395399
line = getNextNode.execute(frame, iter);
396400
} catch (PException e) {
397-
e.expectStopIteration(errorProfile);
401+
e.expectStopIteration(inliningTarget, errorProfile);
398402
break;
399403
}
400404
callMethod.execute(frame, self, T_WRITE, line);
@@ -478,21 +482,15 @@ protected ArgumentClinicProvider getArgumentClinic() {
478482
return IOBaseBuiltinsClinicProviders.ReadlinesNodeClinicProviderGen.INSTANCE;
479483
}
480484

481-
@Specialization(guards = "hint <= 0")
482-
Object doall(VirtualFrame frame, Object self, @SuppressWarnings("unused") int hint,
483-
@Cached GetNextNode next,
484-
@Cached IsBuiltinClassProfile errorProfile,
485-
@Cached PyObjectGetIter getIter,
486-
@Cached PyObjectSizeNode sizeNode) {
487-
return withHint(frame, self, Integer.MAX_VALUE, next, errorProfile, getIter, sizeNode);
488-
}
489-
490-
@Specialization(guards = "hint > 0")
491-
Object withHint(VirtualFrame frame, Object self, int hint,
485+
@Specialization
486+
Object withHint(VirtualFrame frame, Object self, int hintIn,
487+
@Bind("this") Node inliningTarget,
492488
@Cached GetNextNode next,
493-
@Cached IsBuiltinClassProfile errorProfile,
489+
@Cached InlinedConditionProfile isNegativeHintProfile,
490+
@Cached IsBuiltinObjectProfile errorProfile,
494491
@Cached PyObjectGetIter getIter,
495492
@Cached PyObjectSizeNode sizeNode) {
493+
int hint = isNegativeHintProfile.profile(inliningTarget, hintIn <= 0) ? Integer.MAX_VALUE : hintIn;
496494
int length = 0;
497495
Object iterator = getIter.execute(frame, self);
498496
ArrayBuilder<Object> list = new ArrayBuilder<>();
@@ -506,7 +504,7 @@ Object withHint(VirtualFrame frame, Object self, int hint,
506504
}
507505
length += lineLength;
508506
} catch (PException e) {
509-
e.expectStopIteration(errorProfile);
507+
e.expectStopIteration(inliningTarget, errorProfile);
510508
break;
511509
}
512510
}

0 commit comments

Comments
 (0)