[Frontend] Remove unused includes (NFC) (#116927)
[llvm-project.git] / llvm / utils / TableGen / Common / GlobalISel / CombinerUtils.h
blobde6ccd4c023e2c3377fbea259ebe1e56d28653f6
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-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 /// \file Utility functions used by both Combiner backends.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_UTILS_TABLEGEN_COMMON_GLOBALISEL_COMBINERUTILS_H
14 #define LLVM_UTILS_TABLEGEN_COMMON_GLOBALISEL_COMBINERUTILS_H
16 #include "llvm/ADT/StringRef.h"
17 #include "llvm/TableGen/Record.h"
19 namespace llvm {
21 /// A convenience function to check that an Init refers to a specific def. This
22 /// is primarily useful for testing for defs and similar in DagInit's since
23 /// DagInit's support any type inside them.
24 inline 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;
31 /// A convenience function to check that an Init refers to a def that is a
32 /// subclass of the given class and coerce it to a def if it is. This is
33 /// primarily useful for testing for subclasses of GIDefKind and similar in
34 /// DagInit's since DagInit's support any type inside them.
35 inline 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;
42 /// A convenience function to check that an Init refers to a dag whose operator
43 /// is a specific def and coerce it to a dag if it is. This is primarily useful
44 /// for testing for subclasses of GIDefKind and similar in DagInit's since
45 /// DagInit's support any type inside them.
46 inline 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;
56 /// A convenience function to check that an Init refers to a dag whose operator
57 /// is a def that is a subclass of the given class and coerce it to a dag if it
58 /// is. This is primarily useful for testing for subclasses of GIDefKind and
59 /// similar in DagInit's since DagInit's support any type inside them.
60 inline 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;
69 /// Copies a StringRef into a static pool to preserve it.
70 StringRef insertStrRef(StringRef S);
72 } // namespace llvm
74 #endif // LLVM_UTILS_TABLEGEN_COMMON_GLOBALISEL_COMBINERUTILS_H