Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PDLL] Add support for tablegen includes and importing ODS information
This commit adds support for processing tablegen include files, and importing various information from ODS. This includes operations, attribute+type constraints, attribute/operation/type interfaces, etc. This will allow for much more robust tooling, and also allows for referencing ODS constructs directly within PDLL (imported interfaces can be used as constraints, operation result names can be used for member access, etc). Differential Revision: https://reviews.llvm.org/D119900
- Loading branch information
Showing
30 changed files
with
1,312 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
//===- Constraint.h - MLIR PDLL ODS Constraints -----------------*- C++ -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This file contains a PDLL description of ODS constraints. These are used to | ||
// support the import of constraints defined outside of PDLL. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef MLIR_TOOLS_PDLL_ODS_CONSTRAINT_H_ | ||
#define MLIR_TOOLS_PDLL_ODS_CONSTRAINT_H_ | ||
|
||
#include <string> | ||
|
||
#include "mlir/Support/LLVM.h" | ||
#include "llvm/ADT/SmallVector.h" | ||
#include "llvm/ADT/StringMap.h" | ||
|
||
namespace mlir { | ||
namespace pdll { | ||
namespace ods { | ||
|
||
//===----------------------------------------------------------------------===// | ||
// Constraint | ||
//===----------------------------------------------------------------------===// | ||
|
||
/// This class represents a generic ODS constraint. | ||
class Constraint { | ||
public: | ||
/// Return the name of this constraint. | ||
StringRef getName() const { return name; } | ||
|
||
/// Return the summary of this constraint. | ||
StringRef getSummary() const { return summary; } | ||
|
||
protected: | ||
Constraint(StringRef name, StringRef summary) | ||
: name(name.str()), summary(summary.str()) {} | ||
Constraint(const Constraint &) = delete; | ||
|
||
private: | ||
/// The name of the constraint. | ||
std::string name; | ||
/// A summary of the constraint. | ||
std::string summary; | ||
}; | ||
|
||
//===----------------------------------------------------------------------===// | ||
// AttributeConstraint | ||
//===----------------------------------------------------------------------===// | ||
|
||
/// This class represents a generic ODS Attribute constraint. | ||
class AttributeConstraint : public Constraint { | ||
public: | ||
/// Return the name of the underlying c++ class of this constraint. | ||
StringRef getCppClass() const { return cppClassName; } | ||
|
||
private: | ||
AttributeConstraint(StringRef name, StringRef summary, StringRef cppClassName) | ||
: Constraint(name, summary), cppClassName(cppClassName.str()) {} | ||
|
||
/// The c++ class of the constraint. | ||
std::string cppClassName; | ||
|
||
/// Allow access to the constructor. | ||
friend class Context; | ||
}; | ||
|
||
//===----------------------------------------------------------------------===// | ||
// TypeConstraint | ||
//===----------------------------------------------------------------------===// | ||
|
||
/// This class represents a generic ODS Type constraint. | ||
class TypeConstraint : public Constraint { | ||
public: | ||
/// Return the name of the underlying c++ class of this constraint. | ||
StringRef getCppClass() const { return cppClassName; } | ||
|
||
private: | ||
TypeConstraint(StringRef name, StringRef summary, StringRef cppClassName) | ||
: Constraint(name, summary), cppClassName(cppClassName.str()) {} | ||
|
||
/// The c++ class of the constraint. | ||
std::string cppClassName; | ||
|
||
/// Allow access to the constructor. | ||
friend class Context; | ||
}; | ||
|
||
} // namespace ods | ||
} // namespace pdll | ||
} // namespace mlir | ||
|
||
#endif // MLIR_TOOLS_PDLL_ODS_CONSTRAINT_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
//===- Context.h - MLIR PDLL ODS Context ------------------------*- C++ -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef MLIR_TOOLS_PDLL_ODS_CONTEXT_H_ | ||
#define MLIR_TOOLS_PDLL_ODS_CONTEXT_H_ | ||
|
||
#include <string> | ||
|
||
#include "mlir/Support/LLVM.h" | ||
#include "llvm/ADT/STLExtras.h" | ||
#include "llvm/ADT/SmallVector.h" | ||
#include "llvm/ADT/StringMap.h" | ||
|
||
namespace llvm { | ||
class SMLoc; | ||
} // namespace llvm | ||
|
||
namespace mlir { | ||
namespace pdll { | ||
namespace ods { | ||
class AttributeConstraint; | ||
class Dialect; | ||
class Operation; | ||
class TypeConstraint; | ||
|
||
/// This class contains all of the registered ODS operation classes. | ||
class Context { | ||
public: | ||
Context(); | ||
~Context(); | ||
|
||
/// Insert a new attribute constraint with the context. Returns the inserted | ||
/// constraint, or a previously inserted constraint with the same name. | ||
const AttributeConstraint &insertAttributeConstraint(StringRef name, | ||
StringRef summary, | ||
StringRef cppClass); | ||
|
||
/// Insert a new type constraint with the context. Returns the inserted | ||
/// constraint, or a previously inserted constraint with the same name. | ||
const TypeConstraint &insertTypeConstraint(StringRef name, StringRef summary, | ||
StringRef cppClass); | ||
|
||
/// Insert a new dialect with the context. Returns the inserted dialect, or a | ||
/// previously inserted dialect with the same name. | ||
Dialect &insertDialect(StringRef name); | ||
|
||
/// Lookup a dialect registered with the given name, or null if no dialect | ||
/// with that name was inserted. | ||
const Dialect *lookupDialect(StringRef name) const; | ||
|
||
/// Insert a new operation with the context. Returns the inserted operation, | ||
/// and a boolean indicating if the operation newly inserted (false if the | ||
/// operation already existed). | ||
std::pair<Operation *, bool> | ||
insertOperation(StringRef name, StringRef summary, StringRef desc, SMLoc loc); | ||
|
||
/// Lookup an operation registered with the given name, or null if no | ||
/// operation with that name is registered. | ||
const Operation *lookupOperation(StringRef name) const; | ||
|
||
/// Print the contents of this context to the provided stream. | ||
void print(raw_ostream &os) const; | ||
|
||
private: | ||
llvm::StringMap<std::unique_ptr<AttributeConstraint>> attributeConstraints; | ||
llvm::StringMap<std::unique_ptr<Dialect>> dialects; | ||
llvm::StringMap<std::unique_ptr<TypeConstraint>> typeConstraints; | ||
}; | ||
} // namespace ods | ||
} // namespace pdll | ||
} // namespace mlir | ||
|
||
#endif // MLIR_PDL_pdll_ODS_CONTEXT_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
//===- Dialect.h - PDLL ODS Dialect -----------------------------*- C++ -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef MLIR_TOOLS_PDLL_ODS_DIALECT_H_ | ||
#define MLIR_TOOLS_PDLL_ODS_DIALECT_H_ | ||
|
||
#include <string> | ||
|
||
#include "mlir/Support/LLVM.h" | ||
#include "llvm/ADT/STLExtras.h" | ||
#include "llvm/ADT/SmallVector.h" | ||
#include "llvm/ADT/StringMap.h" | ||
|
||
namespace mlir { | ||
namespace pdll { | ||
namespace ods { | ||
class Operation; | ||
|
||
/// This class represents an ODS dialect, and contains information on the | ||
/// constructs held within the dialect. | ||
class Dialect { | ||
public: | ||
~Dialect(); | ||
|
||
/// Return the name of this dialect. | ||
StringRef getName() const { return name; } | ||
|
||
/// Insert a new operation with the dialect. Returns the inserted operation, | ||
/// and a boolean indicating if the operation newly inserted (false if the | ||
/// operation already existed). | ||
std::pair<Operation *, bool> | ||
insertOperation(StringRef name, StringRef summary, StringRef desc, SMLoc loc); | ||
|
||
/// Lookup an operation registered with the given name, or null if no | ||
/// operation with that name is registered. | ||
Operation *lookupOperation(StringRef name) const; | ||
|
||
/// Return a map of all of the operations registered to this dialect. | ||
const llvm::StringMap<std::unique_ptr<Operation>> &getOperations() const { | ||
return operations; | ||
} | ||
|
||
private: | ||
explicit Dialect(StringRef name); | ||
|
||
/// The name of the dialect. | ||
std::string name; | ||
|
||
/// The operations defined by the dialect. | ||
llvm::StringMap<std::unique_ptr<Operation>> operations; | ||
|
||
/// Allow access to the constructor. | ||
friend class Context; | ||
}; | ||
} // namespace ods | ||
} // namespace pdll | ||
} // namespace mlir | ||
|
||
#endif // MLIR_TOOLS_PDLL_ODS_DIALECT_H_ |
Oops, something went wrong.