Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add project for LLVM backend (supports Wasm) #247

Merged
merged 7 commits into from
Nov 29, 2020

Conversation

yowl
Copy link
Contributor

@yowl yowl commented Oct 19, 2020

No description provided.

@jkotas jkotas added the area-NativeAOT-LLVM LLVM generation for Native AOT compilation (including Web Assembly) label Oct 26, 2020
@yowl yowl marked this pull request as ready for review November 25, 2020 19:43
<ToolRuntimeRID Condition="'$(RuntimeOS)' == 'browser' and '$(TargetOS)' != 'windows' and !$(_buildingInOSX)">linux-x64</ToolRuntimeRID>

<!-- this line seems to cause a failure with _SuppressSdkImports . Doesn't make sense to me -->
<!-- <ToolRuntimeRID Condition="'$(RuntimeOS)' == 'browser' and '$(TargetOS)' != 'windows' and !$(_buildingInOSX)" and !$(_buildingInWindows)">linux-x64</ToolRuntimeRID> -->
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't understand this. The condition shouldn't even be met as buildingInWindows is true so why it causes an error I don't know.

Copy link
Member

Choose a reason for hiding this comment

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

I guess it may a problem with evaluation order.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Merging the latest got rid of this

@yowl
Copy link
Contributor Author

yowl commented Nov 25, 2020

