Commit Graph

52 Commits

Author SHA1 Message Date
River Riddle fff39b62bb [mlir][Attribute] Remove usages of Attribute::getKind
This is in preparation for removing the use of "kinds" within attributes and types in MLIR.

Differential Revision: https://reviews.llvm.org/D85370
2020-08-07 13:43:25 -07:00
Jing Pu eddf4dc869 Fix SourceMgrDiagnosticHandler::convertLocToSMLoc for unknown line/column scenerio.
Summary: FileLineColLoc allows the column and line to be zero to represent unknown column and/or unknown line/column information. However, SourceMgr::FindLocForLineAndColumn treats line 0 and col 0 valid and pointing to the first line and col, respectively. To adapt this mismatch in semantics, we explicitly check line/col being zeros in SourceMgrDiagnosticHandler::convertLocToSMLoc

Differential Revision: https://reviews.llvm.org/D80258
2020-06-15 16:15:12 -07:00
Chris Lattner 969e7edd88 [SourceMgr/MLIR diagnostics] Introduce a new method to speed things up
Summary:
This introduces a new SourceMgr::FindLocForLineAndColumn method that
uses the OffsetCache in SourceMgr::SrcBuffer to do do a constant time
lookup for the line number (once the cache is populated).

Use this method in MLIR's SourceMgrDiagnosticHandler::convertLocToSMLoc,
replacing the O(n) scanning logic.  This resolves a long standing TODO
in MLIR, and makes one of my usecases go dramatically faster (which is
currently producing many diagnostics in a 40MB SourceBuffer).

NFC, this is just a performance speedup and cleanup.

Reviewers: rriddle!, ftynse!

Subscribers: hiraditya, mehdi_amini, rriddle, jpienaar, shauheen, antiagainst, nicolasvasilache, arpith-jacob, mgester, lucyrfox, liufengdb, Joonsoo, grosul1, frgossen, Kayjukh, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D78868
2020-04-25 14:06:44 -07:00
River Riddle c0a33aaa80 [mlir][Diagnostic] Don't store Operation arguments as a DiagnosticArgument
Summary: Diagnostics may be cached in the parallel diagnostic handler to preserve proper ordering. Storing the Operation as a DiagnosticArgument is problematic as the operation may be erased or changed before it finally gets printed.

Differential Revision: https://reviews.llvm.org/D77675
2020-04-07 12:49:06 -07:00
River Riddle 79afdfab9a [mlir] Change the default of `mlir-print-op-on-diagnostic` to true
Summary: It is a very common user trap to think that the location printed along with the diagnostic is the same as the current operation that caused the error. This revision changes the behavior to always print the current operation, except for when diagnostics are being verified. This is achieved by moving the command line flags in IR/ to be options on the MLIRContext.

Differential Revision: https://reviews.llvm.org/D77095
2020-04-03 19:02:51 -07:00
River Riddle 3d44f48edc [mlir][Diagnostics] Don't print note source line if it is the same as the previous diagnostic
Summary: This revision updates the SourceMgrDiagnosticHandler to not print the source location of a note if it is the same location as the previously printed diagnostic. This helps avoid redundancy, and potential confusion, when looking at the diagnostic output.

Differential Revision: https://reviews.llvm.org/D76787
2020-03-29 21:43:44 -07:00
Feng Liu 8d96aed566 [mlir] Use the first location in the fused location for diagnostic handler
Differential Revision: https://reviews.llvm.org/D71851
2020-02-11 07:34:15 -05:00
Benjamin Kramer adcd026838 Make llvm::StringRef to std::string conversions explicit.
This is how it should've been and brings it more in line with
std::string_view. There should be no functional change here.

This is mostly mechanical from a custom clang-tidy check, with a lot of
manual fixups. It uncovers a lot of minor inefficiencies.

This doesn't actually modify StringRef yet, I'll do that in a follow-up.
2020-01-28 23:25:25 +01:00
Mehdi Amini 308571074c Mass update the MLIR license header to mention "Part of the LLVM project"
This is an artifact from merging MLIR into LLVM, the file headers are
now aligned with the rest of the project.
2020-01-26 03:58:30 +00:00
Mehdi Amini 56222a0694 Adjust License.txt file to use the LLVM license
PiperOrigin-RevId: 286906740
2019-12-23 15:33:37 -08:00
River Riddle 4562e389a4 NFC: Remove unnecessary 'llvm::' prefix from uses of llvm symbols declared in `mlir` namespace.
Aside from being cleaner, this also makes the codebase more consistent.

