The compiler option of O0, O1, O2, Os in Debug mode

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

The compiler option of O0, O1, O2, Os in Debug mode

4,108 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by shiggy on Fri Jan 17 00:49:25 MST 2014
Hi All!

I ask you about compiler option of O0, O1, O2, Os in Debug mode.
The usage of bellow is OK?
The bellow sample is one file.

//===============================
#pragma O3
void subroutine1(){

}
#pragma O1
void subroutine2(){

}


//end of file

Shiggy
0 Kudos
6 Replies

2,170 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by lpcxpresso-support on Fri Jan 17 04:21:00 MST 2014
It looks like the #pragma pop is trying to pop an attribute which isn't supported for ARM targets - causing this warning message. We'll follow up on this with the GCC maintainers.

But you can prevent #pragma warnings by adding "-Wno-pragmas" to the options specified in "Other flags" line of the Miscellaneous section of the Compiler Settings.

Alternatively, use the attribute method of changing the optimisation level for a function that we described previously.

Regards,
LPCXpresso Support
0 Kudos

2,170 Views
carlnormansuret
Contributor V

Did something happen with this? In the latest KDS its still not working...

I have some issues with my project using a struct that wont work correctly in release. I have done this, but I am not 100% sure its pushing an popping the optmizations... Anyone confirm if this is right, or, how I should do it knowing #pragma GCC pop_options is broken? I cannot get __attribute__((optimize("O0"))) to work, if someone can tell me how to add this attibute to a struct below that might help. 

<HEADER FILE>

typedef struct
__attribute__((__packed__))
{

   int value1;

   unsigned long value2;

   char string1;

}ramtable_s;

extern volatile ramtable_s RamTable;

<C FILE>

#pragma pack(push)
#pragma GCC optimize("O0")

volatile ramtable_s RamTable =
{

   .value1 = 0;

   .value2 = 10;

   .string1 = "TEST";

};

#pragma pack(pop)

PS the #pragma GCC optimize("O0") is 100% working in this case, but, im worried its staying at level 0 for the rest of the code and I am not sure how to prove / disprove this.

0 Kudos

2,170 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by LabRat on Fri Jan 17 02:05:20 MST 2014

Quote: lpcxpresso-support
...you would need to do this:

#pragma GCC push_options
#pragma GCC optimize("O2")
void myFunc(){
blah
}
#pragma GCC pop_options




...and receive a warning:


Quote:
../src/main.c:87:9: warning: #pragma GCC target is not supported for this machine [-Wpragmas]


0 Kudos

2,170 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by lpcxpresso-support on Fri Jan 17 01:49:01 MST 2014
That has different behaviour, which is not what the OP asked.

Using the #pragma tells the compiler to compile EVERYTHING following with that option, not just a single function. If you want to use the #pragma method, on a single function, you would need to do this:

#pragma GCC push_options
#pragma GCC optimize("O2")
void myFunc(){
blah
}
#pragma GCC pop_options


The other advantage of using the attribute is that you can then define a pre-processor macro:
#define OPTIMIZE(level) __attribute__((optimize(level))

OPTIMIZE("O2") myFunc() ...

OPTIMIZE("O1") yourFunc() ...

It is not possible to put #pragma's into pre-processor macros.

0 Kudos

2,170 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Fri Jan 17 01:36:16 MST 2014
I know there are other opinions, but the simplest way to switch optimization is:

#pragma GCC optimize ("O2")

0 Kudos

2,170 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by lpcxpresso-support on Fri Jan 17 01:23:07 MST 2014
The simplest way to do this is to use the function attributes:

__attribute__((optimize("O3"))) void my_func()
{
blah
}

For more information, search the Help (Help->Help Contents)
0 Kudos