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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « src/IceGlobalContext.h ('k') | src/IceSwitchLowering.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 //===- subzero/src/IceGlobalContext.cpp - Global context defs -------------===// 1 //===- subzero/src/IceGlobalContext.cpp - Global context defs -------------===//
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
(...skipping 860 matching lines...) Expand 10 before | Expand all | Expand 10 after
871 case IceType_NUM: 871 case IceType_NUM:
872 break; 872 break;
873 } 873 }
874 llvm_unreachable("Unknown type"); 874 llvm_unreachable("Unknown type");
875 } 875 }
876 876
877 ConstantList GlobalContext::getConstantExternSyms() { 877 ConstantList GlobalContext::getConstantExternSyms() {
878 return getConstPool()->ExternRelocatables.getConstantPool(); 878 return getConstPool()->ExternRelocatables.getConstantPool();
879 } 879 }
880 880
881 JumpTableDataList GlobalContext::getJumpTables() {
882 JumpTableDataList JumpTables(*getJumpTableList());
883 if (getFlags().shouldReorderPooledConstants()) {
884 // If reorder-pooled-constants option is set to true, we need to shuffle the
885 // constant pool before emitting it.
886 RandomShuffle(JumpTables.begin(), JumpTables.end(), [this](uint64_t N) {
887 return (uint32_t)getRNG().next(N);
888 });
889 } else {
890 // Make order deterministic by sorting into functions and then ID of the
891 // jump table within that function.
892 std::sort(JumpTables.begin(), JumpTables.end(), [](const JumpTableData &A,
893 const JumpTableData &B) {
894 if (A.getFunctionName() != B.getFunctionName())
895 return A.getFunctionName() < B.getFunctionName();
896 return A.getId() < B.getId();
897 });
898 }
899 return JumpTables;
900 }
901
881 JumpTableData &GlobalContext::addJumpTable(IceString FuncName, SizeT Id, 902 JumpTableData &GlobalContext::addJumpTable(IceString FuncName, SizeT Id,
882 SizeT NumTargets) { 903 SizeT NumTargets) {
883 auto JumpTables = getJumpTables(); 904 auto JumpTableList = getJumpTableList();
884 JumpTables->emplace_back(FuncName, Id, NumTargets); 905 JumpTableList->emplace_back(FuncName, Id, NumTargets);
885 return JumpTables->back(); 906 return JumpTableList->back();
886 } 907 }
887 908
888 TimerStackIdT GlobalContext::newTimerStackID(const IceString &Name) { 909 TimerStackIdT GlobalContext::newTimerStackID(const IceString &Name) {
889 if (!BuildDefs::dump()) 910 if (!BuildDefs::dump())
890 return 0; 911 return 0;
891 auto Timers = getTimers(); 912 auto Timers = getTimers();
892 TimerStackIdT NewID = Timers->size(); 913 TimerStackIdT NewID = Timers->size();
893 Timers->push_back(TimerStack(Name)); 914 Timers->push_back(TimerStack(Name));
894 return NewID; 915 return NewID;
895 } 916 }
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
992 Ctx = Func->getContext(); 1013 Ctx = Func->getContext();
993 Active = 1014 Active =
994 Func->getFocusedTiming() || Ctx->getFlags().getSubzeroTimingEnabled(); 1015 Func->getFocusedTiming() || Ctx->getFlags().getSubzeroTimingEnabled();
995 if (Active) 1016 if (Active)
996 Ctx->pushTimer(ID, StackID); 1017 Ctx->pushTimer(ID, StackID);
997 } 1018 }
998 1019
999 ICE_TLS_DEFINE_FIELD(GlobalContext::ThreadContext *, GlobalContext, TLS); 1020 ICE_TLS_DEFINE_FIELD(GlobalContext::ThreadContext *, GlobalContext, TLS);
1000 1021
1001 } // end of namespace Ice 1022 } // end of namespace Ice
OLDNEW
« 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