Page MenuHome

Compiler attribute to disable optimizations per-function
Needs ReviewPublic

Authored by Joseph Eagar (joeedh) on May 13 2021, 4:50 AM.

Details

Summary

This patch adds a new macro to BLI_compiler_attrs.h, ATTR_NO_OPT, that disables optimization per-function, which can be very useful for debugging.

There are issues with this. I don't think it makes any sense to commit code with ATTR_NO_OPT in it. Since I keep finding myself forgetting to strip them all out before committing to my temp_multires_bmesh branch I propose that if this patch is accepted, a server-side commit hook be added to reject commits with ATTR_NO_OPT in them.

If this is not acceptable then I can write a client-side pre-commit hook to reject the compiler-specific forms of this attribute. This could then be posted to the wiki or committed to build_files/utils in the repo for other developers to use.

Diff Detail

Event Timeline

Joseph Eagar (joeedh) requested review of this revision.May 13 2021, 4:50 AM
Joseph Eagar (joeedh) created this revision.
Ray Molenkamp (LazyDodo) requested changes to this revision.EditedMay 13 2021, 6:28 AM

Not sure i see the added benefit, the RelWithDebInfo configuration should cover most of the use cases already, having the macro available will just make people think that disabling the optimizer is an OK thing to do, "it works in debug, has issues in release, boom smack an ATTR_NO_OPT on, problem solved" is not behavior i'd like to encourage though any means.

source/blender/blenlib/BLI_compiler_attrs.h
106

This doesn't work the way you think it does, it disabled optimization for all code following the pragma not just the function you put it above.

This revision now requires changes to proceed.May 13 2021, 6:28 AM

Not sure i see the added benefit, the RelWithDebInfo configuration should cover most of the use cases already, having the macro available will just make people think that disabling the optimizer is an OK thing to do, "it works in debug, has issues in release, boom smack an ATTR_NO_OPT on, problem solved" is not behavior i'd like to encourage though any means.

Sometimes you need a debug build with aggressive optimizations on (especially inlining), otherwise a stock RelWithDebInfo would be sufficient.

Fix gcc #if branch and apply clang formatting.