-
Notifications
You must be signed in to change notification settings - Fork 111
Conversation
@@ -855,15 +927,36 @@ std::string JSWriter::getLoad(const Instruction *I, const Value *P, Type *T, uns | |||
return text; | |||
} | |||
|
|||
static const std::string AtomicsStore = "Atomics_store("; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a useful optimization here? Is there a specific reason why it is done on this string and not others?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, let me just remove this, it is a leftover from previous form of code. I hope compilers are smart to optimize this on their own anyways.
Addressed the review comments at juj/emscripten-fastcomp@a5b54c1...0bc3f1a . |
ba7d9a4
to
a2bf439
Compare
std::string getAddressAsString(const Value *Ptr, int shift) { | ||
Type *t = cast<PointerType>(Ptr->getType())->getElementType(); | ||
if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(Ptr)) { | ||
return utostr(getGlobalAddress(GV->getName().str()) >> shift); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getGlobalAddress
returns a number. that number does not include a relocation offset, which we need in shared modules. relocateGlobal
will do a relocation for you (it operates on a string, so need to take into account the shift on the extra part here).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, fixed. Although note that threads and shared libraries is not supported at present, that is left for later.
…guarantee that SpiderMonkey will not optimize those instructions out when executing, and to offer x86-like strong memory consistency across code that uses such constructs.
…ontrol whether targeting multithreading with Atomics and SAB or not.
…h pthreads enabled.
…hg support to UsedVars in JSBackend.cpp.
…ith pthreads enabled in JSBackend.cpp.
… GCC intrinsics to Emscripten library function calls. Mark 64-bit AtomicCmpXchg instructions unsupported at the moment.
…und, do it as u32 version with a CAS loop. TODO: revert this commit once https://bugzilla.mozilla.org/show_bug.cgi?id=1141986 lands.
…nd unsupported f32 and f64 atomic cas ops.
Addressed the review comments and rebased on top of the latest. This should hopefully look simpler now? |
@@ -549,6 +554,154 @@ DEF_CALL_HANDLER(emscripten_asm_const_double, { | |||
return getAssign(CI) + getCast(handleAsmConst(CI), Type::getDoubleTy(CI->getContext())); | |||
}) | |||
|
|||
std::string getAddressAsString(const Value *Ptr, int shift) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's call this getShiftedPtr
, as it works on pointers, and it doesn't return just a string, but specifically it returns a shifted result (so it isn't the real pointer/address anymore).
Also, please move this to right before getPtrUse
in the main JSBackend.cpp
file. Then the distinction between the two methods is clear.
And once at that location, it looks like we can remove getHeapAccess
, and instead implement getPtrUse
using the new getShiftedPtr
(the only extra thing needed is HEAP?[
on the left and ]
on the right, can do that in getPtrUse
, or alternatively leave getHeapAccess
but without the shifting inside it, so all it does is add the HEAP?[
and ]
; I am ok with either).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I see there is getHeapName
, so can use that for the HEAP?
part, leaving just [
and ]
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or actually instead of everything I said, this method could be implemented using the getHeapNameAndIndex
family of methods.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Anyhow, sorry to ramble here, but in summary
- I think
getShiftedPtr
is a better name - I'd prefer this to be implemented using other methods, without a special check on
GlobalVariable
, and without the need torelocateGlobal
, as the other methods already do both.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, updated the pull request to rename this to getShiftedPtr
and to reuse the existing code as much as possible.
…tation from the existing functions.
Looks nice, thanks. One last thing, just to be sure, please test compilation time before and after this pull. I'm not too worried, but still this changes a lot of the string handling code in emitting pointer uses in the backend. A quick test on a large codebase of js backend time, with and without this pull, should be enough to check. If that is ok, then lgtm. |
I rebuilt Unity3D three times with trunk and both pthreads PRs applied, with the following results:
so the differences do look quite negligible. I'll go ahead and merge these in, if everything is set? |
Sure! |
Adds LLVM side support for compiling for the pthreads/atomics support.
This set of commits implements initial pthreads library support for Emscripten code, and allows native code to utilize multithreading with the pthreads API. This backs on experimental research on the JavaScript SharedArrayBuffer and Atomics APIs from https://docs.google.com/document/d/1NDGA_gZJ7M7w1Bh8S0AoDyEqwDdRh4uSoTPSNn77PFk/edit?usp=sharing , and as such is preliminary and unsupported in other browsers except current Firefox Nightly builds. By default pthreads support is disabled, and the feature must be explicitly enabled by specifying the compiler flag -s USE_PTHREADS=1 and the linker flag -lpthread.