[llvm] r226836 - Rewrite DIExpression::printInternal() to use the iterator interface.

David Blaikie dblaikie at gmail.com
Thu Jan 22 10:02:17 PST 2015


On Thu, Jan 22, 2015 at 8:55 AM, Adrian Prantl <aprantl at apple.com> wrote:

> Author: adrian
> Date: Thu Jan 22 10:55:22 2015
> New Revision: 226836
>
> URL: http://llvm.org/viewvc/llvm-project?rev=226836&view=rev
> Log:
> Rewrite DIExpression::printInternal() to use the iterator interface.
> NFC.
>
> Modified:
>     llvm/trunk/lib/IR/DebugInfo.cpp
>
> Modified: llvm/trunk/lib/IR/DebugInfo.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/DebugInfo.cpp?rev=226836&r1=226835&r2=226836&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/IR/DebugInfo.cpp (original)
> +++ llvm/trunk/lib/IR/DebugInfo.cpp Thu Jan 22 10:55:22 2015
> @@ -1406,27 +1406,23 @@ void DIVariable::printInternal(raw_ostre
>  }
>
>  void DIExpression::printInternal(raw_ostream &OS) const {
> -  for (unsigned I = 0; I < getNumElements(); ++I) {
> -    uint64_t OpCode = getElement(I);
> +  for (auto E = end(), I = begin(); I != E; ++I) {
> +    uint64_t OpCode = *I;
>      OS << " [" << OperationEncodingString(OpCode);
>      switch (OpCode) {
>      case DW_OP_plus: {
> -      OS << " " << getElement(++I);
> +      OS << " " << I.getArg(1);
>

It's weird to have extra functions on iterators - could the iterator
instead be over a more complete object with the arguments? (this could be a
lightweight object that can be copied, etc)

That change would allow this loop to be the obvious:

  for (ExprNode E : *this)


>        break;
>      }
>      case DW_OP_piece: {
> -      unsigned Offset = getElement(++I);
> -      unsigned Size = getElement(++I);
> -      OS << " offset=" << Offset << ", size=" << Size;
> +      OS << " offset=" << I.getArg(1) << ", size=" << I.getArg(2);
>        break;
>      }
>      case DW_OP_deref:
>        // No arguments.
>        break;
>      default:
> -      // Else bail out early. This may be a line table entry.
> -      OS << "Unknown]";
> -      return;
> +      llvm_unreachable("unhandled operation");
>      }
>      OS << "]";
>    }
>
>
> _______________________________________________
> 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/20150122/2e5c402e/attachment.html>


More information about the llvm-commits mailing list