InternPool: pass by const pointer

The Zig language allows the compiler to make this optimization
automatically. We should definitely make the compiler do that, and
revert this commit. However, that will not happen in this branch, and I
want to continue to explore achieving performance parity with
merge-base. So, this commit changes all InternPool parameters to be
passed by const pointer rather than by value.

I measured a 1.03x ± 0.03 speedup vs the previous commit compiling the
(set of passing) behavior tests. Against merge-base, this commit is
1.17x ± 0.04 slower, which is an improvement from the previous
measurement of 1.22x ± 0.02.

Related issue: #13510
Related issue: #14129
Related issue: #15688
This commit is contained in:
Andrew Kelley
2023-05-30 13:54:22 -07:00
parent 6b81546454
commit 90a877f462
17 changed files with 94 additions and 94 deletions
+3 -3
View File
@@ -489,12 +489,12 @@ pub const Function = struct {
fn typeOf(f: *Function, inst: Air.Inst.Ref) Type {
const mod = f.object.dg.module;
return f.air.typeOf(inst, mod.intern_pool);
return f.air.typeOf(inst, &mod.intern_pool);
}
fn typeOfIndex(f: *Function, inst: Air.Inst.Index) Type {
const mod = f.object.dg.module;
return f.air.typeOfIndex(inst, mod.intern_pool);
return f.air.typeOfIndex(inst, &mod.intern_pool);
}
};
@@ -2808,7 +2808,7 @@ fn genBodyInner(f: *Function, body: []const Air.Inst.Index) error{ AnalysisFail,
const air_tags = f.air.instructions.items(.tag);
for (body) |inst| {
if (f.liveness.isUnused(inst) and !f.air.mustLower(inst, ip.*))
if (f.liveness.isUnused(inst) and !f.air.mustLower(inst, ip))
continue;
const result_value = switch (air_tags[inst]) {
+5 -5
View File
@@ -1574,7 +1574,7 @@ pub const Object = struct {
},
.Pointer => {
// Normalize everything that the debug info does not represent.
const ptr_info = Type.ptrInfoIp(mod.intern_pool, ty.toIntern());
const ptr_info = Type.ptrInfoIp(&mod.intern_pool, ty.toIntern());
if (ptr_info.sentinel != .none or
ptr_info.address_space != .generic or
@@ -4330,7 +4330,7 @@ pub const FuncGen = struct {
const ip = &mod.intern_pool;
const air_tags = self.air.instructions.items(.tag);
for (body, 0..) |inst, i| {
if (self.liveness.isUnused(inst) and !self.air.mustLower(inst, ip.*))
if (self.liveness.isUnused(inst) and !self.air.mustLower(inst, ip))
continue;
const opt_value: ?*llvm.Value = switch (air_tags[inst]) {
@@ -8055,7 +8055,7 @@ pub const FuncGen = struct {
const mod = fg.dg.module;
const ip = &mod.intern_pool;
for (body_tail[1..]) |body_inst| {
switch (fg.liveness.categorizeOperand(fg.air, body_inst, body_tail[0], ip.*)) {
switch (fg.liveness.categorizeOperand(fg.air, body_inst, body_tail[0], ip)) {
.none => continue,
.write, .noret, .complex => return false,
.tomb => return true,
@@ -9920,12 +9920,12 @@ pub const FuncGen = struct {
fn typeOf(fg: *FuncGen, inst: Air.Inst.Ref) Type {
const mod = fg.dg.module;
return fg.air.typeOf(inst, mod.intern_pool);
return fg.air.typeOf(inst, &mod.intern_pool);
}
fn typeOfIndex(fg: *FuncGen, inst: Air.Inst.Index) Type {
const mod = fg.dg.module;
return fg.air.typeOfIndex(inst, mod.intern_pool);
return fg.air.typeOfIndex(inst, &mod.intern_pool);
}
};
+3 -3
View File
@@ -1688,7 +1688,7 @@ pub const DeclGen = struct {
const mod = self.module;
const ip = &mod.intern_pool;
// TODO: remove now-redundant isUnused calls from AIR handler functions
if (self.liveness.isUnused(inst) and !self.air.mustLower(inst, ip.*))
if (self.liveness.isUnused(inst) and !self.air.mustLower(inst, ip))
return;
const air_tags = self.air.instructions.items(.tag);
@@ -3339,11 +3339,11 @@ pub const DeclGen = struct {
fn typeOf(self: *DeclGen, inst: Air.Inst.Ref) Type {
const mod = self.module;
return self.air.typeOf(inst, mod.intern_pool);
return self.air.typeOf(inst, &mod.intern_pool);
}
fn typeOfIndex(self: *DeclGen, inst: Air.Inst.Index) Type {
const mod = self.module;
return self.air.typeOfIndex(inst, mod.intern_pool);
return self.air.typeOfIndex(inst, &mod.intern_pool);
}
};