Back to home page

EIC code displayed by LXR

 
 

    


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

0001 //===- DebugLoc.h - Debug Location Information ------------------*- 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 a number of light weight data structures used
0010 // to describe and track debug location information.
0011 //
0012 //===----------------------------------------------------------------------===//
0013 
0014 #ifndef LLVM_IR_DEBUGLOC_H
0015 #define LLVM_IR_DEBUGLOC_H
0016 
0017 #include "llvm/IR/TrackingMDRef.h"
0018 #include "llvm/Support/DataTypes.h"
0019 
0020 namespace llvm {
0021 
0022   class LLVMContext;
0023   class raw_ostream;
0024   class DILocation;
0025 
0026   /// A debug info location.
0027   ///
0028   /// This class is a wrapper around a tracking reference to an \a DILocation
0029   /// pointer.
0030   ///
0031   /// To avoid extra includes, \a DebugLoc doubles the \a DILocation API with a
0032   /// one based on relatively opaque \a MDNode pointers.
0033   class DebugLoc {
0034     TrackingMDNodeRef Loc;
0035 
0036   public:
0037     DebugLoc() = default;
0038 
0039     /// Construct from an \a DILocation.
0040     DebugLoc(const DILocation *L);
0041 
0042     /// Construct from an \a MDNode.
0043     ///
0044     /// Note: if \c N is not an \a DILocation, a verifier check will fail, and
0045     /// accessors will crash.  However, construction from other nodes is
0046     /// supported in order to handle forward references when reading textual
0047     /// IR.
0048     explicit DebugLoc(const MDNode *N);
0049 
0050     /// Get the underlying \a DILocation.
0051     ///
0052     /// \pre !*this or \c isa<DILocation>(getAsMDNode()).
0053     /// @{
0054     DILocation *get() const;
0055     operator DILocation *() const { return get(); }
0056     DILocation *operator->() const { return get(); }
0057     DILocation &operator*() const { return *get(); }
0058     /// @}
0059 
0060     /// Check for null.
0061     ///
0062     /// Check for null in a way that is safe with broken debug info.  Unlike
0063     /// the conversion to \c DILocation, this doesn't require that \c Loc is of
0064     /// the right type.  Important for cases like \a llvm::StripDebugInfo() and
0065     /// \a Instruction::hasMetadata().
0066     explicit operator bool() const { return Loc; }
0067 
0068     /// Check whether this has a trivial destructor.
0069     bool hasTrivialDestructor() const { return Loc.hasTrivialDestructor(); }
0070 
0071     enum { ReplaceLastInlinedAt = true };
0072     /// Rebuild the entire inlined-at chain for this instruction so that the top of
0073     /// the chain now is inlined-at the new call site.
0074     /// \param   InlinedAt    The new outermost inlined-at in the chain.
0075     static DebugLoc appendInlinedAt(const DebugLoc &DL, DILocation *InlinedAt,
0076                                     LLVMContext &Ctx,
0077                                     DenseMap<const MDNode *, MDNode *> &Cache);
0078 
0079     unsigned getLine() const;
0080     unsigned getCol() const;
0081     MDNode *getScope() const;
0082     DILocation *getInlinedAt() const;
0083 
0084     /// Get the fully inlined-at scope for a DebugLoc.
0085     ///
0086     /// Gets the inlined-at scope for a DebugLoc.
0087     MDNode *getInlinedAtScope() const;
0088 
0089     /// Rebuild the entire inline-at chain by replacing the subprogram at the
0090     /// end of the chain with NewSP.
0091     static DebugLoc
0092     replaceInlinedAtSubprogram(const DebugLoc &DL, DISubprogram &NewSP,
0093                                LLVMContext &Ctx,
0094                                DenseMap<const MDNode *, MDNode *> &Cache);
0095 
0096     /// Find the debug info location for the start of the function.
0097     ///
0098     /// Walk up the scope chain of given debug loc and find line number info
0099     /// for the function.
0100     ///
0101     /// FIXME: Remove this.  Users should use DILocation/DILocalScope API to
0102     /// find the subprogram, and then DILocation::get().
0103     DebugLoc getFnDebugLoc() const;
0104 
0105     /// Return \c this as a bar \a MDNode.
0106     MDNode *getAsMDNode() const { return Loc; }
0107 
0108     /// Check if the DebugLoc corresponds to an implicit code.
0109     bool isImplicitCode() const;
0110     void setImplicitCode(bool ImplicitCode);
0111 
0112     bool operator==(const DebugLoc &DL) const { return Loc == DL.Loc; }
0113     bool operator!=(const DebugLoc &DL) const { return Loc != DL.Loc; }
0114 
0115     void dump() const;
0116 
0117     /// prints source location /path/to/file.exe:line:col @[inlined at]
0118     void print(raw_ostream &OS) const;
0119   };
0120 
0121 } // end namespace llvm
0122 
0123 #endif // LLVM_IR_DEBUGLOC_H