Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 1 | //===- subzero/src/IceCfg.cpp - Control flow graph implementation ---------===// |
| 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 |
Andrew Scull | 57e1268 | 2015-09-16 11:30:19 -0700 | [diff] [blame] | 11 | /// This file implements the Cfg class, including constant pool management. |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 12 | /// |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #include "IceCfg.h" |
John Porto | 67f8de9 | 2015-06-25 10:14:17 -0700 | [diff] [blame] | 16 | |
| 17 | #include "IceAssembler.h" |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 18 | #include "IceCfgNode.h" |
Jim Stichnoth | 989a703 | 2014-08-08 10:13:44 -0700 | [diff] [blame] | 19 | #include "IceClFlags.h" |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 20 | #include "IceDefs.h" |
Jan Voung | ec27073 | 2015-01-12 17:00:22 -0800 | [diff] [blame] | 21 | #include "IceELFObjectWriter.h" |
John Porto | f8b4cc8 | 2015-06-09 18:06:19 -0700 | [diff] [blame] | 22 | #include "IceGlobalInits.h" |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 23 | #include "IceInst.h" |
John Porto | ec3f565 | 2015-08-31 15:07:09 -0700 | [diff] [blame] | 24 | #include "IceInstVarIter.h" |
Jim Stichnoth | d97c7df | 2014-06-04 11:57:08 -0700 | [diff] [blame] | 25 | #include "IceLiveness.h" |
Andrew Scull | aa6c109 | 2015-09-03 17:50:30 -0700 | [diff] [blame] | 26 | #include "IceLoopAnalyzer.h" |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 27 | #include "IceOperand.h" |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 28 | #include "IceTargetLowering.h" |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 29 | |
| 30 | namespace Ice { |
| 31 | |
Jim Stichnoth | a5fe17a | 2015-01-26 11:10:03 -0800 | [diff] [blame] | 32 | ICE_TLS_DEFINE_FIELD(const Cfg *, Cfg, CurrentCfg); |
Jim Stichnoth | 31c9559 | 2014-12-19 12:51:35 -0800 | [diff] [blame] | 33 | |
Jan Voung | 1d62cf0 | 2015-01-09 14:57:32 -0800 | [diff] [blame] | 34 | ArenaAllocator<> *getCurrentCfgAllocator() { |
Jim Stichnoth | 31c9559 | 2014-12-19 12:51:35 -0800 | [diff] [blame] | 35 | return Cfg::getCurrentCfgAllocator(); |
| 36 | } |
| 37 | |
Jim Stichnoth | bbca754 | 2015-02-11 16:08:31 -0800 | [diff] [blame] | 38 | Cfg::Cfg(GlobalContext *Ctx, uint32_t SequenceNumber) |
Jan Voung | 1f47ad0 | 2015-03-20 15:01:26 -0700 | [diff] [blame] | 39 | : Ctx(Ctx), SequenceNumber(SequenceNumber), |
Jim Stichnoth | eafb56c | 2015-06-22 10:35:22 -0700 | [diff] [blame] | 40 | VMask(Ctx->getFlags().getVerbose()), NextInstNumber(Inst::NumberInitial), |
| 41 | Allocator(new ArenaAllocator<>()), Live(nullptr), |
| 42 | Target(TargetLowering::createLowering(Ctx->getFlags().getTargetArch(), |
| 43 | this)), |
Jan Voung | 8acded0 | 2014-09-22 18:02:25 -0700 | [diff] [blame] | 44 | VMetadata(new VariablesMetadata(this)), |
Jan Voung | 1f47ad0 | 2015-03-20 15:01:26 -0700 | [diff] [blame] | 45 | TargetAssembler(TargetLowering::createAssembler( |
Jim Stichnoth | eafb56c | 2015-06-22 10:35:22 -0700 | [diff] [blame] | 46 | Ctx->getFlags().getTargetArch(), this)) { |
Qining Lu | aee5fa8 | 2015-08-20 14:59:03 -0700 | [diff] [blame] | 47 | if (Ctx->getFlags().getRandomizeAndPoolImmediatesOption() == RPI_Randomize) { |
Andrew Scull | 57e1268 | 2015-09-16 11:30:19 -0700 | [diff] [blame] | 48 | // If -randomize-pool-immediates=randomize, create a random number |
| 49 | // generator to generate a cookie for constant blinding. |
Qining Lu | aee5fa8 | 2015-08-20 14:59:03 -0700 | [diff] [blame] | 50 | RandomNumberGenerator RNG(Ctx->getFlags().getRandomSeed(), |
Qining Lu | 360e319 | 2015-08-20 17:13:07 -0700 | [diff] [blame] | 51 | RPE_ConstantBlinding, this->SequenceNumber); |
Qining Lu | aee5fa8 | 2015-08-20 14:59:03 -0700 | [diff] [blame] | 52 | ConstantBlindingCookie = |
Qining Lu | 360e319 | 2015-08-20 17:13:07 -0700 | [diff] [blame] | 53 | (uint32_t)RNG.next((uint64_t)std::numeric_limits<uint32_t>::max() + 1); |
Qining Lu | aee5fa8 | 2015-08-20 14:59:03 -0700 | [diff] [blame] | 54 | } |
Karl Schimpf | 6fcbddd | 2014-11-06 09:49:24 -0800 | [diff] [blame] | 55 | } |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 56 | |
Jim Stichnoth | 8e92838 | 2015-02-02 17:03:08 -0800 | [diff] [blame] | 57 | Cfg::~Cfg() { assert(ICE_TLS_GET_FIELD(CurrentCfg) == nullptr); } |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 58 | |
| 59 | void Cfg::setError(const IceString &Message) { |
| 60 | HasError = true; |
| 61 | ErrorMessage = Message; |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 62 | } |
| 63 | |
Jim Stichnoth | 668a7a3 | 2014-12-10 15:32:25 -0800 | [diff] [blame] | 64 | CfgNode *Cfg::makeNode() { |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 65 | SizeT LabelIndex = Nodes.size(); |
Jim Stichnoth | 668a7a3 | 2014-12-10 15:32:25 -0800 | [diff] [blame] | 66 | CfgNode *Node = CfgNode::create(this, LabelIndex); |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 67 | Nodes.push_back(Node); |
| 68 | return Node; |
| 69 | } |
| 70 | |
Karl Schimpf | ac7d734 | 2015-08-06 12:55:23 -0700 | [diff] [blame] | 71 | void Cfg::swapNodes(NodeList &NewNodes) { |
Jim Stichnoth | e7dbc0b | 2015-09-15 10:09:24 -0700 | [diff] [blame] | 72 | assert(Nodes.size() == NewNodes.size()); |
Karl Schimpf | ac7d734 | 2015-08-06 12:55:23 -0700 | [diff] [blame] | 73 | Nodes.swap(NewNodes); |
| 74 | for (SizeT I = 0, NumNodes = getNumNodes(); I < NumNodes; ++I) |
| 75 | Nodes[I]->resetIndex(I); |
| 76 | } |
| 77 | |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 78 | void Cfg::addArg(Variable *Arg) { |
Jim Stichnoth | 144cdce | 2014-09-22 16:02:59 -0700 | [diff] [blame] | 79 | Arg->setIsArg(); |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 80 | Args.push_back(Arg); |
| 81 | } |
| 82 | |
Jim Stichnoth | 144cdce | 2014-09-22 16:02:59 -0700 | [diff] [blame] | 83 | void Cfg::addImplicitArg(Variable *Arg) { |
| 84 | Arg->setIsImplicitArg(); |
| 85 | ImplicitArgs.push_back(Arg); |
| 86 | } |
| 87 | |
Andrew Scull | 57e1268 | 2015-09-16 11:30:19 -0700 | [diff] [blame] | 88 | // Returns whether the stack frame layout has been computed yet. This is used |
| 89 | // for dumping the stack frame location of Variables. |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 90 | bool Cfg::hasComputedFrame() const { return getTarget()->hasComputedFrame(); } |
| 91 | |
John Porto | f8b4cc8 | 2015-06-09 18:06:19 -0700 | [diff] [blame] | 92 | namespace { |
| 93 | constexpr char BlockNameGlobalPrefix[] = ".L$profiler$block_name$"; |
| 94 | constexpr char BlockStatsGlobalPrefix[] = ".L$profiler$block_info$"; |
| 95 | |
John Porto | 1bec8bc | 2015-06-22 10:51:13 -0700 | [diff] [blame] | 96 | VariableDeclaration *nodeNameDeclaration(GlobalContext *Ctx, |
| 97 | const IceString &NodeAsmName) { |
| 98 | VariableDeclaration *Var = VariableDeclaration::create(Ctx); |
John Porto | f8b4cc8 | 2015-06-09 18:06:19 -0700 | [diff] [blame] | 99 | Var->setName(BlockNameGlobalPrefix + NodeAsmName); |
| 100 | Var->setIsConstant(true); |
John Porto | 1bec8bc | 2015-06-22 10:51:13 -0700 | [diff] [blame] | 101 | Var->addInitializer(VariableDeclaration::DataInitializer::create( |
John Porto | f8b4cc8 | 2015-06-09 18:06:19 -0700 | [diff] [blame] | 102 | NodeAsmName.data(), NodeAsmName.size() + 1)); |
| 103 | const SizeT Int64ByteSize = typeWidthInBytes(IceType_i64); |
| 104 | Var->setAlignment(Int64ByteSize); // Wasteful, 32-bit could use 4 bytes. |
| 105 | return Var; |
| 106 | } |
| 107 | |
| 108 | VariableDeclaration * |
John Porto | 1bec8bc | 2015-06-22 10:51:13 -0700 | [diff] [blame] | 109 | blockProfilingInfoDeclaration(GlobalContext *Ctx, const IceString &NodeAsmName, |
John Porto | f8b4cc8 | 2015-06-09 18:06:19 -0700 | [diff] [blame] | 110 | VariableDeclaration *NodeNameDeclaration) { |
John Porto | 1bec8bc | 2015-06-22 10:51:13 -0700 | [diff] [blame] | 111 | VariableDeclaration *Var = VariableDeclaration::create(Ctx); |
John Porto | f8b4cc8 | 2015-06-09 18:06:19 -0700 | [diff] [blame] | 112 | Var->setName(BlockStatsGlobalPrefix + NodeAsmName); |
| 113 | const SizeT Int64ByteSize = typeWidthInBytes(IceType_i64); |
John Porto | 1bec8bc | 2015-06-22 10:51:13 -0700 | [diff] [blame] | 114 | Var->addInitializer( |
| 115 | VariableDeclaration::ZeroInitializer::create(Int64ByteSize)); |
John Porto | f8b4cc8 | 2015-06-09 18:06:19 -0700 | [diff] [blame] | 116 | |
| 117 | const RelocOffsetT NodeNameDeclarationOffset = 0; |
John Porto | 1bec8bc | 2015-06-22 10:51:13 -0700 | [diff] [blame] | 118 | Var->addInitializer(VariableDeclaration::RelocInitializer::create( |
John Porto | f8b4cc8 | 2015-06-09 18:06:19 -0700 | [diff] [blame] | 119 | NodeNameDeclaration, NodeNameDeclarationOffset)); |
| 120 | Var->setAlignment(Int64ByteSize); |
| 121 | return Var; |
| 122 | } |
John Porto | f8b4cc8 | 2015-06-09 18:06:19 -0700 | [diff] [blame] | 123 | } // end of anonymous namespace |
| 124 | |
| 125 | void Cfg::profileBlocks() { |
| 126 | if (GlobalInits == nullptr) |
| 127 | GlobalInits.reset(new VariableDeclarationList()); |
| 128 | |
| 129 | for (CfgNode *Node : Nodes) { |
| 130 | IceString NodeAsmName = Node->getAsmName(); |
John Porto | 1bec8bc | 2015-06-22 10:51:13 -0700 | [diff] [blame] | 131 | GlobalInits->push_back(nodeNameDeclaration(Ctx, NodeAsmName)); |
John Porto | f8b4cc8 | 2015-06-09 18:06:19 -0700 | [diff] [blame] | 132 | GlobalInits->push_back( |
John Porto | 1bec8bc | 2015-06-22 10:51:13 -0700 | [diff] [blame] | 133 | blockProfilingInfoDeclaration(Ctx, NodeAsmName, GlobalInits->back())); |
John Porto | f8b4cc8 | 2015-06-09 18:06:19 -0700 | [diff] [blame] | 134 | Node->profileExecutionCount(GlobalInits->back()); |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | bool Cfg::isProfileGlobal(const VariableDeclaration &Var) { |
| 139 | return Var.getName().find(BlockStatsGlobalPrefix) == 0; |
| 140 | } |
| 141 | |
| 142 | void Cfg::addCallToProfileSummary() { |
| 143 | // The call(s) to __Sz_profile_summary are added by the profiler in functions |
| 144 | // that cause the program to exit. This function is defined in |
| 145 | // runtime/szrt_profiler.c. |
| 146 | Constant *ProfileSummarySym = |
| 147 | Ctx->getConstantExternSym("__Sz_profile_summary"); |
| 148 | constexpr SizeT NumArgs = 0; |
| 149 | constexpr Variable *Void = nullptr; |
| 150 | constexpr bool HasTailCall = false; |
| 151 | auto *Call = |
| 152 | InstCall::create(this, NumArgs, Void, ProfileSummarySym, HasTailCall); |
| 153 | getEntryNode()->getInsts().push_front(Call); |
| 154 | } |
| 155 | |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 156 | void Cfg::translate() { |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 157 | if (hasError()) |
| 158 | return; |
Andrew Scull | 57e1268 | 2015-09-16 11:30:19 -0700 | [diff] [blame] | 159 | // FunctionTimer conditionally pushes/pops a TimerMarker if TimeEachFunction |
| 160 | // is enabled. |
Jim Stichnoth | 380d7b9 | 2015-01-30 13:10:39 -0800 | [diff] [blame] | 161 | std::unique_ptr<TimerMarker> FunctionTimer; |
Jim Stichnoth | 20b71f5 | 2015-06-24 15:52:24 -0700 | [diff] [blame] | 162 | if (BuildDefs::dump()) { |
Karl Schimpf | df80eb8 | 2015-02-09 14:20:22 -0800 | [diff] [blame] | 163 | const IceString &TimingFocusOn = |
| 164 | getContext()->getFlags().getTimingFocusOn(); |
Jim Stichnoth | 380d7b9 | 2015-01-30 13:10:39 -0800 | [diff] [blame] | 165 | const IceString &Name = getFunctionName(); |
| 166 | if (TimingFocusOn == "*" || TimingFocusOn == Name) { |
Jim Stichnoth | 1c44d81 | 2014-12-08 14:57:52 -0800 | [diff] [blame] | 167 | setFocusedTiming(); |
| 168 | getContext()->resetTimer(GlobalContext::TSK_Default); |
Jim Stichnoth | 380d7b9 | 2015-01-30 13:10:39 -0800 | [diff] [blame] | 169 | getContext()->setTimerName(GlobalContext::TSK_Default, Name); |
Jim Stichnoth | 1c44d81 | 2014-12-08 14:57:52 -0800 | [diff] [blame] | 170 | } |
Karl Schimpf | df80eb8 | 2015-02-09 14:20:22 -0800 | [diff] [blame] | 171 | if (getContext()->getFlags().getTimeEachFunction()) |
Jim Stichnoth | 380d7b9 | 2015-01-30 13:10:39 -0800 | [diff] [blame] | 172 | FunctionTimer.reset(new TimerMarker( |
| 173 | getContext()->getTimerID(GlobalContext::TSK_Funcs, Name), |
| 174 | getContext(), GlobalContext::TSK_Funcs)); |
Jim Stichnoth | d14b1a0 | 2014-10-08 08:28:36 -0700 | [diff] [blame] | 175 | } |
Jim Stichnoth | 8363a06 | 2014-10-07 10:02:38 -0700 | [diff] [blame] | 176 | TimerMarker T(TimerStack::TT_translate, this); |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 177 | |
Jim Stichnoth | d97c7df | 2014-06-04 11:57:08 -0700 | [diff] [blame] | 178 | dump("Initial CFG"); |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 179 | |
John Porto | f8b4cc8 | 2015-06-09 18:06:19 -0700 | [diff] [blame] | 180 | if (getContext()->getFlags().getEnableBlockProfile()) { |
| 181 | profileBlocks(); |
Andrew Scull | 57e1268 | 2015-09-16 11:30:19 -0700 | [diff] [blame] | 182 | // TODO(jpp): this is fragile, at best. Figure out a better way of |
| 183 | // detecting exit functions. |
John Porto | f8b4cc8 | 2015-06-09 18:06:19 -0700 | [diff] [blame] | 184 | if (GlobalContext::matchSymbolName(getFunctionName(), "exit")) { |
| 185 | addCallToProfileSummary(); |
| 186 | } |
| 187 | dump("Profiled CFG"); |
| 188 | } |
| 189 | |
Andrew Scull | 57e1268 | 2015-09-16 11:30:19 -0700 | [diff] [blame] | 190 | // The set of translation passes and their order are determined by the |
| 191 | // target. |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 192 | getTarget()->translate(); |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 193 | |
Jim Stichnoth | d97c7df | 2014-06-04 11:57:08 -0700 | [diff] [blame] | 194 | dump("Final output"); |
Jim Stichnoth | 8363a06 | 2014-10-07 10:02:38 -0700 | [diff] [blame] | 195 | if (getFocusedTiming()) |
| 196 | getContext()->dumpTimers(); |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 197 | } |
| 198 | |
Jim Stichnoth | 69d3f9c | 2015-03-23 10:33:38 -0700 | [diff] [blame] | 199 | void Cfg::computeInOutEdges() { |
| 200 | // Compute the out-edges. |
Jim Stichnoth | f44f371 | 2014-10-01 14:05:51 -0700 | [diff] [blame] | 201 | for (CfgNode *Node : Nodes) |
Jim Stichnoth | 69d3f9c | 2015-03-23 10:33:38 -0700 | [diff] [blame] | 202 | Node->computeSuccessors(); |
| 203 | |
| 204 | // Prune any unreachable nodes before computing in-edges. |
| 205 | SizeT NumNodes = getNumNodes(); |
| 206 | llvm::BitVector Reachable(NumNodes); |
| 207 | llvm::BitVector Pending(NumNodes); |
| 208 | Pending.set(getEntryNode()->getIndex()); |
| 209 | while (true) { |
| 210 | int Index = Pending.find_first(); |
| 211 | if (Index == -1) |
| 212 | break; |
| 213 | Pending.reset(Index); |
| 214 | Reachable.set(Index); |
| 215 | CfgNode *Node = Nodes[Index]; |
| 216 | assert(Node->getIndex() == (SizeT)Index); |
| 217 | for (CfgNode *Succ : Node->getOutEdges()) { |
| 218 | SizeT SuccIndex = Succ->getIndex(); |
| 219 | if (!Reachable.test(SuccIndex)) |
| 220 | Pending.set(SuccIndex); |
| 221 | } |
| 222 | } |
| 223 | SizeT Dest = 0; |
| 224 | for (SizeT Source = 0; Source < NumNodes; ++Source) { |
| 225 | if (Reachable.test(Source)) { |
| 226 | Nodes[Dest] = Nodes[Source]; |
| 227 | Nodes[Dest]->resetIndex(Dest); |
| 228 | // Compute the in-edges. |
| 229 | Nodes[Dest]->computePredecessors(); |
| 230 | ++Dest; |
| 231 | } |
| 232 | } |
| 233 | Nodes.resize(Dest); |
Jim Stichnoth | 1aca230 | 2015-09-16 11:25:22 -0700 | [diff] [blame] | 234 | |
| 235 | TimerMarker T(TimerStack::TT_phiValidation, this); |
| 236 | for (CfgNode *Node : Nodes) |
| 237 | Node->validatePhis(); |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 238 | } |
| 239 | |
Jim Stichnoth | d97c7df | 2014-06-04 11:57:08 -0700 | [diff] [blame] | 240 | void Cfg::renumberInstructions() { |
Jim Stichnoth | 8363a06 | 2014-10-07 10:02:38 -0700 | [diff] [blame] | 241 | TimerMarker T(TimerStack::TT_renumberInstructions, this); |
Jim Stichnoth | e5b73e6 | 2014-12-15 09:58:51 -0800 | [diff] [blame] | 242 | NextInstNumber = Inst::NumberInitial; |
Jim Stichnoth | f44f371 | 2014-10-01 14:05:51 -0700 | [diff] [blame] | 243 | for (CfgNode *Node : Nodes) |
| 244 | Node->renumberInstructions(); |
Jim Stichnoth | d97c7df | 2014-06-04 11:57:08 -0700 | [diff] [blame] | 245 | } |
| 246 | |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 247 | // placePhiLoads() must be called before placePhiStores(). |
| 248 | void Cfg::placePhiLoads() { |
Jim Stichnoth | 8363a06 | 2014-10-07 10:02:38 -0700 | [diff] [blame] | 249 | TimerMarker T(TimerStack::TT_placePhiLoads, this); |
Jim Stichnoth | f44f371 | 2014-10-01 14:05:51 -0700 | [diff] [blame] | 250 | for (CfgNode *Node : Nodes) |
| 251 | Node->placePhiLoads(); |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | // placePhiStores() must be called after placePhiLoads(). |
| 255 | void Cfg::placePhiStores() { |
Jim Stichnoth | 8363a06 | 2014-10-07 10:02:38 -0700 | [diff] [blame] | 256 | TimerMarker T(TimerStack::TT_placePhiStores, this); |
Jim Stichnoth | f44f371 | 2014-10-01 14:05:51 -0700 | [diff] [blame] | 257 | for (CfgNode *Node : Nodes) |
| 258 | Node->placePhiStores(); |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | void Cfg::deletePhis() { |
Jim Stichnoth | 8363a06 | 2014-10-07 10:02:38 -0700 | [diff] [blame] | 262 | TimerMarker T(TimerStack::TT_deletePhis, this); |
Jim Stichnoth | f44f371 | 2014-10-01 14:05:51 -0700 | [diff] [blame] | 263 | for (CfgNode *Node : Nodes) |
| 264 | Node->deletePhis(); |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 265 | } |
| 266 | |
Jim Stichnoth | 336f6c4 | 2014-10-30 15:01:31 -0700 | [diff] [blame] | 267 | void Cfg::advancedPhiLowering() { |
| 268 | TimerMarker T(TimerStack::TT_advancedPhiLowering, this); |
Jim Stichnoth | a3f57b9 | 2015-07-30 12:46:04 -0700 | [diff] [blame] | 269 | // Clear all previously computed live ranges (but not live-in/live-out bit |
| 270 | // vectors or last-use markers), because the follow-on register allocation is |
| 271 | // only concerned with live ranges across the newly created blocks. |
| 272 | for (Variable *Var : Variables) { |
| 273 | Var->getLiveRange().reset(); |
| 274 | } |
Andrew Scull | 57e1268 | 2015-09-16 11:30:19 -0700 | [diff] [blame] | 275 | // This splits edges and appends new nodes to the end of the node list. This |
| 276 | // can invalidate iterators, so don't use an iterator. |
Jim Stichnoth | 336f6c4 | 2014-10-30 15:01:31 -0700 | [diff] [blame] | 277 | SizeT NumNodes = getNumNodes(); |
Jim Stichnoth | a3f57b9 | 2015-07-30 12:46:04 -0700 | [diff] [blame] | 278 | SizeT NumVars = getNumVariables(); |
Jim Stichnoth | 336f6c4 | 2014-10-30 15:01:31 -0700 | [diff] [blame] | 279 | for (SizeT I = 0; I < NumNodes; ++I) |
| 280 | Nodes[I]->advancedPhiLowering(); |
Jim Stichnoth | a3f57b9 | 2015-07-30 12:46:04 -0700 | [diff] [blame] | 281 | |
| 282 | TimerMarker TT(TimerStack::TT_lowerPhiAssignments, this); |
| 283 | if (true) { |
Andrew Scull | 57e1268 | 2015-09-16 11:30:19 -0700 | [diff] [blame] | 284 | // The following code does an in-place update of liveness and live ranges |
| 285 | // as a result of adding the new phi edge split nodes. |
Jim Stichnoth | a3f57b9 | 2015-07-30 12:46:04 -0700 | [diff] [blame] | 286 | getLiveness()->initPhiEdgeSplits(Nodes.begin() + NumNodes, |
| 287 | Variables.begin() + NumVars); |
| 288 | TimerMarker TTT(TimerStack::TT_liveness, this); |
| 289 | // Iterate over the newly added nodes to add their liveness info. |
| 290 | for (auto I = Nodes.begin() + NumNodes, E = Nodes.end(); I != E; ++I) { |
| 291 | InstNumberT FirstInstNum = getNextInstNumber(); |
| 292 | (*I)->renumberInstructions(); |
| 293 | InstNumberT LastInstNum = getNextInstNumber() - 1; |
Jim Stichnoth | a3f57b9 | 2015-07-30 12:46:04 -0700 | [diff] [blame] | 294 | (*I)->liveness(getLiveness()); |
| 295 | (*I)->livenessAddIntervals(getLiveness(), FirstInstNum, LastInstNum); |
| 296 | } |
| 297 | } else { |
| 298 | // The following code does a brute-force recalculation of live ranges as a |
Andrew Scull | 57e1268 | 2015-09-16 11:30:19 -0700 | [diff] [blame] | 299 | // result of adding the new phi edge split nodes. The liveness calculation |
Jim Stichnoth | a3f57b9 | 2015-07-30 12:46:04 -0700 | [diff] [blame] | 300 | // is particularly expensive because the new nodes are not yet in a proper |
| 301 | // topological order and so convergence is slower. |
| 302 | // |
| 303 | // This code is kept here for reference and can be temporarily enabled in |
| 304 | // case the incremental code is under suspicion. |
| 305 | renumberInstructions(); |
| 306 | liveness(Liveness_Intervals); |
| 307 | getVMetadata()->init(VMK_All); |
| 308 | } |
| 309 | Target->regAlloc(RAK_Phi); |
Jim Stichnoth | 336f6c4 | 2014-10-30 15:01:31 -0700 | [diff] [blame] | 310 | } |
| 311 | |
Andrew Scull | 57e1268 | 2015-09-16 11:30:19 -0700 | [diff] [blame] | 312 | // Find a reasonable placement for nodes that have not yet been placed, while |
| 313 | // maintaining the same relative ordering among already placed nodes. |
Jim Stichnoth | 336f6c4 | 2014-10-30 15:01:31 -0700 | [diff] [blame] | 314 | void Cfg::reorderNodes() { |
Andrew Scull | 57e1268 | 2015-09-16 11:30:19 -0700 | [diff] [blame] | 315 | // TODO(ascull): it would be nice if the switch tests were always followed by |
| 316 | // the default case to allow for fall through. |
Andrew Scull | 00741a0 | 2015-09-16 19:04:09 -0700 | [diff] [blame^] | 317 | using PlacedList = CfgList<CfgNode *>; |
Jim Stichnoth | 336f6c4 | 2014-10-30 15:01:31 -0700 | [diff] [blame] | 318 | PlacedList Placed; // Nodes with relative placement locked down |
| 319 | PlacedList Unreachable; // Unreachable nodes |
| 320 | PlacedList::iterator NoPlace = Placed.end(); |
Andrew Scull | 57e1268 | 2015-09-16 11:30:19 -0700 | [diff] [blame] | 321 | // Keep track of where each node has been tentatively placed so that we can |
| 322 | // manage insertions into the middle. |
Andrew Scull | 00741a0 | 2015-09-16 19:04:09 -0700 | [diff] [blame^] | 323 | CfgVector<PlacedList::iterator> PlaceIndex(Nodes.size(), NoPlace); |
Jim Stichnoth | 336f6c4 | 2014-10-30 15:01:31 -0700 | [diff] [blame] | 324 | for (CfgNode *Node : Nodes) { |
Andrew Scull | 57e1268 | 2015-09-16 11:30:19 -0700 | [diff] [blame] | 325 | // The "do ... while(0);" construct is to factor out the --PlaceIndex and |
| 326 | // assert() statements before moving to the next node. |
Jim Stichnoth | 336f6c4 | 2014-10-30 15:01:31 -0700 | [diff] [blame] | 327 | do { |
Andrew Scull | 713278a | 2015-07-22 17:17:02 -0700 | [diff] [blame] | 328 | if (Node != getEntryNode() && Node->getInEdges().empty()) { |
Andrew Scull | 57e1268 | 2015-09-16 11:30:19 -0700 | [diff] [blame] | 329 | // The node has essentially been deleted since it is not a successor of |
| 330 | // any other node. |
Andrew Scull | 713278a | 2015-07-22 17:17:02 -0700 | [diff] [blame] | 331 | Unreachable.push_back(Node); |
| 332 | PlaceIndex[Node->getIndex()] = Unreachable.end(); |
| 333 | Node->setNeedsPlacement(false); |
| 334 | continue; |
| 335 | } |
Jim Stichnoth | 336f6c4 | 2014-10-30 15:01:31 -0700 | [diff] [blame] | 336 | if (!Node->needsPlacement()) { |
| 337 | // Add to the end of the Placed list. |
| 338 | Placed.push_back(Node); |
| 339 | PlaceIndex[Node->getIndex()] = Placed.end(); |
| 340 | continue; |
| 341 | } |
| 342 | Node->setNeedsPlacement(false); |
Andrew Scull | 57e1268 | 2015-09-16 11:30:19 -0700 | [diff] [blame] | 343 | // Assume for now that the unplaced node is from edge-splitting and |
| 344 | // therefore has 1 in-edge and 1 out-edge (actually, possibly more than 1 |
| 345 | // in-edge if the predecessor node was contracted). If this changes in |
| 346 | // the future, rethink the strategy. |
Jim Stichnoth | 336f6c4 | 2014-10-30 15:01:31 -0700 | [diff] [blame] | 347 | assert(Node->getInEdges().size() >= 1); |
| 348 | assert(Node->getOutEdges().size() == 1); |
| 349 | |
| 350 | // If it's a (non-critical) edge where the successor has a single |
| 351 | // in-edge, then place it before the successor. |
Jim Stichnoth | bfb410d | 2014-11-05 16:04:05 -0800 | [diff] [blame] | 352 | CfgNode *Succ = Node->getOutEdges().front(); |
Jim Stichnoth | 336f6c4 | 2014-10-30 15:01:31 -0700 | [diff] [blame] | 353 | if (Succ->getInEdges().size() == 1 && |
| 354 | PlaceIndex[Succ->getIndex()] != NoPlace) { |
| 355 | Placed.insert(PlaceIndex[Succ->getIndex()], Node); |
| 356 | PlaceIndex[Node->getIndex()] = PlaceIndex[Succ->getIndex()]; |
| 357 | continue; |
| 358 | } |
| 359 | |
| 360 | // Otherwise, place it after the (first) predecessor. |
Jim Stichnoth | bfb410d | 2014-11-05 16:04:05 -0800 | [diff] [blame] | 361 | CfgNode *Pred = Node->getInEdges().front(); |
Jim Stichnoth | 336f6c4 | 2014-10-30 15:01:31 -0700 | [diff] [blame] | 362 | auto PredPosition = PlaceIndex[Pred->getIndex()]; |
Andrew Scull | 57e1268 | 2015-09-16 11:30:19 -0700 | [diff] [blame] | 363 | // It shouldn't be the case that PredPosition==NoPlace, but if that |
| 364 | // somehow turns out to be true, we just insert Node before |
Jim Stichnoth | 336f6c4 | 2014-10-30 15:01:31 -0700 | [diff] [blame] | 365 | // PredPosition=NoPlace=Placed.end() . |
| 366 | if (PredPosition != NoPlace) |
| 367 | ++PredPosition; |
| 368 | Placed.insert(PredPosition, Node); |
| 369 | PlaceIndex[Node->getIndex()] = PredPosition; |
| 370 | } while (0); |
| 371 | |
| 372 | --PlaceIndex[Node->getIndex()]; |
| 373 | assert(*PlaceIndex[Node->getIndex()] == Node); |
| 374 | } |
| 375 | |
| 376 | // Reorder Nodes according to the built-up lists. |
Karl Schimpf | ac7d734 | 2015-08-06 12:55:23 -0700 | [diff] [blame] | 377 | NodeList Reordered; |
| 378 | Reordered.reserve(Placed.size() + Unreachable.size()); |
Jim Stichnoth | 336f6c4 | 2014-10-30 15:01:31 -0700 | [diff] [blame] | 379 | for (CfgNode *Node : Placed) |
Karl Schimpf | ac7d734 | 2015-08-06 12:55:23 -0700 | [diff] [blame] | 380 | Reordered.push_back(Node); |
Jim Stichnoth | 336f6c4 | 2014-10-30 15:01:31 -0700 | [diff] [blame] | 381 | for (CfgNode *Node : Unreachable) |
Karl Schimpf | ac7d734 | 2015-08-06 12:55:23 -0700 | [diff] [blame] | 382 | Reordered.push_back(Node); |
| 383 | assert(getNumNodes() == Reordered.size()); |
| 384 | swapNodes(Reordered); |
Jim Stichnoth | 336f6c4 | 2014-10-30 15:01:31 -0700 | [diff] [blame] | 385 | } |
| 386 | |
Qining Lu | 969f6a3 | 2015-07-31 09:58:34 -0700 | [diff] [blame] | 387 | namespace { |
| 388 | void getRandomPostOrder(CfgNode *Node, llvm::BitVector &ToVisit, |
| 389 | Ice::NodeList &PostOrder, |
| 390 | Ice::RandomNumberGenerator *RNG) { |
| 391 | assert(ToVisit[Node->getIndex()]); |
| 392 | ToVisit[Node->getIndex()] = false; |
| 393 | NodeList Outs = Node->getOutEdges(); |
| 394 | Ice::RandomShuffle(Outs.begin(), Outs.end(), |
| 395 | [RNG](int N) { return RNG->next(N); }); |
| 396 | for (CfgNode *Next : Outs) { |
| 397 | if (ToVisit[Next->getIndex()]) |
| 398 | getRandomPostOrder(Next, ToVisit, PostOrder, RNG); |
| 399 | } |
| 400 | PostOrder.push_back(Node); |
| 401 | } |
| 402 | } // end of anonymous namespace |
| 403 | |
| 404 | void Cfg::shuffleNodes() { |
| 405 | if (!Ctx->getFlags().shouldReorderBasicBlocks()) |
| 406 | return; |
| 407 | |
| 408 | NodeList ReversedReachable; |
| 409 | NodeList Unreachable; |
| 410 | llvm::BitVector ToVisit(Nodes.size(), true); |
Qining Lu | aee5fa8 | 2015-08-20 14:59:03 -0700 | [diff] [blame] | 411 | // Create Random number generator for function reordering |
| 412 | RandomNumberGenerator RNG(Ctx->getFlags().getRandomSeed(), |
| 413 | RPE_BasicBlockReordering, SequenceNumber); |
Qining Lu | 969f6a3 | 2015-07-31 09:58:34 -0700 | [diff] [blame] | 414 | // Traverse from entry node. |
Qining Lu | aee5fa8 | 2015-08-20 14:59:03 -0700 | [diff] [blame] | 415 | getRandomPostOrder(getEntryNode(), ToVisit, ReversedReachable, &RNG); |
Qining Lu | 969f6a3 | 2015-07-31 09:58:34 -0700 | [diff] [blame] | 416 | // Collect the unreachable nodes. |
| 417 | for (CfgNode *Node : Nodes) |
| 418 | if (ToVisit[Node->getIndex()]) |
| 419 | Unreachable.push_back(Node); |
| 420 | // Copy the layout list to the Nodes. |
Karl Schimpf | ac7d734 | 2015-08-06 12:55:23 -0700 | [diff] [blame] | 421 | NodeList Shuffled; |
| 422 | Shuffled.reserve(ReversedReachable.size() + Unreachable.size()); |
Qining Lu | 969f6a3 | 2015-07-31 09:58:34 -0700 | [diff] [blame] | 423 | for (CfgNode *Node : reverse_range(ReversedReachable)) |
Karl Schimpf | ac7d734 | 2015-08-06 12:55:23 -0700 | [diff] [blame] | 424 | Shuffled.push_back(Node); |
| 425 | for (CfgNode *Node : Unreachable) |
| 426 | Shuffled.push_back(Node); |
| 427 | assert(Nodes.size() == Shuffled.size()); |
| 428 | swapNodes(Shuffled); |
Qining Lu | 969f6a3 | 2015-07-31 09:58:34 -0700 | [diff] [blame] | 429 | |
| 430 | dump("After basic block shuffling"); |
| 431 | } |
| 432 | |
Matt Wala | 45a0623 | 2014-07-09 16:33:22 -0700 | [diff] [blame] | 433 | void Cfg::doArgLowering() { |
Jim Stichnoth | 8363a06 | 2014-10-07 10:02:38 -0700 | [diff] [blame] | 434 | TimerMarker T(TimerStack::TT_doArgLowering, this); |
Matt Wala | 45a0623 | 2014-07-09 16:33:22 -0700 | [diff] [blame] | 435 | getTarget()->lowerArguments(); |
| 436 | } |
| 437 | |
Jim Stichnoth | d97c7df | 2014-06-04 11:57:08 -0700 | [diff] [blame] | 438 | void Cfg::doAddressOpt() { |
Jim Stichnoth | 8363a06 | 2014-10-07 10:02:38 -0700 | [diff] [blame] | 439 | TimerMarker T(TimerStack::TT_doAddressOpt, this); |
Jim Stichnoth | f44f371 | 2014-10-01 14:05:51 -0700 | [diff] [blame] | 440 | for (CfgNode *Node : Nodes) |
| 441 | Node->doAddressOpt(); |
Jim Stichnoth | d97c7df | 2014-06-04 11:57:08 -0700 | [diff] [blame] | 442 | } |
| 443 | |
Matt Wala | c330274 | 2014-08-15 16:21:56 -0700 | [diff] [blame] | 444 | void Cfg::doNopInsertion() { |
Qining Lu | 969f6a3 | 2015-07-31 09:58:34 -0700 | [diff] [blame] | 445 | if (!Ctx->getFlags().shouldDoNopInsertion()) |
| 446 | return; |
Jim Stichnoth | 8363a06 | 2014-10-07 10:02:38 -0700 | [diff] [blame] | 447 | TimerMarker T(TimerStack::TT_doNopInsertion, this); |
Qining Lu | aee5fa8 | 2015-08-20 14:59:03 -0700 | [diff] [blame] | 448 | RandomNumberGenerator RNG(Ctx->getFlags().getRandomSeed(), RPE_NopInsertion, |
| 449 | SequenceNumber); |
Jim Stichnoth | f44f371 | 2014-10-01 14:05:51 -0700 | [diff] [blame] | 450 | for (CfgNode *Node : Nodes) |
Qining Lu | aee5fa8 | 2015-08-20 14:59:03 -0700 | [diff] [blame] | 451 | Node->doNopInsertion(RNG); |
Matt Wala | c330274 | 2014-08-15 16:21:56 -0700 | [diff] [blame] | 452 | } |
| 453 | |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 454 | void Cfg::genCode() { |
Jim Stichnoth | 8363a06 | 2014-10-07 10:02:38 -0700 | [diff] [blame] | 455 | TimerMarker T(TimerStack::TT_genCode, this); |
Jim Stichnoth | f44f371 | 2014-10-01 14:05:51 -0700 | [diff] [blame] | 456 | for (CfgNode *Node : Nodes) |
| 457 | Node->genCode(); |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 458 | } |
| 459 | |
| 460 | // Compute the stack frame layout. |
| 461 | void Cfg::genFrame() { |
Jim Stichnoth | 8363a06 | 2014-10-07 10:02:38 -0700 | [diff] [blame] | 462 | TimerMarker T(TimerStack::TT_genFrame, this); |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 463 | getTarget()->addProlog(Entry); |
Jim Stichnoth | f44f371 | 2014-10-01 14:05:51 -0700 | [diff] [blame] | 464 | for (CfgNode *Node : Nodes) |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 465 | if (Node->getHasReturn()) |
| 466 | getTarget()->addEpilog(Node); |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 467 | } |
| 468 | |
Andrew Scull | aa6c109 | 2015-09-03 17:50:30 -0700 | [diff] [blame] | 469 | void Cfg::computeLoopNestDepth() { |
| 470 | TimerMarker T(TimerStack::TT_computeLoopNestDepth, this); |
| 471 | LoopAnalyzer LA(this); |
| 472 | LA.computeLoopNestDepth(); |
| 473 | } |
| 474 | |
Andrew Scull | 57e1268 | 2015-09-16 11:30:19 -0700 | [diff] [blame] | 475 | // This is a lightweight version of live-range-end calculation. Marks the last |
Andrew Scull | aa6c109 | 2015-09-03 17:50:30 -0700 | [diff] [blame] | 476 | // use of only those variables whose definition and uses are completely with a |
Andrew Scull | 57e1268 | 2015-09-16 11:30:19 -0700 | [diff] [blame] | 477 | // single block. It is a quick single pass and doesn't need to iterate until |
Andrew Scull | aa6c109 | 2015-09-03 17:50:30 -0700 | [diff] [blame] | 478 | // convergence. |
Jim Stichnoth | d97c7df | 2014-06-04 11:57:08 -0700 | [diff] [blame] | 479 | void Cfg::livenessLightweight() { |
Jim Stichnoth | 8363a06 | 2014-10-07 10:02:38 -0700 | [diff] [blame] | 480 | TimerMarker T(TimerStack::TT_livenessLightweight, this); |
Jim Stichnoth | 877b04e | 2014-10-15 15:13:06 -0700 | [diff] [blame] | 481 | getVMetadata()->init(VMK_Uses); |
Jim Stichnoth | f44f371 | 2014-10-01 14:05:51 -0700 | [diff] [blame] | 482 | for (CfgNode *Node : Nodes) |
| 483 | Node->livenessLightweight(); |
Jim Stichnoth | d97c7df | 2014-06-04 11:57:08 -0700 | [diff] [blame] | 484 | } |
| 485 | |
| 486 | void Cfg::liveness(LivenessMode Mode) { |
Jim Stichnoth | 8363a06 | 2014-10-07 10:02:38 -0700 | [diff] [blame] | 487 | TimerMarker T(TimerStack::TT_liveness, this); |
Jim Stichnoth | d97c7df | 2014-06-04 11:57:08 -0700 | [diff] [blame] | 488 | Live.reset(new Liveness(this, Mode)); |
Jim Stichnoth | 877b04e | 2014-10-15 15:13:06 -0700 | [diff] [blame] | 489 | getVMetadata()->init(VMK_Uses); |
Jim Stichnoth | d97c7df | 2014-06-04 11:57:08 -0700 | [diff] [blame] | 490 | Live->init(); |
| 491 | // Initialize with all nodes needing to be processed. |
| 492 | llvm::BitVector NeedToProcess(Nodes.size(), true); |
| 493 | while (NeedToProcess.any()) { |
| 494 | // Iterate in reverse topological order to speed up convergence. |
Jim Stichnoth | 7e57136 | 2015-01-09 11:43:26 -0800 | [diff] [blame] | 495 | for (CfgNode *Node : reverse_range(Nodes)) { |
Jim Stichnoth | d97c7df | 2014-06-04 11:57:08 -0700 | [diff] [blame] | 496 | if (NeedToProcess[Node->getIndex()]) { |
| 497 | NeedToProcess[Node->getIndex()] = false; |
| 498 | bool Changed = Node->liveness(getLiveness()); |
| 499 | if (Changed) { |
| 500 | // If the beginning-of-block liveness changed since the last |
| 501 | // iteration, mark all in-edges as needing to be processed. |
Jim Stichnoth | f44f371 | 2014-10-01 14:05:51 -0700 | [diff] [blame] | 502 | for (CfgNode *Pred : Node->getInEdges()) |
Jim Stichnoth | d97c7df | 2014-06-04 11:57:08 -0700 | [diff] [blame] | 503 | NeedToProcess[Pred->getIndex()] = true; |
Jim Stichnoth | d97c7df | 2014-06-04 11:57:08 -0700 | [diff] [blame] | 504 | } |
| 505 | } |
| 506 | } |
| 507 | } |
| 508 | if (Mode == Liveness_Intervals) { |
| 509 | // Reset each variable's live range. |
Jim Stichnoth | f44f371 | 2014-10-01 14:05:51 -0700 | [diff] [blame] | 510 | for (Variable *Var : Variables) |
| 511 | Var->resetLiveRange(); |
Jim Stichnoth | d97c7df | 2014-06-04 11:57:08 -0700 | [diff] [blame] | 512 | } |
Andrew Scull | 57e1268 | 2015-09-16 11:30:19 -0700 | [diff] [blame] | 513 | // Make a final pass over each node to delete dead instructions, collect the |
| 514 | // first and last instruction numbers, and add live range segments for that |
| 515 | // node. |
Jim Stichnoth | e5b73e6 | 2014-12-15 09:58:51 -0800 | [diff] [blame] | 516 | for (CfgNode *Node : Nodes) { |
| 517 | InstNumberT FirstInstNum = Inst::NumberSentinel; |
| 518 | InstNumberT LastInstNum = Inst::NumberSentinel; |
Jim Stichnoth | 29841e8 | 2014-12-23 12:26:24 -0800 | [diff] [blame] | 519 | for (Inst &I : Node->getPhis()) { |
| 520 | I.deleteIfDead(); |
| 521 | if (Mode == Liveness_Intervals && !I.isDeleted()) { |
Jim Stichnoth | e5b73e6 | 2014-12-15 09:58:51 -0800 | [diff] [blame] | 522 | if (FirstInstNum == Inst::NumberSentinel) |
Jim Stichnoth | 29841e8 | 2014-12-23 12:26:24 -0800 | [diff] [blame] | 523 | FirstInstNum = I.getNumber(); |
| 524 | assert(I.getNumber() > LastInstNum); |
| 525 | LastInstNum = I.getNumber(); |
Jim Stichnoth | d97c7df | 2014-06-04 11:57:08 -0700 | [diff] [blame] | 526 | } |
Jim Stichnoth | e5b73e6 | 2014-12-15 09:58:51 -0800 | [diff] [blame] | 527 | } |
Jim Stichnoth | 29841e8 | 2014-12-23 12:26:24 -0800 | [diff] [blame] | 528 | for (Inst &I : Node->getInsts()) { |
| 529 | I.deleteIfDead(); |
| 530 | if (Mode == Liveness_Intervals && !I.isDeleted()) { |
Jim Stichnoth | e5b73e6 | 2014-12-15 09:58:51 -0800 | [diff] [blame] | 531 | if (FirstInstNum == Inst::NumberSentinel) |
Jim Stichnoth | 29841e8 | 2014-12-23 12:26:24 -0800 | [diff] [blame] | 532 | FirstInstNum = I.getNumber(); |
| 533 | assert(I.getNumber() > LastInstNum); |
| 534 | LastInstNum = I.getNumber(); |
Jim Stichnoth | e5b73e6 | 2014-12-15 09:58:51 -0800 | [diff] [blame] | 535 | } |
| 536 | } |
| 537 | if (Mode == Liveness_Intervals) { |
Andrew Scull | 57e1268 | 2015-09-16 11:30:19 -0700 | [diff] [blame] | 538 | // Special treatment for live in-args. Their liveness needs to extend |
| 539 | // beyond the beginning of the function, otherwise an arg whose only use |
| 540 | // is in the first instruction will end up having the trivial live range |
| 541 | // [2,2) and will *not* interfere with other arguments. So if the first |
| 542 | // instruction of the method is "r=arg1+arg2", both args may be assigned |
| 543 | // the same register. This is accomplished by extending the entry block's |
| 544 | // instruction range from [2,n) to [1,n) which will transform the |
| 545 | // problematic [2,2) live ranges into [1,2). |
Jim Stichnoth | e4f65d8 | 2015-06-17 22:16:02 -0700 | [diff] [blame] | 546 | if (Node == getEntryNode()) { |
Andrew Scull | 57e1268 | 2015-09-16 11:30:19 -0700 | [diff] [blame] | 547 | // TODO(stichnot): Make it a strict requirement that the entry node |
| 548 | // gets the lowest instruction numbers, so that extending the live |
| 549 | // range for in-args is guaranteed to work. |
Jim Stichnoth | e5b73e6 | 2014-12-15 09:58:51 -0800 | [diff] [blame] | 550 | FirstInstNum = Inst::NumberExtended; |
Jim Stichnoth | e4f65d8 | 2015-06-17 22:16:02 -0700 | [diff] [blame] | 551 | } |
Jim Stichnoth | e5b73e6 | 2014-12-15 09:58:51 -0800 | [diff] [blame] | 552 | Node->livenessAddIntervals(getLiveness(), FirstInstNum, LastInstNum); |
Jim Stichnoth | d97c7df | 2014-06-04 11:57:08 -0700 | [diff] [blame] | 553 | } |
Jim Stichnoth | d97c7df | 2014-06-04 11:57:08 -0700 | [diff] [blame] | 554 | } |
| 555 | } |
| 556 | |
Andrew Scull | 57e1268 | 2015-09-16 11:30:19 -0700 | [diff] [blame] | 557 | // Traverse every Variable of every Inst and verify that it appears within the |
| 558 | // Variable's computed live range. |
Jim Stichnoth | d97c7df | 2014-06-04 11:57:08 -0700 | [diff] [blame] | 559 | bool Cfg::validateLiveness() const { |
Jim Stichnoth | 8363a06 | 2014-10-07 10:02:38 -0700 | [diff] [blame] | 560 | TimerMarker T(TimerStack::TT_validateLiveness, this); |
Jim Stichnoth | d97c7df | 2014-06-04 11:57:08 -0700 | [diff] [blame] | 561 | bool Valid = true; |
Jim Stichnoth | e4a8f40 | 2015-01-20 12:52:51 -0800 | [diff] [blame] | 562 | OstreamLocker L(Ctx); |
Jim Stichnoth | d97c7df | 2014-06-04 11:57:08 -0700 | [diff] [blame] | 563 | Ostream &Str = Ctx->getStrDump(); |
Jim Stichnoth | f44f371 | 2014-10-01 14:05:51 -0700 | [diff] [blame] | 564 | for (CfgNode *Node : Nodes) { |
Jim Stichnoth | ae95320 | 2014-12-20 06:17:49 -0800 | [diff] [blame] | 565 | Inst *FirstInst = nullptr; |
Jim Stichnoth | 29841e8 | 2014-12-23 12:26:24 -0800 | [diff] [blame] | 566 | for (Inst &Inst : Node->getInsts()) { |
| 567 | if (Inst.isDeleted()) |
Jim Stichnoth | d97c7df | 2014-06-04 11:57:08 -0700 | [diff] [blame] | 568 | continue; |
Jim Stichnoth | ae95320 | 2014-12-20 06:17:49 -0800 | [diff] [blame] | 569 | if (FirstInst == nullptr) |
Jim Stichnoth | 29841e8 | 2014-12-23 12:26:24 -0800 | [diff] [blame] | 570 | FirstInst = &Inst; |
| 571 | InstNumberT InstNumber = Inst.getNumber(); |
| 572 | if (Variable *Dest = Inst.getDest()) { |
Jim Stichnoth | 4775255 | 2014-10-13 17:15:08 -0700 | [diff] [blame] | 573 | if (!Dest->getIgnoreLiveness()) { |
| 574 | bool Invalid = false; |
| 575 | const bool IsDest = true; |
| 576 | if (!Dest->getLiveRange().containsValue(InstNumber, IsDest)) |
| 577 | Invalid = true; |
Andrew Scull | 57e1268 | 2015-09-16 11:30:19 -0700 | [diff] [blame] | 578 | // Check that this instruction actually *begins* Dest's live range, |
| 579 | // by checking that Dest is not live in the previous instruction. As |
| 580 | // a special exception, we don't check this for the first instruction |
| 581 | // of the block, because a Phi temporary may be live at the end of |
| 582 | // the previous block, and if it is also assigned in the first |
| 583 | // instruction of this block, the adjacent live ranges get merged. |
Jim Stichnoth | 29841e8 | 2014-12-23 12:26:24 -0800 | [diff] [blame] | 584 | if (static_cast<class Inst *>(&Inst) != FirstInst && |
| 585 | !Inst.isDestNonKillable() && |
Jim Stichnoth | 4775255 | 2014-10-13 17:15:08 -0700 | [diff] [blame] | 586 | Dest->getLiveRange().containsValue(InstNumber - 1, IsDest)) |
| 587 | Invalid = true; |
| 588 | if (Invalid) { |
| 589 | Valid = false; |
Jim Stichnoth | 29841e8 | 2014-12-23 12:26:24 -0800 | [diff] [blame] | 590 | Str << "Liveness error: inst " << Inst.getNumber() << " dest "; |
Jim Stichnoth | 4775255 | 2014-10-13 17:15:08 -0700 | [diff] [blame] | 591 | Dest->dump(this); |
| 592 | Str << " live range " << Dest->getLiveRange() << "\n"; |
| 593 | } |
Jim Stichnoth | d97c7df | 2014-06-04 11:57:08 -0700 | [diff] [blame] | 594 | } |
| 595 | } |
John Porto | ec3f565 | 2015-08-31 15:07:09 -0700 | [diff] [blame] | 596 | FOREACH_VAR_IN_INST(Var, Inst) { |
| 597 | static constexpr bool IsDest = false; |
| 598 | if (!Var->getIgnoreLiveness() && |
| 599 | !Var->getLiveRange().containsValue(InstNumber, IsDest)) { |
| 600 | Valid = false; |
| 601 | Str << "Liveness error: inst " << Inst.getNumber() << " var "; |
| 602 | Var->dump(this); |
| 603 | Str << " live range " << Var->getLiveRange() << "\n"; |
Jim Stichnoth | d97c7df | 2014-06-04 11:57:08 -0700 | [diff] [blame] | 604 | } |
| 605 | } |
| 606 | } |
| 607 | } |
| 608 | return Valid; |
| 609 | } |
| 610 | |
Jim Stichnoth | 336f6c4 | 2014-10-30 15:01:31 -0700 | [diff] [blame] | 611 | void Cfg::contractEmptyNodes() { |
Andrew Scull | aa6c109 | 2015-09-03 17:50:30 -0700 | [diff] [blame] | 612 | // If we're decorating the asm output with register liveness info, this |
| 613 | // information may become corrupted or incorrect after contracting nodes that |
| 614 | // contain only redundant assignments. As such, we disable this pass when |
| 615 | // DecorateAsm is specified. This may make the resulting code look more |
| 616 | // branchy, but it should have no effect on the register assignments. |
Karl Schimpf | df80eb8 | 2015-02-09 14:20:22 -0800 | [diff] [blame] | 617 | if (Ctx->getFlags().getDecorateAsm()) |
Jim Stichnoth | 3d44fe8 | 2014-11-01 10:10:18 -0700 | [diff] [blame] | 618 | return; |
Jim Stichnoth | 336f6c4 | 2014-10-30 15:01:31 -0700 | [diff] [blame] | 619 | for (CfgNode *Node : Nodes) { |
| 620 | Node->contractIfEmpty(); |
| 621 | } |
| 622 | } |
| 623 | |
Jim Stichnoth | ff9c706 | 2014-09-18 04:50:49 -0700 | [diff] [blame] | 624 | void Cfg::doBranchOpt() { |
Jim Stichnoth | 8363a06 | 2014-10-07 10:02:38 -0700 | [diff] [blame] | 625 | TimerMarker T(TimerStack::TT_doBranchOpt, this); |
Jim Stichnoth | f44f371 | 2014-10-01 14:05:51 -0700 | [diff] [blame] | 626 | for (auto I = Nodes.begin(), E = Nodes.end(); I != E; ++I) { |
Andrew Scull | 713278a | 2015-07-22 17:17:02 -0700 | [diff] [blame] | 627 | auto NextNode = I + 1; |
Jim Stichnoth | ae95320 | 2014-12-20 06:17:49 -0800 | [diff] [blame] | 628 | (*I)->doBranchOpt(NextNode == E ? nullptr : *NextNode); |
Jim Stichnoth | ff9c706 | 2014-09-18 04:50:49 -0700 | [diff] [blame] | 629 | } |
| 630 | } |
| 631 | |
Andrew Scull | 86df4e9 | 2015-07-30 13:54:44 -0700 | [diff] [blame] | 632 | void Cfg::markNodesForSandboxing() { |
| 633 | for (const InstJumpTable *JT : JumpTables) |
| 634 | for (SizeT I = 0; I < JT->getNumTargets(); ++I) |
| 635 | JT->getTarget(I)->setNeedsAlignment(); |
| 636 | } |
| 637 | |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 638 | // ======================== Dump routines ======================== // |
| 639 | |
Andrew Scull | 57e1268 | 2015-09-16 11:30:19 -0700 | [diff] [blame] | 640 | // emitTextHeader() is not target-specific (apart from what is abstracted by |
| 641 | // the Assembler), so it is defined here rather than in the target lowering |
| 642 | // class. |
Jim Stichnoth | bbca754 | 2015-02-11 16:08:31 -0800 | [diff] [blame] | 643 | void Cfg::emitTextHeader(const IceString &MangledName, GlobalContext *Ctx, |
| 644 | const Assembler *Asm) { |
Jim Stichnoth | 20b71f5 | 2015-06-24 15:52:24 -0700 | [diff] [blame] | 645 | if (!BuildDefs::dump()) |
Jim Stichnoth | 729dbd0 | 2015-02-25 14:48:43 -0800 | [diff] [blame] | 646 | return; |
Jan Voung | 0faec4c | 2014-11-05 17:29:56 -0800 | [diff] [blame] | 647 | Ostream &Str = Ctx->getStrEmit(); |
| 648 | Str << "\t.text\n"; |
Karl Schimpf | df80eb8 | 2015-02-09 14:20:22 -0800 | [diff] [blame] | 649 | if (Ctx->getFlags().getFunctionSections()) |
Jan Voung | 0faec4c | 2014-11-05 17:29:56 -0800 | [diff] [blame] | 650 | Str << "\t.section\t.text." << MangledName << ",\"ax\",@progbits\n"; |
Jim Stichnoth | bbca754 | 2015-02-11 16:08:31 -0800 | [diff] [blame] | 651 | if (!Asm->getInternal() || Ctx->getFlags().getDisableInternal()) { |
Jan Voung | 0faec4c | 2014-11-05 17:29:56 -0800 | [diff] [blame] | 652 | Str << "\t.globl\t" << MangledName << "\n"; |
Jan Voung | b2d5084 | 2015-05-12 09:53:50 -0700 | [diff] [blame] | 653 | Str << "\t.type\t" << MangledName << ",%function\n"; |
Jan Voung | 0faec4c | 2014-11-05 17:29:56 -0800 | [diff] [blame] | 654 | } |
Andrew Scull | 86df4e9 | 2015-07-30 13:54:44 -0700 | [diff] [blame] | 655 | Str << "\t" << Asm->getAlignDirective() << " " |
Jan Voung | b2d5084 | 2015-05-12 09:53:50 -0700 | [diff] [blame] | 656 | << Asm->getBundleAlignLog2Bytes() << ",0x"; |
Jan Voung | 08c3bcd | 2014-12-01 17:55:16 -0800 | [diff] [blame] | 657 | for (uint8_t I : Asm->getNonExecBundlePadding()) |
Jan Voung | 0faec4c | 2014-11-05 17:29:56 -0800 | [diff] [blame] | 658 | Str.write_hex(I); |
| 659 | Str << "\n"; |
| 660 | Str << MangledName << ":\n"; |
| 661 | } |
| 662 | |
Andrew Scull | 86df4e9 | 2015-07-30 13:54:44 -0700 | [diff] [blame] | 663 | void Cfg::deleteJumpTableInsts() { |
| 664 | for (InstJumpTable *JumpTable : JumpTables) |
| 665 | JumpTable->setDeleted(); |
| 666 | } |
| 667 | |
| 668 | void Cfg::emitJumpTables() { |
| 669 | switch (Ctx->getFlags().getOutFileType()) { |
| 670 | case FT_Elf: |
| 671 | case FT_Iasm: { |
Andrew Scull | 57e1268 | 2015-09-16 11:30:19 -0700 | [diff] [blame] | 672 | // The emission needs to be delayed until the after the text section so |
| 673 | // save the offsets in the global context. |
Andrew Scull | 86df4e9 | 2015-07-30 13:54:44 -0700 | [diff] [blame] | 674 | IceString MangledName = Ctx->mangleName(getFunctionName()); |
| 675 | for (const InstJumpTable *JumpTable : JumpTables) { |
| 676 | SizeT NumTargets = JumpTable->getNumTargets(); |
| 677 | JumpTableData &JT = |
| 678 | Ctx->addJumpTable(MangledName, JumpTable->getId(), NumTargets); |
| 679 | for (SizeT I = 0; I < NumTargets; ++I) { |
| 680 | SizeT Index = JumpTable->getTarget(I)->getIndex(); |
Jan Voung | c2ec581 | 2015-08-05 09:35:18 -0700 | [diff] [blame] | 681 | JT.pushTarget(getAssembler()->getCfgNodeLabel(Index)->getPosition()); |
Andrew Scull | 86df4e9 | 2015-07-30 13:54:44 -0700 | [diff] [blame] | 682 | } |
| 683 | } |
| 684 | } break; |
| 685 | case FT_Asm: { |
| 686 | // Emit the assembly directly so we don't need to hang on to all the names |
| 687 | for (const InstJumpTable *JumpTable : JumpTables) |
| 688 | getTarget()->emitJumpTable(this, JumpTable); |
| 689 | } break; |
Andrew Scull | 86df4e9 | 2015-07-30 13:54:44 -0700 | [diff] [blame] | 690 | } |
| 691 | } |
| 692 | |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 693 | void Cfg::emit() { |
Jim Stichnoth | 20b71f5 | 2015-06-24 15:52:24 -0700 | [diff] [blame] | 694 | if (!BuildDefs::dump()) |
Karl Schimpf | b6c96af | 2014-11-17 10:58:39 -0800 | [diff] [blame] | 695 | return; |
Jim Stichnoth | 8363a06 | 2014-10-07 10:02:38 -0700 | [diff] [blame] | 696 | TimerMarker T(TimerStack::TT_emit, this); |
Karl Schimpf | df80eb8 | 2015-02-09 14:20:22 -0800 | [diff] [blame] | 697 | if (Ctx->getFlags().getDecorateAsm()) { |
Jim Stichnoth | 3d44fe8 | 2014-11-01 10:10:18 -0700 | [diff] [blame] | 698 | renumberInstructions(); |
| 699 | getVMetadata()->init(VMK_Uses); |
| 700 | liveness(Liveness_Basic); |
| 701 | dump("After recomputing liveness for -decorate-asm"); |
| 702 | } |
Jim Stichnoth | e4a8f40 | 2015-01-20 12:52:51 -0800 | [diff] [blame] | 703 | OstreamLocker L(Ctx); |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 704 | Ostream &Str = Ctx->getStrEmit(); |
Andrew Scull | 86df4e9 | 2015-07-30 13:54:44 -0700 | [diff] [blame] | 705 | IceString MangledName = Ctx->mangleName(getFunctionName()); |
| 706 | const Assembler *Asm = getAssembler<>(); |
| 707 | const bool NeedSandboxing = Ctx->getFlags().getUseSandboxing(); |
| 708 | |
| 709 | emitTextHeader(MangledName, Ctx, Asm); |
| 710 | deleteJumpTableInsts(); |
| 711 | for (CfgNode *Node : Nodes) { |
| 712 | if (NeedSandboxing && Node->needsAlignment()) { |
| 713 | Str << "\t" << Asm->getAlignDirective() << " " |
| 714 | << Asm->getBundleAlignLog2Bytes() << "\n"; |
| 715 | } |
Jim Stichnoth | f44f371 | 2014-10-01 14:05:51 -0700 | [diff] [blame] | 716 | Node->emit(this); |
Andrew Scull | 86df4e9 | 2015-07-30 13:54:44 -0700 | [diff] [blame] | 717 | } |
| 718 | emitJumpTables(); |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 719 | Str << "\n"; |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 720 | } |
| 721 | |
Jan Voung | 0faec4c | 2014-11-05 17:29:56 -0800 | [diff] [blame] | 722 | void Cfg::emitIAS() { |
| 723 | TimerMarker T(TimerStack::TT_emit, this); |
Andrew Scull | 57e1268 | 2015-09-16 11:30:19 -0700 | [diff] [blame] | 724 | // The emitIAS() routines emit into the internal assembler buffer, so there's |
| 725 | // no need to lock the streams. |
Andrew Scull | 86df4e9 | 2015-07-30 13:54:44 -0700 | [diff] [blame] | 726 | deleteJumpTableInsts(); |
| 727 | const bool NeedSandboxing = Ctx->getFlags().getUseSandboxing(); |
| 728 | for (CfgNode *Node : Nodes) { |
| 729 | if (NeedSandboxing && Node->needsAlignment()) |
| 730 | getAssembler()->alignCfgNode(); |
Jan Voung | 0faec4c | 2014-11-05 17:29:56 -0800 | [diff] [blame] | 731 | Node->emitIAS(this); |
Andrew Scull | 86df4e9 | 2015-07-30 13:54:44 -0700 | [diff] [blame] | 732 | } |
| 733 | emitJumpTables(); |
Jan Voung | 0faec4c | 2014-11-05 17:29:56 -0800 | [diff] [blame] | 734 | } |
| 735 | |
Jim Stichnoth | d97c7df | 2014-06-04 11:57:08 -0700 | [diff] [blame] | 736 | // Dumps the IR with an optional introductory message. |
| 737 | void Cfg::dump(const IceString &Message) { |
Jim Stichnoth | 20b71f5 | 2015-06-24 15:52:24 -0700 | [diff] [blame] | 738 | if (!BuildDefs::dump()) |
Karl Schimpf | b6c96af | 2014-11-17 10:58:39 -0800 | [diff] [blame] | 739 | return; |
Jim Stichnoth | fa4efea | 2015-01-27 05:06:03 -0800 | [diff] [blame] | 740 | if (!isVerbose()) |
Jim Stichnoth | d97c7df | 2014-06-04 11:57:08 -0700 | [diff] [blame] | 741 | return; |
Jim Stichnoth | e4a8f40 | 2015-01-20 12:52:51 -0800 | [diff] [blame] | 742 | OstreamLocker L(Ctx); |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 743 | Ostream &Str = Ctx->getStrDump(); |
Jim Stichnoth | d97c7df | 2014-06-04 11:57:08 -0700 | [diff] [blame] | 744 | if (!Message.empty()) |
| 745 | Str << "================ " << Message << " ================\n"; |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 746 | setCurrentNode(getEntryNode()); |
| 747 | // Print function name+args |
Jim Stichnoth | fa4efea | 2015-01-27 05:06:03 -0800 | [diff] [blame] | 748 | if (isVerbose(IceV_Instructions)) { |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 749 | Str << "define "; |
Karl Schimpf | df80eb8 | 2015-02-09 14:20:22 -0800 | [diff] [blame] | 750 | if (getInternal() && !Ctx->getFlags().getDisableInternal()) |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 751 | Str << "internal "; |
Karl Schimpf | df6f9d1 | 2014-10-20 14:09:00 -0700 | [diff] [blame] | 752 | Str << ReturnType << " @" << Ctx->mangleName(getFunctionName()) << "("; |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 753 | for (SizeT i = 0; i < Args.size(); ++i) { |
| 754 | if (i > 0) |
| 755 | Str << ", "; |
| 756 | Str << Args[i]->getType() << " "; |
| 757 | Args[i]->dump(this); |
| 758 | } |
| 759 | Str << ") {\n"; |
| 760 | } |
Jim Stichnoth | 800dab2 | 2014-09-20 12:25:02 -0700 | [diff] [blame] | 761 | resetCurrentNode(); |
Jim Stichnoth | fa4efea | 2015-01-27 05:06:03 -0800 | [diff] [blame] | 762 | if (isVerbose(IceV_Liveness)) { |
Jim Stichnoth | d97c7df | 2014-06-04 11:57:08 -0700 | [diff] [blame] | 763 | // Print summary info about variables |
Jim Stichnoth | f44f371 | 2014-10-01 14:05:51 -0700 | [diff] [blame] | 764 | for (Variable *Var : Variables) { |
Jim Stichnoth | 144cdce | 2014-09-22 16:02:59 -0700 | [diff] [blame] | 765 | Str << "// multiblock="; |
| 766 | if (getVMetadata()->isTracked(Var)) |
| 767 | Str << getVMetadata()->isMultiBlock(Var); |
| 768 | else |
| 769 | Str << "?"; |
Andrew Scull | 11c9a32 | 2015-08-28 14:24:14 -0700 | [diff] [blame] | 770 | Str << " weight=" << Var->getWeight(this) << " "; |
Jim Stichnoth | d97c7df | 2014-06-04 11:57:08 -0700 | [diff] [blame] | 771 | Var->dump(this); |
| 772 | Str << " LIVE=" << Var->getLiveRange() << "\n"; |
| 773 | } |
| 774 | } |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 775 | // Print each basic block |
Jim Stichnoth | f44f371 | 2014-10-01 14:05:51 -0700 | [diff] [blame] | 776 | for (CfgNode *Node : Nodes) |
| 777 | Node->dump(this); |
Jim Stichnoth | fa4efea | 2015-01-27 05:06:03 -0800 | [diff] [blame] | 778 | if (isVerbose(IceV_Instructions)) |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 779 | Str << "}\n"; |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 780 | } |
| 781 | |
| 782 | } // end of namespace Ice |