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

Side by Side Diff: src/IceTargetLoweringX8632Traits.h

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: rebase to master 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/IceTargetLoweringX8632.cpp ('k') | src/IceTargetLoweringX8664.cpp » ('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/IceTargetLoweringX8632Traits.h - x86-32 traits -*- C++ -*-=// 1 //===- subzero/src/IceTargetLoweringX8632Traits.h - x86-32 traits -*- C++ -*-=//
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 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 REGX8632_TABLE 355 REGX8632_TABLE
356 356
357 #undef X 357 #undef X
358 358
359 return Registers; 359 return Registers;
360 } 360 }
361 361
362 static void 362 static void
363 makeRandomRegisterPermutation(GlobalContext *Ctx, Cfg *Func, 363 makeRandomRegisterPermutation(GlobalContext *Ctx, Cfg *Func,
364 llvm::SmallVectorImpl<int32_t> &Permutation, 364 llvm::SmallVectorImpl<int32_t> &Permutation,
365 const llvm::SmallBitVector &ExcludeRegisters) { 365 const llvm::SmallBitVector &ExcludeRegisters,
366 uint64_t Salt) {
366 // TODO(stichnot): Declaring Permutation this way loses type/size 367 // TODO(stichnot): Declaring Permutation this way loses type/size
367 // information. Fix this in conjunction with the caller-side TODO. 368 // information. Fix this in conjunction with the caller-side TODO.
368 assert(Permutation.size() >= RegisterSet::Reg_NUM); 369 assert(Permutation.size() >= RegisterSet::Reg_NUM);
369 // Expected upper bound on the number of registers in a single equivalence 370 // Expected upper bound on the number of registers in a single equivalence
370 // class. For x86-32, this would comprise the 8 XMM registers. This is for 371 // class. For x86-32, this would comprise the 8 XMM registers. This is for
371 // performance, not correctness. 372 // performance, not correctness.
372 static const unsigned MaxEquivalenceClassSize = 8; 373 static const unsigned MaxEquivalenceClassSize = 8;
373 typedef llvm::SmallVector<int32_t, MaxEquivalenceClassSize> RegisterList; 374 typedef llvm::SmallVector<int32_t, MaxEquivalenceClassSize> RegisterList;
374 typedef std::map<uint32_t, RegisterList> EquivalenceClassMap; 375 typedef std::map<uint32_t, RegisterList> EquivalenceClassMap;
375 EquivalenceClassMap EquivalenceClasses; 376 EquivalenceClassMap EquivalenceClasses;
(...skipping 10 matching lines...) Expand all
386 ++NumPreserved; \ 387 ++NumPreserved; \
387 } else { \ 388 } else { \
388 const uint32_t Index = (scratch << 0) | (preserved << 1) | (isI8 << 2) | \ 389 const uint32_t Index = (scratch << 0) | (preserved << 1) | (isI8 << 2) | \
389 (isInt << 3) | (isFP << 4); \ 390 (isInt << 3) | (isFP << 4); \
390 /* val is assigned to an equivalence class based on its properties. */ \ 391 /* val is assigned to an equivalence class based on its properties. */ \
391 EquivalenceClasses[Index].push_back(RegisterSet::val); \ 392 EquivalenceClasses[Index].push_back(RegisterSet::val); \
392 } 393 }
393 REGX8632_TABLE 394 REGX8632_TABLE
394 #undef X 395 #undef X
395 396
396 RandomNumberGeneratorWrapper RNG(Ctx->getRNG()); 397 // Create a random number generator for regalloc randomization.
398 RandomNumberGenerator RNG(Ctx->getFlags().getRandomSeed(),
399 RPE_RegAllocRandomization, Salt);
400 RandomNumberGeneratorWrapper RNGW(RNG);
397 401
398 // Shuffle the resulting equivalence classes. 402 // Shuffle the resulting equivalence classes.
399 for (auto I : EquivalenceClasses) { 403 for (auto I : EquivalenceClasses) {
400 const RegisterList &List = I.second; 404 const RegisterList &List = I.second;
401 RegisterList Shuffled(List); 405 RegisterList Shuffled(List);
402 RandomShuffle(Shuffled.begin(), Shuffled.end(), RNG); 406 RandomShuffle(Shuffled.begin(), Shuffled.end(), RNGW);
403 for (size_t SI = 0, SE = Shuffled.size(); SI < SE; ++SI) { 407 for (size_t SI = 0, SE = Shuffled.size(); SI < SE; ++SI) {
404 Permutation[List[SI]] = Shuffled[SI]; 408 Permutation[List[SI]] = Shuffled[SI];
405 ++NumShuffled; 409 ++NumShuffled;
406 } 410 }
407 } 411 }
408 412
409 assert(NumShuffled + NumPreserved == RegisterSet::Reg_NUM); 413 assert(NumShuffled + NumPreserved == RegisterSet::Reg_NUM);
410 414
411 if (Func->isVerbose(IceV_Random)) { 415 if (Func->isVerbose(IceV_Random)) {
412 OstreamLocker L(Func->getContext()); 416 OstreamLocker L(Func->getContext());
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
712 716
713 } // end of namespace X86Internal 717 } // end of namespace X86Internal
714 718
715 namespace X8632 { 719 namespace X8632 {
716 using Traits = ::Ice::X86Internal::MachineTraits<TargetX8632>; 720 using Traits = ::Ice::X86Internal::MachineTraits<TargetX8632>;
717 } // end of namespace X8632 721 } // end of namespace X8632
718 722
719 } // end of namespace Ice 723 } // end of namespace Ice
720 724
721 #endif // SUBZERO_SRC_ICETARGETLOWERINGX8632TRAITS_H 725 #endif // SUBZERO_SRC_ICETARGETLOWERINGX8632TRAITS_H
OLDNEW
« no previous file with comments | « src/IceTargetLoweringX8632.cpp ('k') | src/IceTargetLoweringX8664.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698