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