Skip to content

Commit a5ab7b2

Browse files
committed
[TPDE][NFC] Remove unused exclusion_mask parameter
As alloc_reg is not inlined, the always-zero exclusion mask still must be merged into the register mask. Removing the mask therefore removes one instruction from the critical path.
1 parent a60fac2 commit a5ab7b2

3 files changed

Lines changed: 15 additions & 21 deletions

File tree

tpde/include/tpde/CompilerBase.hpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -438,19 +438,19 @@ struct CompilerBase {
438438

439439
private:
440440
/// @internal Select register when a value needs to be evicted.
441-
Reg select_reg_evict(RegBank bank, u64 exclusion_mask) noexcept;
441+
Reg select_reg_evict(RegBank bank) noexcept;
442442

443443
public:
444444
/// \name Low-Level Assignment Register Handling
445445
/// @{
446446

447447
/// Select an available register, evicting loaded values if needed.
448-
Reg select_reg(RegBank bank, u64 exclusion_mask) noexcept {
449-
Reg res = register_file.find_first_free_excluding(bank, exclusion_mask);
448+
Reg select_reg(RegBank bank) noexcept {
449+
Reg res = register_file.find_first_free_excluding(bank, 0);
450450
if (res.valid()) [[likely]] {
451451
return res;
452452
}
453-
return select_reg_evict(bank, exclusion_mask);
453+
return select_reg_evict(bank);
454454
}
455455

456456
/// Reload a value part from memory or recompute variable address.
@@ -1393,10 +1393,9 @@ typename CompilerBase<Adaptor, Derived, Config>::AsmReg
13931393

13941394
template <IRAdaptor Adaptor, typename Derived, CompilerConfig Config>
13951395
Reg CompilerBase<Adaptor, Derived, Config>::select_reg_evict(
1396-
RegBank bank, u64 exclusion_mask) noexcept {
1396+
RegBank bank) noexcept {
13971397
TPDE_LOG_DBG("select_reg_evict for bank {}", bank.id());
1398-
auto candidates =
1399-
register_file.used & register_file.bank_regs(bank) & ~exclusion_mask;
1398+
auto candidates = register_file.used & register_file.bank_regs(bank);
14001399

14011400
Reg candidate = Reg::make_invalid();
14021401
u32 max_score = 0;

tpde/include/tpde/ScratchReg.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ CompilerBase<Adaptor, Derived, Config>::AsmReg
113113
return reg;
114114
}
115115

116-
reg = compiler->select_reg(bank, /*exclusion_mask=*/0);
116+
reg = compiler->select_reg(bank);
117117
reg_file.mark_used(reg, INVALID_VAL_LOCAL_IDX, 0);
118118
reg_file.mark_clobbered(reg);
119119
reg_file.mark_fixed(reg);

tpde/include/tpde/ValuePartRef.hpp

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -167,24 +167,24 @@ class CompilerBase<Adaptor, Derived, Config>::ValuePart {
167167

168168
private:
169169
template <bool Reload>
170-
void alloc_reg_impl(CompilerBase *compiler, u64 exclusion_mask) noexcept;
170+
void alloc_reg_impl(CompilerBase *compiler) noexcept;
171171
AsmReg alloc_specific_impl(CompilerBase *compiler,
172172
AsmReg reg,
173173
bool reload) noexcept;
174174

175175
public:
176176
/// Allocate and lock a register for the value part, *without* reloading the
177177
/// value. Asserts that no register is currently allocated.
178-
AsmReg alloc_reg(CompilerBase *compiler, u64 exclusion_mask = 0) noexcept {
179-
alloc_reg_impl</*Reload=*/false>(compiler, exclusion_mask);
178+
AsmReg alloc_reg(CompilerBase *compiler) noexcept {
179+
alloc_reg_impl</*Reload=*/false>(compiler);
180180
return cur_reg();
181181
}
182182

183183
/// Allocate and lock a register for the value part, *without* reloading the
184184
/// value. Does nothing if a register is already allocated.
185185
AsmReg cur_reg_or_alloc(CompilerBase *compiler) noexcept {
186186
if (!has_reg()) {
187-
alloc_reg_impl</*Reload=*/false>(compiler, 0);
187+
alloc_reg_impl</*Reload=*/false>(compiler);
188188
}
189189
return cur_reg();
190190
}
@@ -232,7 +232,7 @@ class CompilerBase<Adaptor, Derived, Config>::ValuePart {
232232
/// the stack or materializing the constant if necessary. Requires that the
233233
/// value is currently unlocked (i.e., has_reg() is false).
234234
AsmReg load_to_reg(CompilerBase *compiler) noexcept {
235-
alloc_reg_impl</*Reload=*/true>(compiler, 0);
235+
alloc_reg_impl</*Reload=*/true>(compiler);
236236
return cur_reg();
237237
}
238238

@@ -402,7 +402,7 @@ class CompilerBase<Adaptor, Derived, Config>::ValuePart {
402402
template <IRAdaptor Adaptor, typename Derived, CompilerConfig Config>
403403
template <bool Reload>
404404
void CompilerBase<Adaptor, Derived, Config>::ValuePart::alloc_reg_impl(
405-
CompilerBase *compiler, u64 exclusion_mask) noexcept {
405+
CompilerBase *compiler) noexcept {
406406
// The caller has no control over the selected register, so it must assume
407407
// that this function evicts some register. This is not permitted if the value
408408
// state ought to be the same.
@@ -414,9 +414,6 @@ void CompilerBase<Adaptor, Derived, Config>::ValuePart::alloc_reg_impl(
414414
auto ap = assignment();
415415
if (ap.register_valid()) {
416416
lock(compiler);
417-
// TODO: implement this if needed
418-
assert((exclusion_mask & (1ull << state.v.reg.id())) == 0 &&
419-
"moving registers in alloc_reg is unsupported");
420417
return;
421418
}
422419

@@ -425,7 +422,7 @@ void CompilerBase<Adaptor, Derived, Config>::ValuePart::alloc_reg_impl(
425422
bank = state.c.bank;
426423
}
427424

428-
Reg reg = compiler->select_reg(bank, exclusion_mask);
425+
Reg reg = compiler->select_reg(bank);
429426
auto &reg_file = compiler->register_file;
430427
reg_file.mark_clobbered(reg);
431428
if (has_assignment()) {
@@ -870,9 +867,7 @@ struct CompilerBase<Adaptor, Derived, Config>::ValuePartRef : ValuePart {
870867
return *this;
871868
}
872869

873-
AsmReg alloc_reg(u64 exclusion_mask = 0) noexcept {
874-
return ValuePart::alloc_reg(compiler, exclusion_mask);
875-
}
870+
AsmReg alloc_reg() noexcept { return ValuePart::alloc_reg(compiler); }
876871

877872
AsmReg cur_reg_or_alloc() noexcept {
878873
return ValuePart::cur_reg_or_alloc(compiler);

0 commit comments

Comments
 (0)