Included assert.h so that the code compiles under newer versions of GCC.
[oota-llvm.git] / include / llvm / Target / TargetCacheInfo.h
1 //===-- llvm/Target/TargetCacheInfo.h ---------------------------*- C++ -*-===//
2 //
3 //  Describes properties of the target cache architecture.
4 //
5 //===----------------------------------------------------------------------===//
6
7 #ifndef LLVM_TARGET_TARGETCACHEINFO_H
8 #define LLVM_TARGET_TARGETCACHEINFO_H
9
10 #include "Support/DataTypes.h"
11 #include <assert.h>
12
13 class TargetMachine;
14
15 struct TargetCacheInfo {
16   const TargetMachine &target;
17   TargetCacheInfo(const TargetCacheInfo&); // DO NOT IMPLEMENT
18   void operator=(const TargetCacheInfo&);  // DO NOT IMPLEMENT
19 protected:
20   unsigned int           numLevels;
21   std::vector<unsigned short> cacheLineSizes;
22   std::vector<unsigned int>   cacheSizes;
23   std::vector<unsigned short> cacheAssoc;
24   
25 public:
26   TargetCacheInfo(const TargetMachine& tgt) : target(tgt) {
27     Initialize();
28   }
29   virtual ~TargetCacheInfo() {}
30   
31   // Default parameters are:
32   //    NumLevels    = 2
33   //    L1: LineSize 16, Cache Size 32KB, Direct-mapped (assoc = 1)
34   //    L2: LineSize 32, Cache Size 1 MB, 4-way associative
35   // NOTE: Cache levels are numbered from 1 as above, not from 0.
36   // 
37   virtual  void     Initialize          (); // subclass to override defaults
38   
39   unsigned int      getNumCacheLevels   () const {
40     return numLevels;
41   }
42   unsigned short    getCacheLineSize    (unsigned level)  const {
43     assert(level <= cacheLineSizes.size() && "Invalid cache level");
44     return cacheLineSizes[level-1];
45   }
46   unsigned int      getCacheSize        (unsigned level)  const {
47     assert(level <= cacheSizes.size() && "Invalid cache level");
48     return cacheSizes[level-1];
49   }
50   unsigned short    getCacheAssoc       (unsigned level)  const {
51     assert(level <= cacheAssoc.size() && "Invalid cache level");
52     return cacheAssoc[level];
53   }
54 };
55
56 #endif