Sparc.h revision 263763
1184610Salfred//===-- Sparc.h - Top-level interface for Sparc representation --*- C++ -*-===//
2184610Salfred//
3184610Salfred//                     The LLVM Compiler Infrastructure
4184610Salfred//
5184610Salfred// This file is distributed under the University of Illinois Open Source
6184610Salfred// License. See LICENSE.TXT for details.
7184610Salfred//
8184610Salfred//===----------------------------------------------------------------------===//
9184610Salfred//
10184610Salfred// This file contains the entry points for global functions defined in the LLVM
11184610Salfred// Sparc back-end.
12184610Salfred//
13184610Salfred//===----------------------------------------------------------------------===//
14184610Salfred
15184610Salfred#ifndef TARGET_SPARC_H
16184610Salfred#define TARGET_SPARC_H
17184610Salfred
18184610Salfred#include "MCTargetDesc/SparcMCTargetDesc.h"
19184610Salfred#include "llvm/Support/ErrorHandling.h"
20184610Salfred#include "llvm/Target/TargetMachine.h"
21184610Salfred
22184610Salfrednamespace llvm {
23184610Salfred  class FunctionPass;
24184610Salfred  class SparcTargetMachine;
25184610Salfred  class formatted_raw_ostream;
26184610Salfred  class AsmPrinter;
27184610Salfred  class MCInst;
28184610Salfred  class MachineInstr;
29184610Salfred
30184610Salfred  FunctionPass *createSparcISelDag(SparcTargetMachine &TM);
31184610Salfred  FunctionPass *createSparcDelaySlotFillerPass(TargetMachine &TM);
32184610Salfred  FunctionPass *createSparcJITCodeEmitterPass(SparcTargetMachine &TM,
33184610Salfred                                              JITCodeEmitter &JCE);
34184610Salfred
35190754Sthompsa  void LowerSparcMachineInstrToMCInst(const MachineInstr *MI,
36184610Salfred                                      MCInst &OutMI,
37184610Salfred                                      AsmPrinter &AP);
38194677Sthompsa} // end namespace llvm;
39194677Sthompsa
40194677Sthompsanamespace llvm {
41194677Sthompsa  // Enums corresponding to Sparc condition codes, both icc's and fcc's.  These
42194677Sthompsa  // values must be kept in sync with the ones in the .td file.
43194677Sthompsa  namespace SPCC {
44194677Sthompsa    enum CondCodes {
45194677Sthompsa      //ICC_A   =  8   ,  // Always
46194677Sthompsa      //ICC_N   =  0   ,  // Never
47194677Sthompsa      ICC_NE  =  9   ,  // Not Equal
48194677Sthompsa      ICC_E   =  1   ,  // Equal
49194677Sthompsa      ICC_G   = 10   ,  // Greater
50194677Sthompsa      ICC_LE  =  2   ,  // Less or Equal
51194677Sthompsa      ICC_GE  = 11   ,  // Greater or Equal
52194677Sthompsa      ICC_L   =  3   ,  // Less
53194677Sthompsa      ICC_GU  = 12   ,  // Greater Unsigned
54194677Sthompsa      ICC_LEU =  4   ,  // Less or Equal Unsigned
55194677Sthompsa      ICC_CC  = 13   ,  // Carry Clear/Great or Equal Unsigned
56194677Sthompsa      ICC_CS  =  5   ,  // Carry Set/Less Unsigned
57188942Sthompsa      ICC_POS = 14   ,  // Positive
58194677Sthompsa      ICC_NEG =  6   ,  // Negative
59184610Salfred      ICC_VC  = 15   ,  // Overflow Clear
60184610Salfred      ICC_VS  =  7   ,  // Overflow Set
61184610Salfred
62188942Sthompsa      //FCC_A   =  8+16,  // Always
63188942Sthompsa      //FCC_N   =  0+16,  // Never
64188942Sthompsa      FCC_U   =  7+16,  // Unordered
65188942Sthompsa      FCC_G   =  6+16,  // Greater
66188942Sthompsa      FCC_UG  =  5+16,  // Unordered or Greater
67188942Sthompsa      FCC_L   =  4+16,  // Less
68188942Sthompsa      FCC_UL  =  3+16,  // Unordered or Less
69188942Sthompsa      FCC_LG  =  2+16,  // Less or Greater
70184610Salfred      FCC_NE  =  1+16,  // Not Equal
71188942Sthompsa      FCC_E   =  9+16,  // Equal
72188942Sthompsa      FCC_UE  = 10+16,  // Unordered or Equal
73188942Sthompsa      FCC_GE  = 11+16,  // Greater or Equal
74198151Sthompsa      FCC_UGE = 12+16,  // Unordered or Greater or Equal
75184610Salfred      FCC_LE  = 13+16,  // Less or Equal
76190181Sthompsa      FCC_ULE = 14+16,  // Unordered or Less or Equal
77190181Sthompsa      FCC_O   = 15+16   // Ordered
78190181Sthompsa    };
79184610Salfred  }
80194677Sthompsa
81184610Salfred  inline static const char *SPARCCondCodeToString(SPCC::CondCodes CC) {
82184610Salfred    switch (CC) {
83227309Sed    case SPCC::ICC_NE:  return "ne";
84192502Sthompsa    case SPCC::ICC_E:   return "e";
85184610Salfred    case SPCC::ICC_G:   return "g";
86199675Sthompsa    case SPCC::ICC_LE:  return "le";
87199675Sthompsa    case SPCC::ICC_GE:  return "ge";
88199675Sthompsa    case SPCC::ICC_L:   return "l";
89184610Salfred    case SPCC::ICC_GU:  return "gu";
90184610Salfred    case SPCC::ICC_LEU: return "leu";
91184610Salfred    case SPCC::ICC_CC:  return "cc";
92184610Salfred    case SPCC::ICC_CS:  return "cs";
93184610Salfred    case SPCC::ICC_POS: return "pos";
94184610Salfred    case SPCC::ICC_NEG: return "neg";
95184610Salfred    case SPCC::ICC_VC:  return "vc";
96184610Salfred    case SPCC::ICC_VS:  return "vs";
97184610Salfred    case SPCC::FCC_U:   return "u";
98184610Salfred    case SPCC::FCC_G:   return "g";
99184610Salfred    case SPCC::FCC_UG:  return "ug";
100184610Salfred    case SPCC::FCC_L:   return "l";
101184610Salfred    case SPCC::FCC_UL:  return "ul";
102184610Salfred    case SPCC::FCC_LG:  return "lg";
103184610Salfred    case SPCC::FCC_NE:  return "ne";
104184610Salfred    case SPCC::FCC_E:   return "e";
105184610Salfred    case SPCC::FCC_UE:  return "ue";
106184610Salfred    case SPCC::FCC_GE:  return "ge";
107184610Salfred    case SPCC::FCC_UGE: return "uge";
108184610Salfred    case SPCC::FCC_LE:  return "le";
109184610Salfred    case SPCC::FCC_ULE: return "ule";
110184610Salfred    case SPCC::FCC_O:   return "o";
111184610Salfred    }
112192984Sthompsa    llvm_unreachable("Invalid cond code");
113192984Sthompsa  }
114192984Sthompsa
115192984Sthompsa  inline static unsigned HI22(int64_t imm) {
116192984Sthompsa    return (unsigned)((imm >> 10) & ((1 << 22)-1));
117184610Salfred  }
118192984Sthompsa
119193045Sthompsa  inline static unsigned LO10(int64_t imm) {
120184610Salfred    return (unsigned)(imm & 0x3FF);
121192984Sthompsa  }
122190735Sthompsa
123184610Salfred  inline static unsigned HIX22(int64_t imm) {
124184610Salfred    return HI22(~imm);
125192984Sthompsa  }
126184610Salfred
127184610Salfred  inline static unsigned LOX10(int64_t imm) {
128184610Salfred    return ~LO10(~imm);
129184610Salfred  }
130184610Salfred
131184610Salfred}  // end namespace llvm
132184610Salfred#endif
133184610Salfred