Index: src/IceOperand.h |
diff --git a/src/IceOperand.h b/src/IceOperand.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..741cf7742be9a994e8cd3b6c56aa1ff5e7631951 |
--- /dev/null |
+++ b/src/IceOperand.h |
@@ -0,0 +1,247 @@ |
+//===- subzero/src/IceOperand.h - High-level operands -----------*- C++ -*-===// |
+// |
+// The Subzero Code Generator |
+// |
+// This file is distributed under the University of Illinois Open Source |
+// License. See LICENSE.TXT for details. |
+// |
+//===----------------------------------------------------------------------===// |
+// |
+// This file declares the Operand class and its target-independent |
+// subclasses. The main classes are Variable, which represents an |
+// LLVM variable that is either register- or stack-allocated, and the |
+// Constant hierarchy, which represents integer, floating-point, |
+// and/or symbolic constants. |
+// |
+//===----------------------------------------------------------------------===// |
+ |
+#ifndef SUBZERO_SRC_ICEOPERAND_H |
+#define SUBZERO_SRC_ICEOPERAND_H |
+ |
+#include "IceDefs.h" |
+#include "IceTypes.h" |
+ |
+namespace Ice { |
+ |
+class Operand { |
+public: |
+ enum OperandKind { |
+ kConst_Base, |
+ kConstInteger, |
+ kConstFloat, |
+ kConstDouble, |
+ kConstRelocatable, |
+ kConst_Num, |
+ kVariable, |
+ // Target-specific operand classes use kTarget as the starting |
+ // point for their Kind enum space. |
+ kTarget |
+ }; |
+ OperandKind getKind() const { return Kind; } |
+ IceType getType() const { return Type; } |
+ |
+ // Every Operand keeps an array of the Variables referenced in |
+ // the operand. This is so that the liveness operations can get |
+ // quick access to the variables of interest, without having to dig |
+ // so far into the operand. |
+ IceSize_t getNumVars() const { return NumVars; } |
+ Variable *getVar(IceSize_t I) const { |
+ assert(I < getNumVars()); |
+ return Vars[I]; |
+ } |
+ virtual void dump(const IceCfg *Cfg) const = 0; |
+ |
+ // Query whether this object was allocated in isolation, or added to |
+ // some higher-level pool. This determines whether a containing |
+ // object's destructor should delete this object. Generally, |
+ // constants are pooled globally, variables are pooled per-CFG, and |
+ // target-specific operands are not pooled. |
+ virtual bool isPooled() const { return false; } |
+ |
+ virtual ~Operand() {} |
+ |
+protected: |
+ Operand(OperandKind Kind, IceType Type) |
+ : Type(Type), Kind(Kind), NumVars(0), Vars(NULL) {} |
+ |
+ const IceType Type; |
+ const OperandKind Kind; |
+ // Vars and NumVars are initialized by the derived class. |
+ IceSize_t NumVars; |
+ Variable **Vars; |
+ |
+private: |
+ Operand(const Operand &) LLVM_DELETED_FUNCTION; |
+ Operand &operator=(const Operand &) LLVM_DELETED_FUNCTION; |
+}; |
+ |
+// Constant is the abstract base class for constants. All |
+// constants are allocated from a global arena and are pooled. |
+class Constant : public Operand { |
+public: |
+ virtual void dump(const IceCfg *Cfg) const = 0; |
+ |
+ static bool classof(const Operand *Operand) { |
+ OperandKind Kind = Operand->getKind(); |
+ return Kind >= kConst_Base && Kind <= kConst_Num; |
+ } |
+ |
+protected: |
+ Constant(OperandKind Kind, IceType Type) : Operand(Kind, Type) { |
+ Vars = NULL; |
+ NumVars = 0; |
+ } |
+ virtual ~Constant() {} |
+ |
+private: |
+ Constant(const Constant &) LLVM_DELETED_FUNCTION; |
+ Constant &operator=(const Constant &) LLVM_DELETED_FUNCTION; |
+}; |
+ |
+// ConstantPrimitive<> wraps a primitive type. |
+template <typename T, Operand::OperandKind K> |
+class ConstantPrimitive : public Constant { |
+public: |
+ static ConstantPrimitive *create(GlobalContext *Ctx, IceType Type, T Value) { |
+ return new (Ctx->allocate<ConstantPrimitive>()) |
+ ConstantPrimitive(Type, Value); |
+ } |
+ T getValue() const { return Value; } |
+ virtual void dump(const IceCfg *Cfg) const { |
+ IceOstream &Str = Cfg->getContext()->getStrDump(); |
+ Str << getValue(); |
+ } |
+ |
+ static bool classof(const Operand *Operand) { |
+ return Operand->getKind() == K; |
+ } |
+ |
+private: |
+ ConstantPrimitive(IceType Type, T Value) : Constant(K, Type), Value(Value) {} |
+ ConstantPrimitive(const ConstantPrimitive &) LLVM_DELETED_FUNCTION; |
+ ConstantPrimitive &operator=(const ConstantPrimitive &) LLVM_DELETED_FUNCTION; |
+ virtual ~ConstantPrimitive() {} |
+ const T Value; |
+}; |
+ |
+typedef ConstantPrimitive<uint64_t, Operand::kConstInteger> ConstantInteger; |
+typedef ConstantPrimitive<float, Operand::kConstFloat> ConstantFloat; |
+typedef ConstantPrimitive<double, Operand::kConstDouble> ConstantDouble; |
+ |
+// RelocatableTuple bundles the parameters that are used to |
+// construct an ConstantRelocatable. It is done this way so that |
+// ConstantRelocatable can fit into the global constant pool |
+// template mechanism. |
+class RelocatableTuple { |
+ RelocatableTuple &operator=(const RelocatableTuple &) LLVM_DELETED_FUNCTION; |
+ |
+public: |
+ RelocatableTuple(const int64_t Offset, const IceString &Name, |
+ bool SuppressMangling) |
+ : Offset(Offset), Name(Name), SuppressMangling(SuppressMangling) {} |
+ RelocatableTuple(const RelocatableTuple &Other) |
+ : Offset(Other.Offset), Name(Other.Name), |
+ SuppressMangling(Other.SuppressMangling) {} |
+ |
+ const int64_t Offset; |
+ const IceString Name; |
+ bool SuppressMangling; |
+}; |
+ |
+// ConstantRelocatable represents a symbolic constant combined with |
+// a fixed offset. |
+class ConstantRelocatable : public Constant { |
+public: |
+ static ConstantRelocatable *create(GlobalContext *Ctx, IceType Type, |
+ const RelocatableTuple &Tuple) { |
+ return new (Ctx->allocate<ConstantRelocatable>()) ConstantRelocatable( |
+ Type, Tuple.Offset, Tuple.Name, Tuple.SuppressMangling); |
+ } |
+ int64_t getOffset() const { return Offset; } |
+ IceString getName() const { return Name; } |
+ void setSuppressMangling(bool Value) { SuppressMangling = Value; } |
+ bool getSuppressMangling() const { return SuppressMangling; } |
+ virtual void dump(const IceCfg *Cfg) const; |
+ |
+ static bool classof(const Operand *Operand) { |
+ OperandKind Kind = Operand->getKind(); |
+ return Kind == kConstRelocatable; |
+ } |
+ |
+private: |
+ ConstantRelocatable(IceType Type, int64_t Offset, const IceString &Name, |
+ bool SuppressMangling) |
+ : Constant(kConstRelocatable, Type), Offset(Offset), Name(Name), |
+ SuppressMangling(SuppressMangling) {} |
+ ConstantRelocatable(const ConstantRelocatable &) LLVM_DELETED_FUNCTION; |
+ ConstantRelocatable & |
+ operator=(const ConstantRelocatable &) LLVM_DELETED_FUNCTION; |
+ virtual ~ConstantRelocatable() {} |
+ const int64_t Offset; // fixed offset to add |
+ const IceString Name; // optional for debug/dump |
+ bool SuppressMangling; |
+}; |
+ |
+// Variable represents an operand that is register-allocated or |
+// stack-allocated. If it is register-allocated, it will ultimately |
+// have a non-negative RegNum field. |
+class Variable : public Operand { |
+public: |
+ static Variable *create(IceCfg *Cfg, IceType Type, const CfgNode *Node, |
+ IceSize_t Index, const IceString &Name) { |
+ return new (Cfg->allocate<Variable>()) Variable(Type, Node, Index, Name); |
+ } |
+ |
+ IceSize_t getIndex() const { return Number; } |
+ IceString getName() const; |
+ |
+ Inst *getDefinition() const { return DefInst; } |
+ void setDefinition(Inst *Inst, const CfgNode *Node); |
+ void replaceDefinition(Inst *Inst, const CfgNode *Node); |
+ |
+ const CfgNode *getLocalUseNode() const { return DefNode; } |
+ bool isMultiblockLife() const { return (DefNode == NULL); } |
+ void setUse(const Inst *Inst, const CfgNode *Node); |
+ |
+ bool getIsArg() const { return IsArgument; } |
+ void setIsArg(IceCfg *Cfg); |
+ |
+ virtual void dump(const IceCfg *Cfg) const; |
+ |
+ static bool classof(const Operand *Operand) { |
+ return Operand->getKind() == kVariable; |
+ } |
+ |
+private: |
+ Variable(IceType Type, const CfgNode *Node, IceSize_t Index, |
+ const IceString &Name) |
+ : Operand(kVariable, Type), Number(Index), Name(Name), DefInst(NULL), |
+ DefNode(Node), IsArgument(false) { |
+ Vars = VarsReal; |
+ Vars[0] = this; |
+ NumVars = 1; |
+ } |
+ Variable(const Variable &) LLVM_DELETED_FUNCTION; |
+ Variable &operator=(const Variable &) LLVM_DELETED_FUNCTION; |
+ virtual ~Variable() {} |
+ // Number is unique across all variables, and is used as a |
+ // (bit)vector index for liveness analysis. |
+ const IceSize_t Number; |
+ // Name is optional. |
+ const IceString Name; |
+ // DefInst is the instruction that produces this variable as its |
+ // dest. |
+ Inst *DefInst; |
+ // DefNode is the node where this variable was produced, and is |
+ // reset to NULL if it is used outside that node. This is used for |
+ // detecting isMultiblockLife(). |
+ const CfgNode *DefNode; |
+ bool IsArgument; |
+ // VarsReal (and Operand::Vars) are set up such that Vars[0] == |
+ // this. |
+ Variable *VarsReal[1]; |
+}; |
+ |
+} // end of namespace Ice |
+ |
+#endif // SUBZERO_SRC_ICEOPERAND_H |