MCPcopy Create free account
hub / github.com/NVIDIA/cuda-tile / DebugInfoReader

Class DebugInfoReader

lib/Bytecode/Reader/BytecodeReader.cpp:784–1115  ·  view source on GitHub ↗

This class manages reading debug info attributes from bytecode format.

Source from the content-addressed store, hash-verified

782
783/// This class manages reading debug info attributes from bytecode format.
784class DebugInfoReader {
785public:
786 DebugInfoReader(MLIRContext &context, EncodingReader &masterReader)
787 : context(context), masterReader(masterReader) {}
788
789 class Iterator {
790 public:
791 Iterator(DebugInfoReader &reader, uint64_t opIndex)
792 : reader(reader), opIndex(opIndex) {}
793
794 /// Return the next debug info attribute for the current operation.
795 template <typename T>
796 T next() {
797 // Check if the index is reserved for special debug info attributes.
798 if (opIndex == static_cast<uint64_t>(Bytecode::DebugReserved::UnknownLoc))
799 return dyn_cast<T>(UnknownLoc::get(&reader.context));
800
801 // Adjust the index to account for reserved indices.
802 auto actualOpIndex =
803 opIndex - static_cast<uint64_t>(Bytecode::DebugReserved::SIZE);
804
805 // Calculate the offset for the current operation index.
806 if (actualOpIndex >= reader.diIndexOffsets.size())
807 return T();
808 auto offset = reader.diIndexOffsets[actualOpIndex];
809
810 // Validate size to prevent excessive memory allocation.
811 if (reader.diIndices.size() > (std::numeric_limits<uint32_t>::max() - 1))
812 return T();
813 if (offset > (std::numeric_limits<uint32_t>::max() - 1))
814 return T();
815 if (offset + opIndexOffset >= reader.diIndices.size())
816 return T();
817 offset += opIndexOffset++;
818
819 // Return the next debug info attribute for the current operation.
820 return reader.getDebugInfo<T>(reader.diIndices[offset]);
821 }
822
823 private:
824 DebugInfoReader &reader;
825 uint64_t opIndex;
826 uint64_t opIndexOffset = 0;
827 };
828
829 Iterator getIterator(uint64_t opIndex) { return Iterator(*this, opIndex); }
830
831 /// This method initializes the debug info reader after construction.
832 void initialize(ArrayRef<uint64_t> indices, ArrayRef<uint32_t> indexOffsets,
833 ArrayRef<uint8_t> data, ArrayRef<uint32_t> offsets) {
834 diIndices = indices;
835 diIndexOffsets = indexOffsets;
836 diData = data;
837 diOffsets = offsets;
838 diCache.resize(offsets.size());
839 }
840
841private:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected