freebsd-dev/contrib/llvm/utils/TableGen/CodeGenTarget.h

216 lines
6.7 KiB
C
Raw Normal View History

2009-06-02 17:52:33 +00:00
//===- CodeGenTarget.h - Target Class Wrapper -------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// 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 abort
// on error conditions.
2009-06-02 17:52:33 +00:00
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_UTILS_TABLEGEN_CODEGENTARGET_H
#define LLVM_UTILS_TABLEGEN_CODEGENTARGET_H
2009-06-02 17:52:33 +00:00
#include "CodeGenInstruction.h"
#include "CodeGenRegisters.h"
2010-03-21 10:49:05 +00:00
#include "llvm/Support/raw_ostream.h"
#include "llvm/TableGen/Record.h"
2009-06-02 17:52:33 +00:00
#include <algorithm>
namespace llvm {
struct CodeGenRegister;
class CodeGenSchedModels;
2009-06-02 17:52:33 +00:00
class CodeGenTarget;
// SelectionDAG node properties.
// SDNPMemOperand: indicates that a node touches memory and therefore must
// have an associated memory operand that describes the access.
enum SDNP {
SDNPCommutative,
SDNPAssociative,
2009-06-02 17:52:33 +00:00
SDNPHasChain,
SDNPOutGlue,
SDNPInGlue,
SDNPOptInGlue,
2009-06-02 17:52:33 +00:00
SDNPMayLoad,
SDNPMayStore,
SDNPSideEffect,
2010-03-21 10:49:05 +00:00
SDNPMemOperand,
SDNPVariadic,
SDNPWantRoot,
SDNPWantParent
2009-06-02 17:52:33 +00:00
};
/// getValueType - Return the MVT::SimpleValueType that the specified TableGen
/// record corresponds to.
MVT::SimpleValueType getValueType(Record *Rec);
StringRef getName(MVT::SimpleValueType T);
StringRef getEnumName(MVT::SimpleValueType T);
2009-06-02 17:52:33 +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);
2009-06-02 17:52:33 +00:00
/// CodeGenTarget - This class corresponds to the Target class in the .td files.
///
class CodeGenTarget {
RecordKeeper &Records;
2009-06-02 17:52:33 +00:00
Record *TargetRec;
mutable DenseMap<const Record*,
std::unique_ptr<CodeGenInstruction>> Instructions;
mutable std::unique_ptr<CodeGenRegBank> RegBank;
mutable std::vector<Record*> RegAltNameIndices;
mutable SmallVector<MVT::SimpleValueType, 8> LegalValueTypes;
void ReadRegAltNameIndices() const;
2009-06-02 17:52:33 +00:00
void ReadInstructions() const;
void ReadLegalValueTypes() const;
mutable std::unique_ptr<CodeGenSchedModels> SchedModels;
2010-03-21 10:49:05 +00:00
mutable std::vector<const CodeGenInstruction*> InstrsByEnum;
2009-06-02 17:52:33 +00:00
public:
CodeGenTarget(RecordKeeper &Records);
~CodeGenTarget();
2009-06-02 17:52:33 +00:00
Record *getTargetRecord() const { return TargetRec; }
const StringRef getName() const;
2009-06-02 17:52:33 +00:00
/// getInstNamespace - Return the target-specific instruction namespace.
///
StringRef getInstNamespace() const;
2009-06-02 17:52:33 +00:00
/// getInstructionSet - Return the InstructionSet object.
///
Record *getInstructionSet() const;
2009-10-14 17:57:32 +00:00
/// getAsmParser - Return the AssemblyParser definition for this target.
///
Record *getAsmParser() const;
/// 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;
2009-06-02 17:52:33 +00:00
/// getAsmWriter - Return the AssemblyWriter definition for this target.
///
Record *getAsmWriter() const;
/// getRegBank - Return the register bank description.
CodeGenRegBank &getRegBank() const;
/// getRegisterByName - If there is a register with the specific AsmName,
/// return it.
const CodeGenRegister *getRegisterByName(StringRef Name) const;
2009-06-02 17:52:33 +00:00
const std::vector<Record*> &getRegAltNameIndices() const {
if (RegAltNameIndices.empty()) ReadRegAltNameIndices();
return RegAltNameIndices;
2009-06-02 17:52:33 +00:00
}
2010-05-27 15:15:58 +00:00
const CodeGenRegisterClass &getRegisterClass(Record *R) const {
return *getRegBank().getRegClass(R);
2009-06-02 17:52:33 +00:00
}
/// getRegisterVTs - Find the union of all possible SimpleValueTypes for the
/// specified physical register.
2010-03-16 16:51:38 +00:00
std::vector<MVT::SimpleValueType> getRegisterVTs(Record *R) const;
ArrayRef<MVT::SimpleValueType> getLegalValueTypes() const {
2009-06-02 17:52:33 +00:00
if (LegalValueTypes.empty()) ReadLegalValueTypes();
return LegalValueTypes;
}
2009-06-02 17:52:33 +00:00
/// isLegalValueType - Return true if the specified value type is natively
/// supported by the target (i.e. there are registers that directly hold it).
bool isLegalValueType(MVT::SimpleValueType VT) const {
ArrayRef<MVT::SimpleValueType> LegalVTs = getLegalValueTypes();
return is_contained(LegalVTs, VT);
2009-06-02 17:52:33 +00:00
}
CodeGenSchedModels &getSchedModels() const;
2010-03-21 10:49:05 +00:00
private:
DenseMap<const Record*, std::unique_ptr<CodeGenInstruction>> &
getInstructions() const {
2009-06-02 17:52:33 +00:00
if (Instructions.empty()) ReadInstructions();
return Instructions;
}
2010-03-21 10:49:05 +00:00
public:
2010-03-21 10:49:05 +00:00
CodeGenInstruction &getInstruction(const Record *InstRec) const {
2009-06-02 17:52:33 +00:00
if (Instructions.empty()) ReadInstructions();
auto I = Instructions.find(InstRec);
2010-03-21 10:49:05 +00:00
assert(I != Instructions.end() && "Not an instruction");
return *I->second;
2009-06-02 17:52:33 +00:00
}
/// getInstructionsByEnumValue - Return all of the instructions defined by the
/// target, ordered by their enum value.
ArrayRef<const CodeGenInstruction *>
2010-03-21 10:49:05 +00:00
getInstructionsByEnumValue() const {
if (InstrsByEnum.empty()) ComputeInstrsByEnum();
return InstrsByEnum;
}
2009-06-02 17:52:33 +00:00
typedef ArrayRef<const CodeGenInstruction *>::const_iterator inst_iterator;
2010-03-21 10:49:05 +00:00
inst_iterator inst_begin() const{return getInstructionsByEnumValue().begin();}
inst_iterator inst_end() const { return getInstructionsByEnumValue().end(); }
2009-06-02 17:52:33 +00:00
/// isLittleEndianEncoding - are instruction bit patterns defined as [0..n]?
///
bool isLittleEndianEncoding() const;
/// reverseBitsForLittleEndianEncoding - For little-endian instruction bit
/// encodings, reverse the bit order of all instructions.
void reverseBitsForLittleEndianEncoding();
/// guessInstructionProperties - should we just guess unset instruction
/// properties?
bool guessInstructionProperties() const;
2010-03-21 10:49:05 +00:00
private:
void ComputeInstrsByEnum() const;
2009-06-02 17:52:33 +00:00
};
/// ComplexPattern - ComplexPattern info, corresponding to the ComplexPattern
/// tablegen class in TargetSelectionDAG.td
class ComplexPattern {
MVT::SimpleValueType Ty;
unsigned NumOperands;
std::string SelectFunc;
std::vector<Record*> RootNodes;
unsigned Properties; // Node properties
unsigned Complexity;
2009-06-02 17:52:33 +00:00
public:
ComplexPattern(Record *R);
MVT::SimpleValueType getValueType() const { return Ty; }
unsigned getNumOperands() const { return NumOperands; }
const std::string &getSelectFunc() const { return SelectFunc; }
const std::vector<Record*> &getRootNodes() const {
return RootNodes;
}
bool hasProperty(enum SDNP Prop) const { return Properties & (1 << Prop); }
unsigned getComplexity() const { return Complexity; }
2009-06-02 17:52:33 +00:00
};
} // End llvm namespace
#endif