2004-08-01 06:04:35 +02:00
|
|
|
//===- CodeGenTarget.h - Target Class Wrapper -------------------*- 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
|
|
|
//
|
2004-08-01 06:04:35 +02: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 21:27:59 +02:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2004-08-01 06:04:35 +02:00
|
|
|
#ifndef CODEGEN_TARGET_H
|
|
|
|
#define CODEGEN_TARGET_H
|
2003-10-05 21:27:59 +02:00
|
|
|
|
2004-08-16 03:10:21 +02:00
|
|
|
#include "CodeGenRegisters.h"
|
2004-08-01 07:04:00 +02:00
|
|
|
#include "CodeGenInstruction.h"
|
2011-10-01 18:41:13 +02:00
|
|
|
#include "llvm/TableGen/Record.h"
|
2010-03-19 02:07:44 +01:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2009-04-13 17:24:11 +02:00
|
|
|
#include <algorithm>
|
2003-11-11 23:41:34 +01:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
2004-10-27 18:14:51 +02:00
|
|
|
struct CodeGenRegister;
|
2006-03-28 00:48:18 +02:00
|
|
|
class CodeGenTarget;
|
2003-10-05 21:27:59 +02:00
|
|
|
|
2006-10-11 23:02:01 +02:00
|
|
|
// SelectionDAG node properties.
|
2008-06-25 10:15:39 +02:00
|
|
|
// SDNPMemOperand: indicates that a node touches memory and therefore must
|
|
|
|
// have an associated memory operand that describes the access.
|
2008-01-06 07:44:58 +01:00
|
|
|
enum SDNP {
|
2011-03-11 02:27:24 +01:00
|
|
|
SDNPCommutative,
|
|
|
|
SDNPAssociative,
|
2008-01-06 07:44:58 +01:00
|
|
|
SDNPHasChain,
|
2010-12-23 19:28:41 +01:00
|
|
|
SDNPOutGlue,
|
|
|
|
SDNPInGlue,
|
|
|
|
SDNPOptInGlue,
|
2008-01-10 05:38:57 +01:00
|
|
|
SDNPMayLoad,
|
2008-01-10 06:39:30 +01:00
|
|
|
SDNPMayStore,
|
2008-06-25 10:15:39 +02:00
|
|
|
SDNPSideEffect,
|
2010-03-19 06:07:09 +01:00
|
|
|
SDNPMemOperand,
|
2010-09-21 22:31:19 +02:00
|
|
|
SDNPVariadic,
|
|
|
|
SDNPWantRoot,
|
|
|
|
SDNPWantParent
|
2008-01-06 07:44:58 +01:00
|
|
|
};
|
2006-10-11 23:02:01 +02:00
|
|
|
|
2009-08-11 22:47:22 +02:00
|
|
|
/// getValueType - Return the MVT::SimpleValueType that the specified TableGen
|
2008-06-06 14:08:01 +02:00
|
|
|
/// record corresponds to.
|
2009-08-11 22:47:22 +02:00
|
|
|
MVT::SimpleValueType getValueType(Record *Rec);
|
2003-10-05 21:27:59 +02:00
|
|
|
|
2009-08-11 22:47:22 +02:00
|
|
|
std::string getName(MVT::SimpleValueType T);
|
|
|
|
std::string getEnumName(MVT::SimpleValueType T);
|
2003-10-05 21:27:59 +02:00
|
|
|
|
2008-01-05 23:25:12 +01:00
|
|
|
/// getQualifiedName - Return the name of the specified record, with a
|
|
|
|
/// namespace qualifier if the record contains one.
|
|
|
|
std::string getQualifiedName(const Record *R);
|
2011-03-11 02:27:24 +01:00
|
|
|
|
2003-10-05 21:27:59 +02:00
|
|
|
/// CodeGenTarget - This class corresponds to the Target class in the .td files.
|
|
|
|
///
|
|
|
|
class CodeGenTarget {
|
2010-12-13 01:23:57 +01:00
|
|
|
RecordKeeper &Records;
|
2003-10-05 21:27:59 +02:00
|
|
|
Record *TargetRec;
|
|
|
|
|
2010-03-19 02:07:44 +01:00
|
|
|
mutable DenseMap<const Record*, CodeGenInstruction*> Instructions;
|
2011-06-10 20:40:00 +02:00
|
|
|
mutable CodeGenRegBank *RegBank;
|
2011-06-27 23:06:21 +02:00
|
|
|
mutable std::vector<Record*> RegAltNameIndices;
|
2009-08-11 22:47:22 +02:00
|
|
|
mutable std::vector<MVT::SimpleValueType> LegalValueTypes;
|
2011-06-27 23:06:21 +02:00
|
|
|
void ReadRegAltNameIndices() const;
|
2004-08-21 06:05:00 +02:00
|
|
|
void ReadInstructions() const;
|
2005-09-08 23:43:21 +02:00
|
|
|
void ReadLegalValueTypes() const;
|
2011-03-11 02:27:24 +01:00
|
|
|
|
2010-03-19 02:00:55 +01:00
|
|
|
mutable std::vector<const CodeGenInstruction*> InstrsByEnum;
|
2003-10-05 21:27:59 +02:00
|
|
|
public:
|
2010-12-13 01:23:57 +01:00
|
|
|
CodeGenTarget(RecordKeeper &Records);
|
2003-10-05 21:27:59 +02:00
|
|
|
|
|
|
|
Record *getTargetRecord() const { return TargetRec; }
|
|
|
|
const std::string &getName() const;
|
|
|
|
|
2008-08-20 23:45:57 +02:00
|
|
|
/// getInstNamespace - Return the target-specific instruction namespace.
|
|
|
|
///
|
|
|
|
std::string getInstNamespace() const;
|
|
|
|
|
2004-08-15 00:50:53 +02:00
|
|
|
/// getInstructionSet - Return the InstructionSet object.
|
2004-08-01 07:04:00 +02:00
|
|
|
///
|
2003-10-05 21:27:59 +02:00
|
|
|
Record *getInstructionSet() const;
|
|
|
|
|
2009-07-29 02:02:19 +02:00
|
|
|
/// getAsmParser - Return the AssemblyParser definition for this target.
|
|
|
|
///
|
|
|
|
Record *getAsmParser() const;
|
|
|
|
|
2012-01-09 20:13:28 +01:00
|
|
|
/// getAsmParserVariant - Return the AssmblyParserVariant definition for
|
|
|
|
/// this target.
|
|
|
|
///
|
|
|
|
Record *getAsmParserVariant(unsigned i) const;
|
|
|
|
|
|
|
|
/// getAsmParserVariantCount - Return the AssmblyParserVariant definition
|
|
|
|
/// available for this target.
|
|
|
|
///
|
|
|
|
unsigned getAsmParserVariantCount() const;
|
|
|
|
|
2004-08-15 00:50:53 +02:00
|
|
|
/// getAsmWriter - Return the AssemblyWriter definition for this target.
|
|
|
|
///
|
|
|
|
Record *getAsmWriter() const;
|
|
|
|
|
2011-06-10 20:40:00 +02:00
|
|
|
/// getRegBank - Return the register bank description.
|
|
|
|
CodeGenRegBank &getRegBank() const;
|
|
|
|
|
2010-11-02 19:10:06 +01:00
|
|
|
/// getRegisterByName - If there is a register with the specific AsmName,
|
|
|
|
/// return it.
|
|
|
|
const CodeGenRegister *getRegisterByName(StringRef Name) const;
|
2004-08-01 07:04:00 +02:00
|
|
|
|
2011-06-27 23:06:21 +02:00
|
|
|
const std::vector<Record*> &getRegAltNameIndices() const {
|
|
|
|
if (RegAltNameIndices.empty()) ReadRegAltNameIndices();
|
|
|
|
return RegAltNameIndices;
|
|
|
|
}
|
|
|
|
|
2005-12-01 01:06:14 +01:00
|
|
|
const CodeGenRegisterClass &getRegisterClass(Record *R) const {
|
2011-06-15 02:20:40 +02:00
|
|
|
return *getRegBank().getRegClass(R);
|
2005-12-05 03:35:08 +01:00
|
|
|
}
|
2006-05-16 09:05:30 +02:00
|
|
|
|
2008-06-06 14:08:01 +02:00
|
|
|
/// getRegisterVTs - Find the union of all possible SimpleValueTypes for the
|
2006-05-16 09:05:30 +02:00
|
|
|
/// specified physical register.
|
2010-03-15 07:00:16 +01:00
|
|
|
std::vector<MVT::SimpleValueType> getRegisterVTs(Record *R) const;
|
2011-03-11 02:27:24 +01:00
|
|
|
|
2009-08-11 22:47:22 +02:00
|
|
|
const std::vector<MVT::SimpleValueType> &getLegalValueTypes() const {
|
2005-09-08 23:43:21 +02:00
|
|
|
if (LegalValueTypes.empty()) ReadLegalValueTypes();
|
|
|
|
return LegalValueTypes;
|
|
|
|
}
|
2011-03-11 02:27:24 +01:00
|
|
|
|
2005-09-08 23:43:21 +02:00
|
|
|
/// 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-11 22:47:22 +02:00
|
|
|
bool isLegalValueType(MVT::SimpleValueType VT) const {
|
|
|
|
const std::vector<MVT::SimpleValueType> &LegalVTs = getLegalValueTypes();
|
2005-09-08 23:43:21 +02:00
|
|
|
for (unsigned i = 0, e = LegalVTs.size(); i != e; ++i)
|
|
|
|
if (LegalVTs[i] == VT) return true;
|
2011-03-11 02:27:24 +01:00
|
|
|
return false;
|
2005-09-08 23:43:21 +02:00
|
|
|
}
|
2004-08-21 06:05:00 +02:00
|
|
|
|
2010-03-19 01:18:23 +01:00
|
|
|
private:
|
2010-03-19 02:07:44 +01:00
|
|
|
DenseMap<const Record*, CodeGenInstruction*> &getInstructions() const {
|
2004-08-01 07:04:00 +02:00
|
|
|
if (Instructions.empty()) ReadInstructions();
|
|
|
|
return Instructions;
|
|
|
|
}
|
2010-03-19 01:07:20 +01:00
|
|
|
public:
|
2011-03-11 02:27:24 +01:00
|
|
|
|
2010-03-19 02:07:44 +01: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-14 20:02:53 +02:00
|
|
|
|
2005-01-22 19:58:51 +01:00
|
|
|
/// getInstructionsByEnumValue - Return all of the instructions defined by the
|
|
|
|
/// target, ordered by their enum value.
|
2010-03-19 02:00:55 +01:00
|
|
|
const std::vector<const CodeGenInstruction*> &
|
|
|
|
getInstructionsByEnumValue() const {
|
2010-03-19 01:34:35 +01:00
|
|
|
if (InstrsByEnum.empty()) ComputeInstrsByEnum();
|
|
|
|
return InstrsByEnum;
|
|
|
|
}
|
2005-01-22 19:58:51 +01:00
|
|
|
|
2010-03-19 02:00:55 +01: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(); }
|
2011-03-11 02:27:24 +01:00
|
|
|
|
|
|
|
|
2004-10-14 07:50:43 +02:00
|
|
|
/// isLittleEndianEncoding - are instruction bit patterns defined as [0..n]?
|
|
|
|
///
|
|
|
|
bool isLittleEndianEncoding() const;
|
2011-03-11 02:27:24 +01:00
|
|
|
|
2010-03-19 01:34:35 +01:00
|
|
|
private:
|
2010-03-19 02:00:55 +01:00
|
|
|
void ComputeInstrsByEnum() const;
|
2003-10-05 21:27:59 +02:00
|
|
|
};
|
|
|
|
|
2005-12-08 03:00:36 +01:00
|
|
|
/// ComplexPattern - ComplexPattern info, corresponding to the ComplexPattern
|
|
|
|
/// tablegen class in TargetSelectionDAG.td
|
|
|
|
class ComplexPattern {
|
2009-08-11 22:47:22 +02:00
|
|
|
MVT::SimpleValueType Ty;
|
2005-12-08 03:00:36 +01:00
|
|
|
unsigned NumOperands;
|
|
|
|
std::string SelectFunc;
|
2005-12-08 03:14:08 +01:00
|
|
|
std::vector<Record*> RootNodes;
|
2008-01-31 08:27:46 +01:00
|
|
|
unsigned Properties; // Node properties
|
2005-12-08 03:00:36 +01:00
|
|
|
public:
|
2009-11-06 07:33:01 +01:00
|
|
|
ComplexPattern() : NumOperands(0) {}
|
2005-12-08 03:00:36 +01:00
|
|
|
ComplexPattern(Record *R);
|
|
|
|
|
2009-08-11 22:47:22 +02:00
|
|
|
MVT::SimpleValueType getValueType() const { return Ty; }
|
2005-12-08 03:00:36 +01:00
|
|
|
unsigned getNumOperands() const { return NumOperands; }
|
|
|
|
const std::string &getSelectFunc() const { return SelectFunc; }
|
2005-12-08 03:14:08 +01:00
|
|
|
const std::vector<Record*> &getRootNodes() const {
|
|
|
|
return RootNodes;
|
2005-12-08 03:00:36 +01:00
|
|
|
}
|
2006-10-11 23:02:01 +02:00
|
|
|
bool hasProperty(enum SDNP Prop) const { return Properties & (1 << Prop); }
|
2005-12-08 03:00:36 +01:00
|
|
|
};
|
|
|
|
|
2003-11-11 23:41:34 +01:00
|
|
|
} // End llvm namespace
|
|
|
|
|
2003-10-05 21:27:59 +02:00
|
|
|
#endif
|