Beispiel #1
0
            public override void Visit(GuardedCast node)
            {
                //UpdateType(node, TypeCalculator.GetType(node, _cgInfo.FuncCode.Profiler));
                Profiler profile;

                _typeCalculator.GuardedCastProfile.TryGetValue(node, out profile);
                UpdateType(node, TypeCalculator.GetType(node, profile));
            }
Beispiel #2
0
        public override void Visit(GuardedCast node)
        {
            var clone = new GuardedCast(GetCloneOf(node.Expression));

            clone.ProfileIndex = node.ProfileIndex;
            unfinishedClone    = clone;
            base.Visit(node);
        }
Beispiel #3
0
        public mdr.ValueTypes GetHotPrimitiveType(GuardedCast node)
        {
            Debug.Assert(node != null, "Node cannot be null!");

            var nodeProfile = GetNodeProfile(node);

            if (nodeProfile == null)
            {
                return(mdr.ValueTypes.DValueRef);
            }

            return((nodeProfile as GuardNodeProfile).GetHotPrimitiveType());
        }
Beispiel #4
0
 public override void Visit(GuardedCast node)
 {
     base.Visit(node);
     if (_result.ValueType == mdr.ValueTypes.DValueRef && ((JSRuntime.Instance.Configuration.EnableGuardElimination && node.IsRequired) ||
                                                           !JSRuntime.Instance.Configuration.EnableGuardElimination))
     {
         int profIndex = _currFuncMetadata.GetProfileIndex(node);
         _ilGen.Dup();
         _ilGen.Call(Types.DValue.GetValueType);
         _ilGen.Ldloc(_profiler);
         _ilGen.Ldc_I4(profIndex);
         _ilGen.Call(Types.Operations.Internals.UpdateGuardProfile);
     }
 }
Beispiel #5
0
 public int GetGuardNodeIndex(GuardedCast node)
 {
     //Debug.Assert(node.ProfileIndex <= GuardProfileData.Count, "Assignment happens in codegen time");
     if (node.ProfileIndex == -1)
     {
         node.ProfileIndex = GuardProfilerCounter;
         int index = node.ProfileIndex;
         if (index >= GuardProfileData.Count)
         {
             _resizeProfileData <GuardNodeProfile>(GuardProfileData, index + 1, null);
             GuardProfileData[index] = new GuardNodeProfile(mdr.ValueTypes.Unknown);
         }
         GuardProfilerCounter++;
         if (GuardProfilerCounter > jsMD.GuardProfileSize)
         {
             jsMD.GuardProfileSize = GuardProfilerCounter;
         }
     }
     return(node.ProfileIndex);
 }
Beispiel #6
0
 public void UpdateTypeProfile(GuardedCast node, mdr.ValueTypes type)
 {
     if (node.ProfileIndex < GuardProfileData.Count && node.ProfileIndex != -1)
     {
         var prof = GuardProfileData[node.ProfileIndex];
         prof.UpdateNodeProfile(type);
     }
     else
     {
         GuardNodeProfile prof = new GuardNodeProfile(type);
         if (node.ProfileIndex == -1)
         {
             node.ProfileIndex = GuardProfileData.Count;
             GuardProfileData.Add(prof);
             jsMD.GuardProfileSize++;
         }
         else
         {
             _resizeProfileData <GuardNodeProfile>(GuardProfileData, node.ProfileIndex + 1, null);
             GuardProfileData[node.ProfileIndex] = prof;
         }
     }
 }
Beispiel #7
0
 public override void Visit(GuardedCast node)
 {
     Visit((ParenExpression)node);
 }
 public int GetProfileIndex(GuardedCast node)
 {
     return((node.ProfileIndex == -1) ? (node.ProfileIndex = GuardedCastNodeCount++) : node.ProfileIndex);
 }
