ã¿ã¤ãã«ã®ã¨ããã§ãï¼ãã誰ãLLVM IRã§æ³£ããªããããªä¸çãä½ãã®ã夢ã§ãï¼
LLVM IRã«ã¯å¤ããã¤(Legacy Pass Manager)ã¨æ°ãããã¤(New Pass Manager)ãããã¾ããï¼æ¬è¨äºã¯æ°ãããã¤åãã§ãï¼
é¢æ°å ã®ã«ã¼ããæ½åºãã
ã¾ãLoopInfo
ãåã£ã¦ããã¤ãã¬ã¼ã¿ã使ã£ã¦ã«ã¼ã(Loop
ã¯ã©ã¹)ãåãåºãã¾ãï¼ä¸çªå¤å´ã®ã«ã¼ãã®ã¿æ½åºã§ãã¾ãï¼
ModulePass::run(Module& M, ModuleAnalysisManager& MAM) { FunctionAnalysisManager &FAM = MAM.getResult<FunctionAnalysisManagerModuleProxy>(M).getManager(); for (auto &F : M) { if (!F.isDeclaration()) { LoopInfo &li = FAM.getResult<LoopAnalysis>(F); for (LoopInfo::iterator i = li.begin(), e = li.end(); i != e; i++) { // *i 㧠Loop* ãåãã } } } }
ã«ã¼ãå ã«ã¼ããåã
// Loop *loop; const std::vector<Loop*> &subloops = loop->getSubLoops();
ã«ã¼ãã®è¦ªã«ã¼ããåã
ä¸çªå¤ã®ã«ã¼ãã ã£ãå ´ånullptrãè¿ãã¾ãï¼
// Loop *loop; Loop *parent = loop->getParentLoop();
ã«ã¼ãå ã®å½ä»¤åãåã
// Loop *loop; for (Loop::block_iterator bb = loop->block_begin(); bb != loop->block_end(); bb++) { BasicBlock *BB = *bb; for (auto &I: *BB) { // I 㯠Instruction& } }
ãã®ã«ã¼ãå ã«å±ããå ¨ã¦ã®BasicBlockãåã
// Loop *loop; for (Loop::block_iterator bb = loop->block_begin(); bb != loop->block_end(); bb++) { BasicBlock *BB = *bb; if (loop->contains(BB)) { // BB 㯠loop ã«å±ãã } }
ã«ã¼ãã«ããªããããä»ãã
hoistingãªã©ã«æç¨ã§ãï¼
// Loop *loop; BasicBlock *newBB = InsertPreheaderForLoop(loop, nullptr, nullptr, nullptr, false);
ä»ããããªãããã«å½ä»¤ãæ¿å
¥ããéã¯ï¼IRBuilder
ãå©ç¨ãã¾ã
IRBuilder<> IRB(&newBB->back());