Advertisement
Guest User

Untitled

a guest
Jan 19th, 2021
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.24 KB | None | 0 0
  1. PreservedAnalyses LoopDistributePass::run(Function &F,
  2.                                           FunctionAnalysisManager &AM) {
  3.  
  4.   // For every block in the function
  5.   for (BasicBlock &BB : F) {
  6.     // For every instruction in the block
  7.     for (Instruction &I : BB) {
  8.  
  9.       // Print the instruction
  10.       dbgs() << I << "\n";
  11.       // Print the instruction's name (if it has one... Check if it has one with hasName())
  12.       dbgs() << I->getName() << "\n";
  13.  
  14.       // You can print similar things for BB.
  15.     }
  16.  
  17.     // Loop through the precessors of BB
  18.     for (BasicBlock *Pred : predecessors(&BB)) {
  19.       dbgs() << Pred->getName() << "\n";
  20.       // ...
  21.     }
  22.     // Similarly
  23.     // for (BasicBlock *Succ : successors(&BB)) ...
  24.   }
  25.  
  26.   // This is an example of querying an analysis result. Let's not care too much for now...
  27.   LoopInfo &LI = AM.getResult<LoopAnalysis>(F);
  28.  
  29.   // However, this specific analysis identifies loops. So, you can now loop through the loops in the function
  30.   for (Loop *L : LI) {
  31.     // Print a summary of the loop
  32.     dbgs() << *L;
  33.     // Learn more about loops (in LLVM) here
  34.     // https://llvm.org/docs/LoopTerminology.html
  35.   }
  36.  
  37.   // You can ignore that for now
  38.   return PreservedAnalysis.none();
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement