2003-10-05 21:27:59 +02:00
|
|
|
//===- RegisterInfoEmitter.cpp - Generate a Register File Desc. -*- C++ -*-===//
|
2005-04-22 02:00:37 +02:00
|
|
|
//
|
2003-10-20 22:20:30 +02:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 21:37:13 +01:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-22 02:00:37 +02:00
|
|
|
//
|
2003-10-20 22:20:30 +02:00
|
|
|
//===----------------------------------------------------------------------===//
|
2003-10-05 21:27:59 +02:00
|
|
|
//
|
|
|
|
// This tablegen backend is responsible for emitting a description of a target
|
|
|
|
// register file for a code generator. It uses instances of the Register,
|
|
|
|
// RegisterAliases, and RegisterClass classes to gather this information.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "RegisterInfoEmitter.h"
|
2004-08-01 06:04:35 +02:00
|
|
|
#include "CodeGenTarget.h"
|
2004-08-16 03:10:21 +02:00
|
|
|
#include "CodeGenRegisters.h"
|
2011-10-01 18:41:13 +02:00
|
|
|
#include "llvm/TableGen/Record.h"
|
2011-07-23 02:47:49 +02:00
|
|
|
#include "llvm/ADT/BitVector.h"
|
2004-09-02 00:55:40 +02:00
|
|
|
#include "llvm/ADT/StringExtras.h"
|
|
|
|
#include "llvm/ADT/STLExtras.h"
|
2011-06-12 09:04:26 +02:00
|
|
|
#include "llvm/Support/Format.h"
|
2008-04-15 23:27:11 +02:00
|
|
|
#include <algorithm>
|
2009-07-03 02:10:29 +02:00
|
|
|
#include <set>
|
2004-08-01 05:55:39 +02:00
|
|
|
using namespace llvm;
|
2003-11-11 23:41:34 +01:00
|
|
|
|
2003-10-05 21:27:59 +02:00
|
|
|
// runEnums - Print out enum values for all of the registers.
|
2011-06-27 20:32:37 +02:00
|
|
|
void
|
|
|
|
RegisterInfoEmitter::runEnums(raw_ostream &OS,
|
|
|
|
CodeGenTarget &Target, CodeGenRegBank &Bank) {
|
2011-06-18 06:26:06 +02:00
|
|
|
const std::vector<CodeGenRegister*> &Registers = Bank.getRegisters();
|
2003-10-05 21:27:59 +02:00
|
|
|
|
2011-06-18 06:26:06 +02:00
|
|
|
std::string Namespace = Registers[0]->TheDef->getValueAsString("Namespace");
|
2003-10-05 21:27:59 +02:00
|
|
|
|
|
|
|
EmitSourceFileHeader("Target Register Enum Values", OS);
|
2011-06-27 20:32:37 +02:00
|
|
|
|
|
|
|
OS << "\n#ifdef GET_REGINFO_ENUM\n";
|
|
|
|
OS << "#undef GET_REGINFO_ENUM\n";
|
|
|
|
|
2004-08-17 05:08:28 +02:00
|
|
|
OS << "namespace llvm {\n\n";
|
2003-10-05 21:27:59 +02:00
|
|
|
|
2011-07-28 01:22:03 +02:00
|
|
|
OS << "class MCRegisterClass;\n"
|
2011-10-22 18:50:00 +02:00
|
|
|
<< "extern const MCRegisterClass " << Namespace
|
|
|
|
<< "MCRegisterClasses[];\n\n";
|
2011-07-28 01:22:03 +02:00
|
|
|
|
2003-10-05 21:27:59 +02:00
|
|
|
if (!Namespace.empty())
|
|
|
|
OS << "namespace " << Namespace << " {\n";
|
2010-05-24 16:48:12 +02:00
|
|
|
OS << "enum {\n NoRegister,\n";
|
2003-10-05 21:27:59 +02:00
|
|
|
|
|
|
|
for (unsigned i = 0, e = Registers.size(); i != e; ++i)
|
2011-06-18 06:26:06 +02:00
|
|
|
OS << " " << Registers[i]->getName() << " = " <<
|
|
|
|
Registers[i]->EnumValue << ",\n";
|
|
|
|
assert(Registers.size() == Registers[Registers.size()-1]->EnumValue &&
|
2011-03-11 02:33:54 +01:00
|
|
|
"Register enum value mismatch!");
|
2010-05-24 16:48:12 +02:00
|
|
|
OS << " NUM_TARGET_REGS \t// " << Registers.size()+1 << "\n";
|
|
|
|
OS << "};\n";
|
2003-10-05 21:27:59 +02:00
|
|
|
if (!Namespace.empty())
|
|
|
|
OS << "}\n";
|
2010-05-24 16:48:12 +02:00
|
|
|
|
2011-09-30 00:28:37 +02:00
|
|
|
ArrayRef<CodeGenRegisterClass*> RegisterClasses = Bank.getRegClasses();
|
2011-06-27 20:32:37 +02:00
|
|
|
if (!RegisterClasses.empty()) {
|
|
|
|
OS << "\n// Register classes\n";
|
2011-06-28 03:36:01 +02:00
|
|
|
if (!Namespace.empty())
|
|
|
|
OS << "namespace " << Namespace << " {\n";
|
2011-06-27 20:32:37 +02:00
|
|
|
OS << "enum {\n";
|
|
|
|
for (unsigned i = 0, e = RegisterClasses.size(); i != e; ++i) {
|
|
|
|
if (i) OS << ",\n";
|
2011-09-30 00:28:37 +02:00
|
|
|
OS << " " << RegisterClasses[i]->getName() << "RegClassID";
|
2011-06-27 20:32:37 +02:00
|
|
|
OS << " = " << i;
|
|
|
|
}
|
|
|
|
OS << "\n };\n";
|
2011-06-28 03:36:01 +02:00
|
|
|
if (!Namespace.empty())
|
|
|
|
OS << "}\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::vector<Record*> RegAltNameIndices = Target.getRegAltNameIndices();
|
|
|
|
// If the only definition is the default NoRegAltName, we don't need to
|
|
|
|
// emit anything.
|
|
|
|
if (RegAltNameIndices.size() > 1) {
|
|
|
|
OS << "\n// Register alternate name indices\n";
|
|
|
|
if (!Namespace.empty())
|
|
|
|
OS << "namespace " << Namespace << " {\n";
|
|
|
|
OS << "enum {\n";
|
|
|
|
for (unsigned i = 0, e = RegAltNameIndices.size(); i != e; ++i)
|
|
|
|
OS << " " << RegAltNameIndices[i]->getName() << ",\t// " << i << "\n";
|
|
|
|
OS << " NUM_TARGET_REG_ALT_NAMES = " << RegAltNameIndices.size() << "\n";
|
|
|
|
OS << "};\n";
|
|
|
|
if (!Namespace.empty())
|
|
|
|
OS << "}\n";
|
2011-06-27 20:32:37 +02:00
|
|
|
}
|
|
|
|
|
2011-06-28 03:36:01 +02:00
|
|
|
|
2004-08-17 05:08:28 +02:00
|
|
|
OS << "} // End llvm namespace \n";
|
2011-06-27 20:32:37 +02:00
|
|
|
OS << "#endif // GET_REGINFO_ENUM\n\n";
|
2003-10-05 21:27:59 +02:00
|
|
|
}
|
|
|
|
|
2011-07-18 22:57:22 +02:00
|
|
|
void
|
|
|
|
RegisterInfoEmitter::EmitRegMapping(raw_ostream &OS,
|
|
|
|
const std::vector<CodeGenRegister*> &Regs,
|
|
|
|
bool isCtor) {
|
|
|
|
|
|
|
|
// Collect all information about dwarf register numbers
|
|
|
|
typedef std::map<Record*, std::vector<int64_t>, LessRecord> DwarfRegNumsMapTy;
|
|
|
|
DwarfRegNumsMapTy DwarfRegNums;
|
|
|
|
|
|
|
|
// First, just pull all provided information to the map
|
|
|
|
unsigned maxLength = 0;
|
|
|
|
for (unsigned i = 0, e = Regs.size(); i != e; ++i) {
|
|
|
|
Record *Reg = Regs[i]->TheDef;
|
|
|
|
std::vector<int64_t> RegNums = Reg->getValueAsListOfInts("DwarfNumbers");
|
|
|
|
maxLength = std::max((size_t)maxLength, RegNums.size());
|
|
|
|
if (DwarfRegNums.count(Reg))
|
|
|
|
errs() << "Warning: DWARF numbers for register " << getQualifiedName(Reg)
|
|
|
|
<< "specified multiple times\n";
|
|
|
|
DwarfRegNums[Reg] = RegNums;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!maxLength)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Now we know maximal length of number list. Append -1's, where needed
|
|
|
|
for (DwarfRegNumsMapTy::iterator
|
|
|
|
I = DwarfRegNums.begin(), E = DwarfRegNums.end(); I != E; ++I)
|
|
|
|
for (unsigned i = I->second.size(), e = maxLength; i != e; ++i)
|
|
|
|
I->second.push_back(-1);
|
|
|
|
|
|
|
|
// Emit reverse information about the dwarf register numbers.
|
|
|
|
for (unsigned j = 0; j < 2; ++j) {
|
|
|
|
OS << " switch (";
|
|
|
|
if (j == 0)
|
|
|
|
OS << "DwarfFlavour";
|
|
|
|
else
|
|
|
|
OS << "EHFlavour";
|
|
|
|
OS << ") {\n"
|
|
|
|
<< " default:\n"
|
2012-02-05 08:21:30 +01:00
|
|
|
<< " llvm_unreachable(\"Unknown DWARF flavour\");\n";
|
2011-07-18 22:57:22 +02:00
|
|
|
|
|
|
|
for (unsigned i = 0, e = maxLength; i != e; ++i) {
|
|
|
|
OS << " case " << i << ":\n";
|
|
|
|
for (DwarfRegNumsMapTy::iterator
|
|
|
|
I = DwarfRegNums.begin(), E = DwarfRegNums.end(); I != E; ++I) {
|
|
|
|
int DwarfRegNo = I->second[i];
|
|
|
|
if (DwarfRegNo < 0)
|
|
|
|
continue;
|
|
|
|
OS << " ";
|
|
|
|
if (!isCtor)
|
|
|
|
OS << "RI->";
|
|
|
|
OS << "mapDwarfRegToLLVMReg(" << DwarfRegNo << ", "
|
|
|
|
<< getQualifiedName(I->first) << ", ";
|
|
|
|
if (j == 0)
|
|
|
|
OS << "false";
|
|
|
|
else
|
|
|
|
OS << "true";
|
|
|
|
OS << " );\n";
|
|
|
|
}
|
|
|
|
OS << " break;\n";
|
|
|
|
}
|
|
|
|
OS << " }\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
for (unsigned i = 0, e = Regs.size(); i != e; ++i) {
|
|
|
|
Record *Reg = Regs[i]->TheDef;
|
|
|
|
const RecordVal *V = Reg->getValue("DwarfAlias");
|
|
|
|
if (!V || !V->getValue())
|
|
|
|
continue;
|
|
|
|
|
2011-07-30 00:43:06 +02:00
|
|
|
DefInit *DI = dynamic_cast<DefInit*>(V->getValue());
|
2011-07-18 22:57:22 +02:00
|
|
|
Record *Alias = DI->getDef();
|
|
|
|
DwarfRegNums[Reg] = DwarfRegNums[Alias];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Emit information about the dwarf register numbers.
|
|
|
|
for (unsigned j = 0; j < 2; ++j) {
|
|
|
|
OS << " switch (";
|
|
|
|
if (j == 0)
|
|
|
|
OS << "DwarfFlavour";
|
|
|
|
else
|
|
|
|
OS << "EHFlavour";
|
|
|
|
OS << ") {\n"
|
|
|
|
<< " default:\n"
|
2012-02-05 08:21:30 +01:00
|
|
|
<< " llvm_unreachable(\"Unknown DWARF flavour\");\n";
|
2011-07-18 22:57:22 +02:00
|
|
|
|
|
|
|
for (unsigned i = 0, e = maxLength; i != e; ++i) {
|
|
|
|
OS << " case " << i << ":\n";
|
|
|
|
// Sort by name to get a stable order.
|
|
|
|
for (DwarfRegNumsMapTy::iterator
|
|
|
|
I = DwarfRegNums.begin(), E = DwarfRegNums.end(); I != E; ++I) {
|
|
|
|
int RegNo = I->second[i];
|
2012-02-08 19:46:26 +01:00
|
|
|
if (RegNo == -1) // -1 is the default value, don't emit a mapping.
|
|
|
|
continue;
|
|
|
|
|
2011-07-18 22:57:22 +02:00
|
|
|
OS << " ";
|
|
|
|
if (!isCtor)
|
|
|
|
OS << "RI->";
|
|
|
|
OS << "mapLLVMRegToDwarfReg(" << getQualifiedName(I->first) << ", "
|
|
|
|
<< RegNo << ", ";
|
|
|
|
if (j == 0)
|
|
|
|
OS << "false";
|
|
|
|
else
|
|
|
|
OS << "true";
|
|
|
|
OS << " );\n";
|
|
|
|
}
|
|
|
|
OS << " break;\n";
|
|
|
|
}
|
|
|
|
OS << " }\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-01 00:18:54 +02:00
|
|
|
// Print a BitVector as a sequence of hex numbers using a little-endian mapping.
|
|
|
|
// Width is the number of bits per hex number.
|
|
|
|
static void printBitVectorAsHex(raw_ostream &OS,
|
|
|
|
const BitVector &Bits,
|
|
|
|
unsigned Width) {
|
|
|
|
assert(Width <= 32 && "Width too large");
|
|
|
|
unsigned Digits = (Width + 3) / 4;
|
|
|
|
for (unsigned i = 0, e = Bits.size(); i < e; i += Width) {
|
|
|
|
unsigned Value = 0;
|
|
|
|
for (unsigned j = 0; j != Width && i + j != e; ++j)
|
|
|
|
Value |= Bits.test(i + j) << j;
|
|
|
|
OS << format("0x%0*x, ", Digits, Value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-23 02:47:49 +02:00
|
|
|
// Helper to emit a set of bits into a constant byte array.
|
|
|
|
class BitVectorEmitter {
|
|
|
|
BitVector Values;
|
|
|
|
public:
|
2011-07-23 04:49:37 +02:00
|
|
|
void add(unsigned v) {
|
|
|
|
if (v >= Values.size())
|
|
|
|
Values.resize(((v/8)+1)*8); // Round up to the next byte.
|
|
|
|
Values[v] = true;
|
2011-07-23 02:47:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void print(raw_ostream &OS) {
|
2011-10-01 00:18:54 +02:00
|
|
|
printBitVectorAsHex(OS, Values, 8);
|
2011-07-23 02:47:49 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-06-12 09:04:26 +02:00
|
|
|
//
|
2011-06-27 20:32:37 +02:00
|
|
|
// runMCDesc - Print out MC register descriptions.
|
2003-10-05 21:27:59 +02:00
|
|
|
//
|
2011-06-27 20:32:37 +02:00
|
|
|
void
|
|
|
|
RegisterInfoEmitter::runMCDesc(raw_ostream &OS, CodeGenTarget &Target,
|
|
|
|
CodeGenRegBank &RegBank) {
|
|
|
|
EmitSourceFileHeader("MC Register Information", OS);
|
|
|
|
|
|
|
|
OS << "\n#ifdef GET_REGINFO_MC_DESC\n";
|
|
|
|
OS << "#undef GET_REGINFO_MC_DESC\n";
|
|
|
|
|
|
|
|
std::map<const CodeGenRegister*, CodeGenRegister::Set> Overlaps;
|
|
|
|
RegBank.computeOverlaps(Overlaps);
|
|
|
|
|
|
|
|
OS << "namespace llvm {\n\n";
|
|
|
|
|
|
|
|
const std::string &TargetName = Target.getName();
|
|
|
|
|
|
|
|
const std::vector<CodeGenRegister*> &Regs = RegBank.getRegisters();
|
|
|
|
|
2012-02-21 07:23:21 +01:00
|
|
|
OS << "extern const unsigned " << TargetName << "RegOverlaps[] = {\n";
|
|
|
|
|
2011-06-27 20:32:37 +02:00
|
|
|
// Emit an overlap list for all registers.
|
|
|
|
for (unsigned i = 0, e = Regs.size(); i != e; ++i) {
|
|
|
|
const CodeGenRegister *Reg = Regs[i];
|
|
|
|
const CodeGenRegister::Set &O = Overlaps[Reg];
|
|
|
|
// Move Reg to the front so TRI::getAliasSet can share the list.
|
2012-02-21 07:23:21 +01:00
|
|
|
OS << " /* " << Reg->getName() << "_Overlaps */ "
|
2011-06-27 20:32:37 +02:00
|
|
|
<< getQualifiedName(Reg->TheDef) << ", ";
|
|
|
|
for (CodeGenRegister::Set::const_iterator I = O.begin(), E = O.end();
|
|
|
|
I != E; ++I)
|
|
|
|
if (*I != Reg)
|
|
|
|
OS << getQualifiedName((*I)->TheDef) << ", ";
|
2012-02-21 07:23:21 +01:00
|
|
|
OS << "0,\n";
|
2011-06-27 20:32:37 +02:00
|
|
|
}
|
2012-02-21 07:23:21 +01:00
|
|
|
OS << "};\n\n";
|
2011-06-27 20:32:37 +02:00
|
|
|
|
2012-02-21 07:23:21 +01:00
|
|
|
OS << "extern const unsigned " << TargetName << "SubRegsSet[] = {\n";
|
2011-06-27 20:32:37 +02:00
|
|
|
// Emit the empty sub-registers list
|
2012-02-21 07:23:21 +01:00
|
|
|
OS << " /* Empty_SubRegsSet */ 0,\n";
|
2011-06-27 20:32:37 +02:00
|
|
|
// Loop over all of the registers which have sub-registers, emitting the
|
|
|
|
// sub-registers list to memory.
|
|
|
|
for (unsigned i = 0, e = Regs.size(); i != e; ++i) {
|
|
|
|
const CodeGenRegister &Reg = *Regs[i];
|
|
|
|
if (Reg.getSubRegs().empty())
|
|
|
|
continue;
|
|
|
|
// getSubRegs() orders by SubRegIndex. We want a topological order.
|
|
|
|
SetVector<CodeGenRegister*> SR;
|
2012-01-31 21:57:55 +01:00
|
|
|
Reg.addSubRegsPreOrder(SR, RegBank);
|
2012-02-21 07:23:21 +01:00
|
|
|
OS << " /* " << Reg.getName() << "_SubRegsSet */ ";
|
2011-06-27 20:32:37 +02:00
|
|
|
for (unsigned j = 0, je = SR.size(); j != je; ++j)
|
|
|
|
OS << getQualifiedName(SR[j]->TheDef) << ", ";
|
2012-02-21 07:23:21 +01:00
|
|
|
OS << "0,\n";
|
2011-06-27 20:32:37 +02:00
|
|
|
}
|
2012-02-21 07:23:21 +01:00
|
|
|
OS << "};\n\n";
|
2011-06-27 20:32:37 +02:00
|
|
|
|
2012-02-21 07:23:21 +01:00
|
|
|
OS << "extern const unsigned " << TargetName << "SuperRegsSet[] = {\n";
|
2011-06-27 20:32:37 +02:00
|
|
|
// Emit the empty super-registers list
|
2012-02-21 07:23:21 +01:00
|
|
|
OS << " /* Empty_SuperRegsSet */ 0,\n";
|
2011-06-27 20:32:37 +02:00
|
|
|
// Loop over all of the registers which have super-registers, emitting the
|
|
|
|
// super-registers list to memory.
|
|
|
|
for (unsigned i = 0, e = Regs.size(); i != e; ++i) {
|
|
|
|
const CodeGenRegister &Reg = *Regs[i];
|
|
|
|
const CodeGenRegister::SuperRegList &SR = Reg.getSuperRegs();
|
|
|
|
if (SR.empty())
|
|
|
|
continue;
|
2012-02-21 07:23:21 +01:00
|
|
|
OS << " /* " << Reg.getName() << "_SuperRegsSet */ ";
|
2011-06-27 20:32:37 +02:00
|
|
|
for (unsigned j = 0, je = SR.size(); j != je; ++j)
|
|
|
|
OS << getQualifiedName(SR[j]->TheDef) << ", ";
|
2012-02-21 07:23:21 +01:00
|
|
|
OS << "0,\n";
|
2011-06-27 20:32:37 +02:00
|
|
|
}
|
2012-02-21 07:23:21 +01:00
|
|
|
OS << "};\n\n";
|
2011-06-27 20:32:37 +02:00
|
|
|
|
2012-02-21 07:23:21 +01:00
|
|
|
OS << "extern const MCRegisterDesc " << TargetName
|
2011-06-27 20:32:37 +02:00
|
|
|
<< "RegDesc[] = { // Descriptors\n";
|
2012-02-21 07:23:21 +01:00
|
|
|
OS << " { \"NOREG\", -1, -1, -1 },\n";
|
2011-06-27 20:32:37 +02:00
|
|
|
|
|
|
|
// Now that register alias and sub-registers sets have been emitted, emit the
|
|
|
|
// register descriptors now.
|
2012-02-21 07:23:21 +01:00
|
|
|
unsigned OverlapsIndex = 0;
|
|
|
|
unsigned SubRegIndex = 1; // skip 1 for empty set
|
|
|
|
unsigned SuperRegIndex = 1; // skip 1 for empty set
|
2011-06-27 20:32:37 +02:00
|
|
|
for (unsigned i = 0, e = Regs.size(); i != e; ++i) {
|
2012-02-21 07:23:21 +01:00
|
|
|
const CodeGenRegister *Reg = Regs[i];
|
2011-07-14 22:59:42 +02:00
|
|
|
OS << " { \"";
|
2012-02-21 07:23:21 +01:00
|
|
|
OS << Reg->getName() << "\", /* " << Reg->getName() << "_Overlaps */ "
|
|
|
|
<< OverlapsIndex << ", ";
|
|
|
|
OverlapsIndex += Overlaps[Reg].size() + 1;
|
|
|
|
if (!Reg->getSubRegs().empty()) {
|
|
|
|
OS << "/* " << Reg->getName() << "_SubRegsSet */ " << SubRegIndex
|
|
|
|
<< ", ";
|
|
|
|
// FIXME not very nice to recalculate this
|
|
|
|
SetVector<CodeGenRegister*> SR;
|
|
|
|
Reg->addSubRegsPreOrder(SR, RegBank);
|
|
|
|
SubRegIndex += SR.size() + 1;
|
|
|
|
} else
|
|
|
|
OS << "/* Empty_SubRegsSet */ 0, ";
|
|
|
|
if (!Reg->getSuperRegs().empty()) {
|
|
|
|
OS << "/* " << Reg->getName() << "_SuperRegsSet */ " << SuperRegIndex;
|
|
|
|
SuperRegIndex += Reg->getSuperRegs().size() + 1;
|
|
|
|
} else
|
|
|
|
OS << "/* Empty_SuperRegsSet */ 0";
|
2011-06-27 20:32:37 +02:00
|
|
|
OS << " },\n";
|
|
|
|
}
|
2011-07-14 22:59:42 +02:00
|
|
|
OS << "};\n\n"; // End of register descriptors...
|
2011-06-27 20:32:37 +02:00
|
|
|
|
2011-09-30 00:28:37 +02:00
|
|
|
ArrayRef<CodeGenRegisterClass*> RegisterClasses = RegBank.getRegClasses();
|
2011-07-22 02:44:39 +02:00
|
|
|
|
|
|
|
// Loop over all of the register classes... emitting each one.
|
|
|
|
OS << "namespace { // Register classes...\n";
|
|
|
|
|
|
|
|
// Emit the register enum value arrays for each RegisterClass
|
|
|
|
for (unsigned rc = 0, e = RegisterClasses.size(); rc != e; ++rc) {
|
2011-09-30 00:28:37 +02:00
|
|
|
const CodeGenRegisterClass &RC = *RegisterClasses[rc];
|
2011-07-22 02:44:39 +02:00
|
|
|
ArrayRef<Record*> Order = RC.getOrder();
|
|
|
|
|
|
|
|
// Give the register class a legal C name if it's anonymous.
|
|
|
|
std::string Name = RC.getName();
|
|
|
|
|
|
|
|
// Emit the register list now.
|
|
|
|
OS << " // " << Name << " Register Class...\n"
|
2012-02-21 07:23:21 +01:00
|
|
|
<< " const unsigned " << Name
|
2011-07-22 02:44:39 +02:00
|
|
|
<< "[] = {\n ";
|
|
|
|
for (unsigned i = 0, e = Order.size(); i != e; ++i) {
|
|
|
|
Record *Reg = Order[i];
|
|
|
|
OS << getQualifiedName(Reg) << ", ";
|
|
|
|
}
|
|
|
|
OS << "\n };\n\n";
|
2011-07-23 02:47:49 +02:00
|
|
|
|
|
|
|
OS << " // " << Name << " Bit set.\n"
|
2012-02-21 07:23:21 +01:00
|
|
|
<< " const unsigned char " << Name
|
2011-07-23 02:47:49 +02:00
|
|
|
<< "Bits[] = {\n ";
|
2011-07-23 04:49:37 +02:00
|
|
|
BitVectorEmitter BVE;
|
2011-07-23 02:47:49 +02:00
|
|
|
for (unsigned i = 0, e = Order.size(); i != e; ++i) {
|
|
|
|
Record *Reg = Order[i];
|
|
|
|
BVE.add(Target.getRegBank().getReg(Reg)->EnumValue);
|
|
|
|
}
|
|
|
|
BVE.print(OS);
|
|
|
|
OS << "\n };\n\n";
|
|
|
|
|
2011-07-22 02:44:39 +02:00
|
|
|
}
|
|
|
|
OS << "}\n\n";
|
|
|
|
|
2011-10-22 18:50:00 +02:00
|
|
|
OS << "extern const MCRegisterClass " << TargetName
|
|
|
|
<< "MCRegisterClasses[] = {\n";
|
2011-07-22 02:44:39 +02:00
|
|
|
|
|
|
|
for (unsigned rc = 0, e = RegisterClasses.size(); rc != e; ++rc) {
|
2011-09-30 00:28:37 +02:00
|
|
|
const CodeGenRegisterClass &RC = *RegisterClasses[rc];
|
2012-02-08 15:43:53 +01:00
|
|
|
OS << " { " << RC.getQualifiedName() + "RegClassID" << ", "
|
2011-07-22 02:44:39 +02:00
|
|
|
<< '\"' << RC.getName() << "\", "
|
|
|
|
<< RC.SpillSize/8 << ", "
|
|
|
|
<< RC.SpillAlignment/8 << ", "
|
|
|
|
<< RC.CopyCost << ", "
|
|
|
|
<< RC.Allocatable << ", "
|
2012-02-21 08:36:39 +01:00
|
|
|
<< RC.getName() << ", " << RC.getName() << "Bits, "
|
|
|
|
<< RC.getOrder().size() << ", sizeof(" << RC.getName() << "Bits) },\n";
|
2011-07-22 02:44:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
OS << "};\n\n";
|
|
|
|
|
2011-06-27 20:32:37 +02:00
|
|
|
// MCRegisterInfo initialization routine.
|
|
|
|
OS << "static inline void Init" << TargetName
|
2011-07-18 22:57:22 +02:00
|
|
|
<< "MCRegisterInfo(MCRegisterInfo *RI, unsigned RA, "
|
|
|
|
<< "unsigned DwarfFlavour = 0, unsigned EHFlavour = 0) {\n";
|
2011-06-27 20:32:37 +02:00
|
|
|
OS << " RI->InitMCRegisterInfo(" << TargetName << "RegDesc, "
|
2011-07-22 02:44:39 +02:00
|
|
|
<< Regs.size()+1 << ", RA, " << TargetName << "MCRegisterClasses, "
|
2012-02-21 07:23:21 +01:00
|
|
|
<< RegisterClasses.size() << ", " << TargetName << "RegOverlaps, "
|
|
|
|
<< TargetName << "SubRegsSet, " << TargetName << "SuperRegsSet);\n\n";
|
2011-07-18 22:57:22 +02:00
|
|
|
|
|
|
|
EmitRegMapping(OS, Regs, false);
|
|
|
|
|
|
|
|
OS << "}\n\n";
|
|
|
|
|
2011-06-27 20:32:37 +02:00
|
|
|
|
|
|
|
OS << "} // End llvm namespace \n";
|
|
|
|
OS << "#endif // GET_REGINFO_MC_DESC\n\n";
|
|
|
|
}
|
2011-06-12 05:05:52 +02:00
|
|
|
|
2011-06-27 21:24:13 +02:00
|
|
|
void
|
|
|
|
RegisterInfoEmitter::runTargetHeader(raw_ostream &OS, CodeGenTarget &Target,
|
|
|
|
CodeGenRegBank &RegBank) {
|
|
|
|
EmitSourceFileHeader("Register Information Header Fragment", OS);
|
|
|
|
|
|
|
|
OS << "\n#ifdef GET_REGINFO_HEADER\n";
|
|
|
|
OS << "#undef GET_REGINFO_HEADER\n";
|
|
|
|
|
|
|
|
const std::string &TargetName = Target.getName();
|
|
|
|
std::string ClassName = TargetName + "GenRegisterInfo";
|
|
|
|
|
|
|
|
OS << "#include \"llvm/Target/TargetRegisterInfo.h\"\n";
|
|
|
|
OS << "#include <string>\n\n";
|
|
|
|
|
|
|
|
OS << "namespace llvm {\n\n";
|
|
|
|
|
|
|
|
OS << "struct " << ClassName << " : public TargetRegisterInfo {\n"
|
2011-07-18 22:57:22 +02:00
|
|
|
<< " explicit " << ClassName
|
|
|
|
<< "(unsigned RA, unsigned D = 0, unsigned E = 0);\n"
|
2011-06-27 21:24:13 +02:00
|
|
|
<< " virtual bool needsStackRealignment(const MachineFunction &) const\n"
|
|
|
|
<< " { return false; }\n"
|
|
|
|
<< " unsigned getSubReg(unsigned RegNo, unsigned Index) const;\n"
|
|
|
|
<< " unsigned getSubRegIndex(unsigned RegNo, unsigned SubRegNo) const;\n"
|
|
|
|
<< " unsigned composeSubRegIndices(unsigned, unsigned) const;\n"
|
2011-10-05 02:35:49 +02:00
|
|
|
<< " const TargetRegisterClass *"
|
|
|
|
"getSubClassWithSubReg(const TargetRegisterClass*, unsigned) const;\n"
|
2011-12-19 17:53:34 +01:00
|
|
|
<< " const TargetRegisterClass *getMatchingSuperRegClass("
|
|
|
|
"const TargetRegisterClass*, const TargetRegisterClass*, "
|
|
|
|
"unsigned) const;\n"
|
2011-06-27 21:24:13 +02:00
|
|
|
<< "};\n\n";
|
|
|
|
|
2012-01-31 21:57:55 +01:00
|
|
|
ArrayRef<CodeGenSubRegIndex*> SubRegIndices = RegBank.getSubRegIndices();
|
2011-06-27 21:24:13 +02:00
|
|
|
if (!SubRegIndices.empty()) {
|
|
|
|
OS << "\n// Subregister indices\n";
|
2012-01-31 21:57:55 +01:00
|
|
|
std::string Namespace =
|
|
|
|
SubRegIndices[0]->getNamespace();
|
2011-06-27 21:24:13 +02:00
|
|
|
if (!Namespace.empty())
|
|
|
|
OS << "namespace " << Namespace << " {\n";
|
|
|
|
OS << "enum {\n NoSubRegister,\n";
|
|
|
|
for (unsigned i = 0, e = RegBank.getNumNamedIndices(); i != e; ++i)
|
|
|
|
OS << " " << SubRegIndices[i]->getName() << ",\t// " << i+1 << "\n";
|
2012-01-31 22:51:53 +01:00
|
|
|
OS << " NUM_TARGET_NAMED_SUBREGS\n};\n";
|
2011-06-27 21:24:13 +02:00
|
|
|
if (!Namespace.empty())
|
|
|
|
OS << "}\n";
|
|
|
|
}
|
|
|
|
|
2011-09-30 00:28:37 +02:00
|
|
|
ArrayRef<CodeGenRegisterClass*> RegisterClasses = RegBank.getRegClasses();
|
2011-06-27 21:24:13 +02:00
|
|
|
|
|
|
|
if (!RegisterClasses.empty()) {
|
2011-09-30 00:28:37 +02:00
|
|
|
OS << "namespace " << RegisterClasses[0]->Namespace
|
2011-06-27 21:24:13 +02:00
|
|
|
<< " { // Register classes\n";
|
|
|
|
|
|
|
|
for (unsigned i = 0, e = RegisterClasses.size(); i != e; ++i) {
|
2011-09-30 00:28:37 +02:00
|
|
|
const CodeGenRegisterClass &RC = *RegisterClasses[i];
|
2011-06-27 21:24:13 +02:00
|
|
|
const std::string &Name = RC.getName();
|
|
|
|
|
|
|
|
// Output the register class definition.
|
|
|
|
OS << " struct " << Name << "Class : public TargetRegisterClass {\n"
|
|
|
|
<< " " << Name << "Class();\n";
|
|
|
|
if (!RC.AltOrderSelect.empty())
|
|
|
|
OS << " ArrayRef<unsigned> "
|
|
|
|
"getRawAllocationOrder(const MachineFunction&) const;\n";
|
|
|
|
OS << " };\n";
|
|
|
|
|
|
|
|
// Output the extern for the instance.
|
|
|
|
OS << " extern " << Name << "Class\t" << Name << "RegClass;\n";
|
|
|
|
// Output the extern for the pointer to the instance (should remove).
|
2012-02-22 06:59:10 +01:00
|
|
|
OS << " static const TargetRegisterClass * const " << Name
|
|
|
|
<< "RegisterClass = &" << Name << "RegClass;\n";
|
2011-06-27 21:24:13 +02:00
|
|
|
}
|
|
|
|
OS << "} // end of namespace " << TargetName << "\n\n";
|
|
|
|
}
|
|
|
|
OS << "} // End llvm namespace \n";
|
|
|
|
OS << "#endif // GET_REGINFO_HEADER\n\n";
|
|
|
|
}
|
|
|
|
|
2011-06-27 20:32:37 +02:00
|
|
|
//
|
|
|
|
// runTargetDesc - Output the target register and register file descriptions.
|
|
|
|
//
|
|
|
|
void
|
|
|
|
RegisterInfoEmitter::runTargetDesc(raw_ostream &OS, CodeGenTarget &Target,
|
|
|
|
CodeGenRegBank &RegBank){
|
|
|
|
EmitSourceFileHeader("Target Register and Register Classes Information", OS);
|
|
|
|
|
|
|
|
OS << "\n#ifdef GET_REGINFO_TARGET_DESC\n";
|
|
|
|
OS << "#undef GET_REGINFO_TARGET_DESC\n";
|
2003-10-05 21:27:59 +02:00
|
|
|
|
2004-08-17 05:08:28 +02:00
|
|
|
OS << "namespace llvm {\n\n";
|
|
|
|
|
2011-07-23 02:47:46 +02:00
|
|
|
// Get access to MCRegisterClass data.
|
2011-10-22 18:50:00 +02:00
|
|
|
OS << "extern const MCRegisterClass " << Target.getName()
|
|
|
|
<< "MCRegisterClasses[];\n";
|
2011-07-23 02:47:46 +02:00
|
|
|
|
2011-06-03 01:07:20 +02:00
|
|
|
// Start out by emitting each of the register classes.
|
2011-09-30 00:28:37 +02:00
|
|
|
ArrayRef<CodeGenRegisterClass*> RegisterClasses = RegBank.getRegClasses();
|
2003-10-05 21:27:59 +02:00
|
|
|
|
2011-06-03 01:07:20 +02:00
|
|
|
// Collect all registers belonging to any allocatable class.
|
|
|
|
std::set<Record*> AllocatableRegs;
|
|
|
|
|
2011-07-23 02:47:46 +02:00
|
|
|
// Collect allocatable registers.
|
2003-10-05 21:27:59 +02:00
|
|
|
for (unsigned rc = 0, e = RegisterClasses.size(); rc != e; ++rc) {
|
2011-09-30 00:28:37 +02:00
|
|
|
const CodeGenRegisterClass &RC = *RegisterClasses[rc];
|
2011-06-15 06:50:36 +02:00
|
|
|
ArrayRef<Record*> Order = RC.getOrder();
|
2003-10-05 21:27:59 +02:00
|
|
|
|
2011-06-03 01:07:20 +02:00
|
|
|
if (RC.Allocatable)
|
2011-06-15 06:50:36 +02:00
|
|
|
AllocatableRegs.insert(Order.begin(), Order.end());
|
2005-08-19 20:47:59 +02:00
|
|
|
}
|
2006-05-09 08:34:26 +02:00
|
|
|
|
2011-07-23 02:47:46 +02:00
|
|
|
OS << "namespace { // Register classes...\n";
|
|
|
|
|
2005-12-01 05:51:06 +01:00
|
|
|
// Emit the ValueType arrays for each RegisterClass
|
|
|
|
for (unsigned rc = 0, e = RegisterClasses.size(); rc != e; ++rc) {
|
2011-09-30 00:28:37 +02:00
|
|
|
const CodeGenRegisterClass &RC = *RegisterClasses[rc];
|
2011-03-11 02:19:05 +01:00
|
|
|
|
2005-12-01 05:51:06 +01:00
|
|
|
// Give the register class a legal C name if it's anonymous.
|
2011-06-15 06:50:36 +02:00
|
|
|
std::string Name = RC.getName() + "VTs";
|
2011-03-11 02:19:05 +01:00
|
|
|
|
2005-12-01 05:51:06 +01:00
|
|
|
// Emit the register list now.
|
2011-03-11 02:19:05 +01:00
|
|
|
OS << " // " << Name
|
2006-07-19 07:58:18 +02:00
|
|
|
<< " Register Class Value Types...\n"
|
2012-02-21 07:23:21 +01:00
|
|
|
<< " const MVT::SimpleValueType " << Name
|
2006-07-19 07:58:18 +02:00
|
|
|
<< "[] = {\n ";
|
2005-12-01 05:51:06 +01:00
|
|
|
for (unsigned i = 0, e = RC.VTs.size(); i != e; ++i)
|
2007-08-04 03:51:18 +02:00
|
|
|
OS << getEnumName(RC.VTs[i]) << ", ";
|
2009-08-11 22:47:22 +02:00
|
|
|
OS << "MVT::Other\n };\n\n";
|
2005-12-01 05:51:06 +01:00
|
|
|
}
|
2005-08-19 20:47:59 +02:00
|
|
|
OS << "} // end anonymous namespace\n\n";
|
2011-03-11 02:19:05 +01:00
|
|
|
|
2005-08-19 20:47:59 +02:00
|
|
|
// Now that all of the structs have been emitted, emit the instances.
|
|
|
|
if (!RegisterClasses.empty()) {
|
2011-09-30 00:28:37 +02:00
|
|
|
OS << "namespace " << RegisterClasses[0]->Namespace
|
2005-08-19 20:47:59 +02:00
|
|
|
<< " { // Register class instances\n";
|
|
|
|
for (unsigned i = 0, e = RegisterClasses.size(); i != e; ++i)
|
2011-09-30 00:28:37 +02:00
|
|
|
OS << " " << RegisterClasses[i]->getName() << "Class\t"
|
|
|
|
<< RegisterClasses[i]->getName() << "RegClass;\n";
|
2011-03-11 02:19:05 +01:00
|
|
|
|
2009-04-13 17:38:05 +02:00
|
|
|
std::map<unsigned, std::set<unsigned> > SuperRegClassMap;
|
2011-10-01 00:18:45 +02:00
|
|
|
|
|
|
|
OS << "\n static const TargetRegisterClass* const "
|
|
|
|
<< "NullRegClasses[] = { NULL };\n\n";
|
2007-07-26 10:01:58 +02:00
|
|
|
|
2011-06-10 20:40:00 +02:00
|
|
|
unsigned NumSubRegIndices = RegBank.getSubRegIndices().size();
|
2010-05-24 23:46:58 +02:00
|
|
|
|
|
|
|
if (NumSubRegIndices) {
|
2011-10-06 02:08:27 +02:00
|
|
|
// Compute the super-register classes for each RegisterClass
|
2010-05-24 23:46:58 +02:00
|
|
|
for (unsigned rc = 0, e = RegisterClasses.size(); rc != e; ++rc) {
|
2011-09-30 00:28:37 +02:00
|
|
|
const CodeGenRegisterClass &RC = *RegisterClasses[rc];
|
2010-05-24 23:46:58 +02:00
|
|
|
for (DenseMap<Record*,Record*>::const_iterator
|
|
|
|
i = RC.SubRegClasses.begin(),
|
|
|
|
e = RC.SubRegClasses.end(); i != e; ++i) {
|
|
|
|
// Find the register class number of i->second for SuperRegClassMap.
|
2011-10-04 17:28:08 +02:00
|
|
|
const CodeGenRegisterClass *RC2 = RegBank.getRegClass(i->second);
|
|
|
|
assert(RC2 && "Invalid register class in SubRegClasses");
|
|
|
|
SuperRegClassMap[RC2->EnumValue].insert(rc);
|
2010-05-24 23:46:58 +02:00
|
|
|
}
|
|
|
|
}
|
2009-04-13 17:38:05 +02:00
|
|
|
|
2010-05-24 23:46:58 +02:00
|
|
|
// Emit the super-register classes for each RegisterClass
|
|
|
|
for (unsigned rc = 0, e = RegisterClasses.size(); rc != e; ++rc) {
|
2011-09-30 00:28:37 +02:00
|
|
|
const CodeGenRegisterClass &RC = *RegisterClasses[rc];
|
2010-05-24 23:46:58 +02:00
|
|
|
|
|
|
|
// Give the register class a legal C name if it's anonymous.
|
2011-10-04 17:28:08 +02:00
|
|
|
std::string Name = RC.getName();
|
2010-05-24 23:46:58 +02:00
|
|
|
|
|
|
|
OS << " // " << Name
|
|
|
|
<< " Super-register Classes...\n"
|
|
|
|
<< " static const TargetRegisterClass* const "
|
|
|
|
<< Name << "SuperRegClasses[] = {\n ";
|
|
|
|
|
|
|
|
bool Empty = true;
|
|
|
|
std::map<unsigned, std::set<unsigned> >::iterator I =
|
|
|
|
SuperRegClassMap.find(rc);
|
|
|
|
if (I != SuperRegClassMap.end()) {
|
|
|
|
for (std::set<unsigned>::iterator II = I->second.begin(),
|
|
|
|
EE = I->second.end(); II != EE; ++II) {
|
2011-09-30 00:28:37 +02:00
|
|
|
const CodeGenRegisterClass &RC2 = *RegisterClasses[*II];
|
2009-04-13 17:38:05 +02:00
|
|
|
if (!Empty)
|
|
|
|
OS << ", ";
|
2011-10-04 17:28:08 +02:00
|
|
|
OS << "&" << RC2.getQualifiedName() << "RegClass";
|
2009-04-13 17:38:05 +02:00
|
|
|
Empty = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-24 23:46:58 +02:00
|
|
|
OS << (!Empty ? ", " : "") << "NULL";
|
|
|
|
OS << "\n };\n\n";
|
2009-04-13 17:38:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-05-09 08:34:26 +02:00
|
|
|
// Emit the sub-classes array for each RegisterClass
|
|
|
|
for (unsigned rc = 0, e = RegisterClasses.size(); rc != e; ++rc) {
|
2011-09-30 00:28:37 +02:00
|
|
|
const CodeGenRegisterClass &RC = *RegisterClasses[rc];
|
2006-05-09 08:34:26 +02:00
|
|
|
|
|
|
|
// Give the register class a legal C name if it's anonymous.
|
2011-10-04 17:28:08 +02:00
|
|
|
std::string Name = RC.getName();
|
2006-05-09 08:34:26 +02:00
|
|
|
|
2011-10-01 00:19:07 +02:00
|
|
|
OS << " static const unsigned " << Name << "SubclassMask[] = { ";
|
|
|
|
printBitVectorAsHex(OS, RC.getSubClasses(), 32);
|
|
|
|
OS << "};\n\n";
|
2006-05-09 08:34:26 +02:00
|
|
|
}
|
|
|
|
|
2011-10-01 00:18:45 +02:00
|
|
|
// Emit NULL terminated super-class lists.
|
2006-05-11 09:30:26 +02:00
|
|
|
for (unsigned rc = 0, e = RegisterClasses.size(); rc != e; ++rc) {
|
2011-09-30 00:28:37 +02:00
|
|
|
const CodeGenRegisterClass &RC = *RegisterClasses[rc];
|
2011-10-01 00:18:45 +02:00
|
|
|
ArrayRef<CodeGenRegisterClass*> Supers = RC.getSuperClasses();
|
2006-05-11 09:30:26 +02:00
|
|
|
|
2011-10-01 00:18:45 +02:00
|
|
|
// Skip classes without supers. We can reuse NullRegClasses.
|
|
|
|
if (Supers.empty())
|
|
|
|
continue;
|
2006-05-11 09:30:26 +02:00
|
|
|
|
2011-10-01 00:18:45 +02:00
|
|
|
OS << " static const TargetRegisterClass* const "
|
|
|
|
<< RC.getName() << "Superclasses[] = {\n";
|
|
|
|
for (unsigned i = 0; i != Supers.size(); ++i)
|
2011-10-04 17:28:08 +02:00
|
|
|
OS << " &" << Supers[i]->getQualifiedName() << "RegClass,\n";
|
2011-10-01 00:18:45 +02:00
|
|
|
OS << " NULL\n };\n\n";
|
2006-05-11 09:30:26 +02:00
|
|
|
}
|
|
|
|
|
2011-06-18 02:50:49 +02:00
|
|
|
// Emit methods.
|
2005-08-19 22:23:42 +02:00
|
|
|
for (unsigned i = 0, e = RegisterClasses.size(); i != e; ++i) {
|
2011-09-30 00:28:37 +02:00
|
|
|
const CodeGenRegisterClass &RC = *RegisterClasses[i];
|
2011-03-11 02:19:05 +01:00
|
|
|
OS << RC.getName() << "Class::" << RC.getName()
|
2011-07-23 02:47:46 +02:00
|
|
|
<< "Class() : TargetRegisterClass(&"
|
|
|
|
<< Target.getName() << "MCRegisterClasses["
|
|
|
|
<< RC.getName() + "RegClassID" << "], "
|
2006-05-09 08:34:26 +02:00
|
|
|
<< RC.getName() + "VTs" << ", "
|
2011-10-01 00:19:07 +02:00
|
|
|
<< RC.getName() + "SubclassMask" << ", ";
|
2011-10-01 00:18:45 +02:00
|
|
|
if (RC.getSuperClasses().empty())
|
|
|
|
OS << "NullRegClasses, ";
|
|
|
|
else
|
|
|
|
OS << RC.getName() + "Superclasses, ";
|
2011-10-06 02:08:27 +02:00
|
|
|
OS << (NumSubRegIndices ? RC.getName() + "Super" : std::string("Null"))
|
2011-07-23 02:47:46 +02:00
|
|
|
<< "RegClasses"
|
2007-09-19 03:35:01 +02:00
|
|
|
<< ") {}\n";
|
2011-06-18 02:50:49 +02:00
|
|
|
if (!RC.AltOrderSelect.empty()) {
|
|
|
|
OS << "\nstatic inline unsigned " << RC.getName()
|
|
|
|
<< "AltOrderSelect(const MachineFunction &MF) {"
|
|
|
|
<< RC.AltOrderSelect << "}\n\nArrayRef<unsigned> "
|
|
|
|
<< RC.getName() << "Class::"
|
|
|
|
<< "getRawAllocationOrder(const MachineFunction &MF) const {\n";
|
|
|
|
for (unsigned oi = 1 , oe = RC.getNumOrders(); oi != oe; ++oi) {
|
|
|
|
ArrayRef<Record*> Elems = RC.getOrder(oi);
|
2012-02-01 23:12:51 +01:00
|
|
|
if (!Elems.empty()) {
|
|
|
|
OS << " static const unsigned AltOrder" << oi << "[] = {";
|
|
|
|
for (unsigned elem = 0; elem != Elems.size(); ++elem)
|
|
|
|
OS << (elem ? ", " : " ") << getQualifiedName(Elems[elem]);
|
|
|
|
OS << " };\n";
|
|
|
|
}
|
2011-06-18 02:50:49 +02:00
|
|
|
}
|
2011-07-23 02:47:46 +02:00
|
|
|
OS << " const MCRegisterClass &MCR = " << Target.getName()
|
2012-02-01 23:12:51 +01:00
|
|
|
<< "MCRegisterClasses[" << RC.getQualifiedName() + "RegClassID];\n"
|
2011-07-23 02:47:46 +02:00
|
|
|
<< " static const ArrayRef<unsigned> Order[] = {\n"
|
|
|
|
<< " makeArrayRef(MCR.begin(), MCR.getNumRegs()";
|
2011-06-18 02:50:49 +02:00
|
|
|
for (unsigned oi = 1, oe = RC.getNumOrders(); oi != oe; ++oi)
|
2012-02-01 23:12:51 +01:00
|
|
|
if (RC.getOrder(oi).empty())
|
|
|
|
OS << "),\n ArrayRef<unsigned>(";
|
|
|
|
else
|
|
|
|
OS << "),\n makeArrayRef(AltOrder" << oi;
|
2011-06-18 02:50:49 +02:00
|
|
|
OS << ")\n };\n const unsigned Select = " << RC.getName()
|
|
|
|
<< "AltOrderSelect(MF);\n assert(Select < " << RC.getNumOrders()
|
|
|
|
<< ");\n return Order[Select];\n}\n";
|
|
|
|
}
|
2005-08-19 22:23:42 +02:00
|
|
|
}
|
2011-03-11 02:19:05 +01:00
|
|
|
|
2005-08-19 20:47:59 +02:00
|
|
|
OS << "}\n";
|
2003-10-05 21:27:59 +02:00
|
|
|
}
|
|
|
|
|
2005-08-19 20:47:59 +02:00
|
|
|
OS << "\nnamespace {\n";
|
2003-10-05 21:27:59 +02:00
|
|
|
OS << " const TargetRegisterClass* const RegisterClasses[] = {\n";
|
2005-08-19 20:47:59 +02:00
|
|
|
for (unsigned i = 0, e = RegisterClasses.size(); i != e; ++i)
|
2011-10-04 17:28:08 +02:00
|
|
|
OS << " &" << RegisterClasses[i]->getQualifiedName()
|
2005-08-19 22:23:42 +02:00
|
|
|
<< "RegClass,\n";
|
2003-10-05 21:27:59 +02:00
|
|
|
OS << " };\n";
|
2011-07-14 22:59:42 +02:00
|
|
|
OS << "}\n"; // End of anonymous namespace...
|
2003-10-05 21:27:59 +02:00
|
|
|
|
2011-06-24 03:44:41 +02:00
|
|
|
// Emit extra information about registers.
|
2011-06-28 22:44:22 +02:00
|
|
|
const std::string &TargetName = Target.getName();
|
2011-06-24 03:44:41 +02:00
|
|
|
OS << "\n static const TargetRegisterInfoDesc "
|
2011-06-28 22:44:22 +02:00
|
|
|
<< TargetName << "RegInfoDesc[] = "
|
2011-06-24 03:44:41 +02:00
|
|
|
<< "{ // Extra Descriptors\n";
|
|
|
|
OS << " { 0, 0 },\n";
|
2004-08-16 03:10:21 +02:00
|
|
|
|
2011-06-24 03:44:41 +02:00
|
|
|
const std::vector<CodeGenRegister*> &Regs = RegBank.getRegisters();
|
2010-05-26 01:43:18 +02:00
|
|
|
for (unsigned i = 0, e = Regs.size(); i != e; ++i) {
|
2011-06-18 06:26:06 +02:00
|
|
|
const CodeGenRegister &Reg = *Regs[i];
|
2011-06-24 03:44:41 +02:00
|
|
|
OS << " { ";
|
|
|
|
OS << Reg.CostPerUse << ", "
|
2011-06-03 01:07:20 +02:00
|
|
|
<< int(AllocatableRegs.count(Reg.TheDef)) << " },\n";
|
2003-10-05 21:27:59 +02:00
|
|
|
}
|
|
|
|
OS << " };\n"; // End of register descriptors...
|
2010-05-25 21:49:38 +02:00
|
|
|
|
2011-06-24 03:44:41 +02:00
|
|
|
|
2011-05-07 23:22:39 +02:00
|
|
|
// Calculate the mapping of subregister+index pairs to physical registers.
|
|
|
|
// This will also create further anonymous indexes.
|
2011-06-10 20:40:00 +02:00
|
|
|
unsigned NamedIndices = RegBank.getNumNamedIndices();
|
2011-05-07 23:22:39 +02:00
|
|
|
|
2010-05-25 21:49:38 +02:00
|
|
|
// Emit SubRegIndex names, skipping 0
|
2012-01-31 21:57:55 +01:00
|
|
|
ArrayRef<CodeGenSubRegIndex*> SubRegIndices = RegBank.getSubRegIndices();
|
2011-07-14 22:59:42 +02:00
|
|
|
OS << "\n static const char *const " << TargetName
|
|
|
|
<< "SubRegIndexTable[] = { \"";
|
2010-05-25 21:49:38 +02:00
|
|
|
for (unsigned i = 0, e = SubRegIndices.size(); i != e; ++i) {
|
|
|
|
OS << SubRegIndices[i]->getName();
|
|
|
|
if (i+1 != e)
|
|
|
|
OS << "\", \"";
|
|
|
|
}
|
|
|
|
OS << "\" };\n\n";
|
2011-05-07 23:22:39 +02:00
|
|
|
|
|
|
|
// Emit names of the anonymus subreg indexes.
|
|
|
|
if (SubRegIndices.size() > NamedIndices) {
|
|
|
|
OS << " enum {";
|
|
|
|
for (unsigned i = NamedIndices, e = SubRegIndices.size(); i != e; ++i) {
|
|
|
|
OS << "\n " << SubRegIndices[i]->getName() << " = " << i+1;
|
|
|
|
if (i+1 != e)
|
|
|
|
OS << ',';
|
|
|
|
}
|
|
|
|
OS << "\n };\n\n";
|
|
|
|
}
|
2011-07-14 22:59:42 +02:00
|
|
|
OS << "\n";
|
2003-10-05 21:27:59 +02:00
|
|
|
|
|
|
|
std::string ClassName = Target.getName() + "GenRegisterInfo";
|
2005-04-22 02:00:37 +02:00
|
|
|
|
2007-05-01 07:57:02 +02:00
|
|
|
// Emit the subregister + index mapping function based on the information
|
|
|
|
// calculated above.
|
2010-05-26 19:27:12 +02:00
|
|
|
OS << "unsigned " << ClassName
|
2007-05-01 07:57:02 +02:00
|
|
|
<< "::getSubReg(unsigned RegNo, unsigned Index) const {\n"
|
|
|
|
<< " switch (RegNo) {\n"
|
2008-09-11 08:25:25 +02:00
|
|
|
<< " default:\n return 0;\n";
|
2010-05-26 19:27:12 +02:00
|
|
|
for (unsigned i = 0, e = Regs.size(); i != e; ++i) {
|
2011-06-18 06:26:06 +02:00
|
|
|
const CodeGenRegister::SubRegMap &SRM = Regs[i]->getSubRegs();
|
2010-05-26 19:27:12 +02:00
|
|
|
if (SRM.empty())
|
|
|
|
continue;
|
2011-06-18 06:26:06 +02:00
|
|
|
OS << " case " << getQualifiedName(Regs[i]->TheDef) << ":\n";
|
2007-05-01 07:57:02 +02:00
|
|
|
OS << " switch (Index) {\n";
|
2008-09-11 19:31:12 +02:00
|
|
|
OS << " default: return 0;\n";
|
2011-06-11 02:28:06 +02:00
|
|
|
for (CodeGenRegister::SubRegMap::const_iterator ii = SRM.begin(),
|
2010-05-29 01:48:31 +02:00
|
|
|
ie = SRM.end(); ii != ie; ++ii)
|
2012-01-31 21:57:55 +01:00
|
|
|
OS << " case " << ii->first->getQualifiedName()
|
2011-06-11 02:28:06 +02:00
|
|
|
<< ": return " << getQualifiedName(ii->second->TheDef) << ";\n";
|
2008-09-11 19:31:12 +02:00
|
|
|
OS << " };\n" << " break;\n";
|
2007-05-01 07:57:02 +02:00
|
|
|
}
|
|
|
|
OS << " };\n";
|
2007-06-05 01:52:59 +02:00
|
|
|
OS << " return 0;\n";
|
2007-05-01 07:57:02 +02:00
|
|
|
OS << "}\n\n";
|
2009-11-14 04:42:17 +01:00
|
|
|
|
2010-05-26 19:27:12 +02:00
|
|
|
OS << "unsigned " << ClassName
|
2009-11-14 04:42:17 +01:00
|
|
|
<< "::getSubRegIndex(unsigned RegNo, unsigned SubRegNo) const {\n"
|
|
|
|
<< " switch (RegNo) {\n"
|
|
|
|
<< " default:\n return 0;\n";
|
2010-05-26 19:27:12 +02:00
|
|
|
for (unsigned i = 0, e = Regs.size(); i != e; ++i) {
|
2011-06-18 06:26:06 +02:00
|
|
|
const CodeGenRegister::SubRegMap &SRM = Regs[i]->getSubRegs();
|
2010-05-26 19:27:12 +02:00
|
|
|
if (SRM.empty())
|
|
|
|
continue;
|
2011-06-18 06:26:06 +02:00
|
|
|
OS << " case " << getQualifiedName(Regs[i]->TheDef) << ":\n";
|
2011-06-11 02:28:06 +02:00
|
|
|
for (CodeGenRegister::SubRegMap::const_iterator ii = SRM.begin(),
|
2010-05-29 01:48:31 +02:00
|
|
|
ie = SRM.end(); ii != ie; ++ii)
|
2011-06-11 02:28:06 +02:00
|
|
|
OS << " if (SubRegNo == " << getQualifiedName(ii->second->TheDef)
|
2012-01-31 21:57:55 +01:00
|
|
|
<< ") return " << ii->first->getQualifiedName() << ";\n";
|
2009-11-14 04:42:17 +01:00
|
|
|
OS << " return 0;\n";
|
|
|
|
}
|
|
|
|
OS << " };\n";
|
|
|
|
OS << " return 0;\n";
|
|
|
|
OS << "}\n\n";
|
2010-05-29 01:48:31 +02:00
|
|
|
|
|
|
|
// Emit composeSubRegIndices
|
|
|
|
OS << "unsigned " << ClassName
|
|
|
|
<< "::composeSubRegIndices(unsigned IdxA, unsigned IdxB) const {\n"
|
|
|
|
<< " switch (IdxA) {\n"
|
|
|
|
<< " default:\n return IdxB;\n";
|
|
|
|
for (unsigned i = 0, e = SubRegIndices.size(); i != e; ++i) {
|
|
|
|
bool Open = false;
|
|
|
|
for (unsigned j = 0; j != e; ++j) {
|
2012-01-31 21:57:55 +01:00
|
|
|
if (CodeGenSubRegIndex *Comp =
|
2012-01-31 22:44:11 +01:00
|
|
|
SubRegIndices[i]->compose(SubRegIndices[j])) {
|
2010-05-29 01:48:31 +02:00
|
|
|
if (!Open) {
|
2012-01-31 21:57:55 +01:00
|
|
|
OS << " case " << SubRegIndices[i]->getQualifiedName()
|
2010-05-29 01:48:31 +02:00
|
|
|
<< ": switch(IdxB) {\n default: return IdxB;\n";
|
|
|
|
Open = true;
|
|
|
|
}
|
2012-01-31 21:57:55 +01:00
|
|
|
OS << " case " << SubRegIndices[j]->getQualifiedName()
|
|
|
|
<< ": return " << Comp->getQualifiedName() << ";\n";
|
2010-05-29 01:48:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (Open)
|
|
|
|
OS << " }\n";
|
|
|
|
}
|
|
|
|
OS << " }\n}\n\n";
|
|
|
|
|
2011-10-05 02:35:49 +02:00
|
|
|
// Emit getSubClassWithSubReg.
|
|
|
|
OS << "const TargetRegisterClass *" << ClassName
|
|
|
|
<< "::getSubClassWithSubReg(const TargetRegisterClass *RC, unsigned Idx)"
|
|
|
|
" const {\n";
|
|
|
|
if (SubRegIndices.empty()) {
|
|
|
|
OS << " assert(Idx == 0 && \"Target has no sub-registers\");\n"
|
|
|
|
<< " return RC;\n";
|
|
|
|
} else {
|
|
|
|
// Use the smallest type that can hold a regclass ID with room for a
|
|
|
|
// sentinel.
|
|
|
|
if (RegisterClasses.size() < UINT8_MAX)
|
|
|
|
OS << " static const uint8_t Table[";
|
|
|
|
else if (RegisterClasses.size() < UINT16_MAX)
|
|
|
|
OS << " static const uint16_t Table[";
|
|
|
|
else
|
|
|
|
throw "Too many register classes.";
|
|
|
|
OS << RegisterClasses.size() << "][" << SubRegIndices.size() << "] = {\n";
|
|
|
|
for (unsigned rci = 0, rce = RegisterClasses.size(); rci != rce; ++rci) {
|
|
|
|
const CodeGenRegisterClass &RC = *RegisterClasses[rci];
|
|
|
|
OS << " {\t// " << RC.getName() << "\n";
|
|
|
|
for (unsigned sri = 0, sre = SubRegIndices.size(); sri != sre; ++sri) {
|
2012-01-31 21:57:55 +01:00
|
|
|
CodeGenSubRegIndex *Idx = SubRegIndices[sri];
|
2011-10-05 02:35:49 +02:00
|
|
|
if (CodeGenRegisterClass *SRC = RC.getSubClassWithSubReg(Idx))
|
|
|
|
OS << " " << SRC->EnumValue + 1 << ",\t// " << Idx->getName()
|
|
|
|
<< " -> " << SRC->getName() << "\n";
|
|
|
|
else
|
|
|
|
OS << " 0,\t// " << Idx->getName() << "\n";
|
|
|
|
}
|
|
|
|
OS << " },\n";
|
|
|
|
}
|
|
|
|
OS << " };\n assert(RC && \"Missing regclass\");\n"
|
|
|
|
<< " if (!Idx) return RC;\n --Idx;\n"
|
|
|
|
<< " assert(Idx < " << SubRegIndices.size() << " && \"Bad subreg\");\n"
|
|
|
|
<< " unsigned TV = Table[RC->getID()][Idx];\n"
|
|
|
|
<< " return TV ? getRegClass(TV - 1) : 0;\n";
|
|
|
|
}
|
|
|
|
OS << "}\n\n";
|
|
|
|
|
2011-12-19 17:53:34 +01:00
|
|
|
// Emit getMatchingSuperRegClass.
|
|
|
|
OS << "const TargetRegisterClass *" << ClassName
|
|
|
|
<< "::getMatchingSuperRegClass(const TargetRegisterClass *A,"
|
|
|
|
" const TargetRegisterClass *B, unsigned Idx) const {\n";
|
|
|
|
if (SubRegIndices.empty()) {
|
|
|
|
OS << " llvm_unreachable(\"Target has no sub-registers\");\n";
|
|
|
|
} else {
|
|
|
|
// We need to find the largest sub-class of A such that every register has
|
|
|
|
// an Idx sub-register in B. Map (B, Idx) to a bit-vector of
|
|
|
|
// super-register classes that map into B. Then compute the largest common
|
|
|
|
// sub-class with A by taking advantage of the register class ordering,
|
|
|
|
// like getCommonSubClass().
|
|
|
|
|
|
|
|
// Bitvector table is NumRCs x NumSubIndexes x BVWords, where BVWords is
|
|
|
|
// the number of 32-bit words required to represent all register classes.
|
|
|
|
const unsigned BVWords = (RegisterClasses.size()+31)/32;
|
|
|
|
BitVector BV(RegisterClasses.size());
|
|
|
|
|
|
|
|
OS << " static const unsigned Table[" << RegisterClasses.size()
|
|
|
|
<< "][" << SubRegIndices.size() << "][" << BVWords << "] = {\n";
|
|
|
|
for (unsigned rci = 0, rce = RegisterClasses.size(); rci != rce; ++rci) {
|
|
|
|
const CodeGenRegisterClass &RC = *RegisterClasses[rci];
|
|
|
|
OS << " {\t// " << RC.getName() << "\n";
|
|
|
|
for (unsigned sri = 0, sre = SubRegIndices.size(); sri != sre; ++sri) {
|
2012-01-31 21:57:55 +01:00
|
|
|
CodeGenSubRegIndex *Idx = SubRegIndices[sri];
|
2011-12-19 17:53:34 +01:00
|
|
|
BV.reset();
|
|
|
|
RC.getSuperRegClasses(Idx, BV);
|
|
|
|
OS << " { ";
|
|
|
|
printBitVectorAsHex(OS, BV, 32);
|
|
|
|
OS << "},\t// " << Idx->getName() << '\n';
|
|
|
|
}
|
|
|
|
OS << " },\n";
|
|
|
|
}
|
|
|
|
OS << " };\n assert(A && B && \"Missing regclass\");\n"
|
|
|
|
<< " --Idx;\n"
|
|
|
|
<< " assert(Idx < " << SubRegIndices.size() << " && \"Bad subreg\");\n"
|
|
|
|
<< " const unsigned *TV = Table[B->getID()][Idx];\n"
|
|
|
|
<< " const unsigned *SC = A->getSubClassMask();\n"
|
|
|
|
<< " for (unsigned i = 0; i != " << BVWords << "; ++i)\n"
|
|
|
|
<< " if (unsigned Common = TV[i] & SC[i])\n"
|
|
|
|
<< " return getRegClass(32*i + CountTrailingZeros_32(Common));\n"
|
|
|
|
<< " return 0;\n";
|
|
|
|
}
|
|
|
|
OS << "}\n\n";
|
|
|
|
|
2003-10-05 21:27:59 +02:00
|
|
|
// Emit the constructor of the class...
|
2011-10-22 18:50:00 +02:00
|
|
|
OS << "extern const MCRegisterDesc " << TargetName << "RegDesc[];\n";
|
2012-02-21 07:23:21 +01:00
|
|
|
OS << "extern const unsigned " << TargetName << "RegOverlaps[];\n";
|
|
|
|
OS << "extern const unsigned " << TargetName << "SubRegsSet[];\n";
|
|
|
|
OS << "extern const unsigned " << TargetName << "SuperRegsSet[];\n";
|
2011-07-14 22:59:42 +02:00
|
|
|
|
2003-10-05 21:27:59 +02:00
|
|
|
OS << ClassName << "::" << ClassName
|
2011-07-18 22:57:22 +02:00
|
|
|
<< "(unsigned RA, unsigned DwarfFlavour, unsigned EHFlavour)\n"
|
2011-06-28 22:44:22 +02:00
|
|
|
<< " : TargetRegisterInfo(" << TargetName << "RegInfoDesc"
|
2010-05-25 21:49:38 +02:00
|
|
|
<< ", RegisterClasses, RegisterClasses+" << RegisterClasses.size() <<",\n"
|
2011-07-14 22:59:42 +02:00
|
|
|
<< " " << TargetName << "SubRegIndexTable) {\n"
|
2011-06-28 22:44:22 +02:00
|
|
|
<< " InitMCRegisterInfo(" << TargetName << "RegDesc, "
|
2011-07-22 02:44:39 +02:00
|
|
|
<< Regs.size()+1 << ", RA, " << TargetName << "MCRegisterClasses, "
|
2012-02-21 07:23:21 +01:00
|
|
|
<< RegisterClasses.size() << ", " << TargetName << "RegOverlaps, "
|
|
|
|
<< TargetName << "SubRegsSet, " << TargetName << "SuperRegsSet);\n\n";
|
2011-03-11 02:19:05 +01:00
|
|
|
|
2011-07-18 22:57:22 +02:00
|
|
|
EmitRegMapping(OS, Regs, true);
|
2011-03-11 02:19:05 +01:00
|
|
|
|
2011-07-18 22:57:22 +02:00
|
|
|
OS << "}\n\n";
|
2005-09-30 08:44:45 +02:00
|
|
|
|
2012-01-17 23:46:58 +01:00
|
|
|
|
|
|
|
// Emit CalleeSavedRegs information.
|
|
|
|
std::vector<Record*> CSRSets =
|
|
|
|
Records.getAllDerivedDefinitions("CalleeSavedRegs");
|
|
|
|
for (unsigned i = 0, e = CSRSets.size(); i != e; ++i) {
|
|
|
|
Record *CSRSet = CSRSets[i];
|
|
|
|
const SetTheory::RecVec *Regs = RegBank.getSets().expand(CSRSet);
|
|
|
|
assert(Regs && "Cannot expand CalleeSavedRegs instance");
|
|
|
|
|
|
|
|
// Emit the *_SaveList list of callee-saved registers.
|
|
|
|
OS << "static const unsigned " << CSRSet->getName()
|
|
|
|
<< "_SaveList[] = { ";
|
|
|
|
for (unsigned r = 0, re = Regs->size(); r != re; ++r)
|
|
|
|
OS << getQualifiedName((*Regs)[r]) << ", ";
|
|
|
|
OS << "0 };\n";
|
|
|
|
|
|
|
|
// Emit the *_RegMask bit mask of call-preserved registers.
|
|
|
|
OS << "static const uint32_t " << CSRSet->getName()
|
|
|
|
<< "_RegMask[] = { ";
|
|
|
|
printBitVectorAsHex(OS, RegBank.computeCoveredRegisters(*Regs), 32);
|
|
|
|
OS << "};\n";
|
|
|
|
}
|
|
|
|
OS << "\n\n";
|
|
|
|
|
2004-08-17 05:08:28 +02:00
|
|
|
OS << "} // End llvm namespace \n";
|
2011-06-27 20:32:37 +02:00
|
|
|
OS << "#endif // GET_REGINFO_TARGET_DESC\n\n";
|
2003-10-05 21:27:59 +02:00
|
|
|
}
|
2011-06-24 03:44:41 +02:00
|
|
|
|
2011-06-27 20:32:37 +02:00
|
|
|
void RegisterInfoEmitter::run(raw_ostream &OS) {
|
2011-06-24 03:44:41 +02:00
|
|
|
CodeGenTarget Target(Records);
|
|
|
|
CodeGenRegBank &RegBank = Target.getRegBank();
|
|
|
|
RegBank.computeDerivedInfo();
|
|
|
|
|
2011-06-27 20:32:37 +02:00
|
|
|
runEnums(OS, Target, RegBank);
|
|
|
|
runMCDesc(OS, Target, RegBank);
|
2011-06-27 21:24:13 +02:00
|
|
|
runTargetHeader(OS, Target, RegBank);
|
2011-06-27 20:32:37 +02:00
|
|
|
runTargetDesc(OS, Target, RegBank);
|
2011-06-24 03:44:41 +02:00
|
|
|
}
|