summaryrefslogtreecommitdiff
path: root/bolt
diff options
context:
space:
mode:
authorYi Kong <yikong@google.com>2023-03-31 16:07:47 +0800
committerYi Kong <yikong@google.com>2023-04-01 13:47:36 +0800
commitd788db3d193eac219a9e2a1afc785800ab7378bf (patch)
treeef416846763b00fc1f669c28fd1bd950856f9c5c /bolt
parentce616aa014e1bf2710ae3afb2e4cd814cdadb402 (diff)
downloadllvm-d788db3d193eac219a9e2a1afc785800ab7378bf.tar.gz
[BOLT][NFC] Simplify code using std::optional
Use std::optional instead of tracking if it is the first profile seen. Differential Revision: https://reviews.llvm.org/D147308
Diffstat (limited to 'bolt')
-rw-r--r--bolt/tools/merge-fdata/merge-fdata.cpp9
1 files changed, 4 insertions, 5 deletions
diff --git a/bolt/tools/merge-fdata/merge-fdata.cpp b/bolt/tools/merge-fdata/merge-fdata.cpp
index b17568efb831..61ca97971dae 100644
--- a/bolt/tools/merge-fdata/merge-fdata.cpp
+++ b/bolt/tools/merge-fdata/merge-fdata.cpp
@@ -257,8 +257,7 @@ bool isYAML(const StringRef Filename) {
void mergeLegacyProfiles(const SmallVectorImpl<std::string> &Filenames) {
errs() << "Using legacy profile format.\n";
- bool BoltedCollection = false;
- bool First = true;
+ std::optional<bool> BoltedCollection;
StringMap<uint64_t> Entries;
for (const std::string &Filename : Filenames) {
if (isYAML(Filename))
@@ -272,17 +271,18 @@ void mergeLegacyProfiles(const SmallVectorImpl<std::string> &Filenames) {
StringRef Buf = MB.get()->getBuffer();
// Check if the string "boltedcollection" is in the first line
if (Buf.startswith("boltedcollection\n")) {
- if (!First && !BoltedCollection)
+ if (!BoltedCollection.value_or(true))
report_error(
Filename,
"cannot mix profile collected in BOLT and non-BOLT deployments");
BoltedCollection = true;
Buf = Buf.drop_front(17);
} else {
- if (BoltedCollection)
+ if (BoltedCollection.value_or(false))
report_error(
Filename,
"cannot mix profile collected in BOLT and non-BOLT deployments");
+ BoltedCollection = false;
}
SmallVector<StringRef> Lines;
@@ -298,7 +298,6 @@ void mergeLegacyProfiles(const SmallVectorImpl<std::string> &Filenames) {
Count += Entries.lookup(Signature);
Entries.insert_or_assign(Signature, Count);
}
- First = false;
}
if (BoltedCollection)