#ifndef LLVM_CODEGEN_SELECTIONDAG_H
#define LLVM_CODEGEN_SELECTIONDAG_H
#include "llvm/ADT/ilist.h"
#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/FoldingSet.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/CodeGen/SelectionDAGNodes.h"
#include "llvm/Target/TargetMachine.h"
#include <cassert>
#include <vector>
#include <map>
#include <string>
namespace llvm {
class AliasAnalysis;
class TargetLowering;
class MachineModuleInfo;
class DwarfWriter;
class MachineFunction;
class MachineConstantPoolValue;
class FunctionLoweringInfo;
template<> struct ilist_traits<SDNode> : public ilist_default_traits<SDNode> {
private:
mutable ilist_node<SDNode> Sentinel;
public:
SDNode *createSentinel() const {
return static_cast<SDNode*>(&Sentinel);
}
static void destroySentinel(SDNode *) {}
SDNode *provideInitialHead() const { return createSentinel(); }
SDNode *ensureHead(SDNode*) const { return createSentinel(); }
static void noteHead(SDNode*, SDNode*) {}
static void deleteNode(SDNode *) {
assert(0 && "ilist_traits<SDNode> shouldn't see a deleteNode call!");
}
private:
static void createNode(const SDNode &);
};
enum CombineLevel {
Unrestricted, NoIllegalTypes, NoIllegalOperations };
class SelectionDAG {
TargetLowering &TLI;
MachineFunction *MF;
FunctionLoweringInfo &FLI;
MachineModuleInfo *MMI;
DwarfWriter *DW;
SDNode EntryNode;
SDValue Root;
ilist<SDNode> AllNodes;
typedef RecyclingAllocator<BumpPtrAllocator, SDNode, sizeof(LargestSDNode),
AlignOf<MostAlignedSDNode>::Alignment>
NodeAllocatorType;
NodeAllocatorType NodeAllocator;
FoldingSet<SDNode> CSEMap;
BumpPtrAllocator OperandAllocator;
BumpPtrAllocator Allocator;
void VerifyNode(SDNode *N);
bool setSubgraphColorHelper(SDNode *N, const char *Color,
DenseSet<SDNode *> &visited,
int level, bool &printed);
public:
SelectionDAG(TargetLowering &tli, FunctionLoweringInfo &fli);
~SelectionDAG();
void init(MachineFunction &mf, MachineModuleInfo *mmi, DwarfWriter *dw);
void clear();
MachineFunction &getMachineFunction() const { return *MF; }
const TargetMachine &getTarget() const;
TargetLowering &getTargetLoweringInfo() const { return TLI; }
FunctionLoweringInfo &getFunctionLoweringInfo() const { return FLI; }
MachineModuleInfo *getMachineModuleInfo() const { return MMI; }
DwarfWriter *getDwarfWriter() const { return DW; }
void viewGraph(const std::string &Title);
void viewGraph();
#ifndef NDEBUG
std::map<const SDNode *, std::string> NodeGraphAttrs;
#endif
void clearGraphAttrs();
void setGraphAttrs(const SDNode *N, const char *Attrs);
const std::string getGraphAttrs(const SDNode *N) const;
void setGraphColor(const SDNode *N, const char *Color);
void setSubgraphColor(SDNode *N, const char *Color);
typedef ilist<SDNode>::const_iterator allnodes_const_iterator;
allnodes_const_iterator allnodes_begin() const { return AllNodes.begin(); }
allnodes_const_iterator allnodes_end() const { return AllNodes.end(); }
typedef ilist<SDNode>::iterator allnodes_iterator;
allnodes_iterator allnodes_begin() { return AllNodes.begin(); }
allnodes_iterator allnodes_end() { return AllNodes.end(); }
ilist<SDNode>::size_type allnodes_size() const {
return AllNodes.size();
}
const SDValue &getRoot() const { return Root; }
SDValue getEntryNode() const {
return SDValue(const_cast<SDNode *>(&EntryNode), 0);
}
const SDValue &setRoot(SDValue N) {
assert((!N.getNode() || N.getValueType() == MVT::Other) &&
"DAG root value is not a chain!");
return Root = N;
}
void Combine(CombineLevel Level, AliasAnalysis &AA,
CodeGenOpt::Level OptLevel);
bool LegalizeTypes();
void Legalize(bool TypesNeedLegalizing, CodeGenOpt::Level OptLevel);
void RemoveDeadNodes();
void DeleteNode(SDNode *N);
SDVTList getVTList(MVT VT);
SDVTList getVTList(MVT VT1, MVT VT2);
SDVTList getVTList(MVT VT1, MVT VT2, MVT VT3);
SDVTList getVTList(MVT VT1, MVT VT2, MVT VT3, MVT VT4);
SDVTList getVTList(const MVT *VTs, unsigned NumVTs);
SDValue getConstant(uint64_t Val, MVT VT, bool isTarget = false);
SDValue getConstant(const APInt &Val, MVT VT, bool isTarget = false);
SDValue getConstant(const ConstantInt &Val, MVT VT, bool isTarget = false);
SDValue getIntPtrConstant(uint64_t Val, bool isTarget = false);
SDValue getTargetConstant(uint64_t Val, MVT VT) {
return getConstant(Val, VT, true);
}
SDValue getTargetConstant(const APInt &Val, MVT VT) {
return getConstant(Val, VT, true);
}
SDValue getTargetConstant(const ConstantInt &Val, MVT VT) {
return getConstant(Val, VT, true);
}
SDValue getConstantFP(double Val, MVT VT, bool isTarget = false);
SDValue getConstantFP(const APFloat& Val, MVT VT, bool isTarget = false);
SDValue getConstantFP(const ConstantFP &CF, MVT VT, bool isTarget = false);
SDValue getTargetConstantFP(double Val, MVT VT) {
return getConstantFP(Val, VT, true);
}
SDValue getTargetConstantFP(const APFloat& Val, MVT VT) {
return getConstantFP(Val, VT, true);
}
SDValue getTargetConstantFP(const ConstantFP &Val, MVT VT) {
return getConstantFP(Val, VT, true);
}
SDValue getGlobalAddress(const GlobalValue *GV, MVT VT,
int64_t offset = 0, bool isTargetGA = false);
SDValue getTargetGlobalAddress(const GlobalValue *GV, MVT VT,
int64_t offset = 0) {
return getGlobalAddress(GV, VT, offset, true);
}
SDValue getFrameIndex(int FI, MVT VT, bool isTarget = false);
SDValue getTargetFrameIndex(int FI, MVT VT) {
return getFrameIndex(FI, VT, true);
}
SDValue getJumpTable(int JTI, MVT VT, bool isTarget = false);
SDValue getTargetJumpTable(int JTI, MVT VT) {
return getJumpTable(JTI, VT, true);
}
SDValue getConstantPool(Constant *C, MVT VT,
unsigned Align = 0, int Offs = 0, bool isT=false);
SDValue getTargetConstantPool(Constant *C, MVT VT,
unsigned Align = 0, int Offset = 0) {
return getConstantPool(C, VT, Align, Offset, true);
}
SDValue getConstantPool(MachineConstantPoolValue *C, MVT VT,
unsigned Align = 0, int Offs = 0, bool isT=false);
SDValue getTargetConstantPool(MachineConstantPoolValue *C,
MVT VT, unsigned Align = 0,
int Offset = 0) {
return getConstantPool(C, VT, Align, Offset, true);
}
SDValue getBasicBlock(MachineBasicBlock *MBB);
SDValue getBasicBlock(MachineBasicBlock *MBB, DebugLoc dl);
SDValue getExternalSymbol(const char *Sym, MVT VT);
SDValue getExternalSymbol(const char *Sym, DebugLoc dl, MVT VT);
SDValue getTargetExternalSymbol(const char *Sym, MVT VT);
SDValue getTargetExternalSymbol(const char *Sym, DebugLoc dl, MVT VT);
SDValue getArgFlags(ISD::ArgFlagsTy Flags);
SDValue getValueType(MVT);
SDValue getRegister(unsigned Reg, MVT VT);
SDValue getDbgStopPoint(SDValue Root, unsigned Line, unsigned Col,
Value *CU);
SDValue getLabel(unsigned Opcode, DebugLoc dl, SDValue Root,
unsigned LabelID);
SDValue getCopyToReg(SDValue Chain, DebugLoc dl, unsigned Reg, SDValue N) {
return getNode(ISD::CopyToReg, dl, MVT::Other, Chain,
getRegister(Reg, N.getValueType()), N);
}
SDValue getCopyToReg(SDValue Chain, DebugLoc dl, unsigned Reg, SDValue N,
SDValue Flag) {
SDVTList VTs = getVTList(MVT::Other, MVT::Flag);
SDValue Ops[] = { Chain, getRegister(Reg, N.getValueType()), N, Flag };
return getNode(ISD::CopyToReg, dl, VTs, Ops, Flag.getNode() ? 4 : 3);
}
SDValue getCopyToReg(SDValue Chain, DebugLoc dl, SDValue Reg, SDValue N,
SDValue Flag) {
SDVTList VTs = getVTList(MVT::Other, MVT::Flag);
SDValue Ops[] = { Chain, Reg, N, Flag };
return getNode(ISD::CopyToReg, dl, VTs, Ops, Flag.getNode() ? 4 : 3);
}
SDValue getCopyFromReg(SDValue Chain, DebugLoc dl, unsigned Reg, MVT VT) {
SDVTList VTs = getVTList(VT, MVT::Other);
SDValue Ops[] = { Chain, getRegister(Reg, VT) };
return getNode(ISD::CopyFromReg, dl, VTs, Ops, 2);
}
SDValue getCopyFromReg(SDValue Chain, DebugLoc dl, unsigned Reg, MVT VT,
SDValue Flag) {
SDVTList VTs = getVTList(VT, MVT::Other, MVT::Flag);
SDValue Ops[] = { Chain, getRegister(Reg, VT), Flag };
return getNode(ISD::CopyFromReg, dl, VTs, Ops, Flag.getNode() ? 3 : 2);
}
SDValue getCondCode(ISD::CondCode Cond);
SDValue getConvertRndSat(MVT VT, DebugLoc dl, SDValue Val, SDValue DTy,
SDValue STy,
SDValue Rnd, SDValue Sat, ISD::CvtCode Code);
SDValue getVectorShuffle(MVT VT, DebugLoc dl, SDValue N1, SDValue N2,
const int *MaskElts);
SDValue getZeroExtendInReg(SDValue Op, DebugLoc DL, MVT SrcTy);
SDValue getNOT(DebugLoc DL, SDValue Val, MVT VT);
SDValue getCALLSEQ_START(SDValue Chain, SDValue Op) {
SDVTList VTs = getVTList(MVT::Other, MVT::Flag);
SDValue Ops[] = { Chain, Op };
return getNode(ISD::CALLSEQ_START, DebugLoc::getUnknownLoc(),
VTs, Ops, 2);
}
SDValue getCALLSEQ_END(SDValue Chain, SDValue Op1, SDValue Op2,
SDValue InFlag) {
SDVTList NodeTys = getVTList(MVT::Other, MVT::Flag);
SmallVector<SDValue, 4> Ops;
Ops.push_back(Chain);
Ops.push_back(Op1);
Ops.push_back(Op2);
Ops.push_back(InFlag);
return getNode(ISD::CALLSEQ_END, DebugLoc::getUnknownLoc(), NodeTys,
&Ops[0],
(unsigned)Ops.size() - (InFlag.getNode() == 0 ? 1 : 0));
}
SDValue getUNDEF(MVT VT) {
return getNode(ISD::UNDEF, DebugLoc::getUnknownLoc(), VT);
}
SDValue getGLOBAL_OFFSET_TABLE(MVT VT) {
return getNode(ISD::GLOBAL_OFFSET_TABLE, DebugLoc::getUnknownLoc(), VT);
}
SDValue getNode(unsigned Opcode, DebugLoc DL, MVT VT);
SDValue getNode(unsigned Opcode, DebugLoc DL, MVT VT, SDValue N);
SDValue getNode(unsigned Opcode, DebugLoc DL, MVT VT, SDValue N1, SDValue N2);
SDValue getNode(unsigned Opcode, DebugLoc DL, MVT VT,
SDValue N1, SDValue N2, SDValue N3);
SDValue getNode(unsigned Opcode, DebugLoc DL, MVT VT,
SDValue N1, SDValue N2, SDValue N3, SDValue N4);
SDValue getNode(unsigned Opcode, DebugLoc DL, MVT VT,
SDValue N1, SDValue N2, SDValue N3, SDValue N4,
SDValue N5);
SDValue getNode(unsigned Opcode, DebugLoc DL, MVT VT,
const SDUse *Ops, unsigned NumOps);
SDValue getNode(unsigned Opcode, DebugLoc DL, MVT VT,
const SDValue *Ops, unsigned NumOps);
SDValue getNode(unsigned Opcode, DebugLoc DL,
const std::vector<MVT> &ResultTys,
const SDValue *Ops, unsigned NumOps);
SDValue getNode(unsigned Opcode, DebugLoc DL, const MVT *VTs, unsigned NumVTs,
const SDValue *Ops, unsigned NumOps);
SDValue getNode(unsigned Opcode, DebugLoc DL, SDVTList VTs,
const SDValue *Ops, unsigned NumOps);
SDValue getNode(unsigned Opcode, DebugLoc DL, SDVTList VTs);
SDValue getNode(unsigned Opcode, DebugLoc DL, SDVTList VTs, SDValue N);
SDValue getNode(unsigned Opcode, DebugLoc DL, SDVTList VTs,
SDValue N1, SDValue N2);
SDValue getNode(unsigned Opcode, DebugLoc DL, SDVTList VTs,
SDValue N1, SDValue N2, SDValue N3);
SDValue getNode(unsigned Opcode, DebugLoc DL, SDVTList VTs,
SDValue N1, SDValue N2, SDValue N3, SDValue N4);
SDValue getNode(unsigned Opcode, DebugLoc DL, SDVTList VTs,
SDValue N1, SDValue N2, SDValue N3, SDValue N4,
SDValue N5);
SDValue getMemcpy(SDValue Chain, DebugLoc dl, SDValue Dst, SDValue Src,
SDValue Size, unsigned Align, bool AlwaysInline,
const Value *DstSV, uint64_t DstSVOff,
const Value *SrcSV, uint64_t SrcSVOff);
SDValue getMemmove(SDValue Chain, DebugLoc dl, SDValue Dst, SDValue Src,
SDValue Size, unsigned Align,
const Value *DstSV, uint64_t DstOSVff,
const Value *SrcSV, uint64_t SrcSVOff);
SDValue getMemset(SDValue Chain, DebugLoc dl, SDValue Dst, SDValue Src,
SDValue Size, unsigned Align,
const Value *DstSV, uint64_t DstSVOff);
SDValue getSetCC(DebugLoc DL, MVT VT, SDValue LHS, SDValue RHS,
ISD::CondCode Cond) {
return getNode(ISD::SETCC, DL, VT, LHS, RHS, getCondCode(Cond));
}
SDValue getVSetCC(DebugLoc DL, MVT VT, SDValue LHS, SDValue RHS,
ISD::CondCode Cond) {
return getNode(ISD::VSETCC, DL, VT, LHS, RHS, getCondCode(Cond));
}
SDValue getSelectCC(DebugLoc DL, SDValue LHS, SDValue RHS,
SDValue True, SDValue False, ISD::CondCode Cond) {
return getNode(ISD::SELECT_CC, DL, True.getValueType(),
LHS, RHS, True, False, getCondCode(Cond));
}
SDValue getVAArg(MVT VT, DebugLoc dl, SDValue Chain, SDValue Ptr,
SDValue SV);
SDValue getAtomic(unsigned Opcode, DebugLoc dl, MVT MemVT, SDValue Chain,
SDValue Ptr, SDValue Cmp, SDValue Swp, const Value* PtrVal,
unsigned Alignment=0);
SDValue getAtomic(unsigned Opcode, DebugLoc dl, MVT MemVT, SDValue Chain,
SDValue Ptr, SDValue Val, const Value* PtrVal,
unsigned Alignment = 0);
SDValue getMemIntrinsicNode(unsigned Opcode, DebugLoc dl,
const MVT *VTs, unsigned NumVTs,
const SDValue *Ops, unsigned NumOps,
MVT MemVT, const Value *srcValue, int SVOff,
unsigned Align = 0, bool Vol = false,
bool ReadMem = true, bool WriteMem = true);
SDValue getMemIntrinsicNode(unsigned Opcode, DebugLoc dl, SDVTList VTList,
const SDValue *Ops, unsigned NumOps,
MVT MemVT, const Value *srcValue, int SVOff,
unsigned Align = 0, bool Vol = false,
bool ReadMem = true, bool WriteMem = true);
SDValue getMergeValues(const SDValue *Ops, unsigned NumOps, DebugLoc dl);
SDValue getCall(unsigned CallingConv, DebugLoc dl, bool IsVarArgs,
bool IsTailCall, bool isInreg, SDVTList VTs,
const SDValue *Operands, unsigned NumOperands);
SDValue getLoad(MVT VT, DebugLoc dl, SDValue Chain, SDValue Ptr,
const Value *SV, int SVOffset, bool isVolatile=false,
unsigned Alignment=0);
SDValue getExtLoad(ISD::LoadExtType ExtType, DebugLoc dl, MVT VT,
SDValue Chain, SDValue Ptr, const Value *SV,
int SVOffset, MVT EVT, bool isVolatile=false,
unsigned Alignment=0);
SDValue getIndexedLoad(SDValue OrigLoad, DebugLoc dl, SDValue Base,
SDValue Offset, ISD::MemIndexedMode AM);
SDValue getLoad(ISD::MemIndexedMode AM, DebugLoc dl, ISD::LoadExtType ExtType,
MVT VT, SDValue Chain,
SDValue Ptr, SDValue Offset,
const Value *SV, int SVOffset, MVT EVT,
bool isVolatile=false, unsigned Alignment=0);
SDValue getStore(SDValue Chain, DebugLoc dl, SDValue Val, SDValue Ptr,
const Value *SV, int SVOffset, bool isVolatile=false,
unsigned Alignment=0);
SDValue getTruncStore(SDValue Chain, DebugLoc dl, SDValue Val, SDValue Ptr,
const Value *SV, int SVOffset, MVT TVT,
bool isVolatile=false, unsigned Alignment=0);
SDValue getIndexedStore(SDValue OrigStoe, DebugLoc dl, SDValue Base,
SDValue Offset, ISD::MemIndexedMode AM);
SDValue getSrcValue(const Value *v);
SDValue getMemOperand(const MachineMemOperand &MO);
SDValue getShiftAmountOperand(SDValue Op);
SDValue UpdateNodeOperands(SDValue N, SDValue Op);
SDValue UpdateNodeOperands(SDValue N, SDValue Op1, SDValue Op2);
SDValue UpdateNodeOperands(SDValue N, SDValue Op1, SDValue Op2,
SDValue Op3);
SDValue UpdateNodeOperands(SDValue N, SDValue Op1, SDValue Op2,
SDValue Op3, SDValue Op4);
SDValue UpdateNodeOperands(SDValue N, SDValue Op1, SDValue Op2,
SDValue Op3, SDValue Op4, SDValue Op5);
SDValue UpdateNodeOperands(SDValue N,
const SDValue *Ops, unsigned NumOps);
SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT);
SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT, SDValue Op1);
SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT,
SDValue Op1, SDValue Op2);
SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT,
SDValue Op1, SDValue Op2, SDValue Op3);
SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT,
const SDValue *Ops, unsigned NumOps);
SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT1, MVT VT2);
SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT1,
MVT VT2, const SDValue *Ops, unsigned NumOps);
SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT1,
MVT VT2, MVT VT3, const SDValue *Ops, unsigned NumOps);
SDNode *SelectNodeTo(SDNode *N, unsigned MachineOpc, MVT VT1,
MVT VT2, MVT VT3, MVT VT4, const SDValue *Ops,
unsigned NumOps);
SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT1,
MVT VT2, SDValue Op1);
SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT1,
MVT VT2, SDValue Op1, SDValue Op2);
SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT1,
MVT VT2, SDValue Op1, SDValue Op2, SDValue Op3);
SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT1,
MVT VT2, MVT VT3, SDValue Op1, SDValue Op2, SDValue Op3);
SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, SDVTList VTs,
const SDValue *Ops, unsigned NumOps);
SDNode *MorphNodeTo(SDNode *N, unsigned Opc, MVT VT);
SDNode *MorphNodeTo(SDNode *N, unsigned Opc, MVT VT, SDValue Op1);
SDNode *MorphNodeTo(SDNode *N, unsigned Opc, MVT VT,
SDValue Op1, SDValue Op2);
SDNode *MorphNodeTo(SDNode *N, unsigned Opc, MVT VT,
SDValue Op1, SDValue Op2, SDValue Op3);
SDNode *MorphNodeTo(SDNode *N, unsigned Opc, MVT VT,
const SDValue *Ops, unsigned NumOps);
SDNode *MorphNodeTo(SDNode *N, unsigned Opc, MVT VT1, MVT VT2);
SDNode *MorphNodeTo(SDNode *N, unsigned Opc, MVT VT1,
MVT VT2, const SDValue *Ops, unsigned NumOps);
SDNode *MorphNodeTo(SDNode *N, unsigned Opc, MVT VT1,
MVT VT2, MVT VT3, const SDValue *Ops, unsigned NumOps);
SDNode *MorphNodeTo(SDNode *N, unsigned Opc, MVT VT1,
MVT VT2, SDValue Op1);
SDNode *MorphNodeTo(SDNode *N, unsigned Opc, MVT VT1,
MVT VT2, SDValue Op1, SDValue Op2);
SDNode *MorphNodeTo(SDNode *N, unsigned Opc, MVT VT1,
MVT VT2, SDValue Op1, SDValue Op2, SDValue Op3);
SDNode *MorphNodeTo(SDNode *N, unsigned Opc, SDVTList VTs,
const SDValue *Ops, unsigned NumOps);
SDNode *getTargetNode(unsigned Opcode, DebugLoc dl, MVT VT);
SDNode *getTargetNode(unsigned Opcode, DebugLoc dl, MVT VT, SDValue Op1);
SDNode *getTargetNode(unsigned Opcode, DebugLoc dl, MVT VT, SDValue Op1,
SDValue Op2);
SDNode *getTargetNode(unsigned Opcode, DebugLoc dl, MVT VT,
SDValue Op1, SDValue Op2, SDValue Op3);
SDNode *getTargetNode(unsigned Opcode, DebugLoc dl, MVT VT,
const SDValue *Ops, unsigned NumOps);
SDNode *getTargetNode(unsigned Opcode, DebugLoc dl, MVT VT1, MVT VT2);
SDNode *getTargetNode(unsigned Opcode, DebugLoc dl, MVT VT1, MVT VT2,
SDValue Op1);
SDNode *getTargetNode(unsigned Opcode, DebugLoc dl, MVT VT1,
MVT VT2, SDValue Op1, SDValue Op2);
SDNode *getTargetNode(unsigned Opcode, DebugLoc dl, MVT VT1,
MVT VT2, SDValue Op1, SDValue Op2, SDValue Op3);
SDNode *getTargetNode(unsigned Opcode, DebugLoc dl, MVT VT1, MVT VT2,
const SDValue *Ops, unsigned NumOps);
SDNode *getTargetNode(unsigned Opcode, DebugLoc dl, MVT VT1, MVT VT2, MVT VT3,
SDValue Op1, SDValue Op2);
SDNode *getTargetNode(unsigned Opcode, DebugLoc dl, MVT VT1, MVT VT2, MVT VT3,
SDValue Op1, SDValue Op2, SDValue Op3);
SDNode *getTargetNode(unsigned Opcode, DebugLoc dl, MVT VT1, MVT VT2, MVT VT3,
const SDValue *Ops, unsigned NumOps);
SDNode *getTargetNode(unsigned Opcode, DebugLoc dl, MVT VT1, MVT VT2, MVT VT3,
MVT VT4, const SDValue *Ops, unsigned NumOps);
SDNode *getTargetNode(unsigned Opcode, DebugLoc dl,
const std::vector<MVT> &ResultTys, const SDValue *Ops,
unsigned NumOps);
SDNode *getNodeIfExists(unsigned Opcode, SDVTList VTs,
const SDValue *Ops, unsigned NumOps);
class DAGUpdateListener {
public:
virtual ~DAGUpdateListener();
virtual void NodeDeleted(SDNode *N, SDNode *E) = 0;
virtual void NodeUpdated(SDNode *N) = 0;
};
void RemoveDeadNode(SDNode *N, DAGUpdateListener *UpdateListener = 0);
void RemoveDeadNodes(SmallVectorImpl<SDNode *> &DeadNodes,
DAGUpdateListener *UpdateListener = 0);
void ReplaceAllUsesWith(SDValue From, SDValue Op,
DAGUpdateListener *UpdateListener = 0);
void ReplaceAllUsesWith(SDNode *From, SDNode *To,
DAGUpdateListener *UpdateListener = 0);
void ReplaceAllUsesWith(SDNode *From, const SDValue *To,
DAGUpdateListener *UpdateListener = 0);
void ReplaceAllUsesOfValueWith(SDValue From, SDValue To,
DAGUpdateListener *UpdateListener = 0);
void ReplaceAllUsesOfValuesWith(const SDValue *From, const SDValue *To,
unsigned Num,
DAGUpdateListener *UpdateListener = 0);
unsigned AssignTopologicalOrder();
void RepositionNode(allnodes_iterator Position, SDNode *N) {
AllNodes.insert(Position, AllNodes.remove(N));
}
static bool isCommutativeBinOp(unsigned Opcode) {
switch (Opcode) {
case ISD::ADD:
case ISD::MUL:
case ISD::MULHU:
case ISD::MULHS:
case ISD::SMUL_LOHI:
case ISD::UMUL_LOHI:
case ISD::FADD:
case ISD::FMUL:
case ISD::AND:
case ISD::OR:
case ISD::XOR:
case ISD::SADDO:
case ISD::UADDO:
case ISD::ADDC:
case ISD::ADDE: return true;
default: return false;
}
}
void dump() const;
SDValue CreateStackTemporary(MVT VT, unsigned minAlign = 1);
SDValue CreateStackTemporary(MVT VT1, MVT VT2);
SDValue FoldConstantArithmetic(unsigned Opcode,
MVT VT,
ConstantSDNode *Cst1,
ConstantSDNode *Cst2);
SDValue FoldSetCC(MVT VT, SDValue N1,
SDValue N2, ISD::CondCode Cond, DebugLoc dl);
bool SignBitIsZero(SDValue Op, unsigned Depth = 0) const;
bool MaskedValueIsZero(SDValue Op, const APInt &Mask, unsigned Depth = 0)
const;
void ComputeMaskedBits(SDValue Op, const APInt &Mask, APInt &KnownZero,
APInt &KnownOne, unsigned Depth = 0) const;
unsigned ComputeNumSignBits(SDValue Op, unsigned Depth = 0) const;
bool isVerifiedDebugInfoDesc(SDValue Op) const;
SDValue getShuffleScalarElt(const SDNode *N, unsigned Idx);
private:
bool RemoveNodeFromCSEMaps(SDNode *N);
void AddModifiedNodeToCSEMaps(SDNode *N, DAGUpdateListener *UpdateListener);
SDNode *FindModifiedNodeSlot(SDNode *N, SDValue Op, void *&InsertPos);
SDNode *FindModifiedNodeSlot(SDNode *N, SDValue Op1, SDValue Op2,
void *&InsertPos);
SDNode *FindModifiedNodeSlot(SDNode *N, const SDValue *Ops, unsigned NumOps,
void *&InsertPos);
void DeleteNodeNotInCSEMaps(SDNode *N);
void DeallocateNode(SDNode *N);
unsigned getMVTAlignment(MVT MemoryVT) const;
void allnodes_clear();
std::vector<SDVTList> VTList;
std::vector<CondCodeSDNode*> CondCodeNodes;
std::vector<SDNode*> ValueTypeNodes;
std::map<MVT, SDNode*, MVT::compareRawBits> ExtendedValueTypeNodes;
StringMap<SDNode*> ExternalSymbols;
StringMap<SDNode*> TargetExternalSymbols;
};
template <> struct GraphTraits<SelectionDAG*> : public GraphTraits<SDNode*> {
typedef SelectionDAG::allnodes_iterator nodes_iterator;
static nodes_iterator nodes_begin(SelectionDAG *G) {
return G->allnodes_begin();
}
static nodes_iterator nodes_end(SelectionDAG *G) {
return G->allnodes_end();
}
};
}
#endif