I'm going to release this now for review. Sorry it's rather long. If you want to know what each change fixes I can revert it and show the error. It will publish and run the Samples\HelloWorld (with https://github.com/dotnet/runtimelab/pull/247/files#diff-95c7fc3099f2a4f95cd78e2aae618395f1a7aef4e88e34d30d957f4814bf688e) and that's as far as I've taken it. Once it goes in I could either:

  • Add yml for CI
  • Get the old tests passing - HelloWasm/Exceptions/SimpleGenerics

@yowl yowl changed the title WIP: add project for LLVM backend (supports Wasm) Add project for LLVM backend (supports Wasm) Nov 25, 2020
@@ -0,0 +1,21 @@
if ( -not (Test-Path -LiteralPath $Env:__versionSourceFile))
Copy link
Member

Choose a reason for hiding this comment

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

What's wrong with the default version.c/.h generation that you had to duplicate it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Deleted. Whatever reason I had has gone.

# The -fms-extensions enable the stuff like __if_exists, __declspec(uuid()), etc.
add_compile_options(-fms-extensions)
add_compile_options(-Wno-invalid-offsetof)
add_compile_options(-Wno-tautological-undefined-compare) # this == NULL warning suppression
Copy link
Member

Choose a reason for hiding this comment

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

I believe that we have cleaned up all these in dotnet/runtime. Are these warning suppressions and -fms-extension really required?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ms-extensions I believe is preventing

In file included from E:\GitHub\runtimelab\src\coreclr\src\nativeaot\Runtime\allocheap.cpp:9:
         E:/GitHub/runtimelab/src/coreclr/src/nativeaot/Runtime/./PalRedhawk.h:658:1: error: unknown type name '__forceinline'
         __forceinline
         ^
         In file included from E:\GitHub\runtimelab\src\coreclr\src\nativeaot\Runtime\allocheap.cpp:9:
         In file included from E:/GitHub/runtimelab/src/coreclr/src/nativeaot/Runtime/./PalRedhawk.h:873:

-Wno-invalid-offsetof is stopping:

        In file included from E:\GitHub\runtimelab\src\coreclr\src\nativeaot\Runtime\allocheap.cpp:21:
         E:/GitHub/runtimelab/src/coreclr/src/nativeaot/Runtime/./slist.inl:41:54: warning: offset of on non-standard-layout type 'AllocHeap::BlockListElem' [-Winvalid-offsetof]
             return dac_cast<PTR_PTR_T>(dac_cast<TADDR>(pT) + offsetof(T, m_pNext));
                                                              ^           ~~~~~~~
         E:\GitHub\emsdk\upstream\emscripten\system\include\libc\stddef.h:20:32: note: expanded from macro 'offsetof'
         #define offsetof(type, member) __builtin_offsetof(type, member)
                                        ^                        ~~~~~~
         E:/GitHub/runtimelab/src/coreclr/src/nativeaot/Runtime/./slist.inl:245:14: note: in instantiation of member function 'DefaultSListTraits<AllocHeap::BlockListElem, DoNothingFailFastPolicy>::GetNextPtr' requested here
             *Traits::GetNextPtr(pItem) = *m_ppCur;
                      ^
         E:/GitHub/runtimelab/src/coreclr/src/nativeaot/Runtime/./slist.inl:85:13: note: in instantiation of member function 'SList<AllocHeap::BlockListElem, DefaultSListTraits<AllocHeap::BlockListElem, DoNothingFailFastPolicy>>::Iterator::Insert' requested here
             Begin().Insert(pItem);
                     ^
         E:\GitHub\runtimelab\src\coreclr\src\nativeaot\Runtime\allocheap.cpp:100:17: note: in instantiation of member function 'SList<AllocHeap::BlockListElem, DefaultSListTraits<AllocHeap::BlockListElem, DoNothingFailFastPolicy>>::PushHead' requested here
             m_blockList.PushHead(pBlock);
                         ^
         1 warning generated.

-Wno-tautological-undefined-compare is for:

         E:\GitHub\runtimelab\src\coreclr\src\nativeaot\Runtime\eetype.cpp:24:9: warning: 'this' pointer cannot be null in well-defined C++ code; comparison may be assumed to always evaluate to false [-Wtautological-undefined-compare]
             if (this == NULL)
                 ^~~~    ~~~~
         1 warning generated.

Copy link
Member

Choose a reason for hiding this comment

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

I see. These and warning options are in this file under CLR_CMAKE_HOST_UNIX. Would it make sense to change the condition on that block to !MSVC or something similar instead of duplicating them here?

Copy link
Contributor Author

@yowl yowl Nov 28, 2020

Choose a reason for hiding this comment

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

Thanks, moved as suggested to not duplicate.

@@ -24,12 +24,13 @@ set __Arch=%4
set __CmakeGenerator=Visual Studio
set __UseEmcmake=0
if /i "%__Ninja%" == "1" (
echo using Ninja
Copy link
Member

Choose a reason for hiding this comment

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

Are these echo statements needed? If yes, the alignment is off for this one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, missed this one, deleted.

src/libraries/Native/build-native.cmd Show resolved Hide resolved
<ToolRuntimeRID Condition="'$(RuntimeOS)' == 'browser' and '$(TargetOS)' != 'windows' and !$(_buildingInOSX)">linux-x64</ToolRuntimeRID>

<!-- this line seems to cause a failure with _SuppressSdkImports . Doesn't make sense to me -->
<!-- <ToolRuntimeRID Condition="'$(RuntimeOS)' == 'browser' and '$(TargetOS)' != 'windows' and !$(_buildingInOSX)" and !$(_buildingInWindows)">linux-x64</ToolRuntimeRID> -->
Copy link
Member

Choose a reason for hiding this comment

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

I guess it may a problem with evaluation order.

@jkotas
Copy link
Member

jkotas commented Nov 25, 2020

Could you please also update pre-release label as described in https://github.com/dotnet/runtimelab/blob/master/CreateAnExperiment.md so that the packages do not clash?

Merge remote-tracking branch 'origin/feature/NativeAOT-LLVM' into llvm-rename

# Conflicts:
#	src/coreclr/dir.common.props
#	src/libraries/Directory.Build.props
@@ -256,4 +256,7 @@
<CLSCompliant Condition="'$(CLSCompliant)' == ''">true</CLSCompliant>
</PropertyGroup>

<PropertyGroup Condition="$([MSBuild]::IsOSPlatform('windows')) and '$(TargetOS)' == 'Browser'"> <!-- the Unix versions are used without this override -->
Copy link
Member

Choose a reason for hiding this comment

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

Is the actual problem a bug in eng\Configurations.props?

I think the block in Configurations.props should be something like:

    <!-- There are no WebAssembly tools, so use the default ones -->
    <_toolRuntimeRID Condition="'$(_runtimeOS)' == 'browser'">linux-x64</_toolRuntimeRID>
    <_toolRuntimeRID Condition="'$(_runtimeOS)' == 'browser' and $([MSBuild]::IsOSPlatform('WINDOWS'))">win-x64</_toolRuntimeRID>
    <_toolRuntimeRID Condition="'$(_runtimeOS)' == 'browser' and $([MSBuild]::IsOSPlatform('OSX'))">osx-x64</_toolRuntimeRID>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, that looks better. Admittedly I don't know my way around the build files.

Copy link
Member

Choose a reason for hiding this comment

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

This condition should be using the OS that the build is running on.

TargetOS should mean the OS we are compiling for, everywhere in the build system. If TargetOS means the OS that the build is running in some places, I think we should fix those place.

mono's lead on making 'is browser' decision

I am not sure what this means.

Copy link
Member

Choose a reason for hiding this comment

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

TargetOS is not browser on mono when we are building for wasm today

Is it really the case? There are number of places under libraries that compare TargetOS with Browser, one example from many: https://github.com/dotnet/runtime/blob/master/src/libraries/System.Diagnostics.StackTrace/tests/System.Diagnostics.StackTrace.Tests.csproj#L16

If the TargetOS was not set correct for Browser, all these places would be broken.

In any case, I think it is a good idea to keep fixing places that use wrong meaning of TargetOS.

@@ -6,7 +6,7 @@
<MajorVersion>6</MajorVersion>
<MinorVersion>0</MinorVersion>
<PatchVersion>0</PatchVersion>
<PreReleaseVersionLabel>alpha</PreReleaseVersionLabel>
<PreReleaseVersionLabel>llvm</PreReleaseVersionLabel>
Copy link
Member

Choose a reason for hiding this comment

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

I have realized that this won't be sufficient to avoid collisions given how nuget works and how things are setup currently.

The problem is what PackageReference Include="Microsoft.DotNet.ILCompiler" Version="6.0.0-*" package reference is going to pick up the latest * that will be llvm once this starts publishing.

I think it will be best to use different package name for this branch, like Microsoft.DotNet.ILCompiler.LLVM.

Could you please rename Microsoft.DotNet.ILCompiler to Microsoft.DotNet.ILCompiler.LLVM under src\installer\pkg\projects ? (Both directory names and references in sources.)

There may be a few other places througout the tree that may need similar rename.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, is the label change now superfluous ?

Copy link
Member

Choose a reason for hiding this comment

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

Yes - if you change the package name, it is not necessary to change the label.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe I've gone overboard on this, I renamed the targets file and the pkgproj.

<_toolRuntimeRID Condition="'$(_runtimeOS)' == 'browser' and '$(TargetOS)' == 'windows'">win-x64</_toolRuntimeRID>
<_toolRuntimeRID Condition="'$(_runtimeOS)' == 'browser' and '$(TargetOS)' != 'windows' and $(_buildingInOSX)">osx-x64</_toolRuntimeRID>
<_toolRuntimeRID Condition="'$(_runtimeOS)' == 'browser' and '$(TargetOS)' != 'windows' and !$(_buildingInOSX)">linux-x64</_toolRuntimeRID>
<_toolRuntimeRID Condition="'$(_runtimeOS)' == 'browser'">linux-x64</_toolRuntimeRID>
Copy link
Member

Choose a reason for hiding this comment

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

If it works, it would be nice to submit this to dotnet/runtime. Also, the Android block below should get the same fix.

@@ -158,7 +158,8 @@ set __generatorArgs=
if [%__Ninja%] == [1] (
set __generatorArgs=
) else if [%__BuildArch%] == [wasm] (
set __generatorArgs=-j
rem nmake does support -j
Copy link
Member

Choose a reason for hiding this comment

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

I think this can also be done in dotnet/runtime

Copy link
Member

@jkotas jkotas left a comment

Choose a reason for hiding this comment

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

LGTM. Thank you!

@jkotas jkotas merged commit 150c6f7 into dotnet:feature/NativeAOT-LLVM Nov 29, 2020
@yowl
Copy link
Contributor Author

yowl commented Nov 29, 2020

Thanks for all the help.

@yowl yowl deleted the llvm-rename branch November 29, 2020 16:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-NativeAOT-LLVM LLVM generation for Native AOT compilation (including Web Assembly)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants