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

Side by Side Diff: tools/pnacl-llc/ThreadedStreamingCache.h

Issue 939073008: Rebased PNaCl localmods in LLVM to 223109 (Closed)
Patch Set: Created 5 years, 10 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
(Empty)
1 //==- ThreadedStreamingCache.h - Cache for StreamingMemoryObject -*- C++ -*-==//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef THREADEDSTREAMINGCACHE_H
11 #define THREADEDSTREAMINGCACHE_H
12
13 #include "llvm/Support/ErrorHandling.h"
14 #include "llvm/Support/Mutex.h"
15 #include "llvm/Support/StreamingMemoryObject.h"
16
17 namespace llvm {
18
19 // An implementation of StreamingMemoryObject for use in multithreaded
20 // translation. Each thread has one of these objects, each of which has a
21 // pointer to a shared StreamingMemoryObject. This object is effectively
22 // a thread-local cache for the bitcode streamer to avoid contention, since
23 // bits are only read from the bitcode stream one word at a time.
24
25 class ThreadedStreamingCache : public llvm::StreamingMemoryObject {
26 public:
27 explicit ThreadedStreamingCache(llvm::StreamingMemoryObject *S);
28 uint64_t getExtent() const override;
29 uint64_t readBytes(uint8_t *Buf, uint64_t Size,
30 uint64_t Address) const override;
31 const uint8_t *getPointer(uint64_t address,
32 uint64_t size) const override {
33 // This could be fixed by ensuring the bytes are fetched and making a copy,
34 // requiring that the bitcode size be known, or otherwise ensuring that
35 // the memory doesn't go away/get reallocated, but it's
36 // not currently necessary. Users that need the pointer don't stream.
37 llvm_unreachable("getPointer in streaming memory objects not allowed");
38 return NULL;
39 }
40 bool isValidAddress(uint64_t address) const override;
41
42 /// Drop s bytes from the front of the stream, pushing the positions of the
43 /// remaining bytes down by s. This is used to skip past the bitcode header,
44 /// since we don't know a priori if it's present, and we can't put bytes
45 /// back into the stream once we've read them.
46 bool dropLeadingBytes(size_t s) override;
47
48 /// If the data object size is known in advance, many of the operations can
49 /// be made more efficient, so this method should be called before reading
50 /// starts (although it can be called anytime).
51 void setKnownObjectSize(size_t size) override;
52 private:
53 const static uint64_t kCacheSize = 4 * 4096;
54 const static uint64_t kCacheSizeMask = ~(kCacheSize - 1);
55 static llvm::sys::SmartMutex<false> StreamerLock;
56
57 // Fetch up to kCacheSize worth of data starting from address, into the
58 // CacheBase. Returns true if there is an error.
59 bool fetchCacheLine(uint64_t address) const;
60
61 llvm::StreamingMemoryObject *Streamer;
62 // Cached data for addresses [CacheBase, CacheBase + kCacheSize)
63 mutable std::vector<unsigned char> Cache;
64 // The MemoryObject is at least this size. Used as a cache for isValidAddress.
65 mutable uint64_t MinObjectSize;
66 // Current base address for the cache.
67 mutable uint64_t CacheBase;
68
69 ThreadedStreamingCache(
70 const ThreadedStreamingCache&) LLVM_DELETED_FUNCTION;
71 void operator=(const ThreadedStreamingCache&) LLVM_DELETED_FUNCTION;
72 };
73
74 } // namespace llvm
75
76 #endif // THREADEDSTREAMINGCACHE_H
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698