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 | |
Vikram S. Adve | 0799fc4 | 2001-09-18 12:58:33 +0000 | [diff] [blame] | 8 | #include "llvm/Target/MachineInstrInfo.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 | 0799fc4 | 2001-09-18 12:58:33 +0000 | [diff] [blame] | 19 | |
Vikram S. Adve | 44a853c | 2001-07-28 04:09:37 +0000 | [diff] [blame] | 20 | // function TargetMachine::findOptimalStorageSize |
| 21 | // |
| 22 | // Purpose: |
Vikram S. Adve | 44a853c | 2001-07-28 04:09:37 +0000 | [diff] [blame] | 23 | // This default implementation assumes that all sub-word data items use |
| 24 | // space equal to optSizeForSubWordData, and all other primitive data |
| 25 | // items use space according to the type. |
| 26 | // |
Vikram S. Adve | 0799fc4 | 2001-09-18 12:58:33 +0000 | [diff] [blame] | 27 | unsigned int |
| 28 | TargetMachine::findOptimalStorageSize(const Type* ty) const |
| 29 | { |
| 30 | switch(ty->getPrimitiveID()) |
| 31 | { |
| 32 | case Type::BoolTyID: |
| 33 | case Type::UByteTyID: |
| 34 | case Type::SByteTyID: |
| 35 | case Type::UShortTyID: |
| 36 | case Type::ShortTyID: |
| 37 | return optSizeForSubWordData; |
Vikram S. Adve | daae699 | 2001-07-21 12:42:08 +0000 | [diff] [blame] | 38 | |
Vikram S. Adve | 0799fc4 | 2001-09-18 12:58:33 +0000 | [diff] [blame] | 39 | default: |
| 40 | return DataLayout.getTypeSize(ty); |
| 41 | } |
Vikram S. Adve | daae699 | 2001-07-21 12:42:08 +0000 | [diff] [blame] | 42 | } |
| 43 | |
Vikram S. Adve | 44a853c | 2001-07-28 04:09:37 +0000 | [diff] [blame] | 44 | |
| 45 | //--------------------------------------------------------------------------- |
| 46 | // class MachineInstructionInfo |
| 47 | // Interface to description of machine instructions |
| 48 | //--------------------------------------------------------------------------- |
| 49 | |
| 50 | |
| 51 | /*ctor*/ |
Vikram S. Adve | 7a2f1e7 | 2001-11-08 05:15:08 +0000 | [diff] [blame] | 52 | MachineInstrInfo::MachineInstrInfo(const TargetMachine& tgt, |
| 53 | const MachineInstrDescriptor* _desc, |
Vikram S. Adve | bf24233 | 2001-08-28 23:09:36 +0000 | [diff] [blame] | 54 | unsigned int _descSize, |
| 55 | unsigned int _numRealOpCodes) |
Vikram S. Adve | 7a2f1e7 | 2001-11-08 05:15:08 +0000 | [diff] [blame] | 56 | : target(tgt), |
| 57 | desc(_desc), descSize(_descSize), numRealOpCodes(_numRealOpCodes) |
Vikram S. Adve | 44a853c | 2001-07-28 04:09:37 +0000 | [diff] [blame] | 58 | { |
Chris Lattner | 78a81a2 | 2001-09-14 16:08:12 +0000 | [diff] [blame] | 59 | // FIXME: TargetInstrDescriptors should not be global |
Vikram S. Adve | 44a853c | 2001-07-28 04:09:37 +0000 | [diff] [blame] | 60 | assert(TargetInstrDescriptors == NULL && desc != NULL); |
| 61 | TargetInstrDescriptors = desc; // initialize global variable |
| 62 | } |
| 63 | |
| 64 | |
Vikram S. Adve | 0799fc4 | 2001-09-18 12:58:33 +0000 | [diff] [blame] | 65 | MachineInstrInfo::~MachineInstrInfo() |
| 66 | { |
Vikram S. Adve | 44a853c | 2001-07-28 04:09:37 +0000 | [diff] [blame] | 67 | TargetInstrDescriptors = NULL; // reset global variable |
| 68 | } |
| 69 | |
| 70 | |
| 71 | bool |
| 72 | MachineInstrInfo::constantFitsInImmedField(MachineOpCode opCode, |
| 73 | int64_t intValue) const |
| 74 | { |
| 75 | // First, check if opCode has an immed field. |
| 76 | bool isSignExtended; |
Chris Lattner | c763461 | 2001-09-14 15:43:58 +0000 | [diff] [blame] | 77 | uint64_t maxImmedValue = maxImmedConstant(opCode, isSignExtended); |
Vikram S. Adve | 0799fc4 | 2001-09-18 12:58:33 +0000 | [diff] [blame] | 78 | if (maxImmedValue != 0) |
| 79 | { |
| 80 | // Now check if the constant fits |
| 81 | if (intValue <= (int64_t) maxImmedValue && |
| 82 | intValue >= -((int64_t) maxImmedValue+1)) |
| 83 | return true; |
| 84 | } |
Vikram S. Adve | 44a853c | 2001-07-28 04:09:37 +0000 | [diff] [blame] | 85 | |
| 86 | return false; |
| 87 | } |