Skip to content

Commit a798e5f

Browse files
committed
Use inlined profiles SREModuleBuiltins
1 parent ca055e2 commit a798e5f

File tree

1 file changed

+35
-22
lines changed

1 file changed

+35
-22
lines changed

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

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
import com.oracle.graal.python.runtime.object.PythonObjectFactory;
8989
import com.oracle.truffle.api.CompilerDirectives;
9090
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
91+
import com.oracle.truffle.api.dsl.Bind;
9192
import com.oracle.truffle.api.dsl.Cached;
9293
import com.oracle.truffle.api.dsl.Cached.Shared;
9394
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
@@ -105,8 +106,9 @@
105106
import com.oracle.truffle.api.interop.UnsupportedMessageException;
106107
import com.oracle.truffle.api.interop.UnsupportedTypeException;
107108
import com.oracle.truffle.api.library.CachedLibrary;
108-
import com.oracle.truffle.api.profiles.BranchProfile;
109-
import com.oracle.truffle.api.profiles.ConditionProfile;
109+
import com.oracle.truffle.api.nodes.Node;
110+
import com.oracle.truffle.api.profiles.InlinedBranchProfile;
111+
import com.oracle.truffle.api.profiles.InlinedConditionProfile;
110112
import com.oracle.truffle.api.source.Source;
111113
import com.oracle.truffle.api.source.SourceSection;
112114
import com.oracle.truffle.api.strings.TruffleString;
@@ -541,16 +543,17 @@ abstract static class RECheckInputTypeNode extends PNodeWithRaise {
541543

542544
@Specialization
543545
protected void check(VirtualFrame frame, Object input, boolean expectBytes,
546+
@Bind("this") Node inliningTarget,
544547
@Cached BuiltinFunctions.IsInstanceNode isStringNode,
545548
@Cached BuiltinFunctions.IsInstanceNode isBytesNode,
546-
@Cached ConditionProfile unsupportedInputTypeProfile,
547-
@Cached ConditionProfile unexpectedInputTypeProfile) {
549+
@Cached InlinedConditionProfile unsupportedInputTypeProfile,
550+
@Cached InlinedConditionProfile unexpectedInputTypeProfile) {
548551
boolean isString = (boolean) isStringNode.execute(frame, input, PythonBuiltinClassType.PString);
549552
boolean isBytes = !isString && (boolean) isBytesNode.execute(frame, input, SUPPORTED_BINARY_INPUT_TYPES);
550-
if (unsupportedInputTypeProfile.profile(!isString && !isBytes)) {
553+
if (unsupportedInputTypeProfile.profile(inliningTarget, !isString && !isBytes)) {
551554
throw getRaiseNode().raise(TypeError, T_UNSUPPORTED_INPUT_TYPE);
552555
}
553-
if (unexpectedInputTypeProfile.profile(expectBytes != isBytes)) {
556+
if (unexpectedInputTypeProfile.profile(inliningTarget, expectBytes != isBytes)) {
554557
if (expectBytes) {
555558
throw getRaiseNode().raise(TypeError, T_UNEXPECTED_STR);
556559
} else {
@@ -569,13 +572,14 @@ abstract static class CreateMatchFromTRegexResultNode extends PNodeWithContext {
569572

570573
@Specialization
571574
protected Object createMatch(VirtualFrame frame, Object pattern, int pos, int endPos, Object regexResult, Object input,
575+
@Bind("this") Node inliningTarget,
572576
@Cached("lookupMatchConstructor()") Object matchConstructor,
573-
@Cached ConditionProfile matchProfile,
577+
@Cached InlinedConditionProfile matchProfile,
574578
@CachedLibrary(limit = "1") InteropLibrary libResult,
575579
@Cached PyObjectLookupAttr lookupIndexGroupNode,
576580
@Cached CallNode constructResultNode) {
577581
try {
578-
if (matchProfile.profile((boolean) libResult.readMember(regexResult, "isMatch"))) {
582+
if (matchProfile.profile(inliningTarget, (boolean) libResult.readMember(regexResult, "isMatch"))) {
579583
Object indexGroup = lookupIndexGroupNode.execute(frame, pattern, T__PATTERN__INDEXGROUP);
580584
return constructResultNode.execute(matchConstructor, pattern, pos, endPos, regexResult, input, indexGroup);
581585
} else {
@@ -608,16 +612,18 @@ abstract static class TRegexSearch extends PythonSenaryBuiltinNode {
608612
@Child private PyObjectGetItem getItemNode;
609613

610614
@Specialization(guards = {"isSingleContext()", "pattern == cachedPattern", "method == cachedMethod", "mustAdvance == cachedMustAdvance", "!tRegexCache.isLocaleSensitive()"}, limit = "1")
615+
@SuppressWarnings("truffle-static-method")
611616
protected Object doCached(VirtualFrame frame, Object pattern, Object input, Object posArg, Object endPosArg, int method, boolean mustAdvance,
617+
@Bind("this") Node inliningTarget,
612618
@Cached("pattern") Object cachedPattern,
613619
@Cached("method") int cachedMethod,
614620
@Cached("mustAdvance") boolean cachedMustAdvance,
615621
@Cached @Shared ReadAttributeFromObjectNode readCacheNode,
616622
@Cached @Shared TRegexCompile tRegexCompileNode,
617623
@Cached("getTRegexCache(readCacheNode, pattern)") TRegexCache tRegexCache,
618624
@Cached("tRegexCompileNode.execute(frame, tRegexCache, method, mustAdvance)") Object compiledRegex,
619-
@Cached @Shared ConditionProfile fallbackProfile,
620-
@Cached @Shared ConditionProfile truncatingInputProfile,
625+
@Cached @Shared InlinedConditionProfile fallbackProfile,
626+
@Cached @Shared InlinedConditionProfile truncatingInputProfile,
621627
@Cached @Shared RECheckInputTypeNode reCheckInputTypeNode,
622628
@Cached @Shared PyNumberIndexNode indexNode,
623629
@Cached @Shared PyNumberAsSizeNode asSizeNode,
@@ -642,13 +648,13 @@ protected Object doCached(VirtualFrame frame, Object pattern, Object input, Obje
642648
endPos = length;
643649
}
644650

645-
if (fallbackProfile.profile(libCompiledRegex.isNull(compiledRegex))) {
651+
if (fallbackProfile.profile(inliningTarget, libCompiledRegex.isNull(compiledRegex))) {
646652
Object fallbackRegex = getCallFallbackCompileNode().execute(getGetFallbackCompileNode().executeObject(frame, pattern));
647653
return getCallFallbackMethodNode().execute(getFallbackMethodNode.executeObject(frame, fallbackRegex), input, pos, endPos);
648654
}
649655

650656
Object truncatedInput = input;
651-
if (truncatingInputProfile.profile(endPos != length)) {
657+
if (truncatingInputProfile.profile(inliningTarget, endPos != length)) {
652658
truncatedInput = getGetItemNode().execute(frame, input, getCreateSliceNode().execute(0, endPos, 1));
653659
}
654660
Object regexResult = tRegexCallExec.execute(frame, compiledRegex, truncatedInput, pos);
@@ -658,15 +664,17 @@ protected Object doCached(VirtualFrame frame, Object pattern, Object input, Obje
658664

659665
@Specialization(guards = {"tRegexCompileNode.execute(frame, getTRegexCache(readCacheNode, pattern), method, mustAdvance) == compiledRegex", "method == cachedMethod",
660666
"mustAdvance == cachedMustAdvance", "!tRegexCache.isLocaleSensitive()"}, limit = "1")
667+
@SuppressWarnings("truffle-static-method")
661668
protected Object doCachedRegex(VirtualFrame frame, Object pattern, Object input, Object posArg, Object endPosArg, int method, boolean mustAdvance,
669+
@Bind("this") Node inliningTarget,
662670
@Cached("method") int cachedMethod,
663671
@Cached("mustAdvance") boolean cachedMustAdvance,
664672
@Cached @Shared ReadAttributeFromObjectNode readCacheNode,
665673
@Cached @Shared TRegexCompile tRegexCompileNode,
666674
@Cached("getTRegexCache(readCacheNode, pattern)") TRegexCache tRegexCache,
667675
@Cached("tRegexCompileNode.execute(frame, tRegexCache, method, mustAdvance)") Object compiledRegex,
668-
@Cached @Shared ConditionProfile fallbackProfile,
669-
@Cached @Shared ConditionProfile truncatingInputProfile,
676+
@Cached @Shared InlinedConditionProfile fallbackProfile,
677+
@Cached @Shared InlinedConditionProfile truncatingInputProfile,
670678
@Cached @Shared RECheckInputTypeNode reCheckInputTypeNode,
671679
@Cached @Shared PyNumberIndexNode indexNode,
672680
@Cached @Shared PyNumberAsSizeNode asSizeNode,
@@ -675,30 +683,32 @@ protected Object doCachedRegex(VirtualFrame frame, Object pattern, Object input,
675683
@Cached("create(getMethodName(method))") GetAttributeNode getFallbackMethodNode,
676684
@Cached @Shared TRegexCallExec tRegexCallExec,
677685
@Cached @Shared CreateMatchFromTRegexResultNode createMatchFromTRegexResultNode) {
678-
return doCached(frame, pattern, input, posArg, endPosArg, method, mustAdvance, pattern, cachedMethod, mustAdvance, readCacheNode, tRegexCompileNode, tRegexCache,
686+
return doCached(frame, pattern, input, posArg, endPosArg, method, mustAdvance, inliningTarget, pattern, cachedMethod, mustAdvance, readCacheNode, tRegexCompileNode, tRegexCache,
679687
compiledRegex, fallbackProfile, truncatingInputProfile, reCheckInputTypeNode, indexNode, asSizeNode, lengthNode, libCompiledRegex, getFallbackMethodNode,
680688
tRegexCallExec, createMatchFromTRegexResultNode);
681689
}
682690

683691
@Specialization(guards = "method == cachedMethod", limit = "3", replaces = {"doCached", "doCachedRegex"})
692+
@SuppressWarnings("truffle-static-method")
684693
@ReportPolymorphism.Megamorphic
685694
protected Object doDynamic(VirtualFrame frame, Object pattern, Object input, Object posArg, Object endPosArg, int method, boolean mustAdvance,
695+
@Bind("this") Node inliningTarget,
686696
@Cached("method") int cachedMethod,
687697
@Cached @Shared ReadAttributeFromObjectNode readCacheNode,
688698
@Cached @Shared TRegexCompile tRegexCompileNode,
689699
@Cached @Shared PyNumberIndexNode indexNode,
690700
@Cached @Shared PyNumberAsSizeNode asSizeNode,
691701
@Cached @Shared RECheckInputTypeNode reCheckInputTypeNode,
692702
@Cached @Shared PyObjectSizeNode lengthNode,
693-
@Cached @Shared ConditionProfile fallbackProfile,
694-
@Cached @Shared ConditionProfile truncatingInputProfile,
703+
@Cached @Shared InlinedConditionProfile fallbackProfile,
704+
@Cached @Shared InlinedConditionProfile truncatingInputProfile,
695705
@CachedLibrary(limit = "1") @Shared InteropLibrary libCompiledRegex,
696706
@Cached("create(getMethodName(method))") GetAttributeNode getFallbackMethodNode,
697707
@Cached @Shared TRegexCallExec tRegexCallExec,
698708
@Cached @Shared CreateMatchFromTRegexResultNode createMatchFromTRegexResultNode) {
699709
TRegexCache tRegexCache = getTRegexCache(readCacheNode, pattern);
700710
Object compiledRegex = tRegexCompileNode.execute(frame, tRegexCache, method, mustAdvance);
701-
return doCached(frame, pattern, input, posArg, endPosArg, method, mustAdvance, pattern, cachedMethod, mustAdvance, readCacheNode, tRegexCompileNode, tRegexCache,
711+
return doCached(frame, pattern, input, posArg, endPosArg, method, mustAdvance, inliningTarget, pattern, cachedMethod, mustAdvance, readCacheNode, tRegexCompileNode, tRegexCache,
702712
compiledRegex, fallbackProfile, truncatingInputProfile, reCheckInputTypeNode, indexNode, asSizeNode, lengthNode, libCompiledRegex, getFallbackMethodNode,
703713
tRegexCallExec, createMatchFromTRegexResultNode);
704714
}
@@ -760,21 +770,23 @@ abstract static class TRegexCallExec extends PythonTernaryBuiltinNode {
760770
@Child private BufferToTruffleStringNode bufferToTruffleStringNode;
761771

762772
@Specialization(guards = "callable == cachedCallable", limit = "2")
773+
@SuppressWarnings("truffle-static-method")
763774
Object doCached(VirtualFrame frame, Object callable, Object inputStringOrBytes, Number fromIndex,
775+
@Bind("this") Node inliningTarget,
764776
@Cached("callable") Object cachedCallable,
765777
@Cached @Shared CastToTruffleStringNode cast,
766778
@CachedLibrary(limit = "3") @Shared PythonBufferAcquireLibrary bufferAcquireLib,
767779
@CachedLibrary(limit = "1") @Shared PythonBufferAccessLibrary bufferLib,
768780
@CachedLibrary("callable") InteropLibrary interop,
769-
@Cached @Shared BranchProfile binaryProfile) {
781+
@Cached @Shared InlinedBranchProfile binaryProfile) {
770782
TruffleString input;
771783
Object buffer = null;
772784
try {
773785
try {
774786
// This would materialize the string if it was native
775787
input = cast.execute(inputStringOrBytes);
776788
} catch (CannotCastException e1) {
777-
binaryProfile.enter();
789+
binaryProfile.enter(inliningTarget);
778790
// It's bytes or other buffer object
779791
buffer = bufferAcquireLib.acquireReadonly(inputStringOrBytes, frame, this);
780792
input = getBufferToTruffleStringNode().execute(buffer, 0);
@@ -794,12 +806,13 @@ Object doCached(VirtualFrame frame, Object callable, Object inputStringOrBytes,
794806
@Specialization(limit = "1", replaces = "doCached")
795807
@ReportPolymorphism.Megamorphic
796808
Object doUncached(VirtualFrame frame, Object callable, Object inputStringOrBytes, Number fromIndex,
809+
@Bind("this") Node inliningTarget,
797810
@Cached @Shared CastToTruffleStringNode cast,
798811
@CachedLibrary(limit = "3") @Shared PythonBufferAcquireLibrary bufferAcquireLib,
799812
@CachedLibrary(limit = "1") @Shared PythonBufferAccessLibrary bufferLib,
800813
@CachedLibrary("callable") InteropLibrary interop,
801-
@Cached @Shared BranchProfile binaryProfile) {
802-
return doCached(frame, callable, inputStringOrBytes, fromIndex, callable, cast, bufferAcquireLib, bufferLib, interop, binaryProfile);
814+
@Cached @Shared InlinedBranchProfile binaryProfile) {
815+
return doCached(frame, callable, inputStringOrBytes, fromIndex, inliningTarget, callable, cast, bufferAcquireLib, bufferLib, interop, binaryProfile);
803816
}
804817

805818
private BufferToTruffleStringNode getBufferToTruffleStringNode() {

0 commit comments

Comments
 (0)