aboutsummaryrefslogtreecommitdiffstats
path: root/include/llvm/Target/TargetCacheInfo.h
blob: 21436d09fce4ca392ffa5fec448277bdf0a6ea12 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// $Id$ -*-c++-*-
//***************************************************************************
// File:
//	MachineCacheInfo.h
// 
// Purpose:
//      Describes properties of the target cache architecture.
//**************************************************************************/

#ifndef LLVM_TARGET_MACHINECACHEINFO_H
#define LLVM_TARGET_MACHINECACHEINFO_H

#include "llvm/Target/TargetMachine.h"
#include "Support/DataTypes.h"
#include <vector>


//---------------------------------------------------------------------------
// class MachineCacheInfo 
// 
// Purpose:
//   Describes properties of the target cache architecture.
//---------------------------------------------------------------------------

class MachineCacheInfo : public NonCopyableV {
public:
  const TargetMachine& target;
  
protected:
  unsigned int           numLevels;
  vector<unsigned short> cacheLineSizes;
  vector<unsigned int>   cacheSizes;
  vector<unsigned short> cacheAssoc;
  
public:
  /*ctor*/          MachineCacheInfo    (const TargetMachine& tgt);
  /*dtor*/ virtual ~MachineCacheInfo    () {}
  
  // Default parameters are:
  //    NumLevels    = 2
  //    L1: LineSize 16, Cache Size 32KB, Direct-mapped (assoc = 1)
  //    L2: LineSize 32, Cache Size 1 MB, 4-way associative
  // NOTE: Cache levels are numbered from 1 as above, not from 0.
  // 
  virtual  void     Initialize          (); // subclass to override defaults
  
  unsigned int      getNumCacheLevels   () const {
    return numLevels;
  }
  unsigned short    getCacheLineSize    (unsigned level)  const {
    assert(level <= cacheLineSizes.size() && "Invalid cache level");
    return cacheLineSizes[level-1];
  }
  unsigned int      getCacheSize        (unsigned level)  const {
    assert(level <= cacheSizes.size() && "Invalid cache level");
    return cacheSizes[level-1];
  }
  unsigned short    getCacheAssoc       (unsigned level)  const {
    assert(level <= cacheAssoc.size() && "Invalid cache level");
    return cacheAssoc[level];
  }
};


//---------------------------------------------------------------------------

#endif