@@ -37,7 +37,7 @@ internal static string Generate(BuildPartition buildPartition)
37
37
38
38
string passArguments = GetPassArguments ( benchmark ) ;
39
39
40
- extraDefines . Add ( $ "{ provider . ExtraDefines } _{ buildInfo . Id } ") ;
40
+ string compilationId = $ "{ provider . ReturnsDefinition } _{ buildInfo . Id } ";
41
41
42
42
AddNonEmptyUnique ( additionalLogic , benchmark . Descriptor . AdditionalLogic ) ;
43
43
@@ -64,7 +64,8 @@ internal static string Generate(BuildPartition buildPartition)
64
64
. Replace ( "$EngineFactoryType$" , GetEngineFactoryTypeName ( benchmark ) )
65
65
. Replace ( "$MeasureExtraStats$" , buildInfo . Config . HasExtraStatsDiagnoser ( ) ? "true" : "false" )
66
66
. Replace ( "$DisassemblerEntryMethodName$" , DisassemblerConstants . DisassemblerEntryMethodName )
67
- . Replace ( "$WorkloadMethodCall$" , provider . GetWorkloadMethodCall ( passArguments ) ) . ToString ( ) ;
67
+ . Replace ( "$WorkloadMethodCall$" , provider . GetWorkloadMethodCall ( passArguments ) )
68
+ . RemoveRedundantIfDefines ( compilationId ) ;
68
69
69
70
benchmarkTypeCode = Unroll ( benchmarkTypeCode , benchmark . Job . ResolveValue ( RunMode . UnrollFactorCharacteristic , EnvironmentResolver . Instance ) ) ;
70
71
@@ -122,6 +123,7 @@ private static string Unroll(string text, int factor)
122
123
const string unrollDirective = "@Unroll@" ;
123
124
const string dummyUnrollDirective = "@DummyUnroll@" ;
124
125
const int dummyUnrollFactor = 1 << 6 ;
126
+ string dummyUnrolled = string . Join ( "" , Enumerable . Repeat ( "dummyVar++;" , dummyUnrollFactor ) ) ;
125
127
var oldLines = text . Split ( '\n ' ) ;
126
128
var newLines = new List < string > ( ) ;
127
129
foreach ( string line in oldLines )
@@ -134,9 +136,7 @@ private static string Unroll(string text, int factor)
134
136
}
135
137
else if ( line . Contains ( dummyUnrollDirective ) )
136
138
{
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 ) ) ;
140
140
}
141
141
else
142
142
newLines . Add ( line ) ;
@@ -307,6 +307,31 @@ public SmartStringBuilder Replace(string oldValue, string newValue)
307
307
return this ;
308
308
}
309
309
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
+
310
335
public override string ToString ( ) => builder . ToString ( ) ;
311
336
}
312
337
}
0 commit comments