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

Side by Side Diff: pkg/compiler/lib/src/ssa/codegen.dart

Issue 2260223002: Add SSA instructions for reified type information (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: reformat Created 4 years, 4 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 unified diff | Download patch
« no previous file with comments | « pkg/compiler/lib/src/ssa/builder.dart ('k') | pkg/compiler/lib/src/ssa/nodes.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 import '../common.dart'; 5 import '../common.dart';
6 import '../common/codegen.dart' show CodegenRegistry, CodegenWorkItem; 6 import '../common/codegen.dart' show CodegenRegistry, CodegenWorkItem;
7 import '../common/tasks.dart' show CompilerTask; 7 import '../common/tasks.dart' show CompilerTask;
8 import '../compiler.dart' show Compiler; 8 import '../compiler.dart' show Compiler;
9 import '../constants/constant_system.dart'; 9 import '../constants/constant_system.dart';
10 import '../constants/values.dart'; 10 import '../constants/values.dart';
(...skipping 2837 matching lines...) Expand 10 before | Expand all | Expand 10 after
2848 } else { 2848 } else {
2849 var arguments = [ 2849 var arguments = [
2850 returnType, 2850 returnType,
2851 new js.ArrayInitializer(parameterTypes), 2851 new js.ArrayInitializer(parameterTypes),
2852 new js.ObjectInitializer(namedParameters) 2852 new js.ObjectInitializer(namedParameters)
2853 ]; 2853 ];
2854 push(js.js('#(#)', [accessHelper('buildNamedFunctionType'), arguments])); 2854 push(js.js('#(#)', [accessHelper('buildNamedFunctionType'), arguments]));
2855 } 2855 }
2856 } 2856 }
2857 2857
2858 void visitTypeInfoReadRaw(HTypeInfoReadRaw node) {
2859 use(node.inputs[0]);
2860 js.Expression receiver = pop();
2861 push(js.js(r'#.$builtinTypeInfo', receiver));
2862 }
2863
2864 void visitTypeInfoReadVariable(HTypeInfoReadVariable node) {
2865 TypeVariableElement element = node.variable.element;
2866 ClassElement context = element.enclosingClass;
2867
2868 int index = element.index;
2869 use(node.inputs[0]);
2870 js.Expression receiver = pop();
2871
2872 if (needsSubstitutionForTypeVariableAccess(context)) {
2873 js.Expression typeName =
2874 js.quoteName(backend.namer.runtimeTypeName(context));
2875 Element helperElement = helpers.getRuntimeTypeArgument;
2876 registry.registerStaticUse(
2877 new StaticUse.staticInvoke(helperElement, CallStructure.THREE_ARGS));
2878 js.Expression helper =
2879 backend.emitter.staticFunctionAccess(helperElement);
2880 push(js.js(
2881 r'#(#, #, #)', [helper, receiver, typeName, js.js.number(index)]));
2882 } else {
2883 Element helperElement = helpers.getTypeArgumentByIndex;
2884 registry.registerStaticUse(
2885 new StaticUse.staticInvoke(helperElement, CallStructure.TWO_ARGS));
2886 js.Expression helper =
2887 backend.emitter.staticFunctionAccess(helperElement);
2888 push(js.js(r'#(#, #)', [helper, receiver, js.js.number(index)]));
2889 }
2890 }
2891
2892 void visitTypeInfoExpression(HTypeInfoExpression node) {
2893 List<js.Expression> arguments = <js.Expression>[];
2894 for (HInstruction input in node.inputs) {
2895 use(input);
2896 arguments.add(pop());
2897 }
2898
2899 switch (node.kind) {
2900 case TypeInfoExpressionKind.COMPLETE:
2901 int index = 0;
2902 js.Expression result = backend.rtiEncoder.getTypeRepresentation(
2903 node.dartType, (TypeVariableType variable) => arguments[index++]);
2904 assert(index == node.inputs.length);
2905 push(result);
2906 return;
2907
2908 case TypeInfoExpressionKind.INSTANCE:
2909 // We expect only flat types for the INSTANCE representation.
2910 assert(
2911 node.dartType == (node.dartType.element as ClassElement).thisType);
2912 registry.registerInstantiatedClass(coreClasses.listClass);
2913 push(new js.ArrayInitializer(arguments)
2914 .withSourceInformation(node.sourceInformation));
2915 }
2916 }
2917
2918 bool needsSubstitutionForTypeVariableAccess(ClassElement cls) {
2919 ClassWorld classWorld = compiler.world;
2920 if (classWorld.isUsedAsMixin(cls)) return true;
2921
2922 return compiler.world.anyStrictSubclassOf(cls, (ClassElement subclass) {
2923 return !backend.rti.isTrivialSubstitution(subclass, cls);
2924 });
2925 }
2926
2858 void visitReadTypeVariable(HReadTypeVariable node) { 2927 void visitReadTypeVariable(HReadTypeVariable node) {
2859 TypeVariableElement element = node.dartType.element; 2928 TypeVariableElement element = node.dartType.element;
2860 Element helperElement = helpers.convertRtiToRuntimeType; 2929 Element helperElement = helpers.convertRtiToRuntimeType;
2861 registry.registerStaticUse( 2930 registry.registerStaticUse(
2862 new StaticUse.staticInvoke(helperElement, CallStructure.ONE_ARG)); 2931 new StaticUse.staticInvoke(helperElement, CallStructure.ONE_ARG));
2863 2932
2864 use(node.inputs[0]); 2933 use(node.inputs[0]);
2865 if (node.hasReceiver) { 2934 if (node.hasReceiver) {
2866 if (backend.isInterceptorClass(element.enclosingClass)) { 2935 if (backend.isInterceptorClass(element.enclosingClass)) {
2867 int index = element.index; 2936 int index = element.index;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
2914 registry.registerStaticUse(new StaticUse.staticInvoke( 2983 registry.registerStaticUse(new StaticUse.staticInvoke(
2915 helper, new CallStructure.unnamed(argumentCount))); 2984 helper, new CallStructure.unnamed(argumentCount)));
2916 return backend.emitter.staticFunctionAccess(helper); 2985 return backend.emitter.staticFunctionAccess(helper);
2917 } 2986 }
2918 2987
2919 @override 2988 @override
2920 void visitRef(HRef node) { 2989 void visitRef(HRef node) {
2921 visit(node.value); 2990 visit(node.value);
2922 } 2991 }
2923 } 2992 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/ssa/builder.dart ('k') | pkg/compiler/lib/src/ssa/nodes.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698