[llvm] r229033 - [unroll] Make range based for loops a bit more explicit and more

David Blaikie dblaikie at gmail.com
Thu Feb 12 19:08:08 PST 2015


On Thu, Feb 12, 2015 at 6:45 PM, Chandler Carruth <chandlerc at gmail.com>
wrote:

> Author: chandlerc
> Date: Thu Feb 12 20:45:17 2015
> New Revision: 229033
>
> URL: http://llvm.org/viewvc/llvm-project?rev=229033&view=rev
> Log:
> [unroll] Make range based for loops a bit more explicit and more
> readable.
>
> The biggest thing that was causing me problems is recognizing the
> references vs. poniters here.


Yeah, we do have a style guide point about using * explicitly even when
using auto (doesn't help as much for unique_ptr, of course) - but don't
have good clang-tidy integration, or a clang-tidy check for this particular
rule I don't think. :(


> I also found that for maps naming the loop
> variable as KeyValue helps make it obvious why you don't actually use it
> directly. Finally, using 'auto' instead of 'User *' doesn't seem like
> a good tradeoff. Much like with the other cases, I like to know its
> a pointer, and 'User' is just as long and tells the reader a lot more.
>
> Modified:
>     llvm/trunk/lib/Transforms/Scalar/LoopUnrollPass.cpp
>
> Modified: llvm/trunk/lib/Transforms/Scalar/LoopUnrollPass.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/LoopUnrollPass.cpp?rev=229033&r1=229032&r2=229033&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/Transforms/Scalar/LoopUnrollPass.cpp (original)
> +++ llvm/trunk/lib/Transforms/Scalar/LoopUnrollPass.cpp Thu Feb 12
> 20:45:17 2015
> @@ -461,13 +461,13 @@ public:
>      NumberOfOptimizedInstructions = 0;
>
>      // We start by adding all loads to the worklist.
> -    for (auto LoadDescr : LoadBaseAddresses) {
> +    for (auto &LoadDescr : LoadBaseAddresses) {
>        LoadInst *LI = LoadDescr.first;
>        SimplifiedValues[LI] = computeLoadValue(LI, Iteration);
>        if (CountedInstructions.insert(LI).second)
>          NumberOfOptimizedInstructions += TTI.getUserCost(LI);
>
> -      for (auto U : LI->users()) {
> +      for (User *U : LI->users()) {
>          Instruction *UI = dyn_cast<Instruction>(U);
>          if (!UI)
>            continue;
> @@ -484,7 +484,7 @@ public:
>        Instruction *I = Worklist.pop_back_val();
>        if (!visit(I))
>          continue;
> -      for (auto U : I->users()) {
> +      for (User *U : I->users()) {
>          Instruction *UI = dyn_cast<Instruction>(U);
>          if (!UI)
>            continue;
> @@ -504,8 +504,8 @@ public:
>      SmallPtrSet<Instruction *, 16> DeadInstructions;
>
>      // Start by initializing worklist with simplified instructions.
> -    for (auto Folded : SimplifiedValues)
> -      if (auto FoldedInst = dyn_cast<Instruction>(Folded.first)) {
> +    for (auto &FoldedKeyValue : SimplifiedValues)
> +      if (auto *FoldedInst = dyn_cast<Instruction>(FoldedKeyValue.first))
> {
>          Worklist.push_back(FoldedInst);
>          DeadInstructions.insert(FoldedInst);
>        }
> @@ -516,7 +516,7 @@ public:
>      while (!Worklist.empty()) {
>        Instruction *FoldedInst = Worklist.pop_back_val();
>        for (Value *Op : FoldedInst->operands()) {
> -        if (auto I = dyn_cast<Instruction>(Op)) {
> +        if (auto *I = dyn_cast<Instruction>(Op)) {
>            if (!L->contains(I))
>              continue;
>            if (SimplifiedValues[I])
> @@ -524,7 +524,7 @@ public:
>            if (I->getNumUses() == 0)
>              continue;
>            bool AllUsersFolded = true;
> -          for (auto U : I->users()) {
> +          for (User *U : I->users()) {
>              Instruction *UI = dyn_cast<Instruction>(U);
>              if (!SimplifiedValues[UI] && !DeadInstructions.count(UI)) {
>                AllUsersFolded = false;
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150212/473dd977/attachment.html>


More information about the llvm-commits mailing list