LLVM  14.0.0git
Discriminator.h
Go to the documentation of this file.
1 //===---- llvm/Support/Discriminator.h -- Discriminator Utils ---*- 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 // This file defines the constants and utility functions for discriminators.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_SUPPORT_DISCRIMINATOR_H
14 #define LLVM_SUPPORT_DISCRIMINATOR_H
15 
16 #include "llvm/Support/Error.h"
17 #include <assert.h>
18 
19 // Utility functions for encoding / decoding discriminators.
20 /// With a given unsigned int \p U, use up to 13 bits to represent it.
21 /// old_bit 1~5 --> new_bit 1~5
22 /// old_bit 6~12 --> new_bit 7~13
23 /// new_bit_6 is 0 if higher bits (7~13) are all 0
24 static inline unsigned getPrefixEncodingFromUnsigned(unsigned U) {
25  U &= 0xfff;
26  return U > 0x1f ? (((U & 0xfe0) << 1) | (U & 0x1f) | 0x20) : U;
27 }
28 
29 /// Reverse transformation as getPrefixEncodingFromUnsigned.
30 static inline unsigned getUnsignedFromPrefixEncoding(unsigned U) {
31  if (U & 1)
32  return 0;
33  U >>= 1;
34  return (U & 0x20) ? (((U >> 1) & 0xfe0) | (U & 0x1f)) : (U & 0x1f);
35 }
36 
37 /// Returns the next component stored in discriminator.
38 static inline unsigned getNextComponentInDiscriminator(unsigned D) {
39  if ((D & 1) == 0)
40  return D >> ((D & 0x40) ? 14 : 7);
41  else
42  return D >> 1;
43 }
44 
45 static inline unsigned encodeComponent(unsigned C) {
46  return (C == 0) ? 1U : (getPrefixEncodingFromUnsigned(C) << 1);
47 }
48 
49 static inline unsigned encodingBits(unsigned C) {
50  return (C == 0) ? 1 : (C > 0x1f ? 14 : 7);
51 }
52 
53 // Some constants used in FS Discriminators.
54 //
55 namespace llvm {
56 namespace sampleprof {
58  Base = 0,
59  Pass0 = 0,
60  Pass1 = 1,
61  Pass2 = 2,
62  Pass3 = 3,
63  Pass4 = 4,
64  PassLast = 4,
65 };
66 } // namespace sampleprof
67 
68 using namespace sampleprof;
69 
70 // The number of bits reserved for the base discrimininator. The base
71 // discriminaitor starts from bit 0.
72 static const unsigned BaseDiscriminatorBitWidth = 8;
73 
74 // The number of bits reserved for each FS discriminator pass.
75 static const unsigned FSDiscriminatorBitWidth = 6;
76 
77 // Return the number of FS passes, excluding the pass adding the base
78 // discriminators.
79 // The number of passes for FS discriminators. Note that the total
80 // number of discriminaitor bits, i.e.
81 // BaseDiscriminatorBitWidth
82 // + FSDiscriminatorBitWidth * getNumFSPasses()
83 // needs to fit in an unsigned int type.
84 static inline unsigned getNumFSPasses() {
85  return static_cast<unsigned>(FSDiscriminatorPass::PassLast);
86 }
87 
88 // Return the ending bit for FSPass P.
89 static inline unsigned getFSPassBitEnd(FSDiscriminatorPass P) {
90  unsigned I = static_cast<unsigned>(P);
91  assert(I <= getNumFSPasses() && "Invalid FS discriminator pass number.");
93 }
94 
95 // Return the begining bit for FSPass P.
96 static inline unsigned getFSPassBitBegin(FSDiscriminatorPass P) {
98  return 0;
99  unsigned I = static_cast<unsigned>(P);
100  assert(I <= getNumFSPasses() && "Invalid FS discriminator pass number.");
101  return getFSPassBitEnd(static_cast<FSDiscriminatorPass>(I - 1)) + 1;
102 }
103 
104 // Return the beginning bit for the last FSPass.
105 static inline int getLastFSPassBitBegin() {
106  return getFSPassBitBegin(static_cast<FSDiscriminatorPass>(getNumFSPasses()));
107 }
108 
109 // Return the ending bit for the last FSPass.
110 static inline unsigned getLastFSPassBitEnd() {
111  return getFSPassBitEnd(static_cast<FSDiscriminatorPass>(getNumFSPasses()));
112 }
113 
114 // Return the beginning bit for the base (first) FSPass.
115 static inline unsigned getBaseFSBitBegin() { return 0; }
116 
117 // Return the ending bit for the base (first) FSPass.
118 static inline unsigned getBaseFSBitEnd() {
119  return BaseDiscriminatorBitWidth - 1;
120 }
121 
122 // Set bits in range of [0 .. n] to 1. Used in FS Discriminators.
123 static inline unsigned getN1Bits(int N) {
124  // Work around the g++ bug that folding "(1U << (N + 1)) - 1" to 0.
125  if (N == 31)
126  return 0xFFFFFFFF;
127  assert((N < 32) && "N is invalid");
128  return (1U << (N + 1)) - 1;
129 }
130 
131 } // namespace llvm
132 
133 #endif /* LLVM_SUPPORT_DISCRIMINATOR_H */
getNextComponentInDiscriminator
static unsigned getNextComponentInDiscriminator(unsigned D)
Returns the next component stored in discriminator.
Definition: Discriminator.h:38
llvm::getFSPassBitBegin
static unsigned getFSPassBitBegin(FSDiscriminatorPass P)
Definition: Discriminator.h:96
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
getUnsignedFromPrefixEncoding
static unsigned getUnsignedFromPrefixEncoding(unsigned U)
Reverse transformation as getPrefixEncodingFromUnsigned.
Definition: Discriminator.h:30
llvm::getBaseFSBitBegin
static unsigned getBaseFSBitBegin()
Definition: Discriminator.h:115
P
This currently compiles esp xmm0 movsd esp eax eax esp ret We should use not the dag combiner This is because dagcombine2 needs to be able to see through the X86ISD::Wrapper which DAGCombine can t really do The code for turning x load into a single vector load is target independent and should be moved to the dag combiner The code for turning x load into a vector load can only handle a direct load from a global or a direct load from the stack It should be generalized to handle any load from P
Definition: README-SSE.txt:411
llvm::BaseDiscriminatorBitWidth
static const unsigned BaseDiscriminatorBitWidth
Definition: Discriminator.h:72
Error.h
encodingBits
static unsigned encodingBits(unsigned C)
Definition: Discriminator.h:49
llvm::getN1Bits
static unsigned getN1Bits(int N)
Definition: Discriminator.h:123
llvm::getBaseFSBitEnd
static unsigned getBaseFSBitEnd()
Definition: Discriminator.h:118
llvm::sampleprof::FSDiscriminatorPass
FSDiscriminatorPass
Definition: Discriminator.h:57
llvm::getNumFSPasses
static unsigned getNumFSPasses()
Definition: Discriminator.h:84
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
llvm::sampleprof::Pass2
@ Pass2
Definition: Discriminator.h:61
llvm::FSDiscriminatorBitWidth
static const unsigned FSDiscriminatorBitWidth
Definition: Discriminator.h:75
llvm::sampleprof::PassLast
@ PassLast
Definition: Discriminator.h:64
encodeComponent
static unsigned encodeComponent(unsigned C)
Definition: Discriminator.h:45
llvm::sampleprof::Pass4
@ Pass4
Definition: Discriminator.h:63
D
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
I
#define I(x, y, z)
Definition: MD5.cpp:59
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
getPrefixEncodingFromUnsigned
static unsigned getPrefixEncodingFromUnsigned(unsigned U)
With a given unsigned int U, use up to 13 bits to represent it.
Definition: Discriminator.h:24
llvm::getLastFSPassBitBegin
static int getLastFSPassBitBegin()
Definition: Discriminator.h:105
llvm::sampleprof::Pass0
@ Pass0
Definition: Discriminator.h:59
llvm::sampleprof::Pass1
@ Pass1
Definition: Discriminator.h:60
llvm::sampleprof::Pass3
@ Pass3
Definition: Discriminator.h:62
N
#define N
llvm::getFSPassBitEnd
static unsigned getFSPassBitEnd(FSDiscriminatorPass P)
Definition: Discriminator.h:89
llvm::getLastFSPassBitEnd
static unsigned getLastFSPassBitEnd()
Definition: Discriminator.h:110
llvm::sampleprof::Base
@ Base
Definition: Discriminator.h:58