Skip to content

Commit 38c6c5b

Browse files
committed
Update and fix bootstrap process logic
1 parent a2f0056 commit 38c6c5b

File tree

4 files changed

+185
-208
lines changed

4 files changed

+185
-208
lines changed

compiler-rt/lib/orc/common.h

Lines changed: 77 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,11 @@
1414
#define ORC_RT_COMMON_H
1515

1616
#include "compiler.h"
17-
#include "orc_rt/c_api.h"
18-
#include <type_traits>
19-
20-
#include "bitmask_enum.h"
21-
#include "debug.h"
2217
#include "error.h"
2318
#include "executor_address.h"
19+
#include "orc_rt/c_api.h"
20+
#include <type_traits>
2421
#include <algorithm>
25-
#include <ios>
26-
#include <map>
27-
#include <mutex>
28-
#include <sstream>
2922
#include <vector>
3023

3124
/// This macro should be used to define tags that will be associated with
@@ -60,86 +53,87 @@ __orc_rt_jit_dispatch(__orc_rt_Opaque *DispatchCtx, const void *FnTag,
6053
/// sections, selector refs, etc.)
6154
template <typename RecordElement> class RecordSectionsTracker {
6255
public:
63-
/// Add a section to the "new" list.
64-
void add(__orc_rt::span<RecordElement> Sec) { New.push_back(std::move(Sec)); }
65-
66-
/// Returns true if there are new sections to process.
67-
bool hasNewSections() const { return !New.empty(); }
68-
69-
/// Returns the number of new sections to process.
70-
size_t numNewSections() const { return New.size(); }
71-
72-
/// Process all new sections.
73-
template <typename ProcessSectionFunc>
74-
std::enable_if_t<std::is_void_v<
75-
std::invoke_result_t<ProcessSectionFunc, __orc_rt::span<RecordElement>>>>
76-
processNewSections(ProcessSectionFunc &&ProcessSection) {
77-
for (auto &Sec : New)
78-
ProcessSection(Sec);
79-
moveNewToProcessed();
80-
}
81-
82-
/// Proces all new sections with a fallible handler.
83-
///
84-
/// Successfully handled sections will be moved to the Processed
85-
/// list.
86-
template <typename ProcessSectionFunc>
87-
std::enable_if_t<
88-
std::is_same_v<__orc_rt::Error, std::invoke_result_t<ProcessSectionFunc,
89-
__orc_rt::span<RecordElement>>>,
90-
__orc_rt::Error>
91-
processNewSections(ProcessSectionFunc &&ProcessSection) {
92-
for (size_t I = 0; I != New.size(); ++I) {
93-
if (auto Err = ProcessSection(New[I])) {
94-
for (size_t J = 0; J != I; ++J)
95-
Processed.push_back(New[J]);
96-
New.erase(New.begin(), New.begin() + I);
97-
return Err;
56+
/// Add a section to the "new" list.
57+
void add(__orc_rt::span<RecordElement> Sec) { New.push_back(std::move(Sec)); }
58+
59+
/// Returns true if there are new sections to process.
60+
bool hasNewSections() const { return !New.empty(); }
61+
62+
/// Returns the number of new sections to process.
63+
size_t numNewSections() const { return New.size(); }
64+
65+
/// Process all new sections.
66+
template <typename ProcessSectionFunc>
67+
std::enable_if_t<std::is_void_v<
68+
std::invoke_result_t<ProcessSectionFunc, __orc_rt::span<RecordElement>>>>
69+
processNewSections(ProcessSectionFunc &&ProcessSection) {
70+
for (auto &Sec : New)
71+
ProcessSection(Sec);
72+
moveNewToProcessed();
73+
}
74+
75+
/// Proces all new sections with a fallible handler.
76+
///
77+
/// Successfully handled sections will be moved to the Processed
78+
/// list.
79+
template <typename ProcessSectionFunc>
80+
std::enable_if_t<
81+
std::is_same_v<__orc_rt::Error,
82+
std::invoke_result_t<ProcessSectionFunc,
83+
__orc_rt::span<RecordElement>>>,
84+
__orc_rt::Error>
85+
processNewSections(ProcessSectionFunc &&ProcessSection) {
86+
for (size_t I = 0; I != New.size(); ++I) {
87+
if (auto Err = ProcessSection(New[I])) {
88+
for (size_t J = 0; J != I; ++J)
89+
Processed.push_back(New[J]);
90+
New.erase(New.begin(), New.begin() + I);
91+
return Err;
92+
}
9893
}
94+
moveNewToProcessed();
95+
return __orc_rt::Error::success();
96+
}
97+
98+
/// Move all sections back to New for reprocessing.
99+
void reset() {
100+
moveNewToProcessed();
101+
New = std::move(Processed);
102+
}
103+
104+
/// Remove the section with the given range.
105+
bool removeIfPresent(__orc_rt::ExecutorAddrRange R) {
106+
if (removeIfPresent(New, R))
107+
return true;
108+
return removeIfPresent(Processed, R);
99109
}
100-
moveNewToProcessed();
101-
return __orc_rt::Error::success();
102-
}
103-
104-
/// Move all sections back to New for reprocessing.
105-
void reset() {
106-
moveNewToProcessed();
107-
New = std::move(Processed);
108-
}
109-
110-
/// Remove the section with the given range.
111-
bool removeIfPresent(__orc_rt::ExecutorAddrRange R) {
112-
if (removeIfPresent(New, R))
113-
return true;
114-
return removeIfPresent(Processed, R);
115-
}
116110

117111
private:
118-
void moveNewToProcessed() {
119-
if (Processed.empty())
120-
Processed = std::move(New);
121-
else {
122-
Processed.reserve(Processed.size() + New.size());
123-
std::copy(New.begin(), New.end(), std::back_inserter(Processed));
124-
New.clear();
112+
void moveNewToProcessed() {
113+
if (Processed.empty())
114+
Processed = std::move(New);
115+
else {
116+
Processed.reserve(Processed.size() + New.size());
117+
std::copy(New.begin(), New.end(), std::back_inserter(Processed));
118+
New.clear();
119+
}
125120
}
126-
}
127-
128-
bool removeIfPresent(std::vector<__orc_rt::span<RecordElement>> &V,
129-
__orc_rt::ExecutorAddrRange R) {
130-
auto RI = std::find_if(
131-
V.rbegin(), V.rend(),
132-
[RS = R.toSpan<RecordElement>()](const __orc_rt::span<RecordElement> &E) {
133-
return E.data() == RS.data();
134-
});
135-
if (RI != V.rend()) {
136-
V.erase(std::next(RI).base());
137-
return true;
121+
122+
bool removeIfPresent(std::vector<__orc_rt::span<RecordElement>> &V,
123+
__orc_rt::ExecutorAddrRange R) {
124+
auto RI = std::find_if(V.rbegin(), V.rend(),
125+
[RS = R.toSpan<RecordElement>()](
126+
const __orc_rt::span<RecordElement> &E) {
127+
return E.data() == RS.data();
128+
});
129+
if (RI != V.rend()) {
130+
V.erase(std::next(RI).base());
131+
return true;
132+
}
133+
return false;
138134
}
139-
return false;
140-
}
141135

142-
std::vector<__orc_rt::span<RecordElement>> Processed;
143-
std::vector<__orc_rt::span<RecordElement>> New;
136+
std::vector<__orc_rt::span<RecordElement>> Processed;
137+
std::vector<__orc_rt::span<RecordElement>> New;
144138
};
145139
#endif // ORC_RT_COMMON_H

0 commit comments

Comments
 (0)