25 std::map<Use *, std::vector<std::vector<ConstantExpr *>>> CEPaths;
35 std::map<
Use *, std::vector<std::vector<ConstantExpr *>>> &CEPaths,
39 for (
Use &U :
I->operands()) {
42 if (!CEPaths.count(&U))
48 if (
auto *Phi = dyn_cast<PHINode>(
I)) {
50 BI = &(*(
BB->getFirstInsertionPt()));
56 auto &Paths = CEPaths[&U];
57 for (
auto &Path : Paths) {
58 for (
auto *CE : Path) {
62 if (!Visited.
count(CE)) {
66 NI = CE->getAsInstruction(BI);
80 assert(NI &&
"Expected an instruction corresponding to constant "
85 II->replaceUsesOfWith(CE, NI);
92 for (
auto Item : Visited)
93 Item.first->removeDeadConstantUsers();
98 std::map<
Use *, std::vector<std::vector<ConstantExpr *>>> &CEPaths) {
99 for (
Use &U :
I->operands()) {
101 auto *CE2 = dyn_cast<ConstantExpr>(U.get());
106 std::vector<std::vector<ConstantExpr *>> Paths;
109 std::vector<ConstantExpr *> Path{CE2};
110 std::vector<std::vector<ConstantExpr *>> Stack{Path};
111 while (!Stack.empty()) {
112 std::vector<ConstantExpr *> TPath = Stack.back();
114 auto *CE3 = TPath.back();
117 Paths.push_back(TPath);
121 for (
auto &UU : CE3->operands()) {
122 if (
auto *CE4 = dyn_cast<ConstantExpr>(UU.get())) {
123 std::vector<ConstantExpr *> NPath(TPath.begin(), TPath.end());
124 NPath.push_back(CE4);
125 Stack.push_back(NPath);