Skip to content

Commit

Permalink
Working on inline method compiler optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
mirkosertic committed Apr 16, 2024
1 parent 9359156 commit be6d241
Show file tree
Hide file tree
Showing 82 changed files with 785 additions and 161 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,115 +105,121 @@ private void visitDominationTreeOf(final ControlTokenConsumer startNode, final S
};

while (current != null) {
switch (current.nodeType) {
case TryCatch: {
// Special-Case : branching
visit((TryCatch) current, activeStack);
current = null;
break;
}
case If: {
// Special-Case : branching
visit((If) current, activeStack);
current = null;
break;
}
case TableSwitch: {
// Special-Case : branching
visit((TableSwitch) current, activeStack);
current = null;
break;
}
case LookupSwitch: {
// Special-Case : branching
visit((LookupSwitch) current, activeStack);
current = null;
break;
}
case Region: {
visit((Region) current, activeStack);
current = followUpProcessor.apply(current);
break;
}
case MethodInvocation: {
codegenerator.write((MethodInvocation) current);
current = followUpProcessor.apply(current);
break;
}
case Copy: {
codegenerator.write((Copy) current);
current = followUpProcessor.apply(current);
break;
}
case Return: {
codegenerator.write((Return) current);
// We are finished here
current = null;
break;
}
case ReturnValue: {
codegenerator.write((ReturnValue) current);
// We are finished here
current = null;
break;
}
case SetInstanceField: {
codegenerator.write((SetInstanceField) current);
current = followUpProcessor.apply(current);
break;
}
case ArrayStore: {
codegenerator.write((ArrayStore) current);
current = followUpProcessor.apply(current);
break;
}
case SetClassField: {
codegenerator.write((SetClassField) current);
current = followUpProcessor.apply(current);
break;
}
case LineNumberDebugInfo: {
codegenerator.write((LineNumberDebugInfo) current);
current = followUpProcessor.apply(current);
break;
}
case FrameDebugInfo: {
codegenerator.write((FrameDebugInfo) current);
current = followUpProcessor.apply(current);
break;
}
case Goto: {
codegenerator.write((Goto) current);
current = followUpProcessor.apply(current);
break;
}
case MonitorEnter: {
codegenerator.write((MonitorEnter) current);
current = followUpProcessor.apply(current);
break;
}
case MonitorExit: {
codegenerator.write((MonitorExit) current);
current = followUpProcessor.apply(current);
break;
}
case Unwind: {
codegenerator.write((Unwind) current);
// We are finished here
current = null;
break;
}
case ClassInitialization: {
codegenerator.write((ClassInitialization) current);
current = followUpProcessor.apply(current);
break;
}
case Nop: {
current = followUpProcessor.apply(current);
break;
try {
switch (current.nodeType) {
case TryCatch: {
// Special-Case : branching
visit((TryCatch) current, activeStack);
current = null;
break;
}
case If: {
// Special-Case : branching
visit((If) current, activeStack);
current = null;
break;
}
case TableSwitch: {
// Special-Case : branching
visit((TableSwitch) current, activeStack);
current = null;
break;
}
case LookupSwitch: {
// Special-Case : branching
visit((LookupSwitch) current, activeStack);
current = null;
break;
}
case Region: {
visit((Region) current, activeStack);
current = followUpProcessor.apply(current);
break;
}
case MethodInvocation: {
codegenerator.write((MethodInvocation) current);
current = followUpProcessor.apply(current);
break;
}
case Copy: {
codegenerator.write((Copy) current);
current = followUpProcessor.apply(current);
break;
}
case Return: {
codegenerator.write((Return) current);
// We are finished here
current = null;
break;
}
case ReturnValue: {
codegenerator.write((ReturnValue) current);
// We are finished here
current = null;
break;
}
case SetInstanceField: {
codegenerator.write((SetInstanceField) current);
current = followUpProcessor.apply(current);
break;
}
case ArrayStore: {
codegenerator.write((ArrayStore) current);
current = followUpProcessor.apply(current);
break;
}
case SetClassField: {
codegenerator.write((SetClassField) current);
current = followUpProcessor.apply(current);
break;
}
case LineNumberDebugInfo: {
codegenerator.write((LineNumberDebugInfo) current);
current = followUpProcessor.apply(current);
break;
}
case FrameDebugInfo: {
codegenerator.write((FrameDebugInfo) current);
current = followUpProcessor.apply(current);
break;
}
case Goto: {
codegenerator.write((Goto) current);
current = followUpProcessor.apply(current);
break;
}
case MonitorEnter: {
codegenerator.write((MonitorEnter) current);
current = followUpProcessor.apply(current);
break;
}
case MonitorExit: {
codegenerator.write((MonitorExit) current);
current = followUpProcessor.apply(current);
break;
}
case Unwind: {
codegenerator.write((Unwind) current);
// We are finished here
current = null;
break;
}
case ClassInitialization: {
codegenerator.write((ClassInitialization) current);
current = followUpProcessor.apply(current);
break;
}
case Nop: {
current = followUpProcessor.apply(current);
break;
}
default:
throw new IllegalStateException("Unsupported node type : " + current.nodeType);
}
default:
throw new IllegalStateException("Unsupported node type : " + current.nodeType);
} catch (final IllegalStateException e) {
throw e;
} catch (final RuntimeException e) {
throw new RuntimeException("Error processing node #" + graph.nodes().indexOf(current) + " " + current.nodeType + current.additionalDebugInfo(), e);
}
}

Expand Down
5 changes: 5 additions & 0 deletions core/src/main/java/de/mirkosertic/bytecoder/core/ir/Add.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,9 @@ public class Add extends Value {
Add(final Graph owner, final Type type) {
super(owner, type, NodeType.Add);
}

@Override
public Add stampInto(final Graph target) {
return target.newAdd(type);
}
}
5 changes: 5 additions & 0 deletions core/src/main/java/de/mirkosertic/bytecoder/core/ir/And.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,9 @@ public class And extends Value {
And(final Graph owner, final Type type) {
super(owner, type, NodeType.And);
}

@Override
public And stampInto(final Graph target) {
return target.newAND(type);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,9 @@ public class ArrayLength extends Value {
ArrayLength(final Graph owner) {
super(owner, Type.INT_TYPE, NodeType.ArrayLength);
}

@Override
public ArrayLength stampInto(final Graph target) {
return target.newArrayLength();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,9 @@ public class ArrayLoad extends Value {
ArrayLoad(final Graph owner, final Type type) {
super(owner, type, NodeType.ArrayLoad);
}

@Override
public ArrayLoad stampInto(final Graph target) {
return target.newArrayLoad(type);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,9 @@ public class ArrayStore extends ControlTokenConsumer {
public boolean hasSideSideEffect() {
return true;
}

@Override
public ArrayStore stampInto(final Graph target) {
return target.newArrayStore();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,9 @@ public class BootstrapMethod extends Value {
public boolean isConstant() {
return true;
}

@Override
public BootstrapMethod stampInto(final Graph target) {
return target.newBootstrapMethod(methodType, className, methodName, kind);
}
}
5 changes: 5 additions & 0 deletions core/src/main/java/de/mirkosertic/bytecoder/core/ir/CMP.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,9 @@ public class CMP extends Value {
CMP(final Graph owner) {
super(owner, Type.INT_TYPE, NodeType.CMP);
}

@Override
public CMP stampInto(final Graph target) {
return target.newCMP();
}
}
5 changes: 5 additions & 0 deletions core/src/main/java/de/mirkosertic/bytecoder/core/ir/Cast.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,9 @@ public class Cast extends Value {
Cast(final Graph owner, final Type type) {
super(owner, type, NodeType.Cast);
}

@Override
public Cast stampInto(final Graph target) {
return target.newCast(type);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,9 @@ public class CaughtException extends Value {
public boolean isConstant() {
return true;
}

@Override
public CaughtException stampInto(final Graph target) {
return target.newCaughtException(type);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,17 @@ public class ClassInitialization extends ControlTokenConsumer {
this.type = type;
}

@Override
public String additionalDebugInfo() {
return ": " + type.getClassName();
}

public void deleteFromControlFlow() {
owner.deleteFromControlFlowInternally(this);
}

@Override
public ClassInitialization stampInto(final Graph target) {
return target.newClassInitialization(type);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,30 @@ public boolean hasIncomingBackEdges() {
}
return false;
}

public void replaceInControlFlow(final ControlTokenConsumer source, final ControlTokenConsumer target) {
final Set<Projection> keys = new HashSet<>(controlFlowsTo.keySet());
for (final Projection p : keys) {
final ControlTokenConsumer t = controlFlowsTo.get(p);
if (t == source) {
controlFlowsTo.put(p, target);
}
}
target.controlComingFrom.add(this);
}

@Override
public void sanityCheck() {
super.sanityCheck();
for (final ControlTokenConsumer source : controlComingFrom) {
if (!owner.nodes().contains(source)) {
throw new IllegalStateException("ControlToken from " + source + " is not part of the graph!");
}
}
for (final ControlTokenConsumer target : controlFlowsTo.values()) {
if (!owner.nodes().contains(target)) {
throw new IllegalStateException("ControlToken to " + target + " is not part of the graph!");
}
}
}
}
5 changes: 5 additions & 0 deletions core/src/main/java/de/mirkosertic/bytecoder/core/ir/Copy.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,9 @@ public class Copy extends ControlTokenConsumer {
public void deleteFromControlFlow() {
owner.deleteFromControlFlowInternally(this);
}

@Override
public Copy stampInto(final Graph target) {
return target.newCopy();
}
}
5 changes: 5 additions & 0 deletions core/src/main/java/de/mirkosertic/bytecoder/core/ir/Div.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,9 @@ public class Div extends Value {
Div(final Graph owner, final Type type) {
super(owner, type, NodeType.Div);
}

@Override
public Div stampInto(final Graph target) {
return target.newDiv(type);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,9 @@ public class EnumValuesOf extends Value {
EnumValuesOf(final Graph owner, final Type type) {
super(owner, type, NodeType.EnumValuesOf);
}

@Override
public EnumValuesOf stampInto(final Graph target) {
return target.newEnumValuesOf(type);
}
}
Loading

0 comments on commit be6d241

Please sign in to comment.