LLVM  9.0.0svn
BypassSlowDivision.h
Go to the documentation of this file.
1 //===- llvm/Transforms/Utils/BypassSlowDivision.h ---------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file contains an optimization for div and rem on architectures that
10 // execute short instructions significantly faster than longer instructions.
11 // For example, on Intel Atom 32-bit divides are slow enough that during
12 // runtime it is profitable to check the value of the operands, and if they are
13 // positive and less than 256 use an unsigned 8-bit divide.
14 //
15 //===----------------------------------------------------------------------===//
16 
17 #ifndef LLVM_TRANSFORMS_UTILS_BYPASSSLOWDIVISION_H
18 #define LLVM_TRANSFORMS_UTILS_BYPASSSLOWDIVISION_H
19 
20 #include "llvm/ADT/DenseMap.h"
21 #include "llvm/ADT/DenseMapInfo.h"
22 #include <cstdint>
23 
24 namespace llvm {
25 
26 class BasicBlock;
27 class Value;
28 
29 struct DivRemMapKey {
30  bool SignedOp;
33 
34  DivRemMapKey(bool InSignedOp, Value *InDividend, Value *InDivisor)
35  : SignedOp(InSignedOp), Dividend(InDividend), Divisor(InDivisor) {}
36 };
37 
38 template <> struct DenseMapInfo<DivRemMapKey> {
39  static bool isEqual(const DivRemMapKey &Val1, const DivRemMapKey &Val2) {
40  return Val1.SignedOp == Val2.SignedOp && Val1.Dividend == Val2.Dividend &&
41  Val1.Divisor == Val2.Divisor;
42  }
43 
45  return DivRemMapKey(false, nullptr, nullptr);
46  }
47 
49  return DivRemMapKey(true, nullptr, nullptr);
50  }
51 
52  static unsigned getHashValue(const DivRemMapKey &Val) {
53  return (unsigned)(reinterpret_cast<uintptr_t>(Val.Dividend) ^
54  reinterpret_cast<uintptr_t>(Val.Divisor)) ^
55  (unsigned)Val.SignedOp;
56  }
57 };
58 
59 /// This optimization identifies DIV instructions in a BB that can be
60 /// profitably bypassed and carried out with a shorter, faster divide.
61 ///
62 /// This optimization may add basic blocks immediately after BB; for obvious
63 /// reasons, you shouldn't pass those blocks to bypassSlowDivision.
65  BasicBlock *BB, const DenseMap<unsigned int, unsigned int> &BypassWidth);
66 
67 } // end namespace llvm
68 
69 #endif // LLVM_TRANSFORMS_UTILS_BYPASSSLOWDIVISION_H
This class represents lattice values for constants.
Definition: AllocatorList.h:23
Various leaf nodes.
Definition: ISDOpcodes.h:59
bool bypassSlowDivision(BasicBlock *BB, const DenseMap< unsigned int, unsigned int > &BypassWidth)
This optimization identifies DIV instructions in a BB that can be profitably bypassed and carried out...
LLVM Basic Block Representation.
Definition: BasicBlock.h:57
static unsigned getHashValue(const DivRemMapKey &Val)
static bool isEqual(const DivRemMapKey &Val1, const DivRemMapKey &Val2)
DivRemMapKey(bool InSignedOp, Value *InDividend, Value *InDivisor)
LLVM Value Representation.
Definition: Value.h:72