@@ -37,7 +37,7 @@ internal static string Generate(BuildPartition buildPartition)
3737
3838 string passArguments = GetPassArguments ( benchmark ) ;
3939
40- extraDefines . Add ( $ "{ provider . ExtraDefines } _{ buildInfo . Id } ") ;
40+ string compilationId = $ "{ provider . ReturnsDefinition } _{ buildInfo . Id } ";
4141
4242 AddNonEmptyUnique ( additionalLogic , benchmark . Descriptor . AdditionalLogic ) ;
4343
@@ -64,7 +64,8 @@ internal static string Generate(BuildPartition buildPartition)
6464 . Replace ( "$EngineFactoryType$" , GetEngineFactoryTypeName ( benchmark ) )
6565 . Replace ( "$MeasureExtraStats$" , buildInfo . Config . HasExtraStatsDiagnoser ( ) ? "true" : "false" )
6666 . Replace ( "$DisassemblerEntryMethodName$" , DisassemblerConstants . DisassemblerEntryMethodName )
67- . Replace ( "$WorkloadMethodCall$" , provider . GetWorkloadMethodCall ( passArguments ) ) . ToString ( ) ;
67+ . Replace ( "$WorkloadMethodCall$" , provider . GetWorkloadMethodCall ( passArguments ) )
68+ . RemoveRedundantIfDefines ( compilationId ) ;
6869
6970 benchmarkTypeCode = Unroll ( benchmarkTypeCode , benchmark . Job . ResolveValue ( RunMode . UnrollFactorCharacteristic , EnvironmentResolver . Instance ) ) ;
7071
@@ -122,6 +123,7 @@ private static string Unroll(string text, int factor)
122123 const string unrollDirective = "@Unroll@" ;
123124 const string dummyUnrollDirective = "@DummyUnroll@" ;
124125 const int dummyUnrollFactor = 1 << 6 ;
126+ string dummyUnrolled = string . Join ( "" , Enumerable . Repeat ( "dummyVar++;" , dummyUnrollFactor ) ) ;
125127 var oldLines = text . Split ( '\n ' ) ;
126128 var newLines = new List < string > ( ) ;
127129 foreach ( string line in oldLines )
@@ -134,9 +136,7 @@ private static string Unroll(string text, int factor)
134136 }
135137 else if ( line . Contains ( dummyUnrollDirective ) )
136138 {
137- string newLine = line . Replace ( dummyUnrollDirective , "" ) ;
138- for ( int i = 0 ; i < dummyUnrollFactor ; i ++ )
139- newLines . Add ( newLine ) ;
139+ newLines . Add ( line . Replace ( dummyUnrollDirective , dummyUnrolled ) ) ;
140140 }
141141 else
142142 newLines . Add ( line ) ;
@@ -307,6 +307,31 @@ public SmartStringBuilder Replace(string oldValue, string newValue)
307307 return this ;
308308 }
309309
310+ public string RemoveRedundantIfDefines ( string id )
311+ {
312+ var oldLines = builder . ToString ( ) . Split ( '\n ' ) ;
313+ var newLines = new List < string > ( ) ;
314+ bool keepAdding = true ;
315+
316+ foreach ( string line in oldLines )
317+ {
318+ if ( line . StartsWith ( "#if RETURNS" ) || line . StartsWith ( "#elif RETURNS" ) )
319+ {
320+ keepAdding = line . Contains ( id ) ;
321+ }
322+ else if ( line . StartsWith ( "#endif // RETURNS" ) )
323+ {
324+ keepAdding = true ;
325+ }
326+ else if ( keepAdding )
327+ {
328+ newLines . Add ( line ) ;
329+ }
330+ }
331+
332+ return string . Join ( "\n " , newLines ) ;
333+ }
334+
310335 public override string ToString ( ) => builder . ToString ( ) ;
311336 }
312337 }
0 commit comments