Vikram S. Adve | daae699 | 2001-07-21 12:42:08 +0000 | [diff] [blame] | 1 | // $Id$ |
| 2 | //*************************************************************************** |
| 3 | // File: |
| 4 | // TargetMachine.cpp |
| 5 | // |
| 6 | // Purpose: |
| 7 | // |
| 8 | // History: |
| 9 | // 7/12/01 - Vikram Adve - Created |
| 10 | //**************************************************************************/ |
| 11 | |
| 12 | |
Vikram S. Adve | daae699 | 2001-07-21 12:42:08 +0000 | [diff] [blame] | 13 | //*************************** User Include Files ***************************/ |
| 14 | |
Chris Lattner | 7e583cf | 2001-07-21 20:58:30 +0000 | [diff] [blame] | 15 | #include "llvm/CodeGen/TargetMachine.h" |
Chris Lattner | 68498ce | 2001-07-21 23:24:48 +0000 | [diff] [blame] | 16 | #include "llvm/DerivedTypes.h" |
Vikram S. Adve | daae699 | 2001-07-21 12:42:08 +0000 | [diff] [blame] | 17 | |
Vikram S. Adve | 44a853c | 2001-07-28 04:09:37 +0000 | [diff] [blame] | 18 | //************************ Exported Constants ******************************/ |
| 19 | |
| 20 | |
| 21 | // External object describing the machine instructions |
| 22 | // Initialized only when the TargetMachine class is created |
| 23 | // and reset when that class is destroyed. |
| 24 | // |
| 25 | const MachineInstrDescriptor* TargetInstrDescriptors = NULL; |
| 26 | |
Vikram S. Adve | daae699 | 2001-07-21 12:42:08 +0000 | [diff] [blame] | 27 | |
| 28 | //************************ Class Implementations **************************/ |
| 29 | |
Vikram S. Adve | daae699 | 2001-07-21 12:42:08 +0000 | [diff] [blame] | 30 | //--------------------------------------------------------------------------- |
Vikram S. Adve | 44a853c | 2001-07-28 04:09:37 +0000 | [diff] [blame] | 31 | // class TargetMachine |
Vikram S. Adve | daae699 | 2001-07-21 12:42:08 +0000 | [diff] [blame] | 32 | // |
| 33 | // Purpose: |
Vikram S. Adve | 44a853c | 2001-07-28 04:09:37 +0000 | [diff] [blame] | 34 | // Machine description. |
| 35 | // |
Vikram S. Adve | daae699 | 2001-07-21 12:42:08 +0000 | [diff] [blame] | 36 | //--------------------------------------------------------------------------- |
| 37 | |
Vikram S. Adve | 44a853c | 2001-07-28 04:09:37 +0000 | [diff] [blame] | 38 | |
| 39 | // function TargetMachine::findOptimalStorageSize |
| 40 | // |
| 41 | // Purpose: |
Vikram S. Adve | 44a853c | 2001-07-28 04:09:37 +0000 | [diff] [blame] | 42 | // This default implementation assumes that all sub-word data items use |
| 43 | // space equal to optSizeForSubWordData, and all other primitive data |
| 44 | // items use space according to the type. |
| 45 | // |
Chris Lattner | 3a13c7e | 2001-08-27 15:50:41 +0000 | [diff] [blame^] | 46 | unsigned int TargetMachine::findOptimalStorageSize(const Type* ty) const { |
| 47 | switch(ty->getPrimitiveID()) { |
| 48 | case Type::BoolTyID: |
| 49 | case Type::UByteTyID: |
| 50 | case Type::SByteTyID: |
| 51 | case Type::UShortTyID: |
| 52 | case Type::ShortTyID: |
| 53 | return optSizeForSubWordData; |
Vikram S. Adve | daae699 | 2001-07-21 12:42:08 +0000 | [diff] [blame] | 54 | |
Chris Lattner | 3a13c7e | 2001-08-27 15:50:41 +0000 | [diff] [blame^] | 55 | default: |
| 56 | return DataLayout.getTypeSize(ty); |
| 57 | } |
Vikram S. Adve | daae699 | 2001-07-21 12:42:08 +0000 | [diff] [blame] | 58 | } |
| 59 | |
Vikram S. Adve | 44a853c | 2001-07-28 04:09:37 +0000 | [diff] [blame] | 60 | |
| 61 | //--------------------------------------------------------------------------- |
| 62 | // class MachineInstructionInfo |
| 63 | // Interface to description of machine instructions |
| 64 | //--------------------------------------------------------------------------- |
| 65 | |
| 66 | |
| 67 | /*ctor*/ |
| 68 | MachineInstrInfo::MachineInstrInfo(const MachineInstrDescriptor* _desc, |
| 69 | unsigned int _descSize) |
| 70 | : desc(_desc), descSize(_descSize) |
| 71 | { |
| 72 | assert(TargetInstrDescriptors == NULL && desc != NULL); |
| 73 | TargetInstrDescriptors = desc; // initialize global variable |
| 74 | } |
| 75 | |
| 76 | |
| 77 | /*dtor*/ |
| 78 | MachineInstrInfo::~MachineInstrInfo() |
| 79 | { |
| 80 | TargetInstrDescriptors = NULL; // reset global variable |
| 81 | } |
| 82 | |
| 83 | |
| 84 | bool |
| 85 | MachineInstrInfo::constantFitsInImmedField(MachineOpCode opCode, |
| 86 | int64_t intValue) const |
| 87 | { |
| 88 | // First, check if opCode has an immed field. |
| 89 | bool isSignExtended; |
| 90 | uint64_t maxImmedValue = this->maxImmedConstant(opCode, isSignExtended); |
| 91 | if (maxImmedValue != 0) |
| 92 | { |
| 93 | // Now check if the constant fits |
| 94 | if (intValue <= (int64_t) maxImmedValue && |
| 95 | intValue >= -((int64_t) maxImmedValue+1)) |
| 96 | return true; |
| 97 | } |
| 98 | |
| 99 | return false; |
| 100 | } |
| 101 | |
Vikram S. Adve | daae699 | 2001-07-21 12:42:08 +0000 | [diff] [blame] | 102 | //--------------------------------------------------------------------------- |