summaryrefslogtreecommitdiffstats
path: root/mlir/lib
diff options
context:
space:
mode:
authorRiver Riddle <riverriddle@google.com>2019-06-04 19:18:23 -0700
committerMehdi Amini <joker.eph@gmail.com>2019-06-09 16:17:59 -0700
commitf1b848e4701a4cd3fa781c259e3728faff1c31df (patch)
tree5587429894d04d9e78eb0e91b76aea3003c94bd1 /mlir/lib
parentf59f64e838c82399f7b31949e8de75547223f42b (diff)
downloadbcm5719-llvm-f1b848e4701a4cd3fa781c259e3728faff1c31df.tar.gz
bcm5719-llvm-f1b848e4701a4cd3fa781c259e3728faff1c31df.zip
NFC: Rename FuncBuilder to OpBuilder and refactor to take a top level region instead of a function.
PiperOrigin-RevId: 251563898
Diffstat (limited to 'mlir/lib')
-rw-r--r--mlir/lib/AffineOps/AffineOps.cpp6
-rw-r--r--mlir/lib/Analysis/LoopAnalysis.cpp2
-rw-r--r--mlir/lib/Analysis/TestParallelismDetection.cpp2
-rw-r--r--mlir/lib/Analysis/Utils.cpp2
-rw-r--r--mlir/lib/EDSC/Builders.cpp9
-rw-r--r--mlir/lib/GPU/Transforms/KernelOutlining.cpp16
-rw-r--r--mlir/lib/IR/Block.cpp18
-rw-r--r--mlir/lib/IR/Builders.cpp12
-rw-r--r--mlir/lib/IR/Function.cpp4
-rw-r--r--mlir/lib/IR/Operation.cpp3
-rw-r--r--mlir/lib/LLVMIR/Transforms/ConvertToLLVMDialect.cpp2
-rw-r--r--mlir/lib/Linalg/IR/LinalgOps.cpp2
-rw-r--r--mlir/lib/Linalg/Transforms/LowerToLLVMDialect.cpp2
-rw-r--r--mlir/lib/Linalg/Transforms/LowerToLoops.cpp4
-rw-r--r--mlir/lib/Linalg/Transforms/Tiling.cpp6
-rw-r--r--mlir/lib/Linalg/Utils/Utils.cpp6
-rw-r--r--mlir/lib/Parser/Parser.cpp4
-rw-r--r--mlir/lib/Quantizer/Transforms/AddDefaultStatsTestPass.cpp4
-rw-r--r--mlir/lib/Quantizer/Transforms/InferQuantizedTypesPass.cpp4
-rw-r--r--mlir/lib/Transforms/DialectConversion.cpp8
-rw-r--r--mlir/lib/Transforms/DmaGeneration.cpp10
-rw-r--r--mlir/lib/Transforms/LoopFusion.cpp4
-rw-r--r--mlir/lib/Transforms/LoopInvariantCodeMotion.cpp2
-rw-r--r--mlir/lib/Transforms/LoopTiling.cpp6
-rw-r--r--mlir/lib/Transforms/LoopUnrollAndJam.cpp5
-rw-r--r--mlir/lib/Transforms/LowerAffine.cpp16
-rw-r--r--mlir/lib/Transforms/MaterializeVectors.cpp14
-rw-r--r--mlir/lib/Transforms/PipelineDataTransfer.cpp6
-rw-r--r--mlir/lib/Transforms/Utils/FoldUtils.cpp2
-rw-r--r--mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp12
-rw-r--r--mlir/lib/Transforms/Utils/LoopUtils.cpp25
-rw-r--r--mlir/lib/Transforms/Utils/Utils.cpp4
-rw-r--r--mlir/lib/Transforms/Vectorization/VectorizerTestPass.cpp2
-rw-r--r--mlir/lib/Transforms/Vectorize.cpp10
34 files changed, 124 insertions, 110 deletions
diff --git a/mlir/lib/AffineOps/AffineOps.cpp b/mlir/lib/AffineOps/AffineOps.cpp
index 28594a34d45..9189acf5f50 100644
--- a/mlir/lib/AffineOps/AffineOps.cpp
+++ b/mlir/lib/AffineOps/AffineOps.cpp
@@ -544,7 +544,7 @@ void mlir::fullyComposeAffineMapAndOperands(
}
}
-AffineApplyOp mlir::makeComposedAffineApply(FuncBuilder *b, Location loc,
+AffineApplyOp mlir::makeComposedAffineApply(OpBuilder *b, Location loc,
AffineMap map,
ArrayRef<Value *> operands) {
AffineMap normalizedMap = map;
@@ -1069,9 +1069,9 @@ void AffineForOp::getCanonicalizationPatterns(OwningRewritePatternList &results,
results.push_back(llvm::make_unique<AffineForLoopBoundFolder>(context));
}
-FuncBuilder AffineForOp::getBodyBuilder() {
+OpBuilder AffineForOp::getBodyBuilder() {
Block *body = getBody();
- return FuncBuilder(body, std::prev(body->end()));
+ return OpBuilder(body, std::prev(body->end()));
}
AffineBound AffineForOp::getLowerBound() {
diff --git a/mlir/lib/Analysis/LoopAnalysis.cpp b/mlir/lib/Analysis/LoopAnalysis.cpp
index 117cf6e109e..16e092b8205 100644
--- a/mlir/lib/Analysis/LoopAnalysis.cpp
+++ b/mlir/lib/Analysis/LoopAnalysis.cpp
@@ -54,7 +54,7 @@ void mlir::buildTripCountMapAndOperands(
int64_t loopSpan;
int64_t step = forOp.getStep();
- FuncBuilder b(forOp.getOperation());
+ OpBuilder b(forOp.getOperation());
if (forOp.hasConstantBounds()) {
int64_t lb = forOp.getConstantLowerBound();
diff --git a/mlir/lib/Analysis/TestParallelismDetection.cpp b/mlir/lib/Analysis/TestParallelismDetection.cpp
index ae5551db215..cbda6d40224 100644
--- a/mlir/lib/Analysis/TestParallelismDetection.cpp
+++ b/mlir/lib/Analysis/TestParallelismDetection.cpp
@@ -44,7 +44,7 @@ FunctionPassBase *mlir::createParallelismDetectionTestPass() {
// parallel.
void TestParallelismDetection::runOnFunction() {
Function &f = getFunction();
- FuncBuilder b(f);
+ OpBuilder b(f.getBody());
f.walk<AffineForOp>([&](AffineForOp forOp) {
if (isLoopParallel(forOp))
forOp.emitRemark("parallel loop");
diff --git a/mlir/lib/Analysis/Utils.cpp b/mlir/lib/Analysis/Utils.cpp
index 476c7c87aec..aa842364f26 100644
--- a/mlir/lib/Analysis/Utils.cpp
+++ b/mlir/lib/Analysis/Utils.cpp
@@ -749,7 +749,7 @@ mlir::insertBackwardComputationSlice(Operation *srcOpInst, Operation *dstOpInst,
// Clone src loop nest and insert it a the beginning of the operation block
// of the loop at 'dstLoopDepth' in 'dstLoopIVs'.
auto dstAffineForOp = dstLoopIVs[dstLoopDepth - 1];
- FuncBuilder b(dstAffineForOp.getBody(), dstAffineForOp.getBody()->begin());
+ OpBuilder b(dstAffineForOp.getBody(), dstAffineForOp.getBody()->begin());
auto sliceLoopNest =
cast<AffineForOp>(b.clone(*srcLoopIVs[0].getOperation()));
diff --git a/mlir/lib/EDSC/Builders.cpp b/mlir/lib/EDSC/Builders.cpp
index 22f91399498..6f6363ffcc5 100644
--- a/mlir/lib/EDSC/Builders.cpp
+++ b/mlir/lib/EDSC/Builders.cpp
@@ -24,8 +24,7 @@
using namespace mlir;
using namespace mlir::edsc;
-mlir::edsc::ScopedContext::ScopedContext(FuncBuilder &builder,
- Location location)
+mlir::edsc::ScopedContext::ScopedContext(OpBuilder &builder, Location location)
: builder(builder), location(location),
enclosingScopedContext(ScopedContext::getCurrentScopedContext()),
nestedBuilder(nullptr) {
@@ -35,8 +34,8 @@ mlir::edsc::ScopedContext::ScopedContext(FuncBuilder &builder,
/// Sets the insertion point of the builder to 'newInsertPt' for the duration
/// of the scope. The existing insertion point of the builder is restored on
/// destruction.
-mlir::edsc::ScopedContext::ScopedContext(FuncBuilder &builder,
- FuncBuilder::InsertPoint newInsertPt,
+mlir::edsc::ScopedContext::ScopedContext(OpBuilder &builder,
+ OpBuilder::InsertPoint newInsertPt,
Location location)
: builder(builder), prevBuilderInsertPoint(builder.saveInsertionPoint()),
location(location),
@@ -59,7 +58,7 @@ ScopedContext *&mlir::edsc::ScopedContext::getCurrentScopedContext() {
return context;
}
-FuncBuilder *mlir::edsc::ScopedContext::getBuilder() {
+OpBuilder *mlir::edsc::ScopedContext::getBuilder() {
assert(ScopedContext::getCurrentScopedContext() &&
"Unexpected Null ScopedContext");
return &ScopedContext::getCurrentScopedContext()->builder;
diff --git a/mlir/lib/GPU/Transforms/KernelOutlining.cpp b/mlir/lib/GPU/Transforms/KernelOutlining.cpp
index 163a7cf6b6c..86fab1a20f1 100644
--- a/mlir/lib/GPU/Transforms/KernelOutlining.cpp
+++ b/mlir/lib/GPU/Transforms/KernelOutlining.cpp
@@ -30,7 +30,7 @@ using namespace mlir;
namespace {
template <typename OpTy>
-void createForAllDimensions(FuncBuilder &builder, Location loc,
+void createForAllDimensions(OpBuilder &builder, Location loc,
SmallVectorImpl<Value *> &values) {
for (StringRef dim : {"x", "y", "z"}) {
Value *v = builder.create<OpTy>(loc, builder.getIndexType(),
@@ -42,12 +42,12 @@ void createForAllDimensions(FuncBuilder &builder, Location loc,
// Add operations generating block/thread ids and gird/block dimensions at the
// beginning of `kernelFunc` and replace uses of the respective function args.
void injectGpuIndexOperations(Location loc, Function &kernelFunc) {
- FuncBuilder funcBuilder(kernelFunc);
+ OpBuilder OpBuilder(kernelFunc.getBody());
SmallVector<Value *, 12> indexOps;
- createForAllDimensions<gpu::BlockId>(funcBuilder, loc, indexOps);
- createForAllDimensions<gpu::ThreadId>(funcBuilder, loc, indexOps);
- createForAllDimensions<gpu::GridDim>(funcBuilder, loc, indexOps);
- createForAllDimensions<gpu::BlockDim>(funcBuilder, loc, indexOps);
+ createForAllDimensions<gpu::BlockId>(OpBuilder, loc, indexOps);
+ createForAllDimensions<gpu::ThreadId>(OpBuilder, loc, indexOps);
+ createForAllDimensions<gpu::GridDim>(OpBuilder, loc, indexOps);
+ createForAllDimensions<gpu::BlockDim>(OpBuilder, loc, indexOps);
// Replace the leading 12 function args with the respective thread/block index
// operations. Iterate backwards since args are erased and indices change.
for (int i = 11; i >= 0; --i) {
@@ -78,10 +78,10 @@ Function *outlineKernelFunc(Module &module, gpu::LaunchOp &launchOp) {
// Replace `gpu.launch` operations with an `gpu.launch_func` operation launching
// `kernelFunc`.
void convertToLaunchFuncOp(gpu::LaunchOp &launchOp, Function &kernelFunc) {
- FuncBuilder funcBuilder(launchOp);
+ OpBuilder OpBuilder(launchOp);
SmallVector<Value *, 4> kernelOperandValues(
launchOp.getKernelOperandValues());
- funcBuilder.create<gpu::LaunchFuncOp>(
+ OpBuilder.create<gpu::LaunchFuncOp>(
launchOp.getLoc(), &kernelFunc, launchOp.getGridSizeOperandValues(),
launchOp.getBlockSizeOperandValues(), kernelOperandValues);
launchOp.erase();
diff --git a/mlir/lib/IR/Block.cpp b/mlir/lib/IR/Block.cpp
index cf85cc86ef0..9595a72c226 100644
--- a/mlir/lib/IR/Block.cpp
+++ b/mlir/lib/IR/Block.cpp
@@ -282,6 +282,24 @@ Region::~Region() {
bb.dropAllReferences();
}
+/// Return the context this region is inserted in. The region must have a valid
+/// parent container.
+MLIRContext *Region::getContext() {
+ assert(!container.isNull() && "region is not attached to a container");
+ if (auto *inst = getContainingOp())
+ return inst->getContext();
+ return getContainingFunction()->getContext();
+}
+
+/// Return a location for this region. This is the location attached to the
+/// parent container. The region must have a valid parent container.
+Location Region::getLoc() {
+ assert(!container.isNull() && "region is not attached to a container");
+ if (auto *inst = getContainingOp())
+ return inst->getLoc();
+ return getContainingFunction()->getLoc();
+}
+
Region *Region::getContainingRegion() {
if (auto *inst = getContainingOp())
return inst->getContainingRegion();
diff --git a/mlir/lib/IR/Builders.cpp b/mlir/lib/IR/Builders.cpp
index 4accfb54e28..d32e705785a 100644
--- a/mlir/lib/IR/Builders.cpp
+++ b/mlir/lib/IR/Builders.cpp
@@ -332,31 +332,31 @@ AffineMap Builder::getShiftedAffineMap(AffineMap map, int64_t shift) {
}
//===----------------------------------------------------------------------===//
-// Operations.
+// OpBuilder.
//===----------------------------------------------------------------------===//
-FuncBuilder::~FuncBuilder() {}
+OpBuilder::~OpBuilder() {}
/// Add new block and set the insertion point to the end of it. If an
/// 'insertBefore' block is passed, the block will be placed before the
/// specified block. If not, the block will be appended to the end of the
/// current function.
-Block *FuncBuilder::createBlock(Block *insertBefore) {
+Block *OpBuilder::createBlock(Block *insertBefore) {
Block *b = new Block();
// If we are supposed to insert before a specific block, do so, otherwise add
// the block to the end of the function.
if (insertBefore)
- function->getBlocks().insert(Function::iterator(insertBefore), b);
+ region->getBlocks().insert(Function::iterator(insertBefore), b);
else
- function->push_back(b);
+ region->push_back(b);
setInsertionPointToEnd(b);
return b;
}
/// Create an operation given the fields represented as an OperationState.
-Operation *FuncBuilder::createOperation(const OperationState &state) {
+Operation *OpBuilder::createOperation(const OperationState &state) {
assert(block && "createOperation() called without setting builder's block");
auto *op = Operation::create(state);
block->getOperations().insert(insertPoint, op);
diff --git a/mlir/lib/IR/Function.cpp b/mlir/lib/IR/Function.cpp
index f53c7156825..6ab5a6febf0 100644
--- a/mlir/lib/IR/Function.cpp
+++ b/mlir/lib/IR/Function.cpp
@@ -214,9 +214,7 @@ void Function::addEntryBlock() {
}
void Function::walk(const std::function<void(Operation *)> &callback) {
- // Walk each of the blocks within the function.
- for (auto &block : getBlocks())
- block.walk(callback);
+ getBody().walk(callback);
}
//===----------------------------------------------------------------------===//
diff --git a/mlir/lib/IR/Operation.cpp b/mlir/lib/IR/Operation.cpp
index 64fb8bcd0e2..5804770a88f 100644
--- a/mlir/lib/IR/Operation.cpp
+++ b/mlir/lib/IR/Operation.cpp
@@ -312,8 +312,7 @@ void Operation::replaceUsesOfWith(Value *from, Value *to) {
void Operation::walk(const std::function<void(Operation *)> &callback) {
// Visit any internal operations.
for (auto &region : getRegions())
- for (auto &block : region)
- block.walk(callback);
+ region.walk(callback);
// Visit the current operation.
callback(this);
diff --git a/mlir/lib/LLVMIR/Transforms/ConvertToLLVMDialect.cpp b/mlir/lib/LLVMIR/Transforms/ConvertToLLVMDialect.cpp
index 0e30a8e147e..1b50320071c 100644
--- a/mlir/lib/LLVMIR/Transforms/ConvertToLLVMDialect.cpp
+++ b/mlir/lib/LLVMIR/Transforms/ConvertToLLVMDialect.cpp
@@ -889,7 +889,7 @@ static void ensureDistinctSuccessors(Block &bb) {
position != end; ++position) {
auto *dummyBlock = new Block();
bb.getParent()->push_back(dummyBlock);
- auto builder = FuncBuilder(dummyBlock);
+ auto builder = OpBuilder(dummyBlock);
SmallVector<Value *, 8> operands(
terminator->getSuccessorOperands(*position));
builder.create<BranchOp>(terminator->getLoc(), successor.first, operands);
diff --git a/mlir/lib/Linalg/IR/LinalgOps.cpp b/mlir/lib/Linalg/IR/LinalgOps.cpp
index 55a791a6d63..3b3a04012fd 100644
--- a/mlir/lib/Linalg/IR/LinalgOps.cpp
+++ b/mlir/lib/Linalg/IR/LinalgOps.cpp
@@ -773,7 +773,7 @@ void mlir::linalg::emitScalarImplementation(
using edsc::intrinsics::select;
// account for affine.terminator in loop.
- FuncBuilder b(body, std::prev(body->end(), 1));
+ OpBuilder b(body, std::prev(body->end(), 1));
ScopedContext scope(b, innermostLoop.getLoc());
auto *op = linalgOp.getOperation();
if (isa<DotOp>(op)) {
diff --git a/mlir/lib/Linalg/Transforms/LowerToLLVMDialect.cpp b/mlir/lib/Linalg/Transforms/LowerToLLVMDialect.cpp
index 60c0daf7938..b3857ac5171 100644
--- a/mlir/lib/Linalg/Transforms/LowerToLLVMDialect.cpp
+++ b/mlir/lib/Linalg/Transforms/LowerToLLVMDialect.cpp
@@ -621,7 +621,7 @@ static void lowerLinalgForToCFG(Function &f) {
auto *op = forOp.getOperation();
auto loc = op->getLoc();
using namespace edsc::op;
- FuncBuilder builder(op);
+ OpBuilder builder(op);
ScopedContext scope(builder, loc);
ValueHandle lb(forOp.getLowerBound()), ub(forOp.getUpperBound()),
step(forOp.getStep());
diff --git a/mlir/lib/Linalg/Transforms/LowerToLoops.cpp b/mlir/lib/Linalg/Transforms/LowerToLoops.cpp
index b2f59c43da1..5e22f8601fc 100644
--- a/mlir/lib/Linalg/Transforms/LowerToLoops.cpp
+++ b/mlir/lib/Linalg/Transforms/LowerToLoops.cpp
@@ -35,7 +35,7 @@ using namespace mlir::linalg;
// Creates a number of ranges equal to the number of results in `map`.
// The returned ranges correspond to the loop ranges, in the proper order, for
// which new loops will be created.
-static SmallVector<Value *, 4> emitLoopRanges(FuncBuilder *b, Location loc,
+static SmallVector<Value *, 4> emitLoopRanges(OpBuilder *b, Location loc,
AffineMap map,
ArrayRef<Value *> allViewSizes,
FunctionConstants &state) {
@@ -51,7 +51,7 @@ static SmallVector<Value *, 4> emitLoopRanges(FuncBuilder *b, Location loc,
}
static void emitLinalgOpAsLoops(LinalgOp &linalgOp, FunctionConstants &state) {
- FuncBuilder b(linalgOp.getOperation());
+ OpBuilder b(linalgOp.getOperation());
ScopedContext scope(b, linalgOp.getOperation()->getLoc());
auto loopRanges = emitLoopRanges(
scope.getBuilder(), scope.getLocation(),
diff --git a/mlir/lib/Linalg/Transforms/Tiling.cpp b/mlir/lib/Linalg/Transforms/Tiling.cpp
index 22090ca6aac..bc2ed2b60de 100644
--- a/mlir/lib/Linalg/Transforms/Tiling.cpp
+++ b/mlir/lib/Linalg/Transforms/Tiling.cpp
@@ -58,7 +58,7 @@ static bool isZero(Value *v) {
// The returned ranges correspond to the loop ranges, in the proper order, that
// are tiled and for which new loops will be created.
static SmallVector<Value *, 4>
-makeTiledLoopRanges(FuncBuilder *b, Location loc, AffineMap map,
+makeTiledLoopRanges(OpBuilder *b, Location loc, AffineMap map,
ArrayRef<Value *> allViewSizes,
ArrayRef<Value *> allTileSizes, FunctionConstants &state) {
assert(allTileSizes.size() == map.getNumResults());
@@ -127,7 +127,7 @@ static Value *foldRange(Value *view, unsigned dim) {
return nullptr;
}
-static SmallVector<Value *, 4> makeTiledViews(FuncBuilder *b, Location loc,
+static SmallVector<Value *, 4> makeTiledViews(OpBuilder *b, Location loc,
LinalgOp &linalgOp,
ArrayRef<Value *> ivs,
ArrayRef<Value *> tileSizes,
@@ -210,7 +210,7 @@ static LogicalResult tileLinalgOp(LinalgOp &op, ArrayRef<Value *> tileSizes,
tileSizes.size() &&
"expected matching number of tile sizes and loops");
- FuncBuilder builder(op.getOperation());
+ OpBuilder builder(op.getOperation());
ScopedContext scope(builder, op.getLoc());
auto loopRanges = makeTiledLoopRanges(
scope.getBuilder(), scope.getLocation(),
diff --git a/mlir/lib/Linalg/Utils/Utils.cpp b/mlir/lib/Linalg/Utils/Utils.cpp
index f19e61c5531..81fad1c870a 100644
--- a/mlir/lib/Linalg/Utils/Utils.cpp
+++ b/mlir/lib/Linalg/Utils/Utils.cpp
@@ -109,7 +109,7 @@ static Value *tryFold(AffineMap map, ArrayRef<Value *> operands,
return nullptr;
}
-static Value *emitOrFoldComposedAffineApply(FuncBuilder *b, Location loc,
+static Value *emitOrFoldComposedAffineApply(OpBuilder *b, Location loc,
AffineMap map,
ArrayRef<Value *> operandsRef,
FunctionConstants &state) {
@@ -121,7 +121,7 @@ static Value *emitOrFoldComposedAffineApply(FuncBuilder *b, Location loc,
}
SmallVector<Value *, 4>
-mlir::linalg::applyMapToValues(FuncBuilder *b, Location loc, AffineMap map,
+mlir::linalg::applyMapToValues(OpBuilder *b, Location loc, AffineMap map,
ArrayRef<Value *> values,
FunctionConstants &state) {
SmallVector<Value *, 4> res;
@@ -141,7 +141,7 @@ Value *FunctionConstants::getOrCreateIndex(int64_t v) {
auto it = map.find(v);
if (it != map.end())
return it->second;
- FuncBuilder builder(f);
+ OpBuilder builder(f.getBody());
edsc::ScopedContext s(builder, f.getLoc());
return map.insert(std::make_pair(v, edsc::intrinsics::constant_index(v)))
.first->getSecond();
diff --git a/mlir/lib/Parser/Parser.cpp b/mlir/lib/Parser/Parser.cpp
index 6cc933a8169..a3d44f9935e 100644
--- a/mlir/lib/Parser/Parser.cpp
+++ b/mlir/lib/Parser/Parser.cpp
@@ -2302,11 +2302,11 @@ public:
/// more specific builder type.
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wshadow-field"
- FuncBuilder builder;
+ OpBuilder builder;
#pragma clang diagnostic pop
FunctionParser(ParserState &state, Function *function)
- : Parser(state), builder(function), function(function) {}
+ : Parser(state), builder(function->getBody()), function(function) {}
~FunctionParser();
diff --git a/mlir/lib/Quantizer/Transforms/AddDefaultStatsTestPass.cpp b/mlir/lib/Quantizer/Transforms/AddDefaultStatsTestPass.cpp
index 75c082fd8ce..375a64d8f2d 100644
--- a/mlir/lib/Quantizer/Transforms/AddDefaultStatsTestPass.cpp
+++ b/mlir/lib/Quantizer/Transforms/AddDefaultStatsTestPass.cpp
@@ -77,7 +77,7 @@ void AddDefaultStatsPass::runWithConfig(SolverContext &solverContext,
for (auto *arg : func.getArguments()) {
if (!config.isHandledType(arg->getType()))
continue;
- FuncBuilder b(func);
+ OpBuilder b(func.getBody());
APFloat minValue(-1.0f);
APFloat maxValue(1.0f);
ElementsAttr layerStats = DenseFPElementsAttr::get(
@@ -102,7 +102,7 @@ void AddDefaultStatsPass::runWithConfig(SolverContext &solverContext,
if (!config.isHandledType(originalResult->getType()))
return;
- FuncBuilder b(op->getBlock(), ++op->getIterator());
+ OpBuilder b(op->getBlock(), ++op->getIterator());
APFloat minValue(-1.0f);
APFloat maxValue(1.0f);
diff --git a/mlir/lib/Quantizer/Transforms/InferQuantizedTypesPass.cpp b/mlir/lib/Quantizer/Transforms/InferQuantizedTypesPass.cpp
index 94bac98598c..c443354714f 100644
--- a/mlir/lib/Quantizer/Transforms/InferQuantizedTypesPass.cpp
+++ b/mlir/lib/Quantizer/Transforms/InferQuantizedTypesPass.cpp
@@ -184,7 +184,7 @@ void InferQuantizedTypesPass::transformOperandType(CAGOperandAnchor *anchor,
Type newType) {
Value *inputValue = anchor->getValue();
Operation *op = anchor->getOp();
- FuncBuilder b(op->getBlock(), Block::iterator(op));
+ OpBuilder b(op->getBlock(), Block::iterator(op));
SmallVector<Value *, 1> removeValuesIfDead;
@@ -240,7 +240,7 @@ void InferQuantizedTypesPass::transformResultType(CAGResultAnchor *anchor,
Type newType) {
Value *origResultValue = anchor->getValue();
Operation *op = origResultValue->getDefiningOp();
- FuncBuilder b(op->getBlock(), ++Block::iterator(op));
+ OpBuilder b(op->getBlock(), ++Block::iterator(op));
Value *replacedResultValue = nullptr;
Value *newResultValue = nullptr;
diff --git a/mlir/lib/Transforms/DialectConversion.cpp b/mlir/lib/Transforms/DialectConversion.cpp
index 6002cadd37d..1deedc1520c 100644
--- a/mlir/lib/Transforms/DialectConversion.cpp
+++ b/mlir/lib/Transforms/DialectConversion.cpp
@@ -108,8 +108,8 @@ struct DialectConversionRewriter final : public PatternRewriter {
SmallVector<Value *, 2> newValues;
};
- DialectConversionRewriter(Function *fn)
- : PatternRewriter(fn), argConverter(fn->getContext()) {}
+ DialectConversionRewriter(Region &region)
+ : PatternRewriter(region), argConverter(region.getContext()) {}
~DialectConversionRewriter() = default;
/// Cleanup and destroy any generated rewrite operations. This method is
@@ -151,7 +151,7 @@ struct DialectConversionRewriter final : public PatternRewriter {
/// PatternRewriter hook for creating a new operation.
Operation *createOperation(const OperationState &state) override {
- auto *result = FuncBuilder::createOperation(state);
+ auto *result = OpBuilder::createOperation(state);
createdOps.push_back(result);
return result;
}
@@ -572,7 +572,7 @@ LogicalResult FunctionConverter::convertFunction(Function *f) {
return success();
// Rewrite the function body.
- DialectConversionRewriter rewriter(f);
+ DialectConversionRewriter rewriter(f->getBody());
if (failed(convertRegion(rewriter, f->getBody(), f->getLoc()))) {
// Reset any of the generated rewrites.
rewriter.discardRewrites();
diff --git a/mlir/lib/Transforms/DmaGeneration.cpp b/mlir/lib/Transforms/DmaGeneration.cpp
index 1ead2e5c8e2..7c745aa1a0b 100644
--- a/mlir/lib/Transforms/DmaGeneration.cpp
+++ b/mlir/lib/Transforms/DmaGeneration.cpp
@@ -240,14 +240,14 @@ bool DmaGeneration::generateDma(const MemRefRegion &region, Block *block,
return true;
// DMAs for read regions are going to be inserted just before the for loop.
- FuncBuilder prologue(block, begin);
+ OpBuilder prologue(block, begin);
// DMAs for write regions are going to be inserted just after the for loop.
- FuncBuilder epilogue(block, end);
- FuncBuilder *b = region.isWrite() ? &epilogue : &prologue;
+ OpBuilder epilogue(block, end);
+ OpBuilder *b = region.isWrite() ? &epilogue : &prologue;
// Builder to create constants at the top level.
auto *func = block->getFunction();
- FuncBuilder top(func);
+ OpBuilder top(func->getBody());
auto loc = region.loc;
auto *memref = region.memref;
@@ -759,7 +759,7 @@ uint64_t DmaGeneration::runOnBlock(Block::iterator begin, Block::iterator end) {
void DmaGeneration::runOnFunction() {
Function &f = getFunction();
- FuncBuilder topBuilder(f);
+ OpBuilder topBuilder(f.getBody());
zeroIndex = topBuilder.create<ConstantIndexOp>(f.getLoc(), 0);
// Override default is a command line option is provided.
diff --git a/mlir/lib/Transforms/LoopFusion.cpp b/mlir/lib/Transforms/LoopFusion.cpp
index b7b69fa54fe..0f39e52eefb 100644
--- a/mlir/lib/Transforms/LoopFusion.cpp
+++ b/mlir/lib/Transforms/LoopFusion.cpp
@@ -1006,9 +1006,9 @@ static Value *createPrivateMemRef(AffineForOp forOp, Operation *srcStoreOpInst,
auto *forInst = forOp.getOperation();
// Create builder to insert alloc op just before 'forOp'.
- FuncBuilder b(forInst);
+ OpBuilder b(forInst);
// Builder to create constants at the top level.
- FuncBuilder top(forInst->getFunction());
+ OpBuilder top(forInst->getFunction()->getBody());
// Create new memref type based on slice bounds.
auto *oldMemRef = cast<StoreOp>(srcStoreOpInst).getMemRef();
auto oldMemRefType = oldMemRef->getType().cast<MemRefType>();
diff --git a/mlir/lib/Transforms/LoopInvariantCodeMotion.cpp b/mlir/lib/Transforms/LoopInvariantCodeMotion.cpp
index 31875664922..c4c1184fa82 100644
--- a/mlir/lib/Transforms/LoopInvariantCodeMotion.cpp
+++ b/mlir/lib/Transforms/LoopInvariantCodeMotion.cpp
@@ -203,7 +203,7 @@ void LoopInvariantCodeMotion::runOnAffineForOp(AffineForOp forOp) {
SmallPtrSet<Operation *, 8> definedOps;
// This is the place where hoisted instructions would reside.
- FuncBuilder b(forOp.getOperation());
+ OpBuilder b(forOp.getOperation());
SmallPtrSet<Operation *, 8> opsToHoist;
SmallVector<Operation *, 8> opsToMove;
diff --git a/mlir/lib/Transforms/LoopTiling.cpp b/mlir/lib/Transforms/LoopTiling.cpp
index 5233081b5f1..c1be6e8f6b1 100644
--- a/mlir/lib/Transforms/LoopTiling.cpp
+++ b/mlir/lib/Transforms/LoopTiling.cpp
@@ -112,7 +112,7 @@ constructTiledIndexSetHyperRect(MutableArrayRef<AffineForOp> origLoops,
assert(!origLoops.empty());
assert(origLoops.size() == tileSizes.size());
- FuncBuilder b(origLoops[0].getOperation());
+ OpBuilder b(origLoops[0].getOperation());
unsigned width = origLoops.size();
// Bounds for tile space loops.
@@ -207,7 +207,7 @@ LogicalResult mlir::tileCodeGen(MutableArrayRef<AffineForOp> band,
// Add intra-tile (or point) loops.
for (unsigned i = 0; i < width; i++) {
- FuncBuilder b(topLoop);
+ OpBuilder b(topLoop);
// Loop bounds will be set later.
auto pointLoop = b.create<AffineForOp>(loc, 0, 0);
pointLoop.getBody()->getOperations().splice(
@@ -221,7 +221,7 @@ LogicalResult mlir::tileCodeGen(MutableArrayRef<AffineForOp> band,
// Add tile space loops;
for (unsigned i = width; i < 2 * width; i++) {
- FuncBuilder b(topLoop);
+ OpBuilder b(topLoop);
// Loop bounds will be set later.
auto tileSpaceLoop = b.create<AffineForOp>(loc, 0, 0);
tileSpaceLoop.getBody()->getOperations().splice(
diff --git a/mlir/lib/Transforms/LoopUnrollAndJam.cpp b/mlir/lib/Transforms/LoopUnrollAndJam.cpp
index 731464bd7c1..409eb397df4 100644
--- a/mlir/lib/Transforms/LoopUnrollAndJam.cpp
+++ b/mlir/lib/Transforms/LoopUnrollAndJam.cpp
@@ -185,8 +185,7 @@ LogicalResult mlir::loopUnrollJamByFactor(AffineForOp forOp,
// unrollJamFactor.
if (getLargestDivisorOfTripCount(forOp) % unrollJamFactor != 0) {
// Insert the cleanup loop right after 'forOp'.
- FuncBuilder builder(forInst->getBlock(),
- std::next(Block::iterator(forInst)));
+ OpBuilder builder(forInst->getBlock(), std::next(Block::iterator(forInst)));
auto cleanupAffineForOp = cast<AffineForOp>(builder.clone(*forInst));
// Adjust the lower bound of the cleanup loop; its upper bound is the same
// as the original loop's upper bound.
@@ -212,7 +211,7 @@ LogicalResult mlir::loopUnrollJamByFactor(AffineForOp forOp,
for (auto &subBlock : subBlocks) {
// Builder to insert unroll-jammed bodies. Insert right at the end of
// sub-block.
- FuncBuilder builder(subBlock.first->getBlock(), std::next(subBlock.second));
+ OpBuilder builder(subBlock.first->getBlock(), std::next(subBlock.second));
// Unroll and jam (appends unrollJamFactor-1 additional copies).
for (unsigned i = 1; i < unrollJamFactor; i++) {
diff --git a/mlir/lib/Transforms/LowerAffine.cpp b/mlir/lib/Transforms/LowerAffine.cpp
index 4dcc82f1178..b890b43da81 100644
--- a/mlir/lib/Transforms/LowerAffine.cpp
+++ b/mlir/lib/Transforms/LowerAffine.cpp
@@ -41,7 +41,7 @@ class AffineApplyExpander
public:
// This internal class expects arguments to be non-null, checks must be
// performed at the call site.
- AffineApplyExpander(FuncBuilder *builder, ArrayRef<Value *> dimValues,
+ AffineApplyExpander(OpBuilder *builder, ArrayRef<Value *> dimValues,
ArrayRef<Value *> symbolValues, Location loc)
: builder(*builder), dimValues(dimValues), symbolValues(symbolValues),
loc(loc) {}
@@ -206,7 +206,7 @@ public:
}
private:
- FuncBuilder &builder;
+ OpBuilder &builder;
ArrayRef<Value *> dimValues;
ArrayRef<Value *> symbolValues;
@@ -216,7 +216,7 @@ private:
// Create a sequence of operations that implement the `expr` applied to the
// given dimension and symbol values.
-static mlir::Value *expandAffineExpr(FuncBuilder *builder, Location loc,
+static mlir::Value *expandAffineExpr(OpBuilder *builder, Location loc,
AffineExpr expr,
ArrayRef<Value *> dimValues,
ArrayRef<Value *> symbolValues) {
@@ -226,7 +226,7 @@ static mlir::Value *expandAffineExpr(FuncBuilder *builder, Location loc,
// Create a sequence of operations that implement the `affineMap` applied to
// the given `operands` (as it it were an AffineApplyOp).
Optional<SmallVector<Value *, 8>> static expandAffineMap(
- FuncBuilder *builder, Location loc, AffineMap affineMap,
+ OpBuilder *builder, Location loc, AffineMap affineMap,
ArrayRef<Value *> operands) {
auto numDims = affineMap.getNumDims();
auto expanded = functional::map(
@@ -260,7 +260,7 @@ struct LowerAffinePass : public FunctionPass<LowerAffinePass> {
// recognize as a reduction by the subsequent passes.
static Value *buildMinMaxReductionSeq(Location loc, CmpIPredicate predicate,
ArrayRef<Value *> values,
- FuncBuilder &builder) {
+ OpBuilder &builder) {
assert(!llvm::empty(values) && "empty min/max chain");
auto valueIt = values.begin();
@@ -348,7 +348,7 @@ static LogicalResult lowerAffineFor(AffineForOp forOp) {
// Append the induction variable stepping logic and branch back to the exit
// condition block. Construct an affine expression f : (x -> x+step) and
// apply this expression to the induction variable.
- FuncBuilder builder(bodyBlock);
+ OpBuilder builder(bodyBlock);
auto affStep = builder.getAffineConstantExpr(forOp.getStep());
auto affDim = builder.getAffineDimExpr(0);
auto stepped = expandAffineExpr(&builder, loc, affDim + affStep, iv, {});
@@ -482,7 +482,7 @@ static LogicalResult lowerAffineIf(AffineIfOp ifOp) {
std::prev(oldThen->end()));
}
- FuncBuilder builder(thenBlock);
+ OpBuilder builder(thenBlock);
builder.create<BranchOp>(loc, continueBlock);
// Handle the 'else' block the same way, but we skip it if we have no else
@@ -569,7 +569,7 @@ static LogicalResult lowerAffineIf(AffineIfOp ifOp) {
// Convert an "affine.apply" operation into a sequence of arithmetic
// operations using the StandardOps dialect. Return true on error.
static LogicalResult lowerAffineApply(AffineApplyOp op) {
- FuncBuilder builder(op.getOperation());
+ OpBuilder builder(op.getOperation());
auto maybeExpandedMap =
expandAffineMap(&builder, op.getLoc(), op.getAffineMap(),
llvm::to_vector<8>(op.getOperands()));
diff --git a/mlir/lib/Transforms/MaterializeVectors.cpp b/mlir/lib/Transforms/MaterializeVectors.cpp
index 80e080f8fa6..0d8cfea7312 100644
--- a/mlir/lib/Transforms/MaterializeVectors.cpp
+++ b/mlir/lib/Transforms/MaterializeVectors.cpp
@@ -238,7 +238,7 @@ static SmallVector<unsigned, 8> delinearize(unsigned linearIndex,
return res;
}
-static Operation *instantiate(FuncBuilder *b, Operation *opInst,
+static Operation *instantiate(OpBuilder *b, Operation *opInst,
VectorType hwVectorType,
DenseMap<Value *, Value *> *substitutionsMap);
@@ -257,7 +257,7 @@ static Value *substitute(Value *v, VectorType hwVectorType,
if (it == substitutionsMap->end()) {
auto *opInst = v->getDefiningOp();
if (isa<ConstantOp>(opInst)) {
- FuncBuilder b(opInst);
+ OpBuilder b(opInst);
auto *op = instantiate(&b, opInst, hwVectorType, substitutionsMap);
auto res = substitutionsMap->insert(std::make_pair(v, op->getResult(0)));
assert(res.second && "Insertion failed");
@@ -331,7 +331,7 @@ static Value *substitute(Value *v, VectorType hwVectorType,
/// TODO(ntv): these implementation details should be captured in a
/// vectorization trait at the op level directly.
static SmallVector<mlir::Value *, 8>
-reindexAffineIndices(FuncBuilder *b, VectorType hwVectorType,
+reindexAffineIndices(OpBuilder *b, VectorType hwVectorType,
ArrayRef<unsigned> hwVectorInstance,
ArrayRef<Value *> memrefIndices) {
auto vectorShape = hwVectorType.getShape();
@@ -404,7 +404,7 @@ materializeAttributes(Operation *opInst, VectorType hwVectorType) {
/// substitutionsMap.
///
/// If the underlying substitution fails, this fails too and returns nullptr.
-static Operation *instantiate(FuncBuilder *b, Operation *opInst,
+static Operation *instantiate(OpBuilder *b, Operation *opInst,
VectorType hwVectorType,
DenseMap<Value *, Value *> *substitutionsMap) {
assert(!isa<VectorTransferReadOp>(opInst) &&
@@ -481,7 +481,7 @@ static AffineMap projectedPermutationMap(VectorTransferOpTy transfer,
/// `hwVectorType` int the covering of the super-vector type. For a more
/// detailed description of the problem, see the description of
/// reindexAffineIndices.
-static Operation *instantiate(FuncBuilder *b, VectorTransferReadOp read,
+static Operation *instantiate(OpBuilder *b, VectorTransferReadOp read,
VectorType hwVectorType,
ArrayRef<unsigned> hwVectorInstance,
DenseMap<Value *, Value *> *substitutionsMap) {
@@ -505,7 +505,7 @@ static Operation *instantiate(FuncBuilder *b, VectorTransferReadOp read,
/// `hwVectorType` int the covering of th3e super-vector type. For a more
/// detailed description of the problem, see the description of
/// reindexAffineIndices.
-static Operation *instantiate(FuncBuilder *b, VectorTransferWriteOp write,
+static Operation *instantiate(OpBuilder *b, VectorTransferWriteOp write,
VectorType hwVectorType,
ArrayRef<unsigned> hwVectorInstance,
DenseMap<Value *, Value *> *substitutionsMap) {
@@ -547,7 +547,7 @@ static bool instantiateMaterialization(Operation *op,
LLVM_DEBUG(dbgs() << "\ninstantiate: " << *op);
// Create a builder here for unroll-and-jam effects.
- FuncBuilder b(op);
+ OpBuilder b(op);
// AffineApplyOp are ignored: instantiating the proper vector op will take
// care of AffineApplyOps by composing them properly.
if (isa<AffineApplyOp>(op)) {
diff --git a/mlir/lib/Transforms/PipelineDataTransfer.cpp b/mlir/lib/Transforms/PipelineDataTransfer.cpp
index de8038c931c..d0e0d18d586 100644
--- a/mlir/lib/Transforms/PipelineDataTransfer.cpp
+++ b/mlir/lib/Transforms/PipelineDataTransfer.cpp
@@ -73,7 +73,7 @@ static unsigned getTagMemRefPos(Operation &dmaInst) {
/// modulo 2. Returns false if such a replacement cannot be performed.
static bool doubleBuffer(Value *oldMemRef, AffineForOp forOp) {
auto *forBody = forOp.getBody();
- FuncBuilder bInner(forBody, forBody->begin());
+ OpBuilder bInner(forBody, forBody->begin());
bInner.setInsertionPoint(forBody, forBody->begin());
// Doubles the shape with a leading dimension extent of 2.
@@ -94,7 +94,7 @@ static bool doubleBuffer(Value *oldMemRef, AffineForOp forOp) {
// The double buffer is allocated right before 'forInst'.
auto *forInst = forOp.getOperation();
- FuncBuilder bOuter(forInst);
+ OpBuilder bOuter(forInst);
// Put together alloc operands for any dynamic dimensions of the memref.
SmallVector<Value *, 4> allocOperands;
unsigned dynamicDimCount = 0;
@@ -360,7 +360,7 @@ void PipelineDataTransfer::runOnAffineForOp(AffineForOp forOp) {
// Tagging operations with shifts for debugging purposes.
LLVM_DEBUG({
- FuncBuilder b(&op);
+ OpBuilder b(&op);
op.setAttr("shift", b.getI64IntegerAttr(shifts[s - 1]));
});
}
diff --git a/mlir/lib/Transforms/Utils/FoldUtils.cpp b/mlir/lib/Transforms/Utils/FoldUtils.cpp
index fbf1a2ae9c1..3983dda98fd 100644
--- a/mlir/lib/Transforms/Utils/FoldUtils.cpp
+++ b/mlir/lib/Transforms/Utils/FoldUtils.cpp
@@ -110,7 +110,7 @@ LogicalResult OperationFolder::tryToFold(Operation *op,
assert(foldResults.size() == op->getNumResults());
// Create the result constants and replace the results.
- FuncBuilder builder(op);
+ OpBuilder builder(op);
for (unsigned i = 0, e = op->getNumResults(); i != e; ++i) {
assert(!foldResults[i].isNull() && "expected valid OpFoldResult");
diff --git a/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp b/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp
index a2e64271c46..0cd32255561 100644
--- a/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp
+++ b/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp
@@ -46,7 +46,7 @@ class GreedyPatternRewriteDriver : public PatternRewriter {
public:
explicit GreedyPatternRewriteDriver(Function &fn,
OwningRewritePatternList &&patterns)
- : PatternRewriter(&fn), matcher(std::move(patterns)) {
+ : PatternRewriter(fn.getBody()), matcher(std::move(patterns)) {
worklist.reserve(64);
}
@@ -88,7 +88,7 @@ protected:
// Implement the hook for creating operations, and make sure that newly
// created ops are added to the worklist for processing.
Operation *createOperation(const OperationState &state) override {
- auto *result = FuncBuilder::createOperation(state);
+ auto *result = OpBuilder::createOperation(state);
addToWorklist(result);
return result;
}
@@ -142,14 +142,16 @@ private:
/// Perform the rewrites.
bool GreedyPatternRewriteDriver::simplifyFunction(int maxIterations) {
- Function *fn = getFunction();
- OperationFolder helper(fn);
+ Region *region = getRegion();
+
+ // TODO(riverriddle) OperationFolder should take a region to insert into.
+ OperationFolder helper(region->getContainingFunction());
bool changed = false;
int i = 0;
do {
// Add all operations to the worklist.
- fn->walk([&](Operation *op) { addToWorklist(op); });
+ region->walk([&](Operation *op) { addToWorklist(op); });
// These are scratch vectors used in the folding loop below.
SmallVector<Value *, 8> originalOperands, resultValues;
diff --git a/mlir/lib/Transforms/Utils/LoopUtils.cpp b/mlir/lib/Transforms/Utils/LoopUtils.cpp
index d5bdcea2c55..23375e7b472 100644
--- a/mlir/lib/Transforms/Utils/LoopUtils.cpp
+++ b/mlir/lib/Transforms/Utils/LoopUtils.cpp
@@ -46,7 +46,7 @@ using namespace mlir;
void mlir::getCleanupLoopLowerBound(AffineForOp forOp, unsigned unrollFactor,
AffineMap *map,
SmallVectorImpl<Value *> *operands,
- FuncBuilder *b) {
+ OpBuilder *b) {
auto lbMap = forOp.getLowerBoundMap();
// Single result lower bound map only.
@@ -125,15 +125,14 @@ LogicalResult mlir::promoteIfSingleIteration(AffineForOp forOp) {
Operation *op = forOp.getOperation();
if (!iv->use_empty()) {
if (forOp.hasConstantLowerBound()) {
- auto *mlFunc = op->getFunction();
- FuncBuilder topBuilder(mlFunc);
+ OpBuilder topBuilder(op->getFunction()->getBody());
auto constOp = topBuilder.create<ConstantIndexOp>(
forOp.getLoc(), forOp.getConstantLowerBound());
iv->replaceAllUsesWith(constOp);
} else {
AffineBound lb = forOp.getLowerBound();
SmallVector<Value *, 4> lbOperands(lb.operand_begin(), lb.operand_end());
- FuncBuilder builder(op->getBlock(), Block::iterator(op));
+ OpBuilder builder(op->getBlock(), Block::iterator(op));
if (lb.getMap() == builder.getDimIdentityMap()) {
// No need of generating an affine.apply.
iv->replaceAllUsesWith(lbOperands[0]);
@@ -173,7 +172,7 @@ static AffineForOp
generateLoop(AffineMap lbMap, AffineMap ubMap,
const std::vector<std::pair<uint64_t, ArrayRef<Operation *>>>
&instGroupQueue,
- unsigned offset, AffineForOp srcForInst, FuncBuilder *b) {
+ unsigned offset, AffineForOp srcForInst, OpBuilder *b) {
SmallVector<Value *, 4> lbOperands(srcForInst.getLowerBoundOperands());
SmallVector<Value *, 4> ubOperands(srcForInst.getUpperBoundOperands());
@@ -188,7 +187,7 @@ generateLoop(AffineMap lbMap, AffineMap ubMap,
BlockAndValueMapping operandMap;
- FuncBuilder bodyBuilder = loopChunk.getBodyBuilder();
+ OpBuilder bodyBuilder = loopChunk.getBodyBuilder();
for (auto it = instGroupQueue.begin() + offset, e = instGroupQueue.end();
it != e; ++it) {
uint64_t shift = it->first;
@@ -291,7 +290,7 @@ LogicalResult mlir::instBodySkew(AffineForOp forOp, ArrayRef<uint64_t> shifts,
auto origLbMap = forOp.getLowerBoundMap();
uint64_t lbShift = 0;
- FuncBuilder b(forOp.getOperation());
+ OpBuilder b(forOp.getOperation());
for (uint64_t d = 0, e = sortedInstGroups.size(); d < e; ++d) {
// If nothing is shifted by d, continue.
if (sortedInstGroups[d].empty())
@@ -424,7 +423,7 @@ LogicalResult mlir::loopUnrollByFactor(AffineForOp forOp,
// Generate the cleanup loop if trip count isn't a multiple of unrollFactor.
Operation *op = forOp.getOperation();
if (getLargestDivisorOfTripCount(forOp) % unrollFactor != 0) {
- FuncBuilder builder(op->getBlock(), ++Block::iterator(op));
+ OpBuilder builder(op->getBlock(), ++Block::iterator(op));
auto cleanupForInst = cast<AffineForOp>(builder.clone(*op));
AffineMap cleanupMap;
SmallVector<Value *, 4> cleanupOperands;
@@ -448,7 +447,7 @@ LogicalResult mlir::loopUnrollByFactor(AffineForOp forOp,
// Builder to insert unrolled bodies just before the terminator of the body of
// 'forOp'.
- FuncBuilder builder = forOp.getBodyBuilder();
+ OpBuilder builder = forOp.getBodyBuilder();
// Keep a pointer to the last non-terminator operation in the original block
// so that we know what to clone (since we are doing this in-place).
@@ -647,7 +646,7 @@ void mlir::sinkLoop(AffineForOp forOp, unsigned loopDepth) {
// ...
// }
// ```
-static void augmentMapAndBounds(FuncBuilder *b, Value *iv, AffineMap *map,
+static void augmentMapAndBounds(OpBuilder *b, Value *iv, AffineMap *map,
SmallVector<Value *, 4> *operands,
int64_t offset = 0) {
auto bounds = llvm::to_vector<4>(map->getResults());
@@ -665,7 +664,7 @@ static void cloneLoopBodyInto(AffineForOp forOp, Value *oldIv,
AffineForOp newForOp) {
BlockAndValueMapping map;
map.map(oldIv, newForOp.getInductionVar());
- FuncBuilder b = newForOp.getBodyBuilder();
+ OpBuilder b = newForOp.getBodyBuilder();
for (auto &op : *forOp.getBody()) {
// Step over newForOp in case it is nested under forOp.
if (&op == newForOp.getOperation()) {
@@ -704,7 +703,7 @@ stripmineSink(AffineForOp forOp, uint64_t factor,
forOp.setStep(scaledStep);
auto *op = forOp.getOperation();
- FuncBuilder b(op->getBlock(), ++Block::iterator(op));
+ OpBuilder b(op->getBlock(), ++Block::iterator(op));
// Lower-bound map creation.
auto lbMap = forOp.getLowerBoundMap();
@@ -720,7 +719,7 @@ stripmineSink(AffineForOp forOp, uint64_t factor,
SmallVector<AffineForOp, 8> innerLoops;
for (auto t : targets) {
// Insert newForOp before the terminator of `t`.
- FuncBuilder b = t.getBodyBuilder();
+ OpBuilder b = t.getBodyBuilder();
auto newForOp = b.create<AffineForOp>(t.getLoc(), lbOperands, lbMap,
ubOperands, ubMap, originalStep);
cloneLoopBodyInto(t, forOp.getInductionVar(), newForOp);
diff --git a/mlir/lib/Transforms/Utils/Utils.cpp b/mlir/lib/Transforms/Utils/Utils.cpp
index 13e5b2f2f08..2e2bc08b24d 100644
--- a/mlir/lib/Transforms/Utils/Utils.cpp
+++ b/mlir/lib/Transforms/Utils/Utils.cpp
@@ -123,7 +123,7 @@ bool mlir::replaceAllMemRefUsesWith(Value *oldMemRef, Value *newMemRef,
opInst->operand_begin() + memRefOperandPos);
state.operands.push_back(newMemRef);
- FuncBuilder builder(opInst);
+ OpBuilder builder(opInst);
for (auto *extraIndex : extraIndices) {
assert(extraIndex->getDefiningOp()->getNumResults() == 1 &&
"single result op's expected to generate these indices");
@@ -249,7 +249,7 @@ void mlir::createAffineComputationSlice(
if (localized)
return;
- FuncBuilder builder(opInst);
+ OpBuilder builder(opInst);
SmallVector<Value *, 4> composedOpOperands(subOperands);
auto composedMap = builder.getMultiDimIdentityMap(composedOpOperands.size());
fullyComposeAffineMapAndOperands(&composedMap, &composedOpOperands);
diff --git a/mlir/lib/Transforms/Vectorization/VectorizerTestPass.cpp b/mlir/lib/Transforms/Vectorization/VectorizerTestPass.cpp
index aeaea02dad0..9220b7bb751 100644
--- a/mlir/lib/Transforms/Vectorization/VectorizerTestPass.cpp
+++ b/mlir/lib/Transforms/Vectorization/VectorizerTestPass.cpp
@@ -240,7 +240,7 @@ void VectorizerTestPass::testNormalizeMaps() {
pattern.match(f, &matches);
for (auto m : matches) {
auto app = cast<AffineApplyOp>(m.getMatchedOperation());
- FuncBuilder b(m.getMatchedOperation());
+ OpBuilder b(m.getMatchedOperation());
SmallVector<Value *, 8> operands(app.getOperands());
makeComposedAffineApply(&b, app.getLoc(), app.getAffineMap(), operands);
}
diff --git a/mlir/lib/Transforms/Vectorize.cpp b/mlir/lib/Transforms/Vectorize.cpp
index ddaf112dece..a96713be547 100644
--- a/mlir/lib/Transforms/Vectorize.cpp
+++ b/mlir/lib/Transforms/Vectorize.cpp
@@ -805,7 +805,7 @@ static LogicalResult vectorizeRootOrTerminal(Value *iv,
return LogicalResult::Failure;
LLVM_DEBUG(dbgs() << "\n[early-vect]+++++ permutationMap: ");
LLVM_DEBUG(permutationMap.print(dbgs()));
- FuncBuilder b(opInst);
+ OpBuilder b(opInst);
auto transfer = b.create<VectorTransferReadOp>(
opInst->getLoc(), vectorType, memoryOp.getMemRef(),
map(makePtrDynCaster<Value>(), memoryOp.getIndices()), permutationMap);
@@ -920,7 +920,7 @@ static Value *vectorizeConstant(Operation *op, ConstantOp constant, Type type) {
!VectorType::isValidElementType(constant.getType())) {
return nullptr;
}
- FuncBuilder b(op);
+ OpBuilder b(op);
Location loc = op->getLoc();
auto vectorType = type.cast<VectorType>();
auto attr = SplatElementsAttr::get(vectorType, constant.getValue());
@@ -1015,7 +1015,7 @@ static Operation *vectorizeOneOperation(Operation *opInst,
auto *value = store.getValueToStore();
auto *vectorValue = vectorizeOperand(value, opInst, state);
auto indices = map(makePtrDynCaster<Value>(), store.getIndices());
- FuncBuilder b(opInst);
+ OpBuilder b(opInst);
auto permutationMap =
makePermutationMap(opInst, state->strategy->loopToVectorDim);
if (!permutationMap)
@@ -1054,7 +1054,7 @@ static Operation *vectorizeOneOperation(Operation *opInst,
// name that works both in scalar mode and vector mode.
// TODO(ntv): Is it worth considering an Operation.clone operation which
// changes the type so we can promote an Operation with less boilerplate?
- FuncBuilder b(opInst);
+ OpBuilder b(opInst);
OperationState newOp(b.getContext(), opInst->getLoc(),
opInst->getName().getStringRef(), vectorOperands,
vectorTypes, opInst->getAttrs(), /*successors=*/{},
@@ -1136,7 +1136,7 @@ static LogicalResult vectorizeRootMatch(NestedMatch m,
/// maintains a clone for handling failure and restores the proper state via
/// RAII.
auto *loopInst = loop.getOperation();
- FuncBuilder builder(loopInst);
+ OpBuilder builder(loopInst);
auto clonedLoop = cast<AffineForOp>(builder.clone(*loopInst));
struct Guard {
LogicalResult failure() {
OpenPOWER on IntegriCloud