LLVM 24.0.0git
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"
22#include "llvm/IR/ValueHandle.h"
23#include <cstdint>
24
25namespace llvm {
26
27class BasicBlock;
29class DomTreeUpdater;
30class LoopInfo;
31class Value;
32
37
38 DivRemMapKey() = default;
39
40 DivRemMapKey(bool InSignedOp, Value *InDividend, Value *InDivisor)
41 : SignedOp(InSignedOp), Dividend(InDividend), Divisor(InDivisor) {}
42};
43
44template <> struct DenseMapInfo<DivRemMapKey> {
45 static bool isEqual(const DivRemMapKey &Val1, const DivRemMapKey &Val2) {
46 return Val1.SignedOp == Val2.SignedOp && Val1.Dividend == Val2.Dividend &&
47 Val1.Divisor == Val2.Divisor;
48 }
49
50 static unsigned getHashValue(const DivRemMapKey &Val) {
51 return (unsigned)(reinterpret_cast<uintptr_t>(
52 static_cast<Value *>(Val.Dividend)) ^
53 reinterpret_cast<uintptr_t>(
54 static_cast<Value *>(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.
64LLVM_ABI bool
66 const DenseMap<unsigned int, unsigned int> &BypassWidth,
67 DomTreeUpdater *DTU = nullptr, LoopInfo *LI = nullptr,
68 BranchProbabilityInfo *BPI = nullptr);
69
70} // end namespace llvm
71
72#endif // LLVM_TRANSFORMS_UTILS_BYPASSSLOWDIVISION_H
#define LLVM_ABI
Definition Compiler.h:215
This file defines DenseMapInfo traits for DenseMap.
This file defines the DenseMap class.
Value handle that asserts if the Value is deleted.
LLVM Basic Block Representation.
Definition BasicBlock.h:62
Analysis providing branch probability information.
LLVM Value Representation.
Definition Value.h:75
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI bool bypassSlowDivision(BasicBlock *BB, const DenseMap< unsigned int, unsigned int > &BypassWidth, DomTreeUpdater *DTU=nullptr, LoopInfo *LI=nullptr, BranchProbabilityInfo *BPI=nullptr)
This optimization identifies DIV instructions in a BB that can be profitably bypassed and carried out...
static unsigned getHashValue(const DivRemMapKey &Val)
static bool isEqual(const DivRemMapKey &Val1, const DivRemMapKey &Val2)
An information struct used to provide DenseMap with the various necessary components for a given valu...
AssertingVH< Value > Divisor
DivRemMapKey(bool InSignedOp, Value *InDividend, Value *InDivisor)
DivRemMapKey()=default
AssertingVH< Value > Dividend