Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 template <class NodeType> | |
| 340 void getRandomReversedPostOrder(NodeType *Node, | |
|
John
2015/07/29 17:52:36
Does this need to be a template? It seems NodeType
qining
2015/07/29 23:04:40
Done, change to a normal function.
| |
| 341 std::unordered_set<const NodeType *> &Visited, | |
| 342 std::list<NodeType *> &ReversePostOrder, | |
| 343 Ice::RandomNumberGenerator *RNG) { | |
| 344 if (Visited.find(Node) != Visited.end()) | |
|
John
2015/07/29 17:52:36
Just a thought...
You are calling this method, an
qining
2015/07/29 23:04:40
I think your code is faster, I've changed to this,
| |
| 345 return; | |
| 346 Visited.insert(Node); | |
| 347 NodeList Outs = Node->getOutEdges(); | |
| 348 Ice::RandomShuffle(Outs.begin(), Outs.end(), | |
| 349 [&](int N) { return RNG->next(N); }); | |
|
John
2015/07/29 17:52:36
please do not use default capture (especially by r
qining
2015/07/29 23:04:40
Done.
| |
| 350 for (auto *Next : Outs) { | |
|
John
2015/07/29 17:52:36
Just a personal preference, but use
CfgNode *
in
qining
2015/07/29 23:04:40
Done.
| |
| 351 getRandomReversedPostOrder(Next, Visited, ReversePostOrder, RNG); | |
| 352 } | |
| 353 ReversePostOrder.push_front(Node); | |
| 354 } | |
| 355 } | |
| 356 | |
| 357 void Cfg::shuffleNodes() { | |
| 358 std::list<CfgNode *> NewList; | |
| 359 std::unordered_set<const CfgNode *> Visited; | |
| 360 Visited.clear(); | |
| 361 getRandomReversedPostOrder<CfgNode>(getEntryNode(), Visited, NewList, | |
| 362 &Ctx->getRNG()); | |
| 363 for (auto *Node : Nodes) | |
| 364 if (Visited.find(Node) == Visited.end()) | |
| 365 NewList.push_back(Node); | |
| 366 | |
| 367 // Copy the layout list to the Nodes. | |
| 368 SizeT OldSize = Nodes.size(); | |
| 369 (void)OldSize; | |
| 370 Nodes.clear(); | |
| 371 for (CfgNode *Node : NewList) | |
|
John
2015/07/29 17:52:36
This is probably not a big deal, but you're traver
qining
2015/07/29 23:04:40
Done.
| |
| 372 Nodes.push_back(Node); | |
| 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 Loading... | |
| 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 |
| OLD | NEW |