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 <map> 18 #include <vector> 19 20 namespace llvm { 21 22 class ConstantExpr; 23 class Instruction; 24 class Use; 25 template <typename PtrType> class SmallPtrSetImpl; 26 27 /// The given instruction \p I contains given constant expression \p CE as one 28 /// of its operands, possibly nested within constant expression trees. Convert 29 /// all reachable paths from contant expression operands of \p I to \p CE into 30 /// corresponding instructions, insert them before \p I, update operands of \p I 31 /// accordingly, and if required, return all such converted instructions at 32 /// \p Insts. 33 void convertConstantExprsToInstructions( 34 Instruction *I, ConstantExpr *CE, 35 SmallPtrSetImpl<Instruction *> *Insts = nullptr); 36 37 /// The given instruction \p I contains constant expression CE within the 38 /// constant expression trees of it`s constant expression operands, and 39 /// \p CEPaths holds all the reachable paths (to CE) from such constant 40 /// expression trees of \p I. Convert constant expressions within these paths 41 /// into corresponding instructions, insert them before \p I, update operands of 42 /// \p I accordingly, and if required, return all such converted instructions at 43 /// \p Insts. 44 void convertConstantExprsToInstructions( 45 Instruction *I, 46 std::map<Use *, std::vector<std::vector<ConstantExpr *>>> &CEPaths, 47 SmallPtrSetImpl<Instruction *> *Insts = nullptr); 48 49 /// Given an instruction \p I which uses given constant expression \p CE as 50 /// operand, either directly or nested within other constant expressions, return 51 /// all reachable paths from the constant expression operands of \p I to \p CE, 52 /// and return collected paths at \p CEPaths. 53 void collectConstantExprPaths( 54 Instruction *I, ConstantExpr *CE, 55 std::map<Use *, std::vector<std::vector<ConstantExpr *>>> &CEPaths); 56 57 } // end namespace llvm 58 59 #endif // LLVM_IR_REPLACECONSTANT_H 60