This is an archive of the discontinued LLVM Phabricator instance.

CFE Knob for: Add a thread-model knob for lowering atomics on baremetal & single threaded systems
ClosedPublic

Authored by jroelofs on Aug 20 2014, 8:39 AM.

Details

Diff Detail

Event Timeline

jroelofs updated this revision to Diff 12702.Aug 20 2014, 8:39 AM
jroelofs retitled this revision from to CFE Knob for: Add a thread-model knob for lowering atomics on baremetal & single threaded systems.
jroelofs updated this object.
jroelofs edited the test plan for this revision. (Show Details)
jroelofs added a reviewer: rengolin.
jroelofs added a subscriber: Unknown Object (MLST).
hfinkel added inline comments.
lib/Frontend/CompilerInvocation.cpp
440

You need to validate the string here (just asserting later is not acceptable). There are plenty of calls to Diags.Report in this file, you'll need to add another.

Then you'll need a regression test for this.

jroelofs updated this revision to Diff 12712.Aug 20 2014, 2:02 PM

Follow up on hfinkel's comments.

majnemer added inline comments.
lib/CodeGen/BackendUtil.cpp
422–429

You may want to consider using LLVM's StringSwitch here.

427

This assertion doesn't look too useful.

jroelofs added inline comments.Aug 29 2014, 10:26 AM
lib/CodeGen/BackendUtil.cpp
422–429

I considered it, but Stringswitch wouldn't let me assert that every case was handled.

427

That's "fail, but don't let users read undefined values if asserts are turned off".

jroelofs updated this revision to Diff 13209.Sep 3 2014, 7:38 AM

Use StringSwitch

rengolin added inline comments.Sep 3 2014, 8:04 AM
lib/CodeGen/BackendUtil.cpp
431

Shouldn't this have a .Default()? If so, which value?

t.p.northover added inline comments.
lib/CodeGen/BackendUtil.cpp
431

And is "posix" really the best term for the C++11 model? Windows has just as much history of threading, and it was all rather a bodge before the C++11 description came around.

jroelofs added inline comments.Sep 3 2014, 8:48 AM
lib/CodeGen/BackendUtil.cpp
431

I based the name on the thing printed out by clang++ -v - < /dev/null and g++ -v - < /dev/null:

$ clang++ -v - < /dev/null
Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
Target: x86_64-apple-darwin13.3.0
Thread model: posix
clang: error: -E or -x required when input is from standard input

See: https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_concurrency.html

431

From earlier in the thread:

"I considered it, but Stringswitch wouldn't let me assert that every case was handled."

"StringSwitch does that automatically for you when getting the result
if you leave off the .Default call."

ping

@t.p.northover do you have a better suggestion on the thread model's name? We could try to match gcc here, as I've half-heartedly done (I didn't add the bits that make it print out "win32" on windows), or we could do something else.

Hi,

The explanation for using posix sounds reasonable to me. Windows users can add win32 as an option later if they need it.

lib/Driver/Driver.cpp
688–689

Sorry to resurrect a multi-pinged and multi-commented review with another comment, but this would seem to allow "clang -v -mthread-model=silly", wouldn't it? That might be confusing for someone trying to work out what's allowed.

jroelofs updated this revision to Diff 14340.Oct 2 2014, 11:47 AM

@TNorthover, no worries. It's better to get the patch right the first time.

Add an error for when the toolchain doesn't support a thread model. This should make the clang -v -mthread-model silly case a bit nicer:

$ ./clang -v -mthread-model silly
clang: error: invalid thread model 'silly' in '-mthread-model silly' for this target
clang version 3.6.0 (trunk 218876)
Target: x86_64-apple-darwin13.4.0

compnerd added inline comments.
lib/Driver/ToolChain.cpp
218

The else here is superfluous.

t.p.northover accepted this revision.Oct 3 2014, 9:23 AM
t.p.northover added a reviewer: t.p.northover.

This looks fine now, as far as I'm concerned. I'd say you should just commit with Saleem's suggestion.

Cheers.

Tim.

This revision is now accepted and ready to land.Oct 3 2014, 9:23 AM
jroelofs closed this revision.Oct 3 2014, 3:08 PM

Committed as r219027, thanks!

Jon