1 //===-- TargetMachine.cpp - General Target Information ---------------------==//
3 // This file describes the general parts of a Target machine.
4 // This file also implements MachineInstrInfo and MachineCacheInfo.
6 //===----------------------------------------------------------------------===//
8 #include "llvm/Target/TargetMachine.h"
9 #include "llvm/Target/MachineInstrInfo.h"
10 #include "llvm/Target/MachineCacheInfo.h"
11 #include "llvm/DerivedTypes.h"
13 //---------------------------------------------------------------------------
14 // class TargetMachine
17 // Machine description.
19 //---------------------------------------------------------------------------
22 // function TargetMachine::findOptimalStorageSize
25 // This default implementation assumes that all sub-word data items use
26 // space equal to optSizeForSubWordData, and all other primitive data
27 // items use space according to the type.
30 TargetMachine::findOptimalStorageSize(const Type* ty) const
32 switch(ty->getPrimitiveID())
37 case Type::UShortTyID:
39 return optSizeForSubWordData;
42 return DataLayout.getTypeSize(ty);
47 //---------------------------------------------------------------------------
48 // class MachineInstructionInfo
49 // Interface to description of machine instructions
50 //---------------------------------------------------------------------------
54 MachineInstrInfo::MachineInstrInfo(const TargetMachine& tgt,
55 const MachineInstrDescriptor* _desc,
56 unsigned int _descSize,
57 unsigned int _numRealOpCodes)
59 desc(_desc), descSize(_descSize), numRealOpCodes(_numRealOpCodes)
61 // FIXME: TargetInstrDescriptors should not be global
62 assert(TargetInstrDescriptors == NULL && desc != NULL);
63 TargetInstrDescriptors = desc; // initialize global variable
67 MachineInstrInfo::~MachineInstrInfo()
69 TargetInstrDescriptors = NULL; // reset global variable
74 MachineInstrInfo::constantFitsInImmedField(MachineOpCode opCode,
75 int64_t intValue) const
77 // First, check if opCode has an immed field.
79 uint64_t maxImmedValue = maxImmedConstant(opCode, isSignExtended);
80 if (maxImmedValue != 0)
82 // Now check if the constant fits
83 if (intValue <= (int64_t) maxImmedValue &&
84 intValue >= -((int64_t) maxImmedValue+1))
92 //---------------------------------------------------------------------------
93 // class MachineCacheInfo
96 // Describes properties of the target cache architecture.
97 //---------------------------------------------------------------------------
100 MachineCacheInfo::MachineCacheInfo(const TargetMachine& tgt)
107 MachineCacheInfo::Initialize()
110 cacheLineSizes.push_back(16); cacheLineSizes.push_back(32);
111 cacheSizes.push_back(1 << 15); cacheSizes.push_back(1 << 20);
112 cacheAssoc.push_back(1); cacheAssoc.push_back(4);