summaryrefslogtreecommitdiffstats
path: root/mlir/lib/Transforms/Utils
diff options
context:
space:
mode:
authorChris Lattner <clattner@google.com>2018-12-27 11:07:34 -0800
committerjpienaar <jpienaar@google.com>2019-03-29 14:39:49 -0700
commit776b035646d809d8b31662363e797f4d7f26c223 (patch)
tree3578d40e9d40b3d4341d176322925f9da95a51ee /mlir/lib/Transforms/Utils
parenta63f44060151c2dd3c5da28f38e87d464a312959 (diff)
downloadbcm5719-llvm-776b035646d809d8b31662363e797f4d7f26c223.tar.gz
bcm5719-llvm-776b035646d809d8b31662363e797f4d7f26c223.zip
Eliminate the Instruction, BasicBlock, CFGFunction, MLFunction, and ExtFunction classes, using the Statement/StmtBlock hierarchy and Function instead.
This *only* changes the internal data structures, it does not affect the user visible syntax or structure of MLIR code. Function gets new "isCFG()" sorts of predicates as a transitional measure. This patch is gross in a number of ways, largely in an effort to reduce the amount of mechanical churn in one go. It introduces a bunch of using decls to keep the old names alive for now, and a bunch of stuff needs to be renamed. This is step 10/n towards merging instructions and statements, NFC. PiperOrigin-RevId: 227044402
Diffstat (limited to 'mlir/lib/Transforms/Utils')
-rw-r--r--mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp21
-rw-r--r--mlir/lib/Transforms/Utils/Utils.cpp14
2 files changed, 18 insertions, 17 deletions
diff --git a/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp b/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp
index fbde1fd1692..0af7e52b5b1 100644
--- a/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp
+++ b/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp
@@ -172,9 +172,10 @@ void GreedyPatternRewriteDriver::simplifyFunction(Function *currentFunction,
// TODO: If we make terminators into Operations then we could turn this
// into a nice Operation::moveBefore(Operation*) method. We just need the
// guarantee that a block is non-empty.
- if (auto *cfgFunc = dyn_cast<CFGFunction>(currentFunction)) {
- auto &entryBB = cfgFunc->front();
- cast<Instruction>(op)->moveBefore(&entryBB, entryBB.begin());
+ // TODO(clattner): This can all be simplified away now.
+ if (currentFunction->isCFG()) {
+ auto &entryBB = currentFunction->front();
+ cast<OperationInst>(op)->moveBefore(&entryBB, entryBB.begin());
} else {
auto *mlFunc = cast<MLFunction>(currentFunction);
cast<OperationStmt>(op)->moveBefore(mlFunc->getBody(),
@@ -315,7 +316,7 @@ static void processCFGFunction(CFGFunction *fn,
void setInsertionPoint(Operation *op) override {
// Any new operations should be added before this instruction.
- builder.setInsertionPoint(cast<Instruction>(op));
+ builder.setInsertionPoint(cast<OperationInst>(op));
}
private:
@@ -325,7 +326,8 @@ static void processCFGFunction(CFGFunction *fn,
GreedyPatternRewriteDriver driver(std::move(patterns));
for (auto &bb : *fn)
for (auto &op : bb)
- driver.addToWorklist(&op);
+ if (auto *opInst = dyn_cast<OperationStmt>(&op))
+ driver.addToWorklist(opInst);
CFGFuncBuilder cfgBuilder(fn);
CFGFuncRewriter rewriter(driver, cfgBuilder);
@@ -337,9 +339,8 @@ static void processCFGFunction(CFGFunction *fn,
///
void mlir::applyPatternsGreedily(Function *fn,
OwningRewritePatternList &&patterns) {
- if (auto *cfg = dyn_cast<CFGFunction>(fn)) {
- processCFGFunction(cfg, std::move(patterns));
- } else {
- processMLFunction(cast<MLFunction>(fn), std::move(patterns));
- }
+ if (fn->isCFG())
+ processCFGFunction(fn, std::move(patterns));
+ else if (fn->isML())
+ processMLFunction(fn, std::move(patterns));
}
diff --git a/mlir/lib/Transforms/Utils/Utils.cpp b/mlir/lib/Transforms/Utils/Utils.cpp
index 8d375c42ca3..2818e8c2e4f 100644
--- a/mlir/lib/Transforms/Utils/Utils.cpp
+++ b/mlir/lib/Transforms/Utils/Utils.cpp
@@ -438,18 +438,18 @@ void mlir::remapFunctionAttrs(
void mlir::remapFunctionAttrs(
Function &fn, const DenseMap<Attribute, FunctionAttr> &remappingTable) {
// Look at all instructions in a CFGFunction.
- if (auto *cfgFn = dyn_cast<CFGFunction>(&fn)) {
- for (auto &bb : *cfgFn) {
+ if (fn.isCFG()) {
+ for (auto &bb : fn.getBlockList()) {
for (auto &inst : bb) {
- remapFunctionAttrs(inst, remappingTable);
+ if (auto *op = dyn_cast<OperationInst>(&inst))
+ remapFunctionAttrs(*op, remappingTable);
}
}
return;
}
- // Otherwise, look at MLFunctions. We ignore ExtFunctions.
- auto *mlFn = dyn_cast<MLFunction>(&fn);
- if (!mlFn)
+ // Otherwise, look at MLFunctions. We ignore external functions.
+ if (!fn.isML())
return;
struct MLFnWalker : public StmtWalker<MLFnWalker> {
@@ -462,7 +462,7 @@ void mlir::remapFunctionAttrs(
const DenseMap<Attribute, FunctionAttr> &remappingTable;
};
- MLFnWalker(remappingTable).walk(mlFn);
+ MLFnWalker(remappingTable).walk(&fn);
}
void mlir::remapFunctionAttrs(
OpenPOWER on IntegriCloud