[InstrProf][attempt 2] Add new format for -fprofile-list=

In D130807 we added the `skipprofile` attribute. This commit
changes the format so we can either `forbid` or `skip` profiling
functions by adding the `noprofile` or `skipprofile` attributes,
respectively. The behavior of the original format remains
unchanged.

Also, add the `skipprofile` attribute when using
`-fprofile-function-groups`.

This was originally landed as https://reviews.llvm.org/D130808 but was
reverted due to a Windows test failure.

Differential Revision: https://reviews.llvm.org/D131195
This commit is contained in:
Ellis Hoag
2022-07-29 14:49:44 -07:00
parent 73b62f8135
commit 6f4c3c0f64
8 changed files with 184 additions and 76 deletions

View File

@@ -2895,46 +2895,44 @@ bool CodeGenModule::imbueXRayAttrs(llvm::Function *Fn, SourceLocation Loc,
return true;
}
bool CodeGenModule::isFunctionBlockedByProfileList(llvm::Function *Fn,
SourceLocation Loc) const {
ProfileList::ExclusionType
CodeGenModule::isFunctionBlockedByProfileList(llvm::Function *Fn,
SourceLocation Loc) const {
const auto &ProfileList = getContext().getProfileList();
// If the profile list is empty, then instrument everything.
if (ProfileList.isEmpty())
return false;
return ProfileList::Allow;
CodeGenOptions::ProfileInstrKind Kind = getCodeGenOpts().getProfileInstr();
// First, check the function name.
Optional<bool> V = ProfileList.isFunctionExcluded(Fn->getName(), Kind);
if (V)
if (auto V = ProfileList.isFunctionExcluded(Fn->getName(), Kind))
return *V;
// Next, check the source location.
if (Loc.isValid()) {
Optional<bool> V = ProfileList.isLocationExcluded(Loc, Kind);
if (V)
if (Loc.isValid())
if (auto V = ProfileList.isLocationExcluded(Loc, Kind))
return *V;
}
// If location is unknown, this may be a compiler-generated function. Assume
// it's located in the main file.
auto &SM = Context.getSourceManager();
if (const auto *MainFile = SM.getFileEntryForID(SM.getMainFileID())) {
Optional<bool> V = ProfileList.isFileExcluded(MainFile->getName(), Kind);
if (V)
if (const auto *MainFile = SM.getFileEntryForID(SM.getMainFileID()))
if (auto V = ProfileList.isFileExcluded(MainFile->getName(), Kind))
return *V;
}
return ProfileList.getDefault();
return ProfileList.getDefault(Kind);
}
bool CodeGenModule::isFunctionBlockedFromProfileInstr(
llvm::Function *Fn, SourceLocation Loc) const {
if (isFunctionBlockedByProfileList(Fn, Loc))
return true;
ProfileList::ExclusionType
CodeGenModule::isFunctionBlockedFromProfileInstr(llvm::Function *Fn,
SourceLocation Loc) const {
auto V = isFunctionBlockedByProfileList(Fn, Loc);
if (V != ProfileList::Allow)
return V;
auto NumGroups = getCodeGenOpts().ProfileTotalFunctionGroups;
if (NumGroups > 1) {
auto Group = llvm::crc32(arrayRefFromStringRef(Fn->getName())) % NumGroups;
if (Group != getCodeGenOpts().ProfileSelectedFunctionGroup)
return true;
return ProfileList::Skip;
}
return false;
return ProfileList::Allow;
}
bool CodeGenModule::MustBeEmitted(const ValueDecl *Global) {