xref: /freebsd/contrib/llvm-project/llvm/include/llvm/IR/ReplaceConstant.h (revision 349cc55c9796c4596a5b9904cd3281af295f878f)
1 //===- ReplaceConstant.h - Replacing LLVM constant expressions --*- 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 // This file declares the utility function for replacing LLVM constant
10 // expressions by instructions.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_IR_REPLACECONSTANT_H
15 #define LLVM_IR_REPLACECONSTANT_H
16 
17 #include "llvm/IR/Constants.h"
18 #include "llvm/IR/Instruction.h"
19 #include <map>
20 #include <vector>
21 
22 namespace llvm {
23 
24 /// The given instruction \p I contains given constant expression \p CE as one
25 /// of its operands, possibly nested within constant expression trees. Convert
26 /// all reachable paths from contant expression operands of \p I to \p CE into
27 /// corresponding instructions, insert them before \p I, update operands of \p I
28 /// accordingly, and if required, return all such converted instructions at
29 /// \p Insts.
30 void convertConstantExprsToInstructions(
31     Instruction *I, ConstantExpr *CE,
32     SmallPtrSetImpl<Instruction *> *Insts = nullptr);
33 
34 /// The given instruction \p I contains constant expression CE within the
35 /// constant expression trees of it`s constant expression operands, and
36 /// \p CEPaths holds all the reachable paths (to CE) from such constant
37 /// expression trees of \p I. Convert constant expressions within these paths
38 /// into corresponding instructions, insert them before \p I, update operands of
39 /// \p I accordingly, and if required, return all such converted instructions at
40 /// \p Insts.
41 void convertConstantExprsToInstructions(
42     Instruction *I,
43     std::map<Use *, std::vector<std::vector<ConstantExpr *>>> &CEPaths,
44     SmallPtrSetImpl<Instruction *> *Insts = nullptr);
45 
46 /// Given an instruction \p I which uses given constant expression \p CE as
47 /// operand, either directly or nested within other constant expressions, return
48 /// all reachable paths from the constant expression operands of \p I to \p CE,
49 /// and return collected paths at \p CEPaths.
50 void collectConstantExprPaths(
51     Instruction *I, ConstantExpr *CE,
52     std::map<Use *, std::vector<std::vector<ConstantExpr *>>> &CEPaths);
53 
54 } // end namespace llvm
55 
56 #endif // LLVM_IR_REPLACECONSTANT_H
57