mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-05-14 01:46:41 +00:00

The MCInstDesc table changed. Bsides this only minor changes were done and some additional code is emitted now for LLVM. This commit is the combination of all previous Auto-Sync commits. The list of commit messages follows: ----------- Combination of all commits of the refactored tablegen backends. These are the changes made for LLVM 16. Refactor Capstone relevant TableGen Emitter backends. This commit extracts the code which emits generated tables into two printer classes. The Printer is called whenever actual code is written to a file. There is the PrinterLLVM which emits tht code as before and PrinterCapstone which is tailored to or needs (emitting C and generates more info). Additionally missing memory access properties were added to ARMs td files. Emit a single header for all files. Captialize Target name for enums. Add lay metric to emit enum value for Banked and system regs. Malloc substr Sort instructions in ascending order. Free substr after use Add vanished constrainsts Fix `regInfoEmitEnums()` and indent Fix `GenDisassemblerTables.inc#checkDecoderPredicate()` Fix `TriCoreGenRegisterInfo.inc` | `PrinterCapstone::regInfoEmitRegClasses` revert changes to NEON instructions Add instructions with duplicate operands as Matchables. Add memory load and store info Correct memory access and out operand info Set register lists again as read ops due to https://github.com/llvm/llvm-project/issues/62455 Make printAliasInstr and getMnemonic static. Generate CS instruction enums from actual mnemonic. Not via the flawed AsmMatcher. Fix typo in InstrInfoEmitter.cpp Add deprecated QPX feature Replace + and - with p and m Add AssemblerPredicates to PPC Generate RegEncodingTable Define functions which are called by the Mapper as static. Necessary because these functions are present in each arch' Remove set_mem_access(). The cases where this is used to mark access to actual memory operands are either very rare, or those are neon lane indicies. Generate correct op type for absolute addresses. Check for RegisterPointer operands first to prevent mis-categorization. Add missing Operand types Generate Instruction formats for PPC. Add Paired Single instructions. Partly revert 94e41ce23a7fd863a96288ec05b6c7202c3cfbf1 (introduces accidentially removed code.) Set correct operand types for PS operands Add memory read/write attributes Add missing operand types Add mayLoad and mayStore information. Add documentation. Handle special AArch64 operand Replace C++ with C code. Check for duplicate enum instr. names Check for duplicate defintions of system registers. Add note about missing target names. Resolve templates in a single static method and add docs about it. Revert printing target name in upper case. Revert partially C++ syntax fixes in .td files. They break the TemplateCOllector since it searches for exactly those references but can't find any' Add all SubtargetFeatures to feature enum. Not just the one used by CGIs. Pass Decoder Enable to check specific table fields to determine if reg enum must be emitted. Allow to add namespace to type name/ Formatting Rework emitting of tables. The system operands are now emitted in reg, imm and aliass groups. Also a bug was fixed which emitted incorrect code.. Check for rename IMPLICIT_IMM operand types Pass DecodeComplete as pointer not as reference Print undef when it needs to be printed. Add namespace ids to all types and functions. Rework C translation. Pass MCOp as pointer not as ref Add missing SysImm type Fix syntax mistakes Generate additonal sys immediates and op groups. Handle edge case for printSVERegOp Handle default arguments of template functions. Add two missing op groups Generate a static RecEncodingTable Set enum values to encodings of the sys ops Generate a single Enum value file for system operands. Replace System operand groups with their operand types Fix missing braces warning Emit MCOperand validator. Emit lookupByName functions for sys operands Add namespaces for ARM. Check for Target if default arguments of template functions are resolved. auto-sync opcode & operand encoding info generation (#14) * Added operand and opcode info generation * Wrapped deprecated macro under an intellisense check Basically intellisense fails, causing multiple errors in other files, so when intellisense parses the code it will use the different version of the macro * Fixed a small bug Used double braces to prevent an old bug Removed extra new line and fixed a bug regarding move semantics
274 lines
14 KiB
C++
274 lines
14 KiB
C++
//===--------------------- PredicateExpander.h ----------------------------===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
/// \file
|
|
/// Functionalities used by the Tablegen backends to expand machine predicates.
|
|
///
|
|
/// See file llvm/Target/TargetInstrPredicate.td for a full list and description
|
|
/// of all the supported MCInstPredicate classes.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef LLVM_UTILS_TABLEGEN_PREDICATEEXPANDER_H
|
|
#define LLVM_UTILS_TABLEGEN_PREDICATEEXPANDER_H
|
|
|
|
#include "llvm/ADT/StringRef.h"
|
|
#include <vector>
|
|
|
|
namespace llvm {
|
|
|
|
// Forward declarations.
|
|
class STIPredicateFunction;
|
|
class OpcodeGroup;
|
|
class raw_ostream;
|
|
class Record;
|
|
class PredicateExpanderLLVM;
|
|
class PredicateExpanderCapstone;
|
|
|
|
class PredicateExpander {
|
|
|
|
friend PredicateExpanderLLVM;
|
|
friend PredicateExpanderCapstone;
|
|
|
|
bool EmitCallsByRef;
|
|
bool NegatePredicate;
|
|
bool ExpandForMC;
|
|
unsigned IndentLevel;
|
|
StringRef TargetName;
|
|
// STI only
|
|
bool ExpandDefinition;
|
|
StringRef ClassPrefix;
|
|
|
|
PredicateExpander(const PredicateExpander &) = delete;
|
|
PredicateExpander &operator=(const PredicateExpander &) = delete;
|
|
|
|
private:
|
|
virtual void expandHeader(raw_ostream &OS, const STIPredicateFunction &Fn) = 0;
|
|
virtual void expandPrologue(raw_ostream &OS, const STIPredicateFunction &Fn) = 0;
|
|
virtual void expandOpcodeGroup(raw_ostream &OS, const OpcodeGroup &Group,
|
|
bool ShouldUpdateOpcodeMask) = 0;
|
|
virtual void expandBody(raw_ostream &OS, const STIPredicateFunction &Fn) = 0;
|
|
virtual void expandEpilogue(raw_ostream &OS, const STIPredicateFunction &Fn) = 0;
|
|
|
|
public:
|
|
PredicateExpander(StringRef Target)
|
|
: EmitCallsByRef(true), NegatePredicate(false), ExpandForMC(false),
|
|
IndentLevel(1U), TargetName(Target), ExpandDefinition(false) {}
|
|
virtual ~PredicateExpander() {}
|
|
bool isByRef() const { return EmitCallsByRef; }
|
|
bool shouldNegate() const { return NegatePredicate; }
|
|
bool shouldExpandForMC() const { return ExpandForMC; }
|
|
unsigned getIndentLevel() const { return IndentLevel; }
|
|
StringRef getTargetName() const { return TargetName; }
|
|
|
|
// STI only
|
|
bool shouldExpandDefinition() const { return ExpandDefinition; }
|
|
StringRef getClassPrefix() const { return ClassPrefix; }
|
|
void setClassPrefix(StringRef S) { ClassPrefix = S; }
|
|
void setExpandDefinition(bool Value) { ExpandDefinition = Value; }
|
|
|
|
void setByRef(bool Value) { EmitCallsByRef = Value; }
|
|
void flipNegatePredicate() { NegatePredicate = !NegatePredicate; }
|
|
void setNegatePredicate(bool Value) { NegatePredicate = Value; }
|
|
void setExpandForMC(bool Value) { ExpandForMC = Value; }
|
|
void setIndentLevel(unsigned Level) { IndentLevel = Level; }
|
|
void increaseIndentLevel() { ++IndentLevel; }
|
|
void decreaseIndentLevel() { --IndentLevel; }
|
|
|
|
using RecVec = std::vector<Record *>;
|
|
virtual void expandTrue(raw_ostream &OS) = 0;
|
|
virtual void expandFalse(raw_ostream &OS) = 0;
|
|
virtual void expandCheckImmOperand(raw_ostream &OS, int OpIndex, int ImmVal,
|
|
StringRef FunctionMapper) = 0;
|
|
virtual void expandCheckImmOperand(raw_ostream &OS, int OpIndex,
|
|
StringRef ImmVal,
|
|
StringRef FunctionMapperer) = 0;
|
|
virtual void expandCheckImmOperandSimple(raw_ostream &OS, int OpIndex,
|
|
StringRef FunctionMapper) = 0;
|
|
virtual void expandCheckImmOperandLT(raw_ostream &OS, int OpIndex, int ImmVal,
|
|
StringRef FunctionMapper) = 0;
|
|
virtual void expandCheckImmOperandGT(raw_ostream &OS, int OpIndex, int ImmVal,
|
|
StringRef FunctionMapper) = 0;
|
|
virtual void expandCheckRegOperand(raw_ostream &OS, int OpIndex,
|
|
const Record *Reg,
|
|
StringRef FunctionMapper) = 0;
|
|
virtual void expandCheckRegOperandSimple(raw_ostream &OS, int OpIndex,
|
|
StringRef FunctionMapper) = 0;
|
|
virtual void expandCheckSameRegOperand(raw_ostream &OS, int First,
|
|
int Second) = 0;
|
|
virtual void expandCheckNumOperands(raw_ostream &OS, int NumOps) = 0;
|
|
virtual void expandCheckOpcode(raw_ostream &OS, const Record *Inst) = 0;
|
|
|
|
virtual void expandCheckPseudo(raw_ostream &OS, const RecVec &Opcodes) = 0;
|
|
virtual void expandCheckOpcode(raw_ostream &OS, const RecVec &Opcodes) = 0;
|
|
virtual void expandPredicateSequence(raw_ostream &OS, const RecVec &Sequence,
|
|
bool IsCheckAll) = 0;
|
|
virtual void expandTIIFunctionCall(raw_ostream &OS, StringRef MethodName) = 0;
|
|
virtual void expandCheckIsRegOperand(raw_ostream &OS, int OpIndex) = 0;
|
|
virtual void expandCheckIsVRegOperand(raw_ostream &OS, int OpIndex) = 0;
|
|
virtual void expandCheckIsImmOperand(raw_ostream &OS, int OpIndex) = 0;
|
|
virtual void expandCheckInvalidRegOperand(raw_ostream &OS, int OpIndex) = 0;
|
|
virtual void expandCheckFunctionPredicate(raw_ostream &OS, StringRef MCInstFn,
|
|
StringRef MachineInstrFn) = 0;
|
|
virtual void expandCheckFunctionPredicateWithTII(raw_ostream &OS,
|
|
StringRef MCInstFn,
|
|
StringRef MachineInstrFn,
|
|
StringRef TIIPtr) = 0;
|
|
virtual void expandCheckNonPortable(raw_ostream &OS, StringRef CodeBlock) = 0;
|
|
virtual void expandPredicate(raw_ostream &OS, const Record *Rec) = 0;
|
|
virtual void expandReturnStatement(raw_ostream &OS, const Record *Rec) = 0;
|
|
virtual void expandOpcodeSwitchCase(raw_ostream &OS, const Record *Rec) = 0;
|
|
virtual void expandOpcodeSwitchStatement(raw_ostream &OS, const RecVec &Cases,
|
|
const Record *Default) = 0;
|
|
virtual void expandStatement(raw_ostream &OS, const Record *Rec) = 0;
|
|
virtual void expandSTIPredicate(raw_ostream &OS,
|
|
const STIPredicateFunction &Fn) = 0;
|
|
};
|
|
|
|
// Forward declarations.
|
|
class STIPredicateFunction;
|
|
class OpcodeGroup;
|
|
|
|
class STIPredicateExpander : public PredicateExpander {
|
|
StringRef ClassPrefix;
|
|
bool ExpandDefinition;
|
|
|
|
STIPredicateExpander(const PredicateExpander &) = delete;
|
|
STIPredicateExpander &operator=(const PredicateExpander &) = delete;
|
|
|
|
void expandHeader(raw_ostream &OS, const STIPredicateFunction &Fn) override;
|
|
void expandPrologue(raw_ostream &OS, const STIPredicateFunction &Fn) override;
|
|
void expandOpcodeGroup(raw_ostream &OS, const OpcodeGroup &Group,
|
|
bool ShouldUpdateOpcodeMask) override;
|
|
void expandBody(raw_ostream &OS, const STIPredicateFunction &Fn) override;
|
|
void expandEpilogue(raw_ostream &OS, const STIPredicateFunction &Fn) override;
|
|
|
|
public:
|
|
STIPredicateExpander(StringRef Target)
|
|
: PredicateExpander(Target), ExpandDefinition(false) {}
|
|
};
|
|
|
|
class PredicateExpanderLLVM : public PredicateExpander {
|
|
using PredicateExpander::PredicateExpander;
|
|
|
|
void expandHeader(raw_ostream &OS, const STIPredicateFunction &Fn) override;
|
|
void expandPrologue(raw_ostream &OS, const STIPredicateFunction &Fn) override;
|
|
void expandOpcodeGroup(raw_ostream &OS, const OpcodeGroup &Group,
|
|
bool ShouldUpdateOpcodeMask) override;
|
|
void expandBody(raw_ostream &OS, const STIPredicateFunction &Fn) override;
|
|
void expandEpilogue(raw_ostream &OS, const STIPredicateFunction &Fn) override;
|
|
|
|
void expandTrue(raw_ostream &OS) override;
|
|
void expandFalse(raw_ostream &OS) override;
|
|
void expandCheckImmOperand(raw_ostream &OS, int OpIndex, int ImmVal,
|
|
StringRef FunctionMapper) override;
|
|
void expandCheckImmOperand(raw_ostream &OS, int OpIndex, StringRef ImmVal,
|
|
StringRef FunctionMapperer) override;
|
|
void expandCheckImmOperandSimple(raw_ostream &OS, int OpIndex,
|
|
StringRef FunctionMapper) override;
|
|
void expandCheckImmOperandLT(raw_ostream &OS, int OpIndex, int ImmVal,
|
|
StringRef FunctionMapper) override;
|
|
void expandCheckImmOperandGT(raw_ostream &OS, int OpIndex, int ImmVal,
|
|
StringRef FunctionMapper) override;
|
|
void expandCheckRegOperand(raw_ostream &OS, int OpIndex, const Record *Reg,
|
|
StringRef FunctionMapper) override;
|
|
void expandCheckRegOperandSimple(raw_ostream &OS, int OpIndex,
|
|
StringRef FunctionMapper) override;
|
|
void expandCheckSameRegOperand(raw_ostream &OS, int First,
|
|
int Second) override;
|
|
void expandCheckNumOperands(raw_ostream &OS, int NumOps) override;
|
|
void expandCheckOpcode(raw_ostream &OS, const Record *Inst) override;
|
|
|
|
void expandCheckPseudo(raw_ostream &OS, const RecVec &Opcodes) override;
|
|
void expandCheckOpcode(raw_ostream &OS, const RecVec &Opcodes) override;
|
|
void expandPredicateSequence(raw_ostream &OS, const RecVec &Sequence,
|
|
bool IsCheckAll) override;
|
|
void expandTIIFunctionCall(raw_ostream &OS, StringRef MethodName) override;
|
|
void expandCheckIsRegOperand(raw_ostream &OS, int OpIndex) override;
|
|
void expandCheckIsVRegOperand(raw_ostream &OS, int OpIndex) override;
|
|
void expandCheckIsImmOperand(raw_ostream &OS, int OpIndex) override;
|
|
void expandCheckInvalidRegOperand(raw_ostream &OS, int OpIndex) override;
|
|
void expandCheckFunctionPredicate(raw_ostream &OS, StringRef MCInstFn,
|
|
StringRef MachineInstrFn) override;
|
|
void expandCheckFunctionPredicateWithTII(raw_ostream &OS, StringRef MCInstFn,
|
|
StringRef MachineInstrFn,
|
|
StringRef TIIPtr) override;
|
|
void expandCheckNonPortable(raw_ostream &OS, StringRef CodeBlock) override;
|
|
void expandPredicate(raw_ostream &OS, const Record *Rec) override;
|
|
void expandReturnStatement(raw_ostream &OS, const Record *Rec) override;
|
|
void expandOpcodeSwitchCase(raw_ostream &OS, const Record *Rec) override;
|
|
void expandOpcodeSwitchStatement(raw_ostream &OS, const RecVec &Cases,
|
|
const Record *Default) override;
|
|
void expandStatement(raw_ostream &OS, const Record *Rec) override;
|
|
|
|
// STI only
|
|
void expandSTIPredicate(raw_ostream &OS,
|
|
const STIPredicateFunction &Fn) override;
|
|
};
|
|
|
|
class PredicateExpanderCapstone : public PredicateExpander {
|
|
using PredicateExpander::PredicateExpander;
|
|
|
|
void expandHeader(raw_ostream &OS, const STIPredicateFunction &Fn) override;
|
|
void expandPrologue(raw_ostream &OS, const STIPredicateFunction &Fn) override;
|
|
void expandOpcodeGroup(raw_ostream &OS, const OpcodeGroup &Group,
|
|
bool ShouldUpdateOpcodeMask) override;
|
|
void expandBody(raw_ostream &OS, const STIPredicateFunction &Fn) override;
|
|
void expandEpilogue(raw_ostream &OS, const STIPredicateFunction &Fn) override;
|
|
|
|
void expandTrue(raw_ostream &OS) override;
|
|
void expandFalse(raw_ostream &OS) override;
|
|
void expandCheckImmOperand(raw_ostream &OS, int OpIndex, int ImmVal,
|
|
StringRef FunctionMapper) override;
|
|
void expandCheckImmOperand(raw_ostream &OS, int OpIndex, StringRef ImmVal,
|
|
StringRef FunctionMapperer) override;
|
|
void expandCheckImmOperandSimple(raw_ostream &OS, int OpIndex,
|
|
StringRef FunctionMapper) override;
|
|
void expandCheckImmOperandLT(raw_ostream &OS, int OpIndex, int ImmVal,
|
|
StringRef FunctionMapper) override;
|
|
void expandCheckImmOperandGT(raw_ostream &OS, int OpIndex, int ImmVal,
|
|
StringRef FunctionMapper) override;
|
|
void expandCheckRegOperand(raw_ostream &OS, int OpIndex, const Record *Reg,
|
|
StringRef FunctionMapper) override;
|
|
void expandCheckRegOperandSimple(raw_ostream &OS, int OpIndex,
|
|
StringRef FunctionMapper) override;
|
|
void expandCheckSameRegOperand(raw_ostream &OS, int First,
|
|
int Second) override;
|
|
void expandCheckNumOperands(raw_ostream &OS, int NumOps) override;
|
|
void expandCheckOpcode(raw_ostream &OS, const Record *Inst) override;
|
|
|
|
void expandCheckPseudo(raw_ostream &OS, const RecVec &Opcodes) override;
|
|
void expandCheckOpcode(raw_ostream &OS, const RecVec &Opcodes) override;
|
|
void expandPredicateSequence(raw_ostream &OS, const RecVec &Sequence,
|
|
bool IsCheckAll) override;
|
|
void expandTIIFunctionCall(raw_ostream &OS, StringRef MethodName) override;
|
|
void expandCheckIsRegOperand(raw_ostream &OS, int OpIndex) override;
|
|
void expandCheckIsVRegOperand(raw_ostream &OS, int OpIndex) override;
|
|
void expandCheckIsImmOperand(raw_ostream &OS, int OpIndex) override;
|
|
void expandCheckInvalidRegOperand(raw_ostream &OS, int OpIndex) override;
|
|
void expandCheckFunctionPredicate(raw_ostream &OS, StringRef MCInstFn,
|
|
StringRef MachineInstrFn) override;
|
|
void expandCheckFunctionPredicateWithTII(raw_ostream &OS, StringRef MCInstFn,
|
|
StringRef MachineInstrFn,
|
|
StringRef TIIPtr) override;
|
|
void expandCheckNonPortable(raw_ostream &OS, StringRef CodeBlock) override;
|
|
void expandPredicate(raw_ostream &OS, const Record *Rec) override;
|
|
void expandReturnStatement(raw_ostream &OS, const Record *Rec) override;
|
|
void expandOpcodeSwitchCase(raw_ostream &OS, const Record *Rec) override;
|
|
void expandOpcodeSwitchStatement(raw_ostream &OS, const RecVec &Cases,
|
|
const Record *Default) override;
|
|
void expandStatement(raw_ostream &OS, const Record *Rec) override;
|
|
|
|
// STI only
|
|
void expandSTIPredicate(raw_ostream &OS,
|
|
const STIPredicateFunction &Fn) override;
|
|
};
|
|
|
|
} // namespace llvm
|
|
|
|
#endif
|