Single-File Scanning Mode
You can add the -i parameter to the ./tiancheng command to scan and analyze all the source code in a single source file.
Prerequisites
Assume that the Tiancheng Code Optimizer is installed in /home/tiancheng-x.x.x-Linux-Kunpeng.
Example
- Scan a single source file to generate an analysis report. In this example, the source code contained in /home/demo/input.cpp is scanned and the analysis report is stored in /home/demo. Replace the example parameter values with actual values.
./tiancheng -i /home/demo/input.cpp -o /home/demo -r /path/to/code_project
Scan the input.cpp file in the /home/demo directory. The vectorization check report and JSON report files are generated in the /home/demo directory. In addition, specify the project root directory /path/to/code_project to avoid missing header files.
Command output:
1 2 3 4 5 6 7 8 9 10 11 12 13
Warning: Single file mode uses '-i'. '-r' will be ignored. Compile database file does not exist or is unreachable. Analyzing file: /home/demo/input.cpp Start to recognize file: /home/demo/input.cpp // Starts to identify the input.cpp source file. compile_commands.json not found under: /path/to/code_project Recursively collecting include paths as fallback. Start to scan code. // Starts to scan the code. Vectorization check task is being executed. Please wait... Scanning start time: 2026/05/27 17:02:05 Successfully generated vectorization report: /home/demo/Vectorization_Source_20260527_170218_072_3691.html // Indicates the vectorization check report file path. Successfully generated vectorization optimization result: /home/demo/Vectorization_Optimization_Result_20260527_170218_072_3691.json // Indicates the JSON report file path.
You can open the JSON report file to view the analysis result. If the system displays a message indicating that the header file is not found, rectify the fault following instructions in Header File Not Found During Source File Scan with the Tiancheng Code Optimizer.
- Open the generated JSON report file and analyze and confirm the modification points.
vim /home/demo/Vectorization_Optimization_Result_20260527_170218_072_3691.json
The JSON file content is as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
{ "advisor_items": [ { "opt_file": { "begin_line": 18, "description": "", "end_line": 19, "fileName": "/home/demo/input.cpp", "headerFile": "#include <arm_neon.h>", "headerLocBegin": 9, "headerLocEnd": 9, "sample_code": " int64_t j = 0;\n for (; j + 4 < nb; j += 4) {\n vst1q_f32(dis + j, vaddq_f32(vdupq_n_f32(qNorm), vld1q_f32(bNorms + j)));\n }\n for (; j < nb; j++) dis[j] = qNorm + bNorms[j];" } }, { "opt_file": { "begin_line": 25, "description": "", "end_line": 27, "fileName": "/home/demo/input.cpp", "headerFile": "#include <arm_neon.h>", "headerLocBegin": 9, "headerLocEnd": 9, "sample_code": " int64_t j = 0;\n for (; j + 4 < nb; j += 4) {\n vst1q_f32(dis + j, vaddq_f32(vdupq_n_f32(qNorm), vld1q_f32(bNorms + j)));\n }\n for (; j < nb; j++) {\n dis[j] = qNorm + bNorms[j];\n }" } }, { "opt_file": { "begin_line": 48, "description": "", "end_line": 50, "fileName": "/home/demo/input.cpp", "headerFile": "#include <arm_neon.h>", "headerLocBegin": 9, "headerLocEnd": 9, "sample_code": " int64_t j = 0;\n for (; j + 4 < nb; j += 4) {\n vst1q_f32(dis + j, vaddq_f32(vld1q_f32(dis + j), vdupq_n_f32(qNorm)));\n }\n for (; j < nb; j++) {\n dis[j] += qNorm;\n }" } } ], "code": 0, "recognizedPattern": 3 }
Table 1 Field description Field
Description
advisor_items
Array of code optimization suggestions. Each item in the array is a code tuning optimization.
opt_file
Detailed information about a single optimization suggestion.
begin_line
Start line number of the code to be tuned.
In the example, the start line number is 18.
description
Detailed description of the tuning suggestion.
end_line
End line number of the code to be tuned.
In the example, the end line number is 19.
fileName
Path to the analyzed source file.
In the example, the path is /home/demo/input.cpp.
headerFile
Header file to be added.
In the example, #include <arm_neon.h> indicates that the Arm NEON header file must be included in this code snippet to use the NEON instruction set.
headerLocBegin
Start line number where the header file will be inserted.
- If the value is -1, the header file is already included in the code and does not need to be manually added.
- If the value is a positive integer, it indicates the start line number where the header file will be inserted.
In the example, the start line number is 9.
headerLocEnd
End line number where the header file will be inserted.
- If the value is -1, the header file is already included in the code and does not need to be manually added.
- If the value is a positive integer, it indicates the end line number where the header file will be inserted.
In the example, the end line number is 9.
sample_code
Recommended code vectorization sample, which can be directly used to replace the current code.
The following is an example of optimized code:
int64_t j = 0;\n for (; j + 4 < nb; j += 4) {\n vst1q_f32(dis + j, vaddq_f32(vdupq_n_f32(qNorm), vld1q_f32(bNorms + j)));\n }\n for (; j < nb; j++) dis[j] = qNorm + bNorms[j];code
Tool execution status code.
- The value 0 indicates execution success.
- A non-zero value indicates an interruption.
In the example, 0 indicates that the tool is executed successfully.
recognizedPattern
Number of code snippets to be optimized.
In the example, the number is 3.
- Rewrite the code based on the JSON report.
- View advisor_items, which contains all identified optimization suggestions.
- For each optimization suggestion, check the begin_line and end_line fields to determine the code range to be replaced.
- Copy the vectorized code from sample_code and replace the code in the source file between begin_line and end_line.
- Check the headerLocBegin and headerLocEnd fields.
- If the value is -1, the header file already exists and does not need to be added.
- If the value is a positive integer, add the header file declaration in headerFile to the specified location.
- Save the modified file to complete the automatic rewrite.