Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(515)

Side by Side Diff: src/IceCfg.cpp

Issue 1255303004: Add -reorder-basic-blocks option and fix nop insertion (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: fix comments Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 //===- subzero/src/IceCfg.cpp - Control flow graph implementation ---------===// 1 //===- subzero/src/IceCfg.cpp - Control flow graph implementation ---------===//
2 // 2 //
3 // The Subzero Code Generator 3 // The Subzero Code Generator
4 // 4 //
5 // This file is distributed under the University of Illinois Open Source 5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details. 6 // License. See LICENSE.TXT for details.
7 // 7 //
8 //===----------------------------------------------------------------------===// 8 //===----------------------------------------------------------------------===//
9 /// 9 ///
10 /// \file 10 /// \file
11 /// This file implements the Cfg class, including constant pool 11 /// This file implements the Cfg class, including constant pool
12 /// management. 12 /// management.
13 /// 13 ///
14 //===----------------------------------------------------------------------===// 14 //===----------------------------------------------------------------------===//
15 15
16 #include "IceCfg.h" 16 #include "IceCfg.h"
17 17
18 #include "IceAssembler.h" 18 #include "IceAssembler.h"
19 #include "IceCfgNode.h" 19 #include "IceCfgNode.h"
20 #include "IceClFlags.h" 20 #include "IceClFlags.h"
21 #include "IceDefs.h" 21 #include "IceDefs.h"
22 #include "IceELFObjectWriter.h" 22 #include "IceELFObjectWriter.h"
23 #include "IceGlobalInits.h" 23 #include "IceGlobalInits.h"
24 #include "IceInst.h" 24 #include "IceInst.h"
25 #include "IceLiveness.h" 25 #include "IceLiveness.h"
26 #include "IceOperand.h" 26 #include "IceOperand.h"
27 #include "IceTargetLowering.h" 27 #include "IceTargetLowering.h"
28 28
29 #include <list>
30 #include <unordered_set>
31
29 namespace Ice { 32 namespace Ice {
30 33
31 ICE_TLS_DEFINE_FIELD(const Cfg *, Cfg, CurrentCfg); 34 ICE_TLS_DEFINE_FIELD(const Cfg *, Cfg, CurrentCfg);
32 35
33 ArenaAllocator<> *getCurrentCfgAllocator() { 36 ArenaAllocator<> *getCurrentCfgAllocator() {
34 return Cfg::getCurrentCfgAllocator(); 37 return Cfg::getCurrentCfgAllocator();
35 } 38 }
36 39
37 Cfg::Cfg(GlobalContext *Ctx, uint32_t SequenceNumber) 40 Cfg::Cfg(GlobalContext *Ctx, uint32_t SequenceNumber)
38 : Ctx(Ctx), SequenceNumber(SequenceNumber), 41 : Ctx(Ctx), SequenceNumber(SequenceNumber),
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 SizeT OldSize = Nodes.size(); 328 SizeT OldSize = Nodes.size();
326 (void)OldSize; 329 (void)OldSize;
327 Nodes.clear(); 330 Nodes.clear();
328 for (CfgNode *Node : Placed) 331 for (CfgNode *Node : Placed)
329 Nodes.push_back(Node); 332 Nodes.push_back(Node);
330 for (CfgNode *Node : Unreachable) 333 for (CfgNode *Node : Unreachable)
331 Nodes.push_back(Node); 334 Nodes.push_back(Node);
332 assert(Nodes.size() == OldSize); 335 assert(Nodes.size() == OldSize);
333 } 336 }
334 337
338 namespace {
339 void getRandomReversedPostOrder(CfgNode *Node,
340 std::unordered_set<const CfgNode *> &Visited,
341 std::list<CfgNode *> &ReversePostOrder,
342 Ice::RandomNumberGenerator *RNG) {
343 assert(Visited.count(Node) == 0);
344 Visited.insert(Node);
345 NodeList Outs = Node->getOutEdges();
346 Ice::RandomShuffle(Outs.begin(), Outs.end(),
347 [RNG](int N) { return RNG->next(N); });
348 for (CfgNode *Next : Outs) {
349 if (Visited.count(Next) == 0)
350 getRandomReversedPostOrder(Next, Visited, ReversePostOrder, RNG);
351 }
352 ReversePostOrder.push_front(Node);
353 }
354 }
Jim Stichnoth 2015/07/30 16:30:50 add "// end of anonymous namespace" comment
qining 2015/07/30 20:25:54 Done.
355
356 void Cfg::shuffleNodes() {
357 std::list<CfgNode *> NewList;
Jim Stichnoth 2015/07/30 16:30:50 Can you use CfgNodeList instead of list<CfgNode*>?
qining 2015/07/30 20:25:55 Done.
358 std::unordered_set<const CfgNode *> Visited;
Jim Stichnoth 2015/07/30 16:30:51 Can you just make Visited an llvm::BitVector, inde
qining 2015/07/30 20:25:55 Done. Change Visited to ToVisit. True bits mean no
359 Visited.clear();
360 getRandomReversedPostOrder(getEntryNode(), Visited, NewList, &Ctx->getRNG());
361 for (auto *Node : Nodes)
362 if (Visited.find(Node) == Visited.end())
363 NewList.push_back(Node);
364
365 // Copy the layout list to the Nodes.
366 SizeT OldSize = Nodes.size();
367 (void)OldSize;
368 Nodes.clear();
369 while (!NewList.empty()) {
370 Nodes.emplace_back(NewList.front());
371 NewList.pop_front();
372 }
373 assert(Nodes.size() == OldSize);
374 }
375
335 void Cfg::doArgLowering() { 376 void Cfg::doArgLowering() {
336 TimerMarker T(TimerStack::TT_doArgLowering, this); 377 TimerMarker T(TimerStack::TT_doArgLowering, this);
337 getTarget()->lowerArguments(); 378 getTarget()->lowerArguments();
338 } 379 }
339 380
340 void Cfg::doAddressOpt() { 381 void Cfg::doAddressOpt() {
341 TimerMarker T(TimerStack::TT_doAddressOpt, this); 382 TimerMarker T(TimerStack::TT_doAddressOpt, this);
342 for (CfgNode *Node : Nodes) 383 for (CfgNode *Node : Nodes)
343 Node->doAddressOpt(); 384 Node->doAddressOpt();
344 } 385 }
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
621 } 662 }
622 } 663 }
623 // Print each basic block 664 // Print each basic block
624 for (CfgNode *Node : Nodes) 665 for (CfgNode *Node : Nodes)
625 Node->dump(this); 666 Node->dump(this);
626 if (isVerbose(IceV_Instructions)) 667 if (isVerbose(IceV_Instructions))
627 Str << "}\n"; 668 Str << "}\n";
628 } 669 }
629 670
630 } // end of namespace Ice 671 } // end of namespace Ice
OLDNEW
« no previous file with comments | « src/IceCfg.h ('k') | src/IceCfgNode.cpp » ('j') | src/IceTargetLoweringX86BaseImpl.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698