14
14
#ifndef LLVM_CODEGEN_GLOBALISEL_GISELVALUETRACKING_H
15
15
#define LLVM_CODEGEN_GLOBALISEL_GISELVALUETRACKING_H
16
16
17
+ #include " llvm/ADT/APFloat.h"
17
18
#include " llvm/ADT/DenseMap.h"
18
19
#include " llvm/CodeGen/GlobalISel/GISelChangeObserver.h"
19
20
#include " llvm/CodeGen/MachineFunctionPass.h"
20
21
#include " llvm/CodeGen/Register.h"
22
+ #include " llvm/IR/InstrTypes.h"
21
23
#include " llvm/InitializePasses.h"
22
24
#include " llvm/Support/KnownBits.h"
25
+ #include " llvm/Support/KnownFPClass.h"
23
26
24
27
namespace llvm {
25
28
@@ -41,6 +44,64 @@ class GISelValueTracking : public GISelChangeObserver {
41
44
unsigned computeNumSignBitsMin (Register Src0, Register Src1,
42
45
const APInt &DemandedElts, unsigned Depth = 0 );
43
46
47
+ // / Returns a pair of values, which if passed to llvm.is.fpclass, returns the
48
+ // / same result as an fcmp with the given operands.
49
+ // /
50
+ // / If \p LookThroughSrc is true, consider the input value when computing the
51
+ // / mask.
52
+ // /
53
+ // / If \p LookThroughSrc is false, ignore the source value (i.e. the first
54
+ // / pair element will always be LHS.
55
+ std::pair<Register, FPClassTest> fcmpToClassTest (CmpInst::Predicate Pred,
56
+ const MachineFunction &MF,
57
+ Register LHS, Value *RHS,
58
+ bool LookThroughSrc = true );
59
+ std::pair<Register, FPClassTest> fcmpToClassTest (CmpInst::Predicate Pred,
60
+ const MachineFunction &MF,
61
+ Register LHS,
62
+ const APFloat *ConstRHS,
63
+ bool LookThroughSrc = true );
64
+
65
+ // / Compute the possible floating-point classes that \p LHS could be based on
66
+ // / fcmp \Pred \p LHS, \p RHS.
67
+ // /
68
+ // / \returns { TestedValue, ClassesIfTrue, ClassesIfFalse }
69
+ // /
70
+ // / If the compare returns an exact class test, ClassesIfTrue ==
71
+ // / ~ClassesIfFalse
72
+ // /
73
+ // / This is a less exact version of fcmpToClassTest (e.g. fcmpToClassTest will
74
+ // / only succeed for a test of x > 0 implies positive, but not x > 1).
75
+ // /
76
+ // / If \p LookThroughSrc is true, consider the input value when computing the
77
+ // / mask. This may look through sign bit operations.
78
+ // /
79
+ // / If \p LookThroughSrc is false, ignore the source value (i.e. the first
80
+ // / pair element will always be LHS.
81
+ // /
82
+ std::tuple<Register, FPClassTest, FPClassTest>
83
+ fcmpImpliesClass (CmpInst::Predicate Pred, const MachineFunction &MF,
84
+ Register LHS, Register RHS, bool LookThroughSrc = true );
85
+ std::tuple<Register, FPClassTest, FPClassTest>
86
+ fcmpImpliesClass (CmpInst::Predicate Pred, const MachineFunction &MF,
87
+ Register LHS, FPClassTest RHS, bool LookThroughSrc = true );
88
+ std::tuple<Register, FPClassTest, FPClassTest>
89
+ fcmpImpliesClass (CmpInst::Predicate Pred, const MachineFunction &MF,
90
+ Register LHS, const APFloat &RHS,
91
+ bool LookThroughSrc = true );
92
+
93
+ void computeKnownFPClass (Register R, KnownFPClass &Known,
94
+ FPClassTest InterestedClasses, unsigned Depth);
95
+
96
+ void computeKnownFPClassForFPTrunc (const MachineInstr &MI,
97
+ const APInt &DemandedElts,
98
+ FPClassTest InterestedClasses,
99
+ KnownFPClass &Known, unsigned Depth);
100
+
101
+ void computeKnownFPClass (Register R, const APInt &DemandedElts,
102
+ FPClassTest InterestedClasses, KnownFPClass &Known,
103
+ unsigned Depth);
104
+
44
105
public:
45
106
GISelValueTracking (MachineFunction &MF, unsigned MaxDepth = 6 );
46
107
virtual ~GISelValueTracking () = default ;
@@ -86,6 +147,34 @@ class GISelValueTracking : public GISelChangeObserver {
86
147
// / \return The known alignment for the pointer-like value \p R.
87
148
Align computeKnownAlignment (Register R, unsigned Depth = 0 );
88
149
150
+ // / Determine which floating-point classes are valid for \p V, and return them
151
+ // / in KnownFPClass bit sets.
152
+ // /
153
+ // / This function is defined on values with floating-point type, values
154
+ // / vectors of floating-point type, and arrays of floating-point type.
155
+
156
+ // / \p InterestedClasses is a compile time optimization hint for which
157
+ // / floating point classes should be queried. Queries not specified in \p
158
+ // / InterestedClasses should be reliable if they are determined during the
159
+ // / query.
160
+ KnownFPClass computeKnownFPClass (Register R, const APInt &DemandedElts,
161
+ FPClassTest InterestedClasses,
162
+ unsigned Depth);
163
+
164
+ KnownFPClass computeKnownFPClass (Register R,
165
+ FPClassTest InterestedClasses = fcAllFlags,
166
+ unsigned Depth = 0 );
167
+
168
+ // / Wrapper to account for known fast math flags at the use instruction.
169
+ KnownFPClass computeKnownFPClass (Register R, const APInt &DemandedElts,
170
+ uint32_t Flags,
171
+ FPClassTest InterestedClasses,
172
+ unsigned Depth);
173
+
174
+ KnownFPClass computeKnownFPClass (Register R, uint32_t Flags,
175
+ FPClassTest InterestedClasses,
176
+ unsigned Depth);
177
+
89
178
// Observer API. No-op for non-caching implementation.
90
179
void erasingInstr (MachineInstr &MI) override {}
91
180
void createdInstr (MachineInstr &MI) override {}
0 commit comments