<div dir="ltr">LLVM typically prefers "getFoo" type names for getters. More broadly the rule is verb phrases: <a href="https://llvm.org/docs/CodingStandards.html#name-types-functions-variables-and-enumerators-properly">https://llvm.org/docs/CodingStandards.html#name-types-functions-variables-and-enumerators-properly</a><div><br></div><div>The main exception I can think of is when we are trying to be compatible with STL conventions. E.g. Value::{use_begin,use_end,users}<br><div><br></div><div>-- Sean Silva</div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Oct 17, 2017 at 11:43 AM, Jessica Paquette via llvm-commits <span dir="ltr"><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: paquette<br>
Date: Tue Oct 17 11:43:15 2017<br>
New Revision: 316019<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=316019&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project?rev=316019&view=rev</a><br>
Log:<br>
[MachineOutliner][NFC] Move end index calculation into Candidate<br>
<br>
Cleanup to Candidate that moves all end index calculations into<br>
Candidate.endIdx(). For the sake of consistency, StartIdx and Len are now<br>
private members, and can be accessed with length() and startIdx() respectively.<br>
<br>
<br>
Modified:<br>
    llvm/trunk/lib/CodeGen/<wbr>MachineOutliner.cpp<br>
<br>
Modified: llvm/trunk/lib/CodeGen/<wbr>MachineOutliner.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineOutliner.cpp?rev=316019&r1=316018&r2=316019&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/llvm/trunk/lib/<wbr>CodeGen/MachineOutliner.cpp?<wbr>rev=316019&r1=316018&r2=<wbr>316019&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- llvm/trunk/lib/CodeGen/<wbr>MachineOutliner.cpp (original)<br>
+++ llvm/trunk/lib/CodeGen/<wbr>MachineOutliner.cpp Tue Oct 17 11:43:15 2017<br>
@@ -92,23 +92,33 @@ namespace {<br>
 /// \brief An individual sequence of instructions to be replaced with a call to<br>
 /// an outlined function.<br>
 struct Candidate {<br>
-<br>
-  /// Set to false if the candidate overlapped with another candidate.<br>
-  bool InCandidateList = true;<br>
-<br>
-  /// The start index of this \p Candidate.<br>
+private:<br>
+  /// The start index of this \p Candidate in the instruction list.<br>
   unsigned StartIdx;<br>
<br>
   /// The number of instructions in this \p Candidate.<br>
   unsigned Len;<br>
<br>
-  /// The index of this \p Candidate's \p OutlinedFunction in the list of<br>
+public:<br>
+  /// Set to false if the candidate overlapped with another candidate.<br>
+  bool InCandidateList = true;<br>
+<br>
+  /// \brief The index of this \p Candidate's \p OutlinedFunction in the list of<br>
   /// \p OutlinedFunctions.<br>
   unsigned FunctionIdx;<br>
<br>
   /// Contains all target-specific information for this \p Candidate.<br>
   TargetInstrInfo::<wbr>MachineOutlinerInfo MInfo;<br>
<br>
+  /// Return the number of instructions in this Candidate.<br>
+  unsigned length() const { return Len; }<br>
+<br>
+  /// Return the start index of this candidate.<br>
+  unsigned startIdx() const { return StartIdx; }<br>
+<br>
+  // Return the end index of this candidate.<br>
+  unsigned endIdx() const { return StartIdx + Len - 1; }<br>
+<br>
   /// \brief The number of instructions that would be saved by outlining every<br>
   /// candidate of this type.<br>
   ///<br>
@@ -125,7 +135,9 @@ struct Candidate {<br>
<br>
   /// \brief Used to ensure that \p Candidates are outlined in an order that<br>
   /// preserves the start and end indices of other \p Candidates.<br>
-  bool operator<(const Candidate &RHS) const { return StartIdx > RHS.StartIdx; }<br>
+  bool operator<(const Candidate &RHS) const {<br>
+    return startIdx() > RHS.startIdx();<br>
+  }<br>
 };<br>
<br>
 /// \brief The information necessary to create an outlined function for some<br>
@@ -759,8 +771,8 @@ struct MachineOutliner : public ModulePa<br>
     ModulePass::getAnalysisUsage(<wbr>AU);<br>
   }<br>
<br>
-  MachineOutliner(bool OutlineFromLinkOnceODRs = false) :<br>
-  ModulePass(ID), OutlineFromLinkOnceODRs(<wbr>OutlineFromLinkOnceODRs) {<br>
+  MachineOutliner(bool OutlineFromLinkOnceODRs = false)<br>
+      : ModulePass(ID), OutlineFromLinkOnceODRs(<wbr>OutlineFromLinkOnceODRs) {<br>
     initializeMachineOutlinerPass(<wbr>*PassRegistry::<wbr>getPassRegistry());<br>
   }<br>
<br>
@@ -1060,8 +1072,8 @@ void MachineOutliner::<wbr>pruneOverlaps(std:<br>
     unsigned FarthestPossibleIdx = 0;<br>
<br>
     // Either the index is 0, or it's at most MaxCandidateLen indices away.<br>
-    if (C1.StartIdx > MaxCandidateLen)<br>
-      FarthestPossibleIdx = C1.StartIdx - MaxCandidateLen;<br>
+    if (C1.startIdx() > MaxCandidateLen)<br>
+      FarthestPossibleIdx = C1.startIdx() - MaxCandidateLen;<br>
<br>
     // Compare against the candidates in the list that start at at most<br>
     // FarthestPossibleIdx indices away from C1. There are at most<br>
@@ -1070,7 +1082,7 @@ void MachineOutliner::<wbr>pruneOverlaps(std:<br>
       Candidate &C2 = *Sit;<br>
<br>
       // Is this candidate too far away to overlap?<br>
-      if (C2.StartIdx < FarthestPossibleIdx)<br>
+      if (C2.startIdx() < FarthestPossibleIdx)<br>
         break;<br>
<br>
       // If C2 was already pruned, or its function is no longer beneficial for<br>
@@ -1078,8 +1090,6 @@ void MachineOutliner::<wbr>pruneOverlaps(std:<br>
       if (ShouldSkipCandidate(C2))<br>
         continue;<br>
<br>
-      unsigned C2End = C2.StartIdx + C2.Len - 1;<br>
-<br>
       // Do C1 and C2 overlap?<br>
       //<br>
       // Not overlapping:<br>
@@ -1088,7 +1098,7 @@ void MachineOutliner::<wbr>pruneOverlaps(std:<br>
       // We sorted our candidate list so C2Start <= C1Start. We know that<br>
       // C2End > C2Start since each candidate has length >= 2. Therefore, all we<br>
       // have to check is C2End < C2Start to see if we overlap.<br>
-      if (C2End < C1.StartIdx)<br>
+      if (C2.endIdx() < C1.startIdx())<br>
         continue;<br>
<br>
       // C1 and C2 overlap.<br>
@@ -1202,10 +1212,11 @@ bool MachineOutliner::outline(<wbr>Module &M,<br>
       continue;<br>
<br>
     // If not, then outline it.<br>
-    assert(C.StartIdx < Mapper.InstrList.size() && "Candidate out of bounds!");<br>
-    MachineBasicBlock *MBB = (*Mapper.InstrList[C.StartIdx]<wbr>).getParent();<br>
-    MachineBasicBlock::iterator StartIt = Mapper.InstrList[C.StartIdx];<br>
-    unsigned EndIdx = C.StartIdx + C.Len - 1;<br>
+    assert(C.startIdx() < Mapper.InstrList.size() &&<br>
+           "Candidate out of bounds!");<br>
+    MachineBasicBlock *MBB = (*Mapper.InstrList[C.startIdx(<wbr>)]).getParent();<br>
+    MachineBasicBlock::iterator StartIt = Mapper.InstrList[C.startIdx()]<wbr>;<br>
+    unsigned EndIdx = C.endIdx();<br>
<br>
     assert(EndIdx < Mapper.InstrList.size() && "Candidate out of bounds!");<br>
     MachineBasicBlock::iterator EndIt = Mapper.InstrList[EndIdx];<br>
@@ -1225,7 +1236,7 @@ bool MachineOutliner::outline(<wbr>Module &M,<br>
<br>
     // Insert a call to the new function and erase the old sequence.<br>
     TII.insertOutlinedCall(M, *MBB, StartIt, *MF, C.MInfo);<br>
-    StartIt = Mapper.InstrList[C.StartIdx];<br>
+    StartIt = Mapper.InstrList[C.startIdx()]<wbr>;<br>
     MBB->erase(StartIt, EndIt);<br>
<br>
     OutlinedSomething = true;<br>
<br>
<br>
______________________________<wbr>_________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div>