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