using namespace llvm;
-namespace llvm {
+namespace {
struct DivOpInfo {
bool SignedOp;
Value *Dividend;
DivPhiNodes(PHINode *InQuotient, PHINode *InRemainder)
: Quotient(InQuotient), Remainder(InRemainder) {}
};
+}
+namespace llvm {
template<>
struct DenseMapInfo<DivOpInfo> {
static bool isEqual(const DivOpInfo &Val1, const DivOpInfo &Val2) {
// Get instruction operands
Instruction *Instr = J;
DivOpInfo Key(UseSignedOp, Instr->getOperand(0), Instr->getOperand(1));
- DivCacheTy::const_iterator CacheI = PerBBDivCache.find(Key);
+ DivCacheTy::iterator CacheI = PerBBDivCache.find(Key);
if (CacheI == PerBBDivCache.end()) {
// If previous instance does not exist, insert fast div
}
// Replace operation value with previously generated phi node
- DivPhiNodes Value = CacheI->second;
+ DivPhiNodes &Value = CacheI->second;
if (UseDivOp) {
// Replace all uses of div instruction with quotient phi node
J->replaceAllUsesWith(Value.Quotient);
// bypassSlowDivision - This optimization identifies DIV instructions that can
// be profitably bypassed and carried out with a shorter, faster divide.
-bool bypassSlowDivision(Function &F,
- Function::iterator &I,
- const llvm::DenseMap<Type *, Type *> &BypassTypeMap) {
+bool llvm::bypassSlowDivision(Function &F,
+ Function::iterator &I,
+ const DenseMap<unsigned int, unsigned int> &BypassWidths) {
DivCacheTy DivCache;
bool MadeChange = false;
if (!UseDivOp && !UseRemOp)
continue;
- // Continue if div/rem type is not bypassed
- DenseMap<Type *, Type *>::const_iterator BT =
- BypassTypeMap.find(J->getType());
- if (BT == BypassTypeMap.end())
+ // Skip division on vector types, only optimize integer instructions
+ if (!J->getType()->isIntegerTy())
continue;
- IntegerType *BypassType = cast<IntegerType>(BT->second);
- MadeChange |= reuseOrInsertFastDiv(F, I, J, BypassType, UseDivOp,
+ // Get bitwidth of div/rem instruction
+ IntegerType *T = cast<IntegerType>(J->getType());
+ int bitwidth = T->getBitWidth();
+
+ // Continue if bitwidth is not bypassed
+ DenseMap<unsigned int, unsigned int>::const_iterator BI = BypassWidths.find(bitwidth);
+ if (BI == BypassWidths.end())
+ continue;
+
+ // Get type for div/rem instruction with bypass bitwidth
+ IntegerType *BT = IntegerType::get(J->getContext(), BI->second);
+
+ MadeChange |= reuseOrInsertFastDiv(F, I, J, BT, UseDivOp,
UseSignedOp, DivCache);
- MadeChange = true;
}
return MadeChange;