Skip to content
This repository has been archived by the owner on Mar 15, 2022. It is now read-only.

Implement support for localloc. #417

Merged
merged 1 commit into from
Apr 18, 2015
Merged

Conversation

AndyAyersMS
Copy link
Member

Getting the LLVM IR right here is not too hard. Note we're zeroing things via the helper since
using LLVM's memset might lead to calls into the CRT.

Most of the challenge here is in getting this IR properly lowered to machine code. I have some
corequisite changes to LLVM for this.

@AndyAyersMS
Copy link
Member Author

Note this requires these LLVM changes. So this won't go in until we've closed on those and have them available.

@@ -277,6 +277,10 @@ void GenIR::readerPrePass(uint8_t *Buffer, uint32_t NumBytes) {
ASSERTNR(UNREACHED);
}

// We now require the LLVM default triple to end with
// -coreclr, eg x86_64-pc-win32-coreclr
ASSERT(PT.getEnvironment() == Triple::CoreCLR);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is the corresponding change that sets the target environment to coreclr?

@dnfclas
Copy link

dnfclas commented Apr 16, 2015

@AndyAyersMS, Thanks for signing the contribution license agreement so quickly! Actual humans will now validate the agreement and then evaluate the PR.

Thanks, DNFBOT;

@AndyAyersMS
Copy link
Member Author

@pgavlin Unless I'm confused there's no place in source control where we specify the target triple, other than docs.

@pgavlin
Copy link
Contributor

pgavlin commented Apr 17, 2015

The corresponding change may be in LLVM, but surely the CoreCLR environment isn't the default when building LLVM?

@AndyAyersMS
Copy link
Member Author

I don't think the LLVM build is particularly sensitive to the value of the default triple when it's built. So modifying LLVM's build seems like the wrong way to go about this.

LLILC refers to LLVM_DEFAULT_TARGET_TRIPLE when setting up the module, this seems like the thing we should change. Instead of using the default we should have some other value we use here that is set up by LLILC's build scripts.

@pgavlin
Copy link
Contributor

pgavlin commented Apr 17, 2015

Hence my question--I thought that you had made (or intended to make) such a change, and was confused by its absence :)

@AndyAyersMS
Copy link
Member Author

Ok, good.

@AndyAyersMS
Copy link
Member Author

Seems to work but could not figure out how to pass a string as a define value through CMake. So I'm currently stringizing via preprocessor magic.... Seem ok to you? I suspect there are macros like these in headers we include too so perhaps I can use something that is already there.

#define STRINGIZE(X) #X
#define ID(X) STRINGIZE(X)
  const char * TargetTriple = ID(LLILC_TARGET_TRIPLE);
  Context.CurrentModule->setTargetTriple(TargetTriple);

@AndyAyersMS
Copy link
Member Author

@pgavlin PTAL at the updated changes. LLVM part is in already.

endif()

message(STATUS "LLILC_TARGET_TRIPLE is ${LLILC_TARGET_TRIPLE}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DLLILC_TARGET_TRIPLE=${LLILC_TARGET_TRIPLE}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can escape the quotes in order to get the value passed as a string: "-DLLILC_TARGET_TRIPLE=\"${LLILC_TARGET_TRIPLE}\""

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried that already and the quotes didn't make it through. I can experiment some more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like you might need to escape the escapes. Not sure if there is a good cross-platform way to do that. For the Linux build, I expect that "-DFOO=\\\"${FOO}\\\"" would work, but CMD might need "-DFOO=^\"${FOO}^\"" or similar.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If worst comes to worst and there's no good way to do this, your current workaround is fine.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CMake's add_definitions seems a bit better about preserving quotes. So will go with that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent, thanks.

@pgavlin
Copy link
Contributor

pgavlin commented Apr 17, 2015

IR looks good, but I'd definitely like to avoid the extra macros if possible.

Getting the LLVM IR right here is not too hard. We're zeroing via the JIT helper since using LLVM's memset might lead to calls into the CRT.

Most of the challenge here is getting this IR properly lowered to machine code. I have some preliminary changes checked into LLVM for this already, and this change depends upon them.

To enable those changes we now use the CoreCLR environment when targeting windows. Thus the LLVM triple we use on windows is now actually a quad.

The LLVM work is incomplete so this only works at runtime if the localloc is small enough to stay within the guard page, but it handles all our simple test cases.
@AndyAyersMS
Copy link
Member Author

retest this please

1 similar comment
@AndyAyersMS
Copy link
Member Author

retest this please

AndyAyersMS added a commit that referenced this pull request Apr 18, 2015
Implement support for localloc.
@AndyAyersMS AndyAyersMS merged commit b60b5bf into dotnet:master Apr 18, 2015
@AndyAyersMS AndyAyersMS deleted the Localloc branch April 18, 2015 01:34
@AndyAyersMS
Copy link
Member Author

CI failures look spurious, so am going to merge this.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants