Chris Lattner | b26bcc5 | 2001-09-14 05:34:53 +0000 | [diff] [blame] | 1 | //===-- TargetMachine.cpp - General Target Information ---------------------==// |
| 2 | // |
| 3 | // This file describes the general parts of a Target machine. |
Chris Lattner | c763461 | 2001-09-14 15:43:58 +0000 | [diff] [blame^] | 4 | // This file also implements the InstInfo interface as well... |
Chris Lattner | b26bcc5 | 2001-09-14 05:34:53 +0000 | [diff] [blame] | 5 | // |
| 6 | //===----------------------------------------------------------------------===// |
Vikram S. Adve | daae699 | 2001-07-21 12:42:08 +0000 | [diff] [blame] | 7 | |
Chris Lattner | c763461 | 2001-09-14 15:43:58 +0000 | [diff] [blame^] | 8 | #include "llvm/Target/InstInfo.h" |
Chris Lattner | 68498ce | 2001-07-21 23:24:48 +0000 | [diff] [blame] | 9 | #include "llvm/DerivedTypes.h" |
Vikram S. Adve | daae699 | 2001-07-21 12:42:08 +0000 | [diff] [blame] | 10 | |
Vikram S. Adve | daae699 | 2001-07-21 12:42:08 +0000 | [diff] [blame] | 11 | //--------------------------------------------------------------------------- |
Vikram S. Adve | 44a853c | 2001-07-28 04:09:37 +0000 | [diff] [blame] | 12 | // class TargetMachine |
Vikram S. Adve | daae699 | 2001-07-21 12:42:08 +0000 | [diff] [blame] | 13 | // |
| 14 | // Purpose: |
Vikram S. Adve | 44a853c | 2001-07-28 04:09:37 +0000 | [diff] [blame] | 15 | // Machine description. |
| 16 | // |
Vikram S. Adve | daae699 | 2001-07-21 12:42:08 +0000 | [diff] [blame] | 17 | //--------------------------------------------------------------------------- |
| 18 | |
Vikram S. Adve | 44a853c | 2001-07-28 04:09:37 +0000 | [diff] [blame] | 19 | // function TargetMachine::findOptimalStorageSize |
| 20 | // |
| 21 | // Purpose: |
Vikram S. Adve | 44a853c | 2001-07-28 04:09:37 +0000 | [diff] [blame] | 22 | // This default implementation assumes that all sub-word data items use |
| 23 | // space equal to optSizeForSubWordData, and all other primitive data |
| 24 | // items use space according to the type. |
| 25 | // |
Chris Lattner | 3a13c7e | 2001-08-27 15:50:41 +0000 | [diff] [blame] | 26 | unsigned int TargetMachine::findOptimalStorageSize(const Type* ty) const { |
| 27 | switch(ty->getPrimitiveID()) { |
| 28 | case Type::BoolTyID: |
| 29 | case Type::UByteTyID: |
| 30 | case Type::SByteTyID: |
| 31 | case Type::UShortTyID: |
| 32 | case Type::ShortTyID: |
| 33 | return optSizeForSubWordData; |
Vikram S. Adve | daae699 | 2001-07-21 12:42:08 +0000 | [diff] [blame] | 34 | |
Chris Lattner | 3a13c7e | 2001-08-27 15:50:41 +0000 | [diff] [blame] | 35 | default: |
| 36 | return DataLayout.getTypeSize(ty); |
| 37 | } |
Vikram S. Adve | daae699 | 2001-07-21 12:42:08 +0000 | [diff] [blame] | 38 | } |
| 39 | |
Vikram S. Adve | 44a853c | 2001-07-28 04:09:37 +0000 | [diff] [blame] | 40 | |
| 41 | //--------------------------------------------------------------------------- |
| 42 | // class MachineInstructionInfo |
| 43 | // Interface to description of machine instructions |
| 44 | //--------------------------------------------------------------------------- |
| 45 | |
| 46 | |
| 47 | /*ctor*/ |
| 48 | MachineInstrInfo::MachineInstrInfo(const MachineInstrDescriptor* _desc, |
Vikram S. Adve | bf24233 | 2001-08-28 23:09:36 +0000 | [diff] [blame] | 49 | unsigned int _descSize, |
| 50 | unsigned int _numRealOpCodes) |
| 51 | : desc(_desc), descSize(_descSize), numRealOpCodes(_numRealOpCodes) |
Vikram S. Adve | 44a853c | 2001-07-28 04:09:37 +0000 | [diff] [blame] | 52 | { |
| 53 | assert(TargetInstrDescriptors == NULL && desc != NULL); |
| 54 | TargetInstrDescriptors = desc; // initialize global variable |
| 55 | } |
| 56 | |
| 57 | |
Chris Lattner | c763461 | 2001-09-14 15:43:58 +0000 | [diff] [blame^] | 58 | MachineInstrInfo::~MachineInstrInfo() { |
Vikram S. Adve | 44a853c | 2001-07-28 04:09:37 +0000 | [diff] [blame] | 59 | TargetInstrDescriptors = NULL; // reset global variable |
| 60 | } |
| 61 | |
| 62 | |
| 63 | bool |
| 64 | MachineInstrInfo::constantFitsInImmedField(MachineOpCode opCode, |
| 65 | int64_t intValue) const |
| 66 | { |
| 67 | // First, check if opCode has an immed field. |
| 68 | bool isSignExtended; |
Chris Lattner | c763461 | 2001-09-14 15:43:58 +0000 | [diff] [blame^] | 69 | uint64_t maxImmedValue = maxImmedConstant(opCode, isSignExtended); |
| 70 | if (maxImmedValue != 0) { |
| 71 | // Now check if the constant fits |
| 72 | if (intValue <= (int64_t) maxImmedValue && |
| 73 | intValue >= -((int64_t) maxImmedValue+1)) |
| 74 | return true; |
| 75 | } |
Vikram S. Adve | 44a853c | 2001-07-28 04:09:37 +0000 | [diff] [blame] | 76 | |
| 77 | return false; |
| 78 | } |