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.

Optimization 'changes' via #pragma

I'm using CCS Version: 5.5.0.00077

I can't seem to find pragma that can allow me to temporarily turn off optimization for a section of code.

(for the curious) the code doesn't do anything important it's a BREAK point location however the optimizer doesn't know that and it will poof it away (and thus the break point for the condition). Using a watch is less efficient and less specific (FYI). Anyhow is their such a program to disable optimization or push the optimization state change it then pop the last state? (Sort of like Lint allows you to turn off Linting stuff for a few lines that it gets confused by on a good day and then restore it's state afterward).


There are also times when you don't want code optimized (for debugging code for example the optimizer can drive you nuts at times). Making a general switch or a module specific switch is difficult to notice (IE you can turn off optimization and forget you did it for a module). However in a pragma this generally sticks out like a sore thumb (because you can search for it automatically).


Suggestions and thoughts welcome.

Stephen

  • If you are building C code, then try 

    #pragma FUNCTION_OPTIONS(name_of_function, "--opt_level=off")

    If you are building C++ code, then write this just before the function

    #pragma FUNCTION_OPTIONS("--opt_level=off")

    Thanks and regards,

    -George

  • This implies the optimizer operates at  a minimum of a function level.

    Thanks but the results connote something I'm either missing or ... what I'm not sure.  I've applied the aforementioned pragma on the function but it appears that it is still optimizing out "unused code" in the function.

    What I'm trying to do is set a break point for when an integer iterator is at a certain value for example:

    if(sensor_index == sl_sensor_4)
    {
    	compensation_value = temperature.current.value;
    }
    // compensate the sensor
    // get the temperature first
    compensation_value = temperature.current.value;
    

    The break point is the line inside the conditional so as I can inspect what is going on at that point. However the line inside it is automatically optimized out despite the use of

    #pragma FUNCTION_OPTIONS(temp_compensate, "--opt_level=off")
    void	temp_compensate(void)
    

    Being applied to the function, shouldn't it NOT touch the code and generate EXACTLY what I have (and thus the break point should be able to be set at that point). The list file shows that it completely ignores the lines where the break point needs to occur despite turning off optimization on the function.

    Trying to debug a specific instance of a loop over a set of values is difficult if you have to do it for every value (when I only need to look at one value heh).

    I suspect I may have to unroll the loop to find out what is going on at the specific instance (sigh) a lot of work I guess. :D


    Stephen

  • Hi,

    You can try with a volatile, non static, maybe also extern variable (or call a dummy function defined in another compilation unit). I don't know if it work also when program level optimizaiton are turned on.

    volatile int watchpoint;

    ....

    if (cond) { watchpoint =temperature.current.value; }

     

  • The compiler will still do some fundamental optimizations even when the "optimization" pass is turned off, and this cannot be controlled.  As Alberto Chessa suggests, your best bet is to set a static volatile inside your conditional.

  • Thanks both of you, I hadn't considered using the volatile keyword to 'fix' some of the issue.

    I also hadn't realized that complete control of compiler behavior wasn't available. It would explain a few things anyhow.


    This definitively answered my question.

    Thanks!

    Stephen