[llvm] 2e6bb8c - [DebugInfo] Support more than 2 operands in DWARF operations

Scott Linder via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 19 12:39:22 PDT 2023


Author: Scott Linder
Date: 2023-06-19T19:38:26Z
New Revision: 2e6bb8c9b82c185f0e96895b1f69045cfb0640b4

URL: https://github.com/llvm/llvm-project/commit/2e6bb8c9b82c185f0e96895b1f69045cfb0640b4
DIFF: https://github.com/llvm/llvm-project/commit/2e6bb8c9b82c185f0e96895b1f69045cfb0640b4.diff

LOG: [DebugInfo] Support more than 2 operands in DWARF operations

Update DWARFExpression::Operation and LVOperation to support more than
2 operands.

Take the opportunity to use a SmallVector, which will handle at least 2
operands without allocation anyway, and removes the static limit
completely.

As there is no longer the concept of an "unused operand", remove
Operation::Encoding::SizeNA. Any use of it is now replaced with explicit
checks for how many operands an operation has.

There are still places where the limit remains 2, namely in the
DWARFLinker and in DIExpressions, but these can be updated in later
patches as-needed.

There are no explicit tests as this is nearly NFC: no new operation is
added which makes use of the additional operand capacity yet. A future
patch adding a new DWARF extension point will include operations which
require the support.

Reviewed By: Orlando, CarlosAlbertoEnciso

Differential Revision: https://reviews.llvm.org/D147270

Added: 
    

Modified: 
    llvm/include/llvm/DebugInfo/DWARF/DWARFExpression.h
    llvm/include/llvm/DebugInfo/LogicalView/Core/LVLocation.h
    llvm/include/llvm/DebugInfo/LogicalView/Core/LVReader.h
    llvm/include/llvm/DebugInfo/LogicalView/Core/LVSymbol.h
    llvm/include/llvm/DebugInfo/LogicalView/Readers/LVCodeViewReader.h
    llvm/include/llvm/DebugInfo/LogicalView/Readers/LVELFReader.h
    llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
    llvm/lib/DWARFLinker/DWARFLinker.cpp
    llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp
    llvm/lib/DebugInfo/LogicalView/Core/LVLocation.cpp
    llvm/lib/DebugInfo/LogicalView/Core/LVSymbol.cpp
    llvm/lib/DebugInfo/LogicalView/Readers/LVCodeViewReader.cpp
    llvm/lib/DebugInfo/LogicalView/Readers/LVCodeViewVisitor.cpp
    llvm/lib/DebugInfo/LogicalView/Readers/LVELFReader.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/DebugInfo/DWARF/DWARFExpression.h b/llvm/include/llvm/DebugInfo/DWARF/DWARFExpression.h
index 7fde32711745d..6b80dbc038822 100644
--- a/llvm/include/llvm/DebugInfo/DWARF/DWARFExpression.h
+++ b/llvm/include/llvm/DebugInfo/DWARF/DWARFExpression.h
@@ -24,8 +24,7 @@ class DWARFExpression {
 public:
   class iterator;
 
-  /// This class represents an Operation in the Expression. Each operation can
-  /// have up to 2 oprerands.
+  /// This class represents an Operation in the Expression.
   ///
   /// An Operation can be in Error state (check with isError()). This
   /// means that it couldn't be decoded successfully and if it is the
@@ -50,7 +49,6 @@ class DWARFExpression {
       SignedSize4 = SignBit | Size4,
       SignedSize8 = SignBit | Size8,
       SignedSizeLEB = SignBit | SizeLEB,
-      SizeNA = 0xFF ///< Unused operands get this encoding.
     };
 
     enum DwarfVersion : uint8_t {
@@ -64,14 +62,13 @@ class DWARFExpression {
     /// Description of the encoding of one expression Op.
     struct Description {
       DwarfVersion Version; ///< Dwarf version where the Op was introduced.
-      Encoding Op[2];       ///< Encoding for Op operands, or SizeNA.
-
-      Description(DwarfVersion Version = DwarfNA, Encoding Op1 = SizeNA,
-                  Encoding Op2 = SizeNA)
-          : Version(Version) {
-        Op[0] = Op1;
-        Op[1] = Op2;
-      }
+      SmallVector<Encoding> Op; ///< Encoding for Op operands.
+
+      template <typename... Ts>
+      Description(DwarfVersion Version, Ts... Op)
+          : Version(Version), Op{Op...} {}
+      Description() : Description(DwarfNA) {}
+      ~Description() = default;
     };
 
   private:
@@ -80,13 +77,18 @@ class DWARFExpression {
     Description Desc;
     bool Error = false;
     uint64_t EndOffset;
-    uint64_t Operands[2];
-    uint64_t OperandEndOffsets[2];
+    SmallVector<uint64_t> Operands;
+    SmallVector<uint64_t> OperandEndOffsets;
 
   public:
     const Description &getDescription() const { return Desc; }
     uint8_t getCode() const { return Opcode; }
+    uint64_t getNumOperands() const { return Operands.size(); }
+    ArrayRef<uint64_t> getRawOperands() const { return Operands; };
     uint64_t getRawOperand(unsigned Idx) const { return Operands[Idx]; }
+    ArrayRef<uint64_t> getOperandEndOffsets() const {
+      return OperandEndOffsets;
+    }
     uint64_t getOperandEndOffset(unsigned Idx) const {
       return OperandEndOffsets[Idx];
     }
@@ -165,7 +167,7 @@ class DWARFExpression {
 
   static bool prettyPrintRegisterOp(DWARFUnit *U, raw_ostream &OS,
                                     DIDumpOptions DumpOpts, uint8_t Opcode,
-                                    const uint64_t Operands[2]);
+                                    const ArrayRef<uint64_t> Operands);
 
 private:
   DataExtractor Data;

diff  --git a/llvm/include/llvm/DebugInfo/LogicalView/Core/LVLocation.h b/llvm/include/llvm/DebugInfo/LogicalView/Core/LVLocation.h
index dc1df9f27a6c4..3b556f9927832 100644
--- a/llvm/include/llvm/DebugInfo/LogicalView/Core/LVLocation.h
+++ b/llvm/include/llvm/DebugInfo/LogicalView/Core/LVLocation.h
@@ -33,22 +33,17 @@ class LVOperation final {
   //   OP_[GNU_]deref_type, OP_[GNU_]entry_value, OP_implicit_value,
   //   OP_[GNU_]implicit_pointer, OP_[GNU_]regval_type, OP_xderef_type.
   LVSmall Opcode = 0;
-  uint64_t Operands[2];
+  SmallVector<uint64_t> Operands;
 
 public:
   LVOperation() = delete;
-  LVOperation(LVSmall Opcode, LVUnsigned Operand1, LVUnsigned Operand2)
-      : Opcode(Opcode) {
-    Operands[0] = Operand1;
-    Operands[1] = Operand2;
-  }
+  LVOperation(LVSmall Opcode, ArrayRef<LVUnsigned> Operands)
+      : Opcode(Opcode), Operands(Operands) {}
   LVOperation(const LVOperation &) = delete;
   LVOperation &operator=(const LVOperation &) = delete;
   ~LVOperation() = default;
 
   LVSmall getOpcode() const { return Opcode; }
-  uint64_t getOperand1() const { return Operands[0]; }
-  uint64_t getOperand2() const { return Operands[1]; }
   std::string getOperandsDWARFInfo();
   std::string getOperandsCodeViewInfo();
 
@@ -154,8 +149,7 @@ class LVLocation : public LVObject {
 
   virtual void addObject(LVAddress LowPC, LVAddress HighPC,
                          LVUnsigned SectionOffset, uint64_t LocDescOffset) {}
-  virtual void addObject(LVSmall Opcode, LVUnsigned Operand1,
-                         LVUnsigned Operand2) {}
+  virtual void addObject(LVSmall Opcode, ArrayRef<LVUnsigned> Operands) {}
 
   static void print(LVLocations *Locations, raw_ostream &OS, bool Full = true);
   void printInterval(raw_ostream &OS, bool Full = true) const;
@@ -184,8 +178,7 @@ class LVLocationSymbol final : public LVLocation {
 
   void addObject(LVAddress LowPC, LVAddress HighPC, LVUnsigned SectionOffset,
                  uint64_t LocDescOffset) override;
-  void addObject(LVSmall Opcode, LVUnsigned Operand1,
-                 LVUnsigned Operand2) override;
+  void addObject(LVSmall Opcode, ArrayRef<LVUnsigned> Operands) override;
 
   void printRawExtra(raw_ostream &OS, bool Full = true) const override;
   void printExtra(raw_ostream &OS, bool Full = true) const override;

diff  --git a/llvm/include/llvm/DebugInfo/LogicalView/Core/LVReader.h b/llvm/include/llvm/DebugInfo/LogicalView/Core/LVReader.h
index ea4c31af364ec..9ce26398e48df 100644
--- a/llvm/include/llvm/DebugInfo/LogicalView/Core/LVReader.h
+++ b/llvm/include/llvm/DebugInfo/LogicalView/Core/LVReader.h
@@ -228,10 +228,8 @@ class LVReader {
 #undef LV_CREATE_OBJECT
 
   // Operations creation.
-  LVOperation *createOperation(LVSmall OpCode, LVUnsigned Operand1,
-                               LVUnsigned Operand2) {
-    return new (AllocatedOperation.Allocate())
-        LVOperation(OpCode, Operand1, Operand2);
+  LVOperation *createOperation(LVSmall OpCode, ArrayRef<LVUnsigned> Operands) {
+    return new (AllocatedOperation.Allocate()) LVOperation(OpCode, Operands);
   }
 
   StringRef getFilename(LVObject *Object, size_t Index) const;
@@ -263,7 +261,8 @@ class LVReader {
   Error doPrint();
   Error doLoad();
 
-  virtual std::string getRegisterName(LVSmall Opcode, uint64_t Operands[2]) {
+  virtual std::string getRegisterName(LVSmall Opcode,
+                                      ArrayRef<uint64_t> Operands) {
     llvm_unreachable("Invalid instance reader.");
     return {};
   }

diff  --git a/llvm/include/llvm/DebugInfo/LogicalView/Core/LVSymbol.h b/llvm/include/llvm/DebugInfo/LogicalView/Core/LVSymbol.h
index 3d4d65b2251f8..25bfa9eb77d8a 100644
--- a/llvm/include/llvm/DebugInfo/LogicalView/Core/LVSymbol.h
+++ b/llvm/include/llvm/DebugInfo/LogicalView/Core/LVSymbol.h
@@ -126,8 +126,7 @@ class LVSymbol final : public LVElement {
   // Add a Location Entry.
   void addLocationConstant(dwarf::Attribute Attr, LVUnsigned Constant,
                            uint64_t LocDescOffset);
-  void addLocationOperands(LVSmall Opcode, uint64_t Operand1,
-                           uint64_t Operand2);
+  void addLocationOperands(LVSmall Opcode, ArrayRef<uint64_t> Operands);
   void addLocation(dwarf::Attribute Attr, LVAddress LowPC, LVAddress HighPC,
                    LVUnsigned SectionOffset, uint64_t LocDescOffset,
                    bool CallSiteLocation = false);

diff  --git a/llvm/include/llvm/DebugInfo/LogicalView/Readers/LVCodeViewReader.h b/llvm/include/llvm/DebugInfo/LogicalView/Readers/LVCodeViewReader.h
index 35d37b03c3bbc..8a32210bac3c9 100644
--- a/llvm/include/llvm/DebugInfo/LogicalView/Readers/LVCodeViewReader.h
+++ b/llvm/include/llvm/DebugInfo/LogicalView/Readers/LVCodeViewReader.h
@@ -215,7 +215,8 @@ class LVCodeViewReader final : public LVBinaryReader {
   static StringRef getSymbolKindName(SymbolKind Kind);
   static std::string formatRegisterId(RegisterId Register, CPUType CPU);
 
-  std::string getRegisterName(LVSmall Opcode, uint64_t Operands[2]) override;
+  std::string getRegisterName(LVSmall Opcode,
+                              ArrayRef<uint64_t> Operands) override;
 
   bool isSystemEntry(LVElement *Element, StringRef Name) const override;
 

diff  --git a/llvm/include/llvm/DebugInfo/LogicalView/Readers/LVELFReader.h b/llvm/include/llvm/DebugInfo/LogicalView/Readers/LVELFReader.h
index 41d927c7e8219..0837b886a273a 100644
--- a/llvm/include/llvm/DebugInfo/LogicalView/Readers/LVELFReader.h
+++ b/llvm/include/llvm/DebugInfo/LogicalView/Readers/LVELFReader.h
@@ -145,7 +145,8 @@ class LVELFReader final : public LVBinaryReader {
     return SymbolsWithLocations;
   }
 
-  std::string getRegisterName(LVSmall Opcode, uint64_t Operands[2]) override;
+  std::string getRegisterName(LVSmall Opcode,
+                              ArrayRef<uint64_t> Operands) override;
 
   void print(raw_ostream &OS) const;
 

diff  --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
index 557291c97265f..f5a58f79ef4d5 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
@@ -2615,9 +2615,7 @@ void DwarfDebug::emitDebugLocEntry(ByteStreamer &Streamer,
            "3 operand ops not yet supported");
     Streamer.emitInt8(Op.getCode(), Comment != End ? *(Comment++) : "");
     Offset++;
-    for (unsigned I = 0; I < 2; ++I) {
-      if (Op.getDescription().Op[I] == Encoding::SizeNA)
-        continue;
+    for (unsigned I = 0; I < Op.getDescription().Op.size(); ++I) {
       if (Op.getDescription().Op[I] == Encoding::BaseTypeRef) {
         unsigned Length =
           Streamer.emitDIERef(*CU->ExprRefedBaseTypes[Op.getRawOperand(I)].Die);

diff  --git a/llvm/lib/DWARFLinker/DWARFLinker.cpp b/llvm/lib/DWARFLinker/DWARFLinker.cpp
index 619df440b695e..2b1c6e5ada26d 100644
--- a/llvm/lib/DWARFLinker/DWARFLinker.cpp
+++ b/llvm/lib/DWARFLinker/DWARFLinker.cpp
@@ -1152,17 +1152,17 @@ void DWARFLinker::DIECloner::cloneExpression(
 
   uint64_t OpOffset = 0;
   for (auto &Op : Expression) {
-    auto Description = Op.getDescription();
+    auto Desc = Op.getDescription();
     // DW_OP_const_type is variable-length and has 3
-    // operands. DWARFExpression thus far only supports 2.
-    auto Op0 = Description.Op[0];
-    auto Op1 = Description.Op[1];
-    if ((Op0 == Encoding::BaseTypeRef && Op1 != Encoding::SizeNA) ||
-        (Op1 == Encoding::BaseTypeRef && Op0 != Encoding::Size1))
+    // operands. Thus far we only support 2.
+    if ((Desc.Op.size() == 2 && Desc.Op[0] == Encoding::BaseTypeRef) ||
+        (Desc.Op.size() == 2 && Desc.Op[1] == Encoding::BaseTypeRef &&
+         Desc.Op[0] != Encoding::Size1))
       Linker.reportWarning("Unsupported DW_OP encoding.", File);
 
-    if ((Op0 == Encoding::BaseTypeRef && Op1 == Encoding::SizeNA) ||
-        (Op1 == Encoding::BaseTypeRef && Op0 == Encoding::Size1)) {
+    if ((Desc.Op.size() == 1 && Desc.Op[0] == Encoding::BaseTypeRef) ||
+        (Desc.Op.size() == 2 && Desc.Op[1] == Encoding::BaseTypeRef &&
+         Desc.Op[0] == Encoding::Size1)) {
       // This code assumes that the other non-typeref operand fits into 1 byte.
       assert(OpOffset < Op.getEndOffset());
       uint32_t ULEBsize = Op.getEndOffset() - OpOffset - 1;
@@ -1171,7 +1171,7 @@ void DWARFLinker::DIECloner::cloneExpression(
       // Copy over the operation.
       OutputBuffer.push_back(Op.getCode());
       uint64_t RefOffset;
-      if (Op1 == Encoding::SizeNA) {
+      if (Desc.Op.size() == 1) {
         RefOffset = Op.getRawOperand(0);
       } else {
         OutputBuffer.push_back(Op.getRawOperand(0));

diff  --git a/llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp b/llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp
index 109731e73c71d..7801170bc6e9e 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp
@@ -18,13 +18,11 @@ using namespace dwarf;
 
 namespace llvm {
 
-typedef std::vector<DWARFExpression::Operation::Description> DescVector;
-
-static DescVector getDescriptions() {
-  DescVector Descriptions;
-  typedef DWARFExpression::Operation Op;
-  typedef Op::Description Desc;
+typedef DWARFExpression::Operation Op;
+typedef Op::Description Desc;
 
+static std::vector<Desc> getOpDescriptions() {
+  std::vector<Desc> Descriptions;
   Descriptions.resize(0xff);
   Descriptions[DW_OP_addr] = Desc(Op::Dwarf2, Op::SizeAddr);
   Descriptions[DW_OP_deref] = Desc(Op::Dwarf2);
@@ -97,24 +95,25 @@ static DescVector getDescriptions() {
   Descriptions[DW_OP_GNU_addr_index] = Desc(Op::Dwarf4, Op::SizeLEB);
   Descriptions[DW_OP_GNU_const_index] = Desc(Op::Dwarf4, Op::SizeLEB);
   Descriptions[DW_OP_GNU_entry_value] = Desc(Op::Dwarf4, Op::SizeLEB);
-
   Descriptions[DW_OP_addrx] = Desc(Op::Dwarf5, Op::SizeLEB);
   Descriptions[DW_OP_constx] = Desc(Op::Dwarf5, Op::SizeLEB);
   Descriptions[DW_OP_convert] = Desc(Op::Dwarf5, Op::BaseTypeRef);
   Descriptions[DW_OP_entry_value] = Desc(Op::Dwarf5, Op::SizeLEB);
   Descriptions[DW_OP_regval_type] =
       Desc(Op::Dwarf5, Op::SizeLEB, Op::BaseTypeRef);
-
   return Descriptions;
 }
 
-static DWARFExpression::Operation::Description getOpDesc(unsigned OpCode) {
-  // FIXME: Make this constexpr once all compilers are smart enough to do it.
-  static DescVector Descriptions = getDescriptions();
+static Desc getDescImpl(ArrayRef<Desc> Descriptions, unsigned Opcode) {
   // Handle possible corrupted or unsupported operation.
-  if (OpCode >= Descriptions.size())
+  if (Opcode >= Descriptions.size())
     return {};
-  return Descriptions[OpCode];
+  return Descriptions[Opcode];
+}
+
+static Desc getOpDesc(unsigned Opcode) {
+  static std::vector<Desc> Descriptions = getOpDescriptions();
+  return getDescImpl(Descriptions, Opcode);
 }
 
 bool DWARFExpression::Operation::extract(DataExtractor Data,
@@ -127,13 +126,12 @@ bool DWARFExpression::Operation::extract(DataExtractor Data,
   if (Desc.Version == Operation::DwarfNA)
     return false;
 
-  for (unsigned Operand = 0; Operand < 2; ++Operand) {
+  Operands.resize(Desc.Op.size());
+  OperandEndOffsets.resize(Desc.Op.size());
+  for (unsigned Operand = 0; Operand < Desc.Op.size(); ++Operand) {
     unsigned Size = Desc.Op[Operand];
     unsigned Signed = Size & Operation::SignBit;
 
-    if (Size == Operation::SizeNA)
-      break;
-
     switch (Size & ~Operation::SignBit) {
     case Operation::Size1:
       Operands[Operand] = Data.getU8(&Offset);
@@ -208,9 +206,9 @@ bool DWARFExpression::Operation::extract(DataExtractor Data,
 
 static void prettyPrintBaseTypeRef(DWARFUnit *U, raw_ostream &OS,
                                    DIDumpOptions DumpOpts,
-                                   const uint64_t Operands[2],
+                                   ArrayRef<uint64_t> Operands,
                                    unsigned Operand) {
-  assert(Operand < 2 && "operand out of bounds");
+  assert(Operand < Operands.size() && "operand out of bounds");
   auto Die = U->getDIEForOffset(U->getOffset() + Operands[Operand]);
   if (Die && Die.getTag() == dwarf::DW_TAG_base_type) {
     OS << " (";
@@ -228,7 +226,7 @@ static void prettyPrintBaseTypeRef(DWARFUnit *U, raw_ostream &OS,
 bool DWARFExpression::prettyPrintRegisterOp(DWARFUnit *U, raw_ostream &OS,
                                             DIDumpOptions DumpOpts,
                                             uint8_t Opcode,
-                                            const uint64_t Operands[2]) {
+                                            ArrayRef<uint64_t> Operands) {
   if (!DumpOpts.GetNameForDWARFReg)
     return false;
 
@@ -278,13 +276,10 @@ bool DWARFExpression::Operation::print(raw_ostream &OS, DIDumpOptions DumpOpts,
     if (prettyPrintRegisterOp(U, OS, DumpOpts, Opcode, Operands))
       return true;
 
-  for (unsigned Operand = 0; Operand < 2; ++Operand) {
+  for (unsigned Operand = 0; Operand < Desc.Op.size(); ++Operand) {
     unsigned Size = Desc.Op[Operand];
     unsigned Signed = Size & Operation::SignBit;
 
-    if (Size == Operation::SizeNA)
-      break;
-
     if (Size == Operation::BaseTypeRef && U) {
       // For DW_OP_convert the operand may be 0 to indicate that conversion to
       // the generic type should be done. The same holds for DW_OP_reinterpret,
@@ -356,12 +351,9 @@ void DWARFExpression::print(raw_ostream &OS, DIDumpOptions DumpOpts,
 }
 
 bool DWARFExpression::Operation::verify(const Operation &Op, DWARFUnit *U) {
-  for (unsigned Operand = 0; Operand < 2; ++Operand) {
+  for (unsigned Operand = 0; Operand < Op.Desc.Op.size(); ++Operand) {
     unsigned Size = Op.Desc.Op[Operand];
 
-    if (Size == Operation::SizeNA)
-      break;
-
     if (Size == Operation::BaseTypeRef) {
       // For DW_OP_convert the operand may be 0 to indicate that conversion to
       // the generic type should be done, so don't look up a base type in that

diff  --git a/llvm/lib/DebugInfo/LogicalView/Core/LVLocation.cpp b/llvm/lib/DebugInfo/LogicalView/Core/LVLocation.cpp
index 954ac0436b6ca..17b32a5f67b49 100644
--- a/llvm/lib/DebugInfo/LogicalView/Core/LVLocation.cpp
+++ b/llvm/lib/DebugInfo/LogicalView/Core/LVLocation.cpp
@@ -352,7 +352,7 @@ std::string LVOperation::getOperandsCodeViewInfo() {
   uint16_t OperationCode = getCodeViewOperationCode(Opcode);
 
   switch (OperationCode) {
-  // Operands: [Offset, 0].
+  // Operands: [Offset].
   case codeview::SymbolKind::S_DEFRANGE_FRAMEPOINTER_REL:
     Stream << "frame_pointer_rel " << int(Operands[0]);
     break;
@@ -360,7 +360,7 @@ std::string LVOperation::getOperandsCodeViewInfo() {
     Stream << "frame_pointer_rel_full_scope " << int(Operands[0]);
     break;
 
-  // Operands: [Register, 0].
+  // Operands: [Register].
   case codeview::SymbolKind::S_DEFRANGE_REGISTER:
     Stream << "register " << getReader().getRegisterName(Opcode, Operands);
     break;
@@ -375,7 +375,7 @@ std::string LVOperation::getOperandsCodeViewInfo() {
            << " offset " << int(Operands[1]);
     break;
 
-  // Operands: [Program, 0].
+  // Operands: [Program].
   case codeview::SymbolKind::S_DEFRANGE:
     Stream << "frame " << int(Operands[0]);
     break;
@@ -576,11 +576,11 @@ void LVLocationSymbol::addObject(LVAddress LowPC, LVAddress HighPC,
 }
 
 // Add a Location Record.
-void LVLocationSymbol::addObject(LVSmall Opcode, LVUnsigned Operand1,
-                                 LVUnsigned Operand2) {
+void LVLocationSymbol::addObject(LVSmall Opcode,
+                                 ArrayRef<LVUnsigned> Operands) {
   if (!Entries)
     Entries = std::make_unique<LVOperations>();
-  Entries->push_back(getReader().createOperation(Opcode, Operand1, Operand2));
+  Entries->push_back(getReader().createOperation(Opcode, Operands));
 }
 
 // Based on the DWARF attribute, define the location kind.

diff  --git a/llvm/lib/DebugInfo/LogicalView/Core/LVSymbol.cpp b/llvm/lib/DebugInfo/LogicalView/Core/LVSymbol.cpp
index 7e86a2f4c1b8a..4608fe20cb6df 100644
--- a/llvm/lib/DebugInfo/LogicalView/Core/LVSymbol.cpp
+++ b/llvm/lib/DebugInfo/LogicalView/Core/LVSymbol.cpp
@@ -82,10 +82,10 @@ void LVSymbol::addLocation(dwarf::Attribute Attr, LVAddress LowPC,
 }
 
 // Add a Location Record.
-void LVSymbol::addLocationOperands(LVSmall Opcode, uint64_t Operand1,
-                                   uint64_t Operand2) {
+void LVSymbol::addLocationOperands(LVSmall Opcode,
+                                   ArrayRef<uint64_t> Operands) {
   if (CurrentLocation)
-    CurrentLocation->addObject(Opcode, Operand1, Operand2);
+    CurrentLocation->addObject(Opcode, Operands);
 }
 
 // Add a Location Entry.
@@ -97,8 +97,7 @@ void LVSymbol::addLocationConstant(dwarf::Attribute Attr, LVUnsigned Constant,
               /*SectionOffset=*/0, LocDescOffset);
 
   // Add records to Location Entry.
-  addLocationOperands(/*Opcode=*/LVLocationMemberOffset,
-                      /*Operand1=*/Constant, /*Operand2=*/0);
+  addLocationOperands(/*Opcode=*/LVLocationMemberOffset, {Constant});
 }
 
 LVLocations::iterator LVSymbol::addLocationGap(LVLocations::iterator Pos,
@@ -115,8 +114,7 @@ LVLocations::iterator LVSymbol::addLocationGap(LVLocations::iterator Pos,
   LVLocations::iterator Iter = Locations->insert(Pos, Gap);
 
   // Add gap to Location Entry.
-  Gap->addObject(/*op=*/dwarf::DW_OP_hi_user,
-                 /*opd1=*/0, /*opd2=*/0);
+  Gap->addObject(dwarf::DW_OP_hi_user, {});
 
   // Mark the entry as a gap.
   Gap->setIsGapEntry();

diff  --git a/llvm/lib/DebugInfo/LogicalView/Readers/LVCodeViewReader.cpp b/llvm/lib/DebugInfo/LogicalView/Readers/LVCodeViewReader.cpp
index 5b099d47c45a4..d72fe2683f92c 100644
--- a/llvm/lib/DebugInfo/LogicalView/Readers/LVCodeViewReader.cpp
+++ b/llvm/lib/DebugInfo/LogicalView/Readers/LVCodeViewReader.cpp
@@ -1212,7 +1212,7 @@ Error LVCodeViewReader::loadTargetInfo(const PDBFile &Pdb) {
 }
 
 std::string LVCodeViewReader::getRegisterName(LVSmall Opcode,
-                                              uint64_t Operands[2]) {
+                                              ArrayRef<uint64_t> Operands) {
   // Get Compilation Unit CPU Type.
   CPUType CPU = getCompileUnitCPUType();
   // For CodeView the register always is in Operands[0];

diff  --git a/llvm/lib/DebugInfo/LogicalView/Readers/LVCodeViewVisitor.cpp b/llvm/lib/DebugInfo/LogicalView/Readers/LVCodeViewVisitor.cpp
index c3ca6df91933f..e4f5f533262bf 100644
--- a/llvm/lib/DebugInfo/LogicalView/Readers/LVCodeViewVisitor.cpp
+++ b/llvm/lib/DebugInfo/LogicalView/Readers/LVCodeViewVisitor.cpp
@@ -1065,7 +1065,7 @@ Error LVSymbolVisitor::visitKnownRecord(
 
     uint64_t Operand1 = DefRangeFramePointerRelFullScope.Offset;
     Symbol->addLocation(Attr, 0, 0, 0, 0);
-    Symbol->addLocationOperands(LVSmall(Attr), Operand1, /*Operand2=*/0);
+    Symbol->addLocationOperands(LVSmall(Attr), {Operand1});
   }
 
   return Error::success();
@@ -1103,7 +1103,7 @@ Error LVSymbolVisitor::visitKnownRecord(
         Reader->linearAddress(Range.ISectStart, Range.OffsetStart);
 
     Symbol->addLocation(Attr, Address, Address + Range.Range, 0, 0);
-    Symbol->addLocationOperands(LVSmall(Attr), Operand1, /*Operand2=*/0);
+    Symbol->addLocationOperands(LVSmall(Attr), {Operand1});
   }
 
   return Error::success();
@@ -1142,7 +1142,7 @@ Error LVSymbolVisitor::visitKnownRecord(
         Reader->linearAddress(Range.ISectStart, Range.OffsetStart);
 
     Symbol->addLocation(Attr, Address, Address + Range.Range, 0, 0);
-    Symbol->addLocationOperands(LVSmall(Attr), Operand1, Operand2);
+    Symbol->addLocationOperands(LVSmall(Attr), {Operand1, Operand2});
   }
 
   return Error::success();
@@ -1177,7 +1177,7 @@ Error LVSymbolVisitor::visitKnownRecord(CVSymbol &Record,
         Reader->linearAddress(Range.ISectStart, Range.OffsetStart);
 
     Symbol->addLocation(Attr, Address, Address + Range.Range, 0, 0);
-    Symbol->addLocationOperands(LVSmall(Attr), Operand1, /*Operand2=*/0);
+    Symbol->addLocationOperands(LVSmall(Attr), {Operand1});
   }
 
   return Error::success();
@@ -1215,7 +1215,7 @@ Error LVSymbolVisitor::visitKnownRecord(
         Reader->linearAddress(Range.ISectStart, Range.OffsetStart);
 
     Symbol->addLocation(Attr, Address, Address + Range.Range, 0, 0);
-    Symbol->addLocationOperands(LVSmall(Attr), Operand1, /*Operand2=*/0);
+    Symbol->addLocationOperands(LVSmall(Attr), {Operand1});
   }
 
   return Error::success();
@@ -1258,7 +1258,7 @@ Error LVSymbolVisitor::visitKnownRecord(CVSymbol &Record,
         Reader->linearAddress(Range.ISectStart, Range.OffsetStart);
 
     Symbol->addLocation(Attr, Address, Address + Range.Range, 0, 0);
-    Symbol->addLocationOperands(LVSmall(Attr), Operand1, /*Operand2=*/0);
+    Symbol->addLocationOperands(LVSmall(Attr), {Operand1, /*Operand2=*/0});
   }
 
   return Error::success();
@@ -1299,7 +1299,7 @@ Error LVSymbolVisitor::visitKnownRecord(CVSymbol &Record,
         Reader->linearAddress(Range.ISectStart, Range.OffsetStart);
 
     Symbol->addLocation(Attr, Address, Address + Range.Range, 0, 0);
-    Symbol->addLocationOperands(LVSmall(Attr), Operand1, /*Operand2=*/0);
+    Symbol->addLocationOperands(LVSmall(Attr), {Operand1, /*Operand2=*/0});
   }
 
   return Error::success();

diff  --git a/llvm/lib/DebugInfo/LogicalView/Readers/LVELFReader.cpp b/llvm/lib/DebugInfo/LogicalView/Readers/LVELFReader.cpp
index 67002fb97153b..ab458341a0bd5 100644
--- a/llvm/lib/DebugInfo/LogicalView/Readers/LVELFReader.cpp
+++ b/llvm/lib/DebugInfo/LogicalView/Readers/LVELFReader.cpp
@@ -759,7 +759,8 @@ void LVELFReader::createLineAndFileRecords(
     }
 }
 
-std::string LVELFReader::getRegisterName(LVSmall Opcode, uint64_t Operands[2]) {
+std::string LVELFReader::getRegisterName(LVSmall Opcode,
+                                         ArrayRef<uint64_t> Operands) {
   // The 'prettyPrintRegisterOp' function uses the DWARFUnit to support
   // DW_OP_regval_type. At this point we are operating on a logical view
   // item, with no access to the underlying DWARF data used by LLVM.
@@ -973,19 +974,8 @@ void LVELFReader::processLocationList(dwarf::Attribute Attr,
                                       bool CallSiteLocation) {
 
   auto ProcessLocationExpression = [&](const DWARFExpression &Expression) {
-    // DW_OP_const_type is variable-length and has 3
-    // operands. DWARFExpression thus far only supports 2.
-    uint64_t Operands[2] = {0};
-    for (const DWARFExpression::Operation &Op : Expression) {
-      DWARFExpression::Operation::Description Description = Op.getDescription();
-      for (unsigned Operand = 0; Operand < 2; ++Operand) {
-        if (Description.Op[Operand] == DWARFExpression::Operation::SizeNA)
-          break;
-        Operands[Operand] = Op.getRawOperand(Operand);
-      }
-      CurrentSymbol->addLocationOperands(Op.getCode(), Operands[0],
-                                         Operands[1]);
-    }
+    for (const DWARFExpression::Operation &Op : Expression)
+      CurrentSymbol->addLocationOperands(Op.getCode(), Op.getRawOperands());
   };
 
   DWARFUnit *U = Die.getDwarfUnit();


        


More information about the llvm-commits mailing list