blob: 330bed85ff30c7a986ebfdc085fecbcd32533349 [file] [log] [blame]
Sanjiv Gupta0e687712008-05-13 09:02:57 +00001//===-- PIC16.h - Top-level interface for PIC16 representation --*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
Sanjiv Gupta2d4e7f72008-05-14 06:50:01 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Sanjiv Gupta0e687712008-05-13 09:02:57 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file contains the entry points for global functions defined in
11// the LLVM PIC16 back-end.
12//
13//===----------------------------------------------------------------------===//
14
Sanjiv Guptab1b5ffd2008-11-19 11:00:54 +000015#ifndef LLVM_TARGET_PIC16_H
16#define LLVM_TARGET_PIC16_H
Sanjiv Gupta0e687712008-05-13 09:02:57 +000017
Bill Wendling98a366d2009-04-29 23:29:43 +000018#include "llvm/Target/TargetMachine.h"
Sanjiv Gupta1b046942009-01-13 19:18:47 +000019#include <iosfwd>
20#include <cassert>
Sanjiv Guptad8d27f42009-05-06 08:02:01 +000021#include <string>
Sanjiv Gupta1b046942009-01-13 19:18:47 +000022
Sanjiv Gupta0e687712008-05-13 09:02:57 +000023namespace llvm {
24 class PIC16TargetMachine;
Sanjiv Gupta0e687712008-05-13 09:02:57 +000025 class FunctionPass;
26 class MachineCodeEmitter;
Owen Andersoncb371882008-08-21 00:14:44 +000027 class raw_ostream;
Sanjiv Gupta0e687712008-05-13 09:02:57 +000028
Sanjiv Gupta1b046942009-01-13 19:18:47 +000029namespace PIC16CC {
30 enum CondCodes {
31 EQ,
32 NE,
33 LT,
34 LE,
35 GT,
Sanjiv Gupta08b9b052009-01-21 05:44:05 +000036 GE,
37 ULT,
38 UGT,
39 ULE,
40 UGE
Sanjiv Gupta1b046942009-01-13 19:18:47 +000041 };
42}
Sanjiv Guptad8d27f42009-05-06 08:02:01 +000043 // A Central object to manage all ABI naming conventions.
44 class PIC16ABINames {
45 public:
46 // Map the name of the symbol to its section name.
47 // Current ABI:
48 // ------------------------------------------------------
49 // Global variables do not have any '.' in their names.
50 // they are prefixed with @
51 // These are maily function names and global variable names.
52 // -------------------------------------------------------
53 // Functions and auto variables.
54 // Names are mangled as <prefix><funcname>.<id>.<varname>
55 // Where prefix is a special char '@' and id is any one of
56 // the following
57 // .auto. - an automatic var of a function.
58 // .temp. - temproray data of a function.
59 // .ret. - return value label for a function.
60 // .frame. - Frame label for a function where retval, args
61 // and temps are stored.
62 // .args. - Label used to pass arguments to a direct call.
63 // Example - Function name: @foo
64 // Its frame: @foo.frame.
65 // Its retval: @foo.ret.
66 // Its local vars: @foo.auto.a
67 // Its temp data: @foo.temp.
68 // Its arg passing: @foo.args.
69 //----------------------------------------------
70 // Libcall - compiler generated libcall names must have a .lib.
71 // This id will be used to emit extern decls for libcalls.
72 // Example - libcall name: @sra_i8.lib.
73 // To pass args: @sra_i8.args.
74 // To return val: @sra_i8.ret.
75 //----------------------------------------------
76
77 enum IDs {
78 PREFIX_SYMBOL,
79
80 FUNC_AUTOS,
81 FUNC_FRAME,
82 FUNC_RET,
83 FUNC_ARGS,
84 FUNC_TEMPS,
85
86 LIBCALL,
87
88 FRAME_SECTION,
89 AUTOS_SECTION
90 };
91
92 };
93
94 inline static const char *getIDName(PIC16ABINames::IDs id) {
95 switch (id) {
96 default: assert(0 && "Unknown id");
97 case PIC16ABINames::PREFIX_SYMBOL: return "@";
98 case PIC16ABINames::FUNC_AUTOS: return ".auto.";
99 case PIC16ABINames::FUNC_FRAME: return ".frame.";
100 case PIC16ABINames::FUNC_TEMPS: return ".temp.";
101 case PIC16ABINames::FUNC_ARGS: return ".args.";
102 case PIC16ABINames::FUNC_RET: return ".ret.";
103 case PIC16ABINames::FRAME_SECTION: return "fpdata";
104 case PIC16ABINames::AUTOS_SECTION: return "fadata";
105 }
106 }
107
108 inline static PIC16ABINames::IDs getID(const std::string &Sym) {
109 if (Sym.find(getIDName(PIC16ABINames::FUNC_TEMPS)))
110 return PIC16ABINames::FUNC_TEMPS;
111
112 if (Sym.find(getIDName(PIC16ABINames::FUNC_FRAME)))
113 return PIC16ABINames::FUNC_FRAME;
114
115 if (Sym.find(getIDName(PIC16ABINames::FUNC_RET)))
116 return PIC16ABINames::FUNC_RET;
117
118 if (Sym.find(getIDName(PIC16ABINames::FUNC_ARGS)))
119 return PIC16ABINames::FUNC_ARGS;
120
121 if (Sym.find(getIDName(PIC16ABINames::FUNC_AUTOS)))
122 return PIC16ABINames::FUNC_AUTOS;
123
124 if (Sym.find(getIDName(PIC16ABINames::LIBCALL)))
125 return PIC16ABINames::LIBCALL;
126
127 // It does not have any ID. So its a global.
128 assert (0 && "Could not determine ID symbol type");
129 }
130
Sanjiv Gupta1b046942009-01-13 19:18:47 +0000131
132 inline static const char *PIC16CondCodeToString(PIC16CC::CondCodes CC) {
133 switch (CC) {
134 default: assert(0 && "Unknown condition code");
135 case PIC16CC::NE: return "ne";
136 case PIC16CC::EQ: return "eq";
137 case PIC16CC::LT: return "lt";
Sanjiv Gupta08b9b052009-01-21 05:44:05 +0000138 case PIC16CC::ULT: return "lt";
Sanjiv Gupta1b046942009-01-13 19:18:47 +0000139 case PIC16CC::LE: return "le";
140 case PIC16CC::GT: return "gt";
Sanjiv Gupta08b9b052009-01-21 05:44:05 +0000141 case PIC16CC::UGT: return "gt";
Sanjiv Gupta1b046942009-01-13 19:18:47 +0000142 case PIC16CC::GE: return "ge";
143 }
144 }
145
Sanjiv Gupta08b9b052009-01-21 05:44:05 +0000146 inline static bool isSignedComparison(PIC16CC::CondCodes CC) {
147 switch (CC) {
148 default: assert(0 && "Unknown condition code");
149 case PIC16CC::NE:
150 case PIC16CC::EQ:
151 case PIC16CC::LT:
152 case PIC16CC::LE:
153 case PIC16CC::GE:
154 case PIC16CC::GT:
155 return true;
156 case PIC16CC::ULT:
157 case PIC16CC::UGT:
158 case PIC16CC::ULE:
159 case PIC16CC::UGE:
160 return false; // condition codes for unsigned comparison.
161 }
162 }
163
Sanjiv Gupta1b046942009-01-13 19:18:47 +0000164
Sanjiv Guptad8d27f42009-05-06 08:02:01 +0000165
Sanjiv Gupta0e687712008-05-13 09:02:57 +0000166 FunctionPass *createPIC16ISelDag(PIC16TargetMachine &TM);
Owen Andersoncb371882008-08-21 00:14:44 +0000167 FunctionPass *createPIC16CodePrinterPass(raw_ostream &OS,
Bill Wendling57f0db82009-02-24 08:30:20 +0000168 PIC16TargetMachine &TM,
Bill Wendling98a366d2009-04-29 23:29:43 +0000169 CodeGenOpt::Level OptLevel,
170 bool Verbose);
Sanjiv Guptad8d27f42009-05-06 08:02:01 +0000171 // Banksel optimzer pass.
172 FunctionPass *createPIC16MemSelOptimizerPass();
173 std::string getSectionNameForSym(const std::string &Sym);
Sanjiv Gupta0e687712008-05-13 09:02:57 +0000174} // end namespace llvm;
175
176// Defines symbolic names for PIC16 registers. This defines a mapping from
177// register name to register number.
178#include "PIC16GenRegisterNames.inc"
179
180// Defines symbolic names for the PIC16 instructions.
181#include "PIC16GenInstrNames.inc"
182
183#endif