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

Unified 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: Minor fix Created 5 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: src/IceCfg.cpp
diff --git a/src/IceCfg.cpp b/src/IceCfg.cpp
index 7e915081700eec8a629c7d3f2fdbc61aba98a43c..1ff88f07a1c893578503eb99a179a42eb7829980 100644
--- a/src/IceCfg.cpp
+++ b/src/IceCfg.cpp
@@ -26,6 +26,9 @@
#include "IceOperand.h"
#include "IceTargetLowering.h"
+#include <list>
+#include <unordered_set>
+
namespace Ice {
ICE_TLS_DEFINE_FIELD(const Cfg *, Cfg, CurrentCfg);
@@ -332,6 +335,44 @@ void Cfg::reorderNodes() {
assert(Nodes.size() == OldSize);
}
+namespace {
+template <class NodeType>
+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.
+ std::unordered_set<const NodeType *> &Visited,
+ std::list<NodeType *> &ReversePostOrder,
+ Ice::RandomNumberGenerator *RNG) {
+ 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,
+ return;
+ Visited.insert(Node);
+ NodeList Outs = Node->getOutEdges();
+ Ice::RandomShuffle(Outs.begin(), Outs.end(),
+ [&](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.
+ 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.
+ getRandomReversedPostOrder(Next, Visited, ReversePostOrder, RNG);
+ }
+ ReversePostOrder.push_front(Node);
+}
+}
+
+void Cfg::shuffleNodes() {
+ std::list<CfgNode *> NewList;
+ std::unordered_set<const CfgNode *> Visited;
+ Visited.clear();
+ getRandomReversedPostOrder<CfgNode>(getEntryNode(), Visited, NewList,
+ &Ctx->getRNG());
+ for (auto *Node : Nodes)
+ if (Visited.find(Node) == Visited.end())
+ NewList.push_back(Node);
+
+ // Copy the layout list to the Nodes.
+ SizeT OldSize = Nodes.size();
+ (void)OldSize;
+ Nodes.clear();
+ 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.
+ Nodes.push_back(Node);
+ assert(Nodes.size() == OldSize);
+}
+
void Cfg::doArgLowering() {
TimerMarker T(TimerStack::TT_doArgLowering, this);
getTarget()->lowerArguments();

Powered by Google App Engine
This is Rietveld 408576698