LLVM  14.0.0git
ReplaceConstant.h
Go to the documentation of this file.
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.
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.
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.
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
llvm
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
Instruction.h
Constants.h
llvm::convertConstantExprsToInstructions
void convertConstantExprsToInstructions(Instruction *I, ConstantExpr *CE, SmallPtrSetImpl< Instruction * > *Insts=nullptr)
The given instruction I contains given constant expression CE as one of its operands,...
Definition: ReplaceConstant.cpp:28
I
#define I(x, y, z)
Definition: MD5.cpp:59
llvm::collectConstantExprPaths
void collectConstantExprPaths(Instruction *I, ConstantExpr *CE, std::map< Use *, std::vector< std::vector< ConstantExpr * >>> &CEPaths)
Given an instruction I which uses given constant expression CE as operand, either directly or nested ...
Definition: ReplaceConstant.cpp:78
llvm::createReplacementInstr
Instruction * createReplacementInstr(ConstantExpr *CE, Instruction *Instr)
Create a replacement instruction for constant expression CE and insert it before Instr.
Definition: ReplaceConstant.cpp:22