1193323Sed//===- CodeGenTarget.h - Target Class Wrapper -------------------*- C++ -*-===// 2193323Sed// 3193323Sed// The LLVM Compiler Infrastructure 4193323Sed// 5193323Sed// This file is distributed under the University of Illinois Open Source 6193323Sed// License. See LICENSE.TXT for details. 7193323Sed// 8193323Sed//===----------------------------------------------------------------------===// 9193323Sed// 10193323Sed// This file defines wrappers for the Target class and related global 11193323Sed// functionality. This makes it easier to access the data and provides a single 12243830Sdim// place that needs to check it for validity. All of these classes abort 13243830Sdim// on error conditions. 14193323Sed// 15193323Sed//===----------------------------------------------------------------------===// 16193323Sed 17193323Sed#ifndef CODEGEN_TARGET_H 18193323Sed#define CODEGEN_TARGET_H 19193323Sed 20249423Sdim#include "CodeGenInstruction.h" 21193323Sed#include "CodeGenRegisters.h" 22249423Sdim#include "llvm/Support/raw_ostream.h" 23226633Sdim#include "llvm/TableGen/Record.h" 24193323Sed#include <algorithm> 25193323Sed 26193323Sednamespace llvm { 27193323Sed 28193323Sedstruct CodeGenRegister; 29239462Sdimclass CodeGenSchedModels; 30193323Sedclass CodeGenTarget; 31193323Sed 32193323Sed// SelectionDAG node properties. 33193323Sed// SDNPMemOperand: indicates that a node touches memory and therefore must 34193323Sed// have an associated memory operand that describes the access. 35193323Sedenum SDNP { 36221345Sdim SDNPCommutative, 37221345Sdim SDNPAssociative, 38193323Sed SDNPHasChain, 39218893Sdim SDNPOutGlue, 40218893Sdim SDNPInGlue, 41218893Sdim SDNPOptInGlue, 42193323Sed SDNPMayLoad, 43193323Sed SDNPMayStore, 44193323Sed SDNPSideEffect, 45205407Srdivacky SDNPMemOperand, 46218893Sdim SDNPVariadic, 47218893Sdim SDNPWantRoot, 48218893Sdim SDNPWantParent 49193323Sed}; 50193323Sed 51193323Sed/// getValueType - Return the MVT::SimpleValueType that the specified TableGen 52193323Sed/// record corresponds to. 53193323SedMVT::SimpleValueType getValueType(Record *Rec); 54193323Sed 55193323Sedstd::string getName(MVT::SimpleValueType T); 56193323Sedstd::string getEnumName(MVT::SimpleValueType T); 57193323Sed 58193323Sed/// getQualifiedName - Return the name of the specified record, with a 59193323Sed/// namespace qualifier if the record contains one. 60193323Sedstd::string getQualifiedName(const Record *R); 61221345Sdim 62193323Sed/// CodeGenTarget - This class corresponds to the Target class in the .td files. 63193323Sed/// 64193323Sedclass CodeGenTarget { 65218893Sdim RecordKeeper &Records; 66193323Sed Record *TargetRec; 67193323Sed 68205407Srdivacky mutable DenseMap<const Record*, CodeGenInstruction*> Instructions; 69223017Sdim mutable CodeGenRegBank *RegBank; 70224145Sdim mutable std::vector<Record*> RegAltNameIndices; 71249423Sdim mutable SmallVector<MVT::SimpleValueType, 8> LegalValueTypes; 72224145Sdim void ReadRegAltNameIndices() const; 73193323Sed void ReadInstructions() const; 74193323Sed void ReadLegalValueTypes() const; 75221345Sdim 76239462Sdim mutable CodeGenSchedModels *SchedModels; 77239462Sdim 78205407Srdivacky mutable std::vector<const CodeGenInstruction*> InstrsByEnum; 79193323Sedpublic: 80218893Sdim CodeGenTarget(RecordKeeper &Records); 81239462Sdim ~CodeGenTarget(); 82193323Sed 83193323Sed Record *getTargetRecord() const { return TargetRec; } 84193323Sed const std::string &getName() const; 85193323Sed 86193323Sed /// getInstNamespace - Return the target-specific instruction namespace. 87193323Sed /// 88193323Sed std::string getInstNamespace() const; 89193323Sed 90193323Sed /// getInstructionSet - Return the InstructionSet object. 91193323Sed /// 92193323Sed Record *getInstructionSet() const; 93193323Sed 94198090Srdivacky /// getAsmParser - Return the AssemblyParser definition for this target. 95198090Srdivacky /// 96198090Srdivacky Record *getAsmParser() const; 97198090Srdivacky 98234353Sdim /// getAsmParserVariant - Return the AssmblyParserVariant definition for 99234353Sdim /// this target. 100234353Sdim /// 101234353Sdim Record *getAsmParserVariant(unsigned i) const; 102234353Sdim 103239462Sdim /// getAsmParserVariantCount - Return the AssmblyParserVariant definition 104234353Sdim /// available for this target. 105234353Sdim /// 106234353Sdim unsigned getAsmParserVariantCount() const; 107234353Sdim 108193323Sed /// getAsmWriter - Return the AssemblyWriter definition for this target. 109193323Sed /// 110193323Sed Record *getAsmWriter() const; 111193323Sed 112223017Sdim /// getRegBank - Return the register bank description. 113223017Sdim CodeGenRegBank &getRegBank() const; 114223017Sdim 115218893Sdim /// getRegisterByName - If there is a register with the specific AsmName, 116218893Sdim /// return it. 117218893Sdim const CodeGenRegister *getRegisterByName(StringRef Name) const; 118193323Sed 119224145Sdim const std::vector<Record*> &getRegAltNameIndices() const { 120224145Sdim if (RegAltNameIndices.empty()) ReadRegAltNameIndices(); 121224145Sdim return RegAltNameIndices; 122224145Sdim } 123224145Sdim 124193323Sed const CodeGenRegisterClass &getRegisterClass(Record *R) const { 125224145Sdim return *getRegBank().getRegClass(R); 126193323Sed } 127221345Sdim 128193323Sed /// getRegisterVTs - Find the union of all possible SimpleValueTypes for the 129193323Sed /// specified physical register. 130205218Srdivacky std::vector<MVT::SimpleValueType> getRegisterVTs(Record *R) const; 131221345Sdim 132249423Sdim ArrayRef<MVT::SimpleValueType> getLegalValueTypes() const { 133193323Sed if (LegalValueTypes.empty()) ReadLegalValueTypes(); 134193323Sed return LegalValueTypes; 135193323Sed } 136221345Sdim 137193323Sed /// isLegalValueType - Return true if the specified value type is natively 138193323Sed /// supported by the target (i.e. there are registers that directly hold it). 139193323Sed bool isLegalValueType(MVT::SimpleValueType VT) const { 140249423Sdim ArrayRef<MVT::SimpleValueType> LegalVTs = getLegalValueTypes(); 141193323Sed for (unsigned i = 0, e = LegalVTs.size(); i != e; ++i) 142193323Sed if (LegalVTs[i] == VT) return true; 143221345Sdim return false; 144193323Sed } 145193323Sed 146239462Sdim CodeGenSchedModels &getSchedModels() const; 147239462Sdim 148205407Srdivackyprivate: 149205407Srdivacky DenseMap<const Record*, CodeGenInstruction*> &getInstructions() const { 150193323Sed if (Instructions.empty()) ReadInstructions(); 151193323Sed return Instructions; 152193323Sed } 153205407Srdivackypublic: 154221345Sdim 155205407Srdivacky CodeGenInstruction &getInstruction(const Record *InstRec) const { 156193323Sed if (Instructions.empty()) ReadInstructions(); 157205407Srdivacky DenseMap<const Record*, CodeGenInstruction*>::iterator I = 158205407Srdivacky Instructions.find(InstRec); 159205407Srdivacky assert(I != Instructions.end() && "Not an instruction"); 160205407Srdivacky return *I->second; 161193323Sed } 162193323Sed 163193323Sed /// getInstructionsByEnumValue - Return all of the instructions defined by the 164193323Sed /// target, ordered by their enum value. 165205407Srdivacky const std::vector<const CodeGenInstruction*> & 166205407Srdivacky getInstructionsByEnumValue() const { 167205407Srdivacky if (InstrsByEnum.empty()) ComputeInstrsByEnum(); 168205407Srdivacky return InstrsByEnum; 169205407Srdivacky } 170193323Sed 171205407Srdivacky typedef std::vector<const CodeGenInstruction*>::const_iterator inst_iterator; 172205407Srdivacky inst_iterator inst_begin() const{return getInstructionsByEnumValue().begin();} 173205407Srdivacky inst_iterator inst_end() const { return getInstructionsByEnumValue().end(); } 174221345Sdim 175221345Sdim 176193323Sed /// isLittleEndianEncoding - are instruction bit patterns defined as [0..n]? 177193323Sed /// 178193323Sed bool isLittleEndianEncoding() const; 179221345Sdim 180243830Sdim /// guessInstructionProperties - should we just guess unset instruction 181243830Sdim /// properties? 182243830Sdim bool guessInstructionProperties() const; 183243830Sdim 184205407Srdivackyprivate: 185205407Srdivacky void ComputeInstrsByEnum() const; 186193323Sed}; 187193323Sed 188193323Sed/// ComplexPattern - ComplexPattern info, corresponding to the ComplexPattern 189193323Sed/// tablegen class in TargetSelectionDAG.td 190193323Sedclass ComplexPattern { 191193323Sed MVT::SimpleValueType Ty; 192193323Sed unsigned NumOperands; 193193323Sed std::string SelectFunc; 194193323Sed std::vector<Record*> RootNodes; 195193323Sed unsigned Properties; // Node properties 196193323Sedpublic: 197199481Srdivacky ComplexPattern() : NumOperands(0) {} 198193323Sed ComplexPattern(Record *R); 199193323Sed 200193323Sed MVT::SimpleValueType getValueType() const { return Ty; } 201193323Sed unsigned getNumOperands() const { return NumOperands; } 202193323Sed const std::string &getSelectFunc() const { return SelectFunc; } 203193323Sed const std::vector<Record*> &getRootNodes() const { 204193323Sed return RootNodes; 205193323Sed } 206193323Sed bool hasProperty(enum SDNP Prop) const { return Properties & (1 << Prop); } 207193323Sed}; 208193323Sed 209193323Sed} // End llvm namespace 210193323Sed 211193323Sed#endif 212