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
|
2012-10-26 04:33:17 +08:00
|
|
|
// place that needs to check it for validity. All of these classes abort
|
|
|
|
// on error conditions.
|
2003-10-06 03:27:59 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-08-14 00:26:38 +08:00
|
|
|
#ifndef LLVM_UTILS_TABLEGEN_CODEGENTARGET_H
|
|
|
|
#define LLVM_UTILS_TABLEGEN_CODEGENTARGET_H
|
2003-10-06 03:27:59 +08:00
|
|
|
|
2004-08-01 13:04:00 +08:00
|
|
|
#include "CodeGenInstruction.h"
|
2012-12-04 18:37:14 +08:00
|
|
|
#include "CodeGenRegisters.h"
|
2010-03-19 09:07:44 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2012-12-04 18:37:14 +08:00
|
|
|
#include "llvm/TableGen/Record.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;
|
2012-07-07 12:00:00 +08:00
|
|
|
class CodeGenSchedModels;
|
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 {
|
2011-03-11 09:27:24 +08:00
|
|
|
SDNPCommutative,
|
|
|
|
SDNPAssociative,
|
2008-01-06 14:44:58 +08:00
|
|
|
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);
|
2011-03-11 09:27:24 +08:00
|
|
|
|
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;
|
|
|
|
|
2014-12-10 14:18:57 +08:00
|
|
|
mutable DenseMap<const Record*,
|
|
|
|
std::unique_ptr<CodeGenInstruction>> Instructions;
|
2014-11-29 04:30:37 +08:00
|
|
|
mutable std::unique_ptr<CodeGenRegBank> RegBank;
|
2011-06-28 05:06:21 +08:00
|
|
|
mutable std::vector<Record*> RegAltNameIndices;
|
2013-03-18 01:26:09 +08:00
|
|
|
mutable SmallVector<MVT::SimpleValueType, 8> LegalValueTypes;
|
2011-06-28 05:06:21 +08:00
|
|
|
void ReadRegAltNameIndices() const;
|
2004-08-21 12:05:00 +08:00
|
|
|
void ReadInstructions() const;
|
2005-09-09 05:43:21 +08:00
|
|
|
void ReadLegalValueTypes() const;
|
2011-03-11 09:27:24 +08:00
|
|
|
|
2014-11-29 04:30:37 +08:00
|
|
|
mutable std::unique_ptr<CodeGenSchedModels> SchedModels;
|
2012-07-07 12:00:00 +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);
|
2012-07-07 12:00:00 +08:00
|
|
|
~CodeGenTarget();
|
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;
|
|
|
|
|
2012-01-10 03:13:28 +08:00
|
|
|
/// getAsmParserVariant - Return the AssmblyParserVariant definition for
|
|
|
|
/// this target.
|
|
|
|
///
|
|
|
|
Record *getAsmParserVariant(unsigned i) const;
|
|
|
|
|
2012-07-07 12:00:00 +08:00
|
|
|
/// getAsmParserVariantCount - Return the AssmblyParserVariant definition
|
2012-01-10 03:13:28 +08:00
|
|
|
/// available for this target.
|
|
|
|
///
|
|
|
|
unsigned getAsmParserVariantCount() const;
|
|
|
|
|
2004-08-15 06:50:53 +08:00
|
|
|
/// getAsmWriter - Return the AssemblyWriter definition for this target.
|
|
|
|
///
|
|
|
|
Record *getAsmWriter() const;
|
|
|
|
|
2011-06-11 02:40:00 +08:00
|
|
|
/// getRegBank - Return the register bank description.
|
|
|
|
CodeGenRegBank &getRegBank() const;
|
|
|
|
|
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
|
|
|
|
2011-06-28 05:06:21 +08:00
|
|
|
const std::vector<Record*> &getRegAltNameIndices() const {
|
|
|
|
if (RegAltNameIndices.empty()) ReadRegAltNameIndices();
|
|
|
|
return RegAltNameIndices;
|
|
|
|
}
|
|
|
|
|
2005-12-01 08:06:14 +08:00
|
|
|
const CodeGenRegisterClass &getRegisterClass(Record *R) const {
|
2011-06-15 08:20:40 +08:00
|
|
|
return *getRegBank().getRegClass(R);
|
2005-12-05 10:35:08 +08:00
|
|
|
}
|
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;
|
2011-03-11 09:27:24 +08:00
|
|
|
|
2013-03-18 01:26:09 +08:00
|
|
|
ArrayRef<MVT::SimpleValueType> getLegalValueTypes() const {
|
2005-09-09 05:43:21 +08:00
|
|
|
if (LegalValueTypes.empty()) ReadLegalValueTypes();
|
|
|
|
return LegalValueTypes;
|
|
|
|
}
|
2011-03-11 09:27:24 +08:00
|
|
|
|
2005-09-09 05:43:21 +08: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-12 04:47:22 +08:00
|
|
|
bool isLegalValueType(MVT::SimpleValueType VT) const {
|
2013-03-18 01:26:09 +08:00
|
|
|
ArrayRef<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;
|
2011-03-11 09:27:24 +08:00
|
|
|
return false;
|
2005-09-09 05:43:21 +08:00
|
|
|
}
|
2004-08-21 12:05:00 +08:00
|
|
|
|
2012-07-07 12:00:00 +08:00
|
|
|
CodeGenSchedModels &getSchedModels() const;
|
|
|
|
|
2010-03-19 08:18:23 +08:00
|
|
|
private:
|
2014-12-10 14:18:57 +08:00
|
|
|
DenseMap<const Record*, std::unique_ptr<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:
|
2011-03-11 09:27:24 +08:00
|
|
|
|
2010-03-19 09:07:44 +08:00
|
|
|
CodeGenInstruction &getInstruction(const Record *InstRec) const {
|
|
|
|
if (Instructions.empty()) ReadInstructions();
|
2014-12-10 14:18:57 +08:00
|
|
|
auto I = Instructions.find(InstRec);
|
2010-03-19 09:07:44 +08:00
|
|
|
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(); }
|
2014-04-18 10:09:02 +08:00
|
|
|
iterator_range<inst_iterator> instructions() const {
|
2015-12-06 13:08:07 +08:00
|
|
|
return make_range(inst_begin(), inst_end());
|
2014-04-18 10:09:02 +08:00
|
|
|
}
|
2011-03-11 09:27:24 +08:00
|
|
|
|
|
|
|
|
2004-10-14 13:50:43 +08:00
|
|
|
/// isLittleEndianEncoding - are instruction bit patterns defined as [0..n]?
|
|
|
|
///
|
|
|
|
bool isLittleEndianEncoding() const;
|
2011-03-11 09:27:24 +08:00
|
|
|
|
2013-12-18 06:37:50 +08:00
|
|
|
/// reverseBitsForLittleEndianEncoding - For little-endian instruction bit
|
|
|
|
/// encodings, reverse the bit order of all instructions.
|
|
|
|
void reverseBitsForLittleEndianEncoding();
|
|
|
|
|
2012-08-24 03:34:41 +08:00
|
|
|
/// guessInstructionProperties - should we just guess unset instruction
|
|
|
|
/// properties?
|
|
|
|
bool guessInstructionProperties() 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
|