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
|
|
|
|
2017-09-15 00:56:21 +08:00
|
|
|
#include "CodeGenHwModes.h"
|
2004-08-01 13:04:00 +08:00
|
|
|
#include "CodeGenInstruction.h"
|
2012-12-04 18:37:14 +08:00
|
|
|
#include "CodeGenRegisters.h"
|
2017-09-15 00:56:21 +08:00
|
|
|
#include "InfoByHwMode.h"
|
2017-12-21 03:36:28 +08:00
|
|
|
#include "SDNodeProperties.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
|
|
|
|
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
|
|
|
|
2016-05-26 02:07:40 +08:00
|
|
|
StringRef getName(MVT::SimpleValueType T);
|
|
|
|
StringRef 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;
|
2017-09-15 00:56:21 +08:00
|
|
|
mutable SmallVector<ValueTypeByHwMode, 8> LegalValueTypes;
|
|
|
|
CodeGenHwModes CGH;
|
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; }
|
2016-12-04 13:48:16 +08:00
|
|
|
const StringRef getName() const;
|
2003-10-06 03:27:59 +08:00
|
|
|
|
2008-08-21 05:45:57 +08:00
|
|
|
/// getInstNamespace - Return the target-specific instruction namespace.
|
|
|
|
///
|
2017-07-07 14:22:35 +08:00
|
|
|
StringRef getInstNamespace() const;
|
2008-08-21 05:45:57 +08:00
|
|
|
|
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;
|
|
|
|
|
[MachineOperand][Target] MachineOperand::isRenamable semantics changes
Summary:
Add a target option AllowRegisterRenaming that is used to opt in to
post-register-allocation renaming of registers. This is set to 0 by
default, which causes the hasExtraSrcRegAllocReq/hasExtraDstRegAllocReq
fields of all opcodes to be set to 1, causing
MachineOperand::isRenamable to always return false.
Set the AllowRegisterRenaming flag to 1 for all in-tree targets that
have lit tests that were effected by enabling COPY forwarding in
MachineCopyPropagation (AArch64, AMDGPU, ARM, Hexagon, Mips, PowerPC,
RISCV, Sparc, SystemZ and X86).
Add some more comments describing the semantics of the
MachineOperand::isRenamable function and how it is set and maintained.
Change isRenamable to check the operand's opcode
hasExtraSrcRegAllocReq/hasExtraDstRegAllocReq bit directly instead of
relying on it being consistently reflected in the IsRenamable bit
setting.
Clear the IsRenamable bit when changing an operand's register value.
Remove target code that was clearing the IsRenamable bit when changing
registers/opcodes now that this is done conservatively by default.
Change setting of hasExtraSrcRegAllocReq in AMDGPU target to be done in
one place covering all opcodes that have constant pipe read limit
restrictions.
Reviewers: qcolombet, MatzeB
Subscribers: aemerson, arsenm, jyknight, mcrosier, sdardis, nhaehnle, javed.absar, tpr, arichardson, kristof.beyls, kbarton, fedor.sergeev, asb, rbar, johnrusso, simoncook, jordy.potman.lists, apazos, sabuasal, niosHD, escha, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D43042
llvm-svn: 325931
2018-02-24 02:25:08 +08:00
|
|
|
/// getAllowRegisterRenaming - Return the AllowRegisterRenaming flag value for
|
|
|
|
/// this target.
|
|
|
|
///
|
|
|
|
bool getAllowRegisterRenaming() 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.
|
2017-09-15 00:56:21 +08:00
|
|
|
std::vector<ValueTypeByHwMode> getRegisterVTs(Record *R) const;
|
2011-03-11 09:27:24 +08:00
|
|
|
|
2017-09-15 00:56:21 +08:00
|
|
|
ArrayRef<ValueTypeByHwMode> getLegalValueTypes() const {
|
|
|
|
if (LegalValueTypes.empty())
|
|
|
|
ReadLegalValueTypes();
|
2005-09-09 05:43:21 +08:00
|
|
|
return LegalValueTypes;
|
|
|
|
}
|
2011-03-11 09:27:24 +08:00
|
|
|
|
2012-07-07 12:00:00 +08:00
|
|
|
CodeGenSchedModels &getSchedModels() const;
|
|
|
|
|
2017-09-15 00:56:21 +08:00
|
|
|
const CodeGenHwModes &getHwModes() const { return CGH; }
|
|
|
|
|
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
|
|
|
|
2018-01-25 06:35:11 +08:00
|
|
|
/// Returns the number of predefined instructions.
|
|
|
|
static unsigned getNumFixedInstructions();
|
|
|
|
|
2005-01-23 02:58:51 +08:00
|
|
|
/// getInstructionsByEnumValue - Return all of the instructions defined by the
|
|
|
|
/// target, ordered by their enum value.
|
2016-01-18 04:38:14 +08:00
|
|
|
ArrayRef<const CodeGenInstruction *>
|
2010-03-19 09:00:55 +08:00
|
|
|
getInstructionsByEnumValue() const {
|
2010-03-19 08:34:35 +08:00
|
|
|
if (InstrsByEnum.empty()) ComputeInstrsByEnum();
|
|
|
|
return InstrsByEnum;
|
|
|
|
}
|
2005-01-23 02:58:51 +08:00
|
|
|
|
2016-01-18 04:38:14 +08:00
|
|
|
typedef ArrayRef<const CodeGenInstruction *>::const_iterator inst_iterator;
|
2010-03-19 09:00:55 +08:00
|
|
|
inst_iterator inst_begin() const{return getInstructionsByEnumValue().begin();}
|
|
|
|
inst_iterator inst_end() const { return getInstructionsByEnumValue().end(); }
|
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
|
2016-11-10 07:53:43 +08:00
|
|
|
unsigned Complexity;
|
2005-12-08 10:00:36 +08:00
|
|
|
public:
|
|
|
|
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); }
|
2016-11-10 07:53:43 +08:00
|
|
|
unsigned getComplexity() const { return Complexity; }
|
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
|