Seperate code out of TargetMachine into MachineInstrInfo
[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 TargetMachine& tgt,
19                                    const MachineInstrDescriptor* Desc,
20                                    unsigned DescSize,
21                                    unsigned NumRealOpCodes)
22   : target(tgt), desc(Desc), descSize(DescSize), numRealOpCodes(NumRealOpCodes) {
23   // FIXME: TargetInstrDescriptors should not be global
24   assert(TargetInstrDescriptors == NULL && desc != NULL);
25   TargetInstrDescriptors = desc;        // initialize global variable
26 }
27
28 MachineInstrInfo::~MachineInstrInfo() {
29   TargetInstrDescriptors = NULL;        // reset global variable
30 }
31
32
33 bool MachineInstrInfo::constantFitsInImmedField(MachineOpCode opCode,
34                                                 int64_t intValue) const {
35   // First, check if opCode has an immed field.
36   bool isSignExtended;
37   uint64_t maxImmedValue = maxImmedConstant(opCode, isSignExtended);
38   if (maxImmedValue != 0)
39     {
40       // NEED TO HANDLE UNSIGNED VALUES SINCE THEY MAY BECOME MUCH
41       // SMALLER AFTER CASTING TO SIGN-EXTENDED int, short, or char.
42       // See CreateUIntSetInstruction in SparcInstrInfo.cpp.
43       
44       // Now check if the constant fits
45       if (intValue <= (int64_t) maxImmedValue &&
46           intValue >= -((int64_t) maxImmedValue+1))
47         return true;
48     }
49   
50   return false;
51 }
52
53 bool MachineInstrInfo::ConstantTypeMustBeLoaded(const Constant* CV) const {
54   assert(CV->getType()->isPrimitiveType() || isa<PointerType>(CV->getType()));
55   return !(CV->getType()->isIntegral() || isa<PointerType>(CV->getType()));
56 }