diff options
| author | River Riddle <riverriddle@google.com> | 2019-12-23 14:45:01 -0800 |
|---|---|---|
| committer | A. Unique TensorFlower <gardener@tensorflow.org> | 2019-12-23 16:36:53 -0800 |
| commit | e62a69561fb9d7b1013d2853da68d79a7907fead (patch) | |
| tree | 0dd059094cbfb8d904513abcdc1fbe8cfa89bb09 /mlir/lib/Transforms | |
| parent | 5d5bd2e1da29d976cb125dbb3cd097a5e42b2be4 (diff) | |
| download | bcm5719-llvm-e62a69561fb9d7b1013d2853da68d79a7907fead.tar.gz bcm5719-llvm-e62a69561fb9d7b1013d2853da68d79a7907fead.zip | |
NFC: Replace ValuePtr with Value and remove it now that Value is value-typed.
ValuePtr was a temporary typedef during the transition to a value-typed Value.
PiperOrigin-RevId: 286945714
Diffstat (limited to 'mlir/lib/Transforms')
| -rw-r--r-- | mlir/lib/Transforms/AffineDataCopyGeneration.cpp | 2 | ||||
| -rw-r--r-- | mlir/lib/Transforms/AffineLoopInvariantCodeMotion.cpp | 19 | ||||
| -rw-r--r-- | mlir/lib/Transforms/DialectConversion.cpp | 50 | ||||
| -rw-r--r-- | mlir/lib/Transforms/LoopFusion.cpp | 65 | ||||
| -rw-r--r-- | mlir/lib/Transforms/LoopInvariantCodeMotion.cpp | 4 | ||||
| -rw-r--r-- | mlir/lib/Transforms/LoopTiling.cpp | 11 | ||||
| -rw-r--r-- | mlir/lib/Transforms/LoopUnrollAndJam.cpp | 2 | ||||
| -rw-r--r-- | mlir/lib/Transforms/MemRefDataFlowOpt.cpp | 4 | ||||
| -rw-r--r-- | mlir/lib/Transforms/PipelineDataTransfer.cpp | 12 | ||||
| -rw-r--r-- | mlir/lib/Transforms/Utils/FoldUtils.cpp | 6 | ||||
| -rw-r--r-- | mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp | 4 | ||||
| -rw-r--r-- | mlir/lib/Transforms/Utils/InliningUtils.cpp | 34 | ||||
| -rw-r--r-- | mlir/lib/Transforms/Utils/LoopFusionUtils.cpp | 10 | ||||
| -rw-r--r-- | mlir/lib/Transforms/Utils/LoopUtils.cpp | 151 | ||||
| -rw-r--r-- | mlir/lib/Transforms/Utils/RegionUtils.cpp | 22 | ||||
| -rw-r--r-- | mlir/lib/Transforms/Utils/Utils.cpp | 45 | ||||
| -rw-r--r-- | mlir/lib/Transforms/Vectorize.cpp | 25 |
17 files changed, 231 insertions, 235 deletions
diff --git a/mlir/lib/Transforms/AffineDataCopyGeneration.cpp b/mlir/lib/Transforms/AffineDataCopyGeneration.cpp index 1e1b8775d32..902f5c3adcb 100644 --- a/mlir/lib/Transforms/AffineDataCopyGeneration.cpp +++ b/mlir/lib/Transforms/AffineDataCopyGeneration.cpp @@ -121,7 +121,7 @@ struct AffineDataCopyGeneration bool skipNonUnitStrideLoops; // Constant zero index to avoid too many duplicates. - ValuePtr zeroIndex = nullptr; + Value zeroIndex = nullptr; }; } // end anonymous namespace diff --git a/mlir/lib/Transforms/AffineLoopInvariantCodeMotion.cpp b/mlir/lib/Transforms/AffineLoopInvariantCodeMotion.cpp index 1f33c0f5dca..24ec2d7c70b 100644 --- a/mlir/lib/Transforms/AffineLoopInvariantCodeMotion.cpp +++ b/mlir/lib/Transforms/AffineLoopInvariantCodeMotion.cpp @@ -49,15 +49,15 @@ struct LoopInvariantCodeMotion : public FunctionPass<LoopInvariantCodeMotion> { } // end anonymous namespace static bool -checkInvarianceOfNestedIfOps(Operation *op, ValuePtr indVar, +checkInvarianceOfNestedIfOps(Operation *op, Value indVar, SmallPtrSetImpl<Operation *> &definedOps, SmallPtrSetImpl<Operation *> &opsToHoist); -static bool isOpLoopInvariant(Operation &op, ValuePtr indVar, +static bool isOpLoopInvariant(Operation &op, Value indVar, SmallPtrSetImpl<Operation *> &definedOps, SmallPtrSetImpl<Operation *> &opsToHoist); static bool -areAllOpsInTheBlockListInvariant(Region &blockList, ValuePtr indVar, +areAllOpsInTheBlockListInvariant(Region &blockList, Value indVar, SmallPtrSetImpl<Operation *> &definedOps, SmallPtrSetImpl<Operation *> &opsToHoist); @@ -70,7 +70,7 @@ static bool isMemRefDereferencingOp(Operation &op) { } // Returns true if the individual op is loop invariant. -bool isOpLoopInvariant(Operation &op, ValuePtr indVar, +bool isOpLoopInvariant(Operation &op, Value indVar, SmallPtrSetImpl<Operation *> &definedOps, SmallPtrSetImpl<Operation *> &opsToHoist) { LLVM_DEBUG(llvm::dbgs() << "iterating on op: " << op;); @@ -88,9 +88,9 @@ bool isOpLoopInvariant(Operation &op, ValuePtr indVar, return false; } else if (!isa<ConstantOp>(op)) { if (isMemRefDereferencingOp(op)) { - ValuePtr memref = isa<AffineLoadOp>(op) - ? cast<AffineLoadOp>(op).getMemRef() - : cast<AffineStoreOp>(op).getMemRef(); + Value memref = isa<AffineLoadOp>(op) + ? cast<AffineLoadOp>(op).getMemRef() + : cast<AffineStoreOp>(op).getMemRef(); for (auto *user : memref->getUsers()) { // If this memref has a user that is a DMA, give up because these // operations write to this memref. @@ -154,8 +154,7 @@ bool isOpLoopInvariant(Operation &op, ValuePtr indVar, // Checks if all ops in a region (i.e. list of blocks) are loop invariant. bool areAllOpsInTheBlockListInvariant( - Region &blockList, ValuePtr indVar, - SmallPtrSetImpl<Operation *> &definedOps, + Region &blockList, Value indVar, SmallPtrSetImpl<Operation *> &definedOps, SmallPtrSetImpl<Operation *> &opsToHoist) { for (auto &b : blockList) { @@ -170,7 +169,7 @@ bool areAllOpsInTheBlockListInvariant( } // Returns true if the affine.if op can be hoisted. -bool checkInvarianceOfNestedIfOps(Operation *op, ValuePtr indVar, +bool checkInvarianceOfNestedIfOps(Operation *op, Value indVar, SmallPtrSetImpl<Operation *> &definedOps, SmallPtrSetImpl<Operation *> &opsToHoist) { assert(isa<AffineIfOp>(op)); diff --git a/mlir/lib/Transforms/DialectConversion.cpp b/mlir/lib/Transforms/DialectConversion.cpp index c9fcb670180..5f7fb7a68c9 100644 --- a/mlir/lib/Transforms/DialectConversion.cpp +++ b/mlir/lib/Transforms/DialectConversion.cpp @@ -77,13 +77,13 @@ namespace { struct ConversionValueMapping { /// Lookup a mapped value within the map. If a mapping for the provided value /// does not exist then return the provided value. - ValuePtr lookupOrDefault(ValuePtr from) const; + Value lookupOrDefault(Value from) const; /// Map a value to the one provided. - void map(ValuePtr oldVal, ValuePtr newVal) { mapping.map(oldVal, newVal); } + void map(Value oldVal, Value newVal) { mapping.map(oldVal, newVal); } /// Drop the last mapping for the given value. - void erase(ValuePtr value) { mapping.erase(value); } + void erase(Value value) { mapping.erase(value); } private: /// Current value mappings. @@ -93,7 +93,7 @@ private: /// Lookup a mapped value within the map. If a mapping for the provided value /// does not exist then return the provided value. -ValuePtr ConversionValueMapping::lookupOrDefault(ValuePtr from) const { +Value ConversionValueMapping::lookupOrDefault(Value from) const { // If this value had a valid mapping, unmap that value as well in the case // that it was also replaced. while (auto mappedValue = mapping.lookupOrNull(from)) @@ -118,7 +118,7 @@ struct ArgConverter { /// been converted. struct ConvertedArgInfo { ConvertedArgInfo(unsigned newArgIdx, unsigned newArgSize, - ValuePtr castValue = nullptr) + Value castValue = nullptr) : newArgIdx(newArgIdx), newArgSize(newArgSize), castValue(castValue) {} /// The start index of in the new argument list that contains arguments that @@ -130,7 +130,7 @@ struct ArgConverter { /// The cast value that was created to cast from the new arguments to the /// old. This only used if 'newArgSize' > 1. - ValuePtr castValue; + Value castValue; }; /// This structure contains information pertaining to a block that has had its @@ -226,7 +226,7 @@ void ArgConverter::notifyOpRemoved(Operation *op) { // Drop all uses of the original arguments and delete the original block. Block *origBlock = it->second.origBlock; - for (BlockArgumentPtr arg : origBlock->getArguments()) + for (BlockArgument arg : origBlock->getArguments()) arg->dropAllUses(); conversionInfo.erase(it); } @@ -261,7 +261,7 @@ void ArgConverter::applyRewrites(ConversionValueMapping &mapping) { // Process the remapping for each of the original arguments. for (unsigned i = 0, e = origBlock->getNumArguments(); i != e; ++i) { Optional<ConvertedArgInfo> &argInfo = blockInfo.argInfo[i]; - BlockArgumentPtr origArg = origBlock->getArgument(i); + BlockArgument origArg = origBlock->getArgument(i); // Handle the case of a 1->0 value mapping. if (!argInfo) { @@ -296,7 +296,7 @@ void ArgConverter::applyRewrites(ConversionValueMapping &mapping) { } // Otherwise this is a 1->N value mapping. - ValuePtr castValue = argInfo->castValue; + Value castValue = argInfo->castValue; assert(argInfo->newArgSize > 1 && castValue && "expected 1->N mapping"); // If the argument is still used, replace it with the generated cast. @@ -335,8 +335,8 @@ Block *ArgConverter::applySignatureConversion( Block *newBlock = block->splitBlock(block->begin()); block->replaceAllUsesWith(newBlock); - SmallVector<ValuePtr, 4> newArgRange(newBlock->addArguments(convertedTypes)); - ArrayRef<ValuePtr> newArgs(newArgRange); + SmallVector<Value, 4> newArgRange(newBlock->addArguments(convertedTypes)); + ArrayRef<Value> newArgs(newArgRange); // Remap each of the original arguments as determined by the signature // conversion. @@ -349,7 +349,7 @@ Block *ArgConverter::applySignatureConversion( auto inputMap = signatureConversion.getInputMapping(i); if (!inputMap) continue; - BlockArgumentPtr origArg = block->getArgument(i); + BlockArgument origArg = block->getArgument(i); // If inputMap->replacementValue is not nullptr, then the argument is // dropped and a replacement value is provided to be the remappedValue. @@ -473,7 +473,7 @@ struct ConversionPatternRewriterImpl { : op(op), newValues(newValues.begin(), newValues.end()) {} Operation *op; - SmallVector<ValuePtr, 2> newValues; + SmallVector<Value, 2> newValues; }; /// The kind of the block action performed during the rewrite. Actions can be @@ -570,7 +570,7 @@ struct ConversionPatternRewriterImpl { /// Remap the given operands to those with potentially different types. void remapValues(Operation::operand_range operands, - SmallVectorImpl<ValuePtr> &remapped); + SmallVectorImpl<Value> &remapped); /// Returns true if the given operation is ignored, and does not need to be /// converted. @@ -803,9 +803,9 @@ void ConversionPatternRewriterImpl::notifyRegionWasClonedBefore( } void ConversionPatternRewriterImpl::remapValues( - Operation::operand_range operands, SmallVectorImpl<ValuePtr> &remapped) { + Operation::operand_range operands, SmallVectorImpl<Value> &remapped) { remapped.reserve(llvm::size(operands)); - for (ValuePtr operand : operands) + for (Value operand : operands) remapped.push_back(mapping.lookupOrDefault(operand)); } @@ -851,7 +851,7 @@ void ConversionPatternRewriter::replaceOp(Operation *op, ValueRange newValues, void ConversionPatternRewriter::eraseOp(Operation *op) { LLVM_DEBUG(llvm::dbgs() << "** Erasing operation : " << op->getName() << "\n"); - SmallVector<ValuePtr, 1> nullRepls(op->getNumResults(), nullptr); + SmallVector<Value, 1> nullRepls(op->getNumResults(), nullptr); impl->replaceOp(op, nullRepls, /*valuesToRemoveIfDead=*/llvm::None); } @@ -861,8 +861,8 @@ Block *ConversionPatternRewriter::applySignatureConversion( return impl->applySignatureConversion(region, conversion); } -void ConversionPatternRewriter::replaceUsesOfBlockArgument( - BlockArgumentPtr from, ValuePtr to) { +void ConversionPatternRewriter::replaceUsesOfBlockArgument(BlockArgument from, + Value to) { for (auto &u : from->getUses()) { if (u.getOwner() == to->getDefiningOp()) continue; @@ -873,7 +873,7 @@ void ConversionPatternRewriter::replaceUsesOfBlockArgument( /// Return the converted value that replaces 'key'. Return 'key' if there is /// no such a converted value. -ValuePtr ConversionPatternRewriter::getRemappedValue(ValuePtr key) { +Value ConversionPatternRewriter::getRemappedValue(Value key) { return impl->mapping.lookupOrDefault(key); } @@ -967,7 +967,7 @@ detail::ConversionPatternRewriterImpl &ConversionPatternRewriter::getImpl() { PatternMatchResult ConversionPattern::matchAndRewrite(Operation *op, PatternRewriter &rewriter) const { - SmallVector<ValuePtr, 4> operands; + SmallVector<Value, 4> operands; auto &dialectRewriter = static_cast<ConversionPatternRewriter &>(rewriter); dialectRewriter.getImpl().remapValues(op->getOperands(), operands); @@ -979,7 +979,7 @@ ConversionPattern::matchAndRewrite(Operation *op, SmallVector<Block *, 2> destinations; destinations.reserve(op->getNumSuccessors()); - SmallVector<ArrayRef<ValuePtr>, 2> operandsPerDestination; + SmallVector<ArrayRef<Value>, 2> operandsPerDestination; unsigned firstSuccessorOperand = op->getSuccessorOperandIndex(0); for (unsigned i = 0, seen = 0, e = op->getNumSuccessors(); i < e; ++i) { destinations.push_back(op->getSuccessor(i)); @@ -1130,7 +1130,7 @@ OperationLegalizer::legalizeWithFold(Operation *op, RewriterState curState = rewriterImpl.getCurrentState(); // Try to fold the operation. - SmallVector<ValuePtr, 2> replacementValues; + SmallVector<Value, 2> replacementValues; rewriter.setInsertionPoint(op); if (failed(rewriter.tryFold(op, replacementValues))) return failure(); @@ -1554,7 +1554,7 @@ void TypeConverter::SignatureConversion::remapInput(unsigned origInputNo, /// Remap an input of the original signature to another `replacementValue` /// value. This would make the signature converter drop this argument. void TypeConverter::SignatureConversion::remapInput(unsigned origInputNo, - ValuePtr replacementValue) { + Value replacementValue) { assert(!remappedInputs[origInputNo] && "input has already been remapped"); remappedInputs[origInputNo] = InputMapping{origInputNo, /*size=*/0, replacementValue}; @@ -1623,7 +1623,7 @@ struct FuncOpSignatureConversion : public OpConversionPattern<FuncOp> { /// Hook for derived classes to implement combined matching and rewriting. PatternMatchResult - matchAndRewrite(FuncOp funcOp, ArrayRef<ValuePtr> operands, + matchAndRewrite(FuncOp funcOp, ArrayRef<Value> operands, ConversionPatternRewriter &rewriter) const override { FunctionType type = funcOp.getType(); diff --git a/mlir/lib/Transforms/LoopFusion.cpp b/mlir/lib/Transforms/LoopFusion.cpp index 51e30ba7163..fcfc1d7ae52 100644 --- a/mlir/lib/Transforms/LoopFusion.cpp +++ b/mlir/lib/Transforms/LoopFusion.cpp @@ -163,7 +163,7 @@ public: Node(unsigned id, Operation *op) : id(id), op(op) {} // Returns the load op count for 'memref'. - unsigned getLoadOpCount(ValuePtr memref) { + unsigned getLoadOpCount(Value memref) { unsigned loadOpCount = 0; for (auto *loadOpInst : loads) { if (memref == cast<AffineLoadOp>(loadOpInst).getMemRef()) @@ -173,7 +173,7 @@ public: } // Returns the store op count for 'memref'. - unsigned getStoreOpCount(ValuePtr memref) { + unsigned getStoreOpCount(Value memref) { unsigned storeOpCount = 0; for (auto *storeOpInst : stores) { if (memref == cast<AffineStoreOp>(storeOpInst).getMemRef()) @@ -183,7 +183,7 @@ public: } // Returns all store ops in 'storeOps' which access 'memref'. - void getStoreOpsForMemref(ValuePtr memref, + void getStoreOpsForMemref(Value memref, SmallVectorImpl<Operation *> *storeOps) { for (auto *storeOpInst : stores) { if (memref == cast<AffineStoreOp>(storeOpInst).getMemRef()) @@ -192,7 +192,7 @@ public: } // Returns all load ops in 'loadOps' which access 'memref'. - void getLoadOpsForMemref(ValuePtr memref, + void getLoadOpsForMemref(Value memref, SmallVectorImpl<Operation *> *loadOps) { for (auto *loadOpInst : loads) { if (memref == cast<AffineLoadOp>(loadOpInst).getMemRef()) @@ -202,8 +202,8 @@ public: // Returns all memrefs in 'loadAndStoreMemrefSet' for which this node // has at least one load and store operation. - void getLoadAndStoreMemrefSet(DenseSet<ValuePtr> *loadAndStoreMemrefSet) { - llvm::SmallDenseSet<ValuePtr, 2> loadMemrefs; + void getLoadAndStoreMemrefSet(DenseSet<Value> *loadAndStoreMemrefSet) { + llvm::SmallDenseSet<Value, 2> loadMemrefs; for (auto *loadOpInst : loads) { loadMemrefs.insert(cast<AffineLoadOp>(loadOpInst).getMemRef()); } @@ -230,7 +230,7 @@ public: // defines an SSA value and another graph node which uses the SSA value // (e.g. a constant operation defining a value which is used inside a loop // nest). - ValuePtr value; + Value value; }; // Map from node id to Node. @@ -241,7 +241,7 @@ public: DenseMap<unsigned, SmallVector<Edge, 2>> outEdges; // Map from memref to a count on the dependence edges associated with that // memref. - DenseMap<ValuePtr, unsigned> memrefEdgeCount; + DenseMap<Value, unsigned> memrefEdgeCount; // The next unique identifier to use for newly created graph nodes. unsigned nextNodeId = 0; @@ -372,7 +372,7 @@ public: // Returns true iff there is an edge from node 'srcId' to node 'dstId' which // is for 'value' if non-null, or for any value otherwise. Returns false // otherwise. - bool hasEdge(unsigned srcId, unsigned dstId, ValuePtr value = nullptr) { + bool hasEdge(unsigned srcId, unsigned dstId, Value value = nullptr) { if (outEdges.count(srcId) == 0 || inEdges.count(dstId) == 0) { return false; } @@ -386,7 +386,7 @@ public: } // Adds an edge from node 'srcId' to node 'dstId' for 'value'. - void addEdge(unsigned srcId, unsigned dstId, ValuePtr value) { + void addEdge(unsigned srcId, unsigned dstId, Value value) { if (!hasEdge(srcId, dstId, value)) { outEdges[srcId].push_back({dstId, value}); inEdges[dstId].push_back({srcId, value}); @@ -396,7 +396,7 @@ public: } // Removes an edge from node 'srcId' to node 'dstId' for 'value'. - void removeEdge(unsigned srcId, unsigned dstId, ValuePtr value) { + void removeEdge(unsigned srcId, unsigned dstId, Value value) { assert(inEdges.count(dstId) > 0); assert(outEdges.count(srcId) > 0); if (value->getType().isa<MemRefType>()) { @@ -450,7 +450,7 @@ public: // Returns the input edge count for node 'id' and 'memref' from src nodes // which access 'memref' with a store operation. - unsigned getIncomingMemRefAccesses(unsigned id, ValuePtr memref) { + unsigned getIncomingMemRefAccesses(unsigned id, Value memref) { unsigned inEdgeCount = 0; if (inEdges.count(id) > 0) for (auto &inEdge : inEdges[id]) @@ -465,7 +465,7 @@ public: // Returns the output edge count for node 'id' and 'memref' (if non-null), // otherwise returns the total output edge count from node 'id'. - unsigned getOutEdgeCount(unsigned id, ValuePtr memref = nullptr) { + unsigned getOutEdgeCount(unsigned id, Value memref = nullptr) { unsigned outEdgeCount = 0; if (outEdges.count(id) > 0) for (auto &outEdge : outEdges[id]) @@ -539,7 +539,7 @@ public: // Updates edge mappings from node 'srcId' to node 'dstId' after 'oldMemRef' // has been replaced in node at 'dstId' by a private memref depending // on the value of 'createPrivateMemRef'. - void updateEdges(unsigned srcId, unsigned dstId, ValuePtr oldMemRef, + void updateEdges(unsigned srcId, unsigned dstId, Value oldMemRef, bool createPrivateMemRef) { // For each edge in 'inEdges[srcId]': add new edge remaping to 'dstId'. if (inEdges.count(srcId) > 0) { @@ -672,7 +672,7 @@ public: // TODO(andydavis) Add support for taking a Block arg to construct the // dependence graph at a different depth. bool MemRefDependenceGraph::init(FuncOp f) { - DenseMap<ValuePtr, SetVector<unsigned>> memrefAccesses; + DenseMap<Value, SetVector<unsigned>> memrefAccesses; // TODO: support multi-block functions. if (f.getBlocks().size() != 1) @@ -768,7 +768,7 @@ bool MemRefDependenceGraph::init(FuncOp f) { // Removes load operations from 'srcLoads' which operate on 'memref', and // adds them to 'dstLoads'. -static void moveLoadsAccessingMemrefTo(ValuePtr memref, +static void moveLoadsAccessingMemrefTo(Value memref, SmallVectorImpl<Operation *> *srcLoads, SmallVectorImpl<Operation *> *dstLoads) { dstLoads->clear(); @@ -884,11 +884,10 @@ static unsigned getMemRefEltSizeInBytes(MemRefType memRefType) { // MemRefRegion written to by 'srcStoreOpInst' at depth 'dstLoopDepth'. // TODO(bondhugula): consider refactoring the common code from generateDma and // this one. -static ValuePtr createPrivateMemRef(AffineForOp forOp, - Operation *srcStoreOpInst, - unsigned dstLoopDepth, - Optional<unsigned> fastMemorySpace, - uint64_t localBufSizeThreshold) { +static Value createPrivateMemRef(AffineForOp forOp, Operation *srcStoreOpInst, + unsigned dstLoopDepth, + Optional<unsigned> fastMemorySpace, + uint64_t localBufSizeThreshold) { auto *forInst = forOp.getOperation(); // Create builder to insert alloc op just before 'forOp'. @@ -920,7 +919,7 @@ static ValuePtr createPrivateMemRef(AffineForOp forOp, // 'outerIVs' holds the values that this memory region is symbolic/parametric // on; this would correspond to loop IVs surrounding the level at which the // slice is being materialized. - SmallVector<ValuePtr, 8> outerIVs; + SmallVector<Value, 8> outerIVs; cst->getIdValues(rank, cst->getNumIds(), &outerIVs); // Build 'rank' AffineExprs from MemRefRegion 'lbs' @@ -952,7 +951,7 @@ static ValuePtr createPrivateMemRef(AffineForOp forOp, auto newMemRefType = MemRefType::get(newShape, oldMemRefType.getElementType(), {}, newMemSpace); // Gather alloc operands for the dynamic dimensions of the memref. - SmallVector<ValuePtr, 4> allocOperands; + SmallVector<Value, 4> allocOperands; unsigned dynamicDimCount = 0; for (auto dimSize : oldMemRefType.getShape()) { if (dimSize == -1) @@ -965,7 +964,7 @@ static ValuePtr createPrivateMemRef(AffineForOp forOp, // consumer loop nests to reduce their live range. Currently they are added // at the beginning of the function, because loop nests can be reordered // during the fusion pass. - ValuePtr newMemRef = + Value newMemRef = top.create<AllocOp>(forOp.getLoc(), newMemRefType, allocOperands); // Build an AffineMap to remap access functions based on lower bound offsets. @@ -1008,7 +1007,7 @@ static bool canFuseSrcWhichWritesToLiveOut(unsigned srcId, unsigned dstId, MemRefDependenceGraph *mdg) { assert(srcLiveOutStoreOp && "Expected a valid store op"); auto *dstNode = mdg->getNode(dstId); - ValuePtr memref = srcLiveOutStoreOp.getMemRef(); + Value memref = srcLiveOutStoreOp.getMemRef(); // Return false if 'srcNode' has more than one output edge on 'memref'. if (mdg->getOutEdgeCount(srcId, memref) > 1) return false; @@ -1487,7 +1486,7 @@ public: SmallVector<Operation *, 4> loads = dstNode->loads; SmallVector<Operation *, 4> dstLoadOpInsts; - DenseSet<ValuePtr> visitedMemrefs; + DenseSet<Value> visitedMemrefs; while (!loads.empty()) { // Get memref of load on top of the stack. auto memref = cast<AffineLoadOp>(loads.back()).getMemRef(); @@ -1729,10 +1728,10 @@ public: // Attempt to fuse 'dstNode' with sibling nodes in the graph. void fuseWithSiblingNodes(Node *dstNode) { DenseSet<unsigned> visitedSibNodeIds; - std::pair<unsigned, ValuePtr> idAndMemref; + std::pair<unsigned, Value> idAndMemref; while (findSiblingNodeToFuse(dstNode, &visitedSibNodeIds, &idAndMemref)) { unsigned sibId = idAndMemref.first; - ValuePtr memref = idAndMemref.second; + Value memref = idAndMemref.second; // TODO(andydavis) Check that 'sibStoreOpInst' post-dominates all other // stores to the same memref in 'sibNode' loop nest. auto *sibNode = mdg->getNode(sibId); @@ -1796,10 +1795,10 @@ public: // 'idAndMemrefToFuse' on success. Returns false otherwise. bool findSiblingNodeToFuse(Node *dstNode, DenseSet<unsigned> *visitedSibNodeIds, - std::pair<unsigned, ValuePtr> *idAndMemrefToFuse) { + std::pair<unsigned, Value> *idAndMemrefToFuse) { // Returns true if 'sibNode' can be fused with 'dstNode' for input reuse // on 'memref'. - auto canFuseWithSibNode = [&](Node *sibNode, ValuePtr memref) { + auto canFuseWithSibNode = [&](Node *sibNode, Value memref) { // Skip if 'outEdge' is not a read-after-write dependence. // TODO(andydavis) Remove restrict to single load op restriction. if (sibNode->getLoadOpCount(memref) != 1) @@ -1811,15 +1810,15 @@ public: return false; // Skip sib node if it loads to (and stores from) the same memref on // which it also has an input dependence edge. - DenseSet<ValuePtr> loadAndStoreMemrefSet; + DenseSet<Value> loadAndStoreMemrefSet; sibNode->getLoadAndStoreMemrefSet(&loadAndStoreMemrefSet); - if (llvm::any_of(loadAndStoreMemrefSet, [=](ValuePtr memref) { + if (llvm::any_of(loadAndStoreMemrefSet, [=](Value memref) { return mdg->getIncomingMemRefAccesses(sibNode->id, memref) > 0; })) return false; // Check that all stores are to the same memref. - DenseSet<ValuePtr> storeMemrefs; + DenseSet<Value> storeMemrefs; for (auto *storeOpInst : sibNode->stores) { storeMemrefs.insert(cast<AffineStoreOp>(storeOpInst).getMemRef()); } diff --git a/mlir/lib/Transforms/LoopInvariantCodeMotion.cpp b/mlir/lib/Transforms/LoopInvariantCodeMotion.cpp index 93c80822fb3..fb3d0c0b45c 100644 --- a/mlir/lib/Transforms/LoopInvariantCodeMotion.cpp +++ b/mlir/lib/Transforms/LoopInvariantCodeMotion.cpp @@ -41,7 +41,7 @@ public: // - the op has no side-effects. If sideEffecting is Never, sideeffects of this // op and its nested ops are ignored. static bool canBeHoisted(Operation *op, - function_ref<bool(ValuePtr)> definedOutside, + function_ref<bool(Value)> definedOutside, SideEffecting sideEffecting, SideEffectsInterface &interface) { // Check that dependencies are defined outside of loop. @@ -83,7 +83,7 @@ static LogicalResult moveLoopInvariantCode(LoopLikeOpInterface looplike, SmallVector<Operation *, 8> opsToMove; // Helper to check whether an operation is loop invariant wrt. SSA properties. - auto isDefinedOutsideOfBody = [&](ValuePtr value) { + auto isDefinedOutsideOfBody = [&](Value value) { auto definingOp = value->getDefiningOp(); return (definingOp && !!willBeMovedSet.count(definingOp)) || looplike.isDefinedOutsideOfLoop(value); diff --git a/mlir/lib/Transforms/LoopTiling.cpp b/mlir/lib/Transforms/LoopTiling.cpp index 5389c7e4429..d3dc81760fc 100644 --- a/mlir/lib/Transforms/LoopTiling.cpp +++ b/mlir/lib/Transforms/LoopTiling.cpp @@ -111,8 +111,8 @@ constructTiledIndexSetHyperRect(MutableArrayRef<AffineForOp> origLoops, for (unsigned i = 0; i < width; i++) { auto lbOperands = origLoops[i].getLowerBoundOperands(); auto ubOperands = origLoops[i].getUpperBoundOperands(); - SmallVector<ValuePtr, 4> newLbOperands(lbOperands); - SmallVector<ValuePtr, 4> newUbOperands(ubOperands); + SmallVector<Value, 4> newLbOperands(lbOperands); + SmallVector<Value, 4> newUbOperands(ubOperands); newLoops[i].setLowerBound(newLbOperands, origLoops[i].getLowerBoundMap()); newLoops[i].setUpperBound(newUbOperands, origLoops[i].getUpperBoundMap()); newLoops[i].setStep(tileSizes[i]); @@ -138,7 +138,7 @@ constructTiledIndexSetHyperRect(MutableArrayRef<AffineForOp> origLoops, // with 'i' (tile-space loop) appended to it. The new upper bound map is // the original one with an additional expression i + tileSize appended. auto ub = origLoops[i].getUpperBound(); - SmallVector<ValuePtr, 4> ubOperands; + SmallVector<Value, 4> ubOperands; ubOperands.reserve(ub.getNumOperands() + 1); auto origUbMap = ub.getMap(); // Add dim operands from original upper bound. @@ -226,10 +226,9 @@ LogicalResult mlir::tileCodeGen(MutableArrayRef<AffineForOp> band, // Move the loop body of the original nest to the new one. moveLoopBody(origLoops[origLoops.size() - 1], innermostPointLoop); - SmallVector<ValuePtr, 8> origLoopIVs; + SmallVector<Value, 8> origLoopIVs; extractForInductionVars(band, &origLoopIVs); - SmallVector<Optional<ValuePtr>, 6> ids(origLoopIVs.begin(), - origLoopIVs.end()); + SmallVector<Optional<Value>, 6> ids(origLoopIVs.begin(), origLoopIVs.end()); FlatAffineConstraints cst; getIndexSet(band, &cst); diff --git a/mlir/lib/Transforms/LoopUnrollAndJam.cpp b/mlir/lib/Transforms/LoopUnrollAndJam.cpp index 3cefcaacadc..6c74d545497 100644 --- a/mlir/lib/Transforms/LoopUnrollAndJam.cpp +++ b/mlir/lib/Transforms/LoopUnrollAndJam.cpp @@ -182,7 +182,7 @@ LogicalResult mlir::loopUnrollJamByFactor(AffineForOp forOp, // Adjust the lower bound of the cleanup loop; its upper bound is the same // as the original loop's upper bound. AffineMap cleanupMap; - SmallVector<ValuePtr, 4> cleanupOperands; + SmallVector<Value, 4> cleanupOperands; getCleanupLoopLowerBound(forOp, unrollJamFactor, &cleanupMap, &cleanupOperands, builder); cleanupAffineForOp.setLowerBound(cleanupOperands, cleanupMap); diff --git a/mlir/lib/Transforms/MemRefDataFlowOpt.cpp b/mlir/lib/Transforms/MemRefDataFlowOpt.cpp index 957f41a9d3e..e2514e12cc7 100644 --- a/mlir/lib/Transforms/MemRefDataFlowOpt.cpp +++ b/mlir/lib/Transforms/MemRefDataFlowOpt.cpp @@ -67,7 +67,7 @@ struct MemRefDataFlowOpt : public FunctionPass<MemRefDataFlowOpt> { void forwardStoreToLoad(AffineLoadOp loadOp); // A list of memref's that are potentially dead / could be eliminated. - SmallPtrSet<ValuePtr, 4> memrefsToErase; + SmallPtrSet<Value, 4> memrefsToErase; // Load op's whose results were replaced by those forwarded from stores. SmallVector<Operation *, 8> loadOpsToErase; @@ -171,7 +171,7 @@ void MemRefDataFlowOpt::forwardStoreToLoad(AffineLoadOp loadOp) { return; // Perform the actual store to load forwarding. - ValuePtr storeVal = cast<AffineStoreOp>(lastWriteStoreOp).getValueToStore(); + Value storeVal = cast<AffineStoreOp>(lastWriteStoreOp).getValueToStore(); loadOp.replaceAllUsesWith(storeVal); // Record the memref for a later sweep to optimize away. memrefsToErase.insert(loadOp.getMemRef()); diff --git a/mlir/lib/Transforms/PipelineDataTransfer.cpp b/mlir/lib/Transforms/PipelineDataTransfer.cpp index 12ce6c66abd..dce02737064 100644 --- a/mlir/lib/Transforms/PipelineDataTransfer.cpp +++ b/mlir/lib/Transforms/PipelineDataTransfer.cpp @@ -61,7 +61,7 @@ static unsigned getTagMemRefPos(Operation &dmaInst) { /// Replaces all uses of the old memref by the new one while indexing the newly /// added dimension by the loop IV of the specified 'affine.for' operation /// modulo 2. Returns false if such a replacement cannot be performed. -static bool doubleBuffer(ValuePtr oldMemRef, AffineForOp forOp) { +static bool doubleBuffer(Value oldMemRef, AffineForOp forOp) { auto *forBody = forOp.getBody(); OpBuilder bInner(forBody, forBody->begin()); @@ -85,7 +85,7 @@ static bool doubleBuffer(ValuePtr oldMemRef, AffineForOp forOp) { auto *forInst = forOp.getOperation(); OpBuilder bOuter(forInst); // Put together alloc operands for any dynamic dimensions of the memref. - SmallVector<ValuePtr, 4> allocOperands; + SmallVector<Value, 4> allocOperands; unsigned dynamicDimCount = 0; for (auto dimSize : oldMemRefType.getShape()) { if (dimSize == -1) @@ -94,7 +94,7 @@ static bool doubleBuffer(ValuePtr oldMemRef, AffineForOp forOp) { } // Create and place the alloc right before the 'affine.for' operation. - ValuePtr newMemRef = + Value newMemRef = bOuter.create<AllocOp>(forInst->getLoc(), newMemRefType, allocOperands); // Create 'iv mod 2' value to index the leading dimension. @@ -261,7 +261,7 @@ void PipelineDataTransfer::runOnAffineForOp(AffineForOp forOp) { // dimension. for (auto &pair : startWaitPairs) { auto *dmaStartInst = pair.first; - ValuePtr oldMemRef = dmaStartInst->getOperand( + Value oldMemRef = dmaStartInst->getOperand( cast<AffineDmaStartOp>(dmaStartInst).getFasterMemPos()); if (!doubleBuffer(oldMemRef, forOp)) { // Normally, double buffering should not fail because we already checked @@ -292,7 +292,7 @@ void PipelineDataTransfer::runOnAffineForOp(AffineForOp forOp) { // Double the buffers for tag memrefs. for (auto &pair : startWaitPairs) { auto *dmaFinishInst = pair.second; - ValuePtr oldTagMemRef = + Value oldTagMemRef = dmaFinishInst->getOperand(getTagMemRefPos(*dmaFinishInst)); if (!doubleBuffer(oldTagMemRef, forOp)) { LLVM_DEBUG(llvm::dbgs() << "tag double buffering failed\n";); @@ -333,7 +333,7 @@ void PipelineDataTransfer::runOnAffineForOp(AffineForOp forOp) { // If a slice wasn't created, the reachable affine.apply op's from its // operands are the ones that go with it. SmallVector<Operation *, 4> affineApplyInsts; - SmallVector<ValuePtr, 4> operands(dmaStartInst->getOperands()); + SmallVector<Value, 4> operands(dmaStartInst->getOperands()); getReachableAffineApplyOps(operands, affineApplyInsts); for (auto *op : affineApplyInsts) { instShiftMap[op] = 0; diff --git a/mlir/lib/Transforms/Utils/FoldUtils.cpp b/mlir/lib/Transforms/Utils/FoldUtils.cpp index ce39625831a..719c6fac731 100644 --- a/mlir/lib/Transforms/Utils/FoldUtils.cpp +++ b/mlir/lib/Transforms/Utils/FoldUtils.cpp @@ -81,7 +81,7 @@ LogicalResult OperationFolder::tryToFold( return failure(); // Try to fold the operation. - SmallVector<ValuePtr, 8> results; + SmallVector<Value, 8> results; if (failed(tryToFold(op, results, processGeneratedConstants))) return failure(); @@ -129,7 +129,7 @@ void OperationFolder::notifyRemoval(Operation *op) { /// Tries to perform folding on the given `op`. If successful, populates /// `results` with the results of the folding. LogicalResult OperationFolder::tryToFold( - Operation *op, SmallVectorImpl<ValuePtr> &results, + Operation *op, SmallVectorImpl<Value> &results, function_ref<void(Operation *)> processGeneratedConstants) { SmallVector<Attribute, 8> operandConstants; SmallVector<OpFoldResult, 8> foldResults; @@ -172,7 +172,7 @@ LogicalResult OperationFolder::tryToFold( assert(!foldResults[i].isNull() && "expected valid OpFoldResult"); // Check if the result was an SSA value. - if (auto repl = foldResults[i].dyn_cast<ValuePtr>()) { + if (auto repl = foldResults[i].dyn_cast<Value>()) { results.emplace_back(repl); continue; } diff --git a/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp b/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp index 3ab4e287bb2..1eb9c57639a 100644 --- a/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp +++ b/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp @@ -109,7 +109,7 @@ private: // operation is modified or removed, as it may trigger further // simplifications. template <typename Operands> void addToWorklist(Operands &&operands) { - for (ValuePtr operand : operands) { + for (Value operand : operands) { // If the use count of this operand is now < 2, we re-add the defining // operation to the worklist. // TODO(riverriddle) This is based on the fact that zero use operations @@ -151,7 +151,7 @@ bool GreedyPatternRewriteDriver::simplify(MutableArrayRef<Region> regions, region.walk(collectOps); // These are scratch vectors used in the folding loop below. - SmallVector<ValuePtr, 8> originalOperands, resultValues; + SmallVector<Value, 8> originalOperands, resultValues; changed = false; while (!worklist.empty()) { diff --git a/mlir/lib/Transforms/Utils/InliningUtils.cpp b/mlir/lib/Transforms/Utils/InliningUtils.cpp index e7b34bb3956..1ac286c67fb 100644 --- a/mlir/lib/Transforms/Utils/InliningUtils.cpp +++ b/mlir/lib/Transforms/Utils/InliningUtils.cpp @@ -89,7 +89,7 @@ void InlinerInterface::handleTerminator(Operation *op, Block *newDest) const { /// Handle the given inlined terminator by replacing it with a new operation /// as necessary. void InlinerInterface::handleTerminator(Operation *op, - ArrayRef<ValuePtr> valuesToRepl) const { + ArrayRef<Value> valuesToRepl) const { auto *handler = getInterfaceFor(op); assert(handler && "expected valid dialect handler"); handler->handleTerminator(op, valuesToRepl); @@ -128,7 +128,7 @@ static bool isLegalToInline(InlinerInterface &interface, Region *src, LogicalResult mlir::inlineRegion(InlinerInterface &interface, Region *src, Operation *inlinePoint, BlockAndValueMapping &mapper, - ArrayRef<ValuePtr> resultsToReplace, + ArrayRef<Value> resultsToReplace, Optional<Location> inlineLoc, bool shouldCloneInlinedRegion) { // We expect the region to have at least one block. @@ -138,7 +138,7 @@ LogicalResult mlir::inlineRegion(InlinerInterface &interface, Region *src, // Check that all of the region arguments have been mapped. auto *srcEntryBlock = &src->front(); if (llvm::any_of(srcEntryBlock->getArguments(), - [&](BlockArgumentPtr arg) { return !mapper.contains(arg); })) + [&](BlockArgument arg) { return !mapper.contains(arg); })) return failure(); // The insertion point must be within a block. @@ -198,7 +198,7 @@ LogicalResult mlir::inlineRegion(InlinerInterface &interface, Region *src, } else { // Otherwise, there were multiple blocks inlined. Add arguments to the post // insertion block to represent the results to replace. - for (ValuePtr resultToRepl : resultsToReplace) { + for (Value resultToRepl : resultsToReplace) { resultToRepl->replaceAllUsesWith( postInsertBlock->addArgument(resultToRepl->getType())); } @@ -220,8 +220,8 @@ LogicalResult mlir::inlineRegion(InlinerInterface &interface, Region *src, /// in-favor of the region arguments when inlining. LogicalResult mlir::inlineRegion(InlinerInterface &interface, Region *src, Operation *inlinePoint, - ArrayRef<ValuePtr> inlinedOperands, - ArrayRef<ValuePtr> resultsToReplace, + ArrayRef<Value> inlinedOperands, + ArrayRef<Value> resultsToReplace, Optional<Location> inlineLoc, bool shouldCloneInlinedRegion) { // We expect the region to have at least one block. @@ -237,7 +237,7 @@ LogicalResult mlir::inlineRegion(InlinerInterface &interface, Region *src, for (unsigned i = 0, e = inlinedOperands.size(); i != e; ++i) { // Verify that the types of the provided values match the function argument // types. - BlockArgumentPtr regionArg = entryBlock->getArgument(i); + BlockArgument regionArg = entryBlock->getArgument(i); if (inlinedOperands[i]->getType() != regionArg->getType()) return failure(); mapper.map(regionArg, inlinedOperands[i]); @@ -250,10 +250,10 @@ LogicalResult mlir::inlineRegion(InlinerInterface &interface, Region *src, /// Utility function used to generate a cast operation from the given interface, /// or return nullptr if a cast could not be generated. -static ValuePtr materializeConversion(const DialectInlinerInterface *interface, - SmallVectorImpl<Operation *> &castOps, - OpBuilder &castBuilder, ValuePtr arg, - Type type, Location conversionLoc) { +static Value materializeConversion(const DialectInlinerInterface *interface, + SmallVectorImpl<Operation *> &castOps, + OpBuilder &castBuilder, Value arg, Type type, + Location conversionLoc) { if (!interface) return nullptr; @@ -288,8 +288,8 @@ LogicalResult mlir::inlineCall(InlinerInterface &interface, // Make sure that the number of arguments and results matchup between the call // and the region. - SmallVector<ValuePtr, 8> callOperands(call.getArgOperands()); - SmallVector<ValuePtr, 8> callResults(call.getOperation()->getResults()); + SmallVector<Value, 8> callOperands(call.getArgOperands()); + SmallVector<Value, 8> callResults(call.getOperation()->getResults()); if (callOperands.size() != entryBlock->getNumArguments() || callResults.size() != callableResultTypes.size()) return failure(); @@ -316,8 +316,8 @@ LogicalResult mlir::inlineCall(InlinerInterface &interface, // Map the provided call operands to the arguments of the region. BlockAndValueMapping mapper; for (unsigned i = 0, e = callOperands.size(); i != e; ++i) { - BlockArgumentPtr regionArg = entryBlock->getArgument(i); - ValuePtr operand = callOperands[i]; + BlockArgument regionArg = entryBlock->getArgument(i); + Value operand = callOperands[i]; // If the call operand doesn't match the expected region argument, try to // generate a cast. @@ -333,13 +333,13 @@ LogicalResult mlir::inlineCall(InlinerInterface &interface, // Ensure that the resultant values of the call, match the callable. castBuilder.setInsertionPointAfter(call); for (unsigned i = 0, e = callResults.size(); i != e; ++i) { - ValuePtr callResult = callResults[i]; + Value callResult = callResults[i]; if (callResult->getType() == callableResultTypes[i]) continue; // Generate a conversion that will produce the original type, so that the IR // is still valid after the original call gets replaced. - ValuePtr castResult = + Value castResult = materializeConversion(callInterface, castOps, castBuilder, callResult, callResult->getType(), castLoc); if (!castResult) diff --git a/mlir/lib/Transforms/Utils/LoopFusionUtils.cpp b/mlir/lib/Transforms/Utils/LoopFusionUtils.cpp index 4745a26e168..b0d9fdf5fd8 100644 --- a/mlir/lib/Transforms/Utils/LoopFusionUtils.cpp +++ b/mlir/lib/Transforms/Utils/LoopFusionUtils.cpp @@ -36,7 +36,7 @@ using namespace mlir; // Gathers all load and store memref accesses in 'opA' into 'values', where // 'values[memref] == true' for each store operation. static void getLoadAndStoreMemRefAccesses(Operation *opA, - DenseMap<ValuePtr, bool> &values) { + DenseMap<Value, bool> &values) { opA->walk([&](Operation *op) { if (auto loadOp = dyn_cast<AffineLoadOp>(op)) { if (values.count(loadOp.getMemRef()) == 0) @@ -51,7 +51,7 @@ static void getLoadAndStoreMemRefAccesses(Operation *opA, // accessed 'values' and at least one of the access is a store operation. // Returns false otherwise. static bool isDependentLoadOrStoreOp(Operation *op, - DenseMap<ValuePtr, bool> &values) { + DenseMap<Value, bool> &values) { if (auto loadOp = dyn_cast<AffineLoadOp>(op)) { return values.count(loadOp.getMemRef()) > 0 && values[loadOp.getMemRef()] == true; @@ -66,7 +66,7 @@ static bool isDependentLoadOrStoreOp(Operation *op, static Operation *getFirstDependentOpInRange(Operation *opA, Operation *opB) { // Record memref values from all loads/store in loop nest rooted at 'opA'. // Map from memref value to bool which is true if store, false otherwise. - DenseMap<ValuePtr, bool> values; + DenseMap<Value, bool> values; getLoadAndStoreMemRefAccesses(opA, values); // For each 'opX' in block in range ('opA', 'opB'), check if there is a data @@ -92,7 +92,7 @@ static Operation *getFirstDependentOpInRange(Operation *opA, Operation *opB) { static Operation *getLastDependentOpInRange(Operation *opA, Operation *opB) { // Record memref values from all loads/store in loop nest rooted at 'opB'. // Map from memref value to bool which is true if store, false otherwise. - DenseMap<ValuePtr, bool> values; + DenseMap<Value, bool> values; getLoadAndStoreMemRefAccesses(opB, values); // For each 'opX' in block in range ('opA', 'opB') in reverse order, @@ -434,7 +434,7 @@ bool mlir::getFusionComputeCost(AffineForOp srcForOp, LoopNestStats &srcStats, // Subtract from operation count the loads/store we expect load/store // forwarding to remove. unsigned storeCount = 0; - llvm::SmallDenseSet<ValuePtr, 4> storeMemrefs; + llvm::SmallDenseSet<Value, 4> storeMemrefs; srcForOp.walk([&](Operation *op) { if (auto storeOp = dyn_cast<AffineStoreOp>(op)) { storeMemrefs.insert(storeOp.getMemRef()); diff --git a/mlir/lib/Transforms/Utils/LoopUtils.cpp b/mlir/lib/Transforms/Utils/LoopUtils.cpp index 3d4db22c866..0fece54132a 100644 --- a/mlir/lib/Transforms/Utils/LoopUtils.cpp +++ b/mlir/lib/Transforms/Utils/LoopUtils.cpp @@ -43,7 +43,7 @@ using llvm::SmallMapVector; /// expression. void mlir::getCleanupLoopLowerBound(AffineForOp forOp, unsigned unrollFactor, AffineMap *map, - SmallVectorImpl<ValuePtr> *operands, + SmallVectorImpl<Value> *operands, OpBuilder &b) { auto lbMap = forOp.getLowerBoundMap(); @@ -54,7 +54,7 @@ void mlir::getCleanupLoopLowerBound(AffineForOp forOp, unsigned unrollFactor, } AffineMap tripCountMap; - SmallVector<ValuePtr, 4> tripCountOperands; + SmallVector<Value, 4> tripCountOperands; buildTripCountMapAndOperands(forOp, &tripCountMap, &tripCountOperands); // Sometimes the trip count cannot be expressed as an affine expression. @@ -73,7 +73,7 @@ void mlir::getCleanupLoopLowerBound(AffineForOp forOp, unsigned unrollFactor, // lb + tr1 - tr1 % ufactor, lb + tr2 - tr2 % ufactor; the results of all // these affine.apply's make up the cleanup loop lower bound. SmallVector<AffineExpr, 4> bumpExprs(tripCountMap.getNumResults()); - SmallVector<ValuePtr, 4> bumpValues(tripCountMap.getNumResults()); + SmallVector<Value, 4> bumpValues(tripCountMap.getNumResults()); for (unsigned i = 0, e = tripCountMap.getNumResults(); i < e; i++) { auto tripCountExpr = tripCountMap.getResult(i); bumpExprs[i] = (tripCountExpr - tripCountExpr % unrollFactor) * step; @@ -128,7 +128,7 @@ LogicalResult mlir::promoteIfSingleIteration(AffineForOp forOp) { iv->replaceAllUsesWith(constOp); } else { AffineBound lb = forOp.getLowerBound(); - SmallVector<ValuePtr, 4> lbOperands(lb.operand_begin(), lb.operand_end()); + SmallVector<Value, 4> lbOperands(lb.operand_begin(), lb.operand_end()); OpBuilder builder(op->getBlock(), Block::iterator(op)); if (lb.getMap() == builder.getDimIdentityMap()) { // No need of generating an affine.apply. @@ -169,8 +169,8 @@ generateLoop(AffineMap lbMap, AffineMap ubMap, const std::vector<std::pair<uint64_t, ArrayRef<Operation *>>> &instGroupQueue, unsigned offset, AffineForOp srcForInst, OpBuilder b) { - SmallVector<ValuePtr, 4> lbOperands(srcForInst.getLowerBoundOperands()); - SmallVector<ValuePtr, 4> ubOperands(srcForInst.getUpperBoundOperands()); + SmallVector<Value, 4> lbOperands(srcForInst.getLowerBoundOperands()); + SmallVector<Value, 4> ubOperands(srcForInst.getUpperBoundOperands()); assert(lbMap.getNumInputs() == lbOperands.size()); assert(ubMap.getNumInputs() == ubOperands.size()); @@ -440,7 +440,7 @@ LogicalResult mlir::loopUnrollByFactor(AffineForOp forOp, OpBuilder builder(op->getBlock(), ++Block::iterator(op)); auto cleanupForInst = cast<AffineForOp>(builder.clone(*op)); AffineMap cleanupMap; - SmallVector<ValuePtr, 4> cleanupOperands; + SmallVector<Value, 4> cleanupOperands; getCleanupLoopLowerBound(forOp, unrollFactor, &cleanupMap, &cleanupOperands, builder); assert(cleanupMap && @@ -660,8 +660,8 @@ void mlir::sinkLoop(AffineForOp forOp, unsigned loopDepth) { // ... // } // ``` -static void augmentMapAndBounds(OpBuilder &b, ValuePtr iv, AffineMap *map, - SmallVector<ValuePtr, 4> *operands, +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()); bounds.push_back(b.getAffineDimExpr(map->getNumDims()) + offset); @@ -690,12 +690,12 @@ stripmineSink(AffineForOp forOp, uint64_t factor, // Lower-bound map creation. auto lbMap = forOp.getLowerBoundMap(); - SmallVector<ValuePtr, 4> lbOperands(forOp.getLowerBoundOperands()); + SmallVector<Value, 4> lbOperands(forOp.getLowerBoundOperands()); augmentMapAndBounds(b, forOp.getInductionVar(), &lbMap, &lbOperands); // Upper-bound map creation. auto ubMap = forOp.getUpperBoundMap(); - SmallVector<ValuePtr, 4> ubOperands(forOp.getUpperBoundOperands()); + SmallVector<Value, 4> ubOperands(forOp.getUpperBoundOperands()); augmentMapAndBounds(b, forOp.getInductionVar(), &ubMap, &ubOperands, /*offset=*/scaledStep); @@ -720,7 +720,7 @@ stripmineSink(AffineForOp forOp, uint64_t factor, return innerLoops; } -static Loops stripmineSink(loop::ForOp forOp, ValuePtr factor, +static Loops stripmineSink(loop::ForOp forOp, Value factor, ArrayRef<loop::ForOp> targets) { auto originalStep = forOp.step(); auto iv = forOp.getInductionVar(); @@ -736,10 +736,10 @@ static Loops stripmineSink(loop::ForOp forOp, ValuePtr factor, // Insert newForOp before the terminator of `t`. OpBuilder b(t.getBodyBuilder()); - ValuePtr stepped = b.create<AddIOp>(t.getLoc(), iv, forOp.step()); - ValuePtr less = b.create<CmpIOp>(t.getLoc(), CmpIPredicate::slt, - forOp.upperBound(), stepped); - ValuePtr ub = + Value stepped = b.create<AddIOp>(t.getLoc(), iv, forOp.step()); + Value less = b.create<CmpIOp>(t.getLoc(), CmpIPredicate::slt, + forOp.upperBound(), stepped); + Value ub = b.create<SelectOp>(t.getLoc(), less, forOp.upperBound(), stepped); // Splice [begin, begin + nOps - 1) into `newForOp` and replace uses. @@ -790,7 +790,7 @@ mlir::tile(ArrayRef<AffineForOp> forOps, ArrayRef<uint64_t> sizes, } SmallVector<Loops, 8> mlir::tile(ArrayRef<loop::ForOp> forOps, - ArrayRef<ValuePtr> sizes, + ArrayRef<Value> sizes, ArrayRef<loop::ForOp> targets) { return tileImpl(forOps, sizes, targets); } @@ -812,13 +812,12 @@ SmallVector<AffineForOp, 8> mlir::tile(ArrayRef<AffineForOp> forOps, return tileImpl(forOps, sizes, target); } -Loops mlir::tile(ArrayRef<loop::ForOp> forOps, ArrayRef<ValuePtr> sizes, +Loops mlir::tile(ArrayRef<loop::ForOp> forOps, ArrayRef<Value> sizes, loop::ForOp target) { return tileImpl(forOps, sizes, target); } -Loops mlir::tilePerfectlyNested(loop::ForOp rootForOp, - ArrayRef<ValuePtr> sizes) { +Loops mlir::tilePerfectlyNested(loop::ForOp rootForOp, ArrayRef<Value> sizes) { // Collect perfectly nested loops. If more size values provided than nested // loops available, truncate `sizes`. SmallVector<loop::ForOp, 4> forOps; @@ -833,15 +832,14 @@ Loops mlir::tilePerfectlyNested(loop::ForOp rootForOp, // Build the IR that performs ceil division of a positive value by a constant: // ceildiv(a, B) = divis(a + (B-1), B) // where divis is rounding-to-zero division. -static ValuePtr ceilDivPositive(OpBuilder &builder, Location loc, - ValuePtr dividend, int64_t divisor) { +static Value ceilDivPositive(OpBuilder &builder, Location loc, Value dividend, + int64_t divisor) { assert(divisor > 0 && "expected positive divisor"); assert(dividend->getType().isIndex() && "expected index-typed value"); - ValuePtr divisorMinusOneCst = - builder.create<ConstantIndexOp>(loc, divisor - 1); - ValuePtr divisorCst = builder.create<ConstantIndexOp>(loc, divisor); - ValuePtr sum = builder.create<AddIOp>(loc, dividend, divisorMinusOneCst); + Value divisorMinusOneCst = builder.create<ConstantIndexOp>(loc, divisor - 1); + Value divisorCst = builder.create<ConstantIndexOp>(loc, divisor); + Value sum = builder.create<AddIOp>(loc, dividend, divisorMinusOneCst); return builder.create<SignedDivIOp>(loc, sum, divisorCst); } @@ -849,13 +847,13 @@ static ValuePtr ceilDivPositive(OpBuilder &builder, Location loc, // positive value: // ceildiv(a, b) = divis(a + (b - 1), b) // where divis is rounding-to-zero division. -static ValuePtr ceilDivPositive(OpBuilder &builder, Location loc, - ValuePtr dividend, ValuePtr divisor) { +static Value ceilDivPositive(OpBuilder &builder, Location loc, Value dividend, + Value divisor) { assert(dividend->getType().isIndex() && "expected index-typed value"); - ValuePtr cstOne = builder.create<ConstantIndexOp>(loc, 1); - ValuePtr divisorMinusOne = builder.create<SubIOp>(loc, divisor, cstOne); - ValuePtr sum = builder.create<AddIOp>(loc, dividend, divisorMinusOne); + Value cstOne = builder.create<ConstantIndexOp>(loc, 1); + Value divisorMinusOne = builder.create<SubIOp>(loc, divisor, cstOne); + Value sum = builder.create<AddIOp>(loc, dividend, divisorMinusOne); return builder.create<SignedDivIOp>(loc, sum, divisor); } @@ -937,7 +935,7 @@ TileLoops mlir::extractFixedOuterLoops(loop::ForOp rootForOp, // iterations. Given that the loop current executes // numIterations = ceildiv((upperBound - lowerBound), step) // iterations, we need to tile with size ceildiv(numIterations, size[i]). - SmallVector<ValuePtr, 4> tileSizes; + SmallVector<Value, 4> tileSizes; tileSizes.reserve(sizes.size()); for (unsigned i = 0, e = sizes.size(); i < e; ++i) { assert(sizes[i] > 0 && "expected strictly positive size for strip-mining"); @@ -945,10 +943,10 @@ TileLoops mlir::extractFixedOuterLoops(loop::ForOp rootForOp, auto forOp = forOps[i]; OpBuilder builder(forOp); auto loc = forOp.getLoc(); - ValuePtr diff = + Value diff = builder.create<SubIOp>(loc, forOp.upperBound(), forOp.lowerBound()); - ValuePtr numIterations = ceilDivPositive(builder, loc, diff, forOp.step()); - ValuePtr iterationsPerBlock = + Value numIterations = ceilDivPositive(builder, loc, diff, forOp.step()); + Value iterationsPerBlock = ceilDivPositive(builder, loc, numIterations, sizes[i]); tileSizes.push_back(iterationsPerBlock); } @@ -968,7 +966,7 @@ TileLoops mlir::extractFixedOuterLoops(loop::ForOp rootForOp, // Replaces all uses of `orig` with `replacement` except if the user is listed // in `exceptions`. static void -replaceAllUsesExcept(ValuePtr orig, ValuePtr replacement, +replaceAllUsesExcept(Value orig, Value replacement, const SmallPtrSetImpl<Operation *> &exceptions) { for (auto &use : llvm::make_early_inc_range(orig->getUses())) { if (exceptions.count(use.getOwner()) == 0) @@ -1010,30 +1008,30 @@ static void normalizeLoop(loop::ForOp loop, loop::ForOp outer, // of the loop to go from 0 to the number of iterations, if necessary. // TODO(zinenko): introduce support for negative steps or emit dynamic asserts // on step positivity, whatever gets implemented first. - ValuePtr diff = + Value diff = builder.create<SubIOp>(loc, loop.upperBound(), loop.lowerBound()); - ValuePtr numIterations = ceilDivPositive(builder, loc, diff, loop.step()); + Value numIterations = ceilDivPositive(builder, loc, diff, loop.step()); loop.setUpperBound(numIterations); - ValuePtr lb = loop.lowerBound(); + Value lb = loop.lowerBound(); if (!isZeroBased) { - ValuePtr cst0 = builder.create<ConstantIndexOp>(loc, 0); + Value cst0 = builder.create<ConstantIndexOp>(loc, 0); loop.setLowerBound(cst0); } - ValuePtr step = loop.step(); + Value step = loop.step(); if (!isStepOne) { - ValuePtr cst1 = builder.create<ConstantIndexOp>(loc, 1); + Value cst1 = builder.create<ConstantIndexOp>(loc, 1); loop.setStep(cst1); } // Insert code computing the value of the original loop induction variable // from the "normalized" one. builder.setInsertionPointToStart(inner.getBody()); - ValuePtr scaled = + Value scaled = isStepOne ? loop.getInductionVar() : builder.create<MulIOp>(loc, loop.getInductionVar(), step); - ValuePtr shifted = + Value shifted = isZeroBased ? scaled : builder.create<AddIOp>(loc, scaled, lb); SmallPtrSet<Operation *, 2> preserve{scaled->getDefiningOp(), @@ -1057,7 +1055,7 @@ void mlir::coalesceLoops(MutableArrayRef<loop::ForOp> loops) { // of the number of iterations of all loops. OpBuilder builder(outermost); Location loc = outermost.getLoc(); - ValuePtr upperBound = outermost.upperBound(); + Value upperBound = outermost.upperBound(); for (auto loop : loops.drop_front()) upperBound = builder.create<MulIOp>(loc, upperBound, loop.upperBound()); outermost.setUpperBound(upperBound); @@ -1072,16 +1070,16 @@ void mlir::coalesceLoops(MutableArrayRef<loop::ForOp> loops) { // iv_i = floordiv(iv_linear, product-of-loop-ranges-until-i) mod range_i. // Compute these iteratively from the innermost loop by creating a "running // quotient" of division by the range. - ValuePtr previous = outermost.getInductionVar(); + Value previous = outermost.getInductionVar(); for (unsigned i = 0, e = loops.size(); i < e; ++i) { unsigned idx = loops.size() - i - 1; if (i != 0) previous = builder.create<SignedDivIOp>(loc, previous, loops[idx + 1].upperBound()); - ValuePtr iv = (i == e - 1) ? previous - : builder.create<SignedRemIOp>( - loc, previous, loops[idx].upperBound()); + Value iv = (i == e - 1) ? previous + : builder.create<SignedRemIOp>( + loc, previous, loops[idx].upperBound()); replaceAllUsesInRegionWith(loops[idx].getInductionVar(), iv, loops.back().region()); } @@ -1096,24 +1094,23 @@ void mlir::coalesceLoops(MutableArrayRef<loop::ForOp> loops) { second.erase(); } -void mlir::mapLoopToProcessorIds(loop::ForOp forOp, - ArrayRef<ValuePtr> processorId, - ArrayRef<ValuePtr> numProcessors) { +void mlir::mapLoopToProcessorIds(loop::ForOp forOp, ArrayRef<Value> processorId, + ArrayRef<Value> numProcessors) { assert(processorId.size() == numProcessors.size()); if (processorId.empty()) return; OpBuilder b(forOp); Location loc(forOp.getLoc()); - ValuePtr mul = processorId.front(); + Value mul = processorId.front(); for (unsigned i = 1, e = processorId.size(); i < e; ++i) mul = b.create<AddIOp>(loc, b.create<MulIOp>(loc, mul, numProcessors[i]), processorId[i]); - ValuePtr lb = b.create<AddIOp>(loc, forOp.lowerBound(), - b.create<MulIOp>(loc, forOp.step(), mul)); + Value lb = b.create<AddIOp>(loc, forOp.lowerBound(), + b.create<MulIOp>(loc, forOp.step(), mul)); forOp.setLowerBound(lb); - ValuePtr step = forOp.step(); + Value step = forOp.step(); for (auto numProcs : numProcessors) step = b.create<MulIOp>(loc, step, numProcs); forOp.setStep(step); @@ -1131,7 +1128,7 @@ findHighestBlockForPlacement(const MemRefRegion ®ion, Block &block, Block::iterator *copyInPlacementStart, Block::iterator *copyOutPlacementStart) { const auto *cst = region.getConstraints(); - SmallVector<ValuePtr, 4> symbols; + SmallVector<Value, 4> symbols; cst->getIdValues(cst->getNumDimIds(), cst->getNumDimAndSymbolIds(), &symbols); SmallVector<AffineForOp, 4> enclosingFors; @@ -1194,10 +1191,10 @@ static void getMultiLevelStrides(const MemRefRegion ®ion, /// returns the outermost AffineForOp of the copy loop nest. `memIndicesStart' /// holds the lower coordinates of the region in the original memref to copy /// in/out. If `copyOut' is true, generates a copy-out; otherwise a copy-in. -static AffineForOp generatePointWiseCopy(Location loc, ValuePtr memref, - ValuePtr fastMemRef, +static AffineForOp generatePointWiseCopy(Location loc, Value memref, + Value fastMemRef, AffineMap memAffineMap, - ArrayRef<ValuePtr> memIndicesStart, + ArrayRef<Value> memIndicesStart, ArrayRef<int64_t> fastBufferShape, bool isCopyOut, OpBuilder b) { assert(!memIndicesStart.empty() && "only 1-d or more memrefs"); @@ -1207,7 +1204,7 @@ static AffineForOp generatePointWiseCopy(Location loc, ValuePtr memref, // for y = ... // fast_buf[x][y] = buf[mem_x + x][mem_y + y] - SmallVector<ValuePtr, 4> fastBufIndices, memIndices; + SmallVector<Value, 4> fastBufIndices, memIndices; AffineForOp copyNestRoot; for (unsigned d = 0, e = fastBufferShape.size(); d < e; ++d) { auto forOp = b.create<AffineForOp>(loc, 0, fastBufferShape[d]); @@ -1216,7 +1213,7 @@ static AffineForOp generatePointWiseCopy(Location loc, ValuePtr memref, b = forOp.getBodyBuilder(); fastBufIndices.push_back(forOp.getInductionVar()); - ValuePtr memBase = + Value memBase = (memAffineMap == b.getMultiDimIdentityMap(memAffineMap.getNumDims())) ? memIndicesStart[d] : b.create<AffineApplyOp>( @@ -1269,7 +1266,7 @@ static LogicalResult generateCopy( const MemRefRegion ®ion, Block *block, Block::iterator begin, Block::iterator end, Block *copyPlacementBlock, Block::iterator copyInPlacementStart, Block::iterator copyOutPlacementStart, - AffineCopyOptions copyOptions, DenseMap<ValuePtr, ValuePtr> &fastBufferMap, + AffineCopyOptions copyOptions, DenseMap<Value, Value> &fastBufferMap, DenseSet<Operation *> ©Nests, uint64_t *sizeInBytes, Block::iterator *nBegin, Block::iterator *nEnd) { *nBegin = begin; @@ -1277,7 +1274,7 @@ static LogicalResult generateCopy( FuncOp f = begin->getParentOfType<FuncOp>(); OpBuilder topBuilder(f.getBody()); - ValuePtr zeroIndex = topBuilder.create<ConstantIndexOp>(f.getLoc(), 0); + Value zeroIndex = topBuilder.create<ConstantIndexOp>(f.getLoc(), 0); if (begin == end) return success(); @@ -1309,9 +1306,9 @@ static LogicalResult generateCopy( // Indices to use for the copying. // Indices for the original memref being copied from/to. - SmallVector<ValuePtr, 4> memIndices; + SmallVector<Value, 4> memIndices; // Indices for the faster buffer being copied into/from. - SmallVector<ValuePtr, 4> bufIndices; + SmallVector<Value, 4> bufIndices; unsigned rank = memRefType.getRank(); SmallVector<int64_t, 4> fastBufferShape; @@ -1337,7 +1334,7 @@ static LogicalResult generateCopy( // 'regionSymbols' hold values that this memory region is symbolic/parametric // on; these typically include loop IVs surrounding the level at which the // copy generation is being done or other valid symbols in MLIR. - SmallVector<ValuePtr, 8> regionSymbols; + SmallVector<Value, 8> regionSymbols; cst->getIdValues(rank, cst->getNumIds(), ®ionSymbols); // Construct the index expressions for the fast memory buffer. The index @@ -1385,7 +1382,7 @@ static LogicalResult generateCopy( } // The faster memory space buffer. - ValuePtr fastMemRef; + Value fastMemRef; // Check if a buffer was already created. bool existingBuf = fastBufferMap.count(memref) > 0; @@ -1425,8 +1422,8 @@ static LogicalResult generateCopy( return failure(); } - ValuePtr stride = nullptr; - ValuePtr numEltPerStride = nullptr; + Value stride = nullptr; + Value numEltPerStride = nullptr; if (!strideInfos.empty()) { stride = top.create<ConstantIndexOp>(loc, strideInfos[0].stride); numEltPerStride = @@ -1465,7 +1462,7 @@ static LogicalResult generateCopy( copyOptions.tagMemorySpace); auto tagMemRef = prologue.create<AllocOp>(loc, tagMemRefType); - SmallVector<ValuePtr, 4> tagIndices({zeroIndex}); + SmallVector<Value, 4> tagIndices({zeroIndex}); auto tagAffineMap = b.getMultiDimIdentityMap(tagIndices.size()); fullyComposeAffineMapAndOperands(&tagAffineMap, &tagIndices); if (!region.isWrite()) { @@ -1574,7 +1571,7 @@ static bool getFullMemRefAsRegion(Operation *opInst, unsigned numParamLoopIVs, SmallVector<AffineForOp, 4> ivs; getLoopIVs(*opInst, &ivs); ivs.resize(numParamLoopIVs); - SmallVector<ValuePtr, 4> symbols; + SmallVector<Value, 4> symbols; extractForInductionVars(ivs, &symbols); regionCst->reset(rank, numParamLoopIVs, 0); regionCst->setIdValues(rank, rank + numParamLoopIVs, symbols); @@ -1621,12 +1618,12 @@ uint64_t mlir::affineDataCopyGenerate(Block::iterator begin, // List of memory regions to copy for. We need a map vector to have a // guaranteed iteration order to write test cases. CHECK-DAG doesn't help here // since the alloc's for example are identical except for the SSA id. - SmallMapVector<ValuePtr, std::unique_ptr<MemRefRegion>, 4> readRegions; - SmallMapVector<ValuePtr, std::unique_ptr<MemRefRegion>, 4> writeRegions; + SmallMapVector<Value, std::unique_ptr<MemRefRegion>, 4> readRegions; + SmallMapVector<Value, std::unique_ptr<MemRefRegion>, 4> writeRegions; // Map from original memref's to the fast buffers that their accesses are // replaced with. - DenseMap<ValuePtr, ValuePtr> fastBufferMap; + DenseMap<Value, Value> fastBufferMap; // To check for errors when walking the block. bool error = false; @@ -1676,7 +1673,7 @@ uint64_t mlir::affineDataCopyGenerate(Block::iterator begin, // Attempts to update; returns true if 'region' exists in targetRegions. auto updateRegion = - [&](const SmallMapVector<ValuePtr, std::unique_ptr<MemRefRegion>, 4> + [&](const SmallMapVector<Value, std::unique_ptr<MemRefRegion>, 4> &targetRegions) { auto it = targetRegions.find(region->memref); if (it == targetRegions.end()) @@ -1728,7 +1725,7 @@ uint64_t mlir::affineDataCopyGenerate(Block::iterator begin, uint64_t totalCopyBuffersSizeInBytes = 0; bool ret = true; auto processRegions = - [&](const SmallMapVector<ValuePtr, std::unique_ptr<MemRefRegion>, 4> + [&](const SmallMapVector<Value, std::unique_ptr<MemRefRegion>, 4> ®ions) { for (const auto ®ionEntry : regions) { // For each region, hoist copy in/out past all hoistable diff --git a/mlir/lib/Transforms/Utils/RegionUtils.cpp b/mlir/lib/Transforms/Utils/RegionUtils.cpp index 569c5416edd..ca26074f288 100644 --- a/mlir/lib/Transforms/Utils/RegionUtils.cpp +++ b/mlir/lib/Transforms/Utils/RegionUtils.cpp @@ -18,7 +18,7 @@ using namespace mlir; -void mlir::replaceAllUsesInRegionWith(ValuePtr orig, ValuePtr replacement, +void mlir::replaceAllUsesInRegionWith(Value orig, Value replacement, Region ®ion) { for (auto &use : llvm::make_early_inc_range(orig->getUses())) { if (region.isAncestor(use.getOwner()->getParentRegion())) @@ -54,14 +54,14 @@ void mlir::visitUsedValuesDefinedAbove( } void mlir::getUsedValuesDefinedAbove(Region ®ion, Region &limit, - llvm::SetVector<ValuePtr> &values) { + llvm::SetVector<Value> &values) { visitUsedValuesDefinedAbove(region, limit, [&](OpOperand *operand) { values.insert(operand->get()); }); } void mlir::getUsedValuesDefinedAbove(MutableArrayRef<Region> regions, - llvm::SetVector<ValuePtr> &values) { + llvm::SetVector<Value> &values) { for (Region ®ion : regions) getUsedValuesDefinedAbove(region, region, values); } @@ -137,8 +137,8 @@ namespace { class LiveMap { public: /// Value methods. - bool wasProvenLive(ValuePtr value) { return liveValues.count(value); } - void setProvedLive(ValuePtr value) { + bool wasProvenLive(Value value) { return liveValues.count(value); } + void setProvedLive(Value value) { changed |= liveValues.insert(value).second; } @@ -152,7 +152,7 @@ public: private: bool changed = false; - DenseSet<ValuePtr> liveValues; + DenseSet<Value> liveValues; DenseSet<Operation *> liveOps; }; } // namespace @@ -179,7 +179,7 @@ static bool isUseSpeciallyKnownDead(OpOperand &use, LiveMap &liveMap) { return false; } -static void processValue(ValuePtr value, LiveMap &liveMap) { +static void processValue(Value value, LiveMap &liveMap) { bool provedLive = llvm::any_of(value->getUses(), [&](OpOperand &use) { if (isUseSpeciallyKnownDead(use, liveMap)) return false; @@ -213,9 +213,9 @@ static void propagateLiveness(Operation *op, LiveMap &liveMap) { liveMap.setProvedLive(op); return; } - for (ValuePtr value : op->getResults()) + for (Value value : op->getResults()) processValue(value, liveMap); - bool provedLive = llvm::any_of(op->getResults(), [&](ValuePtr value) { + bool provedLive = llvm::any_of(op->getResults(), [&](Value value) { return liveMap.wasProvenLive(value); }); if (provedLive) @@ -231,7 +231,7 @@ static void propagateLiveness(Region ®ion, LiveMap &liveMap) { // faster convergence to a fixed point (we try to visit uses before defs). for (Operation &op : llvm::reverse(block->getOperations())) propagateLiveness(&op, liveMap); - for (ValuePtr value : block->getArguments()) + for (Value value : block->getArguments()) processValue(value, liveMap); } } @@ -250,7 +250,7 @@ static void eraseTerminatorSuccessorOperands(Operation *terminator, // Iterating args in reverse is needed for correctness, to avoid // shifting later args when earlier args are erased. unsigned arg = argE - argI - 1; - ValuePtr value = terminator->getSuccessor(succ)->getArgument(arg); + Value value = terminator->getSuccessor(succ)->getArgument(arg); if (!liveMap.wasProvenLive(value)) { terminator->eraseSuccessorOperand(succ, arg); } diff --git a/mlir/lib/Transforms/Utils/Utils.cpp b/mlir/lib/Transforms/Utils/Utils.cpp index 409729a5f20..a6629183dee 100644 --- a/mlir/lib/Transforms/Utils/Utils.cpp +++ b/mlir/lib/Transforms/Utils/Utils.cpp @@ -38,8 +38,7 @@ static bool isMemRefDereferencingOp(Operation &op) { } /// Return the AffineMapAttr associated with memory 'op' on 'memref'. -static NamedAttribute getAffineMapAttrForMemRef(Operation *op, - ValuePtr memref) { +static NamedAttribute getAffineMapAttrForMemRef(Operation *op, Value memref) { return TypeSwitch<Operation *, NamedAttribute>(op) .Case<AffineDmaStartOp, AffineLoadOp, AffinePrefetchOp, AffineStoreOp, AffineDmaWaitOp>( @@ -47,10 +46,12 @@ static NamedAttribute getAffineMapAttrForMemRef(Operation *op, } // Perform the replacement in `op`. -LogicalResult mlir::replaceAllMemRefUsesWith( - ValuePtr oldMemRef, ValuePtr newMemRef, Operation *op, - ArrayRef<ValuePtr> extraIndices, AffineMap indexRemap, - ArrayRef<ValuePtr> extraOperands, ArrayRef<ValuePtr> symbolOperands) { +LogicalResult mlir::replaceAllMemRefUsesWith(Value oldMemRef, Value newMemRef, + Operation *op, + ArrayRef<Value> extraIndices, + AffineMap indexRemap, + ArrayRef<Value> extraOperands, + ArrayRef<Value> symbolOperands) { unsigned newMemRefRank = newMemRef->getType().cast<MemRefType>().getRank(); (void)newMemRefRank; // unused in opt mode unsigned oldMemRefRank = oldMemRef->getType().cast<MemRefType>().getRank(); @@ -96,13 +97,13 @@ LogicalResult mlir::replaceAllMemRefUsesWith( NamedAttribute oldMapAttrPair = getAffineMapAttrForMemRef(op, oldMemRef); AffineMap oldMap = oldMapAttrPair.second.cast<AffineMapAttr>().getValue(); unsigned oldMapNumInputs = oldMap.getNumInputs(); - SmallVector<ValuePtr, 4> oldMapOperands( + SmallVector<Value, 4> oldMapOperands( op->operand_begin() + memRefOperandPos + 1, op->operand_begin() + memRefOperandPos + 1 + oldMapNumInputs); // Apply 'oldMemRefOperands = oldMap(oldMapOperands)'. - SmallVector<ValuePtr, 4> oldMemRefOperands; - SmallVector<ValuePtr, 4> affineApplyOps; + SmallVector<Value, 4> oldMemRefOperands; + SmallVector<Value, 4> affineApplyOps; oldMemRefOperands.reserve(oldMemRefRank); if (oldMap != builder.getMultiDimIdentityMap(oldMap.getNumDims())) { for (auto resultExpr : oldMap.getResults()) { @@ -120,14 +121,14 @@ LogicalResult mlir::replaceAllMemRefUsesWith( // Construct new indices as a remap of the old ones if a remapping has been // provided. The indices of a memref come right after it, i.e., // at position memRefOperandPos + 1. - SmallVector<ValuePtr, 4> remapOperands; + SmallVector<Value, 4> remapOperands; remapOperands.reserve(extraOperands.size() + oldMemRefRank + symbolOperands.size()); remapOperands.append(extraOperands.begin(), extraOperands.end()); remapOperands.append(oldMemRefOperands.begin(), oldMemRefOperands.end()); remapOperands.append(symbolOperands.begin(), symbolOperands.end()); - SmallVector<ValuePtr, 4> remapOutputs; + SmallVector<Value, 4> remapOutputs; remapOutputs.reserve(oldMemRefRank); if (indexRemap && @@ -146,7 +147,7 @@ LogicalResult mlir::replaceAllMemRefUsesWith( remapOutputs.append(remapOperands.begin(), remapOperands.end()); } - SmallVector<ValuePtr, 4> newMapOperands; + SmallVector<Value, 4> newMapOperands; newMapOperands.reserve(newMemRefRank); // Prepend 'extraIndices' in 'newMapOperands'. @@ -214,11 +215,13 @@ LogicalResult mlir::replaceAllMemRefUsesWith( return success(); } -LogicalResult mlir::replaceAllMemRefUsesWith( - ValuePtr oldMemRef, ValuePtr newMemRef, ArrayRef<ValuePtr> extraIndices, - AffineMap indexRemap, ArrayRef<ValuePtr> extraOperands, - ArrayRef<ValuePtr> symbolOperands, Operation *domInstFilter, - Operation *postDomInstFilter) { +LogicalResult mlir::replaceAllMemRefUsesWith(Value oldMemRef, Value newMemRef, + ArrayRef<Value> extraIndices, + AffineMap indexRemap, + ArrayRef<Value> extraOperands, + ArrayRef<Value> symbolOperands, + Operation *domInstFilter, + Operation *postDomInstFilter) { unsigned newMemRefRank = newMemRef->getType().cast<MemRefType>().getRank(); (void)newMemRefRank; // unused in opt mode unsigned oldMemRefRank = oldMemRef->getType().cast<MemRefType>().getRank(); @@ -319,7 +322,7 @@ LogicalResult mlir::replaceAllMemRefUsesWith( void mlir::createAffineComputationSlice( Operation *opInst, SmallVectorImpl<AffineApplyOp> *sliceOps) { // Collect all operands that are results of affine apply ops. - SmallVector<ValuePtr, 4> subOperands; + SmallVector<Value, 4> subOperands; subOperands.reserve(opInst->getNumOperands()); for (auto operand : opInst->getOperands()) if (isa_and_nonnull<AffineApplyOp>(operand->getDefiningOp())) @@ -349,7 +352,7 @@ void mlir::createAffineComputationSlice( return; OpBuilder builder(opInst); - SmallVector<ValuePtr, 4> composedOpOperands(subOperands); + SmallVector<Value, 4> composedOpOperands(subOperands); auto composedMap = builder.getMultiDimIdentityMap(composedOpOperands.size()); fullyComposeAffineMapAndOperands(&composedMap, &composedOpOperands); @@ -366,7 +369,7 @@ void mlir::createAffineComputationSlice( // affine apply op above instead of existing ones (subOperands). So, they // differ from opInst's operands only for those operands in 'subOperands', for // which they will be replaced by the corresponding one from 'sliceOps'. - SmallVector<ValuePtr, 4> newOperands(opInst->getOperands()); + SmallVector<Value, 4> newOperands(opInst->getOperands()); for (unsigned i = 0, e = newOperands.size(); i < e; i++) { // Replace the subOperands from among the new operands. unsigned j, f; @@ -440,7 +443,7 @@ LogicalResult mlir::normalizeMemRef(AllocOp allocOp) { } auto oldMemRef = allocOp.getResult(); - SmallVector<ValuePtr, 4> symbolOperands(allocOp.getSymbolicOperands()); + SmallVector<Value, 4> symbolOperands(allocOp.getSymbolicOperands()); auto newMemRefType = MemRefType::get(newShape, memrefType.getElementType(), b.getMultiDimIdentityMap(newRank)); diff --git a/mlir/lib/Transforms/Vectorize.cpp b/mlir/lib/Transforms/Vectorize.cpp index 2dbac868cc0..6b2b3e1ee7e 100644 --- a/mlir/lib/Transforms/Vectorize.cpp +++ b/mlir/lib/Transforms/Vectorize.cpp @@ -696,7 +696,7 @@ struct VectorizationState { // Map of old scalar Operation to new vectorized Operation. DenseMap<Operation *, Operation *> vectorizationMap; // Map of old scalar Value to new vectorized Value. - DenseMap<ValuePtr, ValuePtr> replacementMap; + DenseMap<Value, Value> replacementMap; // The strategy drives which loop to vectorize by which amount. const VectorizationStrategy *strategy; // Use-def roots. These represent the starting points for the worklist in the @@ -719,7 +719,7 @@ struct VectorizationState { OperationFolder *folder; private: - void registerReplacement(ValuePtr key, ValuePtr value); + void registerReplacement(Value key, Value value); }; } // end namespace @@ -759,7 +759,7 @@ void VectorizationState::finishVectorizationPattern() { } } -void VectorizationState::registerReplacement(ValuePtr key, ValuePtr value) { +void VectorizationState::registerReplacement(Value key, Value value) { assert(replacementMap.count(key) == 0 && "replacement already registered"); replacementMap.insert(std::make_pair(key, value)); } @@ -767,7 +767,7 @@ void VectorizationState::registerReplacement(ValuePtr key, ValuePtr value) { // Apply 'map' with 'mapOperands' returning resulting values in 'results'. static void computeMemoryOpIndices(Operation *op, AffineMap map, ValueRange mapOperands, - SmallVectorImpl<ValuePtr> &results) { + SmallVectorImpl<Value> &results) { OpBuilder builder(op); for (auto resultExpr : map.getResults()) { auto singleResMap = @@ -794,7 +794,7 @@ static void computeMemoryOpIndices(Operation *op, AffineMap map, /// Such special cases force us to delay the vectorization of the stores until /// the last step. Here we merely register the store operation. template <typename LoadOrStoreOpPointer> -static LogicalResult vectorizeRootOrTerminal(ValuePtr iv, +static LogicalResult vectorizeRootOrTerminal(Value iv, LoadOrStoreOpPointer memoryOp, VectorizationState *state) { auto memRefType = memoryOp.getMemRef()->getType().template cast<MemRefType>(); @@ -814,7 +814,7 @@ static LogicalResult vectorizeRootOrTerminal(ValuePtr iv, if (auto load = dyn_cast<AffineLoadOp>(opInst)) { OpBuilder b(opInst); ValueRange mapOperands = load.getMapOperands(); - SmallVector<ValuePtr, 8> indices; + SmallVector<Value, 8> indices; indices.reserve(load.getMemRefType().getRank()); if (load.getAffineMap() != b.getMultiDimIdentityMap(load.getMemRefType().getRank())) { @@ -941,8 +941,7 @@ vectorizeLoopsAndLoadsRecursively(NestedMatch oneMatch, /// element type. /// If `type` is not a valid vector type or if the scalar constant is not a /// valid vector element type, returns nullptr. -static ValuePtr vectorizeConstant(Operation *op, ConstantOp constant, - Type type) { +static Value vectorizeConstant(Operation *op, ConstantOp constant, Type type) { if (!type || !type.isa<VectorType>() || !VectorType::isValidElementType(constant.getType())) { return nullptr; @@ -980,8 +979,8 @@ static ValuePtr vectorizeConstant(Operation *op, ConstantOp constant, /// vectorization is possible with the above logic. Returns nullptr otherwise. /// /// TODO(ntv): handle more complex cases. -static ValuePtr vectorizeOperand(ValuePtr operand, Operation *op, - VectorizationState *state) { +static Value vectorizeOperand(Value operand, Operation *op, + VectorizationState *state) { LLVM_DEBUG(dbgs() << "\n[early-vect]vectorize operand: "); LLVM_DEBUG(operand->print(dbgs())); // 1. If this value has already been vectorized this round, we are done. @@ -1043,7 +1042,7 @@ static Operation *vectorizeOneOperation(Operation *opInst, auto vectorValue = vectorizeOperand(value, opInst, state); ValueRange mapOperands = store.getMapOperands(); - SmallVector<ValuePtr, 8> indices; + SmallVector<Value, 8> indices; indices.reserve(store.getMemRefType().getRank()); if (store.getAffineMap() != b.getMultiDimIdentityMap(store.getMemRefType().getRank())) { @@ -1076,12 +1075,12 @@ static Operation *vectorizeOneOperation(Operation *opInst, vectorTypes.push_back( VectorType::get(state->strategy->vectorSizes, v->getType())); } - SmallVector<ValuePtr, 8> vectorOperands; + SmallVector<Value, 8> vectorOperands; for (auto v : opInst->getOperands()) { vectorOperands.push_back(vectorizeOperand(v, opInst, state)); } // Check whether a single operand is null. If so, vectorization failed. - bool success = llvm::all_of(vectorOperands, [](ValuePtr op) { return op; }); + bool success = llvm::all_of(vectorOperands, [](Value op) { return op; }); if (!success) { LLVM_DEBUG(dbgs() << "\n[early-vect]+++++ an operand failed vectorize"); return nullptr; |