PiperOrigin-RevId: 286206974
2019-12-18 09:29:20 -08:00
Kazuaki Ishizaki 84a6182ddd minor spelling tweaks
Closes tensorflow/mlir#290

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/290 from kiszk:spelling_tweaks_201912 9d9afd16a723dd65754a04698b3976f150a6054a
PiperOrigin-RevId: 284169681
2019-12-06 05:59:30 -08:00
River Riddle 780f0c043a Add a flag to dump the current stack trace when emitting a diagnostic.
It is often desirable to know where within the program that a diagnostic was emitted, without reverting to assert/unreachable which crash the program. This change adds a flag `mlir-print-stacktrace-on-diagnostic` that attaches the current stack trace as a note to every diagnostic that gets emitted.

PiperOrigin-RevId: 283996373
2019-12-05 10:00:25 -08:00
River Riddle c4a0883a92 Add a printer flag to use local scope when printing IR.
This causes the AsmPrinter to use a local value numbering when printing the IR, allowing for the printer to be used safely in a local context, e.g. to ensure thread-safety when printing the IR. This means that the IR printing instrumentation can also be used during multi-threading when module-scope is disabled. Operation::dump and DiagnosticArgument(Operation*) are also updated to always print local scope, as this is the most common use case when debugging.

PiperOrigin-RevId: 279988203
2019-11-12 09:37:11 -08:00
River Riddle 21ee4e987f Add @below and @above directives to verify-diagnostics.
This simplifies defining expected-* directives when there are multiple that apply to the next or previous line. @below applies the directive to the next non-designator line, i.e. the next line that does not contain an expected-* designator. @above applies to the previous non designator line.

Examples:

// Expect an error on the next line that does not contain a designator.
// expected-remark@below {{remark on function below}}
// expected-remark@below {{another remark on function below}}
func @bar(%a : f32)

// Expect an error on the previous line that does not contain a designator.
func @baz(%a : f32)
// expected-remark@above {{remark on function above}}
// expected-remark@above {{another remark on function above}}

PiperOrigin-RevId: 276369085
2019-10-23 15:56:29 -07:00
Kazuaki Ishizaki 8bfedb3ca5 Fix minor spelling tweaks (NFC)
Closes tensorflow/mlir#177

PiperOrigin-RevId: 275692653
2019-10-20 00:11:34 -07:00
MLIR Team 221e661e91 Pre-allocate space for results from a regex match that uses 3 match strings.
That space is 4 StringRefs, not 3, because element 0 of the match always
contains the entire source string.

PiperOrigin-RevId: 273875606
2019-10-09 20:07:46 -07:00
River Riddle c61991ef01 Refactor DiagnosticEngine to support multiple registered diagnostic handlers.
This fixes a problem with current save-restore pattern of diagnostics handlers, as there may be a thread race between when the previous handler is destroyed. For example, this occurs when using multiple ParallelDiagnosticHandlers asynchronously:

Handler A
Handler B | - LifeTime - |    Restore A here.
Handler C | --- LifeTime ---| Restore B after it has been destroyed.

The new design allows for multiple handlers to be registered in a stack like fashion. Handlers can return success() to signal that they have fully processed a diagnostic, or failure to propagate otherwise.

PiperOrigin-RevId: 270720625
2019-09-23 11:25:14 -07:00
Christian Sigg c900d4994e Fix a number of Clang-Tidy warnings.
PiperOrigin-RevId: 270632324
2019-09-23 02:34:27 -07:00
River Riddle 8a1cdeb31b Forward diagnostics from untracked threads in ParallelDiagnosticHandler.
This allows for the use of multiple ParallelDiagnosticHandlers without having them conflict with each other.

