Make this assertion more self-explanatory.
[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 DescSize,
28                                  unsigned NumRealOpCodes)
29   : desc(Desc), descSize(DescSize), numRealOpCodes(NumRealOpCodes) {
30   // FIXME: TargetInstrDescriptors should not be global
31   assert(TargetInstrDescriptors == NULL && desc != NULL
32          && "TargetMachine data structure corrupt; maybe you tried to create another TargetMachine? (only one may exist in a program)");
33   TargetInstrDescriptors = desc;        // initialize global variable
34 }
35
36 TargetInstrInfo::~TargetInstrInfo() {
37   TargetInstrDescriptors = NULL;        // reset global variable
38 }
39
40 bool TargetInstrInfo::constantFitsInImmedField(MachineOpCode opCode,
41                                                int64_t intValue) const {
42   // First, check if opCode has an immed field.
43   bool isSignExtended;
44   uint64_t maxImmedValue = maxImmedConstant(opCode, isSignExtended);
45   if (maxImmedValue != 0)
46     {
47       // NEED TO HANDLE UNSIGNED VALUES SINCE THEY MAY BECOME MUCH
48       // SMALLER AFTER CASTING TO SIGN-EXTENDED int, short, or char.
49       // See CreateUIntSetInstruction in SparcInstrInfo.cpp.
50       
51       // Now check if the constant fits
52       if (intValue <= (int64_t) maxImmedValue &&
53           intValue >= -((int64_t) maxImmedValue+1))
54         return true;
55     }
56   
57   return false;
58 }
59
60 bool TargetInstrInfo::ConstantTypeMustBeLoaded(const Constant* CV) const {
61   assert(CV->getType()->isPrimitiveType() || isa<PointerType>(CV->getType()));
62   return !(CV->getType()->isIntegral() || isa<PointerType>(CV->getType()));
63 }
64
65 } // End llvm namespace