@@ -2747,24 +2747,6 @@ pointer from an iterator is very straight-forward. Assuming that ``i`` is a
2747
2747
Instruction * pinst = &*i; // Grab pointer to instruction reference
2748
2748
const Instruction& inst = *j;
2749
2749
2750
- However, the iterators you'll be working with in the LLVM framework are special:
2751
- they will automatically convert to a ptr-to-instance type whenever they need to.
2752
- Instead of dereferencing the iterator and then taking the address of the result,
2753
- you can simply assign the iterator to the proper pointer type and you get the
2754
- dereference and address-of operation as a result of the assignment (behind the
2755
- scenes, this is a result of overloading casting mechanisms). Thus the second
2756
- line of the last example,
2757
-
2758
- .. code-block :: c++
2759
-
2760
- Instruction *pinst = &*i;
2761
-
2762
- is semantically equivalent to
2763
-
2764
- .. code-block :: c++
2765
-
2766
- Instruction *pinst = i;
2767
-
2768
2750
It's also possible to turn a class pointer into the corresponding iterator, and
2769
2751
this is a constant time operation (very efficient). The following code snippet
2770
2752
illustrates use of the conversion constructors provided by LLVM iterators. By
@@ -2779,18 +2761,6 @@ obtaining it via iteration over some structure:
2779
2761
if (it != inst->getParent()->end()) errs() << *it << "\n ";
2780
2762
}
2781
2763
2782
- Unfortunately, these implicit conversions come at a cost; they prevent these
2783
- iterators from conforming to standard iterator conventions, and thus from being
2784
- usable with standard algorithms and containers. For example, they prevent the
2785
- following code, where ``B `` is a ``BasicBlock ``, from compiling:
2786
-
2787
- .. code-block :: c++
2788
-
2789
- llvm::SmallVector<llvm::Instruction *, 16>(B->begin(), B->end());
2790
-
2791
- Because of this, these implicit conversions may be removed some day, and
2792
- ``operator* `` changed to return a pointer instead of a reference.
2793
-
2794
2764
.. _iterate_complex :
2795
2765
2796
2766
Finding call sites: a slightly more complex example
0 commit comments