[llvm-branch-commits] [llvm][misexpect] Enable diagnostics for profitable llvm.expect annotations (PR #96523)

2024-07-30 Thread Paul Kirth via llvm-branch-commits

https://github.com/ilovepi updated 
https://github.com/llvm/llvm-project/pull/96523


___
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][misexpect] Enable diagnostics for profitable llvm.expect annotations (PR #96523)

2024-07-30 Thread Paul Kirth via llvm-branch-commits

https://github.com/ilovepi updated 
https://github.com/llvm/llvm-project/pull/96523


___
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][misexpect] Enable diagnostics for profitable llvm.expect annotations (PR #96523)

2024-06-24 Thread via llvm-branch-commits

llvmbot wrote:



@llvm/pr-subscribers-llvm-transforms

@llvm/pr-subscribers-pgo

Author: Paul Kirth (ilovepi)


Changes

Issue #56502 describes an enhancement related to the use of llvm.expect.
The request is for a diagnostic mode that can identify branches that
would benefit from the use of llvm.expect based on the branch_weights
assigned from a PGO or sample profile.

To support identify branches(or switches) that would benefit from the
use of an llvm.expect intrinsic, we follow a similar checking pattern to
that used in MisExpect, but only in cases where MisExpect diagnostics
would not be used (i.e., when an llvm.expect intrinsic has already been
used).


---
Full diff: https://github.com/llvm/llvm-project/pull/96523.diff


8 Files Affected:

- (modified) llvm/include/llvm/IR/LLVMContext.h (+2) 
- (modified) llvm/include/llvm/Target/TargetOptions.h (+4) 
- (modified) llvm/include/llvm/Transforms/Utils/MisExpect.h (+3) 
- (modified) llvm/lib/IR/LLVMContext.cpp (+6) 
- (modified) llvm/lib/IR/LLVMContextImpl.h (+4) 
- (modified) llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp (+1) 
- (modified) llvm/lib/Transforms/Utils/MisExpect.cpp (+137-36) 
- (added) llvm/test/Transforms/PGOProfile/missing-annotation.ll (+110) 


``diff
diff --git a/llvm/include/llvm/IR/LLVMContext.h 
b/llvm/include/llvm/IR/LLVMContext.h
index 89ad6f1572c67..94e526d465c8e 100644
--- a/llvm/include/llvm/IR/LLVMContext.h
+++ b/llvm/include/llvm/IR/LLVMContext.h
@@ -212,6 +212,8 @@ class LLVMContext {
   void setMisExpectWarningRequested(bool Requested);
   void setDiagnosticsMisExpectTolerance(std::optional Tolerance);
   uint32_t getDiagnosticsMisExpectTolerance() const;
+  bool getAnnotationDiagsRequested() const;
+  void setAnnotationDiagsRequested(bool Requested);
 
   /// Return the minimum hotness value a diagnostic would need in order
   /// to be included in optimization diagnostics.
diff --git a/llvm/include/llvm/Target/TargetOptions.h 
b/llvm/include/llvm/Target/TargetOptions.h
index d3464b5202ff3..447b86f69cfaa 100644
--- a/llvm/include/llvm/Target/TargetOptions.h
+++ b/llvm/include/llvm/Target/TargetOptions.h
@@ -377,6 +377,10 @@ namespace llvm {
 /// By default, it is set to false
 unsigned MisExpect : 1;
 
+/// When set to true, enable MissingAnnotations diagnostics
+/// By default, it is set to false
+unsigned MissingAnnotations : 1;
+
 /// When set to true, const objects with relocatable address values are put
 /// into the RO data section.
 unsigned XCOFFReadOnlyPointers : 1;
diff --git a/llvm/include/llvm/Transforms/Utils/MisExpect.h 
b/llvm/include/llvm/Transforms/Utils/MisExpect.h
index e9fba47c97a4d..118d859f93dd6 100644
--- a/llvm/include/llvm/Transforms/Utils/MisExpect.h
+++ b/llvm/include/llvm/Transforms/Utils/MisExpect.h
@@ -76,6 +76,9 @@ void checkExpectAnnotations(Instruction ,
 const ArrayRef ExistingWeights,
 bool IsFrontend);
 
+void checkMissingAnnotations(Instruction ,
+ const ArrayRef ExistingWeights,
+ bool IsFrontendInstr);
 } // namespace misexpect
 } // namespace llvm
 
diff --git a/llvm/lib/IR/LLVMContext.cpp b/llvm/lib/IR/LLVMContext.cpp
index 8120cccace40b..e1a05c1347969 100644
--- a/llvm/lib/IR/LLVMContext.cpp
+++ b/llvm/lib/IR/LLVMContext.cpp
@@ -171,6 +171,12 @@ void LLVMContext::setDiagnosticsMisExpectTolerance(
 uint32_t LLVMContext::getDiagnosticsMisExpectTolerance() const {
   return pImpl->DiagnosticsMisExpectTolerance.value_or(0);
 }
+void LLVMContext::setAnnotationDiagsRequested(bool Requested) {
+  pImpl->AnnotationsDiagsRequested = Requested;
+}
+bool LLVMContext::getAnnotationDiagsRequested() const {
+  return pImpl->AnnotationsDiagsRequested;
+}
 
 bool LLVMContext::isDiagnosticsHotnessThresholdSetFromPSI() const {
   return !pImpl->DiagnosticsHotnessThreshold.has_value();
diff --git a/llvm/lib/IR/LLVMContextImpl.h b/llvm/lib/IR/LLVMContextImpl.h
index 5f8df87149f04..59eb5eb29705d 100644
--- a/llvm/lib/IR/LLVMContextImpl.h
+++ b/llvm/lib/IR/LLVMContextImpl.h
@@ -1495,6 +1495,10 @@ class LLVMContextImpl {
   std::optional DiagnosticsMisExpectTolerance = 0;
   bool MisExpectWarningRequested = false;
 
+  /// Enables Diagnostics for Missing llvm.expect annotations on extremely hot
+  /// branches
+  bool AnnotationsDiagsRequested = false;
+
   /// The specialized remark streamer used by LLVM's OptimizationRemarkEmitter.
   std::unique_ptr LLVMRS;
 
diff --git a/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp 
b/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
index 572d37a2b3e55..0fbf60194696a 100644
--- a/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
+++ b/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
@@ -2261,6 +2261,7 @@ void llvm::setProfMetadata(Module *M, Instruction *TI,
   } dbgs() << "\n";);
 
   misexpect::checkExpectAnnotations(*TI, Weights, /*IsFrontend=*/false);
+  

[llvm-branch-commits] [llvm][misexpect] Enable diagnostics for profitable llvm.expect annotations (PR #96523)

2024-06-24 Thread Paul Kirth via llvm-branch-commits

https://github.com/ilovepi created 
https://github.com/llvm/llvm-project/pull/96523

Issue #56502 describes an enhancement related to the use of llvm.expect.
The request is for a diagnostic mode that can identify branches that
would benefit from the use of llvm.expect based on the branch_weights
assigned from a PGO or sample profile.

To support identify branches(or switches) that would benefit from the
use of an llvm.expect intrinsic, we follow a similar checking pattern to
that used in MisExpect, but only in cases where MisExpect diagnostics
would not be used (i.e., when an llvm.expect intrinsic has already been
used).



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits