[llvm-branch-commits] [llvm] [AsmPrinter][ELF] Support profile-guided section prefix for jump tables' (read-only) data sections (PR #122215)

2025-01-22 Thread Wei Xiao via llvm-branch-commits

https://github.com/williamweixiao edited 
https://github.com/llvm/llvm-project/pull/122215
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [AsmPrinter][ELF] Support profile-guided section prefix for jump tables' (read-only) data sections (PR #122215)

2025-01-22 Thread Wei Xiao via llvm-branch-commits

https://github.com/williamweixiao commented:

Looks good. Just some trivial comments.

https://github.com/llvm/llvm-project/pull/122215
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [AsmPrinter][ELF] Support profile-guided section prefix for jump tables' (read-only) data sections (PR #122215)

2025-01-22 Thread Wei Xiao via llvm-branch-commits


@@ -3,21 +3,53 @@
 
 ; Stop after 'finalize-isel' for simpler MIR, and lower the minimum number of
 ; jump table entries so 'switch' needs fewer cases to generate a jump table.
-; RUN: llc -stop-after=finalize-isel -min-jump-table-entries=2 %s -o %t.mir
-; RUN: llc --run-pass=static-data-splitter -stats -x mir %t.mir -o - 2>&1 | 
FileCheck %s --check-prefix=STAT
+; RUN: llc -mtriple=x86_64-unknown-linux-gnu -stop-after=finalize-isel 
-min-jump-table-entries=2 %s -o %t.mir
+; RUN: llc -mtriple=x86_64-unknown-linux-gnu --run-pass=static-data-splitter 
-stats -x mir %t.mir -o - 2>&1 | FileCheck %s --check-prefix=STAT
 
-; Tests stat messages are expected.
-; TODO: Update test to verify section suffixes when target-lowering and 
assembler changes are implemented.
-; TODO: Also run static-data-splitter pass with 
-static-data-default-hotness=cold and check data section suffix.
- 
+ ; Tests stat messages are expected.
 ; STAT-DAG: 2 static-data-splitter - Number of cold jump tables seen
 ; STAT-DAG: 2 static-data-splitter - Number of hot jump tables seen
 ; STAT-DAG: 1 static-data-splitter - Number of jump tables with unknown hotness
 
-; In function @foo, the 2 switch instructions to jt0.* and jt2.* get lowered 
to hot jump tables,
-; and the 2 switch instructions to jt1.* and jt3.* get lowered to cold jump 
tables.
-
-; @func_without_profile doesn't have profiles. It's jump table hotness is 
unknown.
+; When 'partition-static-data-sections' is enabled, static data splitter pass 
will
+; categorize jump tables and assembly printer will place hot jump tables in the
+; `.rodata.hot`-prefixed section, and cold ones in the 
`.rodata.unlikely`-prefixed section.
+; Section names will optionally have `.` if -function-sections is 
enabled.
+; RUN: llc -mtriple=x86_64-unknown-linux-gnu -enable-split-machine-functions 
-partition-static-data-sections=true -function-sections=true 
-min-jump-table-entries=2 -unique-section-names=false  %s -o - 2>&1 | FileCheck 
%s --check-prefixes=LINEAR,JT
+; RUN: llc -mtriple=x86_64-unknown-linux-gnu -enable-split-machine-functions 
-partition-static-data-sections=true -function-sections=true 
-min-jump-table-entries=2  %s -o - 2>&1 | FileCheck %s 
--check-prefixes=FUNC,JT,DEFAULTHOT
+; RUN: llc -mtriple=x86_64-unknown-linux-gnu -enable-split-machine-functions 
-partition-static-data-sections=true -function-sections=false 
-min-jump-table-entries=2 %s -o - 2>&1 | FileCheck %s 
--check-prefixes=FUNCLESS,JT --implicit-check-not=unique
+
+; Tests that `-static-data-default-hotness` can override hotness for data with
+; unknown hotness.
+; RUN: llc -mtriple=x86_64-unknown-linux-gnu -enable-split-machine-functions 
-partition-static-data-sections=true -min-jump-table-entries=2 
-static-data-default-hotness=cold -function-sections=true %s -o - 2>&1 | 
FileCheck %s --check-prefixes=FUNC,JT,DEFAULTCOLD
+
+; LINEAR:.section .rodata.hot,"a",@progbits,unique,2
+; FUNC: .section .rodata.hot.foo,"a",@progbits
+; FUNCLESS: .section .rodata.hot,"a",@progbits
+; JT: .LJTI0_0:
+; JT: .LJTI0_2:
+; LINEAR:  .section.rodata.unlikely,"a",@progbits,unique,3
+; FUNC:   .section .rodata.unlikely.foo,"a",@progbits
+; FUNCLESS:   .section .rodata.unlikely,"a",@progbits
+; JT: .LJTI0_1:
+; JT: .LJTI0_3:
+; DEFAULTHOT: .section .rodata.hot.func_without_entry_count,"a",@progbits

williamweixiao wrote:

According referenced function is inside ".section
.text.func_without_entry_count" but its data in ".section
.rodata.hot.func_without_entry_count". There seems to be some inconsistency 
here.

https://github.com/llvm/llvm-project/pull/122215
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [AsmPrinter][ELF] Support profile-guided section prefix for jump tables' (read-only) data sections (PR #122215)

2025-01-22 Thread Wei Xiao via llvm-branch-commits


@@ -1261,9 +1261,9 @@ void TargetPassConfig::addMachinePasses() {
"performance.\n";
   }
 }
