-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CIR] Add attribute visitor for lowering globals (#1318)
This adds a new mlir-tablegen option to generate a .inc file with the complete set of attrdefs defined in a .td file and uses the file generated for CIR attrdefs to create an attr visitor. This visitor is used in the lowering of global variables directly to LLVM IR. The purpose of this change is to align the incubator lowering implementation with the recent upstream changes to make future upstreaming easier, while also fulfilling the upstream request to have the visitor be based on a tablegen created file. The new mlir-tablegen feature will be upstreamed after it is established here. No observable change is intended in the CIR code.
- Loading branch information
1 parent
a07dbdf
commit f7b9151
Showing
6 changed files
with
141 additions
and
98 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
//===- CIRAttrVisitor.h - Visitor for CIR attributes ------------*- 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 defines the CirAttrVisitor interface. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_CLANG_CIR_DIALECT_IR_CIRATTRVISITOR_H | ||
#define LLVM_CLANG_CIR_DIALECT_IR_CIRATTRVISITOR_H | ||
|
||
#include "clang/CIR/Dialect/IR/CIRAttrs.h" | ||
|
||
namespace cir { | ||
|
||
#define DISPATCH(NAME) return getImpl()->visitCir##NAME(cirAttr); | ||
|
||
template <typename ImplClass, typename RetTy> class CirAttrVisitor { | ||
public: | ||
RetTy visit(mlir::Attribute attr) { | ||
#define ATTRDEF(NAME) \ | ||
if (const auto cirAttr = mlir::dyn_cast<cir::NAME>(attr)) \ | ||
DISPATCH(NAME); | ||
#include "clang/CIR/Dialect/IR/CIRAttrDefsList.inc" | ||
llvm_unreachable("unhandled attribute type"); | ||
} | ||
|
||
// If the implementation chooses not to implement a certain visit | ||
// method, fall back to the parent. | ||
#define ATTRDEF(NAME) \ | ||
RetTy visitCir##NAME(NAME cirAttr) { DISPATCH(Attr); } | ||
#include "clang/CIR/Dialect/IR/CIRAttrDefsList.inc" | ||
|
||
RetTy visitCirAttr(mlir::Attribute attr) { return RetTy(); } | ||
|
||
ImplClass *getImpl() { return static_cast<ImplClass *>(this); } | ||
}; | ||
|
||
#undef DISPATCH | ||
|
||
} // namespace cir | ||
|
||
#endif // LLVM_CLANG_CIR_DIALECT_IR_CIRATTRVISITOR_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
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
Oops, something went wrong.