#ifndef LLVM_LIB_CODEGEN_SELECTIONDAG_SDNODEDBGVALUE_H
#define LLVM_LIB_CODEGEN_SELECTIONDAG_SDNODEDBGVALUE_H
#include "llvm/IR/DebugLoc.h"
#include "llvm/Support/Allocator.h"
#include "llvm/Support/DataTypes.h"
#include <utility>
namespace llvm {
class DIVariable;
class DIExpression;
class SDNode;
class Value;
class raw_ostream;
class SDDbgOperand {
public:
enum Kind {
SDNODE = 0, CONST = 1, FRAMEIX = 2, VREG = 3 };
Kind getKind() const { return kind; }
SDNode *getSDNode() const {
assert(kind == SDNODE);
return u.s.Node;
}
unsigned getResNo() const {
assert(kind == SDNODE);
return u.s.ResNo;
}
const Value *getConst() const {
assert(kind == CONST);
return u.Const;
}
unsigned getFrameIx() const {
assert(kind == FRAMEIX);
return u.FrameIx;
}
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; unsigned ResNo; } s;
const Value *Const; unsigned FrameIx; unsigned VReg; } u;
SDDbgOperand(SDNode *N, unsigned R) : kind(SDNODE) {
u.s.Node = N;
u.s.ResNo = R;
}
SDDbgOperand(const Value *C) : kind(CONST) { u.Const = C; }
SDDbgOperand(unsigned VRegOrFrameIdx, Kind Kind) : kind(Kind) {
assert((Kind == VREG || Kind == FRAMEIX) &&
"Invalid SDDbgValue constructor");
if (kind == VREG)
u.VReg = VRegOrFrameIdx;
else
u.FrameIx = VRegOrFrameIdx;
}
};
class SDDbgValue {
public:
private:
size_t NumLocationOps;
SDDbgOperand *LocationOps;
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);
}
SDDbgValue(const SDDbgValue &Other) = delete;
SDDbgValue &operator=(const SDDbgValue &Other) = delete;
~SDDbgValue() = delete;
DIVariable *getVariable() const { return Var; }
DIExpression *getExpression() const { return Expr; }
ArrayRef<SDDbgOperand> getLocationOps() const {
return ArrayRef<SDDbgOperand>(LocationOps, NumLocationOps);
}
SmallVector<SDDbgOperand> copyLocationOps() const {
return SmallVector<SDDbgOperand>(LocationOps, LocationOps + NumLocationOps);
}
SmallVector<SDNode *> getSDNodes() const {
SmallVector<SDNode *> Dependencies;
for (const SDDbgOperand &DbgOp : getLocationOps())
if (DbgOp.getKind() == SDDbgOperand::SDNODE)
Dependencies.push_back(DbgOp.getSDNode());
for (SDNode *Node : getAdditionalDependencies())
Dependencies.push_back(Node);
return Dependencies;
}
ArrayRef<SDNode *> getAdditionalDependencies() const {
return ArrayRef<SDNode *>(AdditionalDependencies,
NumAdditionalDependencies);
}
bool isIndirect() const { return IsIndirect; }
bool isVariadic() const { return IsVariadic; }
const DebugLoc &getDebugLoc() const { return DL; }
unsigned getOrder() const { return Order; }
void setIsInvalidated() { Invalid = true; }
bool isInvalidated() const { return Invalid; }
void setIsEmitted() { Emitted = true; }
bool isEmitted() const { return Emitted; }
void clearIsEmitted() { Emitted = false; }
LLVM_DUMP_METHOD void dump() const;
LLVM_DUMP_METHOD void print(raw_ostream &OS) const;
};
class SDDbgLabel {
MDNode *Label;
DebugLoc DL;
unsigned Order;
public:
SDDbgLabel(MDNode *Label, DebugLoc dl, unsigned O)
: Label(Label), DL(std::move(dl)), Order(O) {}
MDNode *getLabel() const { return Label; }
const DebugLoc &getDebugLoc() const { return DL; }
unsigned getOrder() const { return Order; }
};
}
#endif