PiperOrigin-RevId: 268967407
2019-09-13 13:19:19 -07:00
Jacques Pienaar 79f53b0cf1 Change from llvm::make_unique to std::make_unique
Switch to C++14 standard method as llvm::make_unique has been removed (
https://reviews.llvm.org/D66259). Also mark some targets as c++14 to ease next
integrates.

PiperOrigin-RevId: 263953918
2019-08-17 11:06:03 -07:00
Jacques Pienaar 77ed5247bf Avoid passing in line/col for files not registered with SourceMgr.
This can result in index expression overflow in "Loc.getPointer() - ColumnNo"
in SourgeMgr.

loc could also be prefixed to the message additionally in this case.

PiperOrigin-RevId: 262935408
2019-08-12 09:00:09 -07:00
River Riddle fdc2b3f75f NFC: Don't print the location of a diagnostic if it is unknown.
Printing 'loc(unknown)' just clutters the output with unhelpful information.

PiperOrigin-RevId: 257883717
2019-07-12 17:43:08 -07:00
River Riddle a4c3a6455c Move the emitError/Warning/Remark utility methods out of MLIRContext and into the mlir namespace.
Now that Locations are attributes, they have direct access to the MLIR context. This allows for simplifying error emission by removing unnecessary context lookups.

PiperOrigin-RevId: 255112791
2019-06-25 21:32:23 -07:00
River Riddle 650dc4bb65 Allow converting Diagnostic to LogicalResult::Failure. This matches the behavior of InFlightDiagnostic and enables notes to be converted to failure.
PiperOrigin-RevId: 254579098
2019-06-24 13:44:22 -07:00
River Riddle 36b7c2da1d Refactor the location classes to be attributes instead of separate IR classes.
This will allow for locations to be used in the same contexts as attributes. Given that attributes are nullable types, the 'Location' class now represents a non-nullable wrapper around a 'LocationAttr'. This preserves the desired semantics we have for non-optional locations.

PiperOrigin-RevId: 254505278
2019-06-22 09:17:51 -07:00
River Riddle 34cb51743d NFC: Append 'Location' to the end of each the location kinds. This is in preparation for making the location classes attributes instead of separate IR types.
PiperOrigin-RevId: 253860058
2019-06-19 23:07:15 -07:00
River Riddle e7b337acf8 Add support for providing an output stream to the SourceMgrDiagnosticHandlers.
--

PiperOrigin-RevId: 250974331
2019-06-01 20:13:39 -07:00
River Riddle 9cb3ea8fe4 Update the type printer for Diagnostic to automatically wrap the type with ''.
--

PiperOrigin-RevId: 249935489
2019-06-01 20:02:22 -07:00
River Riddle 5185acca0d Introduce a new common diagnostic handler ScopedDiagnosticHandler to simplify saving and restoring the currently registered handler.
--

PiperOrigin-RevId: 249735912
2019-06-01 19:59:33 -07:00
River Riddle cf8f1ea918 NFC: Fix the name of a comment header block in Diagnostics.cpp.
--

PiperOrigin-RevId: 249466645
2019-06-01 19:56:03 -07:00
River Riddle 3902cef954 Make the ParallelDiagnosticHandler used by the pass manager publicly available in Diagnostics.h. This provides a common utility for deterministically handling diagnostics in a multi-threaded environment.
--

PiperOrigin-RevId: 249325937
2019-06-01 19:55:24 -07:00
River Riddle 039800bfb6 Add support for streaming an OperationName into a Diagnostic.
--

PiperOrigin-RevId: 248987646
2019-05-20 13:48:28 -07:00
River Riddle 7ffdf2cddd Add support for streaming Operations into Diagnostics.
--

PiperOrigin-RevId: 248967563
2019-05-20 13:47:53 -07:00
River Riddle 6264fccd3a When converting a location to an SMLoc, advance to the first non-whitespace if the column is unknown(zero). This also fixes a small bug with call stack printing.
Example:
    /tmp/file_C.py:21:5: error: 'foo.bar' op attribute 'something'
        raise app.UsageError('Too many command-line arguments.')
        ^
    /tmp/file_D.py:20:3: note: called from
      if len(argv) > 1:
      ^
    /tmp/file_E.py:19:1: note: called from
    def main(argv):
    ^
    /tmp/file_F.py:24:3: note: called from
      app.run(main)
      ^

--

PiperOrigin-RevId: 248151212
2019-05-20 13:41:46 -07:00
River Riddle 30356de1db Add initial support to the SourceMgrDiagnosticHandler for printing call stacks.
Example:

    /tmp/file_C.py:17:1: error: 'foo.bar' op attribute 'something' ...
      app.run(main)
    ^
    /tmp/file_D.py:14:1: note: called from
        raise app.UsageError('Too many command-line arguments.')
    ^
    /tmp/file_E.py:12:1: note: called from
    def main(argv):
    ^
    /tmp/file_F.py:13:1: note: called from
      if len(argv) > 1:
    ^

--

PiperOrigin-RevId: 248074804
2019-05-20 13:41:20 -07:00
River Riddle e686a11523 Remove several heavy includes from Diagnostics.h by a moving a couple of fields/methods to the .cpp file.
--

PiperOrigin-RevId: 247768443
2019-05-20 13:36:48 -07:00
River Riddle 85bf79851e Change the diagnostic handler to accept Diagnostic instead of location/message/kind. This opens the door for many more powerful use cases: fixits, colors, etc.
--

PiperOrigin-RevId: 247705673
2019-05-10 19:30:56 -07:00
River Riddle aa99db1809 Add support to the SourceMgrDiagnosticHandlers to auto-load new source files seen in diagnostics.
--

PiperOrigin-RevId: 247681779
2019-05-10 19:30:15 -07:00
Mehdi Amini ff5d021c39 Add llvm_unreachable in unreachable path to silence GCC warning (NFC)
The switch is supposed to be fully covered, but GCC warns that:
     "control reaches end of non-void function"

--

PiperOrigin-RevId: 247672430
2019-05-10 19:30:06 -07:00
River Riddle 9e363a1f3f Refactor the SourceMgrDiagnosticHandlers to support more locations than FileLineColLoc.
--

PiperOrigin-RevId: 247662828
2019-05-10 19:29:10 -07:00
River Riddle 685f948481 Add support to SourceMgrDiagnosticHandler for handling the case where the llvm::SourceMgr has no main file.
--

PiperOrigin-RevId: 247605584
2019-05-10 19:28:13 -07:00
River Riddle 5fd4ec1b78 Move the diagnostic verification functionality out of mlir-opt and into a new llvm::SourceMgr diagnostic handler 'SourceMgrDiagnosticVerifierHandler'. This will allow for other tools to reuse the 'expected-*' functionality.
--

PiperOrigin-RevId: 247514684
2019-05-10 19:26:51 -07:00
River Riddle 0e481bae68 Add support in the SourceMgrDiagnosticHandler for handling source managers with multiple buffers.
--

PiperOrigin-RevId: 247482733
2019-05-10 19:26:35 -07:00
River Riddle e05eda9d22 Simplify the emission of a few op parser diagnostics. This also adds the ability to stream an attribute into a Diagnostic.
--

PiperOrigin-RevId: 247359911
2019-05-10 19:25:12 -07:00
River Riddle 4bc23a40f4 Add a utility diagnostic handler class, SourceMgrDiagnosticHandler, to interface with llvm::SourceMgr. This lowers the barrier of entry for tools to get rich diagnostic handling when using llvm::SourceMgr.
--

PiperOrigin-RevId: 247358610
2019-05-10 19:24:54 -07:00
River Riddle ce4fa9f652 Add support for using the new diagnostics infrastructure in the parser. This also adds support for streaming in ranges(e.g. ArrayRef) into a diagnostic with an optional element delimiter.
--

PiperOrigin-RevId: 247239436
2019-05-10 19:24:05 -07:00
River Riddle 3df7a80265 Simplify the emission of various diagnostics emitted by the different dialects (Affine/Standard/etc.) by using the new stream interface instead of Twine.
--

PiperOrigin-RevId: 246842016
2019-05-10 19:22:24 -07:00
River Riddle 777e7b4f4f Make the Twine parameter of the current diagnostic emit functions optional. This allows for the ability to exclusively use the new diagnostic interface without breaking all of the existing usages. Several diagnostics emitted in lib/IR have been updated to make use of this functionality.
--

PiperOrigin-RevId: 246546044
2019-05-06 08:27:13 -07:00
River Riddle baa656352a Add the ability to attach notes to Diagnostic/InFlightDiagnostic.
Notes are a way to add additional context to a diagnostic, but don't really make sense as standalone diagnostics. Moving forward, notes will no longer be able to be constructed directly and must be attached to a parent Diagnostic.

    Notes can be attached via `attachNote`:

      auto diag = ...;
      diag.attachNote() << "This is a note";

--

PiperOrigin-RevId: 246545971
2019-05-06 08:26:54 -07:00