2004-08-01 12:04:35 +08:00
|
|
|
//===- CodeGenTarget.h - Target Class Wrapper -------------------*- C++ -*-===//
|
2005-04-22 08:00:37 +08:00
|
|
|
//
|
2003-10-21 04:20:30 +08:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-30 04:37:13 +08:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-22 08:00:37 +08:00
|
|
|
//
|
2003-10-21 04:20:30 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2003-10-06 03:27:59 +08:00
|
|
|
//
|
2004-08-01 12:04:35 +08: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-06 03:27:59 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2004-08-01 12:04:35 +08:00
|
|
|
#ifndef CODEGEN_TARGET_H
|
|
|
|
#define CODEGEN_TARGET_H
|
2003-10-06 03:27:59 +08:00
|
|
|
|
2004-08-16 09:10:21 +08:00
|
|
|
#include "CodeGenRegisters.h"
|
2004-08-01 13:04:00 +08:00
|
|
|
#include "CodeGenInstruction.h"
|
2010-05-25 05:46:58 +08:00
|
|
|
#include "Record.h"
|
2010-03-19 09:07:44 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2009-04-13 23:24:11 +08:00
|
|
|
#include <algorithm>
|
2003-11-12 06:41:34 +08:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
2004-10-28 00:14:51 +08:00
|
|
|
struct CodeGenRegister;
|
2006-03-28 06:48:18 +08:00
|
|
|
class CodeGenTarget;
|
2003-10-06 03:27:59 +08:00
|
|
|
|
2006-10-12 05:02:01 +08:00
|
|
|
// SelectionDAG node properties.
|
2008-06-25 16:15:39 +08:00
|
|
|
// SDNPMemOperand: indicates that a node touches memory and therefore must
|
|
|
|
// have an associated memory operand that describes the access.
|
2008-01-06 14:44:58 +08:00
|
|
|
enum SDNP {
|
|
|
|
SDNPCommutative,
|
|
|
|
SDNPAssociative,
|
|
|
|
SDNPHasChain,
|
2010-12-24 02:28:41 +08:00
|
|
|
SDNPOutGlue,
|
|
|
|
SDNPInGlue,
|
|
|
|
SDNPOptInGlue,
|
2008-01-10 12:38:57 +08:00
|
|
|
SDNPMayLoad,
|
2008-01-10 13:39:30 +08:00
|
|
|
SDNPMayStore,
|
2008-06-25 16:15:39 +08:00
|
|
|
SDNPSideEffect,
|
2010-03-19 13:07:09 +08:00
|
|
|
SDNPMemOperand,
|
2010-09-22 04:31:19 +08:00
|
|
|
SDNPVariadic,
|
|
|
|
SDNPWantRoot,
|
|
|
|
SDNPWantParent
|
2008-01-06 14:44:58 +08:00
|
|
|
};
|
2006-10-12 05:02:01 +08:00
|
|
|
|
2009-08-12 04:47:22 +08:00
|
|
|
/// getValueType - Return the MVT::SimpleValueType that the specified TableGen
|
2008-06-06 20:08:01 +08:00
|
|
|
/// record corresponds to.
|
2009-08-12 04:47:22 +08:00
|
|
|
MVT::SimpleValueType getValueType(Record *Rec);
|
2003-10-06 03:27:59 +08:00
|
|
|
|
2009-08-12 04:47:22 +08:00
|
|
|
std::string getName(MVT::SimpleValueType T);
|
|
|
|
std::string getEnumName(MVT::SimpleValueType T);
|
2003-10-06 03:27:59 +08:00
|
|
|
|
2008-01-06 06:25:12 +08: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-06 03:27:59 +08:00
|
|
|
/// CodeGenTarget - This class corresponds to the Target class in the .td files.
|
|
|
|
///
|
|
|
|
class CodeGenTarget {
|
2010-12-13 08:23:57 +08:00
|
|
|
RecordKeeper &Records;
|
2003-10-06 03:27:59 +08:00
|
|
|
Record *TargetRec;
|
|
|
|
|
2010-03-19 09:07:44 +08:00
|
|
|
mutable DenseMap<const Record*, CodeGenInstruction*> Instructions;
|
2004-08-16 09:10:21 +08:00
|
|
|
mutable std::vector<CodeGenRegister> Registers;
|
2010-05-25 05:46:58 +08:00
|
|
|
mutable std::vector<Record*> SubRegIndices;
|
2004-08-21 12:05:00 +08:00
|
|
|
mutable std::vector<CodeGenRegisterClass> RegisterClasses;
|
2009-08-12 04:47:22 +08:00
|
|
|
mutable std::vector<MVT::SimpleValueType> LegalValueTypes;
|
2004-08-16 09:10:21 +08:00
|
|
|
void ReadRegisters() const;
|
2010-05-25 05:46:58 +08:00
|
|
|
void ReadSubRegIndices() const;
|
2004-08-21 12:05:00 +08:00
|
|
|
void ReadRegisterClasses() const;
|
|
|
|
void ReadInstructions() const;
|
2005-09-09 05:43:21 +08:00
|
|
|
void ReadLegalValueTypes() const;
|
2010-03-19 08:34:35 +08:00
|
|
|
|
2010-03-19 09:00:55 +08:00
|
|
|
mutable std::vector<const CodeGenInstruction*> InstrsByEnum;
|
2003-10-06 03:27:59 +08:00
|
|
|
public:
|
2010-12-13 08:23:57 +08:00
|
|
|
CodeGenTarget(RecordKeeper &Records);
|
2003-10-06 03:27:59 +08:00
|
|
|
|
|
|
|
Record *getTargetRecord() const { return TargetRec; }
|
|
|
|
const std::string &getName() const;
|
|
|
|
|
2008-08-21 05:45:57 +08:00
|
|
|
/// getInstNamespace - Return the target-specific instruction namespace.
|
|
|
|
///
|
|
|
|
std::string getInstNamespace() const;
|
|
|
|
|
2004-08-15 06:50:53 +08:00
|
|
|
/// getInstructionSet - Return the InstructionSet object.
|
2004-08-01 13:04:00 +08:00
|
|
|
///
|
2003-10-06 03:27:59 +08:00
|
|
|
Record *getInstructionSet() const;
|
|
|
|
|
2009-07-29 08:02:19 +08:00
|
|
|
/// getAsmParser - Return the AssemblyParser definition for this target.
|
|
|
|
///
|
|
|
|
Record *getAsmParser() const;
|
|
|
|
|
2004-08-15 06:50:53 +08:00
|
|
|
/// getAsmWriter - Return the AssemblyWriter definition for this target.
|
|
|
|
///
|
|
|
|
Record *getAsmWriter() const;
|
|
|
|
|
2005-09-09 05:43:21 +08:00
|
|
|
const std::vector<CodeGenRegister> &getRegisters() const {
|
2004-08-16 09:10:21 +08:00
|
|
|
if (Registers.empty()) ReadRegisters();
|
|
|
|
return Registers;
|
|
|
|
}
|
2010-11-03 02:10:06 +08:00
|
|
|
|
|
|
|
/// getRegisterByName - If there is a register with the specific AsmName,
|
|
|
|
/// return it.
|
|
|
|
const CodeGenRegister *getRegisterByName(StringRef Name) const;
|
2004-08-01 13:04:00 +08:00
|
|
|
|
2010-05-25 05:46:58 +08:00
|
|
|
const std::vector<Record*> &getSubRegIndices() const {
|
|
|
|
if (SubRegIndices.empty()) ReadSubRegIndices();
|
|
|
|
return SubRegIndices;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Map a SubRegIndex Record to its number.
|
|
|
|
unsigned getSubRegIndexNo(Record *idx) const {
|
2010-05-26 01:21:04 +08:00
|
|
|
if (SubRegIndices.empty()) ReadSubRegIndices();
|
|
|
|
std::vector<Record*>::const_iterator i =
|
|
|
|
std::find(SubRegIndices.begin(), SubRegIndices.end(), idx);
|
|
|
|
assert(i != SubRegIndices.end() && "Not a SubRegIndex");
|
|
|
|
return (i - SubRegIndices.begin()) + 1;
|
2010-05-25 05:46:58 +08:00
|
|
|
}
|
|
|
|
|
2005-09-09 05:43:21 +08:00
|
|
|
const std::vector<CodeGenRegisterClass> &getRegisterClasses() const {
|
2004-08-21 12:05:00 +08:00
|
|
|
if (RegisterClasses.empty()) ReadRegisterClasses();
|
|
|
|
return RegisterClasses;
|
|
|
|
}
|
2010-05-25 05:46:58 +08:00
|
|
|
|
2005-12-01 08:06:14 +08: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 10:35:08 +08:00
|
|
|
|
|
|
|
/// getRegisterClassForRegister - Find the register class that contains the
|
2009-04-13 23:24:11 +08:00
|
|
|
/// specified physical register. If the register is not in a register
|
|
|
|
/// class, return null. If the register is in multiple classes, and the
|
|
|
|
/// classes have a superset-subset relationship and the same set of
|
|
|
|
/// types, return the superclass. Otherwise return null.
|
2005-12-05 10:35:08 +08:00
|
|
|
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) {
|
2009-04-13 23:24:11 +08:00
|
|
|
if (R != RC.Elements[ei])
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// If a register's classes have different types, return null.
|
|
|
|
if (FoundRC && RC.getValueTypes() != FoundRC->getValueTypes())
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
// If this is the first class that contains the register,
|
|
|
|
// make a note of it and go on to the next class.
|
|
|
|
if (!FoundRC) {
|
|
|
|
FoundRC = &RC;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<Record *> Elements(RC.Elements);
|
|
|
|
std::vector<Record *> FoundElements(FoundRC->Elements);
|
|
|
|
std::sort(Elements.begin(), Elements.end());
|
|
|
|
std::sort(FoundElements.begin(), FoundElements.end());
|
|
|
|
|
|
|
|
// Check to see if the previously found class that contains
|
|
|
|
// the register is a subclass of the current class. If so,
|
|
|
|
// prefer the superclass.
|
|
|
|
if (std::includes(Elements.begin(), Elements.end(),
|
|
|
|
FoundElements.begin(), FoundElements.end())) {
|
2005-12-05 10:35:08 +08:00
|
|
|
FoundRC = &RC;
|
|
|
|
break;
|
|
|
|
}
|
2009-04-13 23:24:11 +08:00
|
|
|
|
|
|
|
// Check to see if the previously found class that contains
|
|
|
|
// the register is a superclass of the current class. If so,
|
|
|
|
// prefer the superclass.
|
|
|
|
if (std::includes(FoundElements.begin(), FoundElements.end(),
|
|
|
|
Elements.begin(), Elements.end()))
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Multiple classes, and neither is a superclass of the other.
|
|
|
|
// Return null.
|
|
|
|
return 0;
|
2005-12-05 10:35:08 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return FoundRC;
|
|
|
|
}
|
2006-05-16 15:05:30 +08:00
|
|
|
|
2008-06-06 20:08:01 +08:00
|
|
|
/// getRegisterVTs - Find the union of all possible SimpleValueTypes for the
|
2006-05-16 15:05:30 +08:00
|
|
|
/// specified physical register.
|
2010-03-15 14:00:16 +08:00
|
|
|
std::vector<MVT::SimpleValueType> getRegisterVTs(Record *R) const;
|
2005-12-05 10:35:08 +08:00
|
|
|
|
2009-08-12 04:47:22 +08:00
|
|
|
const std::vector<MVT::SimpleValueType> &getLegalValueTypes() const {
|
2005-09-09 05:43:21 +08: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).
|
2009-08-12 04:47:22 +08:00
|
|
|
bool isLegalValueType(MVT::SimpleValueType VT) const {
|
|
|
|
const std::vector<MVT::SimpleValueType> &LegalVTs = getLegalValueTypes();
|
2005-09-09 05:43:21 +08:00
|
|
|
for (unsigned i = 0, e = LegalVTs.size(); i != e; ++i)
|
|
|
|
if (LegalVTs[i] == VT) return true;
|
|
|
|
return false;
|
|
|
|
}
|
2004-08-21 12:05:00 +08:00
|
|
|
|
2010-03-19 08:18:23 +08:00
|
|
|
private:
|
2010-03-19 09:07:44 +08:00
|
|
|
DenseMap<const Record*, CodeGenInstruction*> &getInstructions() const {
|
2004-08-01 13:04:00 +08:00
|
|
|
if (Instructions.empty()) ReadInstructions();
|
|
|
|
return Instructions;
|
|
|
|
}
|
2010-03-19 08:07:20 +08:00
|
|
|
public:
|
|
|
|
|
2010-03-19 09:07:44 +08:00
|
|
|
CodeGenInstruction &getInstruction(const Record *InstRec) const {
|
|
|
|
if (Instructions.empty()) ReadInstructions();
|
|
|
|
DenseMap<const Record*, CodeGenInstruction*>::iterator I =
|
|
|
|
Instructions.find(InstRec);
|
|
|
|
assert(I != Instructions.end() && "Not an instruction");
|
|
|
|
return *I->second;
|
|
|
|
}
|
2005-09-15 02:02:53 +08:00
|
|
|
|
2005-01-23 02:58:51 +08:00
|
|
|
/// getInstructionsByEnumValue - Return all of the instructions defined by the
|
|
|
|
/// target, ordered by their enum value.
|
2010-03-19 09:00:55 +08:00
|
|
|
const std::vector<const CodeGenInstruction*> &
|
|
|
|
getInstructionsByEnumValue() const {
|
2010-03-19 08:34:35 +08:00
|
|
|
if (InstrsByEnum.empty()) ComputeInstrsByEnum();
|
|
|
|
return InstrsByEnum;
|
|
|
|
}
|
2005-01-23 02:58:51 +08:00
|
|
|
|
2010-03-19 09:00:55 +08:00
|
|
|
typedef std::vector<const CodeGenInstruction*>::const_iterator inst_iterator;
|
|
|
|
inst_iterator inst_begin() const{return getInstructionsByEnumValue().begin();}
|
|
|
|
inst_iterator inst_end() const { return getInstructionsByEnumValue().end(); }
|
|
|
|
|
|
|
|
|
2004-10-14 13:50:43 +08:00
|
|
|
/// isLittleEndianEncoding - are instruction bit patterns defined as [0..n]?
|
|
|
|
///
|
|
|
|
bool isLittleEndianEncoding() const;
|
2010-03-19 08:34:35 +08:00
|
|
|
|
|
|
|
private:
|
2010-03-19 09:00:55 +08:00
|
|
|
void ComputeInstrsByEnum() const;
|
2003-10-06 03:27:59 +08:00
|
|
|
};
|
|
|
|
|
2005-12-08 10:00:36 +08:00
|
|
|
/// ComplexPattern - ComplexPattern info, corresponding to the ComplexPattern
|
|
|
|
/// tablegen class in TargetSelectionDAG.td
|
|
|
|
class ComplexPattern {
|
2009-08-12 04:47:22 +08:00
|
|
|
MVT::SimpleValueType Ty;
|
2005-12-08 10:00:36 +08:00
|
|
|
unsigned NumOperands;
|
|
|
|
std::string SelectFunc;
|
2005-12-08 10:14:08 +08:00
|
|
|
std::vector<Record*> RootNodes;
|
2008-01-31 15:27:46 +08:00
|
|
|
unsigned Properties; // Node properties
|
2005-12-08 10:00:36 +08:00
|
|
|
public:
|
2009-11-06 14:33:01 +08:00
|
|
|
ComplexPattern() : NumOperands(0) {}
|
2005-12-08 10:00:36 +08:00
|
|
|
ComplexPattern(Record *R);
|
|
|
|
|
2009-08-12 04:47:22 +08:00
|
|
|
MVT::SimpleValueType getValueType() const { return Ty; }
|
2005-12-08 10:00:36 +08:00
|
|
|
unsigned getNumOperands() const { return NumOperands; }
|
|
|
|
const std::string &getSelectFunc() const { return SelectFunc; }
|
2005-12-08 10:14:08 +08:00
|
|
|
const std::vector<Record*> &getRootNodes() const {
|
|
|
|
return RootNodes;
|
2005-12-08 10:00:36 +08:00
|
|
|
}
|
2006-10-12 05:02:01 +08:00
|
|
|
bool hasProperty(enum SDNP Prop) const { return Properties & (1 << Prop); }
|
2005-12-08 10:00:36 +08:00
|
|
|
};
|
|
|
|
|
2003-11-12 06:41:34 +08:00
|
|
|
} // End llvm namespace
|
|
|
|
|
2003-10-06 03:27:59 +08:00
|
|
|
#endif
|