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

Side by Side Diff: src/IceRNG.h

Issue 1221643012: Subzero: Add -Wshadow to the build. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Change the previous underscore naming style 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 unified diff | Download patch
OLDNEW
1 //===- subzero/src/IceRNG.h - Random number generator -----------*- C++ -*-===// 1 //===- subzero/src/IceRNG.h - Random number generator -----------*- 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 // This file declares a random number generator. 10 // This file declares a random number generator.
11 // 11 //
12 //===----------------------------------------------------------------------===// 12 //===----------------------------------------------------------------------===//
13 13
14 #ifndef SUBZERO_SRC_ICERNG_H 14 #ifndef SUBZERO_SRC_ICERNG_H
15 #define SUBZERO_SRC_ICERNG_H 15 #define SUBZERO_SRC_ICERNG_H
16 16
17 #pragma clang diagnostic push
18 #pragma clang diagnostic ignored "-Wunused-parameter"
19 #pragma clang diagnostic ignored "-Wshadow"
17 #include "llvm/ADT/StringRef.h" 20 #include "llvm/ADT/StringRef.h"
18 #include "llvm/Support/Compiler.h" 21 #include "llvm/Support/Compiler.h"
22 #pragma clang diagnostic pop
23
19 #include <cstdint> 24 #include <cstdint>
20 25
21 namespace Ice { 26 namespace Ice {
22 27
23 class RandomNumberGenerator { 28 class RandomNumberGenerator {
24 RandomNumberGenerator() = delete; 29 RandomNumberGenerator() = delete;
25 RandomNumberGenerator(const RandomNumberGenerator &) = delete; 30 RandomNumberGenerator(const RandomNumberGenerator &) = delete;
26 RandomNumberGenerator &operator=(const RandomNumberGenerator &) = delete; 31 RandomNumberGenerator &operator=(const RandomNumberGenerator &) = delete;
27 32
28 public: 33 public:
29 explicit RandomNumberGenerator(uint64_t Seed, llvm::StringRef Salt = ""); 34 explicit RandomNumberGenerator(uint64_t Seed, llvm::StringRef Salt = "");
30 uint64_t next(uint64_t Max); 35 uint64_t next(uint64_t Max);
31 36
32 private: 37 private:
33 uint64_t State; 38 uint64_t State;
34 }; 39 };
35 40
36 // This class adds additional random number generator utilities. The 41 // This class adds additional random number generator utilities. The
37 // reason for the wrapper class is that we want to keep the 42 // reason for the wrapper class is that we want to keep the
38 // RandomNumberGenerator interface identical to LLVM's. 43 // RandomNumberGenerator interface identical to LLVM's.
39 class RandomNumberGeneratorWrapper { 44 class RandomNumberGeneratorWrapper {
40 RandomNumberGeneratorWrapper() = delete; 45 RandomNumberGeneratorWrapper() = delete;
41 RandomNumberGeneratorWrapper(const RandomNumberGeneratorWrapper &) = delete; 46 RandomNumberGeneratorWrapper(const RandomNumberGeneratorWrapper &) = delete;
42 RandomNumberGeneratorWrapper & 47 RandomNumberGeneratorWrapper &
43 operator=(const RandomNumberGeneratorWrapper &) = delete; 48 operator=(const RandomNumberGeneratorWrapper &) = delete;
44 49
45 public: 50 public:
46 uint64_t operator()(uint64_t Max) { return RNG.next(Max); } 51 uint64_t operator()(uint64_t Max) { return RNG.next(Max); }
47 bool getTrueWithProbability(float Probability); 52 bool getTrueWithProbability(float Probability);
48 explicit RandomNumberGeneratorWrapper(RandomNumberGenerator &RNG) 53 explicit RandomNumberGeneratorWrapper(RandomNumberGenerator &MyRNG)
49 : RNG(RNG) {} 54 : RNG(MyRNG) {}
50 55
51 private: 56 private:
52 RandomNumberGenerator &RNG; 57 RandomNumberGenerator &RNG;
53 }; 58 };
54 59
55 // RandomShuffle is an implementation of std::random_shuffle() that 60 // RandomShuffle is an implementation of std::random_shuffle() that
56 // doesn't change across stdlib implementations. Adapted from a 61 // doesn't change across stdlib implementations. Adapted from a
57 // sample implementation at cppreference.com. 62 // sample implementation at cppreference.com.
58 template <class RandomIt, class RandomFunc> 63 template <class RandomIt, class RandomFunc>
59 void RandomShuffle(RandomIt First, RandomIt Last, RandomFunc &&RNG) { 64 void RandomShuffle(RandomIt First, RandomIt Last, RandomFunc &&RNG) {
60 for (auto i = Last - First - 1; i > 0; --i) 65 for (auto i = Last - First - 1; i > 0; --i)
61 std::swap(First[i], First[RNG(i + 1)]); 66 std::swap(First[i], First[RNG(i + 1)]);
62 } 67 }
63 68
64 } // end of namespace Ice 69 } // end of namespace Ice
65 70
66 #endif // SUBZERO_SRC_ICERNG_H 71 #endif // SUBZERO_SRC_ICERNG_H
OLDNEW
« src/IceInstARM32.h ('K') | « src/IceOperand.h ('k') | src/IceRegAlloc.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698