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

Unified Diff: src/IceGlobalContext.cpp

Issue 1260183008: Order jump tables for deterministic or randomized emission. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Fix sort comparison. 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/IceGlobalContext.h ('k') | src/IceSwitchLowering.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/IceGlobalContext.cpp
diff --git a/src/IceGlobalContext.cpp b/src/IceGlobalContext.cpp
index 8bfc5dd5022aa126edeedf0b8db9b698f3b8ea1a..1bcb85737c5bf01ca1234a4fd85f0665c20cf994 100644
--- a/src/IceGlobalContext.cpp
+++ b/src/IceGlobalContext.cpp
@@ -878,11 +878,32 @@ ConstantList GlobalContext::getConstantExternSyms() {
return getConstPool()->ExternRelocatables.getConstantPool();
}
+JumpTableDataList GlobalContext::getJumpTables() {
+ JumpTableDataList JumpTables(*getJumpTableList());
+ if (getFlags().shouldReorderPooledConstants()) {
+ // If reorder-pooled-constants option is set to true, we need to shuffle the
+ // constant pool before emitting it.
+ RandomShuffle(JumpTables.begin(), JumpTables.end(), [this](uint64_t N) {
+ return (uint32_t)getRNG().next(N);
+ });
+ } else {
+ // Make order deterministic by sorting into functions and then ID of the
+ // jump table within that function.
+ std::sort(JumpTables.begin(), JumpTables.end(), [](const JumpTableData &A,
+ const JumpTableData &B) {
+ if (A.getFunctionName() != B.getFunctionName())
+ return A.getFunctionName() < B.getFunctionName();
+ return A.getId() < B.getId();
+ });
+ }
+ return JumpTables;
+}
+
JumpTableData &GlobalContext::addJumpTable(IceString FuncName, SizeT Id,
SizeT NumTargets) {
- auto JumpTables = getJumpTables();
- JumpTables->emplace_back(FuncName, Id, NumTargets);
- return JumpTables->back();
+ auto JumpTableList = getJumpTableList();
+ JumpTableList->emplace_back(FuncName, Id, NumTargets);
+ return JumpTableList->back();
}
TimerStackIdT GlobalContext::newTimerStackID(const IceString &Name) {
« no previous file with comments | « src/IceGlobalContext.h ('k') | src/IceSwitchLowering.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698