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

Side by Side Diff: src/IceRegAlloc.cpp

Issue 1300993002: Use separate random number generator for each randomization pass (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: 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/IceRNG.cpp ('k') | src/IceTargetLowering.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/IceRegAlloc.cpp - Linear-scan implementation -----------===// 1 //===- subzero/src/IceRegAlloc.cpp - Linear-scan 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
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 case RAK_Global: 243 case RAK_Global:
244 case RAK_Phi: 244 case RAK_Phi:
245 initForGlobal(); 245 initForGlobal();
246 break; 246 break;
247 case RAK_InfOnly: 247 case RAK_InfOnly:
248 initForInfOnly(); 248 initForInfOnly();
249 break; 249 break;
250 } 250 }
251 251
252 auto CompareRanges = [](const Variable *L, const Variable *R) { 252 auto CompareRanges = [](const Variable *L, const Variable *R) {
253 InstNumberT Lstart = L->getLiveRange().getStart(); 253 InstNumberT Lstart = L->getLiveRange().getStart();
254 InstNumberT Rstart = R->getLiveRange().getStart(); 254 InstNumberT Rstart = R->getLiveRange().getStart();
255 if (Lstart == Rstart) 255 if (Lstart == Rstart)
256 return L->getIndex() < R->getIndex(); 256 return L->getIndex() < R->getIndex();
257 return Lstart < Rstart; 257 return Lstart < Rstart;
258 }; 258 };
259 // Do a reverse sort so that erasing elements (from the end) is fast. 259 // Do a reverse sort so that erasing elements (from the end) is fast.
260 std::sort(Unhandled.rbegin(), Unhandled.rend(), CompareRanges); 260 std::sort(Unhandled.rbegin(), Unhandled.rend(), CompareRanges);
261 std::sort(UnhandledPrecolored.rbegin(), UnhandledPrecolored.rend(), 261 std::sort(UnhandledPrecolored.rbegin(), UnhandledPrecolored.rend(),
262 CompareRanges); 262 CompareRanges);
263 263
264 Handled.reserve(Unhandled.size()); 264 Handled.reserve(Unhandled.size());
265 Inactive.reserve(Unhandled.size()); 265 Inactive.reserve(Unhandled.size());
266 Active.reserve(Unhandled.size()); 266 Active.reserve(Unhandled.size());
267 } 267 }
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after
769 for (Variable *I : Active) 769 for (Variable *I : Active)
770 Handled.push_back(I); 770 Handled.push_back(I);
771 Active.clear(); 771 Active.clear();
772 for (Variable *I : Inactive) 772 for (Variable *I : Inactive)
773 Handled.push_back(I); 773 Handled.push_back(I);
774 Inactive.clear(); 774 Inactive.clear();
775 dump(Func); 775 dump(Func);
776 776
777 llvm::SmallVector<int32_t, REGS_SIZE> Permutation(NumRegisters); 777 llvm::SmallVector<int32_t, REGS_SIZE> Permutation(NumRegisters);
778 if (Randomized) { 778 if (Randomized) {
779 // Create a random number generator for regalloc randomization. Merge
780 // function's sequence and Kind value as the Salt. Because regalloc()
Jim Stichnoth 2015/08/20 20:01:33 regAlloc
781 // are called twice under O2, the second time with RAK_Phi, we check
Jim Stichnoth 2015/08/20 20:01:33 is called
782 // Kind == RAK_Phi to determine the least bit to make sure the Salt is
Jim Stichnoth 2015/08/20 20:01:33 I would say "lowest-order" instead of "least".
783 // different.
784 uint64_t Salt =
785 (Func->getSequenceNumber() << 1) ^ (Kind == RAK_Phi ? 0u : 1u);
779 Func->getTarget()->makeRandomRegisterPermutation( 786 Func->getTarget()->makeRandomRegisterPermutation(
780 Permutation, PreDefinedRegisters | ~RegMaskFull); 787 Permutation, PreDefinedRegisters | ~RegMaskFull, Salt);
781 } 788 }
782 789
783 // Finish up by assigning RegNumTmp->RegNum (or a random permutation 790 // Finish up by assigning RegNumTmp->RegNum (or a random permutation
784 // thereof) for each Variable. 791 // thereof) for each Variable.
785 for (Variable *Item : Handled) { 792 for (Variable *Item : Handled) {
786 int32_t RegNum = Item->getRegNumTmp(); 793 int32_t RegNum = Item->getRegNumTmp();
787 int32_t AssignedRegNum = RegNum; 794 int32_t AssignedRegNum = RegNum;
788 795
789 if (Randomized && Item->hasRegTmp() && !Item->hasReg()) { 796 if (Randomized && Item->hasRegTmp() && !Item->hasReg()) {
790 AssignedRegNum = Permutation[RegNum]; 797 AssignedRegNum = Permutation[RegNum];
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
848 Str << "\n"; 855 Str << "\n";
849 } 856 }
850 Str << "++++++ Inactive:\n"; 857 Str << "++++++ Inactive:\n";
851 for (const Variable *Item : Inactive) { 858 for (const Variable *Item : Inactive) {
852 dumpLiveRange(Item, Func); 859 dumpLiveRange(Item, Func);
853 Str << "\n"; 860 Str << "\n";
854 } 861 }
855 } 862 }
856 863
857 } // end of namespace Ice 864 } // end of namespace Ice
OLDNEW
« no previous file with comments | « src/IceRNG.cpp ('k') | src/IceTargetLowering.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698