Rename MachineInstrInfo -> TargetInstrInfo
[oota-llvm.git] / lib / Target / TargetInstrInfo.cpp
1 //===-- TargetInstrInfo.cpp - Target Instruction Information --------------===//
2 //
3 //
4 //===----------------------------------------------------------------------===//
5
6 #include "llvm/Target/TargetInstrInfo.h"
7 #include "llvm/CodeGen/MachineInstr.h"
8 #include "llvm/Constant.h"
9 #include "llvm/DerivedTypes.h"
10
11 // External object describing the machine instructions
12 // Initialized only when the TargetMachine class is created
13 // and reset when that class is destroyed.
14 // 
15 const TargetInstrDescriptor* TargetInstrDescriptors = 0;
16
17
18 TargetInstrInfo::TargetInstrInfo(const TargetInstrDescriptor* 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 TargetInstrInfo::~TargetInstrInfo() {
28   TargetInstrDescriptors = NULL;        // reset global variable
29 }
30
31 void TargetInstrInfo::print(const MachineInstr *MI, std::ostream &O,
32                             const TargetMachine &TM) const {
33   MI->print(O, TM);
34 }
35
36 bool TargetInstrInfo::constantFitsInImmedField(MachineOpCode opCode,
37                                                int64_t intValue) const {
38   // First, check if opCode has an immed field.
39   bool isSignExtended;
40   uint64_t maxImmedValue = maxImmedConstant(opCode, isSignExtended);
41   if (maxImmedValue != 0)
42     {
43       // NEED TO HANDLE UNSIGNED VALUES SINCE THEY MAY BECOME MUCH
44       // SMALLER AFTER CASTING TO SIGN-EXTENDED int, short, or char.
45       // See CreateUIntSetInstruction in SparcInstrInfo.cpp.
46       
47       // Now check if the constant fits
48       if (intValue <= (int64_t) maxImmedValue &&
49           intValue >= -((int64_t) maxImmedValue+1))
50         return true;
51     }
52   
53   return false;
54 }
55
56 bool TargetInstrInfo::ConstantTypeMustBeLoaded(const Constant* CV) const {
57   assert(CV->getType()->isPrimitiveType() || isa<PointerType>(CV->getType()));
58   return !(CV->getType()->isIntegral() || isa<PointerType>(CV->getType()));
59 }