Please forgive any mistakes in form, this is my first contribution to LLVM.
Starting with this commit: 61ba2e3996120a08deef823dccd7e8d8cd9c4332
Profiling was implemented with an intrinsic and lowering for it was consolidated in InstrProfiling.cpp
Optional lowering of the counter increment via (faster) atomic operations was also added at this time. Per the notes from the original commit, the primary goal here was consolidating the manual lowering of the profiling code into one place so it could be hand optimized.
As best I can tell, later on, c3ddc13d7d631a29b55f82c7cc7a9008bf89b1f4 then sets DoCounterPromotion = true unless O0.
This breaks compilation with the profiler turned on for platforms that don't support 64 bit atomic operations.
Since the atomic operations are an optimization anyway and are only useful if the hardware has support, my patch checks for that support (in an admittedly naive way, but it should be sufficient) and disables the atomic optimizations if they're not going to work.
The resulting output of the compiler (including the profiling) works correctly on my target mipsel platform. It also produces correct output on x86_64, aarch64 and arm.
The existing tests for the profiler will adequately cover my changes as well. Prior to my change, both the atomic and non atomic variations of the code were used even within the same job at various places.
Alina, you approved several commits for this section of code, so I'm assuming you know it well. I'm open to suggestions if you have a better approach. Thanks.
I think this can be refactored to