//===---- llvm/Support/Discriminator.h -- Discriminator Utils ---*- 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 defines the constants and utility functions for discriminators. // //===----------------------------------------------------------------------===// #ifndef LLVM_SUPPORT_DISCRIMINATOR_H #define LLVM_SUPPORT_DISCRIMINATOR_H #include "llvm/Support/Error.h" #include <assert.h> // Utility functions for encoding / decoding discriminators. /// With a given unsigned int \p U, use up to 13 bits to represent it. /// old_bit 1~5 --> new_bit 1~5 /// old_bit 6~12 --> new_bit 7~13 /// new_bit_6 is 0 if higher bits (7~13) are all 0 static inline unsigned getPrefixEncodingFromUnsigned(unsigned U) { … } /// Reverse transformation as getPrefixEncodingFromUnsigned. static inline unsigned getUnsignedFromPrefixEncoding(unsigned U) { … } /// Returns the next component stored in discriminator. static inline unsigned getNextComponentInDiscriminator(unsigned D) { … } static inline unsigned encodeComponent(unsigned C) { … } static inline unsigned encodingBits(unsigned C) { … } // Some constants used in FS Discriminators. // namespace llvm { namespace sampleprof { enum FSDiscriminatorPass { … }; } // namespace sampleprof // The number of bits reserved for the base discrimininator. The base // discriminaitor starts from bit 0. static const unsigned BaseDiscriminatorBitWidth = …; // The number of bits reserved for each FS discriminator pass. static const unsigned FSDiscriminatorBitWidth = …; // Return the number of FS passes, excluding the pass adding the base // discriminators. // The number of passes for FS discriminators. Note that the total // number of discriminaitor bits, i.e. // BaseDiscriminatorBitWidth // + FSDiscriminatorBitWidth * getNumFSPasses() // needs to fit in an unsigned int type. static inline unsigned getNumFSPasses() { … } // Return the ending bit for FSPass P. static inline unsigned getFSPassBitEnd(sampleprof::FSDiscriminatorPass P) { … } // Return the begining bit for FSPass P. static inline unsigned getFSPassBitBegin(sampleprof::FSDiscriminatorPass P) { … } // Return the beginning bit for the last FSPass. static inline int getLastFSPassBitBegin() { … } // Return the ending bit for the last FSPass. static inline unsigned getLastFSPassBitEnd() { … } // Return the beginning bit for the base (first) FSPass. static inline unsigned getBaseFSBitBegin() { … } // Return the ending bit for the base (first) FSPass. static inline unsigned getBaseFSBitEnd() { … } // Set bits in range of [0 .. n] to 1. Used in FS Discriminators. static inline unsigned getN1Bits(int N) { … } } // namespace llvm #endif /* LLVM_SUPPORT_DISCRIMINATOR_H */