2004-08-01 04:04:35 +00:00
|
|
|
//===- CodeGenTarget.h - Target Class Wrapper -------------------*- C++ -*-===//
|
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-10-05 19:27:59 +00:00
|
|
|
//
|
2004-08-01 04:04:35 +00:00
|
|
|
// This file defines wrappers for the Target class and related global
|
|
|
|
// functionality. 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.
|
2003-10-05 19:27:59 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2004-08-01 04:04:35 +00:00
|
|
|
#ifndef CODEGEN_TARGET_H
|
|
|
|
#define CODEGEN_TARGET_H
|
2003-10-05 19:27:59 +00:00
|
|
|
|
2004-08-16 01:10:21 +00:00
|
|
|
#include "CodeGenRegisters.h"
|
2004-08-01 05:04:00 +00:00
|
|
|
#include "CodeGenInstruction.h"
|
2003-10-05 19:27:59 +00:00
|
|
|
#include <iosfwd>
|
2004-08-01 05:04:00 +00:00
|
|
|
#include <map>
|
2003-11-11 22:41:34 +00:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
2003-10-05 19:27:59 +00:00
|
|
|
class Record;
|
|
|
|
class RecordKeeper;
|
2004-10-27 16:14:51 +00:00
|
|
|
struct CodeGenRegister;
|
2006-03-27 22:48:18 +00:00
|
|
|
class CodeGenTarget;
|
2003-10-05 19:27:59 +00:00
|
|
|
|
2006-10-11 21:02:01 +00:00
|
|
|
// SelectionDAG node properties.
|
2008-06-25 08:15:39 +00:00
|
|
|
// SDNPMemOperand: indicates that a node touches memory and therefore must
|
|
|
|
// have an associated memory operand that describes the access.
|
2008-01-06 06:44:58 +00:00
|
|
|
enum SDNP {
|
|
|
|
SDNPCommutative,
|
|
|
|
SDNPAssociative,
|
|
|
|
SDNPHasChain,
|
|
|
|
SDNPOutFlag,
|
|
|
|
SDNPInFlag,
|
|
|
|
SDNPOptInFlag,
|
2008-01-10 04:38:57 +00:00
|
|
|
SDNPMayLoad,
|
2008-01-10 05:39:30 +00:00
|
|
|
SDNPMayStore,
|
2008-06-25 08:15:39 +00:00
|
|
|
SDNPSideEffect,
|
|
|
|
SDNPMemOperand
|
2008-01-06 06:44:58 +00:00
|
|
|
};
|
2006-10-11 21:02:01 +00:00
|
|
|
|
2008-01-31 07:27:46 +00:00
|
|
|
// ComplexPattern attributes.
|
|
|
|
enum CPAttr { CPAttrParentAsRoot };
|
|
|
|
|
2008-06-06 12:08:01 +00:00
|
|
|
/// getValueType - Return the MVT::SimpleValueType that the specified TableGen
|
|
|
|
/// record corresponds to.
|
|
|
|
MVT::SimpleValueType getValueType(Record *Rec);
|
2003-10-05 19:27:59 +00:00
|
|
|
|
2008-06-06 12:08:01 +00:00
|
|
|
std::string getName(MVT::SimpleValueType T);
|
|
|
|
std::string getEnumName(MVT::SimpleValueType T);
|
2003-10-05 19:27:59 +00:00
|
|
|
|
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 getQualifiedName(const Record *R);
|
|
|
|
|
2003-10-05 19:27:59 +00:00
|
|
|
/// CodeGenTarget - This class corresponds to the Target class in the .td files.
|
|
|
|
///
|
|
|
|
class CodeGenTarget {
|
|
|
|
Record *TargetRec;
|
|
|
|
|
2004-08-01 05:04:00 +00:00
|
|
|
mutable std::map<std::string, CodeGenInstruction> Instructions;
|
2004-08-16 01:10:21 +00:00
|
|
|
mutable std::vector<CodeGenRegister> Registers;
|
2004-08-21 04:05:00 +00:00
|
|
|
mutable std::vector<CodeGenRegisterClass> RegisterClasses;
|
2008-06-06 12:08:01 +00:00
|
|
|
mutable std::vector<MVT::SimpleValueType> LegalValueTypes;
|
2004-08-16 01:10:21 +00:00
|
|
|
void ReadRegisters() const;
|
2004-08-21 04:05:00 +00:00
|
|
|
void ReadRegisterClasses() const;
|
|
|
|
void ReadInstructions() const;
|
2005-09-08 21:43:21 +00:00
|
|
|
void ReadLegalValueTypes() const;
|
2003-10-05 19:27:59 +00:00
|
|
|
public:
|
|
|
|
CodeGenTarget();
|
|
|
|
|
|
|
|
Record *getTargetRecord() const { return TargetRec; }
|
|
|
|
const std::string &getName() const;
|
|
|
|
|
2008-08-20 21:45:57 +00:00
|
|
|
/// getInstNamespace - Return the target-specific instruction namespace.
|
|
|
|
///
|
|
|
|
std::string getInstNamespace() const;
|
|
|
|
|
2004-08-14 22:50:53 +00:00
|
|
|
/// getInstructionSet - Return the InstructionSet object.
|
2004-08-01 05:04:00 +00:00
|
|
|
///
|
2003-10-05 19:27:59 +00:00
|
|
|
Record *getInstructionSet() const;
|
|
|
|
|
2004-08-14 22:50:53 +00:00
|
|
|
/// getAsmWriter - Return the AssemblyWriter definition for this target.
|
|
|
|
///
|
|
|
|
Record *getAsmWriter() const;
|
|
|
|
|
2005-09-08 21:43:21 +00:00
|
|
|
const std::vector<CodeGenRegister> &getRegisters() const {
|
2004-08-16 01:10:21 +00:00
|
|
|
if (Registers.empty()) ReadRegisters();
|
|
|
|
return Registers;
|
|
|
|
}
|
2004-08-01 05:04:00 +00:00
|
|
|
|
2005-09-08 21:43:21 +00:00
|
|
|
const std::vector<CodeGenRegisterClass> &getRegisterClasses() const {
|
2004-08-21 04:05:00 +00:00
|
|
|
if (RegisterClasses.empty()) ReadRegisterClasses();
|
|
|
|
return RegisterClasses;
|
|
|
|
}
|
2005-12-01 00:06:14 +00:00
|
|
|
|
|
|
|
const CodeGenRegisterClass &getRegisterClass(Record *R) const {
|
|
|
|
const std::vector<CodeGenRegisterClass> &RC = getRegisterClasses();
|
|
|
|
for (unsigned i = 0, e = RC.size(); i != e; ++i)
|
|
|
|
if (RC[i].TheDef == R)
|
|
|
|
return RC[i];
|
|
|
|
assert(0 && "Didn't find the register class");
|
|
|
|
abort();
|
|
|
|
}
|
2005-12-05 02:35:08 +00:00
|
|
|
|
|
|
|
/// getRegisterClassForRegister - Find the register class that contains the
|
|
|
|
/// specified physical register. If there register exists in multiple
|
|
|
|
/// register classes or is not in a register class, return null.
|
|
|
|
const CodeGenRegisterClass *getRegisterClassForRegister(Record *R) const {
|
|
|
|
const std::vector<CodeGenRegisterClass> &RCs = getRegisterClasses();
|
|
|
|
const CodeGenRegisterClass *FoundRC = 0;
|
|
|
|
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]) {
|
|
|
|
if (FoundRC) return 0; // In multiple RC's
|
|
|
|
FoundRC = &RC;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FoundRC;
|
|
|
|
}
|
2006-05-16 07:05:30 +00:00
|
|
|
|
2008-06-06 12:08:01 +00:00
|
|
|
/// getRegisterVTs - Find the union of all possible SimpleValueTypes for the
|
2006-05-16 07:05:30 +00:00
|
|
|
/// specified physical register.
|
|
|
|
std::vector<unsigned char> getRegisterVTs(Record *R) const;
|
2005-12-05 02:35:08 +00:00
|
|
|
|
2008-06-06 12:08:01 +00:00
|
|
|
const std::vector<MVT::SimpleValueType> &getLegalValueTypes() const {
|
2005-09-08 21:43:21 +00:00
|
|
|
if (LegalValueTypes.empty()) ReadLegalValueTypes();
|
|
|
|
return LegalValueTypes;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// isLegalValueType - Return true if the specified value type is natively
|
|
|
|
/// supported by the target (i.e. there are registers that directly hold it).
|
2008-06-06 12:08:01 +00:00
|
|
|
bool isLegalValueType(MVT::SimpleValueType VT) const {
|
|
|
|
const std::vector<MVT::SimpleValueType> &LegalVTs = getLegalValueTypes();
|
2005-09-08 21:43:21 +00:00
|
|
|
for (unsigned i = 0, e = LegalVTs.size(); i != e; ++i)
|
|
|
|
if (LegalVTs[i] == VT) return true;
|
|
|
|
return false;
|
|
|
|
}
|
2004-08-21 04:05:00 +00:00
|
|
|
|
2004-08-01 05:04:00 +00:00
|
|
|
/// getInstructions - Return all of the instructions defined for this target.
|
|
|
|
///
|
|
|
|
const std::map<std::string, CodeGenInstruction> &getInstructions() const {
|
|
|
|
if (Instructions.empty()) ReadInstructions();
|
|
|
|
return Instructions;
|
|
|
|
}
|
2008-04-03 00:02:49 +00:00
|
|
|
std::map<std::string, CodeGenInstruction> &getInstructions() {
|
|
|
|
if (Instructions.empty()) ReadInstructions();
|
|
|
|
return Instructions;
|
|
|
|
}
|
2004-08-01 05:04:00 +00:00
|
|
|
|
2005-09-14 18:02:53 +00:00
|
|
|
CodeGenInstruction &getInstruction(const std::string &Name) const {
|
|
|
|
const std::map<std::string, CodeGenInstruction> &Insts = getInstructions();
|
|
|
|
assert(Insts.count(Name) && "Not an instruction!");
|
|
|
|
return const_cast<CodeGenInstruction&>(Insts.find(Name)->second);
|
|
|
|
}
|
|
|
|
|
2004-08-01 05:04:00 +00:00
|
|
|
typedef std::map<std::string,
|
|
|
|
CodeGenInstruction>::const_iterator inst_iterator;
|
|
|
|
inst_iterator inst_begin() const { return getInstructions().begin(); }
|
|
|
|
inst_iterator inst_end() const { return Instructions.end(); }
|
2004-08-16 01:10:21 +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.
|
|
|
|
void getInstructionsByEnumValue(std::vector<const CodeGenInstruction*>
|
|
|
|
&NumberedInstructions);
|
|
|
|
|
|
|
|
|
2004-10-14 05:50:43 +00:00
|
|
|
/// isLittleEndianEncoding - are instruction bit patterns defined as [0..n]?
|
|
|
|
///
|
|
|
|
bool isLittleEndianEncoding() const;
|
2003-10-05 19:27:59 +00:00
|
|
|
};
|
|
|
|
|
2005-12-08 02:00:36 +00:00
|
|
|
/// ComplexPattern - ComplexPattern info, corresponding to the ComplexPattern
|
|
|
|
/// tablegen class in TargetSelectionDAG.td
|
|
|
|
class ComplexPattern {
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT::SimpleValueType Ty;
|
2005-12-08 02:00:36 +00:00
|
|
|
unsigned NumOperands;
|
|
|
|
std::string SelectFunc;
|
2005-12-08 02:14:08 +00:00
|
|
|
std::vector<Record*> RootNodes;
|
2008-01-31 07:27:46 +00:00
|
|
|
unsigned Properties; // Node properties
|
|
|
|
unsigned Attributes; // Pattern attributes
|
2005-12-08 02:00:36 +00:00
|
|
|
public:
|
|
|
|
ComplexPattern() : NumOperands(0) {};
|
|
|
|
ComplexPattern(Record *R);
|
|
|
|
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT::SimpleValueType getValueType() const { return Ty; }
|
2005-12-08 02:00:36 +00:00
|
|
|
unsigned getNumOperands() const { return NumOperands; }
|
|
|
|
const std::string &getSelectFunc() const { return SelectFunc; }
|
2005-12-08 02:14:08 +00:00
|
|
|
const std::vector<Record*> &getRootNodes() const {
|
|
|
|
return RootNodes;
|
2005-12-08 02:00:36 +00:00
|
|
|
}
|
2006-10-11 21:02:01 +00:00
|
|
|
bool hasProperty(enum SDNP Prop) const { return Properties & (1 << Prop); }
|
2008-01-31 07:27:46 +00:00
|
|
|
bool hasAttribute(enum CPAttr Attr) const { return Attributes & (1 << Attr); }
|
2005-12-08 02:00:36 +00:00
|
|
|
};
|
|
|
|
|
2003-11-11 22:41:34 +00:00
|
|
|
} // End llvm namespace
|
|
|
|
|
2003-10-05 19:27:59 +00:00
|
|
|
#endif
|