109 lines · c
1//===- CodeGenInstAlias.h - InstAlias Class Wrapper -------------*- C++ -*-===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8//9// This file defines a wrapper class for the 'InstAlias' TableGen class.10//11//===----------------------------------------------------------------------===//12 13#ifndef LLVM_UTILS_TABLEGEN_COMMON_CODEGENINSTALIAS_H14#define LLVM_UTILS_TABLEGEN_COMMON_CODEGENINSTALIAS_H15 16#include "llvm/ADT/StringRef.h"17#include <cassert>18#include <cstdint>19#include <string>20#include <utility>21#include <vector>22 23namespace llvm {24 25class CodeGenInstruction;26class CodeGenTarget;27class DagInit;28class Record;29 30/// CodeGenInstAlias - This represents an InstAlias definition.31class CodeGenInstAlias {32public:33 const Record *TheDef; // The actual record defining this InstAlias.34 35 /// AsmString - The format string used to emit a .s file for the36 /// instruction.37 std::string AsmString;38 39 /// Result - The result instruction.40 const DagInit *Result;41 42 /// ResultInst - The instruction generated by the alias (decoded from43 /// Result).44 const CodeGenInstruction *ResultInst;45 46 class ResultOperand {47 std::string Name;48 const Record *R = nullptr;49 int64_t Imm = 0;50 51 ResultOperand(std::string N, const Record *R)52 : Name(std::move(N)), R(R), Kind(K_Record) {}53 ResultOperand(int64_t Imm) : Imm(Imm), Kind(K_Imm) {}54 ResultOperand(const Record *R) : R(R), Kind(K_Reg) {}55 56 public:57 enum { K_Record, K_Imm, K_Reg } Kind;58 59 static ResultOperand createRecord(std::string N, const Record *R) {60 return ResultOperand(std::move(N), R);61 }62 static ResultOperand createImmediate(int64_t Imm) {63 return ResultOperand(Imm);64 }65 static ResultOperand createRegister(const Record *R) {66 return ResultOperand(R);67 }68 69 bool isRecord() const { return Kind == K_Record; }70 bool isImm() const { return Kind == K_Imm; }71 bool isReg() const { return Kind == K_Reg; }72 73 StringRef getName() const {74 assert(isRecord());75 return Name;76 }77 const Record *getRecord() const {78 assert(isRecord());79 return R;80 }81 int64_t getImm() const {82 assert(isImm());83 return Imm;84 }85 const Record *getRegister() const {86 assert(isReg());87 return R;88 }89 90 unsigned getMINumOperands() const;91 };92 93 /// ResultOperands - The decoded operands for the result instruction.94 std::vector<ResultOperand> ResultOperands;95 96 /// ResultInstOperandIndex - For each operand, this vector holds a pair of97 /// indices to identify the corresponding operand in the result98 /// instruction. The first index specifies the operand and the second99 /// index specifies the suboperand. If there are no suboperands or if all100 /// of them are matched by the operand, the second value should be -1.101 std::vector<std::pair<unsigned, int>> ResultInstOperandIndex;102 103 CodeGenInstAlias(const Record *R, const CodeGenTarget &T);104};105 106} // namespace llvm107 108#endif // LLVM_UTILS_TABLEGEN_COMMON_CODEGENINSTALIAS_H109