Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(547)

Unified Diff: lib/compiler/implementation/ssa/codegen.dart

Issue 10446098: Avoid generating empty else. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | lib/compiler/implementation/ssa/variable_allocator.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/compiler/implementation/ssa/codegen.dart
===================================================================
--- lib/compiler/implementation/ssa/codegen.dart (revision 8145)
+++ lib/compiler/implementation/ssa/codegen.dart (working copy)
@@ -549,7 +549,10 @@
generateStatements(info.thenGraph);
indent--;
addIndented("}");
- if (info.elseGraph !== null) {
+ HSubGraphBlockInformation elseGraph = info.elseGraph;
+ HIf ifInstruction = info.thenGraph.start.predecessors[0].last;
Lasse Reichstein Nielsen 2012/05/31 11:57:28 Or: HIf ifInstruction = info.condition.conditionE
ngeoffray 2012/05/31 12:27:38 Done.
+ if (elseGraph !== null
+ && hasCodeUntil(elseGraph.start, ifInstruction.joinBlock)) {
Lasse Reichstein Nielsen 2012/05/31 11:57:28 I really, really don't like using the ifInstructio
ngeoffray 2012/05/31 12:27:38 Done.
buffer.add(" else {\n");
indent++;
generateStatements(info.elseGraph);
kasperl 2012/05/31 11:26:34 info.elseGraph -> elseGraph
ngeoffray 2012/05/31 11:51:29 Done.
@@ -1251,6 +1254,26 @@
compiler.internalError('visitTry should not be called', instruction: node);
}
+ bool hasCodeUntil(HBasicBlock block, HBasicBlock successor) {
kasperl 2012/05/31 11:26:34 Not sure I like the name. Maybe negate it and make
ngeoffray 2012/05/31 11:51:29 Done.
+ if (block.last is !HGoto) return true;
kasperl 2012/05/31 11:26:34 If the last instruction is a goto can the block ha
ngeoffray 2012/05/31 11:51:29 Good point! Check removed.
Lasse Reichstein Nielsen 2012/05/31 11:57:28 Sadly, HBreak and HContinue are subclasses of HGot
ngeoffray 2012/05/31 12:27:38 +1
+ if (block.successors.length != 1) return true;
+ if (block.successors[0] !== successor) return true;
+ HInstruction instruction = block.first;
kasperl 2012/05/31 11:26:34 Add a comment saying that we generate at use site
ngeoffray 2012/05/31 11:51:29 Done.
+ while (instruction != block.last) {
Lasse Reichstein Nielsen 2012/05/31 11:57:28 for-loop?
ngeoffray 2012/05/31 12:27:38 Done.
+ if (!isGenerateAtUseSite(instruction)) return true;
+ instruction = instruction.next;
+ }
+ CopyHandler handler = variableNames.getCopyHandler(block);
+ if (handler == null || handler.isEmpty()) return false;
+ if (!handler.assignments.isEmpty()) return true;
+ for (Copy copy in handler.copies) {
kasperl 2012/05/31 11:26:34 Add a comment that briefly explains what this loop
ngeoffray 2012/05/31 11:51:29 Done.
+ String sourceName = variableNames.getName(copy.source);
+ String destinationName = variableNames.getName(copy.destination);
+ if (sourceName != destinationName) return true;
Lasse Reichstein Nielsen 2012/05/31 11:57:28 Would it make sense to remove these "identity-copi
ngeoffray 2012/05/31 12:27:38 At the time where we create the copies of HInstruc
+ }
+ return false;
+ }
+
visitIf(HIf node) {
if (subGraph !== null && node.block === subGraph.end) {
if (isGeneratingExpression()) {
@@ -1279,7 +1302,7 @@
generateStatements(info.thenGraph);
preVisitedBlocks++;
endThen(node);
- if (node.hasElse) {
+ if (node.hasElse && hasCodeUntil(node.elseBlock, node.joinBlock)) {
startElse(node);
assert(node.elseBlock === dominated[1]);
generateStatements(info.elseGraph);
« no previous file with comments | « no previous file | lib/compiler/implementation/ssa/variable_allocator.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698