Advertisement
kkubak

Untitled

Jan 15th, 2021 (edited)
546
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.14 KB | None | 0 0
  1. Not Working:
  2.  
  3. BB0:
  4.    // %31 = phi i32* [ %.pre.i, %land.lhs.true.cleanup_crit_edge.i ], [ %26, %lor.lhs.false.i ]
  5. BB1:
  6.    // %33 = call i32 (...) @register_trav_edge1(i32* %.pre.i, i32* %31, i32 1, i32 16)
  7.  
  8. Working:
  9.    // %31 = phi i32* [ %.pre.i, %land.lhs.true.cleanup_crit_edge.i ], [ %26, %lor.lhs.false.i ]
  10.    // %33 = call i32 (...) @register_trav_edge1(i32* %.pre.i, i32* %31, i32 1, i32 16)
  11.  
  12.     bool isUsedInPhiInCurrentBB(llvm::Instruction * instr, llvm::PHINode * phi) {
  13.         for (auto &I : *(instr->getParent())) {
  14.             if (llvm::PHINode * bb_phi = dyn_cast<llvm::PHINode>(&I)) {
  15.                 for (int i = 0; i < bb_phi->getNumIncomingValues(); ++i) {
  16.                     if (bb_phi->getIncomingValue(i) == dyn_cast<llvm::Value>(instr)) {
  17.                         phi = bb_phi;
  18.                         return true;
  19.                     }
  20.                 }
  21.             }
  22.             else {
  23.                 break;
  24.             }
  25.         }
  26.  
  27.         return false;
  28.     }
  29.  
  30.     int main() {
  31.         llvm::PHINode * phi_source;
  32.         if (llvm::Instruction * instr = dyn_cast<llvm::Instruction>(gdi.source)) {
  33.             if (!dyn_cast<llvm::PHINode>(gdi.source)) {
  34.                 if (isUsedInPhiInCurrentBB(instr,phi_source)) {
  35.                     gdi.source = dyn_cast<llvm::Value>(phi_source);
  36.                 }
  37.             }
  38.         }
  39.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement