Skip to content

Commit 1e4ae00

Browse files
committed
tweak inlining options for generator inlining and lookup in MRO cache, replace PIC when we go large
1 parent b6b7617 commit 1e4ae00

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/attributes/LookupAttributeInMRONode.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,15 @@
4343
import com.oracle.graal.python.builtins.objects.PNone;
4444
import com.oracle.graal.python.builtins.objects.type.PythonClass;
4545
import com.oracle.graal.python.nodes.PBaseNode;
46+
import com.oracle.graal.python.runtime.PythonOptions;
4647
import com.oracle.truffle.api.Assumption;
4748
import com.oracle.truffle.api.dsl.Cached;
4849
import com.oracle.truffle.api.dsl.Fallback;
50+
import com.oracle.truffle.api.dsl.ImportStatic;
4951
import com.oracle.truffle.api.dsl.Specialization;
5052
import com.oracle.truffle.api.nodes.ExplodeLoop;
5153

54+
@ImportStatic(PythonOptions.class)
5255
public abstract class LookupAttributeInMRONode extends PBaseNode {
5356

5457
public abstract static class Dynamic extends PBaseNode {
@@ -132,7 +135,7 @@ protected PythonClassAssumptionPair findAttrClassAndAssumptionInMRO(PythonClass
132135
return new PythonClassAssumptionPair(attrAssumption, PNone.NO_VALUE);
133136
}
134137

135-
@Specialization(guards = {"klass == cachedKlass"}, limit = "5", assumptions = {"cachedClassInMROInfo.assumption"})
138+
@Specialization(guards = {"klass == cachedKlass"}, limit = "getIntOption(getContext(), AttributeAccessInlineCacheMaxDepth)", assumptions = {"cachedClassInMROInfo.assumption"})
136139
protected Object lookupConstantMROCached(@SuppressWarnings("unused") PythonClass klass,
137140
@Cached("klass") @SuppressWarnings("unused") PythonClass cachedKlass,
138141
@Cached("findAttrClassAndAssumptionInMRO(cachedKlass)") PythonClassAssumptionPair cachedClassInMROInfo) {
@@ -147,7 +150,7 @@ protected ReadAttributeFromObjectNode[] create(int size) {
147150
return nodes;
148151
}
149152

150-
@Specialization(guards = {"klass == cachedKlass", "mroLength < 32"}, limit = "5", assumptions = "lookupStable")
153+
@Specialization(guards = {"klass == cachedKlass", "mroLength < 32"}, limit = "getIntOption(getContext(), AttributeAccessInlineCacheMaxDepth)", assumptions = "lookupStable")
151154
@ExplodeLoop(kind = ExplodeLoop.LoopExplosionKind.FULL_EXPLODE_UNTIL_RETURN)
152155
protected Object lookupConstantMRO(@SuppressWarnings("unused") PythonClass klass,
153156
@Cached("klass") @SuppressWarnings("unused") PythonClass cachedKlass,
@@ -165,7 +168,7 @@ protected Object lookupConstantMRO(@SuppressWarnings("unused") PythonClass klass
165168
return PNone.NO_VALUE;
166169
}
167170

168-
@Specialization
171+
@Specialization(replaces = {"lookupConstantMROCached", "lookupConstantMRO"})
169172
protected Object lookup(PythonClass klass,
170173
@Cached("create()") ReadAttributeFromObjectNode readAttrNode) {
171174
return lookupSlow(klass, key, readAttrNode);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/InvokeNode.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
import static com.oracle.graal.python.nodes.SpecialMethodNames.__NEW__;
2929

30+
import com.oracle.graal.python.PythonLanguage;
3031
import com.oracle.graal.python.builtins.objects.cell.PCell;
3132
import com.oracle.graal.python.builtins.objects.function.Arity;
3233
import com.oracle.graal.python.builtins.objects.function.PArguments;
@@ -41,6 +42,7 @@
4142
import com.oracle.graal.python.nodes.PRootNode;
4243
import com.oracle.graal.python.nodes.argument.ApplyKeywordsNode;
4344
import com.oracle.graal.python.nodes.argument.ArityCheckNode;
45+
import com.oracle.graal.python.runtime.PythonOptions;
4446
import com.oracle.truffle.api.CallTarget;
4547
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
4648
import com.oracle.truffle.api.RootCallTarget;
@@ -59,6 +61,10 @@ abstract class AbstractInvokeNode extends Node {
5961

6062
private final ConditionProfile needsFrameProfile = ConditionProfile.createBinaryProfile();
6163

64+
protected static boolean shouldInlineGenerators() {
65+
return PythonOptions.getOption(PythonLanguage.getContextRef().get(), PythonOptions.ForceInlineGeneratorCalls);
66+
}
67+
6268
@TruffleBoundary
6369
protected static RootCallTarget getCallTarget(PythonCallable callee) {
6470
RootCallTarget callTarget;
@@ -151,7 +157,7 @@ protected CallTargetInvokeNode(CallTarget callTarget, boolean isBuiltin, boolean
151157
if (isBuiltin) {
152158
callNode.cloneCallTarget();
153159
}
154-
if (isGenerator) {
160+
if (isGenerator && shouldInlineGenerators()) {
155161
this.callNode.forceInlining();
156162
}
157163
this.isBuiltin = isBuiltin;
@@ -209,7 +215,7 @@ protected InvokeNode(CallTarget callTarget, Arity calleeArity, PythonObject glob
209215
if (isBuiltin) {
210216
callNode.cloneCallTarget();
211217
}
212-
if (isGenerator) {
218+
if (isGenerator && shouldInlineGenerators()) {
213219
this.callNode.forceInlining();
214220
}
215221
this.arity = calleeArity;

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/PythonOptions.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ private PythonOptions() {
5050
public static final OptionKey<Boolean> IntrinsifyBuiltinCalls = new OptionKey<>(true);
5151

5252
@Option(category = OptionCategory.DEBUG, help = "") //
53-
public static final OptionKey<Integer> AttributeAccessInlineCacheMaxDepth = new OptionKey<>(4);
53+
public static final OptionKey<Integer> AttributeAccessInlineCacheMaxDepth = new OptionKey<>(3);
5454

5555
@Option(category = OptionCategory.DEBUG, help = "") //
56-
public static final OptionKey<Integer> CallSiteInlineCacheMaxDepth = new OptionKey<>(4);
56+
public static final OptionKey<Integer> CallSiteInlineCacheMaxDepth = new OptionKey<>(3);
5757

5858
@Option(category = OptionCategory.DEBUG, help = "") //
5959
public static final OptionKey<Integer> VariableArgumentReadUnrollingLimit = new OptionKey<>(5);
@@ -62,7 +62,7 @@ private PythonOptions() {
6262
public static final OptionKey<Integer> VariableArgumentInlineCacheLimit = new OptionKey<>(3);
6363

6464
@Option(category = OptionCategory.DEBUG, help = "") //
65-
public static final OptionKey<Boolean> InlineGeneratorCalls = new OptionKey<>(true);
65+
public static final OptionKey<Boolean> ForceInlineGeneratorCalls = new OptionKey<>(false);
6666

6767
@Option(category = OptionCategory.DEBUG, help = "") //
6868
public static final OptionKey<Boolean> CatchGraalPythonExceptionForUnitTesting = new OptionKey<>(false);

0 commit comments

Comments
 (0)