22#include "llvm/ADT/STLExtras.h"
37 Block *succ = op.getDest();
38 Block *opParent = op->getBlock();
39 if (succ == opParent || !llvm::hasSingleElement(succ->
getPredecessors()))
45 for (
Value operand : op.getDestOperands())
46 if (
auto arg = dyn_cast<BlockArgument>(operand))
47 if (arg.getOwner() == succ)
54 if (isa<LandingpadOp>(succ->
front()))
57 [](
Operation &inner) { return isa<BlockTagOp>(inner); }))
60 if (op.getLoopAnnotationAttr())
70 assert(
index == 0 &&
"invalid successor index");
79 assert(
index < getNumSuccessors() &&
"invalid successor index");
81 : getFalseDestOperandsMutable());
87 std::optional<std::pair<uint32_t, uint32_t>> weights) {
92 static_cast<int32_t
>(weights->second)});
94 build(builder,
result, condition, trueOperands, falseOperands, weightsAttr,
95 {}, trueDest, falseDest);
109 if (!branchWeights.empty())
112 build(builder,
result, value, defaultOperands, caseOperands, caseValues,
113 weightsAttr, defaultDestination, caseDestinations);
122 if (!caseValues.empty()) {
123 ShapedType caseValueType = VectorType::get(
128 build(builder,
result, value, defaultDestination, defaultOperands,
129 caseValuesAttr, caseDestinations, caseOperands, branchWeights);
138 if (!caseValues.empty()) {
139 ShapedType caseValueType = VectorType::get(
144 build(builder,
result, value, defaultDestination, defaultOperands,
145 caseValuesAttr, caseDestinations, caseOperands, branchWeights);
161 auto parseCase = [&]() {
165 values.push_back(APInt(bitWidth, value,
true));
177 caseDestinations.push_back(destination);
178 caseOperands.emplace_back(operands);
179 caseOperandTypes.emplace_back(operandTypes);
185 ShapedType caseValueType =
186 VectorType::get(
static_cast<int64_t>(values.size()), flagType);
205 llvm::zip(caseValues, caseDestinations),
220LogicalResult SwitchOp::verify() {
221 if ((!getCaseValues() && !getCaseDestinations().empty()) ||
223 getCaseValues()->size() !=
224 static_cast<int64_t>(getCaseDestinations().size())))
225 return emitOpError(
"expects number of case values to match number of "
226 "case destinations");
227 if (getCaseValues() &&
229 return emitError(
"expects case value type to match condition value type");
232 if (getCaseValues()) {
233 llvm::SmallDenseMap<APInt, unsigned> firstCase;
234 for (
auto [
index, value] :
235 llvm::enumerate(getCaseValues()->getValues<APInt>())) {
241 llvm::raw_svector_ostream os(valueStr);
242 value.
print(os,
true);
243 if (value.isNegative()) {
245 value.
print(os,
false);
248 return emitOpError() <<
"case value " << valueStr
249 <<
" is repeated (cases " << it->second <<
" and "
257 assert(
index < getNumSuccessors() &&
"invalid successor index");
259 : getCaseOperandsMutable(
index - 1));
266LogicalResult ReturnOp::verify() {
267 auto parent = (*this)->getParentOfType<LLVMFuncOp>();
271 Type expectedType = parent.getFunctionType().getReturnType();
272 if (llvm::isa<LLVMVoidType>(expectedType)) {
276 diag.attachNote(parent->getLoc()) <<
"when returning from function";
280 if (llvm::isa<LLVMVoidType>(expectedType))
283 diag.attachNote(parent->getLoc()) <<
"when returning from function";
286 if (expectedType != getArg().
getType()) {
288 diag.attachNote(parent->getLoc()) <<
"when returning from function";
299 assert(
index < getNumSuccessors() &&
"invalid successor index");
311 rangeSegments.push_back(range.size());
325 Block *destination = nullptr;
326 SmallVector<OpAsmParser::UnresolvedOperand> operands;
327 SmallVector<Type> operandTypes;
329 if (parser.parseSuccessor(destination).failed())
332 if (succeeded(parser.parseOptionalLParen())) {
333 if (failed(parser.parseOperandList(
334 operands, OpAsmParser::Delimiter::None)) ||
335 failed(parser.parseColonTypeList(operandTypes)) ||
336 failed(parser.parseRParen()))
339 succOperandBlocks.push_back(destination);
340 succOperands.emplace_back(operands);
341 succOperandsTypes.emplace_back(operandTypes);
344 "successor blocks")))
354 llvm::zip(succs, succOperands),
360 if (!succOperands.empty())
365#define GET_OP_CLASSES
366#include "mlir/Dialect/LLVMIR/LLVMTerminatorOps.cpp.inc"
*if copies could not be generated due to yet unimplemented cases *copyInPlacementStart and copyOutPlacementStart in copyPlacementBlock *specify the insertion points where the incoming copies and outgoing should be inserted(the insertion happens right before the *insertion point). Since `begin` can itself be invalidated due to the memref *rewriting done from this method
static Type getElementType(Type type, ArrayRef< int32_t > indices, function_ref< InFlightDiagnostic(StringRef)> emitErrorFn)
Walks the given type hierarchy with the given indices, potentially down to component granularity,...
@ None
Zero or more operands with no delimiters.
@ Square
Square brackets surrounding zero or more operands.
virtual ParseResult parseColonTypeList(SmallVectorImpl< Type > &result)=0
Parse a colon followed by a type list, which must have at least one type.
virtual ParseResult parseCommaSeparatedList(Delimiter delimiter, function_ref< ParseResult()> parseElementFn, StringRef contextMessage=StringRef())=0
Parse a list of comma-separated items with an optional delimiter.
virtual ParseResult parseRParen()=0
Parse a ) token.
virtual ParseResult parseLSquare()=0
Parse a [ token.
virtual ParseResult parseRSquare()=0
Parse a ] token.
ParseResult parseInteger(IntT &result)
Parse an integer value from the stream.
virtual ParseResult parseColon()=0
Parse a : token.
virtual ParseResult parseOptionalRSquare()=0
Parse a ] token if present.
virtual ParseResult parseOptionalLParen()=0
Parse a ( token if present.
virtual void printNewline()
Print a newline and indent the printer to the start of the current operation/attribute/type.
This class provides an abstraction over the different types of ranges over Blocks.
Block represents an ordered list of Operations.
iterator_range< pred_iterator > getPredecessors()
iterator_range< iterator > without_terminator()
Return an iterator range over the operation within this block excluding the terminator operation at t...
DenseI32ArrayAttr getDenseI32ArrayAttr(ArrayRef< int32_t > values)
An attribute that represents a reference to a dense integer vector or tensor object.
static DenseIntElementsAttr get(const ShapedType &type, Arg &&arg)
Get an instance of a DenseIntElementsAttr with the given arguments.
This class represents a diagnostic that is inflight and set to be reported.
The OpAsmParser has methods for interacting with the asm parser: parsing things from it,...
virtual ParseResult parseSuccessor(Block *&dest)=0
Parse a single operation successor.
virtual ParseResult parseOperandList(SmallVectorImpl< UnresolvedOperand > &result, Delimiter delimiter=Delimiter::None, bool allowResultNumber=true, int requiredOperandCount=-1)=0
Parse zero or more SSA comma-separated operand references with a specified surrounding delimiter,...
This is a pure-virtual base class that exposes the asmprinter hooks necessary to implement a custom p...
virtual void printSuccessorAndUseList(Block *successor, ValueRange succOperands)=0
Print the successor and its operands.
This class helps build Operations.
This class represents a contiguous range of operand ranges, e.g.
Operation is the basic unit of execution within MLIR.
A special type of RewriterBase that coordinates the application of a rewrite pattern on the current I...
virtual void eraseOp(Operation *op)
This method erases an operation that is known to have no uses.
void mergeBlocks(Block *source, Block *dest, ValueRange argValues={})
Inline the operations of block 'source' into the end of block 'dest'.
This class models how operands are forwarded to block arguments in control flow.
This class implements the successor iterators for Block.
This class provides an abstraction for a range of TypeRange.
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
unsigned getIntOrFloatBitWidth() const
Return the bit width of an integer or a float type, assert failure on other types.
This class provides an abstraction over the different types of ranges over Values.
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
void print(raw_ostream &os) const
Type getType() const
Return the type of this value.
void printSwitchOpCases(mlir::OpAsmPrinter &p, mlir::LLVM::SwitchOp op, mlir::Type flagType, mlir::DenseIntElementsAttr caseValues, mlir::SuccessorRange caseDestinations, mlir::OperandRangeRange caseOperands, const mlir::TypeRangeRange &caseOperandTypes)
void printIndirectBrOpSucessors(mlir::OpAsmPrinter &p, mlir::LLVM::IndirectBrOp op, mlir::Type flagType, mlir::SuccessorRange succs, mlir::OperandRangeRange succOperands, const mlir::TypeRangeRange &succOperandsTypes)
mlir::ParseResult parseIndirectBrOpSucessors(mlir::OpAsmParser &parser, mlir::Type &flagType, mlir::SmallVectorImpl< mlir::Block * > &succOperandBlocks, mlir::SmallVectorImpl< mlir::SmallVector< mlir::OpAsmParser::UnresolvedOperand > > &succOperands, mlir::SmallVectorImpl< mlir::SmallVector< mlir::Type > > &succOperandsTypes)
mlir::ParseResult parseSwitchOpCases(mlir::OpAsmParser &parser, mlir::Type flagType, mlir::DenseIntElementsAttr &caseValues, mlir::SmallVectorImpl< mlir::Block * > &caseDestinations, mlir::SmallVectorImpl< mlir::SmallVector< mlir::OpAsmParser::UnresolvedOperand > > &caseOperands, mlir::SmallVectorImpl< mlir::SmallVector< mlir::Type > > &caseOperandTypes)
<cases> ::= [ (case (, case )* )?
Include the generated interface declarations.
Type getType(OpFoldResult ofr)
Returns the int type of the integer in ofr.
InFlightDiagnostic emitError(Location loc)
Utility method to emit an error message using this location.
detail::DenseArrayAttrImpl< int32_t > DenseI32ArrayAttr
This represents an operation in an abstracted form, suitable for use with the builder APIs.
T & getOrAddProperties()
Get (or create) the properties of the provided type to be set on the operation on creation.
void addOperands(ValueRange newOperands)
void addSuccessors(Block *successor)
Adds a successor to the operation sate. successor must not be null.