diff options
| author | mingmingl <mingmingl@google.com> | 2025-10-06 23:45:27 -0700 |
|---|---|---|
| committer | mingmingl <mingmingl@google.com> | 2025-10-07 00:10:26 -0700 |
| commit | 4ead381c76adfef914463426d72a6e318e833352 (patch) | |
| tree | d68862e6865c3999a6b2842c1dfbbe70685d43e6 | |
| parent | bc8e67a42de1f2b22cdde0dd186d505d2c15d1ec (diff) | |
| download | llvm-users/mingmingl-llvm/annotator.zip llvm-users/mingmingl-llvm/annotator.tar.gz llvm-users/mingmingl-llvm/annotator.tar.bz2 | |
simplify test. The next step is to add debug logusers/mingmingl-llvm/annotator-backupusers/mingmingl-llvm/annotator
| -rw-r--r-- | llvm/include/llvm/Analysis/StaticDataProfileInfo.h | 2 | ||||
| -rw-r--r-- | llvm/lib/Analysis/StaticDataProfileInfo.cpp | 7 | ||||
| -rw-r--r-- | llvm/lib/CodeGen/StaticDataSplitter.cpp | 3 | ||||
| -rw-r--r-- | llvm/test/CodeGen/X86/global-variable-partition-dap.ll | 146 |
4 files changed, 63 insertions, 95 deletions
diff --git a/llvm/include/llvm/Analysis/StaticDataProfileInfo.h b/llvm/include/llvm/Analysis/StaticDataProfileInfo.h index fbbc13a..5bd2ae1 100644 --- a/llvm/include/llvm/Analysis/StaticDataProfileInfo.h +++ b/llvm/include/llvm/Analysis/StaticDataProfileInfo.h @@ -10,6 +10,8 @@ namespace llvm { +bool IsReservedGlobalVariable(const GlobalVariable &GV); + /// A class that holds the constants that represent static data and their /// profile information and provides methods to operate on them. class StaticDataProfileInfo { diff --git a/llvm/lib/Analysis/StaticDataProfileInfo.cpp b/llvm/lib/Analysis/StaticDataProfileInfo.cpp index 700f5700..7f42d07 100644 --- a/llvm/lib/Analysis/StaticDataProfileInfo.cpp +++ b/llvm/lib/Analysis/StaticDataProfileInfo.cpp @@ -14,6 +14,10 @@ using namespace llvm; extern cl::opt<bool> AnnotateStaticDataSectionPrefix; +bool llvm::IsReservedGlobalVariable(const GlobalVariable &GV) { + return GV.getName().starts_with("llvm."); +} + void StaticDataProfileInfo::addConstantProfileCount( const Constant *C, std::optional<uint64_t> Count) { if (!Count) { @@ -87,7 +91,8 @@ StringRef StaticDataProfileInfo::getConstantSectionPrefix( // Module flag `HasDataAccessProf` is 1 -> empty section prefix means // unknown hotness except for string literals. if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(C); - GV && !GV->getName().starts_with(".str")) { + GV && !IsReservedGlobalVariable(*GV) && + !GV->getName().starts_with(".str")) { auto HotnessFromDAP = getSectionHotnessUsingDAP(GV->getSectionPrefix()); if (!Count) { diff --git a/llvm/lib/CodeGen/StaticDataSplitter.cpp b/llvm/lib/CodeGen/StaticDataSplitter.cpp index e22dc25..97aa833 100644 --- a/llvm/lib/CodeGen/StaticDataSplitter.cpp +++ b/llvm/lib/CodeGen/StaticDataSplitter.cpp @@ -133,8 +133,7 @@ StaticDataSplitter::getConstant(const MachineOperand &Op, // Skip 'llvm.'-prefixed global variables conservatively because they are // often handled specially, and skip those not in static data // sections. - if (!GV || GV->getName().starts_with("llvm.") || - !inStaticDataSection(*GV, TM)) + if (!GV || llvm::IsReservedGlobalVariable(*GV) || !inStaticDataSection(*GV, TM)) return nullptr; return GV; } diff --git a/llvm/test/CodeGen/X86/global-variable-partition-dap.ll b/llvm/test/CodeGen/X86/global-variable-partition-dap.ll index f987162..22788a2 100644 --- a/llvm/test/CodeGen/X86/global-variable-partition-dap.ll +++ b/llvm/test/CodeGen/X86/global-variable-partition-dap.ll @@ -2,7 +2,7 @@ target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80: target triple = "x86_64-unknown-linux-gnu" ;; Comments for RUN command options -; 1. `-relocation-model=pic` -> `hot_relro_array` and `cold_relro_array` are +; 1. `-relocation-model=pic` -> `relro_var` is ; placed in the .data.rel.ro-prefixed section. ; 2. `-data-sections=true -unique-section-names=false` -> data sections are ; uniqufied by variable names. @@ -10,120 +10,83 @@ target triple = "x86_64-unknown-linux-gnu" ; RUN: llc -mtriple=x86_64-unknown-linux-gnu -relocation-model=pic \ ; RUN: -partition-static-data-sections=true \ ; RUN: -data-sections=true -unique-section-names=false \ -; RUN: %s -o - 2>&1 | FileCheck %s --check-prefixes=UNIQ,COMMON --dump-input=always +; RUN: %s -o - 2>&1 | FileCheck %s --dump-input=always ; For @.str and @.str.1 -; COMMON: .type .L.str,@object -; UNIQ-NEXT: .section .rodata.str1.1.hot.,"aMS",@progbits,1 -; COMMON-NEXT: .L.str: -; COMMON-NEXT: "hot\t" -; COMMON: .L.str.1: -; COMMON-NEXT: "%d\t%d\t%d\n" +; CHECK: .type .L.str,@object +; CHECK-NEXT: .section .rodata.str1.1.hot.,"aMS",@progbits,1 +; CHECK-NEXT: .L.str: +; CHECK-NEXT: "1234" +; CHECK: .type .str.1,@object +; CHECK: .str.1: +; CHECK-NEXT: "abcde" -; For @hot_relro_array -; COMMON: .type hot_relro_array,@object -; UNIQ-NEXT: .section .data.rel.ro.hot.,"aw",@progbits,unique,1 +; For @.str.2 +; CHECK: .type .str.2,@object +; CHECK-NEXT: .section .rodata.str1.1,"aMS",@progbits +; CHECK-NEXT: .globl .str.2 +; CHECK-NEXT: .str.2: +; CHECK-NEXT: "beef" +@.str = private unnamed_addr constant [5 x i8] c"1234\00", align 1 +@.str.1 = internal unnamed_addr constant [6 x i8] c"abcde\00" +@.str.2 = unnamed_addr constant [5 x i8] c"beef\00", align 1 -; For @external_hot_data, which is accessed by {cold_func, unprofiled_func, hot_func}. -; COMMON: .type external_hot_data,@object -; UNIQ-NEXT: .section .data.hot.,"aw",@progbits,unique,2 +; CHECK: .type relro_var,@object +; CHECK-NEXT: .section .data.rel.ro,"aw",@progbits,unique,1 -; For @hot_bss, which is accessed by {unprofiled_func, hot_func}. -; COMMON: .type hot_bss,@object -; UNIQ-NEXT: .section .bss.hot.,"aw",@nobits,unique,3 +; CHECK: .type external_hot_data,@object +; CHECK-NEXT: .section .data.hot.,"aw",@progbits,unique,2 -; For @.str.2 -; COMMON: .type .L.str.2,@object -; UNIQ-NEXT: .section .rodata.str1.1.unlikely.,"aMS",@progbits,1 -; COMMON-NEXT: .L.str.2: -; COMMON-NEXT: "cold%d\t%d\t%d\n" - -; For @cold_bss -; COMMON: .type cold_bss,@object -; UNIQ-NEXT: .section .bss.unlikely.,"aw",@nobits,unique,4 - -; For @cold_data -; COMMON: .type cold_data,@object -; UNIQ-NEXT: .section .data.unlikely.,"aw",@progbits,unique,5 - -; For @cold_data_custom_foo_section -; It has an explicit section 'foo' and shouldn't have hot or unlikely suffix. -; COMMON: .type cold_data_custom_foo_section,@object -; UNIQ-NEXT: .section foo,"aw",@progbits - -; For @cold_relro_array -; COMMON: .type cold_relro_array,@object -; UNIQ-NEXT: .section .data.rel.ro.unlikely.,"aw",@progbits,unique,6 - - -; @bss2 and @data3 are indirectly accessed via @hot_relro_array and -; @cold_relro_array, and actually hot due to accesses via @hot_relro_array. -; Under the hood, the static data splitter pass analyzes accesses from code but -; won't aggressively propgate the hotness of @hot_relro_array into the array -; elements -- instead, this pass reconciles the hotness information from both -; global variable section prefix and PGO counters. - -; @bss2 has a section prefix 'hot' in the IR. StaticDataProfileInfo reconciles -; it into a hot prefix. -; COMMON: .type bss2,@object -; UNIQ-NEXT: .section .bss.hot.,"aw",@nobits,unique,7 - -; @data3 doesn't have data access profile coverage and thereby doesn't have a -; section prefix. PGO counter analysis categorizes it as cold, so it will have -; section name `.data.unlikely`. -; COMMON: .type data3,@object -; UNIQ-NEXT: .section .data,"aw",@progbits,unique,8 - -; For @data_with_unknown_hotness -; COMMON: .type .Ldata_with_unknown_hotness,@object # @data_with_unknown_hotness -; UNIQ: .section .data,"aw",@progbits,unique,9 - -; For @hot_data_custom_bar_section -; It has an explicit section attribute 'var' and shouldn't have hot or unlikely suffix. -; COMMON: .type hot_data_custom_bar_section,@object -; UNIQ: .section bar,"aw",@progbits - -; For @external_cold_bss -; COMMON: .type external_cold_bss,@object -; UNIQ-NEXT: .section .bss,"aw",@nobits,unique, - -@.str = private unnamed_addr constant [5 x i8] c"hot\09\00", align 1 -@.str.1 = private unnamed_addr constant [10 x i8] c"%d\09%d\09%d\0A\00", align 1 -@hot_relro_array = internal constant [2 x ptr] [ptr @bss2, ptr @data3] +; CHECK: .type hot_bss,@object +; CHECK-NEXT: .section .bss.hot.,"aw",@nobits,unique,3 + +@relro_var = constant [2 x ptr] [ptr @bss2, ptr @data3] @external_hot_data = global i32 5, !section_prefix !17 @hot_bss = internal global i32 0 -@.str.2 = private unnamed_addr constant [14 x i8] c"cold%d\09%d\09%d\0A\00", align 1 + +;; Both section prefix and PGO counters indicate @cold_bss and @cold_data are +;; rarely accesed. +; CHECK: .type cold_bss,@object +; CHECK-NEXT: .section .bss.unlikely.,"aw",@nobits,unique,4 +; CHECK: .type cold_data,@object +; CHECK-NEXT: .section .data.unlikely.,"aw",@progbits,unique,5 @cold_bss = internal global i32 0, !section_prefix !18 @cold_data = internal global i32 4, !section_prefix !18 -@cold_data_custom_foo_section = internal global i32 100, section "foo" -@cold_relro_array = internal constant [2 x ptr] [ptr @data3, ptr @bss2], !section_prefix !18 + +;; @bss2 has a section prefix 'hot' in the IR. StaticDataProfileInfo reconciles +;; it into a hot prefix. +; CHECK: .type bss2,@object +; CHECK-NEXT: .section .bss.hot.,"aw",@nobits,unique,6 @bss2 = internal global i32 0, !section_prefix !17 + +;; Since `HasDataAccessProf` is true, data without a section prefix is +;; conservatively categorized as unknown (e.g., from incremental source code) +;; rather than cold. +; CHECK: .type data3,@object +; CHECK-NEXT: .section .data,"aw",@progbits,unique,7 @data3 = internal global i32 3 -@data_with_unknown_hotness = private global i32 5 + +;; These sections have custom names, so they won't be labeled as .hot or .unlikely. +; CHECK: .type hot_data_custom_bar_section,@object +; CHECK-NEXT: .section bar,"aw" +; CHECK: .type cold_data_custom_foo_section,@object +; CHECK-NEXT: .section foo,"aw" @hot_data_custom_bar_section = internal global i32 101 #0 -@external_cold_bss = global i32 0 +@cold_data_custom_foo_section = internal global i32 100, section "foo" define void @cold_func(i32 %0) !prof !15 { %2 = load i32, ptr @cold_bss %3 = load i32, ptr @cold_data - %4 = srem i32 %0, 2 - %5 = sext i32 %4 to i64 - %6 = getelementptr inbounds [2 x ptr], ptr @cold_relro_array, i64 0, i64 %5 - %7 = load ptr, ptr %6 - %8 = load i32, ptr %7 - %9 = load i32, ptr @data_with_unknown_hotness %11 = load i32, ptr @external_hot_data %12 = load i32, ptr @cold_data_custom_foo_section - %val = load i32, ptr @external_cold_bss - %13 = call i32 (...) @func_taking_arbitrary_param(ptr @.str.2, i32 %2, i32 %3, i32 %8, i32 %9, i32 %11, i32 %12, i32 %val) + %13 = call i32 (...) @func_taking_arbitrary_param(ptr @.str.2, i32 %2, i32 %3, i32 %11, i32 %12) ret void } define i32 @unprofiled_func() { - %a = load i32, ptr @data_with_unknown_hotness %b = load i32, ptr @external_hot_data %c = load i32, ptr @hot_bss - %ret = call i32 (...) @func_taking_arbitrary_param(i32 %a, i32 %b, i32 %c) + %ret = call i32 (...) @func_taking_arbitrary_param(i32 %b, i32 %c) ret i32 %ret } @@ -131,7 +94,7 @@ define void @hot_func(i32 %0) !prof !14 { %2 = call i32 (...) @func_taking_arbitrary_param(ptr @.str) %3 = srem i32 %0, 2 %4 = sext i32 %3 to i64 - %5 = getelementptr inbounds [2 x ptr], ptr @hot_relro_array, i64 0, i64 %4 + %5 = getelementptr inbounds [2 x ptr], ptr @relro_var, i64 0, i64 %4 %6 = load ptr, ptr %5 %7 = load i32, ptr %6 %8 = load i32, ptr @external_hot_data @@ -166,4 +129,3 @@ attributes #0 = {"data-section"="bar"} !16 = !{!"branch_weights", i32 1, i32 99999} !17 = !{!"section_prefix", !"hot"} !18 = !{!"section_prefix", !"unlikely"} - |