-addPass(createMachineFunctionSplitterPass());
-if (SplitStaticData)
+if (SplitStaticData || TM->Options.EnableStaticDataPartitioning)
   addPass(createStaticDataSplitterPass());
+addPass(createMachineFunctionSplitterPass());

williamweixiao wrote:

Any specific reason to reorder "createStaticDataSplitterPass" before 
"createMachineFunctionSplitterPass"?

https://github.com/llvm/llvm-project/pull/122215
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [AArch64AsmPrinter]Place jump tables into hot/unlikely-prefixed data sections for aarch64 (PR #126018)

2025-04-07 Thread Wei Xiao via llvm-branch-commits

https://github.com/williamweixiao approved this pull request.


https://github.com/llvm/llvm-project/pull/126018
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [CodeGen][StaticDataSplitter]Support constant pool partitioning (PR #129781)

2025-03-07 Thread Wei Xiao via llvm-branch-commits


@@ -112,21 +117,52 @@ bool 
StaticDataSplitter::runOnMachineFunction(MachineFunction &MF) {
   return Changed;
 }
 
+const Constant *
+StaticDataSplitter::getConstant(const MachineOperand &Op,
+const TargetMachine &TM,
+const MachineConstantPool *MCP) {
+  if (!Op.isGlobal() && !Op.isCPI())
+return nullptr;
+
+  if (Op.isGlobal()) {
+// Find global variables with local linkage.
+const GlobalVariable *GV = getLocalLinkageGlobalVariable(Op.getGlobal());
+// Skip 'special' 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))
+  return nullptr;
+return GV;

williamweixiao wrote:

What's the motivation to handle "GlobalVariable" here? Any test to cover it?

https://github.com/llvm/llvm-project/pull/129781
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [CodeGen][StaticDataSplitter]Support constant pool partitioning (PR #129781)

2025-03-06 Thread Wei Xiao via llvm-branch-commits


@@ -112,21 +117,52 @@ bool 
StaticDataSplitter::runOnMachineFunction(MachineFunction &MF) {
   return Changed;
 }
 
+const Constant *
+StaticDataSplitter::getConstant(const MachineOperand &Op,
+const TargetMachine &TM,
+const MachineConstantPool *MCP) {
+  if (!Op.isGlobal() && !Op.isCPI())
+return nullptr;
+
+  if (Op.isGlobal()) {
+// Find global variables with local linkage.
+const GlobalVariable *GV = getLocalLinkageGlobalVariable(Op.getGlobal());
+// Skip 'special' 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))
+  return nullptr;
+return GV;
+  }
+  assert(Op.isCPI() && "Op must be constant pool index in this branch");
+  int CPI = Op.getIndex();
+  if (CPI == -1)
+return nullptr;
+
+  assert(MCP != nullptr && "Constant pool info is not available.");
+  const MachineConstantPoolEntry &CPE = MCP->getConstants()[CPI];
+
+  if (CPE.isMachineConstantPoolEntry())
+return nullptr;
+
+  return CPE.Val.ConstVal;
+}
+
 bool StaticDataSplitter::partitionStaticDataWithProfiles(MachineFunction &MF) {
   int NumChangedJumpTables = 0;
 
-  const TargetMachine &TM = MF.getTarget();
   MachineJumpTableInfo *MJTI = MF.getJumpTableInfo();
 
   // Jump table could be used by either terminating instructions or
   // non-terminating ones, so we walk all instructions and use
   // `MachineOperand::isJTI()` to identify jump table operands.
-  // Similarly, `MachineOperand::isCPI()` can identify constant pool usages
-  // in the same loop.
+  // Similarly, `MachineOperand::isCPI()` is used to identify constant pool
+  // usages in the same loop.
   for (const auto &MBB : MF) {
 for (const MachineInstr &I : MBB) {
   for (const MachineOperand &Op : I.operands()) {
-if (!Op.isJTI() && !Op.isGlobal())
+if (!Op.isJTI() && !Op.isGlobal() && !Op.isCPI())
   continue;
 
 std::optional Count = MBFI->getBlockProfileCount(&MBB);

williamweixiao wrote:

line 168 can be hoisted out to the outmost loop (i.e line 163).

https://github.com/llvm/llvm-project/pull/129781
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [CodeGen][StaticDataSplitter]Support constant pool partitioning (PR #129781)

2025-03-06 Thread Wei Xiao via llvm-branch-commits


@@ -148,17 +184,9 @@ bool 
StaticDataSplitter::partitionStaticDataWithProfiles(MachineFunction &MF) {
 
   if (MJTI->updateJumpTableEntryHotness(JTI, Hotness))
 ++NumChangedJumpTables;
-} else {
-  // Find global variables with local linkage.
-  const GlobalVariable *GV =
-  getLocalLinkageGlobalVariable(Op.getGlobal());
-  // Skip 'special' 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))
-continue;
-  SDPI->addConstantProfileCount(GV, Count);
+} else if (const Constant *C =
+   getConstant(Op, MF.getTarget(), MF.getConstantPool())) {
+  SDPI->addConstantProfileCount(C, Count);

williamweixiao wrote:

yes, we don't need to update "NumChangedJumpTables" here. but why do we need to 
return "true" or "false" for this function?

https://github.com/llvm/llvm-project/pull/129781
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [CodeGen][StaticDataSplitter]Support constant pool partitioning (PR #129781)

2025-03-26 Thread Wei Xiao via llvm-branch-commits

https://github.com/williamweixiao approved this pull request.


https://github.com/llvm/llvm-project/pull/129781
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits