My Project
Constraint.h
Go to the documentation of this file.
1 //===- Constraint.h - Constraint class --------------------------*- C++ -*-===//
2 //
3 // Part of the MLIR 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 // Constraint wrapper to simplify using TableGen Record for constraints.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef MLIR_TABLEGEN_CONSTRAINT_H_
14 #define MLIR_TABLEGEN_CONSTRAINT_H_
15 
16 #include "mlir/Support/LLVM.h"
18 #include "llvm/ADT/SmallVector.h"
19 #include "llvm/ADT/StringRef.h"
20 
21 namespace llvm {
22 class Record;
23 } // end namespace llvm
24 
25 namespace mlir {
26 namespace tblgen {
27 
28 // Wrapper class with helper methods for accessing Constraint defined in
29 // TableGen.
30 class Constraint {
31 public:
32  Constraint(const llvm::Record *record);
33 
34  bool operator==(const Constraint &that) { return def == that.def; }
35  bool operator!=(const Constraint &that) { return def != that.def; }
36 
37  // Returns the predicate for this constraint.
38  Pred getPredicate() const;
39 
40  // Returns the condition template that can be used to check if a type or
41  // attribute satisfies this constraint. The template may contain "{0}" that
42  // must be substituted with an expression returning an mlir::Type or
43  // mlir::Attribute.
44  std::string getConditionTemplate() const;
45 
46  // Returns the user-readable description of this constraint. If the
47  // description is not provided, returns the TableGen def name.
48  StringRef getDescription() const;
49 
50  // Constraint kind
51  enum Kind { CK_Attr, CK_Region, CK_Type, CK_Uncategorized };
52 
53  Kind getKind() const { return kind; }
54 
55 protected:
56  Constraint(Kind kind, const llvm::Record *record);
57 
58  // The TableGen definition of this constraint.
59  const llvm::Record *def;
60 
61 private:
62  // What kind of constraint this is.
63  Kind kind;
64 };
65 
66 // An constraint and the concrete entities to place the constraint on.
68  AppliedConstraint(Constraint &&constraint, StringRef self,
69  std::vector<std::string> &&entities);
70 
72  // The symbol to replace `$_self` special placeholder in the constraint.
73  std::string self;
74  // The symbols to replace `$N` positional placeholders in the constraint.
75  std::vector<std::string> entities;
76 };
77 
78 } // end namespace tblgen
79 } // end namespace mlir
80 
81 #endif // MLIR_TABLEGEN_CONSTRAINT_H_
Definition: InferTypeOpInterface.cpp:20
Definition: Constraint.h:67
Definition: PassRegistry.cpp:413
bool operator!=(const Constraint &that)
Definition: Constraint.h:35
Definition: Constraint.h:30
Definition: Predicate.h:33
Constraint constraint
Definition: Constraint.h:71
Kind
Definition: Constraint.h:51
std::vector< std::string > entities
Definition: Constraint.h:75
const llvm::Record * def
Definition: Constraint.h:59
bool operator==(const Constraint &that)
Definition: Constraint.h:34
Kind getKind() const
Definition: Constraint.h:53