Skip to content

Commit 4732acf

Browse files
chumerDSouzaM
authored andcommitted
Fix quickening generation for boxing overloads.
1 parent 665d8cb commit 4732acf

File tree

3 files changed

+50
-5
lines changed

3 files changed

+50
-5
lines changed

truffle/src/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/bytecode/generator/BytecodeDSLNodeGeneratorPlugs.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ public void notifySpecialize(FlatNodeGenFactory nodeFactory, CodeTreeBuilder bui
232232
rootNode.emitOnSpecialize(builder, "$bytecode", "$bci", BytecodeRootNodeElement.readInstruction("$bc", "$bci"), specialization.getNode().getNodeId() + "$" + specialization.getId());
233233
}
234234

235-
if (instruction.getQuickeningRoot().hasQuickenings()) {
235+
if (instruction.getQuickeningRoot().hasSpecializedQuickenings()) {
236236
if (quickenMethod == null) {
237237
quickenMethod = createQuickenMethod(nodeFactory, frameState);
238238
}

truffle/src/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/bytecode/model/InstructionModel.java

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,8 @@ public int compareTo(InstructionEncoding other) {
264264
*/
265265
public boolean returnTypeQuickening;
266266

267+
public boolean generic;
268+
267269
/*
268270
* Alternative argument specialization type for builtin quickenings. E.g. for loadLocal
269271
* parameter types.
@@ -370,6 +372,19 @@ public boolean hasQuickenings() {
370372
return !quickenedInstructions.isEmpty();
371373
}
372374

375+
public boolean isSpecializedQuickening() {
376+
return quickeningBase != null && !returnTypeQuickening && !generic;
377+
}
378+
379+
public boolean hasSpecializedQuickenings() {
380+
for (InstructionModel instr : quickenedInstructions) {
381+
if (instr.isSpecializedQuickening()) {
382+
return true;
383+
}
384+
}
385+
return false;
386+
}
387+
373388
public boolean isQuickening() {
374389
return quickeningBase != null;
375390
}
@@ -389,6 +404,25 @@ public void pp(PrettyPrinter printer) {
389404
if (signature != null) {
390405
printer.field("signature", signature);
391406
}
407+
408+
if (getQuickeningRoot().hasQuickenings()) {
409+
String quickenKind;
410+
if (quickeningBase == null) {
411+
quickenKind = "base";
412+
} else {
413+
if (isReturnTypeQuickening()) {
414+
quickenKind = "return-type";
415+
} else {
416+
if (generic) {
417+
quickenKind = "generic";
418+
} else {
419+
quickenKind = "specialized";
420+
}
421+
}
422+
}
423+
printer.field("quicken-kind", quickenKind);
424+
}
425+
392426
}
393427

394428
public boolean isTagInstrumentation() {
@@ -598,15 +632,20 @@ public boolean needsBoxingElimination(BytecodeDSLModel model, int valueIndex) {
598632

599633
public InstructionModel findSpecializedInstruction(TypeMirror type) {
600634
for (InstructionModel specialization : quickenedInstructions) {
601-
if (ElementUtils.typeEquals(type, specialization.specializedType)) {
635+
if (!specialization.generic && ElementUtils.typeEquals(type, specialization.specializedType)) {
602636
return specialization;
603637
}
604638
}
605639
return null;
606640
}
607641

608642
public InstructionModel findGenericInstruction() {
609-
return findSpecializedInstruction(null);
643+
for (InstructionModel specialization : quickenedInstructions) {
644+
if (specialization.generic) {
645+
return specialization;
646+
}
647+
}
648+
return null;
610649
}
611650

612651
public void validateAlignment() {

truffle/src/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/bytecode/parser/BytecodeDSLParser.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@ private void parseBytecodeDSLModel(TypeElement typeElement, BytecodeDSLModel mod
655655
break;
656656
}
657657
}
658-
if (isBoxingEliminatedOverload && operation.instruction.nodeData.needsRewrites(context)) {
658+
if (isBoxingEliminatedOverload && operation.instruction.nodeData.getReachableSpecializations().size() > 1) {
659659
for (List<TypeMirror> signature : expandedSignatures) {
660660
List<TypeMirror> parameterTypes = signature.subList(1, signature.size());
661661
boxingEliminationQuickenings.add(new ResolvedQuickenDecision(operation, List.of(specialization), parameterTypes));
@@ -775,6 +775,7 @@ private void parseBytecodeDSLModel(TypeElement typeElement, BytecodeDSLModel mod
775775
if (!overloadedTypes.isEmpty()) {
776776
InstructionModel specialization = model.quickenInstruction(instruction, instruction.signature, "Generic");
777777
specialization.returnTypeQuickening = false;
778+
specialization.generic = true;
778779
}
779780

780781
}
@@ -809,6 +810,7 @@ private void parseBytecodeDSLModel(TypeElement typeElement, BytecodeDSLModel mod
809810
InstructionModel specialization = model.quickenInstruction(instruction,
810811
new Signature(context.getType(void.class), List.of(context.getType(Object.class))),
811812
"Generic");
813+
specialization.generic = true;
812814
specialization.returnTypeQuickening = false;
813815

814816
InstructionModel returnTypeQuickening = model.quickenInstruction(instruction,
@@ -837,6 +839,7 @@ private void parseBytecodeDSLModel(TypeElement typeElement, BytecodeDSLModel mod
837839
InstructionModel genericQuickening = model.quickenInstruction(instruction,
838840
instruction.signature,
839841
"generic");
842+
genericQuickening.generic = true;
840843
genericQuickening.returnTypeQuickening = false;
841844
genericQuickening.specializedType = null;
842845
break;
@@ -854,6 +857,7 @@ private void parseBytecodeDSLModel(TypeElement typeElement, BytecodeDSLModel mod
854857

855858
genericQuickening = model.quickenInstruction(instruction,
856859
instruction.signature, "generic");
860+
genericQuickening.generic = true;
857861
genericQuickening.returnTypeQuickening = false;
858862
genericQuickening.specializedType = null;
859863
break;
@@ -882,6 +886,7 @@ private void parseBytecodeDSLModel(TypeElement typeElement, BytecodeDSLModel mod
882886

883887
genericQuickening = model.quickenInstruction(instruction,
884888
instruction.signature, "generic");
889+
genericQuickening.generic = true;
885890
genericQuickening.returnTypeQuickening = false;
886891
genericQuickening.specializedType = null;
887892
break;
@@ -909,6 +914,7 @@ private void parseBytecodeDSLModel(TypeElement typeElement, BytecodeDSLModel mod
909914
genericQuickening = model.quickenInstruction(instruction,
910915
instruction.signature,
911916
"generic");
917+
genericQuickening.generic = true;
912918
genericQuickening.returnTypeQuickening = false;
913919
genericQuickening.specializedType = null;
914920

@@ -936,9 +942,9 @@ private void parseBytecodeDSLModel(TypeElement typeElement, BytecodeDSLModel mod
936942
genericQuickening = model.quickenInstruction(instruction,
937943
instruction.signature,
938944
"generic");
945+
genericQuickening.generic = true;
939946
genericQuickening.returnTypeQuickening = false;
940947
genericQuickening.specializedType = null;
941-
942948
break;
943949
}
944950

0 commit comments

Comments
 (0)