blob: 2ee92945b7c5aef5765cf107d14019610f1eb83c [file] [log] [blame]
Vikram S. Advecc776df2001-10-18 00:03:20 +00001// $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. Advee9327f02002-05-19 15:25:51 +000015#include "llvm/DerivedTypes.h"
16#include "llvm/Value.h"
Vikram S. Advecc776df2001-10-18 00:03:20 +000017
18inline MachineOpCode
19ChooseLoadInstruction(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
41inline MachineOpCode
42ChooseStoreInstruction(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. Advee9327f02002-05-19 15:25:51 +000063
64inline MachineOpCode
65ChooseAddInstructionByType(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 Lattner7f74a562002-01-20 22:54:45 +000088#endif