Skip to content

Commit 4e979e1

Browse files
committed
IC: introduce empty
1 parent 04e3856 commit 4e979e1

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

src/asm_writing/icinfo.cpp

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ void ICInvalidator::invalidateAll() {
7676
void ICSlotInfo::clear() {
7777
ic->clear(this);
7878
decref_infos.clear();
79+
empty = true;
7980
}
8081

8182
ICSlotRewrite::ICSlotRewrite(ICInfo* ic, const char* debug_name)
@@ -175,6 +176,7 @@ void ICSlotRewrite::commit(CommitHook* hook, std::vector<void*> gc_references,
175176
}
176177

177178
llvm::sys::Memory::InvalidateInstructionCache(slot_start, ic->getSlotSize());
179+
ic_entry->empty = false;
178180
}
179181

180182
void ICSlotRewrite::addDependenceOn(ICInvalidator& invalidator) {
@@ -209,7 +211,24 @@ std::unique_ptr<ICSlotRewrite> ICInfo::startRewrite(const char* debug_name) {
209211
}
210212

211213
ICSlotInfo* ICInfo::pickEntryForRewrite(const char* debug_name) {
212-
int num_slots = getNumSlots();
214+
int num_slots = slots.size();
215+
216+
for (int _i = 0; _i < num_slots; _i++) {
217+
int i = (_i + next_slot_to_try) % num_slots;
218+
219+
ICSlotInfo& sinfo = slots[i];
220+
assert(sinfo.num_inside >= 0);
221+
if (sinfo.num_inside || !sinfo.empty)
222+
continue;
223+
224+
if (VERBOSITY() >= 4) {
225+
printf("picking %s icentry to in-use slot %d at %p\n", debug_name, i, start_addr);
226+
}
227+
228+
next_slot_to_try = i;
229+
return &sinfo;
230+
}
231+
213232
for (int _i = 0; _i < num_slots; _i++) {
214233
int i = (_i + next_slot_to_try) % num_slots;
215234

@@ -371,6 +390,15 @@ void ICInfo::clear(ICSlotInfo* icentry) {
371390

372391
// writer->endWithSlowpath();
373392
llvm::sys::Memory::InvalidateInstructionCache(start, getSlotSize());
393+
394+
for (int i = 0; i < slots.size(); ++i) {
395+
if (&slots[i] == icentry) {
396+
next_slot_to_try = i;
397+
break;
398+
}
399+
}
400+
401+
icentry->empty = true;
374402
}
375403

376404
bool ICInfo::shouldAttempt() {

src/asm_writing/icinfo.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ struct ICSlotInfo {
6060
ICInfo* ic;
6161
int idx; // the index inside the ic
6262
int num_inside; // the number of stack frames that are currently inside this slot
63+
bool empty = true;
6364

6465
std::vector<void*> gc_references;
6566
std::vector<DecrefInfo> decref_infos;

0 commit comments

Comments
 (0)