//===- LoopUnrollAnalyzer.cpp - Unrolling Effect Estimation -----*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // This file implements UnrolledInstAnalyzer class. It's used for predicting // potential effects that loop unrolling might have, such as enabling constant // propagation and other optimizations. // //===----------------------------------------------------------------------===// #include "llvm/Analysis/LoopUnrollAnalyzer.h" #include "llvm/Analysis/ConstantFolding.h" #include "llvm/Analysis/InstructionSimplify.h" #include "llvm/Analysis/LoopInfo.h" #include "llvm/Analysis/ScalarEvolutionExpressions.h" #include "llvm/IR/Operator.h" usingnamespacellvm; /// Try to simplify instruction \param I using its SCEV expression. /// /// The idea is that some AddRec expressions become constants, which then /// could trigger folding of other instructions. However, that only happens /// for expressions whose start value is also constant, which isn't always the /// case. In another common and important case the start value is just some /// address (i.e. SCEVUnknown) - in this case we compute the offset and save /// it along with the base address instead. bool UnrolledInstAnalyzer::simplifyInstWithSCEV(Instruction *I) { … } /// Try to simplify binary operator I. /// /// TODO: Probably it's worth to hoist the code for estimating the /// simplifications effects to a separate class, since we have a very similar /// code in InlineCost already. bool UnrolledInstAnalyzer::visitBinaryOperator(BinaryOperator &I) { … } /// Try to fold load I. bool UnrolledInstAnalyzer::visitLoad(LoadInst &I) { … } /// Try to simplify cast instruction. bool UnrolledInstAnalyzer::visitCastInst(CastInst &I) { … } /// Try to simplify cmp instruction. bool UnrolledInstAnalyzer::visitCmpInst(CmpInst &I) { … } bool UnrolledInstAnalyzer::visitPHINode(PHINode &PN) { … } bool UnrolledInstAnalyzer::visitInstruction(Instruction &I) { … }