diff options
Diffstat (limited to 'contrib/llvm-project/llvm/lib/CodeGen/SelectionDAG/SDNodeDbgValue.h')
-rw-r--r-- | contrib/llvm-project/llvm/lib/CodeGen/SelectionDAG/SDNodeDbgValue.h | 205 |
1 files changed, 151 insertions, 54 deletions
diff --git a/contrib/llvm-project/llvm/lib/CodeGen/SelectionDAG/SDNodeDbgValue.h b/contrib/llvm-project/llvm/lib/CodeGen/SelectionDAG/SDNodeDbgValue.h index 65b9d017fc5c..75b4242a415c 100644 --- a/contrib/llvm-project/llvm/lib/CodeGen/SelectionDAG/SDNodeDbgValue.h +++ b/contrib/llvm-project/llvm/lib/CodeGen/SelectionDAG/SDNodeDbgValue.h @@ -25,69 +25,155 @@ class SDNode; class Value; class raw_ostream; -/// Holds the information from a dbg_value node through SDISel. -/// We do not use SDValue here to avoid including its header. -class SDDbgValue { +/// Holds the information for a single machine location through SDISel; either +/// an SDNode, a constant, a stack location, or a virtual register. +class SDDbgOperand { public: - enum DbgValueKind { - SDNODE = 0, ///< Value is the result of an expression. - CONST = 1, ///< Value is a constant. - FRAMEIX = 2, ///< Value is contents of a stack location. - VREG = 3 ///< Value is a virtual register. + enum Kind { + SDNODE = 0, ///< Value is the result of an expression. + CONST = 1, ///< Value is a constant. + FRAMEIX = 2, ///< Value is contents of a stack location. + VREG = 3 ///< Value is a virtual register. }; + Kind getKind() const { return kind; } + + /// Returns the SDNode* for a register ref + SDNode *getSDNode() const { + assert(kind == SDNODE); + return u.s.Node; + } + + /// Returns the ResNo for a register ref + unsigned getResNo() const { + assert(kind == SDNODE); + return u.s.ResNo; + } + + /// Returns the Value* for a constant + const Value *getConst() const { + assert(kind == CONST); + return u.Const; + } + + /// Returns the FrameIx for a stack object + unsigned getFrameIx() const { + assert(kind == FRAMEIX); + return u.FrameIx; + } + + /// Returns the Virtual Register for a VReg + unsigned getVReg() const { + assert(kind == VREG); + return u.VReg; + } + + static SDDbgOperand fromNode(SDNode *Node, unsigned ResNo) { + return SDDbgOperand(Node, ResNo); + } + static SDDbgOperand fromFrameIdx(unsigned FrameIdx) { + return SDDbgOperand(FrameIdx, FRAMEIX); + } + static SDDbgOperand fromVReg(unsigned VReg) { + return SDDbgOperand(VReg, VREG); + } + static SDDbgOperand fromConst(const Value *Const) { + return SDDbgOperand(Const); + } + + bool operator!=(const SDDbgOperand &Other) const { return !(*this == Other); } + bool operator==(const SDDbgOperand &Other) const { + if (kind != Other.kind) + return false; + switch (kind) { + case SDNODE: + return getSDNode() == Other.getSDNode() && getResNo() == Other.getResNo(); + case CONST: + return getConst() == Other.getConst(); + case VREG: + return getVReg() == Other.getVReg(); + case FRAMEIX: + return getFrameIx() == Other.getFrameIx(); + } + return false; + } + private: + Kind kind; union { struct { - SDNode *Node; ///< Valid for expressions. - unsigned ResNo; ///< Valid for expressions. + SDNode *Node; ///< Valid for expressions. + unsigned ResNo; ///< Valid for expressions. } s; - const Value *Const; ///< Valid for constants. - unsigned FrameIx; ///< Valid for stack objects. - unsigned VReg; ///< Valid for registers. + const Value *Const; ///< Valid for constants. + unsigned FrameIx; ///< Valid for stack objects. + unsigned VReg; ///< Valid for registers. } u; - DIVariable *Var; - DIExpression *Expr; - DebugLoc DL; - unsigned Order; - enum DbgValueKind kind; - bool IsIndirect; - bool Invalid = false; - bool Emitted = false; -public: /// Constructor for non-constants. - SDDbgValue(DIVariable *Var, DIExpression *Expr, SDNode *N, unsigned R, - bool indir, DebugLoc dl, unsigned O) - : Var(Var), Expr(Expr), DL(std::move(dl)), Order(O), IsIndirect(indir) { - kind = SDNODE; + SDDbgOperand(SDNode *N, unsigned R) : kind(SDNODE) { u.s.Node = N; u.s.ResNo = R; } - /// Constructor for constants. - SDDbgValue(DIVariable *Var, DIExpression *Expr, const Value *C, DebugLoc dl, - unsigned O) - : Var(Var), Expr(Expr), DL(std::move(dl)), Order(O), IsIndirect(false) { - kind = CONST; - u.Const = C; - } - + SDDbgOperand(const Value *C) : kind(CONST) { u.Const = C; } /// Constructor for virtual registers and frame indices. - SDDbgValue(DIVariable *Var, DIExpression *Expr, unsigned VRegOrFrameIdx, - bool IsIndirect, DebugLoc DL, unsigned Order, - enum DbgValueKind Kind) - : Var(Var), Expr(Expr), DL(DL), Order(Order), IsIndirect(IsIndirect) { + SDDbgOperand(unsigned VRegOrFrameIdx, Kind Kind) : kind(Kind) { assert((Kind == VREG || Kind == FRAMEIX) && "Invalid SDDbgValue constructor"); - kind = Kind; if (kind == VREG) u.VReg = VRegOrFrameIdx; else u.FrameIx = VRegOrFrameIdx; } +}; - /// Returns the kind. - DbgValueKind getKind() const { return kind; } +/// Holds the information from a dbg_value node through SDISel. +/// We do not use SDValue here to avoid including its header. +class SDDbgValue { +public: + +private: + // SDDbgValues are allocated by a BumpPtrAllocator, which means the destructor + // may not be called; therefore all member arrays must also be allocated by + // that BumpPtrAllocator, to ensure that they are correctly freed. + size_t NumLocationOps; + SDDbgOperand *LocationOps; + // SDNode dependencies will be calculated as SDNodes that appear in + // LocationOps plus these AdditionalDependencies. + size_t NumAdditionalDependencies; + SDNode **AdditionalDependencies; + DIVariable *Var; + DIExpression *Expr; + DebugLoc DL; + unsigned Order; + bool IsIndirect; + bool IsVariadic; + bool Invalid = false; + bool Emitted = false; + +public: + SDDbgValue(BumpPtrAllocator &Alloc, DIVariable *Var, DIExpression *Expr, + ArrayRef<SDDbgOperand> L, ArrayRef<SDNode *> Dependencies, + bool IsIndirect, DebugLoc DL, unsigned O, bool IsVariadic) + : NumLocationOps(L.size()), + LocationOps(Alloc.Allocate<SDDbgOperand>(L.size())), + NumAdditionalDependencies(Dependencies.size()), + AdditionalDependencies(Alloc.Allocate<SDNode *>(Dependencies.size())), + Var(Var), Expr(Expr), DL(DL), Order(O), IsIndirect(IsIndirect), + IsVariadic(IsVariadic) { + assert(IsVariadic || L.size() == 1); + assert(!(IsVariadic && IsIndirect)); + std::copy(L.begin(), L.end(), LocationOps); + std::copy(Dependencies.begin(), Dependencies.end(), AdditionalDependencies); + } + + // We allocate arrays with the BumpPtrAllocator and never free or copy them, + // for LocationOps and AdditionalDependencies, as we never expect to copy or + // destroy an SDDbgValue. If we ever start copying or destroying instances, we + // should manage the allocated memory appropriately. + SDDbgValue(const SDDbgValue &Other) = delete; + SDDbgValue &operator=(const SDDbgValue &Other) = delete; + ~SDDbgValue() = delete; /// Returns the DIVariable pointer for the variable. DIVariable *getVariable() const { return Var; } @@ -95,26 +181,37 @@ public: /// Returns the DIExpression pointer for the expression. DIExpression *getExpression() const { return Expr; } - /// Returns the SDNode* for a register ref - SDNode *getSDNode() const { assert (kind==SDNODE); return u.s.Node; } - - /// Returns the ResNo for a register ref - unsigned getResNo() const { assert (kind==SDNODE); return u.s.ResNo; } + ArrayRef<SDDbgOperand> getLocationOps() const { + return ArrayRef<SDDbgOperand>(LocationOps, NumLocationOps); + } - /// Returns the Value* for a constant - const Value *getConst() const { assert (kind==CONST); return u.Const; } + SmallVector<SDDbgOperand> copyLocationOps() const { + return SmallVector<SDDbgOperand>(LocationOps, LocationOps + NumLocationOps); + } - /// Returns the FrameIx for a stack object - unsigned getFrameIx() const { assert (kind==FRAMEIX); return u.FrameIx; } + // Returns the SDNodes which this SDDbgValue depends on. + SmallVector<SDNode *> getSDNodes() const { + SmallVector<SDNode *> Dependencies; + for (SDDbgOperand DbgOp : getLocationOps()) + if (DbgOp.getKind() == SDDbgOperand::SDNODE) + Dependencies.push_back(DbgOp.getSDNode()); + for (SDNode *Node : getAdditionalDependencies()) + Dependencies.push_back(Node); + return Dependencies; + } - /// Returns the Virtual Register for a VReg - unsigned getVReg() const { assert (kind==VREG); return u.VReg; } + ArrayRef<SDNode *> getAdditionalDependencies() const { + return ArrayRef<SDNode *>(AdditionalDependencies, + NumAdditionalDependencies); + } /// Returns whether this is an indirect value. bool isIndirect() const { return IsIndirect; } + bool isVariadic() const { return IsVariadic; } + /// Returns the DebugLoc. - DebugLoc getDebugLoc() const { return DL; } + const DebugLoc &getDebugLoc() const { return DL; } /// Returns the SDNodeOrder. This is the order of the preceding node in the /// input. @@ -154,7 +251,7 @@ public: MDNode *getLabel() const { return Label; } /// Returns the DebugLoc. - DebugLoc getDebugLoc() const { return DL; } + const DebugLoc &getDebugLoc() const { return DL; } /// Returns the SDNodeOrder. This is the order of the preceding node in the /// input. |