|
LLVM
10.0.0
|
#include "llvm/Transforms/Scalar/DivRemPairs.h"#include "llvm/ADT/DenseMap.h"#include "llvm/ADT/MapVector.h"#include "llvm/ADT/Statistic.h"#include "llvm/Analysis/GlobalsModRef.h"#include "llvm/Analysis/TargetTransformInfo.h"#include "llvm/IR/Dominators.h"#include "llvm/IR/Function.h"#include "llvm/IR/PatternMatch.h"#include "llvm/InitializePasses.h"#include "llvm/Pass.h"#include "llvm/Support/DebugCounter.h"#include "llvm/Transforms/Scalar.h"#include "llvm/Transforms/Utils/BypassSlowDivision.h"Go to the source code of this file.
Classes | |
| struct | DivRemPairWorklistEntry |
| A thin wrapper to store two values that we matched as div-rem pair. More... | |
Macros | |
| #define | DEBUG_TYPE "div-rem-pairs" |
Typedefs | |
| using | DivRemWorklistTy = SmallVector< DivRemPairWorklistEntry, 4 > |
Functions | |
| STATISTIC (NumPairs, "Number of div/rem pairs") | |
| STATISTIC (NumRecomposed, "Number of instructions recomposed") | |
| STATISTIC (NumHoisted, "Number of instructions hoisted") | |
| STATISTIC (NumDecomposed, "Number of instructions decomposed") | |
| DEBUG_COUNTER (DRPCounter, "div-rem-pairs-transform", "Controls transformations in div-rem-pairs pass") | |
| static llvm::Optional< ExpandedMatch > | matchExpandedRem (Instruction &I) |
| See if we can match: (which is the form we expand into) X - ((X ?/ Y) * Y) which is equivalent to: X ?% Y. More... | |
| static DivRemWorklistTy | getWorklist (Function &F) |
| Find matching pairs of integer div/rem ops (they have the same numerator, denominator, and signedness). More... | |
| static bool | optimizeDivRem (Function &F, const TargetTransformInfo &TTI, const DominatorTree &DT) |
| Find matching pairs of integer div/rem ops (they have the same numerator, denominator, and signedness). More... | |
| INITIALIZE_PASS_BEGIN (DivRemPairsLegacyPass, "div-rem-pairs", "Hoist/decompose integer division and remainder", false, false) INITIALIZE_PASS_END(DivRemPairsLegacyPass | |
Variables | |
| div rem | pairs |
| div rem Hoist decompose integer division and | remainder |
| div rem Hoist decompose integer division and | false |
| #define DEBUG_TYPE "div-rem-pairs" |
Definition at line 32 of file DivRemPairs.cpp.
| using DivRemWorklistTy = SmallVector<DivRemPairWorklistEntry, 4> |
Definition at line 114 of file DivRemPairs.cpp.
| DEBUG_COUNTER | ( | DRPCounter | , |
| "div-rem-pairs-transform" | , | ||
| "Controls transformations in div-rem-pairs pass" | |||
| ) |
|
static |
Find matching pairs of integer div/rem ops (they have the same numerator, denominator, and signedness).
Place those pairs into a worklist for further processing. This indirection is needed because we have to use TrackingVH<> because we will be doing RAUW, and if one of the rem instructions we change happens to be an input to another div/rem in the maps, we'd have problems.
Definition at line 121 of file DivRemPairs.cpp.
References llvm::SmallVectorImpl< T >::emplace_back(), I, llvm::Match, and matchExpandedRem().
Referenced by optimizeDivRem().
| INITIALIZE_PASS_BEGIN | ( | DivRemPairsLegacyPass | , |
| "div-rem-pairs" | , | ||
| "Hoist/decompose integer division and remainder" | , | ||
| false | , | ||
| false | |||
| ) |
Referenced by optimizeDivRem().
|
static |
See if we can match: (which is the form we expand into) X - ((X ?/ Y) * Y) which is equivalent to: X ?% Y.
Definition at line 51 of file DivRemPairs.cpp.
References llvm::Instruction::getOpcode(), I, llvm::PatternMatch::m_c_Mul(), llvm::PatternMatch::m_CombineAnd(), llvm::PatternMatch::m_Deferred(), llvm::PatternMatch::m_IDiv(), llvm::PatternMatch::m_Instruction(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_Sub(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), and llvm::None.
Referenced by getWorklist().
|
static |
Find matching pairs of integer div/rem ops (they have the same numerator, denominator, and signedness).
If they exist in different basic blocks, bring them together by hoisting or replace the common division operation that is implicit in the remainder: X % Y <–> X - ((X / Y) * Y).
We can largely ignore the normal safety and cost constraints on speculation of these ops when we find a matching pair. This is because we are already guaranteed that any exceptions and most cost are already incurred by the first member of the pair.
Note: This transform could be an oddball enhancement to EarlyCSE, GVN, or SimplifyCFG, but it's split off on its own because it's different enough that it doesn't quite match the stated objectives of those passes.
Definition at line 180 of file DivRemPairs.cpp.
References llvm::AnalysisUsage::addPreserved(), llvm::AnalysisUsage::addRequired(), assert(), CreateMul(), llvm::DominatorTree::dominates(), E, llvm::Instruction::eraseFromParent(), F(), llvm::Pass::getAnalysisUsage(), llvm::PassRegistry::getPassRegistry(), getWorklist(), llvm::TargetTransformInfo::hasDivRemOp(), INITIALIZE_PASS_BEGIN(), INITIALIZE_PASS_DEPENDENCY, llvm::initializeDivRemPairsLegacyPassPass(), llvm::Instruction::insertAfter(), llvm::Value::replaceAllUsesWith(), runOnFunction(), llvm::Value::setName(), llvm::AnalysisUsage::setPreservesCFG(), llvm::DebugCounter::shouldExecute(), X, and Y.
Referenced by llvm::DivRemPairsPass::run().
| STATISTIC | ( | NumPairs | , |
| "Number of div/rem pairs" | |||
| ) |
| STATISTIC | ( | NumRecomposed | , |
| "Number of instructions recomposed" | |||
| ) |
| STATISTIC | ( | NumHoisted | , |
| "Number of instructions hoisted" | |||
| ) |
| STATISTIC | ( | NumDecomposed | , |
| "Number of instructions decomposed" | |||
| ) |
| div rem Hoist decompose integer division and false |
Definition at line 354 of file DivRemPairs.cpp.
| div rem pairs |
Definition at line 354 of file DivRemPairs.cpp.
| div rem Hoist decompose integer division and remainder |
Definition at line 354 of file DivRemPairs.cpp.
Referenced by llvm::APInt::abs(), llvm::detail::DoubleAPFloat::getSecond(), KnuthDiv(), and llvm::detail::IEEEFloat::needsCleanup().
1.8.13