brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.0 KiB · eaae928 Raw
76 lines · c
1//===- CombinerUtils.h ----------------------------------------------------===//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/// \file Utility functions used by both Combiner backends.10//11//===----------------------------------------------------------------------===//12 13#ifndef LLVM_UTILS_TABLEGEN_COMMON_GLOBALISEL_COMBINERUTILS_H14#define LLVM_UTILS_TABLEGEN_COMMON_GLOBALISEL_COMBINERUTILS_H15 16#include "llvm/ADT/StringRef.h"17#include "llvm/TableGen/Record.h"18 19namespace llvm {20 21/// A convenience function to check that an Init refers to a specific def. This22/// is primarily useful for testing for defs and similar in DagInit's since23/// DagInit's support any type inside them.24inline bool isSpecificDef(const Init &N, StringRef Def) {25  if (const DefInit *OpI = dyn_cast<DefInit>(&N))26    if (OpI->getDef()->getName() == Def)27      return true;28  return false;29}30 31/// A convenience function to check that an Init refers to a def that is a32/// subclass of the given class and coerce it to a def if it is. This is33/// primarily useful for testing for subclasses of GIDefKind and similar in34/// DagInit's since DagInit's support any type inside them.35inline const Record *getDefOfSubClass(const Init &N, StringRef Cls) {36  if (const DefInit *OpI = dyn_cast<DefInit>(&N))37    if (OpI->getDef()->isSubClassOf(Cls))38      return OpI->getDef();39  return nullptr;40}41 42/// A convenience function to check that an Init refers to a dag whose operator43/// is a specific def and coerce it to a dag if it is. This is primarily useful44/// for testing for subclasses of GIDefKind and similar in DagInit's since45/// DagInit's support any type inside them.46inline const DagInit *getDagWithSpecificOperator(const Init &N,47                                                 StringRef Name) {48  if (const DagInit *I = dyn_cast<DagInit>(&N))49    if (I->getNumArgs() > 0)50      if (const DefInit *OpI = dyn_cast<DefInit>(I->getOperator()))51        if (OpI->getDef()->getName() == Name)52          return I;53  return nullptr;54}55 56/// A convenience function to check that an Init refers to a dag whose operator57/// is a def that is a subclass of the given class and coerce it to a dag if it58/// is. This is primarily useful for testing for subclasses of GIDefKind and59/// similar in DagInit's since DagInit's support any type inside them.60inline const DagInit *getDagWithOperatorOfSubClass(const Init &N,61                                                   StringRef Cls) {62  if (const DagInit *I = dyn_cast<DagInit>(&N))63    if (const DefInit *OpI = dyn_cast<DefInit>(I->getOperator()))64      if (OpI->getDef()->isSubClassOf(Cls))65        return I;66  return nullptr;67}68 69/// Copies a StringRef into a static pool to preserve it.70// FIXME: Use UniqueStringSaver instead.71StringRef insertStrRef(StringRef S);72 73} // namespace llvm74 75#endif // LLVM_UTILS_TABLEGEN_COMMON_GLOBALISEL_COMBINERUTILS_H76