Bug fix: need to initialize new CallArgsDescriptor pointer.
[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 // External object describing the machine instructions
13 // Initialized only when the TargetMachine class is created
14 // and reset when that class is destroyed.
15 // 
16 const MachineInstrDescriptor* TargetInstrDescriptors = 0;
17
18 //---------------------------------------------------------------------------
19 // class MachineInstructionInfo
20 //      Interface to description of machine instructions
21 //---------------------------------------------------------------------------
22
23
24 MachineInstrInfo::MachineInstrInfo(const MachineInstrDescriptor* Desc,
25                                    unsigned DescSize,
26                                    unsigned NumRealOpCodes)
27   : desc(Desc), descSize(DescSize), numRealOpCodes(NumRealOpCodes) {
28   // FIXME: TargetInstrDescriptors should not be global
29   assert(TargetInstrDescriptors == NULL && desc != NULL);
30   TargetInstrDescriptors = desc;        // initialize global variable
31 }
32
33 MachineInstrInfo::~MachineInstrInfo() {
34   TargetInstrDescriptors = NULL;        // reset global variable
35 }
36
37
38 bool MachineInstrInfo::constantFitsInImmedField(MachineOpCode opCode,
39                                                 int64_t intValue) const {
40   // First, check if opCode has an immed field.
41   bool isSignExtended;
42   uint64_t maxImmedValue = maxImmedConstant(opCode, isSignExtended);
43   if (maxImmedValue != 0)
44     {
45       // NEED TO HANDLE UNSIGNED VALUES SINCE THEY MAY BECOME MUCH
46       // SMALLER AFTER CASTING TO SIGN-EXTENDED int, short, or char.
47       // See CreateUIntSetInstruction in SparcInstrInfo.cpp.
48       
49       // Now check if the constant fits
50       if (intValue <= (int64_t) maxImmedValue &&
51           intValue >= -((int64_t) maxImmedValue+1))
52         return true;
53     }
54   
55   return false;
56 }
57
58 bool MachineInstrInfo::ConstantTypeMustBeLoaded(const Constant* CV) const {
59   assert(CV->getType()->isPrimitiveType() || isa<PointerType>(CV->getType()));
60   return !(CV->getType()->isIntegral() || isa<PointerType>(CV->getType()));
61 }