diff options
Diffstat (limited to 'include/llvm/CodeGen/DbgEntityHistoryCalculator.h')
| -rw-r--r-- | include/llvm/CodeGen/DbgEntityHistoryCalculator.h | 89 |
1 files changed, 65 insertions, 24 deletions
diff --git a/include/llvm/CodeGen/DbgEntityHistoryCalculator.h b/include/llvm/CodeGen/DbgEntityHistoryCalculator.h index befc28f084e7..7eec75bc81bf 100644 --- a/include/llvm/CodeGen/DbgEntityHistoryCalculator.h +++ b/include/llvm/CodeGen/DbgEntityHistoryCalculator.h @@ -1,9 +1,8 @@ //===- llvm/CodeGen/DbgEntityHistoryCalculator.h ----------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -11,6 +10,7 @@ #define LLVM_CODEGEN_DBGVALUEHISTORYCALCULATOR_H #include "llvm/ADT/MapVector.h" +#include "llvm/ADT/PointerIntPair.h" #include "llvm/ADT/SmallVector.h" #include "llvm/IR/DebugInfoMetadata.h" #include <utility> @@ -22,35 +22,76 @@ class MachineFunction; class MachineInstr; class TargetRegisterInfo; -// For each user variable, keep a list of instruction ranges where this variable -// is accessible. The variables are listed in order of appearance. +/// For each user variable, keep a list of instruction ranges where this +/// variable is accessible. The variables are listed in order of appearance. class DbgValueHistoryMap { - // Each instruction range starts with a DBG_VALUE instruction, specifying the - // location of a variable, which is assumed to be valid until the end of the - // range. If end is not specified, location is valid until the start - // instruction of the next instruction range, or until the end of the - // function. public: - using InstrRange = std::pair<const MachineInstr *, const MachineInstr *>; - using InstrRanges = SmallVector<InstrRange, 4>; + /// Index in the entry vector. + typedef size_t EntryIndex; + + /// Special value to indicate that an entry is valid until the end of the + /// function. + static const EntryIndex NoEntry = std::numeric_limits<EntryIndex>::max(); + + /// Specifies a change in a variable's debug value history. + /// + /// There exist two types of entries: + /// + /// * Debug value entry: + /// + /// A new debug value becomes live. If the entry's \p EndIndex is \p NoEntry, + /// the value is valid until the end of the function. For other values, the + /// index points to the entry in the entry vector that ends this debug + /// value. The ending entry can either be an overlapping debug value, or + /// an instruction that clobbers the value. + /// + /// * Clobbering entry: + /// + /// This entry's instruction clobbers one or more preceding + /// register-described debug values that have their end index + /// set to this entry's position in the entry vector. + class Entry { + public: + enum EntryKind { DbgValue, Clobber }; + + Entry(const MachineInstr *Instr, EntryKind Kind) + : Instr(Instr, Kind), EndIndex(NoEntry) {} + + const MachineInstr *getInstr() const { return Instr.getPointer(); } + EntryIndex getEndIndex() const { return EndIndex; } + EntryKind getEntryKind() const { return Instr.getInt(); } + + bool isClobber() const { return getEntryKind() == Clobber; } + bool isDbgValue() const { return getEntryKind() == DbgValue; } + bool isClosed() const { return EndIndex != NoEntry; } + + void endEntry(EntryIndex EndIndex); + + private: + PointerIntPair<const MachineInstr *, 1, EntryKind> Instr; + EntryIndex EndIndex; + }; + using Entries = SmallVector<Entry, 4>; using InlinedEntity = std::pair<const DINode *, const DILocation *>; - using InstrRangesMap = MapVector<InlinedEntity, InstrRanges>; + using EntriesMap = MapVector<InlinedEntity, Entries>; private: - InstrRangesMap VarInstrRanges; + EntriesMap VarEntries; public: - void startInstrRange(InlinedEntity Var, const MachineInstr &MI); - void endInstrRange(InlinedEntity Var, const MachineInstr &MI); + bool startDbgValue(InlinedEntity Var, const MachineInstr &MI, + EntryIndex &NewIndex); + EntryIndex startClobber(InlinedEntity Var, const MachineInstr &MI); - // Returns register currently describing @Var. If @Var is currently - // unaccessible or is not described by a register, returns 0. - unsigned getRegisterForVar(InlinedEntity Var) const; + Entry &getEntry(InlinedEntity Var, EntryIndex Index) { + auto &Entries = VarEntries[Var]; + return Entries[Index]; + } - bool empty() const { return VarInstrRanges.empty(); } - void clear() { VarInstrRanges.clear(); } - InstrRangesMap::const_iterator begin() const { return VarInstrRanges.begin(); } - InstrRangesMap::const_iterator end() const { return VarInstrRanges.end(); } + bool empty() const { return VarEntries.empty(); } + void clear() { VarEntries.clear(); } + EntriesMap::const_iterator begin() const { return VarEntries.begin(); } + EntriesMap::const_iterator end() const { return VarEntries.end(); } #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) LLVM_DUMP_METHOD void dump() const; |
