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

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

Powered by Google App Engine
This is Rietveld 408576698