MachineInstrInfo doesn't need a TargetMachine
[oota-llvm.git] / lib / Target / TargetInstrInfo.cpp
1 //===-- TargetMachine.cpp - General Target Information ---------------------==//
2 //
3 // This file describes the general parts of a Target machine.
4 // This file also implements MachineInstrInfo and MachineCacheInfo.
5 //
6 //===----------------------------------------------------------------------===//
7
8 #include "llvm/Target/MachineInstrInfo.h"
9 #include "llvm/Constant.h"
10 #include "llvm/DerivedTypes.h"
11
12 //---------------------------------------------------------------------------
13 // class MachineInstructionInfo
14 //      Interface to description of machine instructions
15 //---------------------------------------------------------------------------
16
17
18 MachineInstrInfo::MachineInstrInfo(const MachineInstrDescriptor* Desc,
19                                    unsigned DescSize,
20                                    unsigned NumRealOpCodes)
21   : desc(Desc), descSize(DescSize), numRealOpCodes(NumRealOpCodes) {
22   // FIXME: TargetInstrDescriptors should not be global
23   assert(TargetInstrDescriptors == NULL && desc != NULL);
24   TargetInstrDescriptors = desc;        // initialize global variable
25 }
26
27 MachineInstrInfo::~MachineInstrInfo() {
28   TargetInstrDescriptors = NULL;        // reset global variable
29 }
30
31
32 bool MachineInstrInfo::constantFitsInImmedField(MachineOpCode opCode,
33                                                 int64_t intValue) const {
34   // First, check if opCode has an immed field.
35   bool isSignExtended;
36   uint64_t maxImmedValue = maxImmedConstant(opCode, isSignExtended);
37   if (maxImmedValue != 0)
38     {
39       // NEED TO HANDLE UNSIGNED VALUES SINCE THEY MAY BECOME MUCH
40       // SMALLER AFTER CASTING TO SIGN-EXTENDED int, short, or char.
41       // See CreateUIntSetInstruction in SparcInstrInfo.cpp.
42       
43       // Now check if the constant fits
44       if (intValue <= (int64_t) maxImmedValue &&
45           intValue >= -((int64_t) maxImmedValue+1))
46         return true;
47     }
48   
49   return false;
50 }
51
52 bool MachineInstrInfo::ConstantTypeMustBeLoaded(const Constant* CV) const {
53   assert(CV->getType()->isPrimitiveType() || isa<PointerType>(CV->getType()));
54   return !(CV->getType()->isIntegral() || isa<PointerType>(CV->getType()));
55 }