Loading [MathJax]/jax/output/HTML-CSS/config.js
CIRCT 22.0.0git
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Utils.h
Go to the documentation of this file.
1//===- Utils.h - Miscellaneous utilities ----------------------------------===//
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// Miscellaneous utilities for CIRCT that do not fit in with other files.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef CIRCT_SUPPORT_UTILS_H
14#define CIRCT_SUPPORT_UTILS_H
15
16#include "circt/Support/LLVM.h"
17#include "mlir/IR/Operation.h"
18#include "mlir/IR/Value.h"
19#include "llvm/Support/Parallel.h"
20
21namespace circt {
22
23/// Return true if a Value is created "underneath" an operation. This is
24/// frequently useful when negated as that indicates that a Value is defined
25/// "outside" the region of an Operation and that the Operation is thereby
26/// "capturing" the value.
27inline bool isAncestorOfValueOwner(Operation *op, Value value) {
28 return op->isAncestor(value.getParentBlock()->getParentOp());
29}
30
31//===----------------------------------------------------------------------===//
32// Parallel utilities
33//===----------------------------------------------------------------------===//
34
35/// Wrapper for llvm::parallelTransformReduce that performs the transform_reduce
36/// serially when MLIR multi-threading is disabled.
37/// Does not add a ParallelDiagnosticHandler like mlir::parallelFor.
38template <class IterTy, class ResultTy, class ReduceFuncTy,
39 class TransformFuncTy>
40static ResultTy transformReduce(MLIRContext *context, IterTy begin, IterTy end,
41 ResultTy init, ReduceFuncTy reduce,
42 TransformFuncTy transform) {
43 // Parallel when enabled
44 if (context->isMultithreadingEnabled())
45 return llvm::parallelTransformReduce(begin, end, init, reduce, transform);
46
47 // Serial fallback (from llvm::parallelTransformReduce)
48 for (IterTy i = begin; i != end; ++i)
49 init = reduce(std::move(init), transform(*i));
50 return std::move(init);
51}
52
53/// Range wrapper
54template <class RangeTy, class ResultTy, class ReduceFuncTy,
55 class TransformFuncTy>
56static ResultTy transformReduce(MLIRContext *context, RangeTy &&r,
57 ResultTy init, ReduceFuncTy reduce,
58 TransformFuncTy transform) {
59 return transformReduce(context, std::begin(r), std::end(r), init, reduce,
60 transform);
61}
62
63} // namespace circt
64
65#endif // CIRCT_SUPPORT_UTILS_H
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
static ResultTy transformReduce(MLIRContext *context, IterTy begin, IterTy end, ResultTy init, ReduceFuncTy reduce, TransformFuncTy transform)
Wrapper for llvm::parallelTransformReduce that performs the transform_reduce serially when MLIR multi...
Definition Utils.h:40
bool isAncestorOfValueOwner(Operation *op, Value value)
Return true if a Value is created "underneath" an operation.
Definition Utils.h:27