Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- PreservedAnalyses LoopDistributePass::run(Function &F,
- FunctionAnalysisManager &AM) {
- // For every block in the function
- for (BasicBlock &BB : F) {
- // For every instruction in the block
- for (Instruction &I : BB) {
- // Print the instruction
- dbgs() << I << "\n";
- // Print the instruction's name (if it has one... Check if it has one with hasName())
- dbgs() << I->getName() << "\n";
- // You can print similar things for BB.
- }
- // Loop through the precessors of BB
- for (BasicBlock *Pred : predecessors(&BB)) {
- dbgs() << Pred->getName() << "\n";
- // ...
- }
- // Similarly
- // for (BasicBlock *Succ : successors(&BB)) ...
- }
- // This is an example of querying an analysis result. Let's not care too much for now...
- LoopInfo &LI = AM.getResult<LoopAnalysis>(F);
- // However, this specific analysis identifies loops. So, you can now loop through the loops in the function
- for (Loop *L : LI) {
- // Print a summary of the loop
- dbgs() << *L;
- // Learn more about loops (in LLVM) here
- // https://llvm.org/docs/LoopTerminology.html
- }
- // You can ignore that for now
- return PreservedAnalysis.none();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement