[llvm] Handle MCInst op, non-null MCInst op, tgt MCExpr; fix AddressMap (PR #192188)
Brian Cain via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 15 22:29:58 PDT 2026
https://github.com/androm3da updated https://github.com/llvm/llvm-project/pull/192188
>From d69299fd856df0253590c9a3cd9265eaddf0c982 Mon Sep 17 00:00:00 2001
From: Brian Cain <brian.cain at oss.qualcomm.com>
Date: Tue, 7 Apr 2026 20:21:15 -0700
Subject: [PATCH] [BOLT] Support non-null MCInst operands in annotation
handling
The annotation sentinel in BOLT is a null MCInst operand appended
after all prime operands. However, some architectures (e.g. Hexagon)
use non-null MCInst operands as legitimate prime operands for duplex
sub-instructions. The existing code treated any MCInst operand as
the annotation sentinel, causing duplex sub-instructions to be
misidentified.
In getNumPrimeOperands(), only treat a null MCInst operand as the
sentinel. In getAnnotationInstOp(), skip non-null MCInst operands
when searching for the annotation sentinel.
---
bolt/include/bolt/Core/MCPlus.h | 10 ++++++++--
bolt/include/bolt/Core/MCPlusBuilder.h | 4 +---
2 files changed, 9 insertions(+), 5 deletions(-)
diff --git a/bolt/include/bolt/Core/MCPlus.h b/bolt/include/bolt/Core/MCPlus.h
index ead6ba1470da6..382e21606d487 100644
--- a/bolt/include/bolt/Core/MCPlus.h
+++ b/bolt/include/bolt/Core/MCPlus.h
@@ -117,8 +117,14 @@ template <typename ValueType> class MCSimpleAnnotation : public MCAnnotation {
/// annotations.
inline unsigned getNumPrimeOperands(const MCInst &Inst) {
for (signed I = Inst.getNumOperands() - 1; I >= 0; --I) {
- if (Inst.getOperand(I).isInst())
- return I;
+ if (Inst.getOperand(I).isInst()) {
+ // Only a null MCInst operand is the annotation sentinel.
+ // Non-null MCInst operands (e.g. Hexagon duplex sub-instructions)
+ // are legitimate prime operands.
+ if (Inst.getOperand(I).getInst() == nullptr)
+ return I;
+ return Inst.getNumOperands();
+ }
if (!Inst.getOperand(I).isImm())
return Inst.getNumOperands();
}
diff --git a/bolt/include/bolt/Core/MCPlusBuilder.h b/bolt/include/bolt/Core/MCPlusBuilder.h
index 0f6076688b65d..85fe6fff3a878 100644
--- a/bolt/include/bolt/Core/MCPlusBuilder.h
+++ b/bolt/include/bolt/Core/MCPlusBuilder.h
@@ -138,10 +138,8 @@ class MCPlusBuilder {
MCInst::iterator getAnnotationInstOp(MCInst &Inst) const {
for (MCInst::iterator Iter = Inst.begin(); Iter != Inst.end(); ++Iter) {
- if (Iter->isInst()) {
- assert(Iter->getInst() == nullptr && "Empty instruction expected.");
+ if (Iter->isInst() && Iter->getInst() == nullptr)
return Iter;
- }
}
return Inst.end();
}
More information about the llvm-commits
mailing list