1 | /* Copyright 2022 The TensorFlow Authors. All Rights Reserved. |
2 | |
3 | Licensed under the Apache License, Version 2.0 (the "License"); |
4 | you may not use this file except in compliance with the License. |
5 | You may obtain a copy of the License at |
6 | |
7 | http://www.apache.org/licenses/LICENSE-2.0 |
8 | |
9 | Unless required by applicable law or agreed to in writing, software |
10 | distributed under the License is distributed on an "AS IS" BASIS, |
11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | See the License for the specific language governing permissions and |
13 | limitations under the License. |
14 | ==============================================================================*/ |
15 | |
16 | #ifndef TENSORFLOW_DTENSOR_MLIR_DTENSOR_LOCATION_H_ |
17 | #define TENSORFLOW_DTENSOR_MLIR_DTENSOR_LOCATION_H_ |
18 | |
19 | #include <string> |
20 | |
21 | #include "mlir/IR/Location.h" // from @llvm-project |
22 | #include "mlir/IR/Operation.h" // from @llvm-project |
23 | #include "mlir/Support/LLVM.h" // from @llvm-project |
24 | |
25 | // mlir::Location utilities for DTensor. `DTensorLocation` augments a location |
26 | // object with the current file and line _of the C++ code creating an |
27 | // operation_. This simplifies tracking down the creator of an invalid operation |
28 | // while debugging. |
29 | namespace tensorflow { |
30 | namespace dtensor { |
31 | |
32 | mlir::Location DTensorLocation(mlir::Location loc, llvm::StringRef file, |
33 | unsigned int line, llvm::StringRef name = "" ); |
34 | |
35 | mlir::Location DTensorLocation(mlir::Operation* op, llvm::StringRef file, |
36 | unsigned int line, llvm::StringRef name = "" ); |
37 | |
38 | // Creates a string from a location of the following format: |
39 | // >> pass_file_1:line1:col1 |
40 | // >> pass_file_2:line2:col2 |
41 | // |
42 | // DTensor location format overloads the filename value to encode pass |
43 | // information. |
44 | // original_file |
45 | // >> pass_file_1:line1:col1 |
46 | // >> pass_file_2:line2:col2 |
47 | // original_line:original_col |
48 | std::string DTensorLocationToString(mlir::Location loc); |
49 | |
50 | } // namespace dtensor |
51 | } // namespace tensorflow |
52 | |
53 | // Creates a location, reusing the current name scope. |
54 | #define DT_LOC(loc) \ |
55 | ::tensorflow::dtensor::DTensorLocation(loc, __FILE__, __LINE__) |
56 | |
57 | // Creates a location, recording a new nested name scope. |
58 | #define DT_LOC2(loc, name) \ |
59 | ::tensorflow::dtensor::DTensorLocation(loc, __FILE__, __LINE__, name) |
60 | |
61 | #endif // TENSORFLOW_DTENSOR_MLIR_DTENSOR_LOCATION_H_ |
62 | |