Function Scanning Mode
You can add the --funcs parameter to the ./tiancheng command to scan and analyze specified functions in a file or file directory.
Prerequisites
Assume that the Tiancheng Code Optimizer is installed in /home/tiancheng-x.x.x-Linux-Kunpeng.
Example
- Select functions from a file or a file directory to scan and analyze.
- Scan a specified function in a file and generate an analysis report. In this example, the BrotliOptimizeHuffmanCountsForRle function 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 --funcs BrotliOptimizeHuffmanCountsForRle -o /home/demo -r /path/to/code_project
Scan the BrotliOptimizeHuffmanCountsForRle function in /home/demo/input.cpp. The vectorization check report and JSON report files are generated in /home/demo. 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 14 15 16 17 18 19 20 21 22 23 24 25 26
Warning: Single file target mode prioritizes '-i'. '-r' will be ignored. Compile database file does not exist or is unreachable. Target functions to analyze: - BrotliOptimizeHuffmanCountsForRle // Indicates that the function to be analyzed is BrotliOptimizeHuffmanCountsForRle. [Locator] Analyzing: BrotliOptimizeHuffmanCountsForRle -> [Match] /home/demo/input.cpp: 248 // Matches the input.cpp source file containing the BrotliOptimizeHuffmanCountsForRle function. 248 indicates the number of the line where the function is located. ================================================================================ Analyzing file: /home/demo/input.cpp // Analyzes the input.cpp source file. -------------------------------------------------------------------------------- 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. [Match Found] Function: BrotliOptimizeHuffmanCountsForRle at /home/demo/input.cpp:248 // Indicates that the BrotliOptimizeHuffmanCountsForRle function is successfully matched. [FilterAnchors] Limiting from 37 to 10 anchors // Indicates that the number of anchors to be filtered is limited to 10 (down from 37). [CallDepth] Function 'BrotliOptimizeHuffmanCountsForRle': original anchors=37, filtered=10 → disabling interprocedural analysis // Indicates that the call depth is restricted and cross-function analysis is disabled. Vectorization check task is being executed. Please wait... Scanning start time: 2026/05/27 16:56:41 Successfully generated vectorization report: /home/demo/Vectorization_Source_20260527_165658_007_9841.html // Indicates the vectorization check report file path. Successfully generated vectorization optimization result: /home/demo/Vectorization_Optimization_Result_20260527_165658_007_9841.json // Indicates the JSON report file path.
- Scan a specified function in a file directory and generate an analysis report. In this example, the BrotliOptimizeHuffmanCountsForRle function contained in /path/to/code_project is scanned and the analysis report is stored in /home/demo/. Replace the example parameter values with actual values.
./tiancheng --funcs BrotliOptimizeHuffmanCountsForRle -o /home/demo -r /path/to/code_project
Scan the BrotliOptimizeHuffmanCountsForRle function of code_project in /path/to. The vectorization check report and JSON report files are generated in /home/demo. 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 14 15 16 17 18 19 20 21 22 23 24 25
Compile database file does not exist or is unreachable. Target functions to analyze: - BrotliOptimizeHuffmanCountsForRle // Indicates that the function to be analyzed is BrotliOptimizeHuffmanCountsForRle. [Locator] Analyzing: BrotliOptimizeHuffmanCountsForRle -> [Match] /path/to/code_project/enc/entropy_encode.c: 248 // Matches the entropy_encode.c source file containing the BrotliOptimizeHuffmanCountsForRle function. 248 indicates the number of the line where the function is located. ================================================================================ Analyzing file: /path/to/code_project/enc/entropy_encode.c // Analyzes the entropy_encode.c source file. -------------------------------------------------------------------------------- Start to recognize file: /path/to/code_project/enc/entropy_encode.c // Starts to identify the entropy_encode.c 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. [Match Found] Function: BrotliOptimizeHuffmanCountsForRle at /path/to/code_project/enc/entropy_encode.c:248 // Indicates that the BrotliOptimizeHuffmanCountsForRle function is successfully matched. [FilterAnchors] Limiting from 37 to 10 anchors // Indicates that the number of anchors to be filtered is limited to 10 (down from 37). [CallDepth] Function 'BrotliOptimizeHuffmanCountsForRle': original anchors=37, filtered=10 → disabling interprocedural analysis // Indicates that the call depth is restricted and cross-function analysis is disabled. Vectorization check task is being executed. Please wait... Scanning start time: 2026/05/27 16:59:52 Successfully generated vectorization report: /home/demo/Vectorization_Source_20260527_165945_490_7232.html // Indicates the vectorization check report file path. Successfully generated vectorization optimization result: /home/demo/Vectorization_Optimization_Result_20260527_165945_490_7232.json // Indicates the JSON report file path.
- Scan a specified function in a file and generate an analysis report. In this example, the BrotliOptimizeHuffmanCountsForRle function 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.
- Open the generated JSON report file and analyze and confirm the modification points.
vim /home/demo/Vectorization_Optimization_Result_20260527_165945_490_7232.json
The JSON file content is as follows:
{ "advisor_items": [ { "opt_file": { "begin_line": 315, "description": "", "end_line": 317, "fileName": "/path/to/code_project/enc/entropy_encode.c", "headerFile": "#include <arm_neon.h>", "headerLocBegin": 11, "headerLocEnd": 11, "sample_code": " k = 0;\n for (; k + 16 < step; k += 16) {\n vst1q_u8(good_for_rle + i - k - 1, vdupq_n_u8(1));\n }\n for (; k < step; ++k) {\n good_for_rle[i - k - 1] = 1;\n }" } }, { "opt_file": { "begin_line": 348, "description": "", "end_line": 352, "fileName": "/path/to/code_project/enc/entropy_encode.c", "headerFile": "#include <arm_neon.h>", "headerLocBegin": 11, "headerLocEnd": 11, "sample_code": " k = 0;\n for (; k + 4 < stride; k += 4) {\n vst1q_u32(counts + i - k - 1, vdupq_n_u32(count));\n }\n for (; k < stride; ++k) {\n /* We don't want to change value at counts[i],\n that is already belonging to the next stride. Thus - 1. */\n counts[i - k - 1] = (uint32_t)count;\n }" } } ], "code": 0, "recognizedPattern": 2 }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 348.
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 352.
fileName
Path to the analyzed source file.
In the example, the path is /path/to/code_project/enc/entropy_encode.c.
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 11.
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 11.
sample_code
Recommended code vectorization sample, which can be directly used to replace the current code.
The following is an example of optimized code:
k = 0;\n for (; k + 4 < stride; k += 4) {\n vst1q_u32(counts + i - k - 1, vdupq_n_u32(count));\n }\n for (; k < stride; ++k) {\n /* We don't want to change value at counts[i],\n that is already belonging to the next stride. Thus - 1. */\n counts[i - k - 1] = (uint32_t)count;\n }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 2.
- 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.