2008-05-13 11:02:57 +02:00
|
|
|
//===-- PIC16.h - Top-level interface for PIC16 representation --*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2008-05-14 08:50:01 +02:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2008-05-13 11:02:57 +02:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file contains the entry points for global functions defined in
|
|
|
|
// the LLVM PIC16 back-end.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2008-11-19 12:00:54 +01:00
|
|
|
#ifndef LLVM_TARGET_PIC16_H
|
|
|
|
#define LLVM_TARGET_PIC16_H
|
2008-05-13 11:02:57 +02:00
|
|
|
|
2009-07-11 22:10:48 +02:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2009-04-30 01:29:43 +02:00
|
|
|
#include "llvm/Target/TargetMachine.h"
|
2009-01-13 20:18:47 +01:00
|
|
|
#include <iosfwd>
|
|
|
|
#include <cassert>
|
2009-05-10 07:23:47 +02:00
|
|
|
#include <sstream>
|
2009-05-08 08:22:25 +02:00
|
|
|
#include <cstring>
|
2009-05-06 10:02:01 +02:00
|
|
|
#include <string>
|
2009-01-13 20:18:47 +01:00
|
|
|
|
2008-05-13 11:02:57 +02:00
|
|
|
namespace llvm {
|
|
|
|
class PIC16TargetMachine;
|
|
|
|
class FunctionPass;
|
|
|
|
class MachineCodeEmitter;
|
2008-08-21 02:14:44 +02:00
|
|
|
class raw_ostream;
|
2008-05-13 11:02:57 +02:00
|
|
|
|
2009-01-13 20:18:47 +01:00
|
|
|
namespace PIC16CC {
|
|
|
|
enum CondCodes {
|
|
|
|
EQ,
|
|
|
|
NE,
|
|
|
|
LT,
|
|
|
|
LE,
|
|
|
|
GT,
|
2009-01-21 06:44:05 +01:00
|
|
|
GE,
|
|
|
|
ULT,
|
|
|
|
UGT,
|
|
|
|
ULE,
|
|
|
|
UGE
|
2009-01-13 20:18:47 +01:00
|
|
|
};
|
|
|
|
}
|
2009-05-10 07:23:47 +02:00
|
|
|
// A Central class to manage all ABI naming conventions.
|
|
|
|
// PAN - [P]ic16 [A]BI [N]ames
|
|
|
|
class PAN {
|
2009-05-06 10:02:01 +02:00
|
|
|
public:
|
|
|
|
// Map the name of the symbol to its section name.
|
|
|
|
// Current ABI:
|
2009-05-10 07:23:47 +02:00
|
|
|
// -----------------------------------------------------
|
|
|
|
// ALL Names are prefixed with the symobl '@'.
|
2009-05-06 10:02:01 +02:00
|
|
|
// ------------------------------------------------------
|
|
|
|
// Global variables do not have any '.' in their names.
|
|
|
|
// These are maily function names and global variable names.
|
2009-05-10 07:23:47 +02:00
|
|
|
// Example - @foo, @i
|
2009-05-06 10:02:01 +02:00
|
|
|
// -------------------------------------------------------
|
|
|
|
// Functions and auto variables.
|
2009-05-10 07:23:47 +02:00
|
|
|
// Names are mangled as <prefix><funcname>.<tag>.<varname>
|
|
|
|
// Where <prefix> is '@' and <tag> is any one of
|
2009-05-06 10:02:01 +02:00
|
|
|
// the following
|
|
|
|
// .auto. - an automatic var of a function.
|
|
|
|
// .temp. - temproray data of a function.
|
|
|
|
// .ret. - return value label for a function.
|
|
|
|
// .frame. - Frame label for a function where retval, args
|
|
|
|
// and temps are stored.
|
|
|
|
// .args. - Label used to pass arguments to a direct call.
|
|
|
|
// Example - Function name: @foo
|
|
|
|
// Its frame: @foo.frame.
|
|
|
|
// Its retval: @foo.ret.
|
|
|
|
// Its local vars: @foo.auto.a
|
|
|
|
// Its temp data: @foo.temp.
|
|
|
|
// Its arg passing: @foo.args.
|
|
|
|
//----------------------------------------------
|
2009-05-11 10:52:04 +02:00
|
|
|
// Libcall - compiler generated libcall names must start with .lib.
|
2009-05-06 10:02:01 +02:00
|
|
|
// This id will be used to emit extern decls for libcalls.
|
2009-05-11 10:52:04 +02:00
|
|
|
// Example - libcall name: @.lib.sra.i8
|
|
|
|
// To pass args: @.lib.sra.i8.args.
|
|
|
|
// To return val: @.lib.sra.i8.ret.
|
2009-05-06 10:02:01 +02:00
|
|
|
//----------------------------------------------
|
2009-05-10 07:23:47 +02:00
|
|
|
// SECTION Names
|
|
|
|
// uninitialized globals - @udata.<num>.#
|
|
|
|
// initialized globals - @idata.<num>.#
|
|
|
|
// Function frame - @<func>.frame_section.
|
|
|
|
// Function autos - @<func>.autos_section.
|
2009-07-06 10:22:15 +02:00
|
|
|
// Declarations - Enclosed in comments. No section for them.
|
2009-05-10 07:23:47 +02:00
|
|
|
//----------------------------------------------------------
|
2009-05-06 10:02:01 +02:00
|
|
|
|
2009-05-10 07:23:47 +02:00
|
|
|
// Tags used to mangle different names.
|
|
|
|
enum TAGS {
|
2009-05-06 10:02:01 +02:00
|
|
|
PREFIX_SYMBOL,
|
2009-05-10 07:23:47 +02:00
|
|
|
GLOBAL,
|
|
|
|
STATIC_LOCAL,
|
|
|
|
AUTOS_LABEL,
|
|
|
|
FRAME_LABEL,
|
|
|
|
RET_LABEL,
|
|
|
|
ARGS_LABEL,
|
|
|
|
TEMPS_LABEL,
|
2009-05-06 10:02:01 +02:00
|
|
|
|
|
|
|
LIBCALL,
|
|
|
|
|
|
|
|
FRAME_SECTION,
|
2009-05-10 07:23:47 +02:00
|
|
|
AUTOS_SECTION,
|
|
|
|
CODE_SECTION
|
2009-05-08 06:50:14 +02:00
|
|
|
};
|
|
|
|
|
2009-05-10 07:23:47 +02:00
|
|
|
// Textual names of the tags.
|
|
|
|
inline static const char *getTagName(TAGS tag) {
|
|
|
|
switch (tag) {
|
|
|
|
default: return "";
|
2009-05-08 06:50:14 +02:00
|
|
|
case PREFIX_SYMBOL: return "@";
|
2009-05-10 07:23:47 +02:00
|
|
|
case AUTOS_LABEL: return ".auto.";
|
|
|
|
case FRAME_LABEL: return ".frame.";
|
|
|
|
case TEMPS_LABEL: return ".temp.";
|
|
|
|
case ARGS_LABEL: return ".args.";
|
|
|
|
case RET_LABEL: return ".ret.";
|
2009-05-11 10:52:04 +02:00
|
|
|
case LIBCALL: return ".lib.";
|
|
|
|
case FRAME_SECTION: return ".frame_section.";
|
|
|
|
case AUTOS_SECTION: return ".autos_section.";
|
|
|
|
case CODE_SECTION: return ".code_section.";
|
2009-05-08 06:50:14 +02:00
|
|
|
}
|
|
|
|
}
|
2009-05-06 10:02:01 +02:00
|
|
|
|
2009-05-10 07:23:47 +02:00
|
|
|
// Get tag type for the Symbol.
|
|
|
|
inline static TAGS getSymbolTag(const std::string &Sym) {
|
|
|
|
if (Sym.find(getTagName(TEMPS_LABEL)) != std::string::npos)
|
|
|
|
return TEMPS_LABEL;
|
2009-05-08 06:50:14 +02:00
|
|
|
|
2009-05-10 07:23:47 +02:00
|
|
|
if (Sym.find(getTagName(FRAME_LABEL)) != std::string::npos)
|
|
|
|
return FRAME_LABEL;
|
2009-05-08 06:50:14 +02:00
|
|
|
|
2009-05-10 07:23:47 +02:00
|
|
|
if (Sym.find(getTagName(RET_LABEL)) != std::string::npos)
|
|
|
|
return RET_LABEL;
|
2009-05-08 06:50:14 +02:00
|
|
|
|
2009-05-10 07:23:47 +02:00
|
|
|
if (Sym.find(getTagName(ARGS_LABEL)) != std::string::npos)
|
|
|
|
return ARGS_LABEL;
|
2009-05-08 06:50:14 +02:00
|
|
|
|
2009-05-10 07:23:47 +02:00
|
|
|
if (Sym.find(getTagName(AUTOS_LABEL)) != std::string::npos)
|
|
|
|
return AUTOS_LABEL;
|
2009-05-08 06:50:14 +02:00
|
|
|
|
2009-05-10 07:23:47 +02:00
|
|
|
if (Sym.find(getTagName(LIBCALL)) != std::string::npos)
|
2009-05-08 06:50:14 +02:00
|
|
|
return LIBCALL;
|
2009-05-06 10:02:01 +02:00
|
|
|
|
2009-05-10 07:23:47 +02:00
|
|
|
// It does not have any Tag. So its a true global or static local.
|
|
|
|
if (Sym.find(".") == std::string::npos)
|
|
|
|
return GLOBAL;
|
|
|
|
|
|
|
|
// If a . is there, then it may be static local.
|
|
|
|
// We should mangle these as well in clang.
|
|
|
|
if (Sym.find(".") != std::string::npos)
|
|
|
|
return STATIC_LOCAL;
|
|
|
|
|
|
|
|
assert (0 && "Could not determine Symbol's tag");
|
2009-07-03 18:11:34 +02:00
|
|
|
return PREFIX_SYMBOL; // Silence warning when assertions are turned off.
|
2009-05-10 07:23:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// addPrefix - add prefix symbol to a name if there isn't one already.
|
|
|
|
inline static std::string addPrefix (const std::string &Name) {
|
|
|
|
std::string prefix = getTagName (PREFIX_SYMBOL);
|
|
|
|
|
|
|
|
// If this name already has a prefix, nothing to do.
|
|
|
|
if (Name.compare(0, prefix.size(), prefix) == 0)
|
|
|
|
return Name;
|
|
|
|
|
|
|
|
return prefix + Name;
|
2009-05-06 10:02:01 +02:00
|
|
|
}
|
|
|
|
|
2009-05-10 07:23:47 +02:00
|
|
|
// Get mangled func name from a mangled sym name.
|
2009-05-08 06:50:14 +02:00
|
|
|
// In all cases func name is the first component before a '.'.
|
2009-05-10 07:23:47 +02:00
|
|
|
static inline std::string getFuncNameForSym(const std::string &Sym1) {
|
|
|
|
assert (getSymbolTag(Sym1) != GLOBAL && "not belongs to a function");
|
2009-05-08 06:50:14 +02:00
|
|
|
|
2009-05-10 07:23:47 +02:00
|
|
|
std::string Sym = addPrefix(Sym1);
|
2009-05-06 10:02:01 +02:00
|
|
|
|
2009-05-08 06:50:14 +02:00
|
|
|
// Position of the . after func name. That's where func name ends.
|
2009-05-10 07:23:47 +02:00
|
|
|
size_t func_name_end = Sym.find ('.');
|
|
|
|
|
|
|
|
return Sym.substr (0, func_name_end);
|
|
|
|
}
|
2009-05-06 10:02:01 +02:00
|
|
|
|
2009-05-10 07:23:47 +02:00
|
|
|
// Get Frame start label for a func.
|
|
|
|
static std::string getFrameLabel(const std::string &Func) {
|
|
|
|
std::string Func1 = addPrefix(Func);
|
|
|
|
std::string tag = getTagName(FRAME_LABEL);
|
|
|
|
return Func1 + tag;
|
2009-05-08 06:50:14 +02:00
|
|
|
}
|
2009-05-06 10:02:01 +02:00
|
|
|
|
2009-05-10 07:23:47 +02:00
|
|
|
static std::string getRetvalLabel(const std::string &Func) {
|
|
|
|
std::string Func1 = addPrefix(Func);
|
|
|
|
std::string tag = getTagName(RET_LABEL);
|
|
|
|
return Func1 + tag;
|
2009-05-08 06:50:14 +02:00
|
|
|
}
|
2009-05-06 10:02:01 +02:00
|
|
|
|
2009-05-10 07:23:47 +02:00
|
|
|
static std::string getArgsLabel(const std::string &Func) {
|
|
|
|
std::string Func1 = addPrefix(Func);
|
|
|
|
std::string tag = getTagName(ARGS_LABEL);
|
|
|
|
return Func1 + tag;
|
|
|
|
}
|
|
|
|
|
|
|
|
static std::string getTempdataLabel(const std::string &Func) {
|
|
|
|
std::string Func1 = addPrefix(Func);
|
|
|
|
std::string tag = getTagName(TEMPS_LABEL);
|
|
|
|
return Func1 + tag;
|
|
|
|
}
|
|
|
|
|
|
|
|
static std::string getFrameSectionName(const std::string &Func) {
|
|
|
|
std::string Func1 = addPrefix(Func);
|
|
|
|
std::string tag = getTagName(FRAME_SECTION);
|
2009-05-11 10:52:04 +02:00
|
|
|
return Func1 + tag + "# UDATA_OVR";
|
2009-05-10 07:23:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static std::string getAutosSectionName(const std::string &Func) {
|
|
|
|
std::string Func1 = addPrefix(Func);
|
|
|
|
std::string tag = getTagName(AUTOS_SECTION);
|
2009-05-11 10:52:04 +02:00
|
|
|
return Func1 + tag + "# UDATA_OVR";
|
2009-05-10 07:23:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static std::string getCodeSectionName(const std::string &Func) {
|
|
|
|
std::string Func1 = addPrefix(Func);
|
|
|
|
std::string tag = getTagName(CODE_SECTION);
|
2009-05-11 10:52:04 +02:00
|
|
|
return Func1 + tag + "# CODE";
|
2009-05-10 07:23:47 +02:00
|
|
|
}
|
|
|
|
|
2009-07-06 12:18:37 +02:00
|
|
|
// udata, romdata and idata section names are generated by a given number.
|
2009-05-10 07:23:47 +02:00
|
|
|
// @udata.<num>.#
|
2009-07-06 12:18:37 +02:00
|
|
|
static std::string getUdataSectionName(unsigned num,
|
|
|
|
std::string prefix = "") {
|
2009-05-10 07:23:47 +02:00
|
|
|
std::ostringstream o;
|
2009-07-06 12:18:37 +02:00
|
|
|
o << getTagName(PREFIX_SYMBOL) << prefix << "udata." << num
|
|
|
|
<< ".# UDATA";
|
2009-05-10 07:23:47 +02:00
|
|
|
return o.str();
|
|
|
|
}
|
|
|
|
|
2009-07-06 12:18:37 +02:00
|
|
|
static std::string getRomdataSectionName(unsigned num,
|
|
|
|
std::string prefix = "") {
|
2009-05-10 07:23:47 +02:00
|
|
|
std::ostringstream o;
|
2009-07-06 12:18:37 +02:00
|
|
|
o << getTagName(PREFIX_SYMBOL) << prefix << "romdata." << num
|
|
|
|
<< ".# ROMDATA";
|
|
|
|
return o.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
static std::string getIdataSectionName(unsigned num,
|
|
|
|
std::string prefix = "") {
|
|
|
|
std::ostringstream o;
|
|
|
|
o << getTagName(PREFIX_SYMBOL) << prefix << "idata." << num
|
|
|
|
<< ".# IDATA";
|
2009-05-10 07:23:47 +02:00
|
|
|
return o.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline static bool isLocalName (const std::string &Name) {
|
|
|
|
if (getSymbolTag(Name) == AUTOS_LABEL)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline static bool isLocalToFunc (std::string &Func, std::string &Var) {
|
|
|
|
if (! isLocalName(Var)) return false;
|
|
|
|
|
|
|
|
std::string Func1 = addPrefix(Func);
|
|
|
|
// Extract func name of the varilable.
|
|
|
|
const std::string &fname = getFuncNameForSym(Var);
|
|
|
|
|
|
|
|
if (fname.compare(Func1) == 0)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-05-08 06:50:14 +02:00
|
|
|
// Get the section for the given external symbol names.
|
2009-05-10 07:23:47 +02:00
|
|
|
// This tries to find the type (Tag) of the symbol from its mangled name
|
2009-05-08 06:50:14 +02:00
|
|
|
// and return appropriate section name for it.
|
2009-05-10 07:23:47 +02:00
|
|
|
static inline std::string getSectionNameForSym(const std::string &Sym1) {
|
|
|
|
std::string Sym = addPrefix(Sym1);
|
|
|
|
|
2009-05-08 06:50:14 +02:00
|
|
|
std::string SectionName;
|
|
|
|
|
|
|
|
std::string Fname = getFuncNameForSym (Sym);
|
2009-05-10 07:23:47 +02:00
|
|
|
TAGS id = getSymbolTag (Sym);
|
2009-05-08 06:50:14 +02:00
|
|
|
|
|
|
|
switch (id) {
|
|
|
|
default : assert (0 && "Could not determine external symbol type");
|
2009-05-10 07:23:47 +02:00
|
|
|
case FRAME_LABEL:
|
|
|
|
case RET_LABEL:
|
|
|
|
case TEMPS_LABEL:
|
|
|
|
case ARGS_LABEL: {
|
|
|
|
return getFrameSectionName(Fname);
|
2009-05-08 06:50:14 +02:00
|
|
|
}
|
2009-05-10 07:23:47 +02:00
|
|
|
case AUTOS_LABEL: {
|
|
|
|
return getAutosSectionName(Fname);
|
2009-05-08 06:50:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-05-10 07:23:47 +02:00
|
|
|
}; // class PAN.
|
|
|
|
|
|
|
|
|
|
|
|
// External symbol names require memory to live till the program end.
|
|
|
|
// So we have to allocate it and keep.
|
|
|
|
inline static const char *createESName (const std::string &name) {
|
|
|
|
char *tmpName = new char[name.size() + 1];
|
|
|
|
strcpy (tmpName, name.c_str());
|
|
|
|
return tmpName;
|
|
|
|
}
|
2009-05-06 10:02:01 +02:00
|
|
|
|
|
|
|
|
2009-01-13 20:18:47 +01:00
|
|
|
|
|
|
|
inline static const char *PIC16CondCodeToString(PIC16CC::CondCodes CC) {
|
|
|
|
switch (CC) {
|
2009-07-11 22:10:48 +02:00
|
|
|
default: LLVM_UNREACHABLE("Unknown condition code");
|
2009-01-13 20:18:47 +01:00
|
|
|
case PIC16CC::NE: return "ne";
|
|
|
|
case PIC16CC::EQ: return "eq";
|
|
|
|
case PIC16CC::LT: return "lt";
|
2009-01-21 06:44:05 +01:00
|
|
|
case PIC16CC::ULT: return "lt";
|
2009-01-13 20:18:47 +01:00
|
|
|
case PIC16CC::LE: return "le";
|
2009-06-03 15:36:44 +02:00
|
|
|
case PIC16CC::ULE: return "le";
|
2009-01-13 20:18:47 +01:00
|
|
|
case PIC16CC::GT: return "gt";
|
2009-01-21 06:44:05 +01:00
|
|
|
case PIC16CC::UGT: return "gt";
|
2009-01-13 20:18:47 +01:00
|
|
|
case PIC16CC::GE: return "ge";
|
2009-06-03 15:36:44 +02:00
|
|
|
case PIC16CC::UGE: return "ge";
|
2009-01-13 20:18:47 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-21 06:44:05 +01:00
|
|
|
inline static bool isSignedComparison(PIC16CC::CondCodes CC) {
|
|
|
|
switch (CC) {
|
2009-07-11 22:10:48 +02:00
|
|
|
default: LLVM_UNREACHABLE("Unknown condition code");
|
2009-01-21 06:44:05 +01:00
|
|
|
case PIC16CC::NE:
|
|
|
|
case PIC16CC::EQ:
|
|
|
|
case PIC16CC::LT:
|
|
|
|
case PIC16CC::LE:
|
|
|
|
case PIC16CC::GE:
|
|
|
|
case PIC16CC::GT:
|
|
|
|
return true;
|
|
|
|
case PIC16CC::ULT:
|
|
|
|
case PIC16CC::UGT:
|
|
|
|
case PIC16CC::ULE:
|
|
|
|
case PIC16CC::UGE:
|
|
|
|
return false; // condition codes for unsigned comparison.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-13 20:18:47 +01:00
|
|
|
|
2009-05-06 10:02:01 +02:00
|
|
|
|
2008-05-13 11:02:57 +02:00
|
|
|
FunctionPass *createPIC16ISelDag(PIC16TargetMachine &TM);
|
2008-08-21 02:14:44 +02:00
|
|
|
FunctionPass *createPIC16CodePrinterPass(raw_ostream &OS,
|
2009-02-24 09:30:20 +01:00
|
|
|
PIC16TargetMachine &TM,
|
2009-04-30 01:29:43 +02:00
|
|
|
bool Verbose);
|
2009-05-06 10:02:01 +02:00
|
|
|
// Banksel optimzer pass.
|
|
|
|
FunctionPass *createPIC16MemSelOptimizerPass();
|
2008-05-13 11:02:57 +02:00
|
|
|
} // end namespace llvm;
|
|
|
|
|
|
|
|
// Defines symbolic names for PIC16 registers. This defines a mapping from
|
|
|
|
// register name to register number.
|
|
|
|
#include "PIC16GenRegisterNames.inc"
|
|
|
|
|
|
|
|
// Defines symbolic names for the PIC16 instructions.
|
|
|
|
#include "PIC16GenInstrNames.inc"
|
|
|
|
|
|
|
|
#endif
|