aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR/Verifier.cpp
diff options
context:
space:
mode:
authorJoel E. Denny <jdenny.ornl@gmail.com>2025-09-11 15:55:18 -0400
committerGitHub <noreply@github.com>2025-09-11 15:55:18 -0400
commit0e3c5566c0c62a56629a927d7de5e2594d2dbe7c (patch)
tree7a653e9d188f46258024958c86c3f34d8ae4a05d /llvm/lib/IR/Verifier.cpp
parente08588d4ae3ed7c81de08aaf88f3454b4985f1b3 (diff)
downloadllvm-0e3c5566c0c62a56629a927d7de5e2594d2dbe7c.zip
llvm-0e3c5566c0c62a56629a927d7de5e2594d2dbe7c.tar.gz
llvm-0e3c5566c0c62a56629a927d7de5e2594d2dbe7c.tar.bz2
[PGO] Add llvm.loop.estimated_trip_count metadata (#152775)
This patch implements the `llvm.loop.estimated_trip_count` metadata discussed in [[RFC] Fix Loop Transformations to Preserve Block Frequencies](https://discourse.llvm.org/t/rfc-fix-loop-transformations-to-preserve-block-frequencies/85785). As the RFC explains, that metadata enables future patches, such as PR #128785, to fix block frequency issues without losing estimated trip counts.
Diffstat (limited to 'llvm/lib/IR/Verifier.cpp')
-rw-r--r--llvm/lib/IR/Verifier.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 7d362ce..c06b60f 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -1076,6 +1076,18 @@ void Verifier::visitMDNode(const MDNode &MD, AreDebugLocsAllowed AllowLocs) {
}
}
+ // Check llvm.loop.estimated_trip_count.
+ if (MD.getNumOperands() > 0 &&
+ MD.getOperand(0).equalsStr(LLVMLoopEstimatedTripCount)) {
+ Check(MD.getNumOperands() == 2, "Expected two operands", &MD);
+ auto *Count = dyn_cast_or_null<ConstantAsMetadata>(MD.getOperand(1));
+ Check(Count && Count->getType()->isIntegerTy() &&
+ cast<IntegerType>(Count->getType())->getBitWidth() <= 32,
+ "Expected second operand to be an integer constant of type i32 or "
+ "smaller",
+ &MD);
+ }
+
// Check these last, so we diagnose problems in operands first.
Check(!MD.isTemporary(), "Expected no forward declarations!", &MD);
Check(MD.isResolved(), "All nodes should be resolved!", &MD);