sosson97 / msh

12 stars 2 forks source link

llvm-project 30c1f31 can not import msh_bolt.diff patch #1

Open jfpu opened 3 months ago

jfpu commented 3 months ago

rtrs:llvm-project (main) $ git checkout 30c1f31 ... HEAD 目前位于 30c1f31274e5 [lldb] Fix 8be139fc1251 for propery value changes rtrs:llvm-project ((头指针分离于 30c1f31274e5)) $ patch -p1 < msh_bolt.diff patching file bolt/include/bolt/Core/BinaryBasicBlock.h patching file bolt/include/bolt/Core/BinaryContext.h patching file bolt/include/bolt/Core/BinaryFunction.h patching file bolt/include/bolt/Core/BinaryLoop.h patching file bolt/include/bolt/Core/FunctionLayout.h patching file bolt/include/bolt/Core/MCPlusBuilder.h patching file bolt/include/bolt/Passes/BinaryPasses.h patching file bolt/include/bolt/Passes/DataflowAnalysis.h patching file bolt/include/bolt/Passes/LivenessAnalysis.h patch: **** malformed patch at line 4967: diff --git a/bolt/include/bolt/Passes/PrefetchAndYield.h b/bolt/include/bolt/Passes/PrefetchAndYield.h

patch error, can not import bolt/include/bolt/Passes/PrefetchAndYield.h

913887524gsd commented 2 months ago

This patch may has problems... I also feel confused when patching. But now I'm clearing it out, here is the patch for msh_bolt.diff patch.

--- msh_bolt.diff       2024-08-20 20:05:34.176415616 +0800
+++ msh_bolt.diff       2024-08-23 14:33:11.958969563 +0800
@@ -4949,7 +4949,7 @@
          BC.MIB->getDefaultLiveOut(State);
          BC.MIB->getCalleeSavedRegs(State);
        } else {
-@@ -129,11 +129,12 @@ protected:
+@@ -129,11 +129,11 @@ protected:

        BitVector Used = BitVector(NumRegs, false);
        if (IsCall) {
@@ -6117,7 +6117,7 @@
      if (!BC.SymbolicDisAsm->getInstruction(Instruction, Size,
                                             FunctionData.slice(Offset),
                                             AbsoluteInstrAddr, nulls())) {
-@@ -1363,6 +1373,66 @@ add_instruction:
+@@ -1363,6 +1373,64 @@ add_instruction:
        MIB->addAnnotation(Instruction, "Size", static_cast<uint32_t>(Size));
      }

@@ -6190,7 +6190,7 @@
      return false;
    }

-@@ -2174,6 +2245,14 @@ bool BinaryFunction::buildCFG(MCPlusBuilder::AllocatorIdTy AllocatorId) {
+@@ -2174,6 +2245,12 @@ bool BinaryFunction::buildCFG(MCPlusBuilder::AllocatorIdTy AllocatorId) {

    normalizeCFIState();

@@ -8641,25 +8641,6 @@
 +
  } // namespace bolt
  } // namespace llvm
-diff --git a/bolt/lib/Passes/ThreeWayBranch.cpp b/bolt/lib/Passes/ThreeWayBranch.cpp
-index dc320d53fb68..cf30464b9637 100644
---- a/bolt/lib/Passes/ThreeWayBranch.cpp
-+++ b/bolt/lib/Passes/ThreeWayBranch.cpp
-@@ -26,6 +26,8 @@ bool ThreeWayBranch::shouldRunOnFunction(BinaryFunction &Function) {
-   return true;
- }
- 
- void ThreeWayBranch::runOnFunction(BinaryFunction &Function) {
-   BinaryContext &BC = Function.getBinaryContext();
-   MCContext *Ctx = BC.Ctx.get();
-@@ -34,6 +36,10 @@ void ThreeWayBranch::runOnFunction(BinaryFunction &Function) {
-   BinaryFunction::BasicBlockOrderType BlockLayout(
-       Function.getLayout().block_begin(), Function.getLayout().block_end());
-   for (BinaryBasicBlock *BB : BlockLayout) {
-+
-     // The block must be hot
-     if (BB->getExecutionCount() == 0 ||
-         BB->getExecutionCount() == BinaryBasicBlock::COUNT_NO_PROFILE)
 diff --git a/bolt/lib/Passes/YDPass.cpp b/bolt/lib/Passes/YDPass.cpp
 new file mode 100644
 index 000000000000..d2ebc809e0e2
@@ -8836,14 +8817,7 @@
  /// Return true if the function \p BF should be disassembled.
  static bool shouldDisassemble(const BinaryFunction &BF) {
    if (BF.isPseudo())
-@@ -749,6 +760,7 @@ Error RewriteInstance::run() {
-     return Error::success();
-   }
- 
-   selectFunctionsToProcess();
- 
-   readDebugInfo();
-@@ -3122,6 +3134,9 @@ void RewriteInstance::processProfileData() {
+@@ -3122,6 +3134,8 @@ void RewriteInstance::processProfileData() {
  void RewriteInstance::disassembleFunctions() {
    NamedRegionTimer T("disassembleFunctions", "disassemble functions",
                       TimerGroupName, TimerGroupDesc, opts::TimeRewrite);

Use this command to apply this patch.

$ patch msh_bolt.diff < {patch above}

I don't know if this still work... Readme is so confusing.

liqingqing1229 commented 1 month ago

This patch may has problems... I also feel confused when patching. But now I'm clearing it out, here is the patch for msh_bolt.diff patch.

--- msh_bolt.diff       2024-08-20 20:05:34.176415616 +0800
+++ msh_bolt.diff       2024-08-23 14:33:11.958969563 +0800
@@ -4949,7 +4949,7 @@
          BC.MIB->getDefaultLiveOut(State);
          BC.MIB->getCalleeSavedRegs(State);
        } else {
-@@ -129,11 +129,12 @@ protected:
+@@ -129,11 +129,11 @@ protected:

        BitVector Used = BitVector(NumRegs, false);
        if (IsCall) {
@@ -6117,7 +6117,7 @@
      if (!BC.SymbolicDisAsm->getInstruction(Instruction, Size,
                                             FunctionData.slice(Offset),
                                             AbsoluteInstrAddr, nulls())) {
-@@ -1363,6 +1373,66 @@ add_instruction:
+@@ -1363,6 +1373,64 @@ add_instruction:
        MIB->addAnnotation(Instruction, "Size", static_cast<uint32_t>(Size));
      }

@@ -6190,7 +6190,7 @@
      return false;
    }

-@@ -2174,6 +2245,14 @@ bool BinaryFunction::buildCFG(MCPlusBuilder::AllocatorIdTy AllocatorId) {
+@@ -2174,6 +2245,12 @@ bool BinaryFunction::buildCFG(MCPlusBuilder::AllocatorIdTy AllocatorId) {

    normalizeCFIState();

@@ -8641,25 +8641,6 @@
 +
  } // namespace bolt
  } // namespace llvm
-diff --git a/bolt/lib/Passes/ThreeWayBranch.cpp b/bolt/lib/Passes/ThreeWayBranch.cpp
-index dc320d53fb68..cf30464b9637 100644
---- a/bolt/lib/Passes/ThreeWayBranch.cpp
-+++ b/bolt/lib/Passes/ThreeWayBranch.cpp
-@@ -26,6 +26,8 @@ bool ThreeWayBranch::shouldRunOnFunction(BinaryFunction &Function) {
-   return true;
- }
- 
- void ThreeWayBranch::runOnFunction(BinaryFunction &Function) {
-   BinaryContext &BC = Function.getBinaryContext();
-   MCContext *Ctx = BC.Ctx.get();
-@@ -34,6 +36,10 @@ void ThreeWayBranch::runOnFunction(BinaryFunction &Function) {
-   BinaryFunction::BasicBlockOrderType BlockLayout(
-       Function.getLayout().block_begin(), Function.getLayout().block_end());
-   for (BinaryBasicBlock *BB : BlockLayout) {
-+
-     // The block must be hot
-     if (BB->getExecutionCount() == 0 ||
-         BB->getExecutionCount() == BinaryBasicBlock::COUNT_NO_PROFILE)
 diff --git a/bolt/lib/Passes/YDPass.cpp b/bolt/lib/Passes/YDPass.cpp
 new file mode 100644
 index 000000000000..d2ebc809e0e2
@@ -8836,14 +8817,7 @@
  /// Return true if the function \p BF should be disassembled.
  static bool shouldDisassemble(const BinaryFunction &BF) {
    if (BF.isPseudo())
-@@ -749,6 +760,7 @@ Error RewriteInstance::run() {
-     return Error::success();
-   }
- 
-   selectFunctionsToProcess();
- 
-   readDebugInfo();
-@@ -3122,6 +3134,9 @@ void RewriteInstance::processProfileData() {
+@@ -3122,6 +3134,8 @@ void RewriteInstance::processProfileData() {
  void RewriteInstance::disassembleFunctions() {
    NamedRegionTimer T("disassembleFunctions", "disassemble functions",
                       TimerGroupName, TimerGroupDesc, opts::TimeRewrite);

Use this command to apply this patch.

$ patch msh_bolt.diff < {patch above}

I don't know if this still work... Readme is so confusing. Thanks, After apply this patch, llvm-bolt can show the new options:
[root@ngxclient build]# llvm-bolt --help | grep clh-cmpc-list --clh-cmpc-list= - file containing list of PCs of deliquent loads

But this has another issue when using "do_prof_primary.sh" , [root@ngxclient apps]# cd .. [root@ngxclient msh]# ./do_prof_primary.sh ./apps/build/ptrchase 13107200 13107200 Capture deliquent load PCs ... Target object: 1) perf record L2/L3 misses sh: line 1: ../../config/set_env.sh: No such file or directory [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.057 MB ../results/perf.data (46 samples) ] 2) perf report 3) Capture Functions that cause most L2/L3 misses 4) perf annotate --stdio & Capturing all deliquent load PCs for each function .... Instruction capture done! 102400