[llvm] r202705 - [C++11] Add a basic block range view for RegionInfo
Tobias Grosser
tobias at grosser.es
Mon Mar 3 05:00:39 PST 2014
Author: grosser
Date: Mon Mar 3 07:00:39 2014
New Revision: 202705
URL: http://llvm.org/viewvc/llvm-project?rev=202705&view=rev
Log:
[C++11] Add a basic block range view for RegionInfo
This also switches the users in LLVM to ensure this functionality is tested.
Modified:
llvm/trunk/include/llvm/Analysis/RegionInfo.h
llvm/trunk/lib/Analysis/RegionInfo.cpp
llvm/trunk/lib/Analysis/RegionPass.cpp
llvm/trunk/lib/Analysis/RegionPrinter.cpp
llvm/trunk/lib/Transforms/Scalar/StructurizeCFG.cpp
Modified: llvm/trunk/include/llvm/Analysis/RegionInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/RegionInfo.h?rev=202705&r1=202704&r2=202705&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/RegionInfo.h (original)
+++ llvm/trunk/include/llvm/Analysis/RegionInfo.h Mon Mar 3 07:00:39 2014
@@ -27,6 +27,7 @@
#ifndef LLVM_ANALYSIS_REGIONINFO_H
#define LLVM_ANALYSIS_REGIONINFO_H
+#include "llvm/ADT/iterator_range.h"
#include "llvm/ADT/PointerIntPair.h"
#include "llvm/Analysis/DominanceFrontier.h"
#include "llvm/Analysis/PostDominators.h"
@@ -545,6 +546,21 @@ public:
const_block_iterator block_end() const {
return const_block_iterator();
}
+
+ typedef iterator_range<block_iterator> block_range;
+ typedef iterator_range<const_block_iterator> const_block_range;
+
+ /// @brief Returns a range view of the basic blocks in the region.
+ inline block_range blocks() {
+ return block_range(block_begin(), block_end());
+ }
+
+ /// @brief Returns a range view of the basic blocks in the region.
+ ///
+ /// This is the 'const' version of the range view.
+ inline const_block_range blocks() const {
+ return const_block_range(block_begin(), block_end());
+ }
//@}
/// @name Element Iterators
Modified: llvm/trunk/lib/Analysis/RegionInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/RegionInfo.cpp?rev=202705&r1=202704&r2=202705&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/RegionInfo.cpp (original)
+++ llvm/trunk/lib/Analysis/RegionInfo.cpp Mon Mar 3 07:00:39 2014
@@ -438,8 +438,8 @@ void Region::print(raw_ostream &OS, bool
OS.indent(level*2 + 2);
if (Style == PrintBB) {
- for (const_block_iterator I = block_begin(), E = block_end(); I != E; ++I)
- OS << (*I)->getName() << ", "; // TODO: remove the last ","
+ for (const auto &BB : blocks())
+ OS << BB->getName() << ", "; // TODO: remove the last ","
} else if (Style == PrintRN) {
for (const_element_iterator I = element_begin(), E = element_end(); I!=E; ++I)
OS << **I << ", "; // TODO: remove the last ",
Modified: llvm/trunk/lib/Analysis/RegionPass.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/RegionPass.cpp?rev=202705&r1=202704&r2=202705&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/RegionPass.cpp (original)
+++ llvm/trunk/lib/Analysis/RegionPass.cpp Mon Mar 3 07:00:39 2014
@@ -195,9 +195,8 @@ public:
virtual bool runOnRegion(Region *R, RGPassManager &RGM) {
Out << Banner;
- for (Region::block_iterator I = R->block_begin(), E = R->block_end();
- I != E; ++I)
- (*I)->print(Out);
+ for (const auto &BB : R->blocks())
+ BB->print(Out);
return false;
}
Modified: llvm/trunk/lib/Analysis/RegionPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/RegionPrinter.cpp?rev=202705&r1=202704&r2=202705&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/RegionPrinter.cpp (original)
+++ llvm/trunk/lib/Analysis/RegionPrinter.cpp Mon Mar 3 07:00:39 2014
@@ -121,11 +121,10 @@ struct DOTGraphTraits<RegionInfo*> : pub
RegionInfo *RI = R->getRegionInfo();
- for (Region::const_block_iterator BI = R->block_begin(),
- BE = R->block_end(); BI != BE; ++BI)
- if (RI->getRegionFor(*BI) == R)
+ for (const auto &BB : R->blocks())
+ if (RI->getRegionFor(BB) == R)
O.indent(2 * (depth + 1)) << "Node"
- << static_cast<const void*>(RI->getTopLevelRegion()->getBBNode(*BI))
+ << static_cast<const void*>(RI->getTopLevelRegion()->getBBNode(BB))
<< ";\n";
O.indent(2 * depth) << "}\n";
Modified: llvm/trunk/lib/Transforms/Scalar/StructurizeCFG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/StructurizeCFG.cpp?rev=202705&r1=202704&r2=202705&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/StructurizeCFG.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/StructurizeCFG.cpp Mon Mar 3 07:00:39 2014
@@ -829,11 +829,7 @@ void StructurizeCFG::createFlow() {
/// no longer dominate all their uses. Not sure if this is really nessasary
void StructurizeCFG::rebuildSSA() {
SSAUpdater Updater;
- for (Region::block_iterator I = ParentRegion->block_begin(),
- E = ParentRegion->block_end();
- I != E; ++I) {
-
- BasicBlock *BB = *I;
+ for (const auto &BB : ParentRegion->blocks())
for (BasicBlock::iterator II = BB->begin(), IE = BB->end();
II != IE; ++II) {
@@ -864,7 +860,6 @@ void StructurizeCFG::rebuildSSA() {
Updater.RewriteUseAfterInsertions(*I);
}
}
- }
}
/// \brief Run the transformation for each region found
More information about the llvm-commits
mailing list