Chris Lattner | a187ed9 | 2002-11-17 22:53:03 +0000 | [diff] [blame] | 1 | //===-- MachineInstrInfo.cpp - Target Instruction Information -------------===// |
Chris Lattner | 93fa705 | 2002-10-28 23:55:33 +0000 | [diff] [blame] | 2 | // |
Chris Lattner | 93fa705 | 2002-10-28 23:55:33 +0000 | [diff] [blame] | 3 | // |
| 4 | //===----------------------------------------------------------------------===// |
| 5 | |
| 6 | #include "llvm/Target/MachineInstrInfo.h" |
Chris Lattner | a187ed9 | 2002-11-17 22:53:03 +0000 | [diff] [blame] | 7 | #include "llvm/CodeGen/MachineInstr.h" |
Chris Lattner | 93fa705 | 2002-10-28 23:55:33 +0000 | [diff] [blame] | 8 | #include "llvm/Constant.h" |
| 9 | #include "llvm/DerivedTypes.h" |
| 10 | |
Chris Lattner | adc101b | 2002-10-29 17:37:48 +0000 | [diff] [blame] | 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 MachineInstrDescriptor* TargetInstrDescriptors = 0; |
| 16 | |
Chris Lattner | 93fa705 | 2002-10-28 23:55:33 +0000 | [diff] [blame] | 17 | //--------------------------------------------------------------------------- |
| 18 | // class MachineInstructionInfo |
| 19 | // Interface to description of machine instructions |
| 20 | //--------------------------------------------------------------------------- |
| 21 | |
| 22 | |
Chris Lattner | 047bbaf | 2002-10-29 15:45:20 +0000 | [diff] [blame] | 23 | MachineInstrInfo::MachineInstrInfo(const MachineInstrDescriptor* Desc, |
Chris Lattner | 93fa705 | 2002-10-28 23:55:33 +0000 | [diff] [blame] | 24 | unsigned DescSize, |
| 25 | unsigned NumRealOpCodes) |
Chris Lattner | 047bbaf | 2002-10-29 15:45:20 +0000 | [diff] [blame] | 26 | : desc(Desc), descSize(DescSize), numRealOpCodes(NumRealOpCodes) { |
Chris Lattner | 93fa705 | 2002-10-28 23:55:33 +0000 | [diff] [blame] | 27 | // FIXME: TargetInstrDescriptors should not be global |
| 28 | assert(TargetInstrDescriptors == NULL && desc != NULL); |
| 29 | TargetInstrDescriptors = desc; // initialize global variable |
| 30 | } |
| 31 | |
| 32 | MachineInstrInfo::~MachineInstrInfo() { |
| 33 | TargetInstrDescriptors = NULL; // reset global variable |
| 34 | } |
| 35 | |
Chris Lattner | 3b49394 | 2002-11-17 23:22:03 +0000 | [diff] [blame] | 36 | void MachineInstrInfo::print(const MachineInstr *MI, std::ostream &O, |
| 37 | const TargetMachine &TM) const { |
| 38 | MI->print(O, TM); |
Chris Lattner | a187ed9 | 2002-11-17 22:53:03 +0000 | [diff] [blame] | 39 | } |
Chris Lattner | 93fa705 | 2002-10-28 23:55:33 +0000 | [diff] [blame] | 40 | |
| 41 | bool MachineInstrInfo::constantFitsInImmedField(MachineOpCode opCode, |
| 42 | int64_t intValue) const { |
| 43 | // First, check if opCode has an immed field. |
| 44 | bool isSignExtended; |
| 45 | uint64_t maxImmedValue = maxImmedConstant(opCode, isSignExtended); |
| 46 | if (maxImmedValue != 0) |
| 47 | { |
| 48 | // NEED TO HANDLE UNSIGNED VALUES SINCE THEY MAY BECOME MUCH |
| 49 | // SMALLER AFTER CASTING TO SIGN-EXTENDED int, short, or char. |
| 50 | // See CreateUIntSetInstruction in SparcInstrInfo.cpp. |
| 51 | |
| 52 | // Now check if the constant fits |
| 53 | if (intValue <= (int64_t) maxImmedValue && |
| 54 | intValue >= -((int64_t) maxImmedValue+1)) |
| 55 | return true; |
| 56 | } |
| 57 | |
| 58 | return false; |
| 59 | } |
| 60 | |
| 61 | bool MachineInstrInfo::ConstantTypeMustBeLoaded(const Constant* CV) const { |
| 62 | assert(CV->getType()->isPrimitiveType() || isa<PointerType>(CV->getType())); |
| 63 | return !(CV->getType()->isIntegral() || isa<PointerType>(CV->getType())); |
| 64 | } |