Adjust to change in TII ctor arguments
[oota-llvm.git] / lib / Target / TargetInstrInfo.cpp
1 //===-- TargetInstrInfo.cpp - Target Instruction Information --------------===//
2 // 
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
7 // 
8 //===----------------------------------------------------------------------===//
9 //
10 //
11 //===----------------------------------------------------------------------===//
12
13 #include "llvm/Target/TargetInstrInfo.h"
14 #include "llvm/CodeGen/MachineInstr.h"
15 #include "llvm/Constant.h"
16 #include "llvm/DerivedTypes.h"
17
18 namespace llvm {
19
20 // External object describing the machine instructions
21 // Initialized only when the TargetMachine class is created
22 // and reset when that class is destroyed.
23 // 
24 const TargetInstrDescriptor* TargetInstrDescriptors = 0;
25
26 TargetInstrInfo::TargetInstrInfo(const TargetInstrDescriptor* Desc,
27                                  unsigned numOpcodes)
28   : desc(Desc), NumOpcodes(numOpcodes) {
29   // FIXME: TargetInstrDescriptors should not be global
30   assert(TargetInstrDescriptors == NULL && desc != NULL
31          && "TargetMachine data structure corrupt; maybe you tried to create another TargetMachine? (only one may exist in a program)");
32   TargetInstrDescriptors = desc;        // initialize global variable
33 }
34
35 TargetInstrInfo::~TargetInstrInfo() {
36   TargetInstrDescriptors = NULL;        // reset global variable
37 }
38
39 bool TargetInstrInfo::constantFitsInImmedField(MachineOpCode opCode,
40                                                int64_t intValue) const {
41   // First, check if opCode has an immed field.
42   bool isSignExtended;
43   uint64_t maxImmedValue = maxImmedConstant(opCode, isSignExtended);
44   if (maxImmedValue != 0)
45     {
46       // NEED TO HANDLE UNSIGNED VALUES SINCE THEY MAY BECOME MUCH
47       // SMALLER AFTER CASTING TO SIGN-EXTENDED int, short, or char.
48       // See CreateUIntSetInstruction in SparcInstrInfo.cpp.
49       
50       // Now check if the constant fits
51       if (intValue <= (int64_t) maxImmedValue &&
52           intValue >= -((int64_t) maxImmedValue+1))
53         return true;
54     }
55   
56   return false;
57 }
58
59 bool TargetInstrInfo::ConstantTypeMustBeLoaded(const Constant* CV) const {
60   assert(CV->getType()->isPrimitiveType() || isa<PointerType>(CV->getType()));
61   return !(CV->getType()->isIntegral() || isa<PointerType>(CV->getType()));
62 }
63
64 } // End llvm namespace