This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

AM2434: tiarmclang Compiler option to get optimized Source Code

Part Number: AM2434

Tool/software:

Hello,
I currently have a problem where in CCS some of my breakpoints say that there is no code associated to them, normal code, no preprocessor defines or anything.
Therefore I assume that the problem lies in the fact that we are using optimization level -Og atm (compare https://software-dl.ti.com/codegen/docs/tiarmclang/compiler_tools_user_guide/compiler_manual/using_compiler/compiler_options/optimization_options.html ).

So I switched to -O0 and tried to run our code again and suddenly I get an abort before reaching main.

As I already got a similar error in different situations where we still cannot explain why, I hope to find a clue by comparing the source code optimized by tiarmclang with -Og to the original one.
I read here: https://stackoverflow.com/questions/8558541/get-optimized-source-code-from-gcc in answer 3, that there is a compiler option for gcc (-fdump-tree-all) that might provide the optimized source code.

Now I am looking for something similar for tiarmclang.

Thank you for your help.


Best regards

Philip.

  • Are those passes also valid for tiarmclang?

    llvm.org/.../Passes.html

    If not, where could I find the ones for tiarmclang.
    I struggle to provide an appropriate regular expression when I do not know what I am looking for.

  • Please consider these alternatives.  I am confident these suggestions will work better than looking at LLVM passes.  

    Add the compiler option -save-temps.  This tells the compiler to save the temporary files it produces when compiling.  You are interested in the assembly file.  It has the same name as the source file, with the file extension changed to .s.

    Use a command similar to ...

    tiarmobjdump --source executable_file.out > interlisted_file.txt

    The command tiarmobjump is located in the same \bin directory as the compiler tiarmclang.  The option --source disassembles the file, and interlists the C/C++ code along the way.  For this to work, the executable must be compiled with debug enabled (-g).  

    To help with understanding the assembly code generated by the compiler, see the GNU-Syntax Arm Assembly Language Reference Guide part of the tiarmclang online manual.

    Thanks and regards,

    -George

  • Thank you for your response, but I am not confident looking at the object files and dissassembly is really that helpful.
    I can look at the dissassembly already in CCS.
    What I wanted is to find out which parts of my code get optimized how.

    What I currently did which seems like the best option for now is to put the following into our CMakeLists.txt:

    set(OPTIMIZE_RECORD "")
    
    # Use for a dump of the executed code optimization actions.
    if(SHOW_CODE_OPTIMIZATION)
        # File where the code optimization action analysis is dumped to.
        set(OPTIMIZE_DUMP_FILE "$ENV{TI_HOME_DIR}/compile_optimize.yml")
        message(STATUS "Dumping code optimization analysis to: ${OPTIMIZE_DUMP_FILE}!")
        if (EXISTS ${OPTIMIZE_DUMP_FILE})
            # Remove to clear content
            file(REMOVE ${OPTIMIZE_DUMP_FILE})
        endif()    
        file(TOUCH ${OPTIMIZE_DUMP_FILE})
        # Compiler options are for tiarmclang. 
        set(OPTIMIZE_RECORD "-fsave-optimization-record;-foptimization-record-file=${OPTIMIZE_DUMP_FILE};-Rpass-analysis=.*;-Rpass=.*")
    endif()
    
    ...
    
    add_compile_options(
        ...
        ${OPTIMIZE_RECORD} 
        ...
    )



    This gives me at least a file which tells me what kind of optimizazions have been executed in which lines of my code base.