LCOV - code coverage report
Current view: top level - include/llvm/Transforms/Utils - BypassSlowDivision.h (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 8 8 100.0 %
Date: 2017-09-14 15:23:50 Functions: 0 0 -
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===- llvm/Transforms/Utils/BypassSlowDivision.h --------------*- C++ -*-===//
       2             : //
       3             : //                     The LLVM Compiler Infrastructure
       4             : //
       5             : // This file is distributed under the University of Illinois Open Source
       6             : // License. See LICENSE.TXT for details.
       7             : //
       8             : //===----------------------------------------------------------------------===//
       9             : //
      10             : // This file contains an optimization for div and rem on architectures that
      11             : // execute short instructions significantly faster than longer instructions.
      12             : // For example, on Intel Atom 32-bit divides are slow enough that during
      13             : // runtime it is profitable to check the value of the operands, and if they are
      14             : // positive and less than 256 use an unsigned 8-bit divide.
      15             : //
      16             : //===----------------------------------------------------------------------===//
      17             : 
      18             : #ifndef LLVM_TRANSFORMS_UTILS_BYPASSSLOWDIVISION_H
      19             : #define LLVM_TRANSFORMS_UTILS_BYPASSSLOWDIVISION_H
      20             : 
      21             : #include "llvm/ADT/DenseMap.h"
      22             : #include "llvm/IR/Function.h"
      23             : 
      24             : namespace llvm {
      25             : 
      26             : struct DivRemMapKey {
      27             :   bool SignedOp;
      28             :   Value *Dividend;
      29             :   Value *Divisor;
      30             : 
      31             :   DivRemMapKey(bool InSignedOp, Value *InDividend, Value *InDivisor)
      32        4041 :       : SignedOp(InSignedOp), Dividend(InDividend), Divisor(InDivisor) {}
      33             : };
      34             : 
      35             : template <> struct DenseMapInfo<DivRemMapKey> {
      36             :   static bool isEqual(const DivRemMapKey &Val1, const DivRemMapKey &Val2) {
      37       24043 :     return Val1.SignedOp == Val2.SignedOp && Val1.Dividend == Val2.Dividend &&
      38       11246 :            Val1.Divisor == Val2.Divisor;
      39             :   }
      40             : 
      41             :   static DivRemMapKey getEmptyKey() {
      42        2319 :     return DivRemMapKey(false, nullptr, nullptr);
      43             :   }
      44             : 
      45             :   static DivRemMapKey getTombstoneKey() {
      46        1144 :     return DivRemMapKey(true, nullptr, nullptr);
      47             :   }
      48             : 
      49             :   static unsigned getHashValue(const DivRemMapKey &Val) {
      50        1518 :     return (unsigned)(reinterpret_cast<uintptr_t>(Val.Dividend) ^
      51         759 :                       reinterpret_cast<uintptr_t>(Val.Divisor)) ^
      52         759 :            (unsigned)Val.SignedOp;
      53             :   }
      54             : };
      55             : 
      56             : /// This optimization identifies DIV instructions in a BB that can be
      57             : /// profitably bypassed and carried out with a shorter, faster divide.
      58             : ///
      59             : /// This optimization may add basic blocks immediately after BB; for obvious
      60             : /// reasons, you shouldn't pass those blocks to bypassSlowDivision.
      61             : bool bypassSlowDivision(
      62             :     BasicBlock *BB, const DenseMap<unsigned int, unsigned int> &BypassWidth);
      63             : 
      64             : } // End llvm namespace
      65             : 
      66             : #endif

Generated by: LCOV version 1.13