Beispiel #9
0
 public override void Visit(GuardedCast node)
 {
     AssignToImplicitReturn(node);
 }
            public override void Visit(GuardedCast node)
            {
                base.Visit(node);

                if (_result.ValueType != mdr.ValueTypes.DValueRef)
                {
                    return;
                }

                var nodeProfile = _currProfiler.GetNodeProfile(node);

                if (nodeProfile != null)
                {
                    var hotType = nodeProfile.GetHotType();
                    if (hotType != mdr.ValueTypes.DValueRef)
                    {
                        var valueType = _localVars.Declare(typeof(int));
                        _ilGen.Dup();
                        _ilGen.Call(Types.DValue.GetValueType);
                        _ilGen.Conv_I4();
                        _ilGen.Dup();
                        _ilGen.Stloc(valueType);
                        _ilGen.Ldc_I4((int)hotType);
                        var success = _ilGen.DefineLabel();
                        _ilGen.Beq(success);

                        if (JSRuntime.Instance.Configuration.EnableDeoptimization)
                        {
                            /*
                             * Get the types of the values in the stack right now from the ValidatingILGenerator
                             * Encode it in a string and push it onto the stack
                             * Push the icIndex of the GuardedCast node
                             * Add the jump to the deoptimizer here
                             */
                            var vILGen = _ilGen as mjr.ILGen.ValidatingILGenerator;
                            if (vILGen != null)
                            {
                                vILGen.DeactivateValidation();
                            }

                            _ilGen.Ldarg_CallFrame();
                            _ilGen.Ldc_I4(_currFuncMetadata.ValuesLength);
                            _ilGen.NewArr(Types.DValue.TypeOf);
                            _ilGen.Stfld(Types.CallFrame.Values);

                            var types           = _ilGen.GetValueTypes();
                            var length          = types.Length;
                            var stackStartIndex = 2 + _currFuncMetadata.Scope.Symbols.Count;
                            var index           = 1;

                            /// CallFrame.Values is usually assinged like this:
                            /// +-------+---------+-------------+-----------+-----------------+
                            /// |context|arguments|...symbols...|...stack...|...temporaries...|
                            /// +-------+---------+-------------+-----------+-----------------+
                            foreach (var t in types)
                            {
                                var vType = Types.ValueTypeOf(t);
                                //Console.WriteLine("Storing Symbols is called as well!\n");
                                //_ilGen.Call(Types.Operations.Internals.PrintString);
                                _ilGen.StoreValue(stackStartIndex + length - index++, vType);
                            }

                            //_ilGen.Ldstr(valueTypesString);
                            _ilGen.Ldc_I4(node.ICIndex);
                            _ilGen.Ldloc(valueType);
                            //_ilGen.Ldstr("JSSpeculationFailed is called as well!");
                            //_ilGen.Call(Types.Operations.Internals.PrintString);
                            _ilGen.Call(Types.JSSpeculationFailedException.Throw.Get(mdr.ValueTypes.Int32));

                            if (vILGen != null)
                            {
                                vILGen.ReactivateValidation();
                            }
                        }
                        else
                        {
                            _ilGen.Ldc_I4(node.ICIndex);
                            _ilGen.Ldloc(valueType);
                            _ilGen.Call(Types.JSSpeculationFailedException.Throw.Get(mdr.ValueTypes.Int32));
                        }
                        _ilGen.MarkLabel(success);
                        AsX(hotType);
                    }
                }
            }
Beispiel #11
0
 public override void Visit(GuardedCast node)
 {
     PushLocation(node);
     VisitNode(node.Expression);
     PopLocation();
 }
Beispiel #12
0
 public GuardNodeProfile GetNodeProfile(GuardedCast node)
 {
     return(GetNodeProfile(node.ProfileIndex, GuardProfileData));
 }
Beispiel #13
0
 public GuardNodeProfile GetOrAddNodeProfile(GuardedCast node)
 {
     return(GetOrAddGuardNodeProfile(_currFuncMetadata.GetProfileIndex(node)));
 }