private ATranslatedSub TranslateSubroutine(AMemory Memory, long Position) { (ABlock[] Graph, ABlock Root)Cfg = ADecoder.DecodeSubroutine(this, Memory, Position); string SubName = SymbolTable.GetOrAdd(Position, $"Sub{Position:x16}"); PropagateName(Cfg.Graph, SubName); AILEmitterCtx Context = new AILEmitterCtx( this, Cfg.Graph, Cfg.Root, SubName); if (Context.CurrBlock.Position != Position) { Context.Emit(OpCodes.Br, Context.GetLabel(Position)); } do { Context.EmitOpCode(); }while (Context.AdvanceOpCode()); //Mark all methods that calls this method for ReJiting, //since we can now call it directly which is faster. foreach (ATranslatedSub TS in CachedSubs.Values) { if (TS.SubCalls.Contains(Position)) { TS.MarkForReJit(); } } ATranslatedSub Subroutine = Context.GetSubroutine(); CachedSubs.AddOrUpdate(Position, Subroutine, (Key, OldVal) => Subroutine); return(Subroutine); }
private void TranslateTier1(AThreadState State, AMemory Memory, long Position) { (ABlock[] Graph, ABlock Root)Cfg = ADecoder.DecodeSubroutine(State, this, Memory, Position); string SubName = GetSubName(Position); PropagateName(Cfg.Graph, SubName); AILEmitterCtx Context = new AILEmitterCtx(this, Cfg.Graph, Cfg.Root, SubName); if (Context.CurrBlock.Position != Position) { Context.Emit(OpCodes.Br, Context.GetLabel(Position)); } do { Context.EmitOpCode(); }while (Context.AdvanceOpCode()); //Mark all methods that calls this method for ReJiting, //since we can now call it directly which is faster. if (CachedSubs.TryGetValue(Position, out ATranslatedSub OldSub)) { foreach (long CallerPos in OldSub.GetCallerPositions()) { if (CachedSubs.TryGetValue(Position, out ATranslatedSub CallerSub)) { CallerSub.MarkForReJit(); } } } ATranslatedSub Subroutine = Context.GetSubroutine(); Subroutine.SetType(ATranslatedSubType.SubTier1); CachedSubs.AddOrUpdate(Position, Subroutine, (Key, OldVal) => Subroutine); }
private ATranslatedSub TranslateSubroutine(long Position) { (ABlock[] Graph, ABlock Root)Cfg = ADecoder.DecodeSubroutine(this, Position); AILEmitterCtx Context = new AILEmitterCtx( this, Cfg.Graph, Cfg.Root); if (Context.CurrBlock.Position != Position) { Context.Emit(OpCodes.Br, Context.GetLabel(Position)); } do { Context.EmitOpCode(); }while (Context.AdvanceOpCode()); //Mark all methods that calls this method for ReJiting, //since we can now call it directly which is faster. foreach (ATranslatedSub TS in CachedSubs.Values) { if (TS.SubCalls.Contains(Position)) { TS.MarkForReJit(); } } ATranslatedSub Subroutine = Context.GetSubroutine(); if (!CachedSubs.TryAdd(Position, Subroutine)) { CachedSubs[Position] = Subroutine; } return(Subroutine); }