[PATCH] D19080: allow SSAUpdater to be used for Swift

David Blaikie via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 14 10:04:55 PDT 2016


Could you add a unit test (with comments describing the use case) so this
isn't accidentally broken later?

Would it be possible to refactor the begin/end as ADL begin/end so they'd
work with range-based for? (Or I guess that doesn't work - iteration over
the basic block's phis is a separate range from iterating over the basic
block's instructions? (so there's no authoritative begin/end to provide))
Perhaps it could be refactored as a range type/functor/function instead?
(not sure if that's better)

On Wed, Apr 13, 2016 at 3:41 PM, Bob Wilson via llvm-commits <
llvm-commits at lists.llvm.org> wrote:

> bob.wilson created this revision.
> bob.wilson added reviewers: joker.eph, dexonsmith.
> bob.wilson added a subscriber: llvm-commits.
> Herald added a subscriber: mcrosier.
>
> The SSAUpdater is already implemented as a template so that we can reuse
> it for both IR-level and Machine-level updates. This simple change adds a
> new PhiItT typedef to the traits so that it can also be used for Swift's
> SIL representation, where phis are separate from other instructions.
>
> http://reviews.llvm.org/D19080
>
> Files:
>   include/llvm/Transforms/Utils/SSAUpdaterImpl.h
>   lib/CodeGen/MachineSSAUpdater.cpp
>   lib/Transforms/Utils/SSAUpdater.cpp
>
> Index: lib/Transforms/Utils/SSAUpdater.cpp
> ===================================================================
> --- lib/Transforms/Utils/SSAUpdater.cpp
> +++ lib/Transforms/Utils/SSAUpdater.cpp
> @@ -216,6 +216,11 @@
>    static BlkSucc_iterator BlkSucc_begin(BlkT *BB) { return
> succ_begin(BB); }
>    static BlkSucc_iterator BlkSucc_end(BlkT *BB) { return succ_end(BB); }
>
> +  /// Iterator over phis in a block.
> +  typedef BlkT::iterator PhiItT;
> +  static PhiItT PhiItT_begin(BlkT *BB) { return BB->begin(); }
> +  static PhiItT PhiItT_end(BlkT *BB) { return BB->end(); }
> +
>    class PHI_iterator {
>    private:
>      PHINode *PHI;
> Index: lib/CodeGen/MachineSSAUpdater.cpp
> ===================================================================
> --- lib/CodeGen/MachineSSAUpdater.cpp
> +++ lib/CodeGen/MachineSSAUpdater.cpp
> @@ -246,6 +246,11 @@
>    static BlkSucc_iterator BlkSucc_begin(BlkT *BB) { return
> BB->succ_begin(); }
>    static BlkSucc_iterator BlkSucc_end(BlkT *BB) { return BB->succ_end(); }
>
> +  /// Iterator over phis in a block.
> +  typedef BlkT::iterator PhiItT;
> +  static PhiItT PhiItT_begin(BlkT *BB) { return BB->begin(); }
> +  static PhiItT PhiItT_end(BlkT *BB) { return BB->end(); }
> +
>    /// Iterator for PHI operands.
>    class PHI_iterator {
>    private:
> Index: include/llvm/Transforms/Utils/SSAUpdaterImpl.h
> ===================================================================
> --- include/llvm/Transforms/Utils/SSAUpdaterImpl.h
> +++ include/llvm/Transforms/Utils/SSAUpdaterImpl.h
> @@ -39,6 +39,7 @@
>    typedef typename Traits::BlkT BlkT;
>    typedef typename Traits::ValT ValT;
>    typedef typename Traits::PhiT PhiT;
> +  typedef typename Traits::PhiItT PhiItT;
>
>    /// BBInfo - Per-basic block information used internally by
> SSAUpdaterImpl.
>    /// The predecessors of each block are cached here since pred_iterator
> is
> @@ -377,7 +378,7 @@
>    /// FindExistingPHI - Look through the PHI nodes in a block to see if
> any of
>    /// them match what is needed.
>    void FindExistingPHI(BlkT *BB, BlockListTy *BlockList) {
> -    for (typename BlkT::iterator BBI = BB->begin(), BBE = BB->end();
> +    for (PhiItT BBI = Traits::PhiItT_begin(BB), BBE =
> Traits::PhiItT_end(BB);
>           BBI != BBE; ++BBI) {
>        PhiT *SomePHI = Traits::InstrIsPHI(&*BBI);
>        if (!SomePHI)
>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160414/3cac4136/attachment.html>


More information about the llvm-commits mailing list