@@ -77,21 +77,24 @@ InlinePolicy* InlinePolicy::GetPolicy(Compiler* compiler, bool isPrejitRoot)
7777
7878#endif // defined(DEBUG) || defined(INLINE_DATA)
7979
80- InlinePolicy* policy = nullptr ;
80+ // Optionally install the ModelPolicy.
8181 bool useModelPolicy = JitConfig.JitInlinePolicyModel () != 0 ;
8282
8383 if (useModelPolicy)
8484 {
85- // Optionally install the ModelPolicy.
86- policy = new (compiler, CMK_Inlining) ModelPolicy (compiler, isPrejitRoot);
85+ return new (compiler, CMK_Inlining) ModelPolicy (compiler, isPrejitRoot);
8786 }
88- else
87+
88+ // Optionally fallback to the original legacy policy
89+ bool useLegacyPolicy = JitConfig.JitInlinePolicyLegacy () != 0 ;
90+
91+ if (useLegacyPolicy)
8992 {
90- // Use the legacy policy
91- policy = new (compiler, CMK_Inlining) LegacyPolicy (compiler, isPrejitRoot);
93+ return new (compiler, CMK_Inlining) LegacyPolicy (compiler, isPrejitRoot);
9294 }
9395
94- return policy;
96+ // Use the enhanced legacy policy by default
97+ return new (compiler, CMK_Inlining) EnhancedLegacyPolicy (compiler, isPrejitRoot);
9598}
9699
97100// ------------------------------------------------------------------------
@@ -849,6 +852,96 @@ int LegacyPolicy::CodeSizeEstimate()
849852 }
850853}
851854
855+ // ------------------------------------------------------------------------
856+ // NoteBool: handle a boolean observation with non-fatal impact
857+ //
858+ // Arguments:
859+ // obs - the current obsevation
860+ // value - the value of the observation
861+
862+ void EnhancedLegacyPolicy::NoteBool (InlineObservation obs, bool value)
863+ {
864+ switch (obs)
865+ {
866+ case InlineObservation::CALLEE_DOES_NOT_RETURN:
867+ m_IsNoReturn = value;
868+ m_IsNoReturnKnown = true ;
869+ break ;
870+
871+ default :
872+ // Pass all other information to the legacy policy
873+ LegacyPolicy::NoteBool (obs, value);
874+ break ;
875+ }
876+ }
877+
878+ // ------------------------------------------------------------------------
879+ // NoteInt: handle an observed integer value
880+ //
881+ // Arguments:
882+ // obs - the current obsevation
883+ // value - the value being observed
884+
885+ void EnhancedLegacyPolicy::NoteInt (InlineObservation obs, int value)
886+ {
887+ switch (obs)
888+ {
889+ case InlineObservation::CALLEE_NUMBER_OF_BASIC_BLOCKS:
890+ {
891+ assert (value != 0 );
892+ assert (m_IsNoReturnKnown);
893+
894+ //
895+ // Let's be conservative for now and reject inlining of "no return" methods only
896+ // if the callee contains a single basic block. This covers most of the use cases
897+ // (typical throw helpers simply do "throw new X();" and so they have a single block)
898+ // without affecting more exotic cases (loops that do actual work for example) where
899+ // failure to inline could negatively impact code quality.
900+ //
901+
902+ unsigned basicBlockCount = static_cast <unsigned >(value);
903+
904+ if (m_IsNoReturn && (basicBlockCount == 1 ))
905+ {
906+ SetNever (InlineObservation::CALLEE_DOES_NOT_RETURN);
907+ }
908+ else
909+ {
910+ LegacyPolicy::NoteInt (obs, value);
911+ }
912+
913+ break ;
914+ }
915+
916+ default :
917+ // Pass all other information to the legacy policy
918+ LegacyPolicy::NoteInt (obs, value);
919+ break ;
920+ }
921+ }
922+
923+ // ------------------------------------------------------------------------
924+ // PropagateNeverToRuntime: determine if a never result should cause the
925+ // method to be marked as un-inlinable.
926+
927+ bool EnhancedLegacyPolicy::PropagateNeverToRuntime () const
928+ {
929+ //
930+ // Do not propagate the "no return" observation. If we do this then future inlining
931+ // attempts will fail immediately without marking the call node as "no return".
932+ // This can have an adverse impact on caller's code quality as it may have to preserve
933+ // registers across the call.
934+ // TODO-Throughput: We should persist the "no return" information in the runtime
935+ // so we don't need to re-analyze the inlinee all the time.
936+ //
937+
938+ bool propagate = (m_Observation != InlineObservation::CALLEE_DOES_NOT_RETURN);
939+
940+ propagate &= LegacyPolicy::PropagateNeverToRuntime ();
941+
942+ return propagate;
943+ }
944+
852945#ifdef DEBUG
853946
854947// ------------------------------------------------------------------------
0 commit comments