Added LLVM project notice to the top of every C++ source file.
[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 // External object describing the machine instructions
19 // Initialized only when the TargetMachine class is created
20 // and reset when that class is destroyed.
21 // 
22 const TargetInstrDescriptor* TargetInstrDescriptors = 0;
23
24
25 TargetInstrInfo::TargetInstrInfo(const TargetInstrDescriptor* Desc,
26                                  unsigned DescSize,
27                                  unsigned NumRealOpCodes)
28   : desc(Desc), descSize(DescSize), numRealOpCodes(NumRealOpCodes) {
29   // FIXME: TargetInstrDescriptors should not be global
30   assert(TargetInstrDescriptors == NULL && desc != NULL);
31   TargetInstrDescriptors = desc;        // initialize global variable
32 }
33
34 TargetInstrInfo::~TargetInstrInfo() {
35   TargetInstrDescriptors = NULL;        // reset global variable
36 }
37
38 bool TargetInstrInfo::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 TargetInstrInfo::ConstantTypeMustBeLoaded(const Constant* CV) const {
59   assert(CV->getType()->isPrimitiveType() || isa<PointerType>(CV->getType()));
60   return !(CV->getType()->isIntegral() || isa<PointerType>(CV->getType()));
61 }