Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a clang analogue of gcc's `__attribute__((hot))`

I wish to mark a function for more aggressive optimizations. The function is not called often, so PGO won't help, but I still want it as low latency as possible.

gcc has attribute hot for this. Is there some clang equivalent I'm missing?

BTW clang does accept __attribute__((hot)), but AFAICT it has zero impact (and is undocumented). Probably for source compatibility with gcc.

like image 406
Ofek Shilon Avatar asked Oct 26 '25 15:10

Ofek Shilon


1 Answers

(Writing an answer instead of deleting, in case it is of use to others)

So turns out that since December 2020 Clang does support __attribute__((hot)), they just didn't document it. I nudged them. When tested in a newer clang version I see a difference in binaries.

BTW they did support __attribute__((cold)) long before that. And as I suspected, the clang front end did accept hot for sake of gcc compatibility.

like image 185
Ofek Shilon Avatar answered Oct 28 '25 07:10

Ofek Shilon