43
43
#include " llvm/Support/SaveAndRestore.h"
44
44
#include " llvm/Support/Threading.h"
45
45
#include " llvm/Support/VirtualFileSystem.h"
46
+ #include " llvm/Support/WithColor.h"
46
47
#include " llvm/Target/CGPassBuilderOption.h"
47
48
#include " llvm/Target/TargetMachine.h"
48
49
#include " llvm/Transforms/Scalar.h"
@@ -172,12 +173,6 @@ static cl::opt<GlobalISelAbortMode> EnableGlobalISelAbort(
172
173
clEnumValN(GlobalISelAbortMode::DisableWithDiag, " 2" ,
173
174
" Disable the abort but emit a diagnostic on failure" )));
174
175
175
- // An option that disables inserting FS-AFDO discriminators before emit.
176
- // This is mainly for debugging and tuning purpose.
177
- static cl::opt<bool >
178
- FSNoFinalDiscrim (" fs-no-final-discrim" , cl::init(false ), cl::Hidden,
179
- cl::desc(" Do not insert FS-AFDO discriminators before "
180
- " emit." ));
181
176
// Disable MIRProfileLoader before RegAlloc. This is for for debugging and
182
177
// tuning purpose.
183
178
static cl::opt<bool > DisableRAFSProfileLoader (
@@ -1225,14 +1220,6 @@ void TargetPassConfig::addMachinePasses() {
1225
1220
addPass (&XRayInstrumentationID);
1226
1221
addPass (&PatchableFunctionID);
1227
1222
1228
- if (EnableFSDiscriminator && !FSNoFinalDiscrim)
1229
- // Add FS discriminators here so that all the instruction duplicates
1230
- // in different BBs get their own discriminators. With this, we can "sum"
1231
- // the SampleFDO counters instead of using MAX. This will improve the
1232
- // SampleFDO profile quality.
1233
- addPass (createMIRAddFSDiscriminatorsPass (
1234
- sampleprof::FSDiscriminatorPass::PassLast));
1235
-
1236
1223
addPreEmitPass ();
1237
1224
1238
1225
if (TM->Options .EnableIPRA )
@@ -1258,6 +1245,10 @@ void TargetPassConfig::addMachinePasses() {
1258
1245
addPass (createMachineOutlinerPass (RunOnAllFunctions));
1259
1246
}
1260
1247
1248
+ if (EnableFSDiscriminator)
1249
+ addPass (createMIRAddFSDiscriminatorsPass (
1250
+ sampleprof::FSDiscriminatorPass::PassLast));
1251
+
1261
1252
// Machine function splitter uses the basic block sections feature. Both
1262
1253
// cannot be enabled at the same time. Basic block sections takes precedence.
1263
1254
// FIXME: In principle, BasicBlockSection::Labels and splitting can used
@@ -1270,6 +1261,20 @@ void TargetPassConfig::addMachinePasses() {
1270
1261
addPass (llvm::createBasicBlockSectionsPass ());
1271
1262
} else if (TM->Options .EnableMachineFunctionSplitter ||
1272
1263
EnableMachineFunctionSplitter) {
1264
+ const std::string ProfileFile = getFSProfileFile (TM);
1265
+ if (!ProfileFile.empty ()) {
1266
+ if (EnableFSDiscriminator) {
1267
+ addPass (createMIRProfileLoaderPass (
1268
+ ProfileFile, getFSRemappingFile (TM),
1269
+ sampleprof::FSDiscriminatorPass::PassLast, nullptr ));
1270
+ } else {
1271
+ // Sample profile is given, but FSDiscriminator is not
1272
+ // enabled, this may result in performance regression.
1273
+ WithColor::warning ()
1274
+ << " Using AutoFDO without FSDiscriminator for MFS may regress "
1275
+ " performance." ;
1276
+ }
1277
+ }
1273
1278
addPass (createMachineFunctionSplitterPass ());
1274
1279
}
1275
1280
0 commit comments