#ifndef MLIR_ANALYSIS_DOMINANCE_H
#define MLIR_ANALYSIS_DOMINANCE_H
-#include "mlir/IR/FunctionGraphTraits.h"
+#include "mlir/IR/RegionGraphTraits.h"
#include "llvm/Support/GenericDomTree.h"
extern template class llvm::DominatorTreeBase<mlir::Block, false>;
using base = llvm::DominatorTreeBase<Block, IsPostDom>;
public:
- DominanceInfoBase(Function function) { recalculate(function); }
+ DominanceInfoBase(Function function);
DominanceInfoBase(Operation *op) { recalculate(op); }
DominanceInfoBase(DominanceInfoBase &&) = default;
DominanceInfoBase &operator=(DominanceInfoBase &&) = default;
InFlightDiagnostic emitRemark();
InFlightDiagnostic emitRemark(const Twine &message);
- /// Displays the CFG in a window. This is for use from the debugger and
- /// depends on Graphviz to generate the graph.
- /// This function is defined in CFGFunctionViewGraph and only works with that
- /// target linked.
- void viewGraph();
-
/// Create a deep copy of this function and all of its blocks, remapping
/// any operands that use values outside of the function using the map that is
/// provided (leaving them alone if no entry is present). If the mapper
/// each operation.
void walk(const std::function<void(Operation *)> &callback);
+ /// Displays the CFG in a window. This is for use from the debugger and
+ /// depends on Graphviz to generate the graph.
+ /// This function is defined in ViewRegionGraph and only works with that
+ /// target linked.
+ void viewGraph(const llvm::Twine ®ionName);
+ void viewGraph();
+
private:
RegionType blocks;
-//===- CFGFunctionGraphTraits.h - llvm::GraphTraits for CFGs ----*- C++ -*-===//
+//===- RegionGraphTraits.h - llvm::GraphTraits for CFGs ---------*- C++ -*-===//
//
// Copyright 2019 The MLIR Authors.
//
//
//===----------------------------------------------------------------------===//
-#ifndef MLIR_IR_CFGFUNCTIONGRAPHTRAITS_H
-#define MLIR_IR_CFGFUNCTIONGRAPHTRAITS_H
+#ifndef MLIR_IR_REGIONGRAPHTRAITS_H
+#define MLIR_IR_REGIONGRAPHTRAITS_H
-#include "mlir/IR/Function.h"
+#include "mlir/IR/Region.h"
#include "llvm/ADT/GraphTraits.h"
namespace llvm {
};
template <>
-struct GraphTraits<mlir::Function *> : public GraphTraits<mlir::Block *> {
- using GraphType = mlir::Function *;
- using NodeRef = mlir::Block *;
-
- static NodeRef getEntryNode(GraphType fn) { return &fn->front(); }
-
- using nodes_iterator = pointer_iterator<mlir::Function::iterator>;
- static nodes_iterator nodes_begin(GraphType fn) {
- return nodes_iterator(fn->begin());
- }
- static nodes_iterator nodes_end(GraphType fn) {
- return nodes_iterator(fn->end());
- }
-};
-
-template <>
-struct GraphTraits<Inverse<mlir::Function *>>
- : public GraphTraits<Inverse<mlir::Block *>> {
- using GraphType = Inverse<mlir::Function *>;
- using NodeRef = NodeRef;
-
- static NodeRef getEntryNode(GraphType fn) { return &fn.Graph->front(); }
-
- using nodes_iterator = pointer_iterator<mlir::Function::iterator>;
- static nodes_iterator nodes_begin(GraphType fn) {
- return nodes_iterator(fn.Graph->begin());
- }
- static nodes_iterator nodes_end(GraphType fn) {
- return nodes_iterator(fn.Graph->end());
- }
-};
-
-template <>
struct GraphTraits<mlir::Region *> : public GraphTraits<mlir::Block *> {
using GraphType = mlir::Region *;
using NodeRef = mlir::Block *;
static NodeRef getEntryNode(GraphType fn) { return &fn->front(); }
- using nodes_iterator = pointer_iterator<mlir::Function::iterator>;
+ using nodes_iterator = pointer_iterator<mlir::Region::iterator>;
static nodes_iterator nodes_begin(GraphType fn) {
return nodes_iterator(fn->begin());
}
static NodeRef getEntryNode(GraphType fn) { return &fn.Graph->front(); }
- using nodes_iterator = pointer_iterator<mlir::Function::iterator>;
+ using nodes_iterator = pointer_iterator<mlir::Region::iterator>;
static nodes_iterator nodes_begin(GraphType fn) {
return nodes_iterator(fn.Graph->begin());
}
-//===- ViewFunctionGraph.h - View/write graphviz graphs ---------*- C++ -*-===//
+//===- ViewRegionGraph.h - View/write graphviz graphs -----------*- C++ -*-===//
//
// Copyright 2019 The MLIR Authors.
//
// limitations under the License.
// =============================================================================
//
-// Defines interface to produce Graphviz outputs of MLIR Functions.
+// Defines interface to produce Graphviz outputs of MLIR Regions.
//
//===----------------------------------------------------------------------===//
#include "llvm/Support/raw_ostream.h"
namespace mlir {
-
-class Function;
class FunctionPassBase;
+class Region;
/// Displays the CFG in a window. This is for use from the debugger and
/// depends on Graphviz to generate the graph.
-void viewGraph(Function function, const Twine &name, bool shortNames = false,
+void viewGraph(Region ®ion, const Twine &name, bool shortNames = false,
const Twine &title = "",
llvm::GraphProgram::Name program = llvm::GraphProgram::DOT);
-llvm::raw_ostream &writeGraph(llvm::raw_ostream &os, Function function,
+llvm::raw_ostream &writeGraph(llvm::raw_ostream &os, Region ®ion,
bool shortNames = false, const Twine &title = "");
/// Creates a pass to print CFG graphs.
//===----------------------------------------------------------------------===//
#include "mlir/Analysis/Dominance.h"
+#include "mlir/IR/Function.h"
#include "mlir/IR/Operation.h"
#include "llvm/Support/GenericDomTreeConstruction.h"
// DominanceInfoBase
//===----------------------------------------------------------------------===//
+template <bool IsPostDom>
+DominanceInfoBase<IsPostDom>::DominanceInfoBase(Function function) {
+ recalculate(function);
+}
+
/// Recalculate the dominance info.
template <bool IsPostDom>
void DominanceInfoBase<IsPostDom>::recalculate(Function function) {
SimplifyAffineStructures.cpp
StripDebugInfo.cpp
Vectorize.cpp
- ViewFunctionGraph.cpp
+ ViewRegionGraph.cpp
ADDITIONAL_HEADER_DIRS
${MLIR_MAIN_INCLUDE_DIR}/mlir/Transforms
-//===- ViewFunctionGraph.cpp - View/write graphviz graphs -----------------===//
+//===- ViewRegionGraph.cpp - View/write graphviz graphs -------------------===//
//
// Copyright 2019 The MLIR Authors.
//
// limitations under the License.
// =============================================================================
-#include "mlir/Transforms/ViewFunctionGraph.h"
-#include "mlir/IR/FunctionGraphTraits.h"
+#include "mlir/Transforms/ViewRegionGraph.h"
+#include "mlir/IR/RegionGraphTraits.h"
#include "mlir/Pass/Pass.h"
using namespace mlir;
namespace llvm {
// Specialize DOTGraphTraits to produce more readable output.
-template <> struct DOTGraphTraits<Function *> : public DefaultDOTGraphTraits {
+template <> struct DOTGraphTraits<Region *> : public DefaultDOTGraphTraits {
using DefaultDOTGraphTraits::DefaultDOTGraphTraits;
- static std::string getNodeLabel(Block *Block, Function *);
+ static std::string getNodeLabel(Block *Block, Region *);
};
-std::string DOTGraphTraits<Function *>::getNodeLabel(Block *Block, Function *) {
+std::string DOTGraphTraits<Region *>::getNodeLabel(Block *Block, Region *) {
// Reuse the print output for the node labels.
std::string outStreamStr;
raw_string_ostream os(outStreamStr);
} // end namespace llvm
-void mlir::viewGraph(Function function, const llvm::Twine &name,
- bool shortNames, const llvm::Twine &title,
+void mlir::viewGraph(Region ®ion, const llvm::Twine &name, bool shortNames,
+ const llvm::Twine &title,
llvm::GraphProgram::Name program) {
- llvm::ViewGraph(&function, name, shortNames, title, program);
+ llvm::ViewGraph(®ion, name, shortNames, title, program);
}
-llvm::raw_ostream &mlir::writeGraph(llvm::raw_ostream &os, Function function,
+llvm::raw_ostream &mlir::writeGraph(llvm::raw_ostream &os, Region ®ion,
bool shortNames, const llvm::Twine &title) {
- return llvm::WriteGraph(os, &function, shortNames, title);
+ return llvm::WriteGraph(os, ®ion, shortNames, title);
}
-void mlir::Function::viewGraph() {
- ::mlir::viewGraph(*this, llvm::Twine("cfgfunc ") + getName().str());
+void mlir::Region::viewGraph(const llvm::Twine ®ionName) {
+ ::mlir::viewGraph(*this, regionName);
}
+void mlir::Region::viewGraph() { viewGraph("region"); }
namespace {
struct PrintCFGPass : public FunctionPass<PrintCFGPass> {
PrintCFGPass(llvm::raw_ostream &os = llvm::errs(), bool shortNames = false,
const llvm::Twine &title = "")
- : os(os), shortNames(shortNames), title(title) {}
+ : os(os), shortNames(shortNames), title(title.str()) {}
void runOnFunction() {
- mlir::writeGraph(os, getFunction(), shortNames, title);
+ mlir::writeGraph(os, getFunction().getBody(), shortNames, title);
}
private:
llvm::raw_ostream &os;
bool shortNames;
- const llvm::Twine &title;
+ std::string title;
};
} // namespace
}
static PassRegistration<PrintCFGPass> pass("print-cfg-graph",
- "Print CFG graph per function");
+ "Print CFG graph per Function");