MLIR 24.0.0git
MemorySlot.cpp
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
11
12using namespace mlir;
13using namespace mlir::affine;
14
15//===----------------------------------------------------------------------===//
16// AffineForOp
17//===----------------------------------------------------------------------===//
18
19bool AffineForOp::isRegionPromotable(const MemorySlot &slot, Region *region,
20 bool hasValueStores) {
21 return true;
22}
23
24void AffineForOp::setupPromotion(
25 const MemorySlot &slot, Value reachingDef, bool hasValueStores,
26 llvm::SmallMapVector<Region *, Value, 2> &regionsToProcess) {
27 Region &bodyRegion = getBodyRegion();
28 if (!hasValueStores) {
29 regionsToProcess.insert({&bodyRegion, reachingDef});
30 return;
31 }
32
33 getInitsMutable().append(reachingDef);
34 bodyRegion.addArgument(slot.elemType, slot.ptr.getLoc());
35 regionsToProcess.insert({&bodyRegion, bodyRegion.getArguments().back()});
36}
37
38Value AffineForOp::finalizePromotion(
39 const MemorySlot &slot, Value reachingDef, bool hasValueStores,
40 const llvm::DenseMap<Block *, Value> &reachingAtBlockEnd,
41 OpBuilder &builder) {
42 if (!hasValueStores)
43 return reachingDef;
44
45 // Update the yield terminator to return the newly defined reaching
46 // definition.
47 memoryslot::updateTerminator(getBody(), reachingDef, reachingAtBlockEnd);
48
49 SmallVector<Type> resultTypes(getResultTypes());
50 resultTypes.push_back(slot.elemType);
51
52 IRRewriter rewriter(builder);
53 Operation *newOp =
54 memoryslot::replaceWithNewResults(rewriter, getOperation(), resultTypes);
55 return newOp->getResults().back();
56}
This class helps build Operations.
Definition Builders.h:210
result_range getResults()
Definition Operation.h:440
This class contains a list of basic blocks and a link to the parent operation it is attached to.
Definition Region.h:26
BlockArgListType getArguments()
Definition Region.h:94
BlockArgument addArgument(Type type, Location loc)
Add one value to the argument list.
Definition Region.h:111
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Definition Value.h:96
Location getLoc() const
Return the location of this value.
Definition Value.cpp:24
Operation * replaceWithNewResults(RewriterBase &rewriter, Operation *op, TypeRange resultTypes)
Creates a shallow copy of an operation with new result types, moving the regions out of the original ...
void updateTerminator(Block *block, Value defaultReachingDef, const DenseMap< Block *, Value > &reachingAtBlockEnd)
Appends the reaching definition for the given block as an operand to its terminator.
Include the generated interface declarations.
Represents a slot in memory.
Value ptr
Pointer to the memory slot, used by operations to refer to it.
Type elemType
Type of the value contained in the slot.