1
- // === llvm/Analysis/ CSADescriptors.cpp - CSA Descriptors -*- C++ -*-===//
1
+ // ===----------- CSADescriptors.. cpp - CSA Descriptors --------- -*- C++ -*-===//
2
2
//
3
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
4
// See https://llvm.org/LICENSE.txt for license information.
@@ -19,43 +19,43 @@ using namespace llvm::PatternMatch;
19
19
20
20
#define DEBUG_TYPE " csa-descriptors"
21
21
22
+ // / Return CSADescriptor that describes a CSA that matches one of these
23
+ // / patterns:
24
+ // / phi loop_inv, (select cmp, value, phi)
25
+ // / phi loop_inv, (select cmp, phi, value)
26
+ // / phi (select cmp, value, phi), loop_inv
27
+ // / phi (select cmp, phi, value), loop_inv
28
+ // / If the CSA does not match any of these paterns, return a CSADescriptor
29
+ // / that describes an InvalidCSA.
22
30
CSADescriptor CSADescriptor::isCSAPhi (PHINode *Phi, Loop *TheLoop) {
23
- // Return CSADescriptor that describes a CSA that matches one of these
24
- // patterns:
25
- // phi loop_inv, (select cmp, value, phi)
26
- // phi loop_inv, (select cmp, phi, value)
27
- // phi (select cmp, value, phi), loop_inv
28
- // phi (select cmp, phi, value), loop_inv
29
- // If the CSA does not match any of these paterns, return a CSADescriptor
30
- // that describes an InvalidCSA.
31
31
32
32
// Must be a scalar
33
33
Type *Type = Phi->getType ();
34
34
if (!Type->isIntegerTy () && !Type->isFloatingPointTy () &&
35
35
!Type->isPointerTy ())
36
- return CSADescriptor () ;
36
+ return {} ;
37
37
38
38
// Match phi loop_inv, (select cmp, value, phi)
39
39
// or phi loop_inv, (select cmp, phi, value)
40
40
// or phi (select cmp, value, phi), loop_inv
41
41
// or phi (select cmp, phi, value), loop_inv
42
42
if (Phi->getNumIncomingValues () != 2 )
43
- return CSADescriptor () ;
44
- auto SelectInstIt = find_if (Phi->incoming_values (), [&Phi](Use &U) {
43
+ return {} ;
44
+ auto SelectInstIt = find_if (Phi->incoming_values (), [&Phi](const Use &U) {
45
45
return match (U.get (), m_Select (m_Value (), m_Specific (Phi), m_Value ())) ||
46
46
match (U.get (), m_Select (m_Value (), m_Value (), m_Specific (Phi)));
47
47
});
48
48
if (SelectInstIt == Phi->incoming_values ().end ())
49
- return CSADescriptor () ;
49
+ return {} ;
50
50
auto LoopInvIt = find_if (Phi->incoming_values (), [&](Use &U) {
51
51
return U.get () != *SelectInstIt && TheLoop->isLoopInvariant (U.get ());
52
52
});
53
53
if (LoopInvIt == Phi->incoming_values ().end ())
54
- return CSADescriptor () ;
54
+ return {} ;
55
55
56
56
// Phi or Sel must be used only outside the loop,
57
57
// excluding if Phi use Sel or Sel use Phi
58
- auto IsOnlyUsedOutsideLoop = [= ](Value *V, Value *Ignore) {
58
+ auto IsOnlyUsedOutsideLoop = [& ](Value *V, Value *Ignore) {
59
59
return all_of (V->users (), [Ignore, TheLoop](User *U) {
60
60
if (U == Ignore)
61
61
return true ;
@@ -64,10 +64,11 @@ CSADescriptor CSADescriptor::isCSAPhi(PHINode *Phi, Loop *TheLoop) {
64
64
return true ;
65
65
});
66
66
};
67
- auto *Sel = cast<SelectInst>(SelectInstIt->get ());
68
- auto *LoopInv = LoopInvIt->get ();
69
- if (!IsOnlyUsedOutsideLoop (Phi, Sel) || !IsOnlyUsedOutsideLoop (Sel, Phi))
70
- return CSADescriptor ();
67
+ Instruction *Select = cast<SelectInst>(SelectInstIt->get ());
68
+ Value *LoopInv = LoopInvIt->get ();
69
+ if (!IsOnlyUsedOutsideLoop (Phi, Select) ||
70
+ !IsOnlyUsedOutsideLoop (Select, Phi))
71
+ return {};
71
72
72
- return CSADescriptor ( Phi, Sel , LoopInv) ;
73
+ return { Phi, Select , LoopInv} ;
73
74
}
0 commit comments