2008-01-06 01:35:39 +00:00
|
|
|
//===- CodeGenTarget.cpp - CodeGen Target Class Wrapper -------------------===//
|
2005-04-22 00:00:37 +00:00
|
|
|
//
|
2003-10-20 20:20:30 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 20:37:13 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-22 00:00:37 +00:00
|
|
|
//
|
2003-10-20 20:20:30 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2003-08-07 05:38:11 +00:00
|
|
|
//
|
2008-01-06 01:35:39 +00:00
|
|
|
// This class wraps target description classes used by the various code
|
2003-08-07 05:38:11 +00:00
|
|
|
// generation TableGen backends. This makes it easier to access the data and
|
|
|
|
// provides a single place that needs to check it for validity. All of these
|
|
|
|
// classes throw exceptions on error conditions.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2004-08-01 04:04:35 +00:00
|
|
|
#include "CodeGenTarget.h"
|
2006-03-24 19:49:31 +00:00
|
|
|
#include "CodeGenIntrinsics.h"
|
2003-08-07 05:38:11 +00:00
|
|
|
#include "Record.h"
|
2004-10-03 19:34:31 +00:00
|
|
|
#include "llvm/ADT/StringExtras.h"
|
2010-03-27 20:32:26 +00:00
|
|
|
#include "llvm/ADT/STLExtras.h"
|
2004-10-03 19:34:31 +00:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
2005-10-14 03:54:49 +00:00
|
|
|
#include <algorithm>
|
2004-08-01 03:55:39 +00:00
|
|
|
using namespace llvm;
|
2003-11-11 22:41:34 +00:00
|
|
|
|
2009-07-29 00:02:19 +00:00
|
|
|
static cl::opt<unsigned>
|
|
|
|
AsmParserNum("asmparsernum", cl::init(0),
|
|
|
|
cl::desc("Make -gen-asm-parser emit assembly parser #N"));
|
|
|
|
|
2004-10-03 19:34:31 +00:00
|
|
|
static cl::opt<unsigned>
|
|
|
|
AsmWriterNum("asmwriternum", cl::init(0),
|
|
|
|
cl::desc("Make -gen-asm-writer emit assembly writer #N"));
|
|
|
|
|
2009-08-11 20:47:22 +00:00
|
|
|
/// getValueType - Return the MVT::SimpleValueType that the specified TableGen
|
2008-06-06 12:08:01 +00:00
|
|
|
/// record corresponds to.
|
2009-08-11 20:47:22 +00:00
|
|
|
MVT::SimpleValueType llvm::getValueType(Record *Rec) {
|
|
|
|
return (MVT::SimpleValueType)Rec->getValueAsInt("Value");
|
2003-08-07 05:38:11 +00:00
|
|
|
}
|
|
|
|
|
2009-08-11 20:47:22 +00:00
|
|
|
std::string llvm::getName(MVT::SimpleValueType T) {
|
2003-08-07 05:38:11 +00:00
|
|
|
switch (T) {
|
2009-08-11 20:47:22 +00:00
|
|
|
case MVT::Other: return "UNKNOWN";
|
|
|
|
case MVT::iPTR: return "TLI.getPointerTy()";
|
|
|
|
case MVT::iPTRAny: return "TLI.getPointerTy()";
|
2009-07-10 22:25:24 +00:00
|
|
|
default: return getEnumName(T);
|
2003-08-07 05:38:11 +00:00
|
|
|
}
|
2003-08-07 23:15:21 +00:00
|
|
|
}
|
|
|
|
|
2009-08-11 20:47:22 +00:00
|
|
|
std::string llvm::getEnumName(MVT::SimpleValueType T) {
|
2003-08-10 19:50:32 +00:00
|
|
|
switch (T) {
|
2009-08-11 20:47:22 +00:00
|
|
|
case MVT::Other: return "MVT::Other";
|
|
|
|
case MVT::i1: return "MVT::i1";
|
|
|
|
case MVT::i8: return "MVT::i8";
|
|
|
|
case MVT::i16: return "MVT::i16";
|
|
|
|
case MVT::i32: return "MVT::i32";
|
|
|
|
case MVT::i64: return "MVT::i64";
|
|
|
|
case MVT::i128: return "MVT::i128";
|
|
|
|
case MVT::iAny: return "MVT::iAny";
|
|
|
|
case MVT::fAny: return "MVT::fAny";
|
|
|
|
case MVT::vAny: return "MVT::vAny";
|
|
|
|
case MVT::f32: return "MVT::f32";
|
|
|
|
case MVT::f64: return "MVT::f64";
|
|
|
|
case MVT::f80: return "MVT::f80";
|
|
|
|
case MVT::f128: return "MVT::f128";
|
|
|
|
case MVT::ppcf128: return "MVT::ppcf128";
|
|
|
|
case MVT::Flag: return "MVT::Flag";
|
|
|
|
case MVT::isVoid:return "MVT::isVoid";
|
|
|
|
case MVT::v2i8: return "MVT::v2i8";
|
|
|
|
case MVT::v4i8: return "MVT::v4i8";
|
|
|
|
case MVT::v8i8: return "MVT::v8i8";
|
|
|
|
case MVT::v16i8: return "MVT::v16i8";
|
|
|
|
case MVT::v32i8: return "MVT::v32i8";
|
|
|
|
case MVT::v2i16: return "MVT::v2i16";
|
|
|
|
case MVT::v4i16: return "MVT::v4i16";
|
|
|
|
case MVT::v8i16: return "MVT::v8i16";
|
|
|
|
case MVT::v16i16: return "MVT::v16i16";
|
|
|
|
case MVT::v2i32: return "MVT::v2i32";
|
|
|
|
case MVT::v4i32: return "MVT::v4i32";
|
|
|
|
case MVT::v8i32: return "MVT::v8i32";
|
|
|
|
case MVT::v1i64: return "MVT::v1i64";
|
|
|
|
case MVT::v2i64: return "MVT::v2i64";
|
|
|
|
case MVT::v4i64: return "MVT::v4i64";
|
|
|
|
case MVT::v2f32: return "MVT::v2f32";
|
|
|
|
case MVT::v4f32: return "MVT::v4f32";
|
|
|
|
case MVT::v8f32: return "MVT::v8f32";
|
|
|
|
case MVT::v2f64: return "MVT::v2f64";
|
|
|
|
case MVT::v4f64: return "MVT::v4f64";
|
|
|
|
case MVT::Metadata: return "MVT::Metadata";
|
|
|
|
case MVT::iPTR: return "MVT::iPTR";
|
|
|
|
case MVT::iPTRAny: return "MVT::iPTRAny";
|
2003-08-10 19:50:32 +00:00
|
|
|
default: assert(0 && "ILLEGAL VALUE TYPE!"); return "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-05 22:25:12 +00:00
|
|
|
/// getQualifiedName - Return the name of the specified record, with a
|
|
|
|
/// namespace qualifier if the record contains one.
|
|
|
|
///
|
|
|
|
std::string llvm::getQualifiedName(const Record *R) {
|
|
|
|
std::string Namespace = R->getValueAsString("Namespace");
|
|
|
|
if (Namespace.empty()) return R->getName();
|
|
|
|
return Namespace + "::" + R->getName();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2003-08-07 23:15:21 +00:00
|
|
|
|
2003-08-07 05:38:11 +00:00
|
|
|
/// getTarget - Return the current instance of the Target class.
|
|
|
|
///
|
2006-05-17 20:37:59 +00:00
|
|
|
CodeGenTarget::CodeGenTarget() {
|
2003-08-07 05:38:11 +00:00
|
|
|
std::vector<Record*> Targets = Records.getAllDerivedDefinitions("Target");
|
2004-06-04 14:59:42 +00:00
|
|
|
if (Targets.size() == 0)
|
2005-04-22 00:00:37 +00:00
|
|
|
throw std::string("ERROR: No 'Target' subclasses defined!");
|
2003-08-07 05:38:11 +00:00
|
|
|
if (Targets.size() != 1)
|
|
|
|
throw std::string("ERROR: Multiple subclasses of Target defined!");
|
|
|
|
TargetRec = Targets[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const std::string &CodeGenTarget::getName() const {
|
|
|
|
return TargetRec->getName();
|
|
|
|
}
|
|
|
|
|
2008-08-20 21:45:57 +00:00
|
|
|
std::string CodeGenTarget::getInstNamespace() const {
|
|
|
|
for (inst_iterator i = inst_begin(), e = inst_end(); i != e; ++i) {
|
2010-03-19 01:00:55 +00:00
|
|
|
// Make sure not to pick up "TargetOpcode" by accidentally getting
|
2008-08-20 21:45:57 +00:00
|
|
|
// the namespace off the PHI instruction or something.
|
2010-03-19 01:00:55 +00:00
|
|
|
if ((*i)->Namespace != "TargetOpcode")
|
|
|
|
return (*i)->Namespace;
|
2008-08-20 21:45:57 +00:00
|
|
|
}
|
|
|
|
|
2010-03-19 01:00:55 +00:00
|
|
|
return "";
|
2008-08-20 21:45:57 +00:00
|
|
|
}
|
|
|
|
|
2003-08-07 05:38:11 +00:00
|
|
|
Record *CodeGenTarget::getInstructionSet() const {
|
|
|
|
return TargetRec->getValueAsDef("InstructionSet");
|
|
|
|
}
|
2003-11-11 22:41:34 +00:00
|
|
|
|
2010-03-19 00:07:20 +00:00
|
|
|
|
2009-07-29 00:02:19 +00:00
|
|
|
/// getAsmParser - Return the AssemblyParser definition for this target.
|
|
|
|
///
|
|
|
|
Record *CodeGenTarget::getAsmParser() const {
|
|
|
|
std::vector<Record*> LI = TargetRec->getValueAsListOfDefs("AssemblyParsers");
|
|
|
|
if (AsmParserNum >= LI.size())
|
|
|
|
throw "Target does not have an AsmParser #" + utostr(AsmParserNum) + "!";
|
|
|
|
return LI[AsmParserNum];
|
|
|
|
}
|
|
|
|
|
2004-08-14 22:50:53 +00:00
|
|
|
/// getAsmWriter - Return the AssemblyWriter definition for this target.
|
|
|
|
///
|
|
|
|
Record *CodeGenTarget::getAsmWriter() const {
|
2005-10-28 22:49:02 +00:00
|
|
|
std::vector<Record*> LI = TargetRec->getValueAsListOfDefs("AssemblyWriters");
|
|
|
|
if (AsmWriterNum >= LI.size())
|
2004-10-03 19:34:31 +00:00
|
|
|
throw "Target does not have an AsmWriter #" + utostr(AsmWriterNum) + "!";
|
2005-10-28 22:49:02 +00:00
|
|
|
return LI[AsmWriterNum];
|
2004-08-14 22:50:53 +00:00
|
|
|
}
|
|
|
|
|
2004-08-16 01:10:21 +00:00
|
|
|
void CodeGenTarget::ReadRegisters() const {
|
|
|
|
std::vector<Record*> Regs = Records.getAllDerivedDefinitions("Register");
|
|
|
|
if (Regs.empty())
|
|
|
|
throw std::string("No 'Register' subclasses defined!");
|
|
|
|
|
|
|
|
Registers.reserve(Regs.size());
|
|
|
|
Registers.assign(Regs.begin(), Regs.end());
|
|
|
|
}
|
|
|
|
|
2004-08-21 02:24:57 +00:00
|
|
|
CodeGenRegister::CodeGenRegister(Record *R) : TheDef(R) {
|
|
|
|
DeclaredSpillSize = R->getValueAsInt("SpillSize");
|
|
|
|
DeclaredSpillAlignment = R->getValueAsInt("SpillAlignment");
|
|
|
|
}
|
|
|
|
|
2004-08-16 01:10:21 +00:00
|
|
|
const std::string &CodeGenRegister::getName() const {
|
|
|
|
return TheDef->getName();
|
|
|
|
}
|
|
|
|
|
2004-08-21 04:05:00 +00:00
|
|
|
void CodeGenTarget::ReadRegisterClasses() const {
|
|
|
|
std::vector<Record*> RegClasses =
|
|
|
|
Records.getAllDerivedDefinitions("RegisterClass");
|
|
|
|
if (RegClasses.empty())
|
|
|
|
throw std::string("No 'RegisterClass' subclasses defined!");
|
|
|
|
|
|
|
|
RegisterClasses.reserve(RegClasses.size());
|
|
|
|
RegisterClasses.assign(RegClasses.begin(), RegClasses.end());
|
|
|
|
}
|
|
|
|
|
2010-03-15 06:00:16 +00:00
|
|
|
std::vector<MVT::SimpleValueType> CodeGenTarget::
|
|
|
|
getRegisterVTs(Record *R) const {
|
|
|
|
std::vector<MVT::SimpleValueType> Result;
|
2006-05-16 07:05:30 +00:00
|
|
|
const std::vector<CodeGenRegisterClass> &RCs = getRegisterClasses();
|
|
|
|
for (unsigned i = 0, e = RCs.size(); i != e; ++i) {
|
|
|
|
const CodeGenRegisterClass &RC = RegisterClasses[i];
|
|
|
|
for (unsigned ei = 0, ee = RC.Elements.size(); ei != ee; ++ei) {
|
|
|
|
if (R == RC.Elements[ei]) {
|
2009-08-11 20:47:22 +00:00
|
|
|
const std::vector<MVT::SimpleValueType> &InVTs = RC.getValueTypes();
|
2010-03-15 06:00:16 +00:00
|
|
|
Result.insert(Result.end(), InVTs.begin(), InVTs.end());
|
2006-05-16 07:05:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-03-27 20:32:26 +00:00
|
|
|
|
|
|
|
// Remove duplicates.
|
|
|
|
array_pod_sort(Result.begin(), Result.end());
|
|
|
|
Result.erase(std::unique(Result.begin(), Result.end()), Result.end());
|
2006-05-16 07:05:30 +00:00
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-08-21 04:05:00 +00:00
|
|
|
CodeGenRegisterClass::CodeGenRegisterClass(Record *R) : TheDef(R) {
|
2005-08-19 18:45:20 +00:00
|
|
|
// Rename anonymous register classes.
|
|
|
|
if (R->getName().size() > 9 && R->getName()[9] == '.') {
|
|
|
|
static unsigned AnonCounter = 0;
|
|
|
|
R->setName("AnonRegClass_"+utostr(AnonCounter++));
|
|
|
|
}
|
|
|
|
|
2005-12-01 04:51:06 +00:00
|
|
|
std::vector<Record*> TypeList = R->getValueAsListOfDefs("RegTypes");
|
|
|
|
for (unsigned i = 0, e = TypeList.size(); i != e; ++i) {
|
|
|
|
Record *Type = TypeList[i];
|
|
|
|
if (!Type->isSubClassOf("ValueType"))
|
|
|
|
throw "RegTypes list member '" + Type->getName() +
|
|
|
|
"' does not derive from the ValueType class!";
|
|
|
|
VTs.push_back(getValueType(Type));
|
|
|
|
}
|
|
|
|
assert(!VTs.empty() && "RegisterClass must contain at least one ValueType!");
|
2005-08-19 19:12:51 +00:00
|
|
|
|
2005-10-28 22:49:02 +00:00
|
|
|
std::vector<Record*> RegList = R->getValueAsListOfDefs("MemberList");
|
|
|
|
for (unsigned i = 0, e = RegList.size(); i != e; ++i) {
|
|
|
|
Record *Reg = RegList[i];
|
2004-08-21 04:05:00 +00:00
|
|
|
if (!Reg->isSubClassOf("Register"))
|
|
|
|
throw "Register Class member '" + Reg->getName() +
|
|
|
|
"' does not derive from the Register class!";
|
|
|
|
Elements.push_back(Reg);
|
|
|
|
}
|
2005-12-01 04:51:06 +00:00
|
|
|
|
2007-06-13 22:20:15 +00:00
|
|
|
std::vector<Record*> SubRegClassList =
|
|
|
|
R->getValueAsListOfDefs("SubRegClassList");
|
|
|
|
for (unsigned i = 0, e = SubRegClassList.size(); i != e; ++i) {
|
|
|
|
Record *SubRegClass = SubRegClassList[i];
|
|
|
|
if (!SubRegClass->isSubClassOf("RegisterClass"))
|
|
|
|
throw "Register Class member '" + SubRegClass->getName() +
|
|
|
|
"' does not derive from the RegisterClass class!";
|
|
|
|
SubRegClasses.push_back(SubRegClass);
|
|
|
|
}
|
|
|
|
|
2005-12-01 04:51:06 +00:00
|
|
|
// Allow targets to override the size in bits of the RegisterClass.
|
|
|
|
unsigned Size = R->getValueAsInt("Size");
|
|
|
|
|
|
|
|
Namespace = R->getValueAsString("Namespace");
|
2009-08-10 22:56:29 +00:00
|
|
|
SpillSize = Size ? Size : EVT(VTs[0]).getSizeInBits();
|
2005-12-01 04:51:06 +00:00
|
|
|
SpillAlignment = R->getValueAsInt("Alignment");
|
2007-09-19 01:35:01 +00:00
|
|
|
CopyCost = R->getValueAsInt("CopyCost");
|
2005-12-01 04:51:06 +00:00
|
|
|
MethodBodies = R->getValueAsCode("MethodBodies");
|
|
|
|
MethodProtos = R->getValueAsCode("MethodProtos");
|
2004-08-21 04:05:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const std::string &CodeGenRegisterClass::getName() const {
|
|
|
|
return TheDef->getName();
|
|
|
|
}
|
|
|
|
|
2005-09-08 21:43:21 +00:00
|
|
|
void CodeGenTarget::ReadLegalValueTypes() const {
|
|
|
|
const std::vector<CodeGenRegisterClass> &RCs = getRegisterClasses();
|
|
|
|
for (unsigned i = 0, e = RCs.size(); i != e; ++i)
|
2005-12-01 04:51:06 +00:00
|
|
|
for (unsigned ri = 0, re = RCs[i].VTs.size(); ri != re; ++ri)
|
|
|
|
LegalValueTypes.push_back(RCs[i].VTs[ri]);
|
2005-10-14 03:54:49 +00:00
|
|
|
|
|
|
|
// Remove duplicates.
|
|
|
|
std::sort(LegalValueTypes.begin(), LegalValueTypes.end());
|
|
|
|
LegalValueTypes.erase(std::unique(LegalValueTypes.begin(),
|
|
|
|
LegalValueTypes.end()),
|
|
|
|
LegalValueTypes.end());
|
2005-09-08 21:43:21 +00:00
|
|
|
}
|
2004-08-21 04:05:00 +00:00
|
|
|
|
2004-08-14 22:50:53 +00:00
|
|
|
|
2004-08-01 05:04:00 +00:00
|
|
|
void CodeGenTarget::ReadInstructions() const {
|
|
|
|
std::vector<Record*> Insts = Records.getAllDerivedDefinitions("Instruction");
|
2006-01-27 01:45:06 +00:00
|
|
|
if (Insts.size() <= 2)
|
2004-08-01 05:04:00 +00:00
|
|
|
throw std::string("No 'Instruction' subclasses defined!");
|
|
|
|
|
2006-01-27 01:45:06 +00:00
|
|
|
// Parse the instructions defined in the .td file.
|
2004-08-14 22:50:53 +00:00
|
|
|
std::string InstFormatName =
|
|
|
|
getAsmWriter()->getValueAsString("InstFormatName");
|
|
|
|
|
|
|
|
for (unsigned i = 0, e = Insts.size(); i != e; ++i) {
|
|
|
|
std::string AsmStr = Insts[i]->getValueAsString(InstFormatName);
|
2010-03-19 01:07:44 +00:00
|
|
|
Instructions[Insts[i]] = new CodeGenInstruction(Insts[i], AsmStr);
|
2004-08-14 22:50:53 +00:00
|
|
|
}
|
2004-08-01 05:04:00 +00:00
|
|
|
}
|
|
|
|
|
2010-03-19 00:23:20 +00:00
|
|
|
static const CodeGenInstruction *
|
|
|
|
GetInstByName(const char *Name,
|
2010-03-19 01:07:44 +00:00
|
|
|
const DenseMap<const Record*, CodeGenInstruction*> &Insts) {
|
|
|
|
const Record *Rec = Records.getDef(Name);
|
|
|
|
|
|
|
|
DenseMap<const Record*, CodeGenInstruction*>::const_iterator
|
|
|
|
I = Insts.find(Rec);
|
|
|
|
if (Rec == 0 || I == Insts.end())
|
2010-03-19 00:23:20 +00:00
|
|
|
throw std::string("Could not find '") + Name + "' instruction!";
|
2010-03-19 01:07:44 +00:00
|
|
|
return I->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
/// SortInstByName - Sorting predicate to sort instructions by name.
|
|
|
|
///
|
|
|
|
struct SortInstByName {
|
|
|
|
bool operator()(const CodeGenInstruction *Rec1,
|
|
|
|
const CodeGenInstruction *Rec2) const {
|
|
|
|
return Rec1->TheDef->getName() < Rec2->TheDef->getName();
|
|
|
|
}
|
|
|
|
};
|
2010-03-19 00:23:20 +00:00
|
|
|
}
|
|
|
|
|
2005-01-22 18:58:51 +00:00
|
|
|
/// getInstructionsByEnumValue - Return all of the instructions defined by the
|
|
|
|
/// target, ordered by their enum value.
|
2010-03-19 01:00:55 +00:00
|
|
|
void CodeGenTarget::ComputeInstrsByEnum() const {
|
2010-03-19 01:07:44 +00:00
|
|
|
const DenseMap<const Record*, CodeGenInstruction*> &Insts = getInstructions();
|
2010-03-19 00:23:20 +00:00
|
|
|
const CodeGenInstruction *PHI = GetInstByName("PHI", Insts);
|
|
|
|
const CodeGenInstruction *INLINEASM = GetInstByName("INLINEASM", Insts);
|
|
|
|
const CodeGenInstruction *DBG_LABEL = GetInstByName("DBG_LABEL", Insts);
|
|
|
|
const CodeGenInstruction *EH_LABEL = GetInstByName("EH_LABEL", Insts);
|
|
|
|
const CodeGenInstruction *GC_LABEL = GetInstByName("GC_LABEL", Insts);
|
|
|
|
const CodeGenInstruction *KILL = GetInstByName("KILL", Insts);
|
|
|
|
const CodeGenInstruction *EXTRACT_SUBREG =
|
|
|
|
GetInstByName("EXTRACT_SUBREG", Insts);
|
|
|
|
const CodeGenInstruction *INSERT_SUBREG =
|
|
|
|
GetInstByName("INSERT_SUBREG", Insts);
|
|
|
|
const CodeGenInstruction *IMPLICIT_DEF = GetInstByName("IMPLICIT_DEF", Insts);
|
|
|
|
const CodeGenInstruction *SUBREG_TO_REG =
|
|
|
|
GetInstByName("SUBREG_TO_REG", Insts);
|
|
|
|
const CodeGenInstruction *COPY_TO_REGCLASS =
|
|
|
|
GetInstByName("COPY_TO_REGCLASS", Insts);
|
|
|
|
const CodeGenInstruction *DBG_VALUE = GetInstByName("DBG_VALUE", Insts);
|
2010-01-08 23:51:25 +00:00
|
|
|
|
2005-01-22 18:58:51 +00:00
|
|
|
// Print out the rest of the instructions now.
|
2010-03-19 00:34:35 +00:00
|
|
|
InstrsByEnum.push_back(PHI);
|
|
|
|
InstrsByEnum.push_back(INLINEASM);
|
|
|
|
InstrsByEnum.push_back(DBG_LABEL);
|
|
|
|
InstrsByEnum.push_back(EH_LABEL);
|
|
|
|
InstrsByEnum.push_back(GC_LABEL);
|
|
|
|
InstrsByEnum.push_back(KILL);
|
|
|
|
InstrsByEnum.push_back(EXTRACT_SUBREG);
|
|
|
|
InstrsByEnum.push_back(INSERT_SUBREG);
|
|
|
|
InstrsByEnum.push_back(IMPLICIT_DEF);
|
|
|
|
InstrsByEnum.push_back(SUBREG_TO_REG);
|
|
|
|
InstrsByEnum.push_back(COPY_TO_REGCLASS);
|
|
|
|
InstrsByEnum.push_back(DBG_VALUE);
|
2010-03-19 01:00:55 +00:00
|
|
|
|
2010-03-19 01:07:44 +00:00
|
|
|
unsigned EndOfPredefines = InstrsByEnum.size();
|
2010-03-19 01:00:55 +00:00
|
|
|
|
2010-03-19 01:07:44 +00:00
|
|
|
for (DenseMap<const Record*, CodeGenInstruction*>::const_iterator
|
|
|
|
I = Insts.begin(), E = Insts.end(); I != E; ++I) {
|
|
|
|
const CodeGenInstruction *CGI = I->second;
|
2010-03-19 01:00:55 +00:00
|
|
|
if (CGI != PHI &&
|
|
|
|
CGI != INLINEASM &&
|
|
|
|
CGI != DBG_LABEL &&
|
|
|
|
CGI != EH_LABEL &&
|
|
|
|
CGI != GC_LABEL &&
|
|
|
|
CGI != KILL &&
|
|
|
|
CGI != EXTRACT_SUBREG &&
|
|
|
|
CGI != INSERT_SUBREG &&
|
|
|
|
CGI != IMPLICIT_DEF &&
|
|
|
|
CGI != SUBREG_TO_REG &&
|
|
|
|
CGI != COPY_TO_REGCLASS &&
|
|
|
|
CGI != DBG_VALUE)
|
|
|
|
InstrsByEnum.push_back(CGI);
|
|
|
|
}
|
2010-03-19 01:07:44 +00:00
|
|
|
|
|
|
|
// All of the instructions are now in random order based on the map iteration.
|
|
|
|
// Sort them by name.
|
|
|
|
std::sort(InstrsByEnum.begin()+EndOfPredefines, InstrsByEnum.end(),
|
|
|
|
SortInstByName());
|
2005-01-22 18:58:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-10-14 05:50:43 +00:00
|
|
|
/// isLittleEndianEncoding - Return whether this target encodes its instruction
|
|
|
|
/// in little-endian format, i.e. bits laid out in the order [0..n]
|
|
|
|
///
|
|
|
|
bool CodeGenTarget::isLittleEndianEncoding() const {
|
|
|
|
return getInstructionSet()->getValueAsBit("isLittleEndianEncoding");
|
|
|
|
}
|
|
|
|
|
2005-12-08 02:00:36 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// ComplexPattern implementation
|
|
|
|
//
|
|
|
|
ComplexPattern::ComplexPattern(Record *R) {
|
2005-12-08 02:14:08 +00:00
|
|
|
Ty = ::getValueType(R->getValueAsDef("Ty"));
|
|
|
|
NumOperands = R->getValueAsInt("NumOperands");
|
|
|
|
SelectFunc = R->getValueAsString("SelectFunc");
|
|
|
|
RootNodes = R->getValueAsListOfDefs("RootNodes");
|
2006-10-11 21:02:01 +00:00
|
|
|
|
|
|
|
// Parse the properties.
|
|
|
|
Properties = 0;
|
|
|
|
std::vector<Record*> PropList = R->getValueAsListOfDefs("Properties");
|
|
|
|
for (unsigned i = 0, e = PropList.size(); i != e; ++i)
|
|
|
|
if (PropList[i]->getName() == "SDNPHasChain") {
|
|
|
|
Properties |= 1 << SDNPHasChain;
|
|
|
|
} else if (PropList[i]->getName() == "SDNPOptInFlag") {
|
|
|
|
Properties |= 1 << SDNPOptInFlag;
|
2008-01-10 07:59:24 +00:00
|
|
|
} else if (PropList[i]->getName() == "SDNPMayStore") {
|
|
|
|
Properties |= 1 << SDNPMayStore;
|
|
|
|
} else if (PropList[i]->getName() == "SDNPMayLoad") {
|
|
|
|
Properties |= 1 << SDNPMayLoad;
|
|
|
|
} else if (PropList[i]->getName() == "SDNPSideEffect") {
|
|
|
|
Properties |= 1 << SDNPSideEffect;
|
2008-06-25 08:15:39 +00:00
|
|
|
} else if (PropList[i]->getName() == "SDNPMemOperand") {
|
|
|
|
Properties |= 1 << SDNPMemOperand;
|
2010-03-19 05:07:09 +00:00
|
|
|
} else if (PropList[i]->getName() == "SDNPVariadic") {
|
|
|
|
Properties |= 1 << SDNPVariadic;
|
2006-10-11 21:02:01 +00:00
|
|
|
} else {
|
2009-07-03 00:10:29 +00:00
|
|
|
errs() << "Unsupported SD Node property '" << PropList[i]->getName()
|
|
|
|
<< "' on ComplexPattern '" << R->getName() << "'!\n";
|
2006-10-11 21:02:01 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
2005-12-08 02:00:36 +00:00
|
|
|
}
|
2005-12-08 02:14:08 +00:00
|
|
|
|
2006-03-24 19:49:31 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// CodeGenIntrinsic Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2009-02-05 01:49:45 +00:00
|
|
|
std::vector<CodeGenIntrinsic> llvm::LoadIntrinsics(const RecordKeeper &RC,
|
|
|
|
bool TargetOnly) {
|
2006-03-24 19:49:31 +00:00
|
|
|
std::vector<Record*> I = RC.getAllDerivedDefinitions("Intrinsic");
|
2006-03-27 22:48:18 +00:00
|
|
|
|
|
|
|
std::vector<CodeGenIntrinsic> Result;
|
2006-03-28 00:15:00 +00:00
|
|
|
|
2009-02-05 01:49:45 +00:00
|
|
|
for (unsigned i = 0, e = I.size(); i != e; ++i) {
|
|
|
|
bool isTarget = I[i]->getValueAsBit("isTarget");
|
|
|
|
if (isTarget == TargetOnly)
|
|
|
|
Result.push_back(CodeGenIntrinsic(I[i]));
|
|
|
|
}
|
2006-03-27 22:48:18 +00:00
|
|
|
return Result;
|
2006-03-24 19:49:31 +00:00
|
|
|
}
|
|
|
|
|
2008-04-03 00:02:49 +00:00
|
|
|
CodeGenIntrinsic::CodeGenIntrinsic(Record *R) {
|
2006-03-24 20:25:01 +00:00
|
|
|
TheDef = R;
|
2006-03-24 19:49:31 +00:00
|
|
|
std::string DefName = R->getName();
|
|
|
|
ModRef = WriteMem;
|
2007-04-01 07:20:02 +00:00
|
|
|
isOverloaded = false;
|
2008-06-16 20:29:38 +00:00
|
|
|
isCommutative = false;
|
2006-03-24 19:49:31 +00:00
|
|
|
|
|
|
|
if (DefName.size() <= 4 ||
|
2008-11-13 09:08:33 +00:00
|
|
|
std::string(DefName.begin(), DefName.begin() + 4) != "int_")
|
2006-03-24 19:49:31 +00:00
|
|
|
throw "Intrinsic '" + DefName + "' does not start with 'int_'!";
|
2008-11-13 09:08:33 +00:00
|
|
|
|
2006-03-24 19:49:31 +00:00
|
|
|
EnumName = std::string(DefName.begin()+4, DefName.end());
|
2008-11-13 09:08:33 +00:00
|
|
|
|
2006-03-24 19:49:31 +00:00
|
|
|
if (R->getValue("GCCBuiltinName")) // Ignore a missing GCCBuiltinName field.
|
|
|
|
GCCBuiltinName = R->getValueAsString("GCCBuiltinName");
|
2008-11-13 09:08:33 +00:00
|
|
|
|
|
|
|
TargetPrefix = R->getValueAsString("TargetPrefix");
|
2006-03-24 19:49:31 +00:00
|
|
|
Name = R->getValueAsString("LLVMName");
|
2008-11-13 09:08:33 +00:00
|
|
|
|
2006-03-24 19:49:31 +00:00
|
|
|
if (Name == "") {
|
|
|
|
// If an explicit name isn't specified, derive one from the DefName.
|
|
|
|
Name = "llvm.";
|
2008-11-13 09:08:33 +00:00
|
|
|
|
2006-03-24 19:49:31 +00:00
|
|
|
for (unsigned i = 0, e = EnumName.size(); i != e; ++i)
|
2008-11-13 09:08:33 +00:00
|
|
|
Name += (EnumName[i] == '_') ? '.' : EnumName[i];
|
2006-03-24 19:49:31 +00:00
|
|
|
} else {
|
|
|
|
// Verify it starts with "llvm.".
|
|
|
|
if (Name.size() <= 5 ||
|
2008-11-13 09:08:33 +00:00
|
|
|
std::string(Name.begin(), Name.begin() + 5) != "llvm.")
|
2006-03-24 19:49:31 +00:00
|
|
|
throw "Intrinsic '" + DefName + "'s name does not start with 'llvm.'!";
|
|
|
|
}
|
|
|
|
|
|
|
|
// If TargetPrefix is specified, make sure that Name starts with
|
|
|
|
// "llvm.<targetprefix>.".
|
|
|
|
if (!TargetPrefix.empty()) {
|
|
|
|
if (Name.size() < 6+TargetPrefix.size() ||
|
2008-11-13 09:08:33 +00:00
|
|
|
std::string(Name.begin() + 5, Name.begin() + 6 + TargetPrefix.size())
|
|
|
|
!= (TargetPrefix + "."))
|
|
|
|
throw "Intrinsic '" + DefName + "' does not start with 'llvm." +
|
2006-03-24 19:49:31 +00:00
|
|
|
TargetPrefix + ".'!";
|
|
|
|
}
|
|
|
|
|
2008-11-13 09:08:33 +00:00
|
|
|
// Parse the list of return types.
|
2009-08-11 20:47:22 +00:00
|
|
|
std::vector<MVT::SimpleValueType> OverloadedVTs;
|
2008-11-13 09:08:33 +00:00
|
|
|
ListInit *TypeList = R->getValueAsListInit("RetTypes");
|
2006-03-24 19:49:31 +00:00
|
|
|
for (unsigned i = 0, e = TypeList->getSize(); i != e; ++i) {
|
2007-02-27 22:08:27 +00:00
|
|
|
Record *TyEl = TypeList->getElementAsRecord(i);
|
2006-03-24 19:49:31 +00:00
|
|
|
assert(TyEl->isSubClassOf("LLVMType") && "Expected a type!");
|
2009-08-11 20:47:22 +00:00
|
|
|
MVT::SimpleValueType VT;
|
2009-01-07 00:09:01 +00:00
|
|
|
if (TyEl->isSubClassOf("LLVMMatchType")) {
|
2009-04-16 21:51:05 +00:00
|
|
|
unsigned MatchTy = TyEl->getValueAsInt("Number");
|
|
|
|
assert(MatchTy < OverloadedVTs.size() &&
|
|
|
|
"Invalid matching number!");
|
|
|
|
VT = OverloadedVTs[MatchTy];
|
2009-01-07 00:09:01 +00:00
|
|
|
// It only makes sense to use the extended and truncated vector element
|
|
|
|
// variants with iAny types; otherwise, if the intrinsic is not
|
|
|
|
// overloaded, all the types can be specified directly.
|
|
|
|
assert(((!TyEl->isSubClassOf("LLVMExtendedElementVectorType") &&
|
|
|
|
!TyEl->isSubClassOf("LLVMTruncatedElementVectorType")) ||
|
2009-08-11 20:47:22 +00:00
|
|
|
VT == MVT::iAny || VT == MVT::vAny) &&
|
2009-08-11 05:03:38 +00:00
|
|
|
"Expected iAny or vAny type");
|
2009-04-16 21:51:05 +00:00
|
|
|
} else {
|
2009-01-07 00:09:01 +00:00
|
|
|
VT = getValueType(TyEl->getValueAsDef("VT"));
|
2009-04-16 21:51:05 +00:00
|
|
|
}
|
2009-08-11 01:14:02 +00:00
|
|
|
if (EVT(VT).isOverloaded()) {
|
2009-04-16 21:51:05 +00:00
|
|
|
OverloadedVTs.push_back(VT);
|
2010-03-23 23:46:27 +00:00
|
|
|
isOverloaded = true;
|
2009-04-16 21:51:05 +00:00
|
|
|
}
|
2010-03-23 23:46:27 +00:00
|
|
|
|
|
|
|
// Reject invalid types.
|
|
|
|
if (VT == MVT::isVoid)
|
|
|
|
throw "Intrinsic '" + DefName + " has void in result type list!";
|
2010-03-22 20:56:36 +00:00
|
|
|
|
2008-11-13 09:08:33 +00:00
|
|
|
IS.RetVTs.push_back(VT);
|
|
|
|
IS.RetTypeDefs.push_back(TyEl);
|
2006-03-24 19:49:31 +00:00
|
|
|
}
|
2010-03-22 20:56:36 +00:00
|
|
|
|
2008-11-13 09:08:33 +00:00
|
|
|
// Parse the list of parameter types.
|
|
|
|
TypeList = R->getValueAsListInit("ParamTypes");
|
|
|
|
for (unsigned i = 0, e = TypeList->getSize(); i != e; ++i) {
|
|
|
|
Record *TyEl = TypeList->getElementAsRecord(i);
|
|
|
|
assert(TyEl->isSubClassOf("LLVMType") && "Expected a type!");
|
2009-08-11 20:47:22 +00:00
|
|
|
MVT::SimpleValueType VT;
|
2009-01-07 00:09:01 +00:00
|
|
|
if (TyEl->isSubClassOf("LLVMMatchType")) {
|
|
|
|
unsigned MatchTy = TyEl->getValueAsInt("Number");
|
2009-04-16 21:51:05 +00:00
|
|
|
assert(MatchTy < OverloadedVTs.size() &&
|
|
|
|
"Invalid matching number!");
|
|
|
|
VT = OverloadedVTs[MatchTy];
|
2009-01-07 00:09:01 +00:00
|
|
|
// It only makes sense to use the extended and truncated vector element
|
|
|
|
// variants with iAny types; otherwise, if the intrinsic is not
|
|
|
|
// overloaded, all the types can be specified directly.
|
|
|
|
assert(((!TyEl->isSubClassOf("LLVMExtendedElementVectorType") &&
|
|
|
|
!TyEl->isSubClassOf("LLVMTruncatedElementVectorType")) ||
|
2009-08-11 20:47:22 +00:00
|
|
|
VT == MVT::iAny || VT == MVT::vAny) &&
|
2009-08-11 05:03:38 +00:00
|
|
|
"Expected iAny or vAny type");
|
2009-01-07 00:09:01 +00:00
|
|
|
} else
|
|
|
|
VT = getValueType(TyEl->getValueAsDef("VT"));
|
2010-03-23 23:46:27 +00:00
|
|
|
|
2009-08-11 01:14:02 +00:00
|
|
|
if (EVT(VT).isOverloaded()) {
|
2009-04-16 21:51:05 +00:00
|
|
|
OverloadedVTs.push_back(VT);
|
2010-03-23 23:46:27 +00:00
|
|
|
isOverloaded = true;
|
2009-04-16 21:51:05 +00:00
|
|
|
}
|
2010-03-23 23:46:27 +00:00
|
|
|
|
|
|
|
// Reject invalid types.
|
|
|
|
if (VT == MVT::isVoid && i != e-1 /*void at end means varargs*/)
|
|
|
|
throw "Intrinsic '" + DefName + " has void in result type list!";
|
|
|
|
|
2008-11-13 09:08:33 +00:00
|
|
|
IS.ParamVTs.push_back(VT);
|
|
|
|
IS.ParamTypeDefs.push_back(TyEl);
|
|
|
|
}
|
|
|
|
|
2006-03-24 19:49:31 +00:00
|
|
|
// Parse the intrinsic properties.
|
|
|
|
ListInit *PropList = R->getValueAsListInit("Properties");
|
|
|
|
for (unsigned i = 0, e = PropList->getSize(); i != e; ++i) {
|
2007-02-27 22:08:27 +00:00
|
|
|
Record *Property = PropList->getElementAsRecord(i);
|
2006-03-24 19:49:31 +00:00
|
|
|
assert(Property->isSubClassOf("IntrinsicProperty") &&
|
|
|
|
"Expected a property!");
|
|
|
|
|
2006-04-10 22:02:59 +00:00
|
|
|
if (Property->getName() == "IntrNoMem")
|
2006-03-24 19:49:31 +00:00
|
|
|
ModRef = NoMem;
|
2006-04-10 22:02:59 +00:00
|
|
|
else if (Property->getName() == "IntrReadArgMem")
|
2006-03-24 19:49:31 +00:00
|
|
|
ModRef = ReadArgMem;
|
|
|
|
else if (Property->getName() == "IntrReadMem")
|
|
|
|
ModRef = ReadMem;
|
2006-04-10 22:02:59 +00:00
|
|
|
else if (Property->getName() == "IntrWriteArgMem")
|
2006-03-24 19:49:31 +00:00
|
|
|
ModRef = WriteArgMem;
|
|
|
|
else if (Property->getName() == "IntrWriteMem")
|
|
|
|
ModRef = WriteMem;
|
2008-06-16 20:29:38 +00:00
|
|
|
else if (Property->getName() == "Commutative")
|
|
|
|
isCommutative = true;
|
2009-01-12 01:12:03 +00:00
|
|
|
else if (Property->isSubClassOf("NoCapture")) {
|
|
|
|
unsigned ArgNo = Property->getValueAsInt("ArgNo");
|
|
|
|
ArgumentAttributes.push_back(std::make_pair(ArgNo, NoCapture));
|
|
|
|
} else
|
2006-03-24 19:49:31 +00:00
|
|
|
assert(0 && "Unknown property!");
|
|
|
|
}
|
|
|
|
}
|