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