| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 class SsaCodeGeneratorTask extends CompilerTask { | 5 class SsaCodeGeneratorTask extends CompilerTask { |
| 6 SsaCodeGeneratorTask(Compiler compiler) : super(compiler); | 6 SsaCodeGeneratorTask(Compiler compiler) : super(compiler); |
| 7 String get name() => 'SSA code generator'; | 7 String get name() => 'SSA code generator'; |
| 8 | 8 |
| 9 | 9 |
| 10 String buildJavaScriptFunction(FunctionElement element, | 10 String buildJavaScriptFunction(FunctionElement element, |
| (...skipping 1049 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1060 HInstruction instruction = node.first; | 1060 HInstruction instruction = node.first; |
| 1061 while (instruction != null) { | 1061 while (instruction != null) { |
| 1062 if (instruction === node.last) { | 1062 if (instruction === node.last) { |
| 1063 assignPhisOfAllSuccessors(node); | 1063 assignPhisOfAllSuccessors(node); |
| 1064 } | 1064 } |
| 1065 | 1065 |
| 1066 if (instruction is HGoto || instruction is HExit || instruction is HTry) { | 1066 if (instruction is HGoto || instruction is HExit || instruction is HTry) { |
| 1067 visit(instruction, JSPrecedence.STATEMENT_PRECEDENCE); | 1067 visit(instruction, JSPrecedence.STATEMENT_PRECEDENCE); |
| 1068 return; | 1068 return; |
| 1069 } else if (!isGenerateAtUseSite(instruction)) { | 1069 } else if (!isGenerateAtUseSite(instruction)) { |
| 1070 if (instruction is !HIf && instruction is !HTypeGuard && | 1070 if (instruction is !HIf |
| 1071 instruction is !HLoopBranch && !isGeneratingExpression()) { | 1071 && instruction is !HTypeGuard |
| 1072 && instruction is !HLoopBranch |
| 1073 && !isGeneratingExpression()) { |
| 1072 addIndentation(); | 1074 addIndentation(); |
| 1073 } | 1075 } |
| 1074 if (isGeneratingExpression()) { | 1076 if (isGeneratingExpression()) { |
| 1075 addExpressionSeparator(); | 1077 addExpressionSeparator(); |
| 1076 } | 1078 } |
| 1077 if (instruction.usedBy.isEmpty() | 1079 if (instruction.usedBy.isEmpty() |
| 1078 || instruction is HTypeGuard | 1080 || instruction is HTypeGuard |
| 1079 || instruction is HCheck) { | 1081 || instruction is HCheck) { |
| 1080 visit(instruction, JSPrecedence.STATEMENT_PRECEDENCE); | 1082 visit(instruction, JSPrecedence.STATEMENT_PRECEDENCE); |
| 1081 } else { | 1083 } else { |
| 1082 define(instruction); | 1084 define(instruction); |
| 1083 } | 1085 } |
| 1084 // Control flow instructions, and some other instructions, | 1086 // Control flow instructions, and some other instructions, |
| 1085 // know how to handle ';'. | 1087 // know how to handle ';'. |
| 1086 if (instruction is !HControlFlow && instruction is !HTypeGuard && | 1088 if (instruction is !HControlFlow |
| 1087 !isGeneratingExpression()) { | 1089 && instruction is !HTypeGuard |
| 1090 && !isGeneratingExpression()) { |
| 1088 buffer.add(';\n'); | 1091 buffer.add(';\n'); |
| 1089 } | 1092 } |
| 1090 } else if (instruction is HIf) { | 1093 } else if (instruction is HIf) { |
| 1091 HIf hif = instruction; | 1094 HIf hif = instruction; |
| 1092 // The "if" is implementing part of a logical expression. | 1095 // The "if" is implementing part of a logical expression. |
| 1093 // Skip directly forward to to its latest successor, since everything | 1096 // Skip directly forward to to its latest successor, since everything |
| 1094 // in-between must also be generateAtUseSite. | 1097 // in-between must also be generateAtUseSite. |
| 1095 assert(hif.trueBranch.id < hif.falseBranch.id); | 1098 assert(hif.trueBranch.id < hif.falseBranch.id); |
| 1096 visitBasicBlock(hif.falseBranch); | 1099 visitBasicBlock(hif.falseBranch); |
| 1097 return; | 1100 return; |
| (...skipping 779 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1877 | 1880 |
| 1878 void checkImmutableArray(HInstruction input) { | 1881 void checkImmutableArray(HInstruction input) { |
| 1879 beginExpression(JSPrecedence.PREFIX_PRECEDENCE); | 1882 beginExpression(JSPrecedence.PREFIX_PRECEDENCE); |
| 1880 buffer.add('!!'); | 1883 buffer.add('!!'); |
| 1881 use(input, JSPrecedence.MEMBER_PRECEDENCE); | 1884 use(input, JSPrecedence.MEMBER_PRECEDENCE); |
| 1882 buffer.add('.immutable\$list'); | 1885 buffer.add('.immutable\$list'); |
| 1883 endExpression(JSPrecedence.PREFIX_PRECEDENCE); | 1886 endExpression(JSPrecedence.PREFIX_PRECEDENCE); |
| 1884 } | 1887 } |
| 1885 | 1888 |
| 1886 void checkExtendableArray(HInstruction input) { | 1889 void checkExtendableArray(HInstruction input) { |
| 1887 compiler.unimplemented("check extendable array"); | 1890 beginExpression(JSPrecedence.PREFIX_PRECEDENCE); |
| 1891 buffer.add('!!'); |
| 1892 use(input, JSPrecedence.MEMBER_PRECEDENCE); |
| 1893 buffer.add('.fixed\$length'); |
| 1894 endExpression(JSPrecedence.PREFIX_PRECEDENCE); |
| 1888 } | 1895 } |
| 1889 | 1896 |
| 1890 void checkNull(HInstruction input) { | 1897 void checkNull(HInstruction input) { |
| 1891 beginExpression(JSPrecedence.EQUALITY_PRECEDENCE); | 1898 beginExpression(JSPrecedence.EQUALITY_PRECEDENCE); |
| 1892 use(input, JSPrecedence.EQUALITY_PRECEDENCE); | 1899 use(input, JSPrecedence.EQUALITY_PRECEDENCE); |
| 1893 buffer.add(" === (void 0)"); | 1900 buffer.add(" === (void 0)"); |
| 1894 endExpression(JSPrecedence.EQUALITY_PRECEDENCE); | 1901 endExpression(JSPrecedence.EQUALITY_PRECEDENCE); |
| 1895 } | 1902 } |
| 1896 | 1903 |
| 1897 void checkFunction(HInstruction input, Element element) { | 1904 void checkFunction(HInstruction input, Element element) { |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2019 buffer.add(".${name.slowToString()} === '${arguments.head}'"); | 2026 buffer.add(".${name.slowToString()} === '${arguments.head}'"); |
| 2020 endExpression(JSPrecedence.LOGICAL_AND_PRECEDENCE); | 2027 endExpression(JSPrecedence.LOGICAL_AND_PRECEDENCE); |
| 2021 }); | 2028 }); |
| 2022 } | 2029 } |
| 2023 if (node.nullOk) { | 2030 if (node.nullOk) { |
| 2024 endExpression(JSPrecedence.LOGICAL_OR_PRECEDENCE); | 2031 endExpression(JSPrecedence.LOGICAL_OR_PRECEDENCE); |
| 2025 } | 2032 } |
| 2026 } | 2033 } |
| 2027 | 2034 |
| 2028 void visitTypeConversion(HTypeConversion node) { | 2035 void visitTypeConversion(HTypeConversion node) { |
| 2029 assert(isGenerateAtUseSite(node)); | 2036 if (node.checked) { |
| 2030 use(node.inputs[0], JSPrecedence.EXPRESSION_PRECEDENCE); | 2037 Element element = node.type.computeType(compiler).element; |
| 2038 compiler.registerIsCheck(element); |
| 2039 SourceString helper; |
| 2040 String additionalArgument; |
| 2041 bool nativeCheck = |
| 2042 compiler.emitter.nativeEmitter.requiresNativeIsCheck(element); |
| 2043 beginExpression(JSPrecedence.CALL_PRECEDENCE); |
| 2044 |
| 2045 if (element == compiler.stringClass) { |
| 2046 helper = const SourceString('stringTypeCheck'); |
| 2047 } else if (element == compiler.doubleClass) { |
| 2048 helper = const SourceString('doubleTypeCheck'); |
| 2049 } else if (element == compiler.numClass) { |
| 2050 helper = const SourceString('numTypeCheck'); |
| 2051 } else if (element == compiler.boolClass) { |
| 2052 helper = const SourceString('boolTypeCheck'); |
| 2053 } else if (element == compiler.functionClass || element.isTypedef()) { |
| 2054 helper = const SourceString('functionTypeCheck'); |
| 2055 } else if (element == compiler.intClass) { |
| 2056 helper = const SourceString('intTypeCheck'); |
| 2057 } else if (Elements.isStringSupertype(element, compiler)) { |
| 2058 if (nativeCheck) { |
| 2059 helper = const SourceString('stringSuperNativeTypeCheck'); |
| 2060 } else { |
| 2061 helper = const SourceString('stringSuperTypeCheck'); |
| 2062 } |
| 2063 } else if (element === compiler.listClass) { |
| 2064 helper = const SourceString('listTypeCheck'); |
| 2065 } else { |
| 2066 additionalArgument = compiler.namer.operatorIs(element); |
| 2067 if (Elements.isListSupertype(element, compiler)) { |
| 2068 if (nativeCheck) { |
| 2069 helper = const SourceString('listSuperNativeTypeCheck'); |
| 2070 } else { |
| 2071 helper = const SourceString('listSuperTypeCheck'); |
| 2072 } |
| 2073 } else if (nativeCheck) { |
| 2074 helper = const SourceString('callTypeCheck'); |
| 2075 } else { |
| 2076 helper = const SourceString('propertyTypeCheck'); |
| 2077 } |
| 2078 } |
| 2079 Element helperElement = compiler.findHelper(helper); |
| 2080 compiler.registerStaticUse(helperElement); |
| 2081 buffer.add(compiler.namer.isolateAccess(helperElement)); |
| 2082 buffer.add('('); |
| 2083 use(node.inputs[0], JSPrecedence.EXPRESSION_PRECEDENCE); |
| 2084 if (additionalArgument !== null) buffer.add(", '$additionalArgument'"); |
| 2085 buffer.add(')'); |
| 2086 endExpression(JSPrecedence.CALL_PRECEDENCE); |
| 2087 } else { |
| 2088 use(node.inputs[0], expectedPrecedence); |
| 2089 } |
| 2031 } | 2090 } |
| 2032 } | 2091 } |
| 2033 | 2092 |
| 2034 class SsaOptimizedCodeGenerator extends SsaCodeGenerator { | 2093 class SsaOptimizedCodeGenerator extends SsaCodeGenerator { |
| 2035 SsaOptimizedCodeGenerator(compiler, work, parameters, parameterNames) | 2094 SsaOptimizedCodeGenerator(compiler, work, parameters, parameterNames) |
| 2036 : super(compiler, work, parameters, parameterNames); | 2095 : super(compiler, work, parameters, parameterNames); |
| 2037 | 2096 |
| 2038 void beginGraph(HGraph graph) {} | 2097 void beginGraph(HGraph graph) {} |
| 2039 void endGraph(HGraph graph) {} | 2098 void endGraph(HGraph graph) {} |
| 2040 | 2099 |
| (...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2428 startBailoutSwitch(); | 2487 startBailoutSwitch(); |
| 2429 } | 2488 } |
| 2430 } | 2489 } |
| 2431 | 2490 |
| 2432 void endLabeledBlock(HLabeledBlockInformation labeledBlockInfo) { | 2491 void endLabeledBlock(HLabeledBlockInformation labeledBlockInfo) { |
| 2433 if (labeledBlockInfo.body.start.hasGuards()) { | 2492 if (labeledBlockInfo.body.start.hasGuards()) { |
| 2434 endBailoutSwitch(); | 2493 endBailoutSwitch(); |
| 2435 } | 2494 } |
| 2436 } | 2495 } |
| 2437 } | 2496 } |
| OLD | NEW |