xref: /freebsd/contrib/llvm-project/llvm/include/llvm/Support/DivisionByConstantInfo.h (revision bdd1243df58e60e85101c09001d9812a789b6bc4)
1fcaf7f86SDimitry Andric //===- llvm/Support/DivisionByConstantInfo.h ---------------------*- C++ -*-==//
2349cc55cSDimitry Andric //
3349cc55cSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4349cc55cSDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5349cc55cSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6349cc55cSDimitry Andric //
7349cc55cSDimitry Andric //===----------------------------------------------------------------------===//
8349cc55cSDimitry Andric ///
9349cc55cSDimitry Andric /// This file implements support for optimizing divisions by a constant
10349cc55cSDimitry Andric ///
11349cc55cSDimitry Andric //===----------------------------------------------------------------------===//
12349cc55cSDimitry Andric 
1304eeddc0SDimitry Andric #ifndef LLVM_SUPPORT_DIVISIONBYCONSTANTINFO_H
1404eeddc0SDimitry Andric #define LLVM_SUPPORT_DIVISIONBYCONSTANTINFO_H
15349cc55cSDimitry Andric 
16349cc55cSDimitry Andric #include "llvm/ADT/APInt.h"
17349cc55cSDimitry Andric 
18349cc55cSDimitry Andric namespace llvm {
19349cc55cSDimitry Andric 
20349cc55cSDimitry Andric /// Magic data for optimising signed division by a constant.
21349cc55cSDimitry Andric struct SignedDivisionByConstantInfo {
22349cc55cSDimitry Andric   static SignedDivisionByConstantInfo get(const APInt &D);
23349cc55cSDimitry Andric   APInt Magic;          ///< magic number
24349cc55cSDimitry Andric   unsigned ShiftAmount; ///< shift amount
25349cc55cSDimitry Andric };
26349cc55cSDimitry Andric 
27349cc55cSDimitry Andric /// Magic data for optimising unsigned division by a constant.
28fcaf7f86SDimitry Andric struct UnsignedDivisionByConstantInfo {
29*bdd1243dSDimitry Andric   static UnsignedDivisionByConstantInfo
30*bdd1243dSDimitry Andric   get(const APInt &D, unsigned LeadingZeros = 0,
31*bdd1243dSDimitry Andric       bool AllowEvenDivisorOptimization = true);
32349cc55cSDimitry Andric   APInt Magic;          ///< magic number
33349cc55cSDimitry Andric   bool IsAdd;           ///< add indicator
34*bdd1243dSDimitry Andric   unsigned PostShift;   ///< post-shift amount
35*bdd1243dSDimitry Andric   unsigned PreShift;    ///< pre-shift amount
36349cc55cSDimitry Andric };
37349cc55cSDimitry Andric 
38349cc55cSDimitry Andric } // namespace llvm
39349cc55cSDimitry Andric 
40349cc55cSDimitry Andric #endif
41