forked from OSchip/llvm-project
Replace the Function reference methods from the OpAsmParser/OpAsmPrinter with usages of FunctionAttr.
-- PiperOrigin-RevId: 250555680
This commit is contained in:
parent
c455ecef22
commit
1fd1c7a8bb
|
@ -30,7 +30,6 @@
|
|||
namespace mlir {
|
||||
|
||||
class Builder;
|
||||
class Function;
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// OpAsmPrinter
|
||||
|
@ -65,7 +64,6 @@ public:
|
|||
}
|
||||
}
|
||||
virtual void printType(Type type) = 0;
|
||||
virtual void printFunctionReference(Function *func) = 0;
|
||||
virtual void printAttribute(Attribute attr) = 0;
|
||||
virtual void printAttributeAndType(Attribute attr) = 0;
|
||||
|
||||
|
@ -110,7 +108,7 @@ inline OpAsmPrinter &operator<<(OpAsmPrinter &p, Attribute attr) {
|
|||
|
||||
// Support printing anything that isn't convertible to one of the above types,
|
||||
// even if it isn't exactly one of them. For example, we want to print
|
||||
// FunctionType with the Type& version above, not have it match this.
|
||||
// FunctionType with the Type version above, not have it match this.
|
||||
template <typename T, typename std::enable_if<
|
||||
!std::is_convertible<T &, Value &>::value &&
|
||||
!std::is_convertible<T &, Type &>::value &&
|
||||
|
@ -270,17 +268,6 @@ public:
|
|||
virtual ParseResult
|
||||
parseOptionalAttributeDict(SmallVectorImpl<NamedAttribute> &result) = 0;
|
||||
|
||||
/// Parse a function name like '@foo' and return the name in a form that can
|
||||
/// be passed to resolveFunctionName when a function type is available.
|
||||
virtual ParseResult parseFunctionName(StringRef &result,
|
||||
llvm::SMLoc &loc) = 0;
|
||||
|
||||
/// Parse a function name like '@foo` if present and return the name without
|
||||
/// the sigil in `result`. Return true if the next token is not a function
|
||||
/// name and keep `result` unchanged.
|
||||
virtual ParseResult parseOptionalFunctionName(StringRef &result,
|
||||
llvm::SMLoc &loc) = 0;
|
||||
|
||||
/// This is the representation of an operand reference.
|
||||
struct OperandType {
|
||||
llvm::SMLoc location; // Location of the token.
|
||||
|
|
|
@ -337,7 +337,6 @@ public:
|
|||
}
|
||||
|
||||
void print(Module *module);
|
||||
void printFunctionReference(Function *func);
|
||||
void printAttributeAndType(Attribute attr) {
|
||||
printAttributeOptionalType(attr, /*includeType=*/true);
|
||||
}
|
||||
|
@ -498,10 +497,6 @@ static void printFloatValue(const APFloat &apValue, raw_ostream &os) {
|
|||
os << str;
|
||||
}
|
||||
|
||||
void ModulePrinter::printFunctionReference(Function *func) {
|
||||
os << '@' << func->getName();
|
||||
}
|
||||
|
||||
void ModulePrinter::printLocation(Location loc) {
|
||||
if (printPrettyDebugInfo) {
|
||||
printLocationInternal(loc, /*pretty=*/true);
|
||||
|
@ -1180,9 +1175,6 @@ public:
|
|||
void printAttributeAndType(Attribute attr) override {
|
||||
ModulePrinter::printAttributeAndType(attr);
|
||||
}
|
||||
void printFunctionReference(Function *func) override {
|
||||
return ModulePrinter::printFunctionReference(func);
|
||||
}
|
||||
void printOperand(Value *value) override { printValueID(value); }
|
||||
|
||||
void printOptionalAttrDict(ArrayRef<NamedAttribute> attrs,
|
||||
|
|
|
@ -336,8 +336,8 @@ static ParseResult parseCallOp(OpAsmParser *parser, OperationState *result) {
|
|||
SmallVector<NamedAttribute, 4> attrs;
|
||||
SmallVector<OpAsmParser::OperandType, 8> operands;
|
||||
Type type;
|
||||
StringRef calleeName;
|
||||
llvm::SMLoc calleeLoc, trailingTypeLoc;
|
||||
FunctionAttr funcAttr;
|
||||
llvm::SMLoc trailingTypeLoc;
|
||||
|
||||
// Parse an operand list that will, in practice, contain 0 or 1 operand. In
|
||||
// case of an indirect call, there will be 1 operand before `(`. In case of a
|
||||
|
@ -349,7 +349,7 @@ static ParseResult parseCallOp(OpAsmParser *parser, OperationState *result) {
|
|||
|
||||
// Optionally parse a function identifier.
|
||||
if (isDirect)
|
||||
if (parser->parseFunctionName(calleeName, calleeLoc))
|
||||
if (parser->parseAttribute(funcAttr, "callee", attrs))
|
||||
return failure();
|
||||
|
||||
if (parser->parseOperandList(operands, /*requiredOperandCount=*/-1,
|
||||
|
@ -362,10 +362,6 @@ static ParseResult parseCallOp(OpAsmParser *parser, OperationState *result) {
|
|||
if (!funcType)
|
||||
return parser->emitError(trailingTypeLoc, "expected function type");
|
||||
if (isDirect) {
|
||||
// Add the direct callee as an Op attribute.
|
||||
auto funcAttr = parser->getBuilder().getFunctionAttr(calleeName);
|
||||
attrs.push_back(parser->getBuilder().getNamedAttr("callee", funcAttr));
|
||||
|
||||
// Make sure types match.
|
||||
if (parser->resolveOperands(operands, funcType.getInputs(),
|
||||
parser->getNameLoc(), result->operands))
|
||||
|
|
|
@ -3148,29 +3148,6 @@ public:
|
|||
return parser.parseAttributeDict(result);
|
||||
}
|
||||
|
||||
/// Parse a function name like '@foo' and return the name in a form that can
|
||||
/// be passed to resolveFunctionName when a function type is available.
|
||||
ParseResult parseFunctionName(StringRef &result, llvm::SMLoc &loc) override {
|
||||
if (parseOptionalFunctionName(result, loc))
|
||||
return emitError(loc, "expected function name");
|
||||
return success();
|
||||
}
|
||||
|
||||
/// Parse a function name like '@foo` if present and return the name without
|
||||
/// the sigil in `result`. Return true if the next token is not a function
|
||||
/// name and keep `result` unchanged.
|
||||
ParseResult parseOptionalFunctionName(StringRef &result,
|
||||
llvm::SMLoc &loc) override {
|
||||
loc = parser.getToken().getLoc();
|
||||
|
||||
if (parser.getToken().isNot(Token::at_identifier))
|
||||
return failure();
|
||||
|
||||
result = parser.getTokenSpelling().drop_front();
|
||||
parser.consumeToken(Token::at_identifier);
|
||||
return success();
|
||||
}
|
||||
|
||||
ParseResult parseOperand(OperandType &result) override {
|
||||
FunctionParser::SSAUseInfo useInfo;
|
||||
if (parser.parseSSAUse(useInfo))
|
||||
|
|
|
@ -409,11 +409,11 @@ void BranchOp::eraseOperand(unsigned index) {
|
|||
//===----------------------------------------------------------------------===//
|
||||
|
||||
static ParseResult parseCallOp(OpAsmParser *parser, OperationState *result) {
|
||||
StringRef calleeName;
|
||||
llvm::SMLoc calleeLoc;
|
||||
FunctionAttr calleeAttr;
|
||||
FunctionType calleeType;
|
||||
SmallVector<OpAsmParser::OperandType, 4> operands;
|
||||
if (parser->parseFunctionName(calleeName, calleeLoc) ||
|
||||
auto calleeLoc = parser->getNameLoc();
|
||||
if (parser->parseAttribute(calleeAttr, "callee", result->attributes) ||
|
||||
parser->parseOperandList(operands, /*requiredOperandCount=*/-1,
|
||||
OpAsmParser::Delimiter::Paren) ||
|
||||
parser->parseOptionalAttributeDict(result->attributes) ||
|
||||
|
@ -423,8 +423,6 @@ static ParseResult parseCallOp(OpAsmParser *parser, OperationState *result) {
|
|||
result->operands))
|
||||
return failure();
|
||||
|
||||
result->addAttribute("callee",
|
||||
parser->getBuilder().getFunctionAttr(calleeName));
|
||||
return success();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue