Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 //===- subzero/src/IceTargetLowering.h - Lowering interface -----*- C++ -*-===// | |
| 2 // | |
| 3 // The Subzero Code Generator | |
| 4 // | |
| 5 // This file is distributed under the University of Illinois Open Source | |
| 6 // License. See LICENSE.TXT for details. | |
| 7 // | |
| 8 //===----------------------------------------------------------------------===// | |
| 9 // | |
| 10 // This file declares the TargetLowering and LoweringContext | |
| 11 // classes. TargetLowering is an abstract class used to drive the | |
| 12 // translation/lowering process. LoweringContext maintains a | |
| 13 // context for lowering each instruction, offering conveniences such | |
| 14 // as iterating over non-deleted instructions. | |
| 15 // | |
| 16 //===----------------------------------------------------------------------===// | |
| 17 | |
| 18 #ifndef SUBZERO_SRC_ICETARGETLOWERING_H | |
| 19 #define SUBZERO_SRC_ICETARGETLOWERING_H | |
| 20 | |
| 21 #include "IceDefs.h" | |
| 22 #include "IceTypes.h" | |
| 23 | |
| 24 #include "IceInst.h" // for the names of the Inst subtypes | |
| 25 | |
| 26 namespace Ice { | |
| 27 | |
| 28 // LoweringContext makes it easy to iterate through non-deleted | |
| 29 // instructions in a node, and insert new (lowered) instructions at | |
| 30 // the current point. Along with the instruction list container and | |
| 31 // associated iterators, it holds the current node, which is needed | |
| 32 // when inserting new instructions in order to track whether variables | |
| 33 // are used as single-block or multi-block. | |
| 34 class LoweringContext { | |
| 35 public: | |
| 36 LoweringContext() : Node(NULL) {} | |
|
JF
2014/05/04 23:54:58
Missing dtor.
Jim Stichnoth
2014/05/05 07:03:55
Done.
| |
| 37 void init(CfgNode *Node); | |
| 38 Inst *getNextInst() const { | |
| 39 if (Next == End) | |
| 40 return NULL; | |
| 41 return *Next; | |
| 42 } | |
| 43 CfgNode *getNode() const { return Node; } | |
| 44 bool atEnd() const { return Cur == End; } | |
| 45 InstList::iterator getCur() const { return Cur; } | |
| 46 InstList::iterator getEnd() const { return End; } | |
| 47 void insert(Inst *Inst); | |
| 48 void advanceCur() { Cur = Next; } | |
| 49 void advanceNext() { advance(Next); } | |
| 50 void setInsertPoint(const InstList::iterator &Position) { | |
| 51 Next = Position; | |
| 52 } | |
| 53 | |
| 54 private: | |
| 55 // Node is the argument to Inst::updateVars(). | |
| 56 CfgNode *Node; | |
| 57 // Cur points to the current instruction being considered. It is | |
| 58 // guaranteed to point to a non-deleted instruction, or to be End. | |
| 59 InstList::iterator Cur; | |
| 60 // Next doubles as a pointer to the next valid instruction (if any), | |
| 61 // and the new-instruction insertion point. It is also updated for | |
| 62 // the caller in case the lowering consumes more than one high-level | |
| 63 // instruction. It is guaranteed to point to a non-deleted | |
| 64 // instruction after Cur, or to be End. TODO: Consider separating | |
| 65 // the notion of "next valid instruction" and "new instruction | |
| 66 // insertion point", to avoid confusion when previously-deleted | |
| 67 // instructions come between the two points. | |
|
JF
2014/05/04 23:54:58
Can't the deleted instruction be recycled as the i
Jim Stichnoth
2014/05/05 07:03:55
I guess that for debugging codegen, I prefer that
| |
| 68 //public: | |
|
JF
2014/05/04 23:54:58
public comment?
Jim Stichnoth
2014/05/05 07:03:55
Whoops, gone now.
| |
| 69 InstList::iterator Next; | |
| 70 // End is a copy of Insts.end(), used if Next needs to be advanced. | |
| 71 InstList::iterator End; | |
| 72 | |
| 73 void skipDeleted(InstList::iterator &I); | |
| 74 void advance(InstList::iterator &I); | |
| 75 LoweringContext(const LoweringContext &) LLVM_DELETED_FUNCTION; | |
| 76 LoweringContext &operator=(const LoweringContext &) LLVM_DELETED_FUNCTION; | |
| 77 }; | |
| 78 | |
| 79 class TargetLowering { | |
|
JF
2014/05/04 23:54:58
I think using the CRTP here would be better. The p
Jim Stichnoth
2014/05/05 07:03:55
Good point - I was thinking about CRTP for the tar
Jim Stichnoth
2014/05/17 14:14:32
On further thought, I don't think CRTP is appropri
| |
| 80 public: | |
| 81 static TargetLowering *createLowering(TargetArch Target, Cfg *Func); | |
| 82 void translate() { | |
| 83 switch (Ctx->getOptLevel()) { | |
| 84 case Opt_m1: | |
| 85 translateOm1(); | |
| 86 break; | |
| 87 case Opt_0: | |
| 88 translateO0(); | |
| 89 break; | |
| 90 case Opt_1: | |
| 91 translateO1(); | |
| 92 break; | |
| 93 case Opt_2: | |
| 94 translateO2(); | |
| 95 break; | |
| 96 default: | |
| 97 Func->setError("Target doesn't specify lowering steps."); | |
| 98 break; | |
| 99 } | |
| 100 } | |
| 101 virtual void translateOm1() { | |
| 102 Func->setError("Target doesn't specify Om1 lowering steps."); | |
| 103 } | |
| 104 virtual void translateO0() { | |
| 105 Func->setError("Target doesn't specify O0 lowering steps."); | |
| 106 } | |
| 107 virtual void translateO1() { | |
| 108 Func->setError("Target doesn't specify O1 lowering steps."); | |
| 109 } | |
| 110 virtual void translateO2() { | |
| 111 Func->setError("Target doesn't specify O2 lowering steps."); | |
| 112 } | |
| 113 | |
| 114 // Lowers a single instruction. | |
| 115 void lower(); | |
| 116 | |
| 117 // Returns a variable pre-colored to the specified physical | |
| 118 // register. This is generally used to get very direct access to | |
| 119 // the register such as in the prolog or epilog or for marking | |
| 120 // scratch registers as killed by a call. | |
| 121 virtual Variable *getPhysicalRegister(SizeT RegNum) = 0; | |
| 122 // Returns a printable name for the register. | |
| 123 virtual IceString getRegName(SizeT RegNum, Type Ty) const = 0; | |
| 124 | |
| 125 virtual bool hasFramePointer() const { return false; } | |
| 126 virtual SizeT getFrameOrStackReg() const = 0; | |
| 127 virtual size_t typeWidthInBytesOnStack(Type Ty) = 0; | |
| 128 bool hasComputedFrame() const { return HasComputedFrame; } | |
| 129 int32_t getStackAdjustment() const { return StackAdjustment; } | |
| 130 void updateStackAdjustment(int32_t Offset) { StackAdjustment += Offset; } | |
| 131 void resetStackAdjustment() { StackAdjustment = 0; } | |
| 132 LoweringContext &getContext() { return Context; } | |
| 133 | |
| 134 enum RegSet { | |
| 135 RegSet_None = 0, | |
| 136 RegSet_CallerSave = 1 << 0, | |
| 137 RegSet_CalleeSave = 1 << 1, | |
| 138 RegSet_StackPointer = 1 << 2, | |
| 139 RegSet_FramePointer = 1 << 3, | |
| 140 RegSet_All = ~RegSet_None | |
| 141 }; | |
| 142 typedef uint32_t RegSetMask; | |
| 143 | |
| 144 virtual llvm::SmallBitVector getRegisterSet(RegSetMask Include, | |
| 145 RegSetMask Exclude) const = 0; | |
| 146 virtual const llvm::SmallBitVector &getRegisterSetForType(Type Ty) const = 0; | |
| 147 void regAlloc(); | |
| 148 | |
| 149 virtual void emitVariable(const Variable *Var, const Cfg *Func) const = 0; | |
| 150 | |
| 151 virtual void addProlog(CfgNode *Node) = 0; | |
| 152 virtual void addEpilog(CfgNode *Node) = 0; | |
| 153 | |
| 154 virtual ~TargetLowering() {} | |
| 155 | |
| 156 protected: | |
| 157 TargetLowering(Cfg *Func) | |
| 158 : Func(Func), Ctx(Func->getContext()), HasComputedFrame(false), | |
| 159 StackAdjustment(0) {} | |
| 160 virtual void lowerAlloca(const InstAlloca *Inst) = 0; | |
| 161 virtual void lowerArithmetic(const InstArithmetic *Inst) = 0; | |
| 162 virtual void lowerAssign(const InstAssign *Inst) = 0; | |
| 163 virtual void lowerBr(const InstBr *Inst) = 0; | |
| 164 virtual void lowerCall(const InstCall *Inst) = 0; | |
| 165 virtual void lowerCast(const InstCast *Inst) = 0; | |
| 166 virtual void lowerFcmp(const InstFcmp *Inst) = 0; | |
| 167 virtual void lowerIcmp(const InstIcmp *Inst) = 0; | |
| 168 virtual void lowerLoad(const InstLoad *Inst) = 0; | |
| 169 virtual void lowerPhi(const InstPhi *Inst) = 0; | |
| 170 virtual void lowerRet(const InstRet *Inst) = 0; | |
| 171 virtual void lowerSelect(const InstSelect *Inst) = 0; | |
| 172 virtual void lowerStore(const InstStore *Inst) = 0; | |
| 173 virtual void lowerSwitch(const InstSwitch *Inst) = 0; | |
| 174 virtual void lowerUnreachable(const InstUnreachable *Inst) = 0; | |
| 175 | |
| 176 // This gives the target an opportunity to post-process the lowered | |
| 177 // expansion before returning. The primary intention is to do some | |
| 178 // Register Manager activity as necessary, specifically to eagerly | |
| 179 // allocate registers based on affinity and other factors. The | |
| 180 // simplest lowering does nothing here and leaves it all to a | |
| 181 // subsequent global register allocation pass. | |
| 182 virtual void postLower() {} | |
| 183 | |
| 184 Cfg *Func; | |
| 185 GlobalContext *Ctx; | |
| 186 bool HasComputedFrame; | |
| 187 // StackAdjustment keeps track of the current stack offset from its | |
| 188 // natural location, as arguments are pushed for a function call. | |
| 189 int32_t StackAdjustment; | |
| 190 LoweringContext Context; | |
| 191 | |
| 192 private: | |
| 193 TargetLowering(const TargetLowering &) LLVM_DELETED_FUNCTION; | |
| 194 TargetLowering &operator=(const TargetLowering &) LLVM_DELETED_FUNCTION; | |
| 195 }; | |
| 196 | |
| 197 } // end of namespace Ice | |
| 198 | |
| 199 #endif // SUBZERO_SRC_ICETARGETLOWERING_H | |
| OLD | NEW |