Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:43:42

0001 //===-- LVLocation.h --------------------------------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 // This file defines the LVOperation and LVLocation classes, which are used
0010 // to describe variable locations.
0011 //
0012 //===----------------------------------------------------------------------===//
0013 
0014 #ifndef LLVM_DEBUGINFO_LOGICALVIEW_CORE_LVLOCATION_H
0015 #define LLVM_DEBUGINFO_LOGICALVIEW_CORE_LVLOCATION_H
0016 
0017 #include "llvm/DebugInfo/LogicalView/Core/LVObject.h"
0018 
0019 namespace llvm {
0020 namespace logicalview {
0021 
0022 using LVLineRange = std::pair<LVLine *, LVLine *>;
0023 
0024 // The DW_AT_data_member_location attribute is a simple member offset.
0025 const LVSmall LVLocationMemberOffset = 0;
0026 
0027 class LVOperation final {
0028   // To describe an operation:
0029   // OpCode
0030   // Operands[0]: First operand.
0031   // Operands[1]: Second operand.
0032   //   OP_bregx, OP_bit_piece, OP_[GNU_]const_type,
0033   //   OP_[GNU_]deref_type, OP_[GNU_]entry_value, OP_implicit_value,
0034   //   OP_[GNU_]implicit_pointer, OP_[GNU_]regval_type, OP_xderef_type.
0035   LVSmall Opcode = 0;
0036   SmallVector<uint64_t> Operands;
0037 
0038 public:
0039   LVOperation() = delete;
0040   LVOperation(LVSmall Opcode, ArrayRef<LVUnsigned> Operands)
0041       : Opcode(Opcode), Operands(Operands) {}
0042   LVOperation(const LVOperation &) = delete;
0043   LVOperation &operator=(const LVOperation &) = delete;
0044   ~LVOperation() = default;
0045 
0046   LVSmall getOpcode() const { return Opcode; }
0047   std::string getOperandsDWARFInfo();
0048   std::string getOperandsCodeViewInfo();
0049 
0050   void print(raw_ostream &OS, bool Full = true) const;
0051 
0052 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
0053   void dump() { print(dbgs()); }
0054 #endif
0055 };
0056 
0057 class LVLocation : public LVObject {
0058   enum class Property {
0059     IsAddressRange,
0060     IsBaseClassOffset,
0061     IsBaseClassStep,
0062     IsClassOffset,
0063     IsFixedAddress,
0064     IsLocationSimple,
0065     IsGapEntry,
0066     IsOperation,
0067     IsOperationList,
0068     IsRegister,
0069     IsStackOffset,
0070     IsDiscardedRange,
0071     IsInvalidRange,
0072     IsInvalidLower,
0073     IsInvalidUpper,
0074     IsCallSite,
0075     LastEntry
0076   };
0077   // Typed bitvector with properties for this location.
0078   LVProperties<Property> Properties;
0079 
0080   // True if the location it is associated with a debug range.
0081   bool hasAssociatedRange() const {
0082     return !getIsClassOffset() && !getIsDiscardedRange();
0083   }
0084 
0085 protected:
0086   // Line numbers associated with locations ranges.
0087   LVLine *LowerLine = nullptr;
0088   LVLine *UpperLine = nullptr;
0089 
0090   // Active range:
0091   // LowPC: an offset from an applicable base address, not a PC value.
0092   // HighPC: an offset from an applicable base address, or a length.
0093   LVAddress LowPC = 0;
0094   LVAddress HighPC = 0;
0095 
0096   void setKind();
0097 
0098 public:
0099   LVLocation() : LVObject() { setIsLocation(); }
0100   LVLocation(const LVLocation &) = delete;
0101   LVLocation &operator=(const LVLocation &) = delete;
0102   virtual ~LVLocation() = default;
0103 
0104   PROPERTY(Property, IsAddressRange);
0105   PROPERTY(Property, IsBaseClassOffset);
0106   PROPERTY(Property, IsBaseClassStep);
0107   PROPERTY_1(Property, IsClassOffset, IsLocationSimple);
0108   PROPERTY_1(Property, IsFixedAddress, IsLocationSimple);
0109   PROPERTY(Property, IsLocationSimple);
0110   PROPERTY(Property, IsGapEntry);
0111   PROPERTY(Property, IsOperationList);
0112   PROPERTY(Property, IsOperation);
0113   PROPERTY(Property, IsRegister);
0114   PROPERTY_1(Property, IsStackOffset, IsLocationSimple);
0115   PROPERTY(Property, IsDiscardedRange);
0116   PROPERTY(Property, IsInvalidRange);
0117   PROPERTY(Property, IsInvalidLower);
0118   PROPERTY(Property, IsInvalidUpper);
0119   PROPERTY(Property, IsCallSite);
0120 
0121   const char *kind() const override;
0122   // Mark the locations that have only DW_OP_fbreg as stack offset based.
0123   virtual void updateKind() {}
0124 
0125   // Line numbers for locations.
0126   const LVLine *getLowerLine() const { return LowerLine; }
0127   void setLowerLine(LVLine *Line) { LowerLine = Line; }
0128   const LVLine *getUpperLine() const { return UpperLine; }
0129   void setUpperLine(LVLine *Line) { UpperLine = Line; }
0130 
0131   // Addresses for locations.
0132   LVAddress getLowerAddress() const override { return LowPC; }
0133   void setLowerAddress(LVAddress Address) override { LowPC = Address; }
0134   LVAddress getUpperAddress() const override { return HighPC; }
0135   void setUpperAddress(LVAddress Address) override { HighPC = Address; }
0136 
0137   std::string getIntervalInfo() const;
0138 
0139   bool validateRanges();
0140 
0141   // In order to calculate a symbol coverage (percentage), take the ranges
0142   // and obtain the number of units (bytes) covered by those ranges. We can't
0143   // use the line numbers, because they can be zero or invalid.
0144   // We return:
0145   //   false: No locations or multiple locations.
0146   //   true: a single location.
0147   static bool calculateCoverage(LVLocations *Locations, unsigned &Factor,
0148                                 float &Percentage);
0149 
0150   virtual void addObject(LVAddress LowPC, LVAddress HighPC,
0151                          LVUnsigned SectionOffset, uint64_t LocDescOffset) {}
0152   virtual void addObject(LVSmall Opcode, ArrayRef<LVUnsigned> Operands) {}
0153 
0154   static void print(LVLocations *Locations, raw_ostream &OS, bool Full = true);
0155   void printInterval(raw_ostream &OS, bool Full = true) const;
0156   void printRaw(raw_ostream &OS, bool Full = true) const;
0157   virtual void printRawExtra(raw_ostream &OS, bool Full = true) const {}
0158 
0159   void print(raw_ostream &OS, bool Full = true) const override;
0160   void printExtra(raw_ostream &OS, bool Full = true) const override;
0161 
0162 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
0163   void dump() const override { print(dbgs()); }
0164 #endif
0165 };
0166 
0167 class LVLocationSymbol final : public LVLocation {
0168   // Location descriptors for the active range.
0169   std::unique_ptr<LVOperations> Entries;
0170 
0171   void updateKind() override;
0172 
0173 public:
0174   LVLocationSymbol() : LVLocation() {}
0175   LVLocationSymbol(const LVLocationSymbol &) = delete;
0176   LVLocationSymbol &operator=(const LVLocationSymbol &) = delete;
0177   ~LVLocationSymbol() = default;
0178 
0179   void addObject(LVAddress LowPC, LVAddress HighPC, LVUnsigned SectionOffset,
0180                  uint64_t LocDescOffset) override;
0181   void addObject(LVSmall Opcode, ArrayRef<LVUnsigned> Operands) override;
0182 
0183   void printRawExtra(raw_ostream &OS, bool Full = true) const override;
0184   void printExtra(raw_ostream &OS, bool Full = true) const override;
0185 };
0186 
0187 } // end namespace logicalview
0188 } // end namespace llvm
0189 
0190 #endif // LLVM_DEBUGINFO_LOGICALVIEW_CORE_LVLOCATION_H