Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 1 | //===- subzero/src/IceCfg.h - Control flow graph ----------------*- 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 | //===----------------------------------------------------------------------===// |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 9 | /// |
| 10 | /// \file |
| 11 | /// This file declares the Cfg class, which represents the control flow |
| 12 | /// graph and the overall per-function compilation context. |
| 13 | /// |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 14 | //===----------------------------------------------------------------------===// |
| 15 | |
| 16 | #ifndef SUBZERO_SRC_ICECFG_H |
| 17 | #define SUBZERO_SRC_ICECFG_H |
| 18 | |
John Porto | aff4ccf | 2015-06-10 16:35:06 -0700 | [diff] [blame] | 19 | #include "IceAssembler.h" |
Jan Voung | 8acded0 | 2014-09-22 18:02:25 -0700 | [diff] [blame] | 20 | #include "IceClFlags.h" |
Jim Stichnoth | a18cc9c | 2014-09-30 19:10:22 -0700 | [diff] [blame] | 21 | #include "IceDefs.h" |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 22 | #include "IceGlobalContext.h" |
Jim Stichnoth | a18cc9c | 2014-09-30 19:10:22 -0700 | [diff] [blame] | 23 | #include "IceTypes.h" |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 24 | |
| 25 | namespace Ice { |
| 26 | |
| 27 | class Cfg { |
Jim Stichnoth | c6ead20 | 2015-02-24 09:30:30 -0800 | [diff] [blame] | 28 | Cfg() = delete; |
Jim Stichnoth | 7b451a9 | 2014-10-15 14:39:23 -0700 | [diff] [blame] | 29 | Cfg(const Cfg &) = delete; |
| 30 | Cfg &operator=(const Cfg &) = delete; |
| 31 | |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 32 | public: |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 33 | ~Cfg(); |
| 34 | |
Jim Stichnoth | bbca754 | 2015-02-11 16:08:31 -0800 | [diff] [blame] | 35 | static std::unique_ptr<Cfg> create(GlobalContext *Ctx, |
| 36 | uint32_t SequenceNumber) { |
| 37 | return std::unique_ptr<Cfg>(new Cfg(Ctx, SequenceNumber)); |
Jim Stichnoth | 31c9559 | 2014-12-19 12:51:35 -0800 | [diff] [blame] | 38 | } |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 39 | /// Gets a pointer to the current thread's Cfg. |
Jim Stichnoth | a5fe17a | 2015-01-26 11:10:03 -0800 | [diff] [blame] | 40 | static const Cfg *getCurrentCfg() { return ICE_TLS_GET_FIELD(CurrentCfg); } |
Jim Stichnoth | 8e92838 | 2015-02-02 17:03:08 -0800 | [diff] [blame] | 41 | static void setCurrentCfg(const Cfg *Func) { |
| 42 | ICE_TLS_SET_FIELD(CurrentCfg, Func); |
| 43 | } |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 44 | /// Gets a pointer to the current thread's Cfg's allocator. |
Jan Voung | 1d62cf0 | 2015-01-09 14:57:32 -0800 | [diff] [blame] | 45 | static ArenaAllocator<> *getCurrentCfgAllocator() { |
Jim Stichnoth | a5fe17a | 2015-01-26 11:10:03 -0800 | [diff] [blame] | 46 | assert(ICE_TLS_GET_FIELD(CurrentCfg)); |
| 47 | return ICE_TLS_GET_FIELD(CurrentCfg)->Allocator.get(); |
Jim Stichnoth | 31c9559 | 2014-12-19 12:51:35 -0800 | [diff] [blame] | 48 | } |
| 49 | |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 50 | GlobalContext *getContext() const { return Ctx; } |
Jim Stichnoth | bbca754 | 2015-02-11 16:08:31 -0800 | [diff] [blame] | 51 | uint32_t getSequenceNumber() const { return SequenceNumber; } |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 52 | |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 53 | /// Returns true if any of the specified options in the verbose mask |
| 54 | /// are set. If the argument is omitted, it checks if any verbose |
| 55 | /// options at all are set. |
Jim Stichnoth | fa4efea | 2015-01-27 05:06:03 -0800 | [diff] [blame] | 56 | bool isVerbose(VerboseMask Mask = IceV_All) const { return VMask & Mask; } |
| 57 | void setVerbose(VerboseMask Mask) { VMask = Mask; } |
| 58 | |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 59 | /// \name Manage the name and return type of the function being translated. |
| 60 | /// @{ |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 61 | void setFunctionName(const IceString &Name) { FunctionName = Name; } |
| 62 | IceString getFunctionName() const { return FunctionName; } |
| 63 | void setReturnType(Type Ty) { ReturnType = Ty; } |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 64 | /// @} |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 65 | |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 66 | /// \name Manage the "internal" attribute of the function. |
| 67 | /// @{ |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 68 | void setInternal(bool Internal) { IsInternalLinkage = Internal; } |
| 69 | bool getInternal() const { return IsInternalLinkage; } |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 70 | /// @} |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 71 | |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 72 | /// \name Manage errors. |
| 73 | /// @{ |
| 74 | |
| 75 | /// Translation error flagging. If support for some construct is |
| 76 | /// known to be missing, instead of an assertion failure, setError() |
| 77 | /// should be called and the error should be propagated back up. |
| 78 | /// This way, we can gracefully fail to translate and let a fallback |
| 79 | /// translator handle the function. |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 80 | void setError(const IceString &Message); |
| 81 | bool hasError() const { return HasError; } |
| 82 | IceString getError() const { return ErrorMessage; } |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 83 | /// @} |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 84 | |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 85 | /// \name Manage nodes (a.k.a. basic blocks, CfgNodes). |
| 86 | /// @{ |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 87 | void setEntryNode(CfgNode *EntryNode) { Entry = EntryNode; } |
| 88 | CfgNode *getEntryNode() const { return Entry; } |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 89 | /// Create a node and append it to the end of the linearized list. |
Jim Stichnoth | 668a7a3 | 2014-12-10 15:32:25 -0800 | [diff] [blame] | 90 | CfgNode *makeNode(); |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 91 | SizeT getNumNodes() const { return Nodes.size(); } |
| 92 | const NodeList &getNodes() const { return Nodes; } |
Karl Schimpf | ac7d734 | 2015-08-06 12:55:23 -0700 | [diff] [blame] | 93 | /// Swap nodes of Cfg with given list of nodes. |
| 94 | void swapNodes(NodeList &NewNodes); |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 95 | /// @} |
Jim Stichnoth | 9a04c07 | 2014-12-11 15:51:42 -0800 | [diff] [blame] | 96 | |
| 97 | typedef int32_t IdentifierIndexType; |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 98 | /// Adds a name to the list and returns its index, suitable for the |
| 99 | /// argument to getIdentifierName(). No checking for duplicates is |
| 100 | /// done. This is generally used for node names and variable names |
| 101 | /// to avoid embedding a std::string inside an arena-allocated |
| 102 | /// object. |
Jim Stichnoth | 9a04c07 | 2014-12-11 15:51:42 -0800 | [diff] [blame] | 103 | IdentifierIndexType addIdentifierName(const IceString &Name) { |
| 104 | IdentifierIndexType Index = IdentifierNames.size(); |
| 105 | IdentifierNames.push_back(Name); |
Jim Stichnoth | 668a7a3 | 2014-12-10 15:32:25 -0800 | [diff] [blame] | 106 | return Index; |
| 107 | } |
Jim Stichnoth | 9a04c07 | 2014-12-11 15:51:42 -0800 | [diff] [blame] | 108 | const IceString &getIdentifierName(IdentifierIndexType Index) const { |
| 109 | return IdentifierNames[Index]; |
| 110 | } |
Jim Stichnoth | dd842db | 2015-01-27 12:53:53 -0800 | [diff] [blame] | 111 | enum { IdentifierIndexInvalid = -1 }; |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 112 | |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 113 | /// \name Manage instruction numbering. |
| 114 | /// @{ |
Jim Stichnoth | d97c7df | 2014-06-04 11:57:08 -0700 | [diff] [blame] | 115 | InstNumberT newInstNumber() { return NextInstNumber++; } |
Jim Stichnoth | 4775255 | 2014-10-13 17:15:08 -0700 | [diff] [blame] | 116 | InstNumberT getNextInstNumber() const { return NextInstNumber; } |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 117 | /// @} |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 118 | |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 119 | /// \name Manage Variables. |
| 120 | /// @{ |
| 121 | |
| 122 | /// Create a new Variable with a particular type and an optional |
| 123 | /// name. The Node argument is the node where the variable is defined. |
Jan Voung | 28068ad | 2015-07-31 12:58:46 -0700 | [diff] [blame] | 124 | // TODO(jpp): untemplate this with separate methods: makeVariable, |
| 125 | // makeSpillVariable, and makeStackVariable. |
Jim Stichnoth | 9a04c07 | 2014-12-11 15:51:42 -0800 | [diff] [blame] | 126 | template <typename T = Variable> T *makeVariable(Type Ty) { |
Jim Stichnoth | 800dab2 | 2014-09-20 12:25:02 -0700 | [diff] [blame] | 127 | SizeT Index = Variables.size(); |
Jim Stichnoth | 9a04c07 | 2014-12-11 15:51:42 -0800 | [diff] [blame] | 128 | T *Var = T::create(this, Ty, Index); |
Jim Stichnoth | 800dab2 | 2014-09-20 12:25:02 -0700 | [diff] [blame] | 129 | Variables.push_back(Var); |
| 130 | return Var; |
| 131 | } |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 132 | SizeT getNumVariables() const { return Variables.size(); } |
| 133 | const VarList &getVariables() const { return Variables; } |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 134 | /// @} |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 135 | |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 136 | /// \name Manage arguments to the function. |
| 137 | /// @{ |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 138 | void addArg(Variable *Arg); |
| 139 | const VarList &getArgs() const { return Args; } |
Matt Wala | 45a0623 | 2014-07-09 16:33:22 -0700 | [diff] [blame] | 140 | VarList &getArgs() { return Args; } |
Jim Stichnoth | 144cdce | 2014-09-22 16:02:59 -0700 | [diff] [blame] | 141 | void addImplicitArg(Variable *Arg); |
| 142 | const VarList &getImplicitArgs() const { return ImplicitArgs; } |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 143 | /// @} |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 144 | |
Andrew Scull | 86df4e9 | 2015-07-30 13:54:44 -0700 | [diff] [blame] | 145 | /// \name Manage the jump tables. |
| 146 | /// @{ |
| 147 | void addJumpTable(InstJumpTable *JumpTable) { |
| 148 | JumpTables.emplace_back(JumpTable); |
| 149 | } |
| 150 | /// @} |
| 151 | |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 152 | /// \name Miscellaneous accessors. |
| 153 | /// @{ |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 154 | TargetLowering *getTarget() const { return Target.get(); } |
Jim Stichnoth | 144cdce | 2014-09-22 16:02:59 -0700 | [diff] [blame] | 155 | VariablesMetadata *getVMetadata() const { return VMetadata.get(); } |
Jim Stichnoth | d97c7df | 2014-06-04 11:57:08 -0700 | [diff] [blame] | 156 | Liveness *getLiveness() const { return Live.get(); } |
Jim Stichnoth | bbca754 | 2015-02-11 16:08:31 -0800 | [diff] [blame] | 157 | template <typename T = Assembler> T *getAssembler() const { |
John Porto | 2da710c | 2015-06-29 07:57:02 -0700 | [diff] [blame] | 158 | return llvm::dyn_cast<T>(TargetAssembler.get()); |
Jan Voung | 8acded0 | 2014-09-22 18:02:25 -0700 | [diff] [blame] | 159 | } |
Jim Stichnoth | bbca754 | 2015-02-11 16:08:31 -0800 | [diff] [blame] | 160 | Assembler *releaseAssembler() { return TargetAssembler.release(); } |
John Porto | f8b4cc8 | 2015-06-09 18:06:19 -0700 | [diff] [blame] | 161 | std::unique_ptr<VariableDeclarationList> getGlobalInits() { |
| 162 | return std::move(GlobalInits); |
| 163 | } |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 164 | bool hasComputedFrame() const; |
Jim Stichnoth | 8363a06 | 2014-10-07 10:02:38 -0700 | [diff] [blame] | 165 | bool getFocusedTiming() const { return FocusedTiming; } |
| 166 | void setFocusedTiming() { FocusedTiming = true; } |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 167 | /// @} |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 168 | |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 169 | /// Returns true if Var is a global variable that is used by the profiling |
| 170 | /// code. |
John Porto | f8b4cc8 | 2015-06-09 18:06:19 -0700 | [diff] [blame] | 171 | static bool isProfileGlobal(const VariableDeclaration &Var); |
| 172 | |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 173 | /// Passes over the CFG. |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 174 | void translate(); |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 175 | /// After the CFG is fully constructed, iterate over the nodes and |
| 176 | /// compute the predecessor and successor edges, in the form of |
| 177 | /// CfgNode::InEdges[] and CfgNode::OutEdges[]. |
Jim Stichnoth | 69d3f9c | 2015-03-23 10:33:38 -0700 | [diff] [blame] | 178 | void computeInOutEdges(); |
Jim Stichnoth | d97c7df | 2014-06-04 11:57:08 -0700 | [diff] [blame] | 179 | void renumberInstructions(); |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 180 | void placePhiLoads(); |
| 181 | void placePhiStores(); |
| 182 | void deletePhis(); |
Jim Stichnoth | 336f6c4 | 2014-10-30 15:01:31 -0700 | [diff] [blame] | 183 | void advancedPhiLowering(); |
| 184 | void reorderNodes(); |
Qining Lu | 969f6a3 | 2015-07-31 09:58:34 -0700 | [diff] [blame] | 185 | void shuffleNodes(); |
Jim Stichnoth | d97c7df | 2014-06-04 11:57:08 -0700 | [diff] [blame] | 186 | void doAddressOpt(); |
Matt Wala | 45a0623 | 2014-07-09 16:33:22 -0700 | [diff] [blame] | 187 | void doArgLowering(); |
Matt Wala | c330274 | 2014-08-15 16:21:56 -0700 | [diff] [blame] | 188 | void doNopInsertion(); |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 189 | void genCode(); |
| 190 | void genFrame(); |
Jim Stichnoth | d97c7df | 2014-06-04 11:57:08 -0700 | [diff] [blame] | 191 | void livenessLightweight(); |
| 192 | void liveness(LivenessMode Mode); |
| 193 | bool validateLiveness() const; |
Jim Stichnoth | 336f6c4 | 2014-10-30 15:01:31 -0700 | [diff] [blame] | 194 | void contractEmptyNodes(); |
Jim Stichnoth | ff9c706 | 2014-09-18 04:50:49 -0700 | [diff] [blame] | 195 | void doBranchOpt(); |
Andrew Scull | 86df4e9 | 2015-07-30 13:54:44 -0700 | [diff] [blame] | 196 | void markNodesForSandboxing(); |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 197 | |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 198 | /// \name Manage the CurrentNode field. |
| 199 | /// CurrentNode is used for validating the Variable::DefNode field during |
| 200 | /// dumping/emitting. |
| 201 | /// @{ |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 202 | void setCurrentNode(const CfgNode *Node) { CurrentNode = Node; } |
Jim Stichnoth | ae95320 | 2014-12-20 06:17:49 -0800 | [diff] [blame] | 203 | void resetCurrentNode() { setCurrentNode(nullptr); } |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 204 | const CfgNode *getCurrentNode() const { return CurrentNode; } |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 205 | /// @} |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 206 | |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 207 | void emit(); |
Jan Voung | 0faec4c | 2014-11-05 17:29:56 -0800 | [diff] [blame] | 208 | void emitIAS(); |
Jim Stichnoth | bbca754 | 2015-02-11 16:08:31 -0800 | [diff] [blame] | 209 | static void emitTextHeader(const IceString &MangledName, GlobalContext *Ctx, |
| 210 | const Assembler *Asm); |
Jim Stichnoth | d97c7df | 2014-06-04 11:57:08 -0700 | [diff] [blame] | 211 | void dump(const IceString &Message = ""); |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 212 | |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 213 | /// Allocate data of type T using the per-Cfg allocator. |
Jim Stichnoth | 31c9559 | 2014-12-19 12:51:35 -0800 | [diff] [blame] | 214 | template <typename T> T *allocate() { return Allocator->Allocate<T>(); } |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 215 | |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 216 | /// Allocate an array of data of type T using the per-Cfg allocator. |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 217 | template <typename T> T *allocateArrayOf(size_t NumElems) { |
Jim Stichnoth | 31c9559 | 2014-12-19 12:51:35 -0800 | [diff] [blame] | 218 | return Allocator->Allocate<T>(NumElems); |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 219 | } |
| 220 | |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 221 | /// Deallocate data that was allocated via allocate<T>(). |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 222 | template <typename T> void deallocate(T *Object) { |
Jim Stichnoth | 31c9559 | 2014-12-19 12:51:35 -0800 | [diff] [blame] | 223 | Allocator->Deallocate(Object); |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 224 | } |
| 225 | |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 226 | /// Deallocate data that was allocated via allocateArrayOf<T>(). |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 227 | template <typename T> void deallocateArrayOf(T *Array) { |
Jim Stichnoth | 31c9559 | 2014-12-19 12:51:35 -0800 | [diff] [blame] | 228 | Allocator->Deallocate(Array); |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | private: |
Jim Stichnoth | bbca754 | 2015-02-11 16:08:31 -0800 | [diff] [blame] | 232 | Cfg(GlobalContext *Ctx, uint32_t SequenceNumber); |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 233 | |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 234 | /// Adds a call to the ProfileSummary runtime function as the first |
| 235 | /// instruction in this CFG's entry block. |
John Porto | f8b4cc8 | 2015-06-09 18:06:19 -0700 | [diff] [blame] | 236 | void addCallToProfileSummary(); |
| 237 | |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 238 | /// Iterates over the basic blocks in this CFG, adding profiling code to each |
| 239 | /// one of them. It returns a list with all the globals that the profiling |
| 240 | /// code needs to be defined. |
John Porto | f8b4cc8 | 2015-06-09 18:06:19 -0700 | [diff] [blame] | 241 | void profileBlocks(); |
| 242 | |
Andrew Scull | 86df4e9 | 2015-07-30 13:54:44 -0700 | [diff] [blame] | 243 | /// Delete registered jump table placeholder instructions. This should only be |
| 244 | /// called once all repointing has taken place. |
| 245 | void deleteJumpTableInsts(); |
| 246 | /// Iterate through the registered jump tables and emit them. |
| 247 | void emitJumpTables(); |
| 248 | |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 249 | GlobalContext *Ctx; |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 250 | uint32_t SequenceNumber; /// output order for emission |
Jim Stichnoth | fa4efea | 2015-01-27 05:06:03 -0800 | [diff] [blame] | 251 | VerboseMask VMask; |
Jim Stichnoth | eafb56c | 2015-06-22 10:35:22 -0700 | [diff] [blame] | 252 | IceString FunctionName = ""; |
| 253 | Type ReturnType = IceType_void; |
| 254 | bool IsInternalLinkage = false; |
| 255 | bool HasError = false; |
| 256 | bool FocusedTiming = false; |
| 257 | IceString ErrorMessage = ""; |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 258 | CfgNode *Entry = nullptr; /// entry basic block |
| 259 | NodeList Nodes; /// linearized node list; Entry should be first |
Jim Stichnoth | 9a04c07 | 2014-12-11 15:51:42 -0800 | [diff] [blame] | 260 | std::vector<IceString> IdentifierNames; |
Jim Stichnoth | d97c7df | 2014-06-04 11:57:08 -0700 | [diff] [blame] | 261 | InstNumberT NextInstNumber; |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 262 | VarList Variables; |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 263 | VarList Args; /// subset of Variables, in argument order |
| 264 | VarList ImplicitArgs; /// subset of Variables |
Jan Voung | 1d62cf0 | 2015-01-09 14:57:32 -0800 | [diff] [blame] | 265 | std::unique_ptr<ArenaAllocator<>> Allocator; |
Jim Stichnoth | a18cc9c | 2014-09-30 19:10:22 -0700 | [diff] [blame] | 266 | std::unique_ptr<Liveness> Live; |
| 267 | std::unique_ptr<TargetLowering> Target; |
| 268 | std::unique_ptr<VariablesMetadata> VMetadata; |
| 269 | std::unique_ptr<Assembler> TargetAssembler; |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 270 | /// Globals required by this CFG. Mostly used for the profiler's globals. |
John Porto | f8b4cc8 | 2015-06-09 18:06:19 -0700 | [diff] [blame] | 271 | std::unique_ptr<VariableDeclarationList> GlobalInits; |
Andrew Scull | 86df4e9 | 2015-07-30 13:54:44 -0700 | [diff] [blame] | 272 | std::vector<InstJumpTable *> JumpTables; |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 273 | |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 274 | /// CurrentNode is maintained during dumping/emitting just for |
| 275 | /// validating Variable::DefNode. Normally, a traversal over |
| 276 | /// CfgNodes maintains this, but before global operations like |
| 277 | /// register allocation, resetCurrentNode() should be called to avoid |
| 278 | /// spurious validation failures. |
Jim Stichnoth | eafb56c | 2015-06-22 10:35:22 -0700 | [diff] [blame] | 279 | const CfgNode *CurrentNode = nullptr; |
Jim Stichnoth | 31c9559 | 2014-12-19 12:51:35 -0800 | [diff] [blame] | 280 | |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 281 | /// Maintain a pointer in TLS to the current Cfg being translated. |
| 282 | /// This is primarily for accessing its allocator statelessly, but |
| 283 | /// other uses are possible. |
Jim Stichnoth | a5fe17a | 2015-01-26 11:10:03 -0800 | [diff] [blame] | 284 | ICE_TLS_DECLARE_FIELD(const Cfg *, CurrentCfg); |
| 285 | |
| 286 | public: |
| 287 | static void TlsInit() { ICE_TLS_INIT_FIELD(CurrentCfg); } |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 288 | }; |
| 289 | |
| 290 | } // end of namespace Ice |
| 291 | |
| 292 | #endif // SUBZERO_SRC_ICECFG_H |