mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2024-12-04 20:20:54 +00:00
Revert "[IR] Add a Location to BlockArgument." and follow-on commit
"[mlir] Speed up Lexer::getEncodedSourceLocation" This reverts commit3043be9d2d
and commit861d69a525
. This change resulted in printing textual MLIR that can't be parsed; see review thread https://reviews.llvm.org/D102567 for details.
This commit is contained in:
parent
68abc3d264
commit
80d981eda6
@ -22,8 +22,7 @@ class BitVector;
|
||||
|
||||
namespace mlir {
|
||||
class TypeRange;
|
||||
template <typename ValueRangeT>
|
||||
class ValueTypeRange;
|
||||
template <typename ValueRangeT> class ValueTypeRange;
|
||||
|
||||
/// `Block` represents an ordered list of `Operation`s.
|
||||
class Block : public IRObjectWithUseList<BlockOperand>,
|
||||
@ -88,21 +87,18 @@ public:
|
||||
bool args_empty() { return arguments.empty(); }
|
||||
|
||||
/// Add one value to the argument list.
|
||||
BlockArgument addArgument(Type type, Optional<Location> loc = {});
|
||||
BlockArgument addArgument(Type type);
|
||||
|
||||
/// Insert one value to the position in the argument list indicated by the
|
||||
/// given iterator. The existing arguments are shifted. The block is expected
|
||||
/// not to have predecessors.
|
||||
BlockArgument insertArgument(args_iterator it, Type type,
|
||||
Optional<Location> loc = {});
|
||||
BlockArgument insertArgument(args_iterator it, Type type);
|
||||
|
||||
/// Add one argument to the argument list for each type specified in the list.
|
||||
iterator_range<args_iterator> addArguments(TypeRange types,
|
||||
ArrayRef<Location> locs = {});
|
||||
iterator_range<args_iterator> addArguments(TypeRange types);
|
||||
|
||||
/// Add one value to the argument list at the specified position.
|
||||
BlockArgument insertArgument(unsigned index, Type type,
|
||||
Optional<Location> loc = {});
|
||||
BlockArgument insertArgument(unsigned index, Type type);
|
||||
|
||||
/// Erase the argument at 'index' and remove it from the argument list.
|
||||
void eraseArgument(unsigned index);
|
||||
@ -181,18 +177,15 @@ public:
|
||||
|
||||
/// Return an iterator range over the operations within this block that are of
|
||||
/// 'OpT'.
|
||||
template <typename OpT>
|
||||
iterator_range<op_iterator<OpT>> getOps() {
|
||||
template <typename OpT> iterator_range<op_iterator<OpT>> getOps() {
|
||||
auto endIt = end();
|
||||
return {detail::op_filter_iterator<OpT, iterator>(begin(), endIt),
|
||||
detail::op_filter_iterator<OpT, iterator>(endIt, endIt)};
|
||||
}
|
||||
template <typename OpT>
|
||||
op_iterator<OpT> op_begin() {
|
||||
template <typename OpT> op_iterator<OpT> op_begin() {
|
||||
return detail::op_filter_iterator<OpT, iterator>(begin(), end());
|
||||
}
|
||||
template <typename OpT>
|
||||
op_iterator<OpT> op_end() {
|
||||
template <typename OpT> op_iterator<OpT> op_end() {
|
||||
return detail::op_filter_iterator<OpT, iterator>(end(), end());
|
||||
}
|
||||
|
||||
|
@ -79,8 +79,7 @@ public:
|
||||
NoneType getNoneType();
|
||||
|
||||
/// Get or construct an instance of the type 'ty' with provided arguments.
|
||||
template <typename Ty, typename... Args>
|
||||
Ty getType(Args... args) {
|
||||
template <typename Ty, typename... Args> Ty getType(Args... args) {
|
||||
return Ty::get(context, args...);
|
||||
}
|
||||
|
||||
@ -373,13 +372,11 @@ public:
|
||||
/// end of it. The block is inserted at the provided insertion point of
|
||||
/// 'parent'.
|
||||
Block *createBlock(Region *parent, Region::iterator insertPt = {},
|
||||
TypeRange argTypes = llvm::None,
|
||||
ArrayRef<Location> locs = {});
|
||||
TypeRange argTypes = llvm::None);
|
||||
|
||||
/// Add new block with 'argTypes' arguments and set the insertion point to the
|
||||
/// end of it. The block is placed before 'insertBefore'.
|
||||
Block *createBlock(Block *insertBefore, TypeRange argTypes = llvm::None,
|
||||
ArrayRef<Location> locs = {});
|
||||
Block *createBlock(Block *insertBefore, TypeRange argTypes = llvm::None);
|
||||
|
||||
//===--------------------------------------------------------------------===//
|
||||
// Operation Creation
|
||||
@ -475,8 +472,7 @@ public:
|
||||
Operation *cloneWithoutRegions(Operation &op) {
|
||||
return insert(op.cloneWithoutRegions());
|
||||
}
|
||||
template <typename OpT>
|
||||
OpT cloneWithoutRegions(OpT op) {
|
||||
template <typename OpT> OpT cloneWithoutRegions(OpT op) {
|
||||
return cast<OpT>(cloneWithoutRegions(*op.getOperation()));
|
||||
}
|
||||
|
||||
|
@ -40,15 +40,6 @@ public:
|
||||
/// operation.
|
||||
virtual void printNewline() = 0;
|
||||
|
||||
/// Print a block argument in the usual format of:
|
||||
/// %ssaName : type {attr1=42} loc("here")
|
||||
/// where location printing is controlled by the standard internal option.
|
||||
/// You may pass omitType=true to not print a type, and pass an empty
|
||||
/// attribute list if you don't care for attributes.
|
||||
virtual void printRegionArgument(BlockArgument arg,
|
||||
ArrayRef<NamedAttribute> argAttrs = {},
|
||||
bool omitType = false) = 0;
|
||||
|
||||
/// Print implementations for various things an operation contains.
|
||||
virtual void printOperand(Value value) = 0;
|
||||
virtual void printOperand(Value value, raw_ostream &os) = 0;
|
||||
@ -587,10 +578,6 @@ public:
|
||||
StringRef attrName,
|
||||
NamedAttrList &attrs) = 0;
|
||||
|
||||
/// Parse a loc(...) specifier if present, filling in result if so.
|
||||
virtual ParseResult
|
||||
parseOptionalLocationSpecifier(Optional<Location> &result) = 0;
|
||||
|
||||
//===--------------------------------------------------------------------===//
|
||||
// Operand Parsing
|
||||
//===--------------------------------------------------------------------===//
|
||||
|
@ -85,8 +85,7 @@ public:
|
||||
Value(const Value &) = default;
|
||||
Value &operator=(const Value &) = default;
|
||||
|
||||
template <typename U>
|
||||
bool isa() const {
|
||||
template <typename U> bool isa() const {
|
||||
assert(*this && "isa<> used on a null type.");
|
||||
return U::classof(*this);
|
||||
}
|
||||
@ -95,16 +94,13 @@ public:
|
||||
bool isa() const {
|
||||
return isa<First>() || isa<Second, Rest...>();
|
||||
}
|
||||
template <typename U>
|
||||
U dyn_cast() const {
|
||||
template <typename U> U dyn_cast() const {
|
||||
return isa<U>() ? U(impl) : U(nullptr);
|
||||
}
|
||||
template <typename U>
|
||||
U dyn_cast_or_null() const {
|
||||
template <typename U> U dyn_cast_or_null() const {
|
||||
return (*this && isa<U>()) ? U(impl) : U(nullptr);
|
||||
}
|
||||
template <typename U>
|
||||
U cast() const {
|
||||
template <typename U> U cast() const {
|
||||
assert(isa<U>());
|
||||
return U(impl);
|
||||
}
|
||||
@ -138,9 +134,9 @@ public:
|
||||
return llvm::dyn_cast_or_null<OpTy>(getDefiningOp());
|
||||
}
|
||||
|
||||
/// Return the location of this value.
|
||||
/// If this value is the result of an operation, use it as a location,
|
||||
/// otherwise return an unknown location.
|
||||
Location getLoc() const;
|
||||
void setLoc(Location loc);
|
||||
|
||||
/// Return the Region in which this Value is defined.
|
||||
Region *getParentRegion();
|
||||
@ -254,9 +250,8 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
BlockArgumentImpl(Type type, Block *owner, int64_t index, Location loc)
|
||||
: ValueImpl(type, Kind::BlockArgument), owner(owner), index(index),
|
||||
loc(loc) {}
|
||||
BlockArgumentImpl(Type type, Block *owner, int64_t index)
|
||||
: ValueImpl(type, Kind::BlockArgument), owner(owner), index(index) {}
|
||||
|
||||
/// The owner of this argument.
|
||||
Block *owner;
|
||||
@ -264,9 +259,6 @@ private:
|
||||
/// The position in the argument list.
|
||||
int64_t index;
|
||||
|
||||
/// The source location of this argument.
|
||||
Location loc;
|
||||
|
||||
/// Allow access to owner and constructor.
|
||||
friend BlockArgument;
|
||||
};
|
||||
@ -287,15 +279,10 @@ public:
|
||||
/// Returns the number of this argument.
|
||||
unsigned getArgNumber() const { return getImpl()->index; }
|
||||
|
||||
/// Return the location for this argument.
|
||||
Location getLoc() const { return getImpl()->loc; }
|
||||
void setLoc(Location loc) { getImpl()->loc = loc; }
|
||||
|
||||
private:
|
||||
/// Allocate a new argument with the given type and owner.
|
||||
static BlockArgument create(Type type, Block *owner, int64_t index,
|
||||
Location loc) {
|
||||
return new detail::BlockArgumentImpl(type, owner, index, loc);
|
||||
static BlockArgument create(Type type, Block *owner, int64_t index) {
|
||||
return new detail::BlockArgumentImpl(type, owner, index);
|
||||
}
|
||||
|
||||
/// Destroy and deallocate this argument.
|
||||
@ -439,8 +426,7 @@ inline ::llvm::hash_code hash_value(Value arg) {
|
||||
|
||||
namespace llvm {
|
||||
|
||||
template <>
|
||||
struct DenseMapInfo<mlir::Value> {
|
||||
template <> struct DenseMapInfo<mlir::Value> {
|
||||
static mlir::Value getEmptyKey() {
|
||||
void *pointer = llvm::DenseMapInfo<void *>::getEmptyKey();
|
||||
return mlir::Value::getFromOpaquePointer(pointer);
|
||||
@ -467,8 +453,7 @@ struct DenseMapInfo<mlir::BlockArgument> : public DenseMapInfo<mlir::Value> {
|
||||
};
|
||||
|
||||
/// Allow stealing the low bits of a value.
|
||||
template <>
|
||||
struct PointerLikeTypeTraits<mlir::Value> {
|
||||
template <> struct PointerLikeTypeTraits<mlir::Value> {
|
||||
public:
|
||||
static inline void *getAsVoidPointer(mlir::Value value) {
|
||||
return const_cast<void *>(value.getAsOpaquePointer());
|
||||
|
@ -485,8 +485,6 @@ private:
|
||||
void printSuccessor(Block *) override {}
|
||||
void printSuccessorAndUseList(Block *, ValueRange) override {}
|
||||
void shadowRegionArgs(Region &, ValueRange) override {}
|
||||
void printRegionArgument(BlockArgument arg, ArrayRef<NamedAttribute> argAttrs,
|
||||
bool omitType) override {}
|
||||
|
||||
/// The printer flags to use when determining potential aliases.
|
||||
const OpPrintingFlags &printerFlags;
|
||||
@ -2347,15 +2345,6 @@ public:
|
||||
ModulePrinter::printAttribute(attr, AttrTypeElision::Must);
|
||||
}
|
||||
|
||||
/// Print a block argument in the usual format of:
|
||||
/// %ssaName : type {attr1=42} loc("here")
|
||||
/// where location printing is controlled by the standard internal option.
|
||||
/// You may pass omitType=true to not print a type, and pass an empty
|
||||
/// attribute list if you don't care for attributes.
|
||||
void printRegionArgument(BlockArgument arg,
|
||||
ArrayRef<NamedAttribute> argAttrs = {},
|
||||
bool omitType = false) override;
|
||||
|
||||
/// Print the ID for the given value.
|
||||
void printOperand(Value value) override { printValueID(value); }
|
||||
void printOperand(Value value, raw_ostream &os) override {
|
||||
@ -2430,23 +2419,6 @@ void OperationPrinter::printTopLevelOperation(Operation *op) {
|
||||
state->getAliasState().printDeferredAliases(os, newLine);
|
||||
}
|
||||
|
||||
/// Print a block argument in the usual format of:
|
||||
/// %ssaName : type {attr1=42} loc("here")
|
||||
/// where location printing is controlled by the standard internal option.
|
||||
/// You may pass omitType=true to not print a type, and pass an empty
|
||||
/// attribute list if you don't care for attributes.
|
||||
void OperationPrinter::printRegionArgument(BlockArgument arg,
|
||||
ArrayRef<NamedAttribute> argAttrs,
|
||||
bool omitType) {
|
||||
printOperand(arg);
|
||||
if (!omitType) {
|
||||
os << ": ";
|
||||
printType(arg.getType());
|
||||
}
|
||||
printOptionalAttrDict(argAttrs);
|
||||
printTrailingLocation(arg.getLoc());
|
||||
}
|
||||
|
||||
void OperationPrinter::print(Operation *op) {
|
||||
// Track the location of this operation.
|
||||
state->registerOperationLocation(op, newLine.curLine, currentIndent);
|
||||
@ -2557,7 +2529,6 @@ void OperationPrinter::print(Block *block, bool printBlockArgs,
|
||||
printValueID(arg);
|
||||
os << ": ";
|
||||
printType(arg.getType());
|
||||
printTrailingLocation(arg.getLoc());
|
||||
});
|
||||
os << ')';
|
||||
}
|
||||
@ -2729,7 +2700,7 @@ void IntegerSet::print(raw_ostream &os) const {
|
||||
void Value::print(raw_ostream &os) {
|
||||
if (auto *op = getDefiningOp())
|
||||
return op->print(os);
|
||||
// TODO: Improve BlockArgument print'ing.
|
||||
// TODO: Improve this.
|
||||
BlockArgument arg = this->cast<BlockArgument>();
|
||||
os << "<block argument> of type '" << arg.getType()
|
||||
<< "' at index: " << arg.getArgNumber() << '\n';
|
||||
@ -2738,7 +2709,7 @@ void Value::print(raw_ostream &os, AsmState &state) {
|
||||
if (auto *op = getDefiningOp())
|
||||
return op->print(os, state);
|
||||
|
||||
// TODO: Improve BlockArgument print'ing.
|
||||
// TODO: Improve this.
|
||||
BlockArgument arg = this->cast<BlockArgument>();
|
||||
os << "<block argument> of type '" << arg.getType()
|
||||
<< "' at index: " << arg.getArgNumber() << '\n';
|
||||
|
@ -138,54 +138,23 @@ auto Block::getArgumentTypes() -> ValueTypeRange<BlockArgListType> {
|
||||
return ValueTypeRange<BlockArgListType>(getArguments());
|
||||
}
|
||||
|
||||
BlockArgument Block::addArgument(Type type, Optional<Location> loc) {
|
||||
// TODO: Require locations for BlockArguments.
|
||||
if (!loc.hasValue()) {
|
||||
// Use the location of the parent operation if the block is attached.
|
||||
if (Operation *parentOp = getParentOp())
|
||||
loc = parentOp->getLoc();
|
||||
else
|
||||
loc = UnknownLoc::get(type.getContext());
|
||||
}
|
||||
|
||||
BlockArgument arg = BlockArgument::create(type, this, arguments.size(), *loc);
|
||||
BlockArgument Block::addArgument(Type type) {
|
||||
BlockArgument arg = BlockArgument::create(type, this, arguments.size());
|
||||
arguments.push_back(arg);
|
||||
return arg;
|
||||
}
|
||||
|
||||
/// Add one argument to the argument list for each type specified in the list.
|
||||
auto Block::addArguments(TypeRange types, ArrayRef<Location> locs)
|
||||
-> iterator_range<args_iterator> {
|
||||
// TODO: Require locations for BlockArguments.
|
||||
assert((locs.empty() || types.size() == locs.size()) &&
|
||||
"incorrect number of block argument locations");
|
||||
auto Block::addArguments(TypeRange types) -> iterator_range<args_iterator> {
|
||||
size_t initialSize = arguments.size();
|
||||
|
||||
arguments.reserve(initialSize + types.size());
|
||||
|
||||
// TODO: Require locations for BlockArguments.
|
||||
if (locs.empty()) {
|
||||
for (auto type : types)
|
||||
addArgument(type);
|
||||
} else {
|
||||
for (auto typeAndLoc : llvm::zip(types, locs))
|
||||
addArgument(std::get<0>(typeAndLoc), std::get<1>(typeAndLoc));
|
||||
}
|
||||
for (auto type : types)
|
||||
addArgument(type);
|
||||
return {arguments.data() + initialSize, arguments.data() + arguments.size()};
|
||||
}
|
||||
|
||||
BlockArgument Block::insertArgument(unsigned index, Type type,
|
||||
Optional<Location> loc) {
|
||||
// TODO: Require locations for BlockArguments.
|
||||
if (!loc.hasValue()) {
|
||||
// Use the location of the parent operation if the block is attached.
|
||||
if (Operation *parentOp = getParentOp())
|
||||
loc = parentOp->getLoc();
|
||||
else
|
||||
loc = UnknownLoc::get(type.getContext());
|
||||
}
|
||||
|
||||
auto arg = BlockArgument::create(type, this, index, *loc);
|
||||
BlockArgument Block::insertArgument(unsigned index, Type type) {
|
||||
auto arg = BlockArgument::create(type, this, index);
|
||||
assert(index <= arguments.size());
|
||||
arguments.insert(arguments.begin() + index, arg);
|
||||
// Update the cached position for all the arguments after the newly inserted
|
||||
@ -198,11 +167,10 @@ BlockArgument Block::insertArgument(unsigned index, Type type,
|
||||
|
||||
/// Insert one value to the given position of the argument list. The existing
|
||||
/// arguments are shifted. The block is expected not to have predecessors.
|
||||
BlockArgument Block::insertArgument(args_iterator it, Type type,
|
||||
Optional<Location> loc) {
|
||||
BlockArgument Block::insertArgument(args_iterator it, Type type) {
|
||||
assert(llvm::empty(getPredecessors()) &&
|
||||
"cannot insert arguments to blocks with predecessors");
|
||||
return insertArgument(it->getArgNumber(), type, loc);
|
||||
return insertArgument(it->getArgNumber(), type);
|
||||
}
|
||||
|
||||
void Block::eraseArgument(unsigned index) {
|
||||
|
@ -371,13 +371,13 @@ Operation *OpBuilder::insert(Operation *op) {
|
||||
/// end of it. The block is inserted at the provided insertion point of
|
||||
/// 'parent'.
|
||||
Block *OpBuilder::createBlock(Region *parent, Region::iterator insertPt,
|
||||
TypeRange argTypes, ArrayRef<Location> locs) {
|
||||
TypeRange argTypes) {
|
||||
assert(parent && "expected valid parent region");
|
||||
if (insertPt == Region::iterator())
|
||||
insertPt = parent->end();
|
||||
|
||||
Block *b = new Block();
|
||||
b->addArguments(argTypes, locs);
|
||||
b->addArguments(argTypes);
|
||||
parent->getBlocks().insert(insertPt, b);
|
||||
setInsertionPointToEnd(b);
|
||||
|
||||
@ -388,11 +388,10 @@ Block *OpBuilder::createBlock(Region *parent, Region::iterator insertPt,
|
||||
|
||||
/// Add new block with 'argTypes' arguments and set the insertion point to the
|
||||
/// end of it. The block is placed before 'insertBefore'.
|
||||
Block *OpBuilder::createBlock(Block *insertBefore, TypeRange argTypes,
|
||||
ArrayRef<Location> locs) {
|
||||
Block *OpBuilder::createBlock(Block *insertBefore, TypeRange argTypes) {
|
||||
assert(insertBefore && "expected valid insertion block");
|
||||
return createBlock(insertBefore->getParent(), Region::iterator(insertBefore),
|
||||
argTypes, locs);
|
||||
argTypes);
|
||||
}
|
||||
|
||||
/// Create an operation given the fields represented as an OperationState.
|
||||
|
@ -59,13 +59,6 @@ ParseResult mlir::function_like_impl::parseFunctionArgumentList(
|
||||
if (!allowAttributes && !attrs.empty())
|
||||
return parser.emitError(loc, "expected arguments without attributes");
|
||||
argAttrs.push_back(attrs);
|
||||
|
||||
// Parse a location if specified. TODO: Don't drop it on the floor.
|
||||
Optional<Location> explicitLoc;
|
||||
if (!argument.name.empty() &&
|
||||
parser.parseOptionalLocationSpecifier(explicitLoc))
|
||||
return failure();
|
||||
|
||||
return success();
|
||||
};
|
||||
|
||||
@ -305,15 +298,13 @@ void mlir::function_like_impl::printFunctionSignature(
|
||||
p << ", ";
|
||||
|
||||
if (!isExternal) {
|
||||
ArrayRef<NamedAttribute> attrs;
|
||||
if (argAttrs)
|
||||
attrs = argAttrs[i].cast<DictionaryAttr>().getValue();
|
||||
p.printRegionArgument(body.getArgument(i), attrs);
|
||||
} else {
|
||||
p.printType(argTypes[i]);
|
||||
if (argAttrs)
|
||||
p.printOptionalAttrDict(argAttrs[i].cast<DictionaryAttr>().getValue());
|
||||
p.printOperand(body.getArgument(i));
|
||||
p << ": ";
|
||||
}
|
||||
|
||||
p.printType(argTypes[i]);
|
||||
if (argAttrs)
|
||||
p.printOptionalAttrDict(argAttrs[i].cast<DictionaryAttr>().getValue());
|
||||
}
|
||||
|
||||
if (isVariadic) {
|
||||
|
@ -27,14 +27,10 @@ Location Value::getLoc() const {
|
||||
if (auto *op = getDefiningOp())
|
||||
return op->getLoc();
|
||||
|
||||
return cast<BlockArgument>().getLoc();
|
||||
}
|
||||
|
||||
void Value::setLoc(Location loc) {
|
||||
if (auto *op = getDefiningOp())
|
||||
return op->setLoc(loc);
|
||||
|
||||
return cast<BlockArgument>().setLoc(loc);
|
||||
// Use the location of the parent operation if this is a block argument.
|
||||
// TODO: Should we just add locations to block arguments?
|
||||
Operation *parentOp = cast<BlockArgument>().getOwner()->getParentOp();
|
||||
return parentOp ? parentOp->getLoc() : UnknownLoc::get(getContext());
|
||||
}
|
||||
|
||||
/// Return the Region in which this Value is defined.
|
||||
|
@ -41,14 +41,11 @@ Lexer::Lexer(const llvm::SourceMgr &sourceMgr, MLIRContext *context)
|
||||
Location Lexer::getEncodedSourceLocation(llvm::SMLoc loc) {
|
||||
auto &sourceMgr = getSourceMgr();
|
||||
unsigned mainFileID = sourceMgr.getMainFileID();
|
||||
auto &bufferInfo = sourceMgr.getBufferInfo(mainFileID);
|
||||
unsigned lineNo = bufferInfo.getLineNumber(loc.getPointer());
|
||||
unsigned column =
|
||||
(loc.getPointer() - bufferInfo.getPointerForLineNumber(lineNo)) + 1;
|
||||
auto lineAndColumn = sourceMgr.getLineAndColumn(loc, mainFileID);
|
||||
auto *buffer = sourceMgr.getMemoryBuffer(mainFileID);
|
||||
|
||||
return FileLineColLoc::get(context, buffer->getBufferIdentifier(), lineNo,
|
||||
column);
|
||||
return FileLineColLoc::get(context, buffer->getBufferIdentifier(),
|
||||
lineAndColumn.first, lineAndColumn.second);
|
||||
}
|
||||
|
||||
/// emitError - Emit an error message and return an Token::error token.
|
||||
|
@ -249,17 +249,11 @@ public:
|
||||
Operation *parseGenericOperation(Block *insertBlock,
|
||||
Block::iterator insertPt);
|
||||
|
||||
/// This type is used to keep track of things that are either an Operation or
|
||||
/// a BlockArgument. We cannot use Value for this, because not all Operations
|
||||
/// have results.
|
||||
using OpOrArgument = llvm::PointerUnion<Operation *, BlockArgument>;
|
||||
|
||||
/// Parse an optional trailing location and add it to the specifier Operation
|
||||
/// or `OperandType` if present.
|
||||
/// Parse an optional trailing location for the given operation.
|
||||
///
|
||||
/// trailing-location ::= (`loc` (`(` location `)` | attribute-alias))?
|
||||
///
|
||||
ParseResult parseTrailingLocationSpecifier(OpOrArgument opOrArgument);
|
||||
ParseResult parseTrailingOperationLocation(Operation *op);
|
||||
|
||||
/// This is the structure of a result specifier in the assembly syntax,
|
||||
/// including the name, number of results, and location.
|
||||
@ -391,8 +385,7 @@ private:
|
||||
|
||||
/// A set of operations whose locations reference aliases that have yet to
|
||||
/// be resolved.
|
||||
SmallVector<std::pair<OpOrArgument, Token>, 8>
|
||||
opsAndArgumentsWithDeferredLocs;
|
||||
SmallVector<std::pair<Operation *, Token>, 8> opsWithDeferredLocs;
|
||||
|
||||
/// The builder used when creating parsed operation instances.
|
||||
OpBuilder opBuilder;
|
||||
@ -440,7 +433,7 @@ ParseResult OperationParser::finalize() {
|
||||
|
||||
// Resolve the locations of any deferred operations.
|
||||
auto &attributeAliases = state.symbols.attributeAliasDefinitions;
|
||||
for (std::pair<OpOrArgument, Token> &it : opsAndArgumentsWithDeferredLocs) {
|
||||
for (std::pair<Operation *, Token> &it : opsWithDeferredLocs) {
|
||||
llvm::SMLoc tokLoc = it.second.getLoc();
|
||||
StringRef identifier = it.second.getSpelling().drop_front();
|
||||
Attribute attr = attributeAliases.lookup(identifier);
|
||||
@ -451,11 +444,7 @@ ParseResult OperationParser::finalize() {
|
||||
if (!locAttr)
|
||||
return emitError(tokLoc)
|
||||
<< "expected location, but found '" << attr << "'";
|
||||
auto opOrArgument = it.first;
|
||||
if (auto *op = opOrArgument.dyn_cast<Operation *>())
|
||||
op->setLoc(locAttr);
|
||||
else
|
||||
opOrArgument.get<BlockArgument>().setLoc(locAttr);
|
||||
it.first->setLoc(locAttr);
|
||||
}
|
||||
|
||||
// Pop the top level name scope.
|
||||
@ -974,7 +963,7 @@ Operation *OperationParser::parseGenericOperation() {
|
||||
|
||||
// Create the operation and try to parse a location for it.
|
||||
Operation *op = opBuilder.createOperation(result);
|
||||
if (parseTrailingLocationSpecifier(op))
|
||||
if (parseTrailingOperationLocation(op))
|
||||
return nullptr;
|
||||
return op;
|
||||
}
|
||||
@ -1370,22 +1359,6 @@ public:
|
||||
return success();
|
||||
}
|
||||
|
||||
/// Parse a loc(...) specifier if present, filling in result if so.
|
||||
ParseResult
|
||||
parseOptionalLocationSpecifier(Optional<Location> &result) override {
|
||||
// If there is a 'loc' we parse a trailing location.
|
||||
if (!parser.consumeIf(Token::kw_loc))
|
||||
return success();
|
||||
LocationAttr directLoc;
|
||||
if (parser.parseToken(Token::l_paren, "expected '(' in location") ||
|
||||
parser.parseLocationInstance(directLoc) ||
|
||||
parser.parseToken(Token::r_paren, "expected ')' in location"))
|
||||
return failure();
|
||||
|
||||
result = directLoc;
|
||||
return success();
|
||||
}
|
||||
|
||||
//===--------------------------------------------------------------------===//
|
||||
// Operand Parsing
|
||||
//===--------------------------------------------------------------------===//
|
||||
@ -1873,13 +1846,12 @@ OperationParser::parseCustomOperation(ArrayRef<ResultRecord> resultIDs) {
|
||||
|
||||
// Otherwise, create the operation and try to parse a location for it.
|
||||
Operation *op = opBuilder.createOperation(opState);
|
||||
if (parseTrailingLocationSpecifier(op))
|
||||
if (parseTrailingOperationLocation(op))
|
||||
return nullptr;
|
||||
return op;
|
||||
}
|
||||
|
||||
ParseResult
|
||||
OperationParser::parseTrailingLocationSpecifier(OpOrArgument opOrArgument) {
|
||||
ParseResult OperationParser::parseTrailingOperationLocation(Operation *op) {
|
||||
// If there is a 'loc' we parse a trailing location.
|
||||
if (!consumeIf(Token::kw_loc))
|
||||
return success();
|
||||
@ -1907,7 +1879,7 @@ OperationParser::parseTrailingLocationSpecifier(OpOrArgument opOrArgument) {
|
||||
<< "expected location, but found '" << attr << "'";
|
||||
} else {
|
||||
// Otherwise, remember this operation and resolve its location later.
|
||||
opsAndArgumentsWithDeferredLocs.emplace_back(opOrArgument, tok);
|
||||
opsWithDeferredLocs.emplace_back(op, tok);
|
||||
}
|
||||
|
||||
// Otherwise, we parse the location directly.
|
||||
@ -1918,12 +1890,8 @@ OperationParser::parseTrailingLocationSpecifier(OpOrArgument opOrArgument) {
|
||||
if (parseToken(Token::r_paren, "expected ')' in location"))
|
||||
return failure();
|
||||
|
||||
if (directLoc) {
|
||||
if (auto *op = opOrArgument.dyn_cast<Operation *>())
|
||||
op->setLoc(directLoc);
|
||||
else
|
||||
opOrArgument.get<BlockArgument>().setLoc(directLoc);
|
||||
}
|
||||
if (directLoc)
|
||||
op->setLoc(directLoc);
|
||||
return success();
|
||||
}
|
||||
|
||||
@ -1974,8 +1942,7 @@ ParseResult OperationParser::parseRegion(
|
||||
.attachNote(getEncodedSourceLocation(*defLoc))
|
||||
<< "previously referenced here";
|
||||
}
|
||||
auto loc = getEncodedSourceLocation(placeholderArgPair.first.loc);
|
||||
BlockArgument arg = block->addArgument(placeholderArgPair.second, loc);
|
||||
BlockArgument arg = block->addArgument(placeholderArgPair.second);
|
||||
|
||||
// Add a definition of this arg to the assembly state if provided.
|
||||
if (state.asmState)
|
||||
@ -2155,15 +2122,9 @@ ParseResult OperationParser::parseOptionalBlockArgList(Block *owner) {
|
||||
if (arg.getType() != type)
|
||||
return emitError("argument and block argument type mismatch");
|
||||
} else {
|
||||
auto loc = getEncodedSourceLocation(useInfo.loc);
|
||||
arg = owner->addArgument(type, loc);
|
||||
arg = owner->addArgument(type);
|
||||
}
|
||||
|
||||
// If the argument has an explicit loc(...) specifier, parse and apply
|
||||
// it.
|
||||
if (parseTrailingLocationSpecifier(arg))
|
||||
return failure();
|
||||
|
||||
// Mark this block argument definition in the parser state if it was
|
||||
// provided.
|
||||
if (state.asmState)
|
||||
|
@ -44,25 +44,5 @@ func @escape_strings() {
|
||||
// CHECK-ALIAS: "foo.op"() : () -> () loc(#[[LOC:.*]])
|
||||
"foo.op"() : () -> () loc(#loc)
|
||||
|
||||
// CHECK-LABEL: func @argLocs(
|
||||
// CHECK-SAME: %arg0: i32 loc({{.*}}locations.mlir":[[# @LINE+1]]:15),
|
||||
func @argLocs(%x: i32,
|
||||
// CHECK-SAME: %arg1: i64 loc({{.*}}locations.mlir":[[# @LINE+1]]:15))
|
||||
%y: i64 loc("hotdog")) {
|
||||
return
|
||||
}
|
||||
|
||||
// CHECK-LABEL: "foo.unknown_op_with_bbargs"()
|
||||
"foo.unknown_op_with_bbargs"() ({
|
||||
// CHECK-NEXT: ^bb0(%arg0: i32 loc({{.*}}locations.mlir":[[# @LINE+1]]:7),
|
||||
^bb0(%x: i32,
|
||||
// CHECK-SAME: %arg1: i32 loc("cheetos"),
|
||||
%y: i32 loc("cheetos"),
|
||||
// CHECK-SAME: %arg2: i32 loc("out_of_line_location")):
|
||||
%z: i32 loc(#loc)):
|
||||
%1 = addi %x, %y : i32
|
||||
"foo.yield"(%1) : (i32) -> ()
|
||||
}) : () -> ()
|
||||
|
||||
// CHECK-ALIAS: #[[LOC]] = loc("out_of_line_location")
|
||||
#loc = loc("out_of_line_location")
|
||||
|
@ -1,9 +1,7 @@
|
||||
// RUN: mlir-opt %s -test-legalize-type-conversion -allow-unregistered-dialect -split-input-file -verify-diagnostics | FileCheck %s
|
||||
|
||||
|
||||
func @test_invalid_arg_materialization(
|
||||
// expected-error@below {{failed to materialize conversion for block argument #0 that remained live after conversion, type was 'i16'}}
|
||||
%arg0: i16) {
|
||||
// expected-error@below {{failed to materialize conversion for block argument #0 that remained live after conversion, type was 'i16'}}
|
||||
func @test_invalid_arg_materialization(%arg0: i16) {
|
||||
// expected-note@below {{see existing live user here}}
|
||||
"foo.return"(%arg0) : (i16) -> ()
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ func @verifyZeroArg() -> i32 {
|
||||
}
|
||||
|
||||
// CHECK-LABEL: testIgnoreArgMatch
|
||||
// CHECK-SAME: (%{{[a-z0-9]*}}: i32 loc({{[^)]*}}), %[[ARG1:[a-z0-9]*]]: i32 loc({{[^)]*}}),
|
||||
// CHECK-SAME: (%{{[a-z0-9]*}}: i32, %[[ARG1:[a-z0-9]*]]: i32
|
||||
func @testIgnoreArgMatch(%arg0: i32, %arg1: i32, %arg2: i32, %arg3: f32) {
|
||||
// CHECK: "test.ignore_arg_match_dst"(%[[ARG1]]) {f = 15 : i64}
|
||||
"test.ignore_arg_match_src"(%arg0, %arg1, %arg2) {d = 42, e = 24, f = 15} : (i32, i32, i32) -> ()
|
||||
@ -53,7 +53,7 @@ func @testIgnoreArgMatch(%arg0: i32, %arg1: i32, %arg2: i32, %arg3: f32) {
|
||||
}
|
||||
|
||||
// CHECK-LABEL: verifyInterleavedOperandAttribute
|
||||
// CHECK-SAME: %[[ARG0:.*]]: i32 loc({{[^)]*}}), %[[ARG1:.*]]: i32 loc({{[^)]*}})
|
||||
// CHECK-SAME: %[[ARG0:.*]]: i32, %[[ARG1:.*]]: i32
|
||||
func @verifyInterleavedOperandAttribute(%arg0: i32, %arg1: i32) {
|
||||
// CHECK: "test.interleaved_operand_attr2"(%[[ARG0]], %[[ARG1]]) {attr1 = 15 : i64, attr2 = 42 : i64}
|
||||
"test.interleaved_operand_attr1"(%arg0, %arg1) {attr1 = 15, attr2 = 42} : (i32, i32) -> ()
|
||||
@ -114,7 +114,7 @@ func @verifyAllAttrConstraintOf() -> (i32, i32, i32) {
|
||||
}
|
||||
|
||||
// CHECK-LABEL: verifyManyArgs
|
||||
// CHECK-SAME: (%[[ARG:.*]]: i32 loc({{[^)]*}}))
|
||||
// CHECK-SAME: (%[[ARG:.*]]: i32)
|
||||
func @verifyManyArgs(%arg: i32) {
|
||||
// CHECK: "test.many_arguments"(%[[ARG]], %[[ARG]], %[[ARG]], %[[ARG]], %[[ARG]], %[[ARG]], %[[ARG]], %[[ARG]], %[[ARG]])
|
||||
// CHECK-SAME: {attr1 = 24 : i64, attr2 = 42 : i64, attr3 = 42 : i64, attr4 = 42 : i64, attr5 = 42 : i64, attr6 = 42 : i64, attr7 = 42 : i64, attr8 = 42 : i64, attr9 = 42 : i64}
|
||||
|
Loading…
Reference in New Issue
Block a user