CIRCT
22.0.0git
Loading...
Searching...
No Matches
include
circt
Support
BuilderUtils.h
Go to the documentation of this file.
1
//===- BuilderUtils.h - Operation builder utilities -------------*- 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_BUILDERUTILS_H
10
#define CIRCT_SUPPORT_BUILDERUTILS_H
11
12
#include <variant>
13
14
#include "
circt/Support/LLVM.h
"
15
#include "mlir/IR/BuiltinOps.h"
16
#include "mlir/IR/ImplicitLocOpBuilder.h"
17
#include "llvm/ADT/StringSet.h"
18
#include "llvm/ADT/TypeSwitch.h"
19
20
namespace
circt
{
21
22
/// A helper union that can represent a `StringAttr`, `StringRef`, or `Twine`.
23
/// It is intended to be used as arguments to an op's `build` function. This
24
/// allows a single builder to accept any flavor value for a string attribute.
25
/// The `get` function can then be used to obtain a `StringAttr` from any of the
26
/// possible variants `StringAttrOrRef` can take.
27
class
StringAttrOrRef
{
28
std::variant<StringAttr, StringRef, Twine, const char *>
value
;
29
30
public
:
31
StringAttrOrRef
() :
value
() {}
32
StringAttrOrRef
(StringAttr attr) :
value
(attr) {}
33
StringAttrOrRef
(
const
StringRef &str) :
value
(str) {}
34
StringAttrOrRef
(
const
char
*ptr) :
value
(ptr) {}
35
StringAttrOrRef
(
const
std::string &str) :
value
(StringRef(str)) {}
36
StringAttrOrRef
(
const
Twine &twine) :
value
(twine) {}
37
38
/// Return the represented string as a `StringAttr`.
39
StringAttr
get
(MLIRContext *
context
)
const
{
40
if
(
auto
*attr = std::get_if<StringAttr>(&
value
))
41
return
*attr;
42
if
(
auto
*ref = std::get_if<StringRef>(&
value
))
43
return
StringAttr::get(
context
, *ref);
44
if
(
auto
*twine = std::get_if<Twine>(&
value
))
45
return
StringAttr::get(
context
, *twine);
46
if
(
auto
*ptr = std::get_if<const char *>(&
value
))
47
return
StringAttr::get(
context
, *ptr);
48
return
StringAttr{};
49
}
50
};
51
52
}
// namespace circt
53
54
#endif
// CIRCT_SUPPORT_BUILDERUTILS_H
context
static std::unique_ptr< Context > context
Definition
DpiEntryPoints.cpp:37
LLVM.h
circt::StringAttrOrRef
A helper union that can represent a StringAttr, StringRef, or Twine.
Definition
BuilderUtils.h:27
circt::StringAttrOrRef::get
StringAttr get(MLIRContext *context) const
Return the represented string as a StringAttr.
Definition
BuilderUtils.h:39
circt::StringAttrOrRef::value
std::variant< StringAttr, StringRef, Twine, const char * > value
Definition
BuilderUtils.h:28
circt::StringAttrOrRef::StringAttrOrRef
StringAttrOrRef(const std::string &str)
Definition
BuilderUtils.h:35
circt::StringAttrOrRef::StringAttrOrRef
StringAttrOrRef(const char *ptr)
Definition
BuilderUtils.h:34
circt::StringAttrOrRef::StringAttrOrRef
StringAttrOrRef()
Definition
BuilderUtils.h:31
circt::StringAttrOrRef::StringAttrOrRef
StringAttrOrRef(StringAttr attr)
Definition
BuilderUtils.h:32
circt::StringAttrOrRef::StringAttrOrRef
StringAttrOrRef(const StringRef &str)
Definition
BuilderUtils.h:33
circt::StringAttrOrRef::StringAttrOrRef
StringAttrOrRef(const Twine &twine)
Definition
BuilderUtils.h:36
circt
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Definition
DebugAnalysis.h:21
Generated on Wed Dec 17 2025 00:08:53 for CIRCT by
1.9.8