//===----- DivisionByConstantInfo.cpp - division by constant -*- C++ -*----===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// /// /// This file implements support for optimizing divisions by a constant /// //===----------------------------------------------------------------------===// #include "llvm/Support/DivisionByConstantInfo.h" usingnamespacellvm; /// Calculate the magic numbers required to implement a signed integer division /// by a constant as a sequence of multiplies, adds and shifts. Requires that /// the divisor not be 0, 1, or -1. Taken from "Hacker's Delight", Henry S. /// Warren, Jr., Chapter 10. SignedDivisionByConstantInfo SignedDivisionByConstantInfo::get(const APInt &D) { … } /// Calculate the magic numbers required to implement an unsigned integer /// division by a constant as a sequence of multiplies, adds and shifts. /// Requires that the divisor not be 0. Taken from "Hacker's Delight", Henry /// S. Warren, Jr., chapter 10. /// LeadingZeros can be used to simplify the calculation if the upper bits /// of the divided value are known zero. UnsignedDivisionByConstantInfo UnsignedDivisionByConstantInfo::get(const APInt &D, unsigned LeadingZeros, bool AllowEvenDivisorOptimization) { … }