Path: blob/main/contrib/llvm-project/llvm/utils/TableGen/Common/GlobalISel/CombinerUtils.h
35313 views
//===- CombinerUtils.h ----------------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8/// \file Utility functions used by both Combiner backends.9//10//===----------------------------------------------------------------------===//1112#ifndef LLVM_UTILS_TABLEGEN_COMBINERUTILS_H13#define LLVM_UTILS_TABLEGEN_COMBINERUTILS_H1415#include "llvm/ADT/StringRef.h"16#include "llvm/TableGen/Record.h"1718namespace llvm {1920/// A convenience function to check that an Init refers to a specific def. This21/// is primarily useful for testing for defs and similar in DagInit's since22/// DagInit's support any type inside them.23inline bool isSpecificDef(const Init &N, StringRef Def) {24if (const DefInit *OpI = dyn_cast<DefInit>(&N))25if (OpI->getDef()->getName() == Def)26return true;27return false;28}2930/// A convenience function to check that an Init refers to a def that is a31/// subclass of the given class and coerce it to a def if it is. This is32/// primarily useful for testing for subclasses of GIDefKind and similar in33/// DagInit's since DagInit's support any type inside them.34inline Record *getDefOfSubClass(const Init &N, StringRef Cls) {35if (const DefInit *OpI = dyn_cast<DefInit>(&N))36if (OpI->getDef()->isSubClassOf(Cls))37return OpI->getDef();38return nullptr;39}4041/// A convenience function to check that an Init refers to a dag whose operator42/// is a specific def and coerce it to a dag if it is. This is primarily useful43/// for testing for subclasses of GIDefKind and similar in DagInit's since44/// DagInit's support any type inside them.45inline const DagInit *getDagWithSpecificOperator(const Init &N,46StringRef Name) {47if (const DagInit *I = dyn_cast<DagInit>(&N))48if (I->getNumArgs() > 0)49if (const DefInit *OpI = dyn_cast<DefInit>(I->getOperator()))50if (OpI->getDef()->getName() == Name)51return I;52return nullptr;53}5455/// A convenience function to check that an Init refers to a dag whose operator56/// is a def that is a subclass of the given class and coerce it to a dag if it57/// is. This is primarily useful for testing for subclasses of GIDefKind and58/// similar in DagInit's since DagInit's support any type inside them.59inline const DagInit *getDagWithOperatorOfSubClass(const Init &N,60StringRef Cls) {61if (const DagInit *I = dyn_cast<DagInit>(&N))62if (const DefInit *OpI = dyn_cast<DefInit>(I->getOperator()))63if (OpI->getDef()->isSubClassOf(Cls))64return I;65return nullptr;66}6768/// Copies a StringRef into a static pool to preserve it.69StringRef insertStrRef(StringRef S);7071} // namespace llvm7273#endif747576