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 powerpc64le Linux support #979

Merged
merged 1 commit into from Jan 16, 2016

Conversation

Projects
None yet
4 participants
@antonblanchard
Contributor

antonblanchard commented Jan 14, 2016

This patch adds powerpc64le Linux support. While the patch also adds
the matching powerpc64 bits, there are endian issues that need to be
sorted out.

The PowerPC LLVM changes for the swift ABI (eg returning three element
non-homogeneous aggregates) are still in the works, but a simple LLVM
fix to allow those aggregates results in swift passing all but 8
test cases.

Note: It would be nice if swift had conditional compilation based on pointer size, a
number of the test cases only care if the target is 32 or 64 bit.

@gribozavr

This comment has been minimized.

Collaborator

gribozavr commented Jan 15, 2016

Is powerpc64 big-endian?

@antonblanchard

This comment has been minimized.

Contributor

antonblanchard commented Jan 15, 2016

Yes, powerpc64 is big endian. We hope to get big endian working, but for now are concentrating on the little endian port (powerpc64le).

@gribozavr

View changes

include/swift/Runtime/Metadata.h Outdated
@@ -919,7 +919,7 @@ static const uintptr_t ObjCReservedBitsMask =
static const unsigned ObjCReservedLowBits =
SWIFT_ABI_X86_64_OBJC_NUM_RESERVED_LOW_BITS;
#elif defined(__arm64__)
#elif defined(__arm64__) || defined(__powerpc64__)

This comment has been minimized.

@gribozavr

gribozavr Jan 15, 2016

Collaborator

Is __powerpc64__ defined on BE, LE or both?

This comment has been minimized.

@antonblanchard

antonblanchard Jan 15, 2016

Contributor

It is defined on both BE and LE targets:

$ uname -m
ppc64le
$ cpp -dM < /dev/null | grep __powerpc64__
#define __powerpc64__ 1
$ uname -m
ppc64
$ cpp -dM < /dev/null | grep __powerpc64__
#define __powerpc64__ 1

This comment has been minimized.

@gribozavr

gribozavr Jan 15, 2016

Collaborator

The comment above this block says that lib/IRGen/SwiftTargetInfo.cpp needs adjustments (you need to add a configurePowerPC function there).

@gribozavr

View changes

stdlib/public/SDK/CoreGraphics/CGFloat.swift.gyb Outdated
@@ -27,7 +27,7 @@ public struct CGFloat {
/// The native type used to store the CGFloat, which is Float on
/// 32-bit architectures and Double on 64-bit architectures.
public typealias NativeType = Float
#elseif arch(x86_64) || arch(arm64)
#elseif arch(x86_64) || arch(arm64) || arch(powerpc64) || arch(powerpc64le)

This comment has been minimized.

@gribozavr

gribozavr Jan 15, 2016

Collaborator

This file is not built on Linux, please revert this part.

@gribozavr

View changes

stdlib/public/core/FixedPoint.swift.gyb Outdated
@@ -244,7 +244,7 @@ public struct ${Self}
/// byte order if necessary.
@_transparent public
init(bigEndian value: ${Self}) {
#if arch(i386) || arch(x86_64) || arch(arm) || arch(arm64)
#if arch(i386) || arch(x86_64) || arch(arm) || arch(arm64) || arch(powerpc64) || arch(powerpc64le)

This comment has been minimized.

@gribozavr

gribozavr Jan 15, 2016

Collaborator

BE needs a different (the opposite!) implementation here and below.

This comment has been minimized.

@antonblanchard

antonblanchard Jan 15, 2016

Contributor

Nice catch, fixing.

@gribozavr

View changes

stdlib/public/runtime/SwiftObject.mm Outdated
@@ -462,7 +462,7 @@ - (BOOL)isNSValue__ { return NO; }
#if defined(__x86_64__)
static uintptr_t const objectPointerIsObjCBit = 0x4000000000000000ULL;
#elif defined(__arm64__)
#elif defined(__arm64__) || defined(__powerpc64__)

This comment has been minimized.

@gribozavr

gribozavr Jan 15, 2016

Collaborator

This code is not built on Linux, please revert this part.

@gribozavr

View changes

test/1_stdlib/BridgeStorage.swift.gyb Outdated
@@ -77,7 +77,7 @@ func isOSAtLeast(major: Int, _ minor: Int, patch: Int = 0) -> Bool {
func expectTagged(s: NSString, _ expected: Bool) -> NSString {
#if arch(x86_64)
let mask: UInt = 0x8000000000000001
#elseif arch(arm64)
#elseif arch(arm64) || arch(powerpc64) || arch(powerpc64le)

This comment has been minimized.

@gribozavr

gribozavr Jan 15, 2016

Collaborator

This file is not built on Linux, please revert this part.

@gribozavr

View changes

test/IRGen/autorelease.sil Outdated
@@ -10,6 +10,8 @@ import Swift
// armv7k: [[OBJC:%objc_object]] = type
// arm64: [[OBJC:%objc_object]] = type
// i386: [[OBJC:%objc_object]] = type
// powerpc64: [[OBJC:%objc_object]] = type
// powerpc64le: [[OBJC:%objc_object]] = type

This comment has been minimized.

@gribozavr

gribozavr Jan 15, 2016

Collaborator

This is an ObjC-runtime-specific test. Please add // REQUIRES: objc_interop instead and revert the other changes.

@gribozavr

View changes

test/Inputs/clang-importer-sdk/swift-modules/CoreGraphics.swift Outdated
@@ -8,7 +8,7 @@ public func == (lhs: CGPoint, rhs: CGPoint) -> Bool {
public struct CGFloat {
#if arch(i386) || arch(arm)
public typealias UnderlyingType = Float
#elseif arch(x86_64) || arch(arm64)
#elseif arch(x86_64) || arch(arm64) || arch(powerpc64) || arch(powerpc64le)

This comment has been minimized.

@gribozavr

gribozavr Jan 15, 2016

Collaborator

This file shouldn't be built on Linux, is it actually built?

@gribozavr

View changes

validation-test/stdlib/SceneKit.swift Outdated
@@ -37,7 +37,7 @@ if #available(iOS 8.0, *) {
],
bytesFromNSData(element.data))
expectEqual(4, element.bytesPerIndex)
#elseif arch(x86_64) || arch(arm64)
#elseif arch(x86_64) || arch(arm64) || arch(powerpc64) || arch(powerpc64le)

This comment has been minimized.

@gribozavr

gribozavr Jan 15, 2016

Collaborator

This file is not built on Linux, please revert this part.

@gribozavr

View changes

validation-test/stdlib/CoreAudio.swift Outdated
@@ -103,7 +103,7 @@ CoreAudioTestSuite.test(
"AudioBuffer.init(_: UnsafeMutableBufferPointer, numberOfChannels: Int)/trap") {
#if arch(i386) || arch(arm)
let overflowingCount = Int.max
#elseif arch(x86_64) || arch(arm64)
#elseif arch(x86_64) || arch(arm64) || arch(powerpc64) || arch(powerpc64le)

This comment has been minimized.

@gribozavr

gribozavr Jan 15, 2016

Collaborator

This file is not built on Linux, please revert this part.

@gribozavr

This comment has been minimized.

Collaborator

gribozavr commented Jan 15, 2016

How far does this patch allows the port to go? Does the standard library build? Does hello world work? Do the tests run?

@antonblanchard

This comment has been minimized.

Contributor

antonblanchard commented Jan 15, 2016

The powerpc64le port builds and runs the test suite with a few failures:

********************
Testing Time: 275.66s
********************
Failing Tests (5):
    Swift :: 1_stdlib/VarArgs.swift
    Swift :: Driver/filelists.swift
    Swift :: IRGen/c_layout.sil
    Swift :: IRGen/type_layout_reference_storage.swift
    Swift :: Parse/BOM.swift

  Expected Passes    : 1698
  Expected Failures  : 67
  Unsupported Tests  : 651
  Unexpected Failures: 5
*** Failed while running tests for swift (check-swift-linux-powerpc64le)

And hello world works:

$ cat hello.swift 
print("Hello, world!")
$ swiftc hello.swift 
$ ./hello 
Hello, world!
@gribozavr

This comment has been minimized.

Collaborator

gribozavr commented Jan 15, 2016

@antonblanchard I'm really impressed!

@gribozavr

This comment has been minimized.

Collaborator

gribozavr commented Jan 15, 2016

Did you try the validation test suite build-script -T?

@antonblanchard

This comment has been minimized.

Contributor

antonblanchard commented Jan 15, 2016

Thanks, that's given me a few more failing tests to sort out:

********************
Testing Time: 1467.18s
********************
Failing Tests (8):
    Swift :: 1_stdlib/VarArgs.swift
    Swift :: Driver/filelists.swift
    Swift :: IRGen/c_layout.sil
    Swift :: IRGen/type_layout_reference_storage.swift
    Swift :: Parse/BOM.swift
    Swift :: stdlib/AtomicInt.swift
    Swift :: stdlib/CollectionType.swift.gyb
    Swift :: stdlib/FloatingPointConversionTraps.swift.gyb

  Expected Passes    : 6961
  Expected Failures  : 79
  Unsupported Tests  : 771
  Unexpected Failures: 8
@gribozavr

This comment has been minimized.

Collaborator

gribozavr commented Jan 15, 2016

Again, very impressed it is just 8 tests in total!

@antonblanchard

This comment has been minimized.

Contributor

antonblanchard commented Jan 15, 2016

Yes, I'm surprised by how clean the port is. Having the compiler written in c++ (vs the target language), and pulling in clang to get the ABI parameter passing rules helps. Other LLVM based languages have required a lot more work.

Big endian still requires work, but we can attack that once the little endian port is solid.

@antonblanchard

This comment has been minimized.

Contributor

antonblanchard commented Jan 15, 2016

I'm not sure of the preferred workflow, but I'm happy to rebase and squash these commits.

@gribozavr

View changes

stdlib/public/core/FixedPoint.swift.gyb Outdated
self = ${Self}(Builtin.int_bswap_${BuiltinName}(value._value) )
#else
_UnsupportedArchitectureError()

This comment has been minimized.

@gribozavr

gribozavr Jan 15, 2016

Collaborator

Please keep the unsupported error so that we get a loud error for new architectures. Just add an explicit #elseif arch(powerpc64) for BE (here and below).

@gribozavr

This comment has been minimized.

Collaborator

gribozavr commented Jan 15, 2016

Yes, we prefer rebasing/squashing.

@antonblanchard antonblanchard force-pushed the antonblanchard:powerpc64_merge branch Jan 15, 2016

break;
case llvm::Triple::ArchType::ppc64le:
addTargetConfigOption("arch", "powerpc64le");
break;

This comment has been minimized.

@gribozavr

gribozavr Jan 15, 2016

Collaborator

This part needs a test like test/BuildConfigurations/x64LinuxTarget.swift for each supported triple.

This comment has been minimized.

@antonblanchard

antonblanchard Jan 15, 2016

Contributor

Thanks, will add these tests

@gribozavr

This comment has been minimized.

Collaborator

gribozavr commented Jan 15, 2016

@antonblanchard Thank you! Looks good, but I have two more comments.

@lattner

This comment has been minimized.

Collaborator

lattner commented Jan 15, 2016

Very cool, thank you for working on adding this!

Add powerpc64le Linux support
This patch adds powerpc64le Linux support. While the patch also adds
the matching powerpc64 bits, there are endian issues that need to be
sorted out.

The PowerPC LLVM changes for the swift ABI (eg returning three element
non-homogeneous aggregates) are still in the works, but a simple LLVM
fix to allow those aggregates results in swift passing all but 8
test cases.

@antonblanchard antonblanchard force-pushed the antonblanchard:powerpc64_merge branch to b1827d8 Jan 15, 2016

@antonblanchard

This comment has been minimized.

Owner

antonblanchard commented on stdlib/public/core/Builtin.swift in b1827d8 Jan 15, 2016

I'm wondering if this is correct. We should have access to the three bottom bits as a result of allocations being aligned, but do I need to care about _objectPointerIsObjCBit on powerpc64 Linux? Should it just be defined to 0?

@gribozavr

This comment has been minimized.

Collaborator

gribozavr commented Jan 16, 2016

@antonblanchard The ObjC values should be dynamically dead as far as I understand. If you find they are also statically unused -- feel free to remove them!

@gribozavr

This comment has been minimized.

Collaborator

gribozavr commented Jan 16, 2016

I ran tests on Ubuntu 14.04 x86_64 and OS X, and see no regressions. Merging. Thank you!

gribozavr added a commit that referenced this pull request Jan 16, 2016

@gribozavr gribozavr merged commit 5a1f8b2 into apple:master Jan 16, 2016

@jrose-apple

This comment has been minimized.

Member

jrose-apple commented on utils/build-script-impl in b1827d8 Jan 16, 2016

Hm. I wonder if we should start allowing this to be customized soon. LLVM targets aren't that quick to build.

@antonblanchard

This comment has been minimized.

Contributor

antonblanchard commented Jan 16, 2016

Thanks for your help @gribozavr!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment