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