[llvm] r188876 - MC CFG: Add more MCFunction container methods (find, empty).

David Blaikie dblaikie at gmail.com
Wed Aug 21 10:23:10 PDT 2013


On Wed, Aug 21, 2013 at 12:27 AM, Ahmed Bougacha
<ahmed.bougacha at gmail.com> wrote:
> Author: ab
> Date: Wed Aug 21 02:27:59 2013
> New Revision: 188876
>
> URL: http://llvm.org/viewvc/llvm-project?rev=188876&view=rev
> Log:
> MC CFG: Add more MCFunction container methods (find, empty).
>
> Modified:
>     llvm/trunk/include/llvm/MC/MCFunction.h
>     llvm/trunk/lib/MC/MCFunction.cpp
>
> Modified: llvm/trunk/include/llvm/MC/MCFunction.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCFunction.h?rev=188876&r1=188875&r2=188876&view=diff
> ==============================================================================
> --- llvm/trunk/include/llvm/MC/MCFunction.h (original)
> +++ llvm/trunk/include/llvm/MC/MCFunction.h Wed Aug 21 02:27:59 2013
> @@ -97,13 +97,15 @@ public:
>
>    StringRef getName() const { return Name; }
>
> -  /// \name Access to the function's basic blocks. No ordering is enforced.
> +  /// \name Access to the function's basic blocks. No ordering is enforced,
> +  /// except that the first block is the entry block.
>    /// @{
>    /// \brief Get the entry point basic block.
>    const MCBasicBlock *getEntryBlock() const { return front(); }
>          MCBasicBlock *getEntryBlock()       { return front(); }
>
> -  // NOTE: Dereferencing iterators gives pointers, so maybe a list is best here.
> +  bool empty() const { return Blocks.empty(); }
> +
>    typedef BasicBlockListTy::const_iterator const_iterator;
>    typedef BasicBlockListTy::      iterator       iterator;
>    const_iterator begin() const { return Blocks.begin(); }
> @@ -115,6 +117,10 @@ public:
>          MCBasicBlock* front()       { return Blocks.front(); }
>    const MCBasicBlock*  back() const { return Blocks.back(); }
>          MCBasicBlock*  back()       { return Blocks.back(); }
> +
> +  /// \brief Find the basic block, if any, that starts at \p StartAddr.
> +  const MCBasicBlock *find(uint64_t StartAddr) const;
> +        MCBasicBlock *find(uint64_t StartAddr);
>    /// @}
>  };
>
>
> Modified: llvm/trunk/lib/MC/MCFunction.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCFunction.cpp?rev=188876&r1=188875&r2=188876&view=diff
> ==============================================================================
> --- llvm/trunk/lib/MC/MCFunction.cpp (original)
> +++ llvm/trunk/lib/MC/MCFunction.cpp Wed Aug 21 02:27:59 2013
> @@ -30,6 +30,18 @@ MCBasicBlock &MCFunction::createBlock(co
>    return *Blocks.back();
>  }
>
> +const MCBasicBlock *MCFunction::find(uint64_t StartAddr) const {
> +  for (const_iterator I = begin(), E = end(); I != E; ++I)
> +    if ((*I)->getInsts()->getBeginAddr() == StartAddr)
> +      return (*I);

Unnecessary parentheses.

> +  return 0;
> +}
> +
> +MCBasicBlock *MCFunction::find(uint64_t StartAddr) {
> +  return const_cast<MCBasicBlock *>(
> +           const_cast<const MCFunction *>(this)->find(StartAddr));

You could do this with one fewer cast if you wrote the implementation
in the non-const function and called that from the const version
(you'd only need to cast away constness from 'this' and then rely on
implicit conversion to const on the return).

> +}
> +
>  // MCBasicBlock
>
>  MCBasicBlock::MCBasicBlock(const MCTextAtom &Insts, MCFunction *Parent)
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits



More information about the llvm-commits mailing list