CIRCT 22.0.0git
Loading...
Searching...
No Matches
FoldUtils.h
Go to the documentation of this file.
1//===- FoldUtils.h - Common folder and canonicalizer 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_FOLDUTILS_H
10#define CIRCT_SUPPORT_FOLDUTILS_H
11
12#include "circt/Support/LLVM.h"
13#include "mlir/IR/BuiltinAttributes.h"
14#include "llvm/ADT/APInt.h"
15
16namespace circt {
17
18/// Determine the integer value of a constant operand.
19static inline std::optional<APInt> getConstantInt(Attribute operand) {
20 if (!operand)
21 return {};
22 if (auto attr = dyn_cast<IntegerAttr>(operand))
23 return attr.getValue();
24 return {};
25}
26
27/// Determine whether a constant operand is a zero value.
28static inline bool isConstantZero(Attribute operand) {
29 if (auto cst = getConstantInt(operand))
30 return cst->isZero();
31 return false;
32}
33
34/// Determine whether a constant operand is a one value.
35static inline bool isConstantOne(Attribute operand) {
36 if (auto cst = getConstantInt(operand))
37 return cst->isOne();
38 return false;
39}
40
41} // namespace circt
42
43#endif // CIRCT_SUPPORT_FOLDUTILS_H
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
static bool isConstantZero(Attribute operand)
Determine whether a constant operand is a zero value.
Definition FoldUtils.h:28
static std::optional< APInt > getConstantInt(Attribute operand)
Determine the integer value of a constant operand.
Definition FoldUtils.h:19
static bool isConstantOne(Attribute operand)
Determine whether a constant operand is a one value.
Definition FoldUtils.h:35