blob: 69c6f4e62eaf14845a02236bd7f5350b6f7dd9f5 [file] [log] [blame]
Chris Lattner21ab22e2004-07-31 10:01:27 +00001//===-- BranchFolding.cpp - Fold machine code branch instructions ---------===//
Misha Brukmanedf128a2005-04-21 22:36:52 +00002//
Chris Lattner21ab22e2004-07-31 10:01:27 +00003// The LLVM Compiler Infrastructure
4//
5// This file was developed by the LLVM research group and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
Misha Brukmanedf128a2005-04-21 22:36:52 +00007//
Chris Lattner21ab22e2004-07-31 10:01:27 +00008//===----------------------------------------------------------------------===//
9//
10// This pass forwards branches to unconditional branches to make them branch
11// directly to the target block. This pass often results in dead MBB's, which
12// it then removes.
13//
14// Note that this pass must be run after register allocation, it cannot handle
15// SSA form.
16//
17//===----------------------------------------------------------------------===//
18
Chris Lattnerf10a56a2006-11-18 21:56:39 +000019#define DEBUG_TYPE "branchfolding"
Chris Lattner21ab22e2004-07-31 10:01:27 +000020#include "llvm/CodeGen/Passes.h"
Chris Lattner683747a2006-10-17 23:17:27 +000021#include "llvm/CodeGen/MachineDebugInfo.h"
Chris Lattner21ab22e2004-07-31 10:01:27 +000022#include "llvm/CodeGen/MachineFunctionPass.h"
Chris Lattnerc50ffcb2006-10-17 17:13:52 +000023#include "llvm/CodeGen/MachineJumpTableInfo.h"
Chris Lattner21ab22e2004-07-31 10:01:27 +000024#include "llvm/Target/TargetInstrInfo.h"
25#include "llvm/Target/TargetMachine.h"
Chris Lattner12143052006-10-21 00:47:49 +000026#include "llvm/Support/CommandLine.h"
Chris Lattnerf10a56a2006-11-18 21:56:39 +000027#include "llvm/Support/Debug.h"
Chris Lattner12143052006-10-21 00:47:49 +000028#include "llvm/ADT/Statistic.h"
Reid Spencer551ccae2004-09-01 22:55:40 +000029#include "llvm/ADT/STLExtras.h"
Jeff Cohend41b30d2006-11-05 19:31:28 +000030#include <algorithm>
Chris Lattner21ab22e2004-07-31 10:01:27 +000031using namespace llvm;
32
Chris Lattnercd3245a2006-12-19 22:41:21 +000033STATISTIC(NumDeadBlocks, "Number of dead blocks removed");
34STATISTIC(NumBranchOpts, "Number of branches optimized");
35STATISTIC(NumTailMerge , "Number of block tails merged");
Chris Lattnerd8ccff02006-11-01 00:38:31 +000036static cl::opt<bool> EnableTailMerge("enable-tail-merge", cl::Hidden);
Chris Lattner12143052006-10-21 00:47:49 +000037
Chris Lattner21ab22e2004-07-31 10:01:27 +000038namespace {
39 struct BranchFolder : public MachineFunctionPass {
40 virtual bool runOnMachineFunction(MachineFunction &MF);
Chris Lattner7821a8a2006-10-14 00:21:48 +000041 virtual const char *getPassName() const { return "Control Flow Optimizer"; }
42 const TargetInstrInfo *TII;
Chris Lattner683747a2006-10-17 23:17:27 +000043 MachineDebugInfo *MDI;
Chris Lattner7821a8a2006-10-14 00:21:48 +000044 bool MadeChange;
Chris Lattner21ab22e2004-07-31 10:01:27 +000045 private:
Chris Lattner12143052006-10-21 00:47:49 +000046 // Tail Merging.
47 bool TailMergeBlocks(MachineFunction &MF);
48 void ReplaceTailWithBranchTo(MachineBasicBlock::iterator OldInst,
49 MachineBasicBlock *NewDest);
Chris Lattner1d08d832006-11-01 01:16:12 +000050 MachineBasicBlock *SplitMBBAt(MachineBasicBlock &CurMBB,
51 MachineBasicBlock::iterator BBI1);
52
Chris Lattner12143052006-10-21 00:47:49 +000053 // Branch optzn.
54 bool OptimizeBranches(MachineFunction &MF);
Chris Lattner7d097842006-10-24 01:12:32 +000055 void OptimizeBlock(MachineBasicBlock *MBB);
Chris Lattner683747a2006-10-17 23:17:27 +000056 void RemoveDeadBlock(MachineBasicBlock *MBB);
Chris Lattner6b0e3f82006-10-29 21:05:41 +000057
58 bool CanFallThrough(MachineBasicBlock *CurBB);
59 bool CanFallThrough(MachineBasicBlock *CurBB, bool BranchUnAnalyzable,
60 MachineBasicBlock *TBB, MachineBasicBlock *FBB,
61 const std::vector<MachineOperand> &Cond);
Chris Lattner21ab22e2004-07-31 10:01:27 +000062 };
63}
64
65FunctionPass *llvm::createBranchFoldingPass() { return new BranchFolder(); }
66
Chris Lattnerc50ffcb2006-10-17 17:13:52 +000067/// RemoveDeadBlock - Remove the specified dead machine basic block from the
68/// function, updating the CFG.
Chris Lattner683747a2006-10-17 23:17:27 +000069void BranchFolder::RemoveDeadBlock(MachineBasicBlock *MBB) {
Chris Lattnerc50ffcb2006-10-17 17:13:52 +000070 assert(MBB->pred_empty() && "MBB must be dead!");
Chris Lattner683747a2006-10-17 23:17:27 +000071
Chris Lattnerc50ffcb2006-10-17 17:13:52 +000072 MachineFunction *MF = MBB->getParent();
73 // drop all successors.
74 while (!MBB->succ_empty())
75 MBB->removeSuccessor(MBB->succ_end()-1);
Chris Lattner683747a2006-10-17 23:17:27 +000076
77 // If there is DWARF info to active, check to see if there are any DWARF_LABEL
78 // records in the basic block. If so, unregister them from MachineDebugInfo.
79 if (MDI && !MBB->empty()) {
80 unsigned DWARF_LABELOpc = TII->getDWARF_LABELOpcode();
81 assert(DWARF_LABELOpc &&
82 "Target supports dwarf but didn't implement getDWARF_LABELOpcode!");
83
84 for (MachineBasicBlock::iterator I = MBB->begin(), E = MBB->end();
85 I != E; ++I) {
86 if ((unsigned)I->getOpcode() == DWARF_LABELOpc) {
87 // The label ID # is always operand #0, an immediate.
Jim Laskey66ebf092006-10-23 14:56:37 +000088 MDI->InvalidateLabel(I->getOperand(0).getImm());
Chris Lattner683747a2006-10-17 23:17:27 +000089 }
90 }
91 }
92
Chris Lattnerc50ffcb2006-10-17 17:13:52 +000093 // Remove the block.
94 MF->getBasicBlockList().erase(MBB);
95}
96
Chris Lattner21ab22e2004-07-31 10:01:27 +000097bool BranchFolder::runOnMachineFunction(MachineFunction &MF) {
Chris Lattner7821a8a2006-10-14 00:21:48 +000098 TII = MF.getTarget().getInstrInfo();
99 if (!TII) return false;
100
Chris Lattner683747a2006-10-17 23:17:27 +0000101 MDI = getAnalysisToUpdate<MachineDebugInfo>();
Chris Lattner7821a8a2006-10-14 00:21:48 +0000102
Chris Lattner21ab22e2004-07-31 10:01:27 +0000103 bool EverMadeChange = false;
Chris Lattner12143052006-10-21 00:47:49 +0000104 bool MadeChangeThisIteration = true;
105 while (MadeChangeThisIteration) {
106 MadeChangeThisIteration = false;
107 MadeChangeThisIteration |= TailMergeBlocks(MF);
108 MadeChangeThisIteration |= OptimizeBranches(MF);
109 EverMadeChange |= MadeChangeThisIteration;
Chris Lattner21ab22e2004-07-31 10:01:27 +0000110 }
111
Chris Lattner6acfe122006-10-28 18:34:47 +0000112 // See if any jump tables have become mergable or dead as the code generator
113 // did its thing.
114 MachineJumpTableInfo *JTI = MF.getJumpTableInfo();
115 const std::vector<MachineJumpTableEntry> &JTs = JTI->getJumpTables();
116 if (!JTs.empty()) {
117 // Figure out how these jump tables should be merged.
118 std::vector<unsigned> JTMapping;
119 JTMapping.reserve(JTs.size());
120
121 // We always keep the 0th jump table.
122 JTMapping.push_back(0);
123
124 // Scan the jump tables, seeing if there are any duplicates. Note that this
125 // is N^2, which should be fixed someday.
126 for (unsigned i = 1, e = JTs.size(); i != e; ++i)
127 JTMapping.push_back(JTI->getJumpTableIndex(JTs[i].MBBs));
128
129 // If a jump table was merge with another one, walk the function rewriting
130 // references to jump tables to reference the new JT ID's. Keep track of
131 // whether we see a jump table idx, if not, we can delete the JT.
132 std::vector<bool> JTIsLive;
133 JTIsLive.resize(JTs.size());
134 for (MachineFunction::iterator BB = MF.begin(), E = MF.end();
135 BB != E; ++BB) {
136 for (MachineBasicBlock::iterator I = BB->begin(), E = BB->end();
137 I != E; ++I)
138 for (unsigned op = 0, e = I->getNumOperands(); op != e; ++op) {
139 MachineOperand &Op = I->getOperand(op);
140 if (!Op.isJumpTableIndex()) continue;
141 unsigned NewIdx = JTMapping[Op.getJumpTableIndex()];
142 Op.setJumpTableIndex(NewIdx);
143
144 // Remember that this JT is live.
145 JTIsLive[NewIdx] = true;
146 }
147 }
148
149 // Finally, remove dead jump tables. This happens either because the
150 // indirect jump was unreachable (and thus deleted) or because the jump
151 // table was merged with some other one.
152 for (unsigned i = 0, e = JTIsLive.size(); i != e; ++i)
153 if (!JTIsLive[i]) {
154 JTI->RemoveJumpTable(i);
155 EverMadeChange = true;
156 }
157 }
158
Chris Lattner21ab22e2004-07-31 10:01:27 +0000159 return EverMadeChange;
160}
161
Chris Lattner12143052006-10-21 00:47:49 +0000162//===----------------------------------------------------------------------===//
163// Tail Merging of Blocks
164//===----------------------------------------------------------------------===//
165
166/// HashMachineInstr - Compute a hash value for MI and its operands.
167static unsigned HashMachineInstr(const MachineInstr *MI) {
168 unsigned Hash = MI->getOpcode();
169 for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
170 const MachineOperand &Op = MI->getOperand(i);
171
172 // Merge in bits from the operand if easy.
173 unsigned OperandHash = 0;
174 switch (Op.getType()) {
175 case MachineOperand::MO_Register: OperandHash = Op.getReg(); break;
176 case MachineOperand::MO_Immediate: OperandHash = Op.getImm(); break;
177 case MachineOperand::MO_MachineBasicBlock:
178 OperandHash = Op.getMachineBasicBlock()->getNumber();
179 break;
180 case MachineOperand::MO_FrameIndex: OperandHash = Op.getFrameIndex(); break;
181 case MachineOperand::MO_ConstantPoolIndex:
182 OperandHash = Op.getConstantPoolIndex();
183 break;
184 case MachineOperand::MO_JumpTableIndex:
185 OperandHash = Op.getJumpTableIndex();
186 break;
187 case MachineOperand::MO_GlobalAddress:
188 case MachineOperand::MO_ExternalSymbol:
189 // Global address / external symbol are too hard, don't bother, but do
190 // pull in the offset.
191 OperandHash = Op.getOffset();
192 break;
193 default: break;
194 }
195
196 Hash += ((OperandHash << 3) | Op.getType()) << (i&31);
197 }
198 return Hash;
199}
200
201/// HashEndOfMBB - Hash the last two instructions in the MBB. We hash two
202/// instructions, because cross-jumping only saves code when at least two
203/// instructions are removed (since a branch must be inserted).
204static unsigned HashEndOfMBB(const MachineBasicBlock *MBB) {
205 MachineBasicBlock::const_iterator I = MBB->end();
206 if (I == MBB->begin())
207 return 0; // Empty MBB.
208
209 --I;
210 unsigned Hash = HashMachineInstr(I);
211
212 if (I == MBB->begin())
213 return Hash; // Single instr MBB.
214
215 --I;
216 // Hash in the second-to-last instruction.
217 Hash ^= HashMachineInstr(I) << 2;
218 return Hash;
219}
220
221/// ComputeCommonTailLength - Given two machine basic blocks, compute the number
222/// of instructions they actually have in common together at their end. Return
223/// iterators for the first shared instruction in each block.
224static unsigned ComputeCommonTailLength(MachineBasicBlock *MBB1,
225 MachineBasicBlock *MBB2,
226 MachineBasicBlock::iterator &I1,
227 MachineBasicBlock::iterator &I2) {
228 I1 = MBB1->end();
229 I2 = MBB2->end();
230
231 unsigned TailLen = 0;
232 while (I1 != MBB1->begin() && I2 != MBB2->begin()) {
233 --I1; --I2;
234 if (!I1->isIdenticalTo(I2)) {
235 ++I1; ++I2;
236 break;
237 }
238 ++TailLen;
239 }
240 return TailLen;
241}
242
243/// ReplaceTailWithBranchTo - Delete the instruction OldInst and everything
Chris Lattner386e2902006-10-21 05:08:28 +0000244/// after it, replacing it with an unconditional branch to NewDest. This
245/// returns true if OldInst's block is modified, false if NewDest is modified.
Chris Lattner12143052006-10-21 00:47:49 +0000246void BranchFolder::ReplaceTailWithBranchTo(MachineBasicBlock::iterator OldInst,
247 MachineBasicBlock *NewDest) {
248 MachineBasicBlock *OldBB = OldInst->getParent();
249
250 // Remove all the old successors of OldBB from the CFG.
251 while (!OldBB->succ_empty())
252 OldBB->removeSuccessor(OldBB->succ_begin());
253
254 // Remove all the dead instructions from the end of OldBB.
255 OldBB->erase(OldInst, OldBB->end());
256
Chris Lattner386e2902006-10-21 05:08:28 +0000257 // If OldBB isn't immediately before OldBB, insert a branch to it.
258 if (++MachineFunction::iterator(OldBB) != MachineFunction::iterator(NewDest))
259 TII->InsertBranch(*OldBB, NewDest, 0, std::vector<MachineOperand>());
Chris Lattner12143052006-10-21 00:47:49 +0000260 OldBB->addSuccessor(NewDest);
261 ++NumTailMerge;
262}
263
Chris Lattner1d08d832006-11-01 01:16:12 +0000264/// SplitMBBAt - Given a machine basic block and an iterator into it, split the
265/// MBB so that the part before the iterator falls into the part starting at the
266/// iterator. This returns the new MBB.
267MachineBasicBlock *BranchFolder::SplitMBBAt(MachineBasicBlock &CurMBB,
268 MachineBasicBlock::iterator BBI1) {
269 // Create the fall-through block.
270 MachineFunction::iterator MBBI = &CurMBB;
271 MachineBasicBlock *NewMBB = new MachineBasicBlock(CurMBB.getBasicBlock());
272 CurMBB.getParent()->getBasicBlockList().insert(++MBBI, NewMBB);
273
274 // Move all the successors of this block to the specified block.
275 while (!CurMBB.succ_empty()) {
276 MachineBasicBlock *S = *(CurMBB.succ_end()-1);
277 NewMBB->addSuccessor(S);
278 CurMBB.removeSuccessor(S);
279 }
280
281 // Add an edge from CurMBB to NewMBB for the fall-through.
282 CurMBB.addSuccessor(NewMBB);
283
284 // Splice the code over.
285 NewMBB->splice(NewMBB->end(), &CurMBB, BBI1, CurMBB.end());
286 return NewMBB;
287}
288
Chris Lattnerd4bf3c22006-11-01 19:36:29 +0000289/// EstimateRuntime - Make a rough estimate for how long it will take to run
290/// the specified code.
291static unsigned EstimateRuntime(MachineBasicBlock::iterator I,
292 MachineBasicBlock::iterator E,
293 const TargetInstrInfo *TII) {
294 unsigned Time = 0;
295 for (; I != E; ++I) {
296 const TargetInstrDescriptor &TID = TII->get(I->getOpcode());
297 if (TID.Flags & M_CALL_FLAG)
298 Time += 10;
299 else if (TID.Flags & (M_LOAD_FLAG|M_STORE_FLAG))
300 Time += 2;
301 else
302 ++Time;
303 }
304 return Time;
305}
306
307/// ShouldSplitFirstBlock - We need to either split MBB1 at MBB1I or MBB2 at
308/// MBB2I and then insert an unconditional branch in the other block. Determine
309/// which is the best to split
310static bool ShouldSplitFirstBlock(MachineBasicBlock *MBB1,
311 MachineBasicBlock::iterator MBB1I,
312 MachineBasicBlock *MBB2,
313 MachineBasicBlock::iterator MBB2I,
314 const TargetInstrInfo *TII) {
315 // TODO: if we had some notion of which block was hotter, we could split
316 // the hot block, so it is the fall-through. Since we don't have profile info
317 // make a decision based on which will hurt most to split.
318 unsigned MBB1Time = EstimateRuntime(MBB1->begin(), MBB1I, TII);
319 unsigned MBB2Time = EstimateRuntime(MBB2->begin(), MBB2I, TII);
320
321 // If the MBB1 prefix takes "less time" to run than the MBB2 prefix, split the
322 // MBB1 block so it falls through. This will penalize the MBB2 path, but will
323 // have a lower overall impact on the program execution.
324 return MBB1Time < MBB2Time;
325}
326
Chris Lattner12143052006-10-21 00:47:49 +0000327bool BranchFolder::TailMergeBlocks(MachineFunction &MF) {
328 MadeChange = false;
329
Chris Lattnerd8ccff02006-11-01 00:38:31 +0000330 if (!EnableTailMerge) return false;
Chris Lattner323ece62006-10-25 18:08:50 +0000331
Chris Lattner12143052006-10-21 00:47:49 +0000332 // Find blocks with no successors.
333 std::vector<std::pair<unsigned,MachineBasicBlock*> > MergePotentials;
334 for (MachineFunction::iterator I = MF.begin(), E = MF.end(); I != E; ++I) {
335 if (I->succ_empty())
336 MergePotentials.push_back(std::make_pair(HashEndOfMBB(I), I));
337 }
338
339 // Sort by hash value so that blocks with identical end sequences sort
340 // together.
341 std::stable_sort(MergePotentials.begin(), MergePotentials.end());
342
343 // Walk through equivalence sets looking for actual exact matches.
344 while (MergePotentials.size() > 1) {
345 unsigned CurHash = (MergePotentials.end()-1)->first;
346 unsigned PrevHash = (MergePotentials.end()-2)->first;
347 MachineBasicBlock *CurMBB = (MergePotentials.end()-1)->second;
348
349 // If there is nothing that matches the hash of the current basic block,
350 // give up.
351 if (CurHash != PrevHash) {
352 MergePotentials.pop_back();
353 continue;
354 }
355
356 // Determine the actual length of the shared tail between these two basic
357 // blocks. Because the hash can have collisions, it's possible that this is
358 // less than 2.
359 MachineBasicBlock::iterator BBI1, BBI2;
360 unsigned CommonTailLen =
361 ComputeCommonTailLength(CurMBB, (MergePotentials.end()-2)->second,
362 BBI1, BBI2);
363
364 // If the tails don't have at least two instructions in common, see if there
365 // is anything else in the equivalence class that does match.
366 if (CommonTailLen < 2) {
367 unsigned FoundMatch = ~0U;
368 for (int i = MergePotentials.size()-2;
369 i != -1 && MergePotentials[i].first == CurHash; --i) {
370 CommonTailLen = ComputeCommonTailLength(CurMBB,
371 MergePotentials[i].second,
372 BBI1, BBI2);
373 if (CommonTailLen >= 2) {
374 FoundMatch = i;
375 break;
376 }
377 }
378
379 // If we didn't find anything that has at least two instructions matching
380 // this one, bail out.
381 if (FoundMatch == ~0U) {
382 MergePotentials.pop_back();
383 continue;
384 }
385
386 // Otherwise, move the matching block to the right position.
387 std::swap(MergePotentials[FoundMatch], *(MergePotentials.end()-2));
388 }
Chris Lattner1d08d832006-11-01 01:16:12 +0000389
Chris Lattner12143052006-10-21 00:47:49 +0000390 MachineBasicBlock *MBB2 = (MergePotentials.end()-2)->second;
Chris Lattner1d08d832006-11-01 01:16:12 +0000391
392 // If neither block is the entire common tail, split the tail of one block
393 // to make it redundant with the other tail.
394 if (CurMBB->begin() != BBI1 && MBB2->begin() != BBI2) {
395 if (0) { // Enable this to disable partial tail merges.
396 MergePotentials.pop_back();
397 continue;
398 }
Chris Lattnerd4bf3c22006-11-01 19:36:29 +0000399
400 // Decide whether we want to split CurMBB or MBB2.
401 if (ShouldSplitFirstBlock(CurMBB, BBI1, MBB2, BBI2, TII)) {
402 CurMBB = SplitMBBAt(*CurMBB, BBI1);
403 BBI1 = CurMBB->begin();
404 MergePotentials.back().second = CurMBB;
405 } else {
406 MBB2 = SplitMBBAt(*MBB2, BBI2);
407 BBI2 = MBB2->begin();
408 (MergePotentials.end()-2)->second = MBB2;
409 }
Chris Lattner1d08d832006-11-01 01:16:12 +0000410 }
411
412 if (MBB2->begin() == BBI2) {
Chris Lattner12143052006-10-21 00:47:49 +0000413 // Hack the end off CurMBB, making it jump to MBBI@ instead.
414 ReplaceTailWithBranchTo(BBI1, MBB2);
415 // This modifies CurMBB, so remove it from the worklist.
416 MergePotentials.pop_back();
Chris Lattner1d08d832006-11-01 01:16:12 +0000417 } else {
418 assert(CurMBB->begin() == BBI1 && "Didn't split block correctly?");
419 // Hack the end off MBB2, making it jump to CurMBB instead.
420 ReplaceTailWithBranchTo(BBI2, CurMBB);
421 // This modifies MBB2, so remove it from the worklist.
422 MergePotentials.erase(MergePotentials.end()-2);
Chris Lattner12143052006-10-21 00:47:49 +0000423 }
Chris Lattner1d08d832006-11-01 01:16:12 +0000424 MadeChange = true;
Chris Lattner12143052006-10-21 00:47:49 +0000425 }
426
427 return MadeChange;
428}
429
430
431//===----------------------------------------------------------------------===//
432// Branch Optimization
433//===----------------------------------------------------------------------===//
434
435bool BranchFolder::OptimizeBranches(MachineFunction &MF) {
436 MadeChange = false;
437
438 for (MachineFunction::iterator I = ++MF.begin(), E = MF.end(); I != E; ) {
439 MachineBasicBlock *MBB = I++;
440 OptimizeBlock(MBB);
441
442 // If it is dead, remove it.
443 if (MBB->pred_empty()) {
444 RemoveDeadBlock(MBB);
445 MadeChange = true;
446 ++NumDeadBlocks;
447 }
448 }
449 return MadeChange;
450}
451
452
Chris Lattner386e2902006-10-21 05:08:28 +0000453/// CorrectExtraCFGEdges - Various pieces of code can cause excess edges in the
454/// CFG to be inserted. If we have proven that MBB can only branch to DestA and
455/// DestB, remove any other MBB successors from the CFG. DestA and DestB can
456/// be null.
457static bool CorrectExtraCFGEdges(MachineBasicBlock &MBB,
458 MachineBasicBlock *DestA,
459 MachineBasicBlock *DestB,
460 bool isCond,
461 MachineFunction::iterator FallThru) {
462 bool MadeChange = false;
463 bool AddedFallThrough = false;
464
465 // If this block ends with a conditional branch that falls through to its
466 // successor, set DestB as the successor.
467 if (isCond) {
468 if (DestB == 0 && FallThru != MBB.getParent()->end()) {
469 DestB = FallThru;
470 AddedFallThrough = true;
471 }
472 } else {
473 // If this is an unconditional branch with no explicit dest, it must just be
474 // a fallthrough into DestB.
475 if (DestA == 0 && FallThru != MBB.getParent()->end()) {
476 DestA = FallThru;
477 AddedFallThrough = true;
478 }
479 }
480
481 MachineBasicBlock::pred_iterator SI = MBB.succ_begin();
482 while (SI != MBB.succ_end()) {
483 if (*SI == DestA) {
484 DestA = 0;
485 ++SI;
486 } else if (*SI == DestB) {
487 DestB = 0;
488 ++SI;
489 } else {
490 // Otherwise, this is a superfluous edge, remove it.
491 MBB.removeSuccessor(SI);
492 MadeChange = true;
493 }
494 }
495 if (!AddedFallThrough) {
496 assert(DestA == 0 && DestB == 0 &&
497 "MachineCFG is missing edges!");
498 } else if (isCond) {
499 assert(DestA == 0 && "MachineCFG is missing edges!");
500 }
501 return MadeChange;
502}
503
504
Chris Lattner21ab22e2004-07-31 10:01:27 +0000505/// ReplaceUsesOfBlockWith - Given a machine basic block 'BB' that branched to
506/// 'Old', change the code and CFG so that it branches to 'New' instead.
507static void ReplaceUsesOfBlockWith(MachineBasicBlock *BB,
508 MachineBasicBlock *Old,
509 MachineBasicBlock *New,
Chris Lattner7821a8a2006-10-14 00:21:48 +0000510 const TargetInstrInfo *TII) {
Chris Lattner21ab22e2004-07-31 10:01:27 +0000511 assert(Old != New && "Cannot replace self with self!");
512
513 MachineBasicBlock::iterator I = BB->end();
514 while (I != BB->begin()) {
515 --I;
Chris Lattner7821a8a2006-10-14 00:21:48 +0000516 if (!TII->isTerminatorInstr(I->getOpcode())) break;
Chris Lattner21ab22e2004-07-31 10:01:27 +0000517
518 // Scan the operands of this machine instruction, replacing any uses of Old
519 // with New.
520 for (unsigned i = 0, e = I->getNumOperands(); i != e; ++i)
521 if (I->getOperand(i).isMachineBasicBlock() &&
522 I->getOperand(i).getMachineBasicBlock() == Old)
523 I->getOperand(i).setMachineBasicBlock(New);
524 }
525
Chris Lattnereb15eee2006-10-13 20:43:10 +0000526 // Update the successor information.
Chris Lattner21ab22e2004-07-31 10:01:27 +0000527 std::vector<MachineBasicBlock*> Succs(BB->succ_begin(), BB->succ_end());
528 for (int i = Succs.size()-1; i >= 0; --i)
529 if (Succs[i] == Old) {
530 BB->removeSuccessor(Old);
531 BB->addSuccessor(New);
532 }
533}
534
Chris Lattner6b0e3f82006-10-29 21:05:41 +0000535/// CanFallThrough - Return true if the specified block (with the specified
536/// branch condition) can implicitly transfer control to the block after it by
537/// falling off the end of it. This should return false if it can reach the
538/// block after it, but it uses an explicit branch to do so (e.g. a table jump).
539///
540/// True is a conservative answer.
541///
542bool BranchFolder::CanFallThrough(MachineBasicBlock *CurBB,
543 bool BranchUnAnalyzable,
544 MachineBasicBlock *TBB, MachineBasicBlock *FBB,
545 const std::vector<MachineOperand> &Cond) {
546 MachineFunction::iterator Fallthrough = CurBB;
547 ++Fallthrough;
548 // If FallthroughBlock is off the end of the function, it can't fall through.
549 if (Fallthrough == CurBB->getParent()->end())
550 return false;
551
552 // If FallthroughBlock isn't a successor of CurBB, no fallthrough is possible.
553 if (!CurBB->isSuccessor(Fallthrough))
554 return false;
555
556 // If we couldn't analyze the branch, assume it could fall through.
557 if (BranchUnAnalyzable) return true;
558
Chris Lattner7d097842006-10-24 01:12:32 +0000559 // If there is no branch, control always falls through.
560 if (TBB == 0) return true;
561
562 // If there is some explicit branch to the fallthrough block, it can obviously
563 // reach, even though the branch should get folded to fall through implicitly.
Chris Lattner6b0e3f82006-10-29 21:05:41 +0000564 if (MachineFunction::iterator(TBB) == Fallthrough ||
565 MachineFunction::iterator(FBB) == Fallthrough)
Chris Lattner7d097842006-10-24 01:12:32 +0000566 return true;
567
568 // If it's an unconditional branch to some block not the fall through, it
569 // doesn't fall through.
570 if (Cond.empty()) return false;
571
572 // Otherwise, if it is conditional and has no explicit false block, it falls
573 // through.
Chris Lattnerc2e91e32006-10-25 22:21:37 +0000574 return FBB == 0;
Chris Lattner7d097842006-10-24 01:12:32 +0000575}
576
Chris Lattner6b0e3f82006-10-29 21:05:41 +0000577/// CanFallThrough - Return true if the specified can implicitly transfer
578/// control to the block after it by falling off the end of it. This should
579/// return false if it can reach the block after it, but it uses an explicit
580/// branch to do so (e.g. a table jump).
581///
582/// True is a conservative answer.
583///
584bool BranchFolder::CanFallThrough(MachineBasicBlock *CurBB) {
585 MachineBasicBlock *TBB = 0, *FBB = 0;
586 std::vector<MachineOperand> Cond;
587 bool CurUnAnalyzable = TII->AnalyzeBranch(*CurBB, TBB, FBB, Cond);
588 return CanFallThrough(CurBB, CurUnAnalyzable, TBB, FBB, Cond);
589}
590
Chris Lattnera7bef4a2006-11-18 20:47:54 +0000591/// IsBetterFallthrough - Return true if it would be clearly better to
592/// fall-through to MBB1 than to fall through into MBB2. This has to return
593/// a strict ordering, returning true for both (MBB1,MBB2) and (MBB2,MBB1) will
594/// result in infinite loops.
595static bool IsBetterFallthrough(MachineBasicBlock *MBB1,
596 MachineBasicBlock *MBB2,
597 const TargetInstrInfo &TII) {
Chris Lattner154e1042006-11-18 21:30:35 +0000598 // Right now, we use a simple heuristic. If MBB2 ends with a call, and
599 // MBB1 doesn't, we prefer to fall through into MBB1. This allows us to
Chris Lattnera7bef4a2006-11-18 20:47:54 +0000600 // optimize branches that branch to either a return block or an assert block
601 // into a fallthrough to the return.
602 if (MBB1->empty() || MBB2->empty()) return false;
603
604 MachineInstr *MBB1I = --MBB1->end();
605 MachineInstr *MBB2I = --MBB2->end();
Chris Lattner154e1042006-11-18 21:30:35 +0000606 return TII.isCall(MBB2I->getOpcode()) && !TII.isCall(MBB1I->getOpcode());
Chris Lattnera7bef4a2006-11-18 20:47:54 +0000607}
608
Chris Lattner7821a8a2006-10-14 00:21:48 +0000609/// OptimizeBlock - Analyze and optimize control flow related to the specified
610/// block. This is never called on the entry block.
Chris Lattner7d097842006-10-24 01:12:32 +0000611void BranchFolder::OptimizeBlock(MachineBasicBlock *MBB) {
612 MachineFunction::iterator FallThrough = MBB;
613 ++FallThrough;
614
Chris Lattnereb15eee2006-10-13 20:43:10 +0000615 // If this block is empty, make everyone use its fall-through, not the block
Chris Lattner21ab22e2004-07-31 10:01:27 +0000616 // explicitly.
617 if (MBB->empty()) {
Chris Lattner386e2902006-10-21 05:08:28 +0000618 // Dead block? Leave for cleanup later.
619 if (MBB->pred_empty()) return;
Chris Lattner7821a8a2006-10-14 00:21:48 +0000620
Chris Lattnerc50ffcb2006-10-17 17:13:52 +0000621 if (FallThrough == MBB->getParent()->end()) {
622 // TODO: Simplify preds to not branch here if possible!
623 } else {
624 // Rewrite all predecessors of the old block to go to the fallthrough
625 // instead.
Chris Lattner7821a8a2006-10-14 00:21:48 +0000626 while (!MBB->pred_empty()) {
627 MachineBasicBlock *Pred = *(MBB->pred_end()-1);
628 ReplaceUsesOfBlockWith(Pred, MBB, FallThrough, TII);
629 }
Chris Lattnerc50ffcb2006-10-17 17:13:52 +0000630
631 // If MBB was the target of a jump table, update jump tables to go to the
632 // fallthrough instead.
Chris Lattner6acfe122006-10-28 18:34:47 +0000633 MBB->getParent()->getJumpTableInfo()->
634 ReplaceMBBInJumpTables(MBB, FallThrough);
Chris Lattner7821a8a2006-10-14 00:21:48 +0000635 MadeChange = true;
Chris Lattner21ab22e2004-07-31 10:01:27 +0000636 }
Chris Lattner7821a8a2006-10-14 00:21:48 +0000637 return;
Chris Lattner21ab22e2004-07-31 10:01:27 +0000638 }
639
Chris Lattner7821a8a2006-10-14 00:21:48 +0000640 // Check to see if we can simplify the terminator of the block before this
641 // one.
Chris Lattner7d097842006-10-24 01:12:32 +0000642 MachineBasicBlock &PrevBB = *prior(MachineFunction::iterator(MBB));
Chris Lattnerffddf6b2006-10-17 18:16:40 +0000643
Chris Lattner7821a8a2006-10-14 00:21:48 +0000644 MachineBasicBlock *PriorTBB = 0, *PriorFBB = 0;
645 std::vector<MachineOperand> PriorCond;
Chris Lattner6b0e3f82006-10-29 21:05:41 +0000646 bool PriorUnAnalyzable =
647 TII->AnalyzeBranch(PrevBB, PriorTBB, PriorFBB, PriorCond);
Chris Lattner386e2902006-10-21 05:08:28 +0000648 if (!PriorUnAnalyzable) {
649 // If the CFG for the prior block has extra edges, remove them.
650 MadeChange |= CorrectExtraCFGEdges(PrevBB, PriorTBB, PriorFBB,
651 !PriorCond.empty(), MBB);
652
Chris Lattner7821a8a2006-10-14 00:21:48 +0000653 // If the previous branch is conditional and both conditions go to the same
Chris Lattner2d47bd92006-10-21 05:43:30 +0000654 // destination, remove the branch, replacing it with an unconditional one or
655 // a fall-through.
Chris Lattner7821a8a2006-10-14 00:21:48 +0000656 if (PriorTBB && PriorTBB == PriorFBB) {
Chris Lattner386e2902006-10-21 05:08:28 +0000657 TII->RemoveBranch(PrevBB);
Chris Lattner7821a8a2006-10-14 00:21:48 +0000658 PriorCond.clear();
Chris Lattner7d097842006-10-24 01:12:32 +0000659 if (PriorTBB != MBB)
Chris Lattner386e2902006-10-21 05:08:28 +0000660 TII->InsertBranch(PrevBB, PriorTBB, 0, PriorCond);
Chris Lattner7821a8a2006-10-14 00:21:48 +0000661 MadeChange = true;
Chris Lattner12143052006-10-21 00:47:49 +0000662 ++NumBranchOpts;
Chris Lattner7821a8a2006-10-14 00:21:48 +0000663 return OptimizeBlock(MBB);
664 }
665
666 // If the previous branch *only* branches to *this* block (conditional or
667 // not) remove the branch.
Chris Lattner7d097842006-10-24 01:12:32 +0000668 if (PriorTBB == MBB && PriorFBB == 0) {
Chris Lattner386e2902006-10-21 05:08:28 +0000669 TII->RemoveBranch(PrevBB);
Chris Lattner7821a8a2006-10-14 00:21:48 +0000670 MadeChange = true;
Chris Lattner12143052006-10-21 00:47:49 +0000671 ++NumBranchOpts;
Chris Lattner7821a8a2006-10-14 00:21:48 +0000672 return OptimizeBlock(MBB);
673 }
Chris Lattner2d47bd92006-10-21 05:43:30 +0000674
675 // If the prior block branches somewhere else on the condition and here if
676 // the condition is false, remove the uncond second branch.
Chris Lattner7d097842006-10-24 01:12:32 +0000677 if (PriorFBB == MBB) {
Chris Lattner2d47bd92006-10-21 05:43:30 +0000678 TII->RemoveBranch(PrevBB);
679 TII->InsertBranch(PrevBB, PriorTBB, 0, PriorCond);
680 MadeChange = true;
681 ++NumBranchOpts;
682 return OptimizeBlock(MBB);
683 }
Chris Lattnera2d79952006-10-21 05:54:00 +0000684
685 // If the prior block branches here on true and somewhere else on false, and
686 // if the branch condition is reversible, reverse the branch to create a
687 // fall-through.
Chris Lattner7d097842006-10-24 01:12:32 +0000688 if (PriorTBB == MBB) {
Chris Lattnera2d79952006-10-21 05:54:00 +0000689 std::vector<MachineOperand> NewPriorCond(PriorCond);
690 if (!TII->ReverseBranchCondition(NewPriorCond)) {
691 TII->RemoveBranch(PrevBB);
692 TII->InsertBranch(PrevBB, PriorFBB, 0, NewPriorCond);
693 MadeChange = true;
694 ++NumBranchOpts;
695 return OptimizeBlock(MBB);
696 }
697 }
Chris Lattnera7bef4a2006-11-18 20:47:54 +0000698
Chris Lattner154e1042006-11-18 21:30:35 +0000699 // If this block doesn't fall through (e.g. it ends with an uncond branch or
700 // has no successors) and if the pred falls through into this block, and if
701 // it would otherwise fall through into the block after this, move this
702 // block to the end of the function.
703 //
Chris Lattnera7bef4a2006-11-18 20:47:54 +0000704 // We consider it more likely that execution will stay in the function (e.g.
705 // due to loops) than it is to exit it. This asserts in loops etc, moving
706 // the assert condition out of the loop body.
Chris Lattner154e1042006-11-18 21:30:35 +0000707 if (!PriorCond.empty() && PriorFBB == 0 &&
708 MachineFunction::iterator(PriorTBB) == FallThrough &&
709 !CanFallThrough(MBB)) {
Chris Lattnerf10a56a2006-11-18 21:56:39 +0000710 bool DoTransform = true;
711
Chris Lattnera7bef4a2006-11-18 20:47:54 +0000712 // We have to be careful that the succs of PredBB aren't both no-successor
713 // blocks. If neither have successors and if PredBB is the second from
714 // last block in the function, we'd just keep swapping the two blocks for
715 // last. Only do the swap if one is clearly better to fall through than
716 // the other.
Chris Lattnerf10a56a2006-11-18 21:56:39 +0000717 if (FallThrough == --MBB->getParent()->end() &&
718 !IsBetterFallthrough(PriorTBB, MBB, *TII))
719 DoTransform = false;
720
721 // We don't want to do this transformation if we have control flow like:
722 // br cond BB2
723 // BB1:
724 // ..
725 // jmp BBX
726 // BB2:
727 // ..
728 // ret
729 //
730 // In this case, we could actually be moving the return block *into* a
731 // loop!
Chris Lattner4b105912006-11-18 22:25:39 +0000732 if (DoTransform && !MBB->succ_empty() &&
733 (!CanFallThrough(PriorTBB) || PriorTBB->empty()))
Chris Lattnerf10a56a2006-11-18 21:56:39 +0000734 DoTransform = false;
Chris Lattnera7bef4a2006-11-18 20:47:54 +0000735
Chris Lattnerf10a56a2006-11-18 21:56:39 +0000736
737 if (DoTransform) {
Chris Lattnera7bef4a2006-11-18 20:47:54 +0000738 // Reverse the branch so we will fall through on the previous true cond.
739 std::vector<MachineOperand> NewPriorCond(PriorCond);
740 if (!TII->ReverseBranchCondition(NewPriorCond)) {
Chris Lattnerf10a56a2006-11-18 21:56:39 +0000741 DOUT << "\nMoving MBB: " << *MBB;
742 DOUT << "To make fallthrough to: " << *PriorTBB << "\n";
743
Chris Lattnera7bef4a2006-11-18 20:47:54 +0000744 TII->RemoveBranch(PrevBB);
745 TII->InsertBranch(PrevBB, MBB, 0, NewPriorCond);
746
747 // Move this block to the end of the function.
748 MBB->moveAfter(--MBB->getParent()->end());
749 MadeChange = true;
750 ++NumBranchOpts;
751 return;
752 }
753 }
754 }
Chris Lattner7821a8a2006-10-14 00:21:48 +0000755 }
Chris Lattner7821a8a2006-10-14 00:21:48 +0000756
Chris Lattner386e2902006-10-21 05:08:28 +0000757 // Analyze the branch in the current block.
758 MachineBasicBlock *CurTBB = 0, *CurFBB = 0;
759 std::vector<MachineOperand> CurCond;
Chris Lattner6b0e3f82006-10-29 21:05:41 +0000760 bool CurUnAnalyzable = TII->AnalyzeBranch(*MBB, CurTBB, CurFBB, CurCond);
761 if (!CurUnAnalyzable) {
Chris Lattner386e2902006-10-21 05:08:28 +0000762 // If the CFG for the prior block has extra edges, remove them.
763 MadeChange |= CorrectExtraCFGEdges(*MBB, CurTBB, CurFBB,
Chris Lattner7d097842006-10-24 01:12:32 +0000764 !CurCond.empty(),
765 ++MachineFunction::iterator(MBB));
Chris Lattnereb15eee2006-10-13 20:43:10 +0000766
Chris Lattner5d056952006-11-08 01:03:21 +0000767 // If this is a two-way branch, and the FBB branches to this block, reverse
768 // the condition so the single-basic-block loop is faster. Instead of:
769 // Loop: xxx; jcc Out; jmp Loop
770 // we want:
771 // Loop: xxx; jncc Loop; jmp Out
772 if (CurTBB && CurFBB && CurFBB == MBB && CurTBB != MBB) {
773 std::vector<MachineOperand> NewCond(CurCond);
774 if (!TII->ReverseBranchCondition(NewCond)) {
775 TII->RemoveBranch(*MBB);
776 TII->InsertBranch(*MBB, CurFBB, CurTBB, NewCond);
777 MadeChange = true;
778 ++NumBranchOpts;
779 return OptimizeBlock(MBB);
780 }
781 }
782
783
Chris Lattner386e2902006-10-21 05:08:28 +0000784 // If this branch is the only thing in its block, see if we can forward
785 // other blocks across it.
786 if (CurTBB && CurCond.empty() && CurFBB == 0 &&
Chris Lattner7d097842006-10-24 01:12:32 +0000787 TII->isBranch(MBB->begin()->getOpcode()) && CurTBB != MBB) {
Chris Lattner386e2902006-10-21 05:08:28 +0000788 // This block may contain just an unconditional branch. Because there can
789 // be 'non-branch terminators' in the block, try removing the branch and
790 // then seeing if the block is empty.
791 TII->RemoveBranch(*MBB);
792
793 // If this block is just an unconditional branch to CurTBB, we can
794 // usually completely eliminate the block. The only case we cannot
795 // completely eliminate the block is when the block before this one
796 // falls through into MBB and we can't understand the prior block's branch
797 // condition.
Chris Lattnercf420cc2006-10-28 17:32:47 +0000798 if (MBB->empty()) {
799 bool PredHasNoFallThrough = TII->BlockHasNoFallThrough(PrevBB);
800 if (PredHasNoFallThrough || !PriorUnAnalyzable ||
801 !PrevBB.isSuccessor(MBB)) {
802 // If the prior block falls through into us, turn it into an
803 // explicit branch to us to make updates simpler.
804 if (!PredHasNoFallThrough && PrevBB.isSuccessor(MBB) &&
805 PriorTBB != MBB && PriorFBB != MBB) {
806 if (PriorTBB == 0) {
Chris Lattner6acfe122006-10-28 18:34:47 +0000807 assert(PriorCond.empty() && PriorFBB == 0 &&
808 "Bad branch analysis");
Chris Lattnercf420cc2006-10-28 17:32:47 +0000809 PriorTBB = MBB;
810 } else {
811 assert(PriorFBB == 0 && "Machine CFG out of date!");
812 PriorFBB = MBB;
813 }
814 TII->RemoveBranch(PrevBB);
815 TII->InsertBranch(PrevBB, PriorTBB, PriorFBB, PriorCond);
Chris Lattner386e2902006-10-21 05:08:28 +0000816 }
Chris Lattner386e2902006-10-21 05:08:28 +0000817
Chris Lattnercf420cc2006-10-28 17:32:47 +0000818 // Iterate through all the predecessors, revectoring each in-turn.
819 MachineBasicBlock::pred_iterator PI = MBB->pred_begin();
820 bool DidChange = false;
821 bool HasBranchToSelf = false;
822 while (PI != MBB->pred_end()) {
823 if (*PI == MBB) {
824 // If this block has an uncond branch to itself, leave it.
825 ++PI;
826 HasBranchToSelf = true;
827 } else {
828 DidChange = true;
829 ReplaceUsesOfBlockWith(*PI, MBB, CurTBB, TII);
830 }
Chris Lattner4bc135e2006-10-21 06:11:43 +0000831 }
Chris Lattner386e2902006-10-21 05:08:28 +0000832
Chris Lattnercf420cc2006-10-28 17:32:47 +0000833 // Change any jumptables to go to the new MBB.
Chris Lattner6acfe122006-10-28 18:34:47 +0000834 MBB->getParent()->getJumpTableInfo()->
835 ReplaceMBBInJumpTables(MBB, CurTBB);
Chris Lattnercf420cc2006-10-28 17:32:47 +0000836 if (DidChange) {
837 ++NumBranchOpts;
838 MadeChange = true;
839 if (!HasBranchToSelf) return;
840 }
Chris Lattner4bc135e2006-10-21 06:11:43 +0000841 }
Chris Lattnereb15eee2006-10-13 20:43:10 +0000842 }
Chris Lattnereb15eee2006-10-13 20:43:10 +0000843
Chris Lattner386e2902006-10-21 05:08:28 +0000844 // Add the branch back if the block is more than just an uncond branch.
845 TII->InsertBranch(*MBB, CurTBB, 0, CurCond);
Chris Lattner21ab22e2004-07-31 10:01:27 +0000846 }
Chris Lattner6b0e3f82006-10-29 21:05:41 +0000847 }
848
849 // If the prior block doesn't fall through into this block, and if this
850 // block doesn't fall through into some other block, see if we can find a
851 // place to move this block where a fall-through will happen.
852 if (!CanFallThrough(&PrevBB, PriorUnAnalyzable,
853 PriorTBB, PriorFBB, PriorCond)) {
854 // Now we know that there was no fall-through into this block, check to
855 // see if it has a fall-through into its successor.
856 if (!CanFallThrough(MBB, CurUnAnalyzable, CurTBB, CurFBB, CurCond)) {
857 // Check all the predecessors of this block. If one of them has no fall
858 // throughs, move this block right after it.
859 for (MachineBasicBlock::pred_iterator PI = MBB->pred_begin(),
860 E = MBB->pred_end(); PI != E; ++PI) {
861 // Analyze the branch at the end of the pred.
862 MachineBasicBlock *PredBB = *PI;
863 MachineFunction::iterator PredFallthrough = PredBB; ++PredFallthrough;
Chris Lattner6b0e3f82006-10-29 21:05:41 +0000864 std::vector<MachineOperand> PredCond;
865 if (PredBB != MBB && !CanFallThrough(PredBB)) {
866 MBB->moveAfter(PredBB);
Chris Lattner7d097842006-10-24 01:12:32 +0000867 MadeChange = true;
Chris Lattner6b0e3f82006-10-29 21:05:41 +0000868 return OptimizeBlock(MBB);
Chris Lattner7d097842006-10-24 01:12:32 +0000869 }
870 }
Chris Lattner6b0e3f82006-10-29 21:05:41 +0000871
872 // Check all successors to see if we can move this block before it.
873 for (MachineBasicBlock::succ_iterator SI = MBB->succ_begin(),
874 E = MBB->succ_end(); SI != E; ++SI) {
875 // Analyze the branch at the end of the block before the succ.
876 MachineBasicBlock *SuccBB = *SI;
877 MachineFunction::iterator SuccPrev = SuccBB; --SuccPrev;
Chris Lattner6b0e3f82006-10-29 21:05:41 +0000878 std::vector<MachineOperand> SuccPrevCond;
879 if (SuccBB != MBB && !CanFallThrough(SuccPrev)) {
880 MBB->moveBefore(SuccBB);
881 MadeChange = true;
882 return OptimizeBlock(MBB);
883 }
884 }
885
886 // Okay, there is no really great place to put this block. If, however,
887 // the block before this one would be a fall-through if this block were
888 // removed, move this block to the end of the function.
889 if (FallThrough != MBB->getParent()->end() &&
890 PrevBB.isSuccessor(FallThrough)) {
891 MBB->moveAfter(--MBB->getParent()->end());
892 MadeChange = true;
893 return;
894 }
Chris Lattner7d097842006-10-24 01:12:32 +0000895 }
Chris Lattner21ab22e2004-07-31 10:01:27 +0000896 }
Chris Lattner21ab22e2004-07-31 10:01:27 +0000897}