123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410 |
- #ifndef LLVM_UTILS_TABLEGEN_CODEGENINSTRUCTION_H
- #define LLVM_UTILS_TABLEGEN_CODEGENINSTRUCTION_H
- #include "llvm/ADT/BitVector.h"
- #include "llvm/ADT/StringMap.h"
- #include "llvm/ADT/StringRef.h"
- #include "llvm/Support/MachineValueType.h"
- #include <cassert>
- #include <string>
- #include <utility>
- #include <vector>
- namespace llvm {
- class SMLoc;
- template <typename T> class ArrayRef;
- class Record;
- class DagInit;
- class CodeGenTarget;
- class CGIOperandList {
- public:
- class ConstraintInfo {
- enum { None, EarlyClobber, Tied } Kind = None;
- unsigned OtherTiedOperand = 0;
- public:
- ConstraintInfo() = default;
- static ConstraintInfo getEarlyClobber() {
- ConstraintInfo I;
- I.Kind = EarlyClobber;
- I.OtherTiedOperand = 0;
- return I;
- }
- static ConstraintInfo getTied(unsigned Op) {
- ConstraintInfo I;
- I.Kind = Tied;
- I.OtherTiedOperand = Op;
- return I;
- }
- bool isNone() const { return Kind == None; }
- bool isEarlyClobber() const { return Kind == EarlyClobber; }
- bool isTied() const { return Kind == Tied; }
- unsigned getTiedOperand() const {
- assert(isTied());
- return OtherTiedOperand;
- }
- bool operator==(const ConstraintInfo &RHS) const {
- if (Kind != RHS.Kind)
- return false;
- if (Kind == Tied && OtherTiedOperand != RHS.OtherTiedOperand)
- return false;
- return true;
- }
- bool operator!=(const ConstraintInfo &RHS) const {
- return !(*this == RHS);
- }
- };
-
-
- struct OperandInfo {
-
-
- Record *Rec;
-
-
- std::string Name;
-
- std::vector<std::string> SubOpNames;
-
-
- std::string PrinterMethodName;
-
-
- std::vector<std::string> EncoderMethodNames;
-
-
- std::string OperandType;
-
-
-
-
-
-
- unsigned MIOperandNo;
- unsigned MINumOperands;
-
-
-
- BitVector DoNotEncode;
-
-
- DagInit *MIOperandInfo;
-
-
- std::vector<ConstraintInfo> Constraints;
- OperandInfo(Record *R, const std::string &N, const std::string &PMN,
- const std::string &OT, unsigned MION, unsigned MINO,
- DagInit *MIOI)
- : Rec(R), Name(N), SubOpNames(MINO), PrinterMethodName(PMN),
- EncoderMethodNames(MINO), OperandType(OT), MIOperandNo(MION),
- MINumOperands(MINO), DoNotEncode(MINO), MIOperandInfo(MIOI),
- Constraints(MINO) {}
-
-
- int getTiedRegister() const {
- for (unsigned j = 0, e = Constraints.size(); j != e; ++j) {
- const CGIOperandList::ConstraintInfo &CI = Constraints[j];
- if (CI.isTied()) return CI.getTiedOperand();
- }
- return -1;
- }
- };
- CGIOperandList(Record *D);
- Record *TheDef;
-
-
-
- unsigned NumDefs;
-
-
- std::vector<OperandInfo> OperandList;
-
- StringMap<std::pair<unsigned, unsigned>> SubOpAliases;
-
- bool isPredicable;
- bool hasOptionalDef;
- bool isVariadic;
-
- bool empty() const { return OperandList.empty(); }
- unsigned size() const { return OperandList.size(); }
- const OperandInfo &operator[](unsigned i) const { return OperandList[i]; }
- OperandInfo &operator[](unsigned i) { return OperandList[i]; }
- OperandInfo &back() { return OperandList.back(); }
- const OperandInfo &back() const { return OperandList.back(); }
- typedef std::vector<OperandInfo>::iterator iterator;
- typedef std::vector<OperandInfo>::const_iterator const_iterator;
- iterator begin() { return OperandList.begin(); }
- const_iterator begin() const { return OperandList.begin(); }
- iterator end() { return OperandList.end(); }
- const_iterator end() const { return OperandList.end(); }
-
-
-
- unsigned getOperandNamed(StringRef Name) const;
-
-
-
- bool hasOperandNamed(StringRef Name, unsigned &OpIdx) const;
- bool hasSubOperandAlias(StringRef Name,
- std::pair<unsigned, unsigned> &SubOp) const;
-
-
-
-
- std::pair<unsigned,unsigned> ParseOperandName(StringRef Op,
- bool AllowWholeOp = true);
-
-
- unsigned getFlattenedOperandNumber(std::pair<unsigned,unsigned> Op) const {
- return OperandList[Op.first].MIOperandNo + Op.second;
- }
-
-
- std::pair<unsigned,unsigned> getSubOperandNumber(unsigned Op) const {
- for (unsigned i = 0; ; ++i) {
- assert(i < OperandList.size() && "Invalid flat operand #");
- if (OperandList[i].MIOperandNo+OperandList[i].MINumOperands > Op)
- return std::make_pair(i, Op-OperandList[i].MIOperandNo);
- }
- }
-
-
- bool isFlatOperandNotEmitted(unsigned FlatOpNo) const {
- std::pair<unsigned,unsigned> Op = getSubOperandNumber(FlatOpNo);
- if (OperandList[Op.first].DoNotEncode.size() > Op.second)
- return OperandList[Op.first].DoNotEncode[Op.second];
- return false;
- }
- void ProcessDisableEncoding(StringRef Value);
- };
- class CodeGenInstruction {
- public:
- Record *TheDef;
- StringRef Namespace;
-
-
- std::string AsmString;
-
-
- CGIOperandList Operands;
-
-
- std::vector<Record*> ImplicitDefs, ImplicitUses;
-
- bool isPreISelOpcode : 1;
- bool isReturn : 1;
- bool isEHScopeReturn : 1;
- bool isBranch : 1;
- bool isIndirectBranch : 1;
- bool isCompare : 1;
- bool isMoveImm : 1;
- bool isMoveReg : 1;
- bool isBitcast : 1;
- bool isSelect : 1;
- bool isBarrier : 1;
- bool isCall : 1;
- bool isAdd : 1;
- bool isTrap : 1;
- bool canFoldAsLoad : 1;
- bool mayLoad : 1;
- bool mayLoad_Unset : 1;
- bool mayStore : 1;
- bool mayStore_Unset : 1;
- bool mayRaiseFPException : 1;
- bool isPredicable : 1;
- bool isConvertibleToThreeAddress : 1;
- bool isCommutable : 1;
- bool isTerminator : 1;
- bool isReMaterializable : 1;
- bool hasDelaySlot : 1;
- bool usesCustomInserter : 1;
- bool hasPostISelHook : 1;
- bool hasCtrlDep : 1;
- bool isNotDuplicable : 1;
- bool hasSideEffects : 1;
- bool hasSideEffects_Unset : 1;
- bool isAsCheapAsAMove : 1;
- bool hasExtraSrcRegAllocReq : 1;
- bool hasExtraDefRegAllocReq : 1;
- bool isCodeGenOnly : 1;
- bool isPseudo : 1;
- bool isMeta : 1;
- bool isRegSequence : 1;
- bool isExtractSubreg : 1;
- bool isInsertSubreg : 1;
- bool isConvergent : 1;
- bool hasNoSchedulingInfo : 1;
- bool FastISelShouldIgnore : 1;
- bool hasChain : 1;
- bool hasChain_Inferred : 1;
- bool variadicOpsAreDefs : 1;
- bool isAuthenticated : 1;
- std::string DeprecatedReason;
- bool HasComplexDeprecationPredicate;
-
- bool hasUndefFlags() const {
- return mayLoad_Unset || mayStore_Unset || hasSideEffects_Unset;
- }
-
-
- Record *InferredFrom;
- CodeGenInstruction(Record *R);
-
-
-
- MVT::SimpleValueType
- HasOneImplicitDefWithKnownVT(const CodeGenTarget &TargetInfo) const;
-
-
- static std::string FlattenAsmStringVariants(StringRef AsmString,
- unsigned Variant);
-
-
-
-
- bool isInOperandAPointer(unsigned i) const {
- return isOperandImpl("InOperandList", i, "IsPointer");
- }
- bool isOutOperandAPointer(unsigned i) const {
- return isOperandImpl("OutOperandList", i, "IsPointer");
- }
-
- bool isInOperandImmArg(unsigned i) const {
- return isOperandImpl("InOperandList", i, "IsImmediate");
- }
- private:
- bool isOperandImpl(StringRef OpListName, unsigned i,
- StringRef PropertyName) const;
- };
-
- class CodeGenInstAlias {
- public:
- Record *TheDef;
-
-
- std::string AsmString;
-
- DagInit *Result;
-
-
- CodeGenInstruction *ResultInst;
- struct ResultOperand {
- private:
- std::string Name;
- Record *R = nullptr;
- int64_t Imm = 0;
- public:
- enum {
- K_Record,
- K_Imm,
- K_Reg
- } Kind;
- ResultOperand(std::string N, Record *r)
- : Name(std::move(N)), R(r), Kind(K_Record) {}
- ResultOperand(int64_t I) : Imm(I), Kind(K_Imm) {}
- ResultOperand(Record *r) : R(r), Kind(K_Reg) {}
- bool isRecord() const { return Kind == K_Record; }
- bool isImm() const { return Kind == K_Imm; }
- bool isReg() const { return Kind == K_Reg; }
- StringRef getName() const { assert(isRecord()); return Name; }
- Record *getRecord() const { assert(isRecord()); return R; }
- int64_t getImm() const { assert(isImm()); return Imm; }
- Record *getRegister() const { assert(isReg()); return R; }
- unsigned getMINumOperands() const;
- };
-
- std::vector<ResultOperand> ResultOperands;
-
-
-
-
-
- std::vector<std::pair<unsigned, int> > ResultInstOperandIndex;
- CodeGenInstAlias(Record *R, CodeGenTarget &T);
- bool tryAliasOpMatch(DagInit *Result, unsigned AliasOpNo,
- Record *InstOpRec, bool hasSubOps, ArrayRef<SMLoc> Loc,
- CodeGenTarget &T, ResultOperand &ResOp);
- };
- }
- #endif
|