blob: 9038a4db85ad937581c9a5a775931c953e626e13 [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:
17 case Type::UByteTyID: return LDUB;
18 case Type::SByteTyID: return LDSB;
19 case Type::UShortTyID: return LDUH;
20 case Type::ShortTyID: return LDSH;
21 case Type::UIntTyID: return LDUW;
22 case Type::IntTyID: return LDSW;
23 case Type::PointerTyID:
24 case Type::ULongTyID:
25 case Type::LongTyID: return LDX;
26 case Type::FloatTyID: return LD;
27 case Type::DoubleTyID: return LDD;
28 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:
40 case Type::SByteTyID: return STB;
41 case Type::UShortTyID:
42 case Type::ShortTyID: return STH;
43 case Type::UIntTyID:
44 case Type::IntTyID: return STW;
45 case Type::PointerTyID:
46 case Type::ULongTyID:
47 case Type::LongTyID: return STX;
48 case Type::FloatTyID: return ST;
49 case Type::DoubleTyID: return STD;
50 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{
60 MachineOpCode opCode = INVALID_OPCODE;
61
62 if (resultType->isIntegral() ||
63 isa<PointerType>(resultType) ||
64 isa<FunctionType>(resultType) ||
Chris Lattnerb0b412e2002-09-03 01:08:28 +000065 resultType == Type::LabelTy)
Vikram S. Advee9327f02002-05-19 15:25:51 +000066 {
67 opCode = ADD;
68 }
69 else
70 switch(resultType->getPrimitiveID())
71 {
72 case Type::FloatTyID: opCode = FADDS; break;
73 case Type::DoubleTyID: opCode = FADDD; break;
74 default: assert(0 && "Invalid type for ADD instruction"); break;
75 }
76
77 return opCode;
78}
79
Chris Lattner7f74a562002-01-20 22:54:45 +000080#endif