Vikram S. Adve | cc776df | 2001-10-18 00:03:20 +0000 | [diff] [blame] | 1 | // $Id$ -*-c++-*- |
| 2 | //*************************************************************************** |
| 3 | // File: |
| 4 | // SparcInstrSelectionSupport.h |
| 5 | // |
| 6 | // Purpose: |
| 7 | // |
| 8 | // History: |
| 9 | // 10/17/01 - Vikram Adve - Created |
| 10 | //**************************************************************************/ |
| 11 | |
| 12 | #ifndef SPARC_INSTR_SELECTION_SUPPORT_h |
| 13 | #define SPARC_INSTR_SELECTION_SUPPORT_h |
| 14 | |
Vikram S. Adve | e9327f0 | 2002-05-19 15:25:51 +0000 | [diff] [blame^] | 15 | #include "llvm/DerivedTypes.h" |
| 16 | #include "llvm/Value.h" |
Vikram S. Adve | cc776df | 2001-10-18 00:03:20 +0000 | [diff] [blame] | 17 | |
| 18 | inline MachineOpCode |
| 19 | ChooseLoadInstruction(const Type *DestTy) |
| 20 | { |
| 21 | switch (DestTy->getPrimitiveID()) { |
| 22 | case Type::BoolTyID: |
| 23 | case Type::UByteTyID: return LDUB; |
| 24 | case Type::SByteTyID: return LDSB; |
| 25 | case Type::UShortTyID: return LDUH; |
| 26 | case Type::ShortTyID: return LDSH; |
| 27 | case Type::UIntTyID: return LDUW; |
| 28 | case Type::IntTyID: return LDSW; |
| 29 | case Type::PointerTyID: |
| 30 | case Type::ULongTyID: |
| 31 | case Type::LongTyID: return LDX; |
| 32 | case Type::FloatTyID: return LD; |
| 33 | case Type::DoubleTyID: return LDD; |
| 34 | default: assert(0 && "Invalid type for Load instruction"); |
| 35 | } |
| 36 | |
| 37 | return 0; |
| 38 | } |
| 39 | |
| 40 | |
| 41 | inline MachineOpCode |
| 42 | ChooseStoreInstruction(const Type *DestTy) |
| 43 | { |
| 44 | switch (DestTy->getPrimitiveID()) { |
| 45 | case Type::BoolTyID: |
| 46 | case Type::UByteTyID: |
| 47 | case Type::SByteTyID: return STB; |
| 48 | case Type::UShortTyID: |
| 49 | case Type::ShortTyID: return STH; |
| 50 | case Type::UIntTyID: |
| 51 | case Type::IntTyID: return STW; |
| 52 | case Type::PointerTyID: |
| 53 | case Type::ULongTyID: |
| 54 | case Type::LongTyID: return STX; |
| 55 | case Type::FloatTyID: return ST; |
| 56 | case Type::DoubleTyID: return STD; |
| 57 | default: assert(0 && "Invalid type for Store instruction"); |
| 58 | } |
| 59 | |
| 60 | return 0; |
| 61 | } |
| 62 | |
Vikram S. Adve | e9327f0 | 2002-05-19 15:25:51 +0000 | [diff] [blame^] | 63 | |
| 64 | inline MachineOpCode |
| 65 | ChooseAddInstructionByType(const Type* resultType) |
| 66 | { |
| 67 | MachineOpCode opCode = INVALID_OPCODE; |
| 68 | |
| 69 | if (resultType->isIntegral() || |
| 70 | isa<PointerType>(resultType) || |
| 71 | isa<FunctionType>(resultType) || |
| 72 | resultType == Type::LabelTy || |
| 73 | resultType == Type::BoolTy) |
| 74 | { |
| 75 | opCode = ADD; |
| 76 | } |
| 77 | else |
| 78 | switch(resultType->getPrimitiveID()) |
| 79 | { |
| 80 | case Type::FloatTyID: opCode = FADDS; break; |
| 81 | case Type::DoubleTyID: opCode = FADDD; break; |
| 82 | default: assert(0 && "Invalid type for ADD instruction"); break; |
| 83 | } |
| 84 | |
| 85 | return opCode; |
| 86 | } |
| 87 | |
Chris Lattner | 7f74a56 | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 88 | #endif |