Chromium Code Reviews| Index: src/IceOperand.h |
| diff --git a/src/IceOperand.h b/src/IceOperand.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..2cfd28b6c4d811afccbfc17fa68fdf0b36737129 |
| --- /dev/null |
| +++ b/src/IceOperand.h |
| @@ -0,0 +1,223 @@ |
| +//===- 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 IceOperand class and its target-independent |
| +// subclasses. The main classes are IceVariable, which represents an |
| +// LLVM variable that is either register- or stack-allocated, and the |
|
JF
2014/04/16 01:27:32
Do variables even have a concept of stack at the I
Jim Stichnoth
2014/04/21 20:26:40
I guess you'd say they are SSA values that are ult
|
| +// IceConstant 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" |
| + |
| +class IceOperand { |
| +public: |
| + enum OperandKind { |
| + Constant, |
|
JF
2014/04/16 01:27:32
What's constant but not Int/FP/Reloc?
Jim Stichnoth
2014/04/21 20:26:40
Constant is the abstract superclass of all the con
|
| + ConstantInteger, |
| + ConstantFloat, |
| + ConstantDouble, |
| + ConstantRelocatable, |
| + Constant_Num, |
| + Variable, |
| + // Target-specific operand classes use Target as the starting |
| + // point for their Kind enum space. |
| + Target |
| + }; |
| + OperandKind getKind() const { return Kind; } |
| + IceType getType() const { return Type; } |
| + |
| + // Every IceOperand keeps an array of the IceVariables 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. |
| + uint32_t getNumVars() const { return NumVars; } |
| + IceVariable *getVar(uint32_t I) const { |
| + assert(I < getNumVars()); |
| + return Vars[I]; |
| + } |
| + virtual void setUse(const IceInst *Inst, const IceCfgNode *Node) {} |
|
JF
2014/04/16 01:27:32
Make this pure virtual, error out for constant and
Jim Stichnoth
2014/04/21 20:26:40
Better yet, take this method out of IceOperand and
|
| + virtual void dump(const IceCfg *Cfg) const = 0; |
| + |
| + virtual ~IceOperand() {} |
|
JF
2014/04/16 01:27:32
Ditto on private virtual dtors in derived classes.
Jim Stichnoth
2014/04/21 20:26:40
Done, though I needed to make ~IceConstant() prote
|
| + |
| +protected: |
| + IceOperand(OperandKind Kind, IceType Type) : Type(Type), Kind(Kind) {} |
|
JF
2014/04/16 01:27:32
You should initialize NumVars(0), Vars(NULL) to be
Jim Stichnoth
2014/04/21 20:26:40
Done.
|
| + const IceType Type; |
| + const OperandKind Kind; |
| + // Vars and NumVars are initialized by the derived class. |
| + uint32_t NumVars; |
| + IceVariable **Vars; |
| + |
| +private: |
| + IceOperand(const IceOperand &) LLVM_DELETED_FUNCTION; |
| + IceOperand &operator=(const IceOperand &) LLVM_DELETED_FUNCTION; |
| +}; |
| + |
| +// IceConstant is the abstract base class for constants. All |
| +// constants are allocated from a global arena and are pooled. |
| +class IceConstant : public IceOperand { |
| +public: |
| + virtual void dump(const IceCfg *Cfg) const = 0; |
| + |
| + static bool classof(const IceOperand *Operand) { |
| + OperandKind Kind = Operand->getKind(); |
| + return Kind >= Constant && Kind <= Constant_Num; |
| + } |
| + |
| +protected: |
| + IceConstant(OperandKind Kind, IceType Type) : IceOperand(Kind, Type) { |
| + Vars = NULL; |
| + NumVars = 0; |
| + } |
| + |
| +private: |
| + IceConstant(const IceConstant &) LLVM_DELETED_FUNCTION; |
| + IceConstant &operator=(const IceConstant &) LLVM_DELETED_FUNCTION; |
| +}; |
| + |
| +// IceConstantPrimitive<> wraps a primitive type. |
| +template <typename T, IceOperand::OperandKind K> |
| +class IceConstantPrimitive : public IceConstant { |
| +public: |
| + static IceConstantPrimitive *create(IceGlobalContext *Ctx, IceType Type, |
| + T Value) { |
| + return new (Ctx->allocate<IceConstantPrimitive>()) |
| + IceConstantPrimitive(Type, Value); |
| + } |
| + T getValue() const { return Value; } |
| + virtual void dump(const IceCfg *Cfg) const { |
| + IceOstream &Str = Cfg->getContext()->StrDump; |
| + Str << getValue(); |
| + } |
| + |
| + static bool classof(const IceOperand *Operand) { |
| + return Operand->getKind() == K; |
| + } |
| + |
| +private: |
| + IceConstantPrimitive(IceType Type, T Value) |
| + : IceConstant(K, Type), Value(Value) {} |
| + IceConstantPrimitive(const IceConstantPrimitive &) LLVM_DELETED_FUNCTION; |
| + IceConstantPrimitive & |
| + operator=(const IceConstantPrimitive &) LLVM_DELETED_FUNCTION; |
| + const T Value; |
| +}; |
| + |
| +typedef IceConstantPrimitive<uint64_t, IceOperand::ConstantInteger> |
| +IceConstantInteger; |
| +typedef IceConstantPrimitive<float, IceOperand::ConstantFloat> IceConstantFloat; |
| +typedef IceConstantPrimitive<double, IceOperand::ConstantDouble> |
| +IceConstantDouble; |
| + |
| +// IceConstantRelocatable represents a symbolic constant combined with |
| +// a fixed offset. |
| +class IceConstantRelocatable : public IceConstant { |
| +public: |
| + static IceConstantRelocatable *create(IceGlobalContext *Ctx, uint32_t CPIndex, |
| + IceType Type, const void *Handle, |
| + int64_t Offset, |
| + const IceString &Name = "") { |
| + return new (Ctx->allocate<IceConstantRelocatable>()) |
| + IceConstantRelocatable(Type, Handle, Offset, Name, CPIndex); |
| + } |
| + uint32_t getCPIndex() const { return CPIndex; } |
| + const void *getHandle() const { return Handle; } |
| + 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 IceOperand *Operand) { |
| + OperandKind Kind = Operand->getKind(); |
| + return Kind == ConstantRelocatable; |
| + } |
| + |
| +private: |
| + IceConstantRelocatable(IceType Type, const void *Handle, int64_t Offset, |
| + const IceString &Name, uint32_t CPIndex) |
| + : IceConstant(ConstantRelocatable, Type), CPIndex(CPIndex), |
| + Handle(Handle), Offset(Offset), Name(Name), SuppressMangling(false) {} |
| + IceConstantRelocatable(const IceConstantRelocatable &) LLVM_DELETED_FUNCTION; |
| + IceConstantRelocatable & |
| + operator=(const IceConstantRelocatable &) LLVM_DELETED_FUNCTION; |
| + const uint32_t CPIndex; // index into ICE constant pool |
| + const void *const Handle; // opaque handle e.g. to LLVM |
| + const int64_t Offset; // fixed offset to add |
| + const IceString Name; // optional for debug/dump |
| + bool SuppressMangling; |
| +}; |
| + |
| +// IceVariable 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 IceVariable : public IceOperand { |
| +public: |
| + static IceVariable *create(IceCfg *Cfg, IceType Type, const IceCfgNode *Node, |
| + uint32_t Index, const IceString &Name) { |
| + return new (Cfg->allocate<IceVariable>()) |
| + IceVariable(Type, Node, Index, Name); |
| + } |
| + |
| + uint32_t getIndex() const { return Number; } |
| + IceString getName() const; |
| + |
| + IceInst *getDefinition() const { return DefInst; } |
| + void setDefinition(IceInst *Inst, const IceCfgNode *Node); |
| + void replaceDefinition(IceInst *Inst, const IceCfgNode *Node); |
| + |
| + const IceCfgNode *getLocalUseNode() const { return DefNode; } |
| + bool isMultiblockLife() const { return (DefNode == NULL); } |
| + void setUse(const IceInst *Inst, const IceCfgNode *Node); |
| + |
| + bool getIsArg() const { return IsArgument; } |
| + void setIsArg(IceCfg *Cfg); |
| + |
| + virtual void dump(const IceCfg *Cfg) const; |
| + |
| + static bool classof(const IceOperand *Operand) { |
| + return Operand->getKind() == Variable; |
| + } |
| + |
| +private: |
| + IceVariable(IceType Type, const IceCfgNode *Node, uint32_t Index, |
| + const IceString &Name) |
| + : IceOperand(Variable, Type), Number(Index), Name(Name), DefInst(NULL), |
| + DefNode(Node), IsArgument(false) { |
| + Vars = VarsReal; |
| + Vars[0] = this; |
| + NumVars = 1; |
| + } |
| + IceVariable(const IceVariable &) LLVM_DELETED_FUNCTION; |
| + IceVariable &operator=(const IceVariable &) LLVM_DELETED_FUNCTION; |
| + // Number is unique across all variables, and is used as a |
| + // (bit)vector index for liveness analysis. |
| + const uint32_t Number; |
| + // Name is optional. |
| + const IceString Name; |
| + // DefInst is the instruction that produces this variable as its |
| + // dest. |
| + IceInst *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 IceCfgNode *DefNode; |
| + bool IsArgument; |
| + // VarsReal (and IceOperand::Vars) are set up such that Vars[0] == |
| + // this. |
| + IceVariable *VarsReal[1]; |
| +}; |
| + |
| +#endif // SUBZERO_SRC_ICEOPERAND_H |