34 "Reads and parses a basic block sections profile.",
false,
41std::pair<bool, SmallVector<BBClusterInfo>>
44 auto R = ProgramBBClusterInfo.
find(getAliasName(FuncName));
45 return R != ProgramBBClusterInfo.
end()
46 ? std::pair(
true,
R->second)
64Error BasicBlockSectionsProfileReader::ReadV1Profile() {
65 auto FI = ProgramBBClusterInfo.
end();
68 unsigned CurrentCluster = 0;
70 unsigned CurrentPosition = 0;
82 char Specifier = S[0];
83 S = S.drop_front().trim();
90 if (Values.
size() != 1) {
91 return createProfileParseError(
Twine(
"invalid module name value: '") +
98 auto It = FunctionNameToDIFilename.find(Alias);
100 if (It == FunctionNameToDIFilename.end())
104 return DIFilename.
empty() || It->second.equals(DIFilename);
106 if (!FunctionFound) {
109 FI = ProgramBBClusterInfo.
end();
113 for (
size_t i = 1; i < Values.
size(); ++i)
114 FuncAliasMap.try_emplace(Values[i], Values.
front());
122 return createProfileParseError(
"duplicate profile for function '" +
123 Values.
front() +
"'");
135 if (FI == ProgramBBClusterInfo.
end())
139 for (
auto BBIDStr : Values) {
140 unsigned long long BBID;
142 return createProfileParseError(
Twine(
"unsigned integer expected: '") +
144 if (!FuncBBIDs.
insert(BBID).second)
145 return createProfileParseError(
146 Twine(
"duplicate basic block id found '") + BBIDStr +
"'");
147 if (BBID == 0 && CurrentPosition)
148 return createProfileParseError(
149 "entry BB (0) does not begin a cluster");
151 FI->second.emplace_back(
157 return createProfileParseError(
Twine(
"invalid specifier: '") +
158 Twine(Specifier) +
"'");
164Error BasicBlockSectionsProfileReader::ReadV0Profile() {
165 auto FI = ProgramBBClusterInfo.
end();
168 unsigned CurrentCluster = 0;
170 unsigned CurrentPosition = 0;
181 if (!S.consume_front(
"!") || S.empty())
184 if (S.consume_front(
"!")) {
187 if (FI == ProgramBBClusterInfo.
end())
193 for (
auto BBIDStr : BBIDs) {
194 unsigned long long BBID;
196 return createProfileParseError(
Twine(
"unsigned integer expected: '") +
198 if (!FuncBBIDs.
insert(BBID).second)
199 return createProfileParseError(
200 Twine(
"duplicate basic block id found '") + BBIDStr +
"'");
201 if (BBID == 0 && CurrentPosition)
202 return createProfileParseError(
203 "entry BB (0) does not begin a cluster");
205 FI->second.emplace_back(
212 auto [AliasesStr, DIFilenameStr] = S.split(
' ');
214 if (DIFilenameStr.startswith(
"M=")) {
217 if (DIFilename.
empty())
218 return createProfileParseError(
"empty module name specifier");
219 }
else if (!DIFilenameStr.empty()) {
220 return createProfileParseError(
"unknown string found: '" +
221 DIFilenameStr +
"'");
227 AliasesStr.split(Aliases,
'/');
229 auto It = FunctionNameToDIFilename.find(Alias);
231 if (It == FunctionNameToDIFilename.end())
235 return DIFilename.
empty() || It->second.equals(DIFilename);
237 if (!FunctionFound) {
240 FI = ProgramBBClusterInfo.
end();
243 for (
size_t i = 1; i < Aliases.
size(); ++i)
244 FuncAliasMap.try_emplace(Aliases[i], Aliases.
front());
252 return createProfileParseError(
"duplicate profile for function '" +
253 Aliases.
front() +
"'");
279Error BasicBlockSectionsProfileReader::ReadProfile() {
282 unsigned long long Version = 0;
284 if (FirstLine.consume_front(
"v")) {
286 return createProfileParseError(
Twine(
"version number expected: '") +
290 return createProfileParseError(
Twine(
"invalid profile version: ") +
299 return ReadV0Profile();
301 return ReadV1Profile();
311 FunctionNameToDIFilename.clear();
314 if (
F.isDeclaration())
322 [[maybe_unused]]
bool inserted =
323 FunctionNameToDIFilename.try_emplace(
F.getName(), DIFilename).second;
326 if (
auto Err = ReadProfile())
This file defines the StringMap class.
bool getBBClusterInfoForFunction(const MachineFunction &MF, BasicBlockSectionsProfileReader *BBSectionsProfileReader, DenseMap< unsigned, BBClusterInfo > &V)
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallSet class.
This file defines the SmallString class.
This file defines the SmallVector class.
std::pair< bool, SmallVector< BBClusterInfo > > getBBClusterInfoForFunction(StringRef FuncName) const
bool doInitialization(Module &M) override
doInitialization - Virtual method overridden by subclasses to do any necessary initialization before ...
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
ImmutablePass class - This class is used to provide information that does not need to be run.
This interface provides simple read-only access to a block of memory, and provides simple methods for...
A Module instance is used to store all the information related to an LLVM module.
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
std::pair< const_iterator, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
iterator find(StringRef Key)
std::pair< iterator, bool > try_emplace(StringRef Key, ArgsTy &&...Args)
Emplace a new element for the specified key into the map if the key isn't already in the map.
StringRef - Represent a constant reference to a string, i.e.
constexpr bool empty() const
empty - Check if the string is empty.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
bool is_at_eof() const
Return true if we've reached EOF or are an "end" iterator.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
StringRef remove_leading_dotslash(StringRef path, Style style=Style::native)
Remove redundant leading "./" pieces and consecutive separators.
This is an optimization pass for GlobalISel generic memory operations.
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
bool getAsUnsignedInteger(StringRef Str, unsigned Radix, unsigned long long &Result)
Helper functions for StringRef::getAsInteger.
ImmutablePass * createBasicBlockSectionsProfileReaderPass(const MemoryBuffer *Buf)
Implement std::hash so that hash_code can be used in STL containers.