1 //===- CombinerUtils.h ----------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
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"
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
)
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
))
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
,
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
)
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
,
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
))
69 /// Copies a StringRef into a static pool to preserve it.
70 StringRef
insertStrRef(StringRef S
);
74 #endif // LLVM_UTILS_TABLEGEN_COMMON_GLOBALISEL_COMBINERUTILS_H