From 1fd1c7a8bbfe606e1eef9554a0dd172a91716443 Mon Sep 17 00:00:00 2001 From: River Riddle Date: Wed, 29 May 2019 13:33:22 -0700 Subject: [PATCH] Replace the Function reference methods from the OpAsmParser/OpAsmPrinter with usages of FunctionAttr. -- PiperOrigin-RevId: 250555680 --- mlir/include/mlir/IR/OpImplementation.h | 15 +-------------- mlir/lib/IR/AsmPrinter.cpp | 8 -------- mlir/lib/LLVMIR/IR/LLVMDialect.cpp | 10 +++------- mlir/lib/Parser/Parser.cpp | 23 ----------------------- mlir/lib/StandardOps/Ops.cpp | 8 +++----- 5 files changed, 7 insertions(+), 57 deletions(-) diff --git a/mlir/include/mlir/IR/OpImplementation.h b/mlir/include/mlir/IR/OpImplementation.h index 825f362..9168d28 100644 --- a/mlir/include/mlir/IR/OpImplementation.h +++ b/mlir/include/mlir/IR/OpImplementation.h @@ -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 ::value && !std::is_convertible::value && @@ -270,17 +268,6 @@ public: virtual ParseResult parseOptionalAttributeDict(SmallVectorImpl &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. diff --git a/mlir/lib/IR/AsmPrinter.cpp b/mlir/lib/IR/AsmPrinter.cpp index 71744cf..2077025 100644 --- a/mlir/lib/IR/AsmPrinter.cpp +++ b/mlir/lib/IR/AsmPrinter.cpp @@ -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 attrs, diff --git a/mlir/lib/LLVMIR/IR/LLVMDialect.cpp b/mlir/lib/LLVMIR/IR/LLVMDialect.cpp index 8490fda..e281702 100644 --- a/mlir/lib/LLVMIR/IR/LLVMDialect.cpp +++ b/mlir/lib/LLVMIR/IR/LLVMDialect.cpp @@ -336,8 +336,8 @@ static ParseResult parseCallOp(OpAsmParser *parser, OperationState *result) { SmallVector attrs; SmallVector 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)) diff --git a/mlir/lib/Parser/Parser.cpp b/mlir/lib/Parser/Parser.cpp index cc6a57c..801ec40 100644 --- a/mlir/lib/Parser/Parser.cpp +++ b/mlir/lib/Parser/Parser.cpp @@ -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)) diff --git a/mlir/lib/StandardOps/Ops.cpp b/mlir/lib/StandardOps/Ops.cpp index d82ccdf..c5dc4a0 100644 --- a/mlir/lib/StandardOps/Ops.cpp +++ b/mlir/lib/StandardOps/Ops.cpp @@ -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 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(); } -- 2.7.4