MLIR  20.0.0git
Constraint.h
Go to the documentation of this file.
1 //===- Constraint.h - MLIR PDLL ODS Constraints -----------------*- C++ -*-===//
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 // This file contains a PDLL description of ODS constraints. These are used to
10 // support the import of constraints defined outside of PDLL.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef MLIR_TOOLS_PDLL_ODS_CONSTRAINT_H_
15 #define MLIR_TOOLS_PDLL_ODS_CONSTRAINT_H_
16 
17 #include <string>
18 
19 #include "mlir/Support/LLVM.h"
20 #include "llvm/ADT/SmallVector.h"
21 #include "llvm/ADT/StringMap.h"
22 
23 namespace mlir {
24 namespace pdll {
25 namespace ods {
26 
27 //===----------------------------------------------------------------------===//
28 // Constraint
29 //===----------------------------------------------------------------------===//
30 
31 /// This class represents a generic ODS constraint.
32 class Constraint {
33 public:
34  /// Return the unique name of this constraint.
35  StringRef getName() const { return name; }
36 
37  /// Return the demangled name of this constraint. This tries to strip out bits
38  /// of the name that are purely for uniquing, and show the underlying name. As
39  /// such, this name does guarantee uniqueness and should only be used for
40  /// logging or other lossy friendly "pretty" output.
41  StringRef getDemangledName() const;
42 
43  /// Return the summary of this constraint.
44  StringRef getSummary() const { return summary; }
45 
46 protected:
47  Constraint(StringRef name, StringRef summary)
48  : name(name.str()), summary(summary.str()) {}
49  Constraint(const Constraint &) = delete;
50 
51 private:
52  /// The name of the constraint.
53  std::string name;
54  /// A summary of the constraint.
55  std::string summary;
56 };
57 
58 //===----------------------------------------------------------------------===//
59 // AttributeConstraint
60 //===----------------------------------------------------------------------===//
61 
62 /// This class represents a generic ODS Attribute constraint.
64 public:
65  /// Return the name of the underlying c++ class of this constraint.
66  StringRef getCppClass() const { return cppClassName; }
67 
68 private:
69  AttributeConstraint(StringRef name, StringRef summary, StringRef cppClassName)
70  : Constraint(name, summary), cppClassName(cppClassName.str()) {}
71 
72  /// The c++ class of the constraint.
73  std::string cppClassName;
74 
75  /// Allow access to the constructor.
76  friend class Context;
77 };
78 
79 //===----------------------------------------------------------------------===//
80 // TypeConstraint
81 //===----------------------------------------------------------------------===//
82 
83 /// This class represents a generic ODS Type constraint.
84 class TypeConstraint : public Constraint {
85 public:
86  /// Return the name of the underlying c++ class of this constraint.
87  StringRef getCppClass() const { return cppClassName; }
88 
89 private:
90  TypeConstraint(StringRef name, StringRef summary, StringRef cppClassName)
91  : Constraint(name, summary), cppClassName(cppClassName.str()) {}
92 
93  /// The c++ class of the constraint.
94  std::string cppClassName;
95 
96  /// Allow access to the constructor.
97  friend class Context;
98 };
99 
100 } // namespace ods
101 } // namespace pdll
102 } // namespace mlir
103 
104 #endif // MLIR_TOOLS_PDLL_ODS_CONSTRAINT_H_
This class represents a generic ODS Attribute constraint.
Definition: Constraint.h:63
StringRef getCppClass() const
Return the name of the underlying c++ class of this constraint.
Definition: Constraint.h:66
This class represents a generic ODS constraint.
Definition: Constraint.h:32
Constraint(const Constraint &)=delete
StringRef getDemangledName() const
Return the demangled name of this constraint.
Definition: Constraint.cpp:18
StringRef getSummary() const
Return the summary of this constraint.
Definition: Constraint.h:44
StringRef getName() const
Return the unique name of this constraint.
Definition: Constraint.h:35
Constraint(StringRef name, StringRef summary)
Definition: Constraint.h:47
This class contains all of the registered ODS operation classes.
Definition: Context.h:32
This class represents a generic ODS Type constraint.
Definition: Constraint.h:84
StringRef getCppClass() const
Return the name of the underlying c++ class of this constraint.
Definition: Constraint.h:87
Include the generated interface declarations.