LLVM 22.0.0git
HashRecognize.h
Go to the documentation of this file.
1//===- HashRecognize.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// Interface for the HashRecognize analysis, which identifies hash functions
10// that can be optimized using a lookup-table or with target-specific
11// instructions.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_ANALYSIS_HASHRECOGNIZE_H
16#define LLVM_ANALYSIS_HASHRECOGNIZE_H
17
18#include "llvm/ADT/APInt.h"
21#include "llvm/IR/PassManager.h"
22#include "llvm/IR/Value.h"
23#include <variant>
24
25namespace llvm {
26
27class LPMUpdater;
28
29/// A custom std::array with 256 entries, that also has a print function.
30struct CRCTable : public std::array<APInt, 256> {
31 void print(raw_ostream &OS) const;
32
33#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
34 LLVM_DUMP_METHOD void dump() const;
35#endif
36};
37
38/// The structure that is returned when a polynomial algorithm was recognized by
39/// the analysis. Currently, only the CRC algorithm is recognized.
41 // The small constant trip-count of the analyzed loop.
42 unsigned TripCount;
43
44 // The LHS in a polynomial operation, or the initial variable of the
45 // computation, since all polynomial operations must have a constant RHS,
46 // which is the generating polynomial. It is the LHS of the polynomial
47 // division in the case of CRC. Since polynomial division is an XOR in
48 // GF(2^m), this variable must be XOR'ed with RHS in a loop to yield the
49 // ComputedValue.
51
52 // The generating polynomial, or the RHS of the polynomial division in the
53 // case of CRC.
55
56 // The final computed value. This is a remainder of a polynomial division in
57 // the case of CRC, which must be zero.
59
60 // Set to true in the case of big-endian.
62
63 // An optional auxiliary checksum that augments the LHS. In the case of CRC,
64 // it is XOR'ed with the LHS, so that the computation's final remainder is
65 // zero.
67
68 PolynomialInfo(unsigned TripCount, Value *LHS, const APInt &RHS,
70 Value *LHSAux = nullptr);
71};
72
73/// The analysis.
75 const Loop &L;
77
78public:
79 HashRecognize(const Loop &L, ScalarEvolution &SE);
80
81 // The main analysis entry points.
82 std::variant<PolynomialInfo, StringRef> recognizeCRC() const;
83 std::optional<PolynomialInfo> getResult() const;
84
85 // Auxilary entry point after analysis to interleave the generating polynomial
86 // and return a 256-entry CRC table.
87 static CRCTable genSarwateTable(const APInt &GenPoly, bool ByteOrderSwapped);
88
89 void print(raw_ostream &OS) const;
90
91#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
92 LLVM_DUMP_METHOD void dump() const;
93#endif
94};
95
97 : public PassInfoMixin<HashRecognizePrinterPass> {
98 raw_ostream &OS;
99
100public:
101 explicit HashRecognizePrinterPass(raw_ostream &OS) : OS(OS) {}
104};
105} // namespace llvm
106
107#endif
This file implements a class to represent arbitrary precision integral constant values and operations...
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition Compiler.h:638
This header defines various interfaces for pass management in LLVM.
This header provides classes for managing per-loop analyses.
Class for arbitrary precision integers.
Definition APInt.h:78
PreservedAnalyses run(Loop &L, LoopAnalysisManager &AM, LoopStandardAnalysisResults &AR, LPMUpdater &)
HashRecognizePrinterPass(raw_ostream &OS)
static CRCTable genSarwateTable(const APInt &GenPoly, bool ByteOrderSwapped)
Generate a lookup table of 256 entries by interleaving the generating polynomial.
std::optional< PolynomialInfo > getResult() const
LLVM_DUMP_METHOD void dump() const
HashRecognize(const Loop &L, ScalarEvolution &SE)
void print(raw_ostream &OS) const
std::variant< PolynomialInfo, StringRef > recognizeCRC() const
The main entry point for analyzing a loop and recognizing the CRC algorithm.
This class provides an interface for updating the loop pass manager based on mutations to the loop ne...
Represents a single loop in the control flow graph.
Definition LoopInfo.h:40
A set of analyses that are preserved following a run of a transformation pass.
Definition Analysis.h:112
The main scalar evolution driver.
LLVM Value Representation.
Definition Value.h:75
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
This is an optimization pass for GlobalISel generic memory operations.
AnalysisManager< Loop, LoopStandardAnalysisResults & > LoopAnalysisManager
The loop analysis manager.
A custom std::array with 256 entries, that also has a print function.
LLVM_DUMP_METHOD void dump() const
void print(raw_ostream &OS) const
The adaptor from a function pass to a loop pass computes these analyses and makes them available to t...
A CRTP mix-in to automatically provide informational APIs needed for passes.
Definition PassManager.h:70
PolynomialInfo(unsigned TripCount, Value *LHS, const APInt &RHS, Value *ComputedValue, bool ByteOrderSwapped, Value *LHSAux=nullptr)