Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f052acc

Browse filesBrowse files
committed
Optimized bytecode: remove NOP from CloudLoop
1 parent fcd579f commit f052acc
Copy full SHA for f052acc

File tree

Expand file treeCollapse file tree

3 files changed

+41
-28
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+41
-28
lines changed
Open diff view settings
Collapse file

‎src/lambdacloud/core/CloudLoop.java‎

Copy file name to clipboardExpand all lines: src/lambdacloud/core/CloudLoop.java
+18-10Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -162,26 +162,34 @@ public InstructionHandle bytecodeGen(String clsName, MethodGen mg,
162162
cv.setLVTIndex(indexLVT);
163163
}
164164
}
165-
165+
InstructionHandle loopStart = null;
166166
if(this.initExpr != null)
167-
this.initExpr.bytecodeGen(clsName, mg, cp, factory, il, argsMap, argsStartPos, funcRefsMap);
168-
InstructionHandle loopStart = il.append(new NOP()); // Mark loop start position
167+
loopStart = this.initExpr.bytecodeGen(clsName, mg, cp, factory, il, argsMap, argsStartPos, funcRefsMap);
168+
169+
InstructionHandle bodyStart = null; //il.append(new NOP()); // Mark loop start position
169170
for(int i=0; i<bodyList.size(); i++) {
170171
Expr be = this.bodyList.get(i);
171-
be.bytecodeGen(clsName, mg, cp, factory, il, argsMap, argsStartPos, funcRefsMap);
172+
InstructionHandle pos = be.bytecodeGen(clsName, mg, cp, factory, il, argsMap, argsStartPos, funcRefsMap);
173+
if(bodyStart == null) bodyStart = pos;
174+
}
175+
if(this.incrementExpr != null) {
176+
InstructionHandle pos = this.incrementExpr.bytecodeGen(clsName, mg, cp, factory, il, argsMap, argsStartPos, funcRefsMap);
177+
if(bodyStart == null) bodyStart = pos;
172178
}
173-
if(this.incrementExpr != null)
174-
this.incrementExpr.bytecodeGen(clsName, mg, cp, factory, il, argsMap, argsStartPos, funcRefsMap);
175179

176-
InstructionHandle cmpStart = il.append(new NOP()); // Mark comparison start position
180+
InstructionHandle cmpStart = null; //il.append(new NOP()); // Mark comparison start position
177181
if(cond instanceof Lt) { // l < r
178-
cond.lhs().bytecodeGen(clsName, mg, cp, factory, il, argsMap, argsStartPos, funcRefsMap);
182+
cmpStart = cond.lhs().bytecodeGen(clsName, mg, cp, factory, il, argsMap, argsStartPos, funcRefsMap);
179183
cond.rhs().bytecodeGen(clsName, mg, cp, factory, il, argsMap, argsStartPos, funcRefsMap);
180-
il.append(new IF_ICMPLT(loopStart));
184+
il.append(new IF_ICMPLT(bodyStart));
181185
} //else if (...)
182186

187+
if(bodyStart != null)
188+
il.insert(bodyStart, new GOTO(cmpStart)); // goto comparison before the loop
183189

184-
return il.insert(loopStart, new GOTO(cmpStart)); // goto comparison before the loop
190+
if(loopStart == null) loopStart = bodyStart;
191+
if(loopStart == null) loopStart = cmpStart;
192+
return loopStart;
185193
}
186194

187195
public BytecodeFunc compile(Expr[] args) {
Collapse file

‎src/lambdacloud/core/operators/OPAsign.java‎

Copy file name to clipboardExpand all lines: src/lambdacloud/core/operators/OPAsign.java
+12-9Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public class OPAsign extends CloudBase {
2525
public OPAsign(Expr lhs, Expr rhs) {
2626
this.lhs = lhs;
2727
this.rhs = rhs;
28+
this.label = lhs + " = " + rhs;
2829
}
2930

3031
public void compile() {
@@ -39,16 +40,18 @@ public InstructionHandle bytecodeGen(String clsName, MethodGen mg,
3940
if(!(lhs instanceof CloudVar))
4041
throw new RuntimeException();
4142
CloudVar var = (CloudVar)lhs;
42-
rhs.bytecodeGen(clsName, mg, cp, factory, il, argsMap, argsStartPos, funcRefsMap);
43+
InstructionHandle startPos = rhs.bytecodeGen(clsName, mg, cp, factory, il, argsMap, argsStartPos, funcRefsMap);
4344
TYPE ty = lhs.getType();
4445
if(ty == TYPE.DOUBLE)
45-
return il.append(new DSTORE(var.getLVTIndex()));
46-
if(ty == TYPE.INT)
47-
return il.append(new ISTORE(var.getLVTIndex()));
48-
if(ty == TYPE.LONG)
49-
return il.append(new LSTORE(var.getLVTIndex()));
50-
if(ty == TYPE.FLOAT)
51-
return il.append(new FSTORE(var.getLVTIndex()));
52-
return il.append(new ISTORE(var.getLVTIndex()));
46+
il.append(new DSTORE(var.getLVTIndex()));
47+
else if(ty == TYPE.INT)
48+
il.append(new ISTORE(var.getLVTIndex()));
49+
else if(ty == TYPE.LONG)
50+
il.append(new LSTORE(var.getLVTIndex()));
51+
else if(ty == TYPE.FLOAT)
52+
il.append(new FSTORE(var.getLVTIndex()));
53+
else
54+
il.append(new ISTORE(var.getLVTIndex()));
55+
return startPos;
5356
}
5457
}
Collapse file

‎src/symjava/symbolic/Add.java‎

Copy file name to clipboardExpand all lines: src/symjava/symbolic/Add.java
+11-9Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -139,17 +139,19 @@ public InstructionHandle bytecodeGen(String clsName, MethodGen mg,
139139
ConstantPoolGen cp, InstructionFactory factory,
140140
InstructionList il, Map<String, Integer> argsMap, int argsStartPos,
141141
Map<Expr, Integer> funcRefsMap) {
142-
arg1.bytecodeGen(clsName, mg, cp, factory, il, argsMap, argsStartPos, funcRefsMap);
142+
InstructionHandle startPos = arg1.bytecodeGen(clsName, mg, cp, factory, il, argsMap, argsStartPos, funcRefsMap);
143143
arg2.bytecodeGen(clsName, mg, cp, factory, il, argsMap, argsStartPos, funcRefsMap);
144144
TYPE ty = Utils.getType(arg1.getType(), arg2.getType());
145145
if(ty == TYPE.DOUBLE)
146-
return il.append(InstructionConstants.DADD);
147-
if(ty == TYPE.INT)
148-
return il.append(InstructionConstants.IADD);
149-
if(ty == TYPE.LONG)
150-
return il.append(InstructionConstants.LADD);
151-
if(ty == TYPE.FLOAT)
152-
return il.append(InstructionConstants.FADD);
153-
return il.append(InstructionConstants.IADD);
146+
il.append(InstructionConstants.DADD);
147+
else if(ty == TYPE.INT)
148+
il.append(InstructionConstants.IADD);
149+
else if(ty == TYPE.LONG)
150+
il.append(InstructionConstants.LADD);
151+
else if(ty == TYPE.FLOAT)
152+
il.append(InstructionConstants.FADD);
153+
else
154+
il.append(InstructionConstants.IADD);
155+
return startPos;
154156
}
155157
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.