//===------ MacroFusionPredicatorEmitter.cpp - Generator for Fusion ------===// // // 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 // //===---------------------------------------------------------------------===// // // MacroFusionPredicatorEmitter implements a TableGen-driven predicators // generator for macro-op fusions. // // This TableGen backend processes `Fusion` definitions and generates // predicators for checking if input instructions can be fused. These // predicators can used in `MacroFusion` DAG mutation. // // The generated header file contains two parts: one for predicator // declarations and one for predicator implementations. The user can get them // by defining macro `GET_<TargetName>_MACRO_FUSION_PRED_DECL` or // `GET_<TargetName>_MACRO_FUSION_PRED_IMPL` and then including the generated // header file. // // The generated predicator will be like: // // ``` // bool isNAME(const TargetInstrInfo &TII, // const TargetSubtargetInfo &STI, // const MachineInstr *FirstMI, // const MachineInstr &SecondMI) { // auto &MRI = SecondMI.getMF()->getRegInfo(); // /* Predicates */ // return true; // } // ``` // // The `Predicates` part is generated from a list of `FusionPredicate`, which // can be predefined predicates, a raw code string or `MCInstPredicate` defined // in TargetInstrPredicate.td. // //===---------------------------------------------------------------------===// #include "Common/CodeGenTarget.h" #include "Common/PredicateExpander.h" #include "llvm/Support/Debug.h" #include "llvm/TableGen/Error.h" #include "llvm/TableGen/Record.h" #include "llvm/TableGen/TableGenBackend.h" #include <vector> usingnamespacellvm; #define DEBUG_TYPE … namespace { class MacroFusionPredicatorEmitter { … }; } // End anonymous namespace. void MacroFusionPredicatorEmitter::emitMacroFusionDecl( ArrayRef<const Record *> Fusions, PredicateExpander &PE, raw_ostream &OS) { … } void MacroFusionPredicatorEmitter::emitMacroFusionImpl( ArrayRef<const Record *> Fusions, PredicateExpander &PE, raw_ostream &OS) { … } void MacroFusionPredicatorEmitter::emitPredicates( ArrayRef<const Record *> Predicates, bool IsCommutable, PredicateExpander &PE, raw_ostream &OS) { … } void MacroFusionPredicatorEmitter::emitFirstPredicate(const Record *Predicate, bool IsCommutable, PredicateExpander &PE, raw_ostream &OS) { … } void MacroFusionPredicatorEmitter::emitSecondPredicate(const Record *Predicate, bool IsCommutable, PredicateExpander &PE, raw_ostream &OS) { … } void MacroFusionPredicatorEmitter::emitBothPredicate(const Record *Predicate, bool IsCommutable, PredicateExpander &PE, raw_ostream &OS) { … } void MacroFusionPredicatorEmitter::run(raw_ostream &OS) { … } static TableGen::Emitter::OptClass<MacroFusionPredicatorEmitter> X("gen-macro-fusion-pred", "Generate macro fusion predicators.");