1//===- PredicateExpanderDag.h - Composable predicate dag lowering ---------===//
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// Shared walker that lowers a composable predicate dag of the form
10//
11// (all_of / any_of / none_of / not <leaf> ...)
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_UTILS_TABLEGEN_BASIC_PREDICATEEXPANDERDAG_H
16#define LLVM_UTILS_TABLEGEN_BASIC_PREDICATEEXPANDERDAG_H
17
18#include "llvm/ADT/STLFunctionalExtras.h"
19
20namespace llvm {
21
22class Init;
23class Record;
24class raw_ostream;
25
26/// Walk a composable predicate dag rooted at \p Val and emit the combined
27/// boolean expression to \p OS.
28///
29/// The structural operators handled are the dags `(not X)`, `(all_of ...)`,
30/// `(any_of ...)` and `(none_of ...)`. Any non-dag operand (and the base leaf)
31/// is delegated to \p EmitLeaf, which emits the leaf test and returns true on
32/// error.
33///
34/// If \p ParenIfBinOp is true, a surrounding pair of parentheses is emitted
35/// when \p Val lowers to a binary (`&&` / `||`) expression. A `(not X)` or
36/// `(none_of ...)` always parenthesizes its operands.
37bool emitPredicateDag(const Record *Owner, const Init &Val, bool ParenIfBinOp,
38 raw_ostream &OS,
39 function_ref<bool(const Init &, raw_ostream &)> EmitLeaf);
40
41} // namespace llvm
42
43#endif // LLVM_UTILS_TABLEGEN_BASIC_PREDICATEEXPANDERDAG_H
44