From: Chris Lattner Date: Fri, 14 Jan 2005 22:07:46 +0000 (+0000) Subject: Start adding some new operators, give IMPLICIT_DEF a chain operand. X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=1cff05c7c216eea0e9173738c2a60b70c2b3c013;p=oota-llvm.git Start adding some new operators, give IMPLICIT_DEF a chain operand. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@19558 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/CodeGen/SelectionDAG.h b/include/llvm/CodeGen/SelectionDAG.h index 5b3fc05d08a..5c55005df85 100644 --- a/include/llvm/CodeGen/SelectionDAG.h +++ b/include/llvm/CodeGen/SelectionDAG.h @@ -44,26 +44,6 @@ class SelectionDAG { // AllNodes - All of the nodes in the DAG std::vector AllNodes; - - // Maps to auto-CSE operations. - std::map >, - SDNode *> UnaryOps; - std::map >, - SDNode *> BinaryOps; - - std::map, ISD::CondCode>, - SetCCSDNode*> SetCCs; - - std::map >, - SDNode *> Loads; - - std::map GlobalValues; - std::map, SDNode*> Constants; - std::map, SDNode*> ConstantFPs; - std::map FrameIndices; - std::map ConstantPoolIndices; - std::map BBNodes; - std::map ExternalSymbols; public: SelectionDAG(const TargetMachine &tm, MachineFunction &mf) : TM(tm), MF(mf) { EntryNode = Root = getNode(ISD::EntryToken, MVT::Other); @@ -119,21 +99,21 @@ public: SDOperand getCopyToReg(SDOperand Chain, SDOperand N, unsigned Reg) { // Note: these are auto-CSE'd because the caller doesn't make requests that // could cause duplicates to occur. - SDNode *NN = new RegSDNode(Chain, N, Reg); + SDNode *NN = new RegSDNode(ISD::CopyToReg, MVT::Other, Chain, N, Reg); AllNodes.push_back(NN); return SDOperand(NN, 0); } SDOperand getCopyFromReg(unsigned Reg, MVT::ValueType VT) { // Note: These nodes are auto-CSE'd by the caller of this method. - SDNode *NN = new RegSDNode(ISD::CopyFromReg, Reg, VT); + SDNode *NN = new RegSDNode(ISD::CopyFromReg, VT, Reg); AllNodes.push_back(NN); return SDOperand(NN, 0); } - SDOperand getImplicitDef(unsigned Reg) { + SDOperand getImplicitDef(SDOperand Chain, unsigned Reg) { // Note: These nodes are auto-CSE'd by the caller of this method. - SDNode *NN = new RegSDNode(ISD::ImplicitDef, Reg, MVT::Other); + SDNode *NN = new RegSDNode(ISD::ImplicitDef, MVT::Other, Chain, Reg); AllNodes.push_back(NN); return SDOperand(NN, 0); } @@ -161,6 +141,13 @@ public: SDOperand getNode(unsigned Opcode, MVT::ValueType VT, std::vector &Children); + // getNode - These versions take an extra value type for extending and + // truncating loads and stores. + SDOperand getNode(unsigned Opcode, MVT::ValueType VT, SDOperand N1, + SDOperand N2, MVT::ValueType EVT); + SDOperand getNode(unsigned Opcode, MVT::ValueType VT, SDOperand N1, + SDOperand N2, SDOperand N3, MVT::ValueType EVT); + /// getLoad - Loads are not normal binary operators: their result type is not /// determined by their operands, and they produce a value AND a token chain. /// @@ -175,6 +162,41 @@ public: private: void DeleteNodeIfDead(SDNode *N, void *NodeSet); + + // Maps to auto-CSE operations. + std::map >, + SDNode *> UnaryOps; + std::map >, + SDNode *> BinaryOps; + + std::map, ISD::CondCode>, + SetCCSDNode*> SetCCs; + + std::map >, + SDNode *> Loads; + + std::map GlobalValues; + std::map, SDNode*> Constants; + std::map, SDNode*> ConstantFPs; + std::map FrameIndices; + std::map ConstantPoolIndices; + std::map BBNodes; + std::map ExternalSymbols; + struct EVTStruct { + unsigned Opcode; + MVT::ValueType VT, EVT; + std::vector Ops; + bool operator<(const EVTStruct &RHS) const { + if (Opcode < RHS.Opcode) return true; + if (Opcode > RHS.Opcode) return false; + if (VT < RHS.VT) return true; + if (VT > RHS.VT) return false; + if (EVT < RHS.EVT) return true; + if (EVT > RHS.EVT) return false; + return Ops < RHS.Ops; + } + }; + std::map MVTSDNodes; }; template <> struct GraphTraits : public GraphTraits { diff --git a/include/llvm/CodeGen/SelectionDAGNodes.h b/include/llvm/CodeGen/SelectionDAGNodes.h index 3627855f146..c9a7df937a9 100644 --- a/include/llvm/CodeGen/SelectionDAGNodes.h +++ b/include/llvm/CodeGen/SelectionDAGNodes.h @@ -138,9 +138,33 @@ namespace ISD { // FP_EXTEND - Extend a smaller FP type into a larger FP type. FP_EXTEND, - // Other operators. LOAD and STORE have token chains. + // Other operators. LOAD and STORE have token chains as their first + // operand, then the same operands as an LLVM load/store instruction. LOAD, STORE, + // EXTLOAD, SEXTLOAD, ZEXTLOAD - These three operators are instances of the + // MVTSDNode. All of these load a value from memory and extend them to a + // larger value (e.g. load a byte into a word register). All three of these + // have two operands, a chain and a pointer to load from. The extra value + // type is the source type being loaded. + // + // SEXTLOAD loads the integer operand and sign extends it to a larger + // integer result type. + // ZEXTLOAD loads the integer operand and zero extends it to a larger + // integer result type. + // EXTLOAD is used for two things: floating point extending loads, and + // integer extending loads where it doesn't matter what the high + // bits are set to. The code generator is allowed to codegen this + // into whichever operation is more efficient. + EXTLOAD, SEXTLOAD, ZEXTLOAD, + + // TRUNCSTORE - This operators truncates (for integer) or rounds (for FP) a + // value and stores it to memory in one operation. This can be used for + // either integer or floating point operands, and the stored type + // represented as the 'extra' value type in the MVTSDNode representing the + // operator. This node has the same three operands as a standard store. + TRUNCSTORE, + // DYNAMIC_STACKALLOC - Allocate some number of bytes on the stack aligned // to a specified boundary. The first operand is the token chain, the // second is the number of bytes to allocate, and the third is the alignment @@ -624,11 +648,17 @@ class RegSDNode : public SDNode { unsigned Reg; protected: friend class SelectionDAG; - RegSDNode(SDOperand Chain, SDOperand Src, unsigned reg) - : SDNode(ISD::CopyToReg, Chain, Src), Reg(reg) { - setValueTypes(MVT::Other); // Just a token chain. + RegSDNode(unsigned Opc, MVT::ValueType VT, SDOperand Chain, + SDOperand Src, unsigned reg) + : SDNode(Opc, Chain, Src), Reg(reg) { + setValueTypes(VT); + } + RegSDNode(unsigned Opc, MVT::ValueType VT, SDOperand Chain, + unsigned reg) + : SDNode(Opc, Chain), Reg(reg) { + setValueTypes(VT); } - RegSDNode(unsigned Opc, unsigned reg, MVT::ValueType VT) + RegSDNode(unsigned Opc, MVT::ValueType VT, unsigned reg) : SDNode(Opc, VT), Reg(reg) { } public: @@ -678,6 +708,35 @@ public: } }; +/// MVTSDNode - This class is used for operators that require an extra +/// value-type to be kept with the node. +class MVTSDNode : public SDNode { + MVT::ValueType ExtraValueType; +protected: + friend class SelectionDAG; + MVTSDNode(unsigned Opc, MVT::ValueType VT, + SDOperand Op0, SDOperand Op1, MVT::ValueType EVT) + : SDNode(Opc, Op0, Op1), ExtraValueType(EVT) { + setValueTypes(VT); + } + MVTSDNode(unsigned Opc, MVT::ValueType VT, + SDOperand Op0, SDOperand Op1, SDOperand Op2, MVT::ValueType EVT) + : SDNode(Opc, Op0, Op1, Op2), ExtraValueType(EVT) { + setValueTypes(VT); + } +public: + + MVT::ValueType getExtraValueType() const { return ExtraValueType; } + + static bool classof(const MVTSDNode *) { return true; } + static bool classof(const SDNode *N) { + return + N->getOpcode() == ISD::EXTLOAD || + N->getOpcode() == ISD::SEXTLOAD || + N->getOpcode() == ISD::ZEXTLOAD || + N->getOpcode() == ISD::TRUNCSTORE; + } +}; class SDNodeIterator : public forward_iterator { SDNode *Node;