Loading [MathJax]/extensions/tex2jax.js
CIRCT 21.0.0git
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Naming.h
Go to the documentation of this file.
1//===- Naming.h - Utilities for handling names ------------------*- 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#ifndef CIRCT_SUPPORT_NAMING_H
10#define CIRCT_SUPPORT_NAMING_H
11
12#include "circt/Support/LLVM.h"
13#include "mlir/IR/PatternMatch.h"
14
15namespace circt {
16
17/// Return true if this is a possibly useless temporary name.
18/// This method is FIRRTL-centric, dropping useless temporaries.
19bool isUselessName(StringRef name);
20
21/// Choose a good name for an item from two options.
22StringRef chooseName(StringRef a, StringRef b);
23
24/// Choose a good name for an item from two options.
25StringAttr chooseName(StringAttr a, StringAttr b);
26
27/// Choose the better name between two ops. Picks the "name" attribute as first
28/// preference, using "sv.namehint" as an alternative.
29StringAttr chooseName(Operation *a, Operation *b);
30
31/// A wrapper of `PatternRewriter::replaceOp` to propagate "sv.namehint"
32/// attribute. If a replaced op has a "sv.namehint" attribute, this function
33/// propagates the name to the new value.
34void replaceOpAndCopyNamehint(PatternRewriter &rewriter, Operation *op,
35 Value newValue);
36
37/// A wrapper of `PatternRewriter::replaceOpWithNewOp` to propagate
38/// "sv.namehint" attribute. If a replaced op has a "sv.namehint" attribute,
39/// this function propagates the name to the new value.
40template <typename OpTy, typename... Args>
41static OpTy replaceOpWithNewOpAndCopyNamehint(PatternRewriter &rewriter,
42 Operation *op, Args &&...args) {
43 auto name = op->getAttrOfType<StringAttr>("sv.namehint");
44 auto newOp =
45 rewriter.replaceOpWithNewOp<OpTy>(op, std::forward<Args>(args)...);
46 if (name && !newOp->hasAttr("sv.namehint"))
47 rewriter.modifyOpInPlace(newOp,
48 [&] { newOp->setAttr("sv.namehint", name); });
49
50 return newOp;
51}
52
53} // namespace circt
54
55#endif // CIRCT_SUPPORT_NAMING_H
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
static OpTy replaceOpWithNewOpAndCopyNamehint(PatternRewriter &rewriter, Operation *op, Args &&...args)
A wrapper of PatternRewriter::replaceOpWithNewOp to propagate "sv.namehint" attribute.
Definition Naming.h:41
void replaceOpAndCopyNamehint(PatternRewriter &rewriter, Operation *op, Value newValue)
A wrapper of PatternRewriter::replaceOp to propagate "sv.namehint" attribute.
Definition Naming.cpp:73
bool isUselessName(StringRef name)
Return true if this is a possibly useless temporary name.
Definition Naming.cpp:16
StringRef chooseName(StringRef a, StringRef b)
Choose a good name for an item from two options.
Definition Naming.cpp:47