blob: aea482e9274e941293eb4e13a1cd5c8b5ed7eba7 [file] [log] [blame]
Chris Lattner959a5fb2002-08-09 20:08:06 +00001//===-- llvm/CodeGen/SparcInstrSelectionSupport.h ---------------*- C++ -*-===//
2//
3//
4//
5//===----------------------------------------------------------------------===//
Vikram S. Advecc776df2001-10-18 00:03:20 +00006
7#ifndef SPARC_INSTR_SELECTION_SUPPORT_h
8#define SPARC_INSTR_SELECTION_SUPPORT_h
9
Vikram S. Advee9327f02002-05-19 15:25:51 +000010#include "llvm/DerivedTypes.h"
Vikram S. Advecc776df2001-10-18 00:03:20 +000011
12inline MachineOpCode
13ChooseLoadInstruction(const Type *DestTy)
14{
15 switch (DestTy->getPrimitiveID()) {
16 case Type::BoolTyID:
Misha Brukman56f4fa12003-05-20 20:32:24 +000017 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. Advecc776df2001-10-18 00:03:20 +000023 case Type::PointerTyID:
24 case Type::ULongTyID:
Misha Brukman56f4fa12003-05-20 20:32:24 +000025 case Type::LongTyID: return V9::LDX;
26 case Type::FloatTyID: return V9::LD;
27 case Type::DoubleTyID: return V9::LDD;
Vikram S. Advecc776df2001-10-18 00:03:20 +000028 default: assert(0 && "Invalid type for Load instruction");
29 }
30
31 return 0;
32}
33
Vikram S. Advecc776df2001-10-18 00:03:20 +000034inline MachineOpCode
35ChooseStoreInstruction(const Type *DestTy)
36{
37 switch (DestTy->getPrimitiveID()) {
38 case Type::BoolTyID:
39 case Type::UByteTyID:
Misha Brukman56f4fa12003-05-20 20:32:24 +000040 case Type::SByteTyID: return V9::STB;
Vikram S. Advecc776df2001-10-18 00:03:20 +000041 case Type::UShortTyID:
Misha Brukman56f4fa12003-05-20 20:32:24 +000042 case Type::ShortTyID: return V9::STH;
Vikram S. Advecc776df2001-10-18 00:03:20 +000043 case Type::UIntTyID:
Misha Brukman56f4fa12003-05-20 20:32:24 +000044 case Type::IntTyID: return V9::STW;
Vikram S. Advecc776df2001-10-18 00:03:20 +000045 case Type::PointerTyID:
46 case Type::ULongTyID:
Misha Brukman56f4fa12003-05-20 20:32:24 +000047 case Type::LongTyID: return V9::STX;
48 case Type::FloatTyID: return V9::ST;
49 case Type::DoubleTyID: return V9::STD;
Vikram S. Advecc776df2001-10-18 00:03:20 +000050 default: assert(0 && "Invalid type for Store instruction");
51 }
52
53 return 0;
54}
55
Vikram S. Advee9327f02002-05-19 15:25:51 +000056
57inline MachineOpCode
58ChooseAddInstructionByType(const Type* resultType)
59{
Misha Brukman56f4fa12003-05-20 20:32:24 +000060 MachineOpCode opCode = V9::INVALID_OPCODE;
Vikram S. Advee9327f02002-05-19 15:25:51 +000061
62 if (resultType->isIntegral() ||
63 isa<PointerType>(resultType) ||
64 isa<FunctionType>(resultType) ||
Chris Lattnerb0b412e2002-09-03 01:08:28 +000065 resultType == Type::LabelTy)
Misha Brukman56f4fa12003-05-20 20:32:24 +000066 {
67 opCode = V9::ADD;
68 }
Vikram S. Advee9327f02002-05-19 15:25:51 +000069 else
70 switch(resultType->getPrimitiveID())
Misha Brukman56f4fa12003-05-20 20:32:24 +000071 {
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. Advee9327f02002-05-19 15:25:51 +000076
77 return opCode;
78}
79
Chris Lattner7f74a562002-01-20 22:54:45 +000080#endif