| OLD | NEW |
| 1 //===- subzero/src/IceCfg.h - Control flow graph ----------------*- C++ -*-===// | 1 //===- subzero/src/IceCfg.h - Control flow graph ----------------*- C++ -*-===// |
| 2 // | 2 // |
| 3 // The Subzero Code Generator | 3 // The Subzero Code Generator |
| 4 // | 4 // |
| 5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
| 6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
| 7 // | 7 // |
| 8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
| 9 // | 9 // |
| 10 // This file declares the Cfg class, which represents the control flow | 10 // This file declares the Cfg class, which represents the control flow |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 | 23 |
| 24 namespace Ice { | 24 namespace Ice { |
| 25 | 25 |
| 26 class Cfg { | 26 class Cfg { |
| 27 Cfg(const Cfg &) = delete; | 27 Cfg(const Cfg &) = delete; |
| 28 Cfg &operator=(const Cfg &) = delete; | 28 Cfg &operator=(const Cfg &) = delete; |
| 29 | 29 |
| 30 public: | 30 public: |
| 31 ~Cfg(); | 31 ~Cfg(); |
| 32 | 32 |
| 33 static std::unique_ptr<Cfg> create(GlobalContext *Ctx) { | 33 static std::unique_ptr<Cfg> create(GlobalContext *Ctx, uint32_t Sequence) { |
| 34 return std::unique_ptr<Cfg>(new Cfg(Ctx)); | 34 return std::unique_ptr<Cfg>(new Cfg(Ctx, Sequence)); |
| 35 } | 35 } |
| 36 // Gets a pointer to the current thread's Cfg. | 36 // Gets a pointer to the current thread's Cfg. |
| 37 static const Cfg *getCurrentCfg() { return ICE_TLS_GET_FIELD(CurrentCfg); } | 37 static const Cfg *getCurrentCfg() { return ICE_TLS_GET_FIELD(CurrentCfg); } |
| 38 static void setCurrentCfg(const Cfg *Func) { | 38 static void setCurrentCfg(const Cfg *Func) { |
| 39 ICE_TLS_SET_FIELD(CurrentCfg, Func); | 39 ICE_TLS_SET_FIELD(CurrentCfg, Func); |
| 40 } | 40 } |
| 41 // Gets a pointer to the current thread's Cfg's allocator. | 41 // Gets a pointer to the current thread's Cfg's allocator. |
| 42 static ArenaAllocator<> *getCurrentCfgAllocator() { | 42 static ArenaAllocator<> *getCurrentCfgAllocator() { |
| 43 assert(ICE_TLS_GET_FIELD(CurrentCfg)); | 43 assert(ICE_TLS_GET_FIELD(CurrentCfg)); |
| 44 return ICE_TLS_GET_FIELD(CurrentCfg)->Allocator.get(); | 44 return ICE_TLS_GET_FIELD(CurrentCfg)->Allocator.get(); |
| 45 } | 45 } |
| 46 | 46 |
| 47 GlobalContext *getContext() const { return Ctx; } | 47 GlobalContext *getContext() const { return Ctx; } |
| 48 uint32_t getSequenceNumber() const { return SequenceNumber; } |
| 48 | 49 |
| 49 // Returns true if any of the specified options in the verbose mask | 50 // Returns true if any of the specified options in the verbose mask |
| 50 // are set. If the argument is omitted, it checks if any verbose | 51 // are set. If the argument is omitted, it checks if any verbose |
| 51 // options at all are set. | 52 // options at all are set. |
| 52 bool isVerbose(VerboseMask Mask = IceV_All) const { return VMask & Mask; } | 53 bool isVerbose(VerboseMask Mask = IceV_All) const { return VMask & Mask; } |
| 53 void setVerbose(VerboseMask Mask) { VMask = Mask; } | 54 void setVerbose(VerboseMask Mask) { VMask = Mask; } |
| 54 | 55 |
| 55 // Manage the name and return type of the function being translated. | 56 // Manage the name and return type of the function being translated. |
| 56 void setFunctionName(const IceString &Name) { FunctionName = Name; } | 57 void setFunctionName(const IceString &Name) { FunctionName = Name; } |
| 57 IceString getFunctionName() const { return FunctionName; } | 58 IceString getFunctionName() const { return FunctionName; } |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 void addArg(Variable *Arg); | 115 void addArg(Variable *Arg); |
| 115 const VarList &getArgs() const { return Args; } | 116 const VarList &getArgs() const { return Args; } |
| 116 VarList &getArgs() { return Args; } | 117 VarList &getArgs() { return Args; } |
| 117 void addImplicitArg(Variable *Arg); | 118 void addImplicitArg(Variable *Arg); |
| 118 const VarList &getImplicitArgs() const { return ImplicitArgs; } | 119 const VarList &getImplicitArgs() const { return ImplicitArgs; } |
| 119 | 120 |
| 120 // Miscellaneous accessors. | 121 // Miscellaneous accessors. |
| 121 TargetLowering *getTarget() const { return Target.get(); } | 122 TargetLowering *getTarget() const { return Target.get(); } |
| 122 VariablesMetadata *getVMetadata() const { return VMetadata.get(); } | 123 VariablesMetadata *getVMetadata() const { return VMetadata.get(); } |
| 123 Liveness *getLiveness() const { return Live.get(); } | 124 Liveness *getLiveness() const { return Live.get(); } |
| 124 template <typename T> T *getAssembler() const { | 125 template <typename T = Assembler> T *getAssembler() const { |
| 125 return static_cast<T *>(TargetAssembler.get()); | 126 return static_cast<T *>(TargetAssembler.get()); |
| 126 } | 127 } |
| 128 Assembler *releaseAssembler() { return TargetAssembler.release(); } |
| 127 bool hasComputedFrame() const; | 129 bool hasComputedFrame() const; |
| 128 bool getFocusedTiming() const { return FocusedTiming; } | 130 bool getFocusedTiming() const { return FocusedTiming; } |
| 129 void setFocusedTiming() { FocusedTiming = true; } | 131 void setFocusedTiming() { FocusedTiming = true; } |
| 130 | 132 |
| 131 // Passes over the CFG. | 133 // Passes over the CFG. |
| 132 void translate(); | 134 void translate(); |
| 133 // After the CFG is fully constructed, iterate over the nodes and | 135 // After the CFG is fully constructed, iterate over the nodes and |
| 134 // compute the predecessor edges, in the form of | 136 // compute the predecessor edges, in the form of |
| 135 // CfgNode::InEdges[]. | 137 // CfgNode::InEdges[]. |
| 136 void computePredecessors(); | 138 void computePredecessors(); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 152 void doBranchOpt(); | 154 void doBranchOpt(); |
| 153 | 155 |
| 154 // Manage the CurrentNode field, which is used for validating the | 156 // Manage the CurrentNode field, which is used for validating the |
| 155 // Variable::DefNode field during dumping/emitting. | 157 // Variable::DefNode field during dumping/emitting. |
| 156 void setCurrentNode(const CfgNode *Node) { CurrentNode = Node; } | 158 void setCurrentNode(const CfgNode *Node) { CurrentNode = Node; } |
| 157 void resetCurrentNode() { setCurrentNode(nullptr); } | 159 void resetCurrentNode() { setCurrentNode(nullptr); } |
| 158 const CfgNode *getCurrentNode() const { return CurrentNode; } | 160 const CfgNode *getCurrentNode() const { return CurrentNode; } |
| 159 | 161 |
| 160 void emit(); | 162 void emit(); |
| 161 void emitIAS(); | 163 void emitIAS(); |
| 162 void emitTextHeader(const IceString &MangledName); | 164 static void emitTextHeader(const IceString &MangledName, GlobalContext *Ctx, |
| 165 Assembler *Asm); |
| 163 void dump(const IceString &Message = ""); | 166 void dump(const IceString &Message = ""); |
| 164 | 167 |
| 165 // Allocate data of type T using the per-Cfg allocator. | 168 // Allocate data of type T using the per-Cfg allocator. |
| 166 template <typename T> T *allocate() { return Allocator->Allocate<T>(); } | 169 template <typename T> T *allocate() { return Allocator->Allocate<T>(); } |
| 167 | 170 |
| 168 // Allocate an array of data of type T using the per-Cfg allocator. | 171 // Allocate an array of data of type T using the per-Cfg allocator. |
| 169 template <typename T> T *allocateArrayOf(size_t NumElems) { | 172 template <typename T> T *allocateArrayOf(size_t NumElems) { |
| 170 return Allocator->Allocate<T>(NumElems); | 173 return Allocator->Allocate<T>(NumElems); |
| 171 } | 174 } |
| 172 | 175 |
| 173 // Deallocate data that was allocated via allocate<T>(). | 176 // Deallocate data that was allocated via allocate<T>(). |
| 174 template <typename T> void deallocate(T *Object) { | 177 template <typename T> void deallocate(T *Object) { |
| 175 Allocator->Deallocate(Object); | 178 Allocator->Deallocate(Object); |
| 176 } | 179 } |
| 177 | 180 |
| 178 // Deallocate data that was allocated via allocateArrayOf<T>(). | 181 // Deallocate data that was allocated via allocateArrayOf<T>(). |
| 179 template <typename T> void deallocateArrayOf(T *Array) { | 182 template <typename T> void deallocateArrayOf(T *Array) { |
| 180 Allocator->Deallocate(Array); | 183 Allocator->Deallocate(Array); |
| 181 } | 184 } |
| 182 | 185 |
| 183 private: | 186 private: |
| 184 Cfg(GlobalContext *Ctx); | 187 Cfg(GlobalContext *Ctx, uint32_t Sequence); |
| 185 | 188 |
| 186 GlobalContext *Ctx; | 189 GlobalContext *Ctx; |
| 190 uint32_t SequenceNumber; // output order for emission |
| 187 VerboseMask VMask; | 191 VerboseMask VMask; |
| 188 IceString FunctionName; | 192 IceString FunctionName; |
| 189 Type ReturnType; | 193 Type ReturnType; |
| 190 bool IsInternalLinkage; | 194 bool IsInternalLinkage; |
| 191 bool HasError; | 195 bool HasError; |
| 192 bool FocusedTiming; | 196 bool FocusedTiming; |
| 193 IceString ErrorMessage; | 197 IceString ErrorMessage; |
| 194 CfgNode *Entry; // entry basic block | 198 CfgNode *Entry; // entry basic block |
| 195 NodeList Nodes; // linearized node list; Entry should be first | 199 NodeList Nodes; // linearized node list; Entry should be first |
| 196 std::vector<IceString> IdentifierNames; | 200 std::vector<IceString> IdentifierNames; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 216 // other uses are possible. | 220 // other uses are possible. |
| 217 ICE_TLS_DECLARE_FIELD(const Cfg *, CurrentCfg); | 221 ICE_TLS_DECLARE_FIELD(const Cfg *, CurrentCfg); |
| 218 | 222 |
| 219 public: | 223 public: |
| 220 static void TlsInit() { ICE_TLS_INIT_FIELD(CurrentCfg); } | 224 static void TlsInit() { ICE_TLS_INIT_FIELD(CurrentCfg); } |
| 221 }; | 225 }; |
| 222 | 226 |
| 223 } // end of namespace Ice | 227 } // end of namespace Ice |
| 224 | 228 |
| 225 #endif // SUBZERO_SRC_ICECFG_H | 229 #endif // SUBZERO_SRC_ICECFG_H |
| OLD | NEW |