Replace the Function reference methods from the OpAsmParser/OpAsmPrinter with...
authorRiver Riddle <riverriddle@google.com>
Wed, 29 May 2019 20:33:22 +0000 (13:33 -0700)
committerMehdi Amini <joker.eph@gmail.com>
Sun, 2 Jun 2019 03:08:03 +0000 (20:08 -0700)
--

PiperOrigin-RevId: 250555680

mlir/include/mlir/IR/OpImplementation.h
mlir/lib/IR/AsmPrinter.cpp
mlir/lib/LLVMIR/IR/LLVMDialect.cpp
mlir/lib/Parser/Parser.cpp
mlir/lib/StandardOps/Ops.cpp

index 825f362..9168d28 100644 (file)
@@ -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.
index 71744cf..2077025 100644 (file)
@@ -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,
index 8490fda..e281702 100644 (file)
@@ -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))
index cc6a57c..801ec40 100644 (file)
@@ -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))
index d82ccdf..c5dc4a0 100644 (file)
@@ -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();
 }