diff options
| author | Matthew Lugg <mlugg@mlugg.co.uk> | 2024-08-27 06:10:56 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-08-27 06:10:56 +0100 |
| commit | d3c6f7179c7a6086ab9cdbaed231da9a1f0b4dee (patch) | |
| tree | a75bc8abc129a679fce0673165e04fa7283f2823 /src/InternPool.zig | |
| parent | d9147b91a601ad2442aaa43f4dba2d01b25d803d (diff) | |
| parent | 4c0f021c2e4270c7392df7250a5d8f2431dcc54f (diff) | |
| download | zig-d3c6f7179c7a6086ab9cdbaed231da9a1f0b4dee.tar.gz zig-d3c6f7179c7a6086ab9cdbaed231da9a1f0b4dee.zip | |
Merge pull request #21214 from mlugg/branch-hint-and-export
Implement `@branchHint` and new `@export` usage
Diffstat (limited to 'src/InternPool.zig')
| -rw-r--r-- | src/InternPool.zig | 35 |
1 files changed, 17 insertions, 18 deletions
diff --git a/src/InternPool.zig b/src/InternPool.zig index 7adfae31f4..d0ade7026c 100644 --- a/src/InternPool.zig +++ b/src/InternPool.zig @@ -2121,6 +2121,17 @@ pub const Key = union(enum) { @atomicStore(FuncAnalysis, analysis_ptr, analysis, .release); } + pub fn setBranchHint(func: Func, ip: *InternPool, hint: std.builtin.BranchHint) void { + const extra_mutex = &ip.getLocal(func.tid).mutate.extra.mutex; + extra_mutex.lock(); + defer extra_mutex.unlock(); + + const analysis_ptr = func.analysisPtr(ip); + var analysis = analysis_ptr.*; + analysis.branch_hint = hint; + @atomicStore(FuncAnalysis, analysis_ptr, analysis, .release); + } + /// Returns a pointer that becomes invalid after any additions to the `InternPool`. fn zirBodyInstPtr(func: Func, ip: *InternPool) *TrackedInst.Index { const extra = ip.getLocalShared(func.tid).extra.acquire(); @@ -5575,7 +5586,7 @@ pub const Tag = enum(u8) { /// to be part of the type of the function. pub const FuncAnalysis = packed struct(u32) { state: State, - is_cold: bool, + branch_hint: std.builtin.BranchHint, is_noinline: bool, calls_or_awaits_errorable_fn: bool, stack_alignment: Alignment, @@ -5583,7 +5594,7 @@ pub const FuncAnalysis = packed struct(u32) { inferred_error_set: bool, disable_instrumentation: bool, - _: u19 = 0, + _: u17 = 0, pub const State = enum(u2) { /// The runtime function has never been referenced. @@ -8636,7 +8647,7 @@ pub fn getFuncDecl( const func_decl_extra_index = addExtraAssumeCapacity(extra, Tag.FuncDecl{ .analysis = .{ .state = .unreferenced, - .is_cold = false, + .branch_hint = .none, .is_noinline = key.is_noinline, .calls_or_awaits_errorable_fn = false, .stack_alignment = .none, @@ -8740,7 +8751,7 @@ pub fn getFuncDeclIes( const func_decl_extra_index = addExtraAssumeCapacity(extra, Tag.FuncDecl{ .analysis = .{ .state = .unreferenced, - .is_cold = false, + .branch_hint = .none, .is_noinline = key.is_noinline, .calls_or_awaits_errorable_fn = false, .stack_alignment = .none, @@ -8932,7 +8943,7 @@ pub fn getFuncInstance( const func_extra_index = addExtraAssumeCapacity(extra, Tag.FuncInstance{ .analysis = .{ .state = .unreferenced, - .is_cold = false, + .branch_hint = .none, .is_noinline = arg.is_noinline, .calls_or_awaits_errorable_fn = false, .stack_alignment = .none, @@ -9032,7 +9043,7 @@ pub fn getFuncInstanceIes( const func_extra_index = addExtraAssumeCapacity(extra, Tag.FuncInstance{ .analysis = .{ .state = .unreferenced, - .is_cold = false, + .branch_hint = .none, .is_noinline = arg.is_noinline, .calls_or_awaits_errorable_fn = false, .stack_alignment = .none, @@ -11853,18 +11864,6 @@ pub fn funcSetDisableInstrumentation(ip: *InternPool, func: Index) void { @atomicStore(FuncAnalysis, analysis_ptr, analysis, .release); } -pub fn funcSetCold(ip: *InternPool, func: Index, is_cold: bool) void { - const unwrapped_func = func.unwrap(ip); - const extra_mutex = &ip.getLocal(unwrapped_func.tid).mutate.extra.mutex; - extra_mutex.lock(); - defer extra_mutex.unlock(); - - const analysis_ptr = ip.funcAnalysisPtr(func); - var analysis = analysis_ptr.*; - analysis.is_cold = is_cold; - @atomicStore(FuncAnalysis, analysis_ptr, analysis, .release); -} - pub fn funcZirBodyInst(ip: *const InternPool, func: Index) TrackedInst.Index { const unwrapped_func = func.unwrap(ip); const item = unwrapped_func.getItem(ip); |
