1- // === llvm/Analysis/ CSADescriptors.cpp - CSA Descriptors -*- C++ -*-===//
1+ // ===----------- CSADescriptors.. cpp - CSA Descriptors --------- -*- C++ -*-===//
22//
33// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44// See https://llvm.org/LICENSE.txt for license information.
@@ -19,43 +19,43 @@ using namespace llvm::PatternMatch;
1919
2020#define DEBUG_TYPE " csa-descriptors"
2121
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.
2230CSADescriptor 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.
3131
3232 // Must be a scalar
3333 Type *Type = Phi->getType ();
3434 if (!Type->isIntegerTy () && !Type->isFloatingPointTy () &&
3535 !Type->isPointerTy ())
36- return CSADescriptor () ;
36+ return {} ;
3737
3838 // Match phi loop_inv, (select cmp, value, phi)
3939 // or phi loop_inv, (select cmp, phi, value)
4040 // or phi (select cmp, value, phi), loop_inv
4141 // or phi (select cmp, phi, value), loop_inv
4242 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) {
4545 return match (U.get (), m_Select (m_Value (), m_Specific (Phi), m_Value ())) ||
4646 match (U.get (), m_Select (m_Value (), m_Value (), m_Specific (Phi)));
4747 });
4848 if (SelectInstIt == Phi->incoming_values ().end ())
49- return CSADescriptor () ;
49+ return {} ;
5050 auto LoopInvIt = find_if (Phi->incoming_values (), [&](Use &U) {
5151 return U.get () != *SelectInstIt && TheLoop->isLoopInvariant (U.get ());
5252 });
5353 if (LoopInvIt == Phi->incoming_values ().end ())
54- return CSADescriptor () ;
54+ return {} ;
5555
5656 // Phi or Sel must be used only outside the loop,
5757 // excluding if Phi use Sel or Sel use Phi
58- auto IsOnlyUsedOutsideLoop = [= ](Value *V, Value *Ignore) {
58+ auto IsOnlyUsedOutsideLoop = [& ](Value *V, Value *Ignore) {
5959 return all_of (V->users (), [Ignore, TheLoop](User *U) {
6060 if (U == Ignore)
6161 return true ;
@@ -64,10 +64,11 @@ CSADescriptor CSADescriptor::isCSAPhi(PHINode *Phi, Loop *TheLoop) {
6464 return true ;
6565 });
6666 };
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 {};
7172
72- return CSADescriptor ( Phi, Sel , LoopInv) ;
73+ return { Phi, Select , LoopInv} ;
7374}
0 commit comments