Skip to content

Support -embed-bitcode and -driver-print-bindings #101

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

Merged
merged 3 commits into from
May 20, 2020

Conversation

cltnschlosser
Copy link
Contributor

  • The moduleNameIsFallback fix for the linker fixes Driver/verify-debug-info.swift (dysm at wrong name)
  • embed-bitcode tests in Driver/multi-threaded.swift are fixed (Still some tests there "failing" because parsable output json is in different order)
  • Driver/embed-bitcode.swift tests are fixed except one. Driver jobs are printed in different order.
// RUN: %target-swiftc_driver -embed-bitcode -Xcc -DDEBUG -Xllvm -fake-llvm-option -c -emit-module %s 2>&1 -### | %FileCheck %s -check-prefix=CHECK-MODULE
// CHECK-MODULE: -frontend
// CHECK-MODULE: -emit-bc
// CHECK-MODULE-DAG: -Xcc -DDEBUG
// CHECK-MODULE-DAG: -Xllvm -fake-llvm-option
// CHECK-MODULE-DAG: -emit-module-path
// CHECK-MODULE: -frontend
// CHECK-MODULE: -emit-module
// CHECK-MODULE: -frontend
// CHECK-MODULE: -c
// CHECK-MODULE-NOT: -Xcc
// CHECK-MODULE-NOT: -DDEBUG
// CHECK-MODULE-NOT: -fake-llvm-option
// CHECK-MODULE-NOT: -emit-module-path

In this case the merge module job gets printed before the backend job. For all other tests the merge module job is last. Not sure what is effecting the print order in c++ driver.

Comment on lines +33 to +44
// -embed-bitcode only supports a restricted set of flags.
commandLine.appendFlag(.target)
commandLine.appendFlag(targetTriple.triple)

// Enable address top-byte ignored in the ARM64 backend.
if targetTriple.arch == .aarch64 {
commandLine.appendFlag(.Xllvm)
commandLine.appendFlag("-aarch64-use-tbi")
}

// Handle the CPU and its preferences.
try commandLine.appendLast(.targetCpu, from: &parsedOptions)
Copy link
Member

Choose a reason for hiding this comment

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

A bunch of this is repeated fromaddCommonFrontendOptions. Can you factor some of it our so there's less duplication here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So there is some duplication here, but I don't know how much I can factor out without changing the order of the arguments (That shouldn't really matter, but there are probably some lit tests that rely on the current ordering.

The interesting part from addCommonFrontendOptions is:

    switch compilerMode {
    case .standardCompile, .singleCompile, .batchCompile, .compilePCM:
      commandLine.appendFlag(.target)
      commandLine.appendFlag(targetTriple.triple)

    case .repl, .immediate:
      if parsedOptions.hasArgument(.target) {
        commandLine.appendFlag(.target)
        commandLine.appendFlag(targetTriple.triple)
      }
    }

    if let variant = parsedOptions.getLastArgument(.targetVariant)?.asSingle {
      commandLine.appendFlag(.targetVariant)
      commandLine.appendFlag(Triple(variant, normalizing: true).triple)
    }

    // Enable address top-byte ignored in the ARM64 backend.
    if (targetTriple.arch == .aarch64) {
      commandLine.appendFlag(.Xllvm)
      commandLine.appendFlag("-aarch64-use-tbi")
    }

    // Enable or disable ObjC interop appropriately for the platform
    if targetTriple.isDarwin {
      commandLine.appendFlag(.enableObjcInterop)
    } else {
      commandLine.appendFlag(.disableObjcInterop)
    }

    // Handle the CPU and its preferences.
    try commandLine.appendLast(.targetCpu, from: &parsedOptions)

The switch is fine, because we don't have backend jobs for repl and immediate builds, but would have to move these out of order.

    if let variant = parsedOptions.getLastArgument(.targetVariant)?.asSingle {
      commandLine.appendFlag(.targetVariant)
      commandLine.appendFlag(Triple(variant, normalizing: true).triple)
    }
    // Enable or disable ObjC interop appropriately for the platform
    if targetTriple.isDarwin {
      commandLine.appendFlag(.enableObjcInterop)
    } else {
      commandLine.appendFlag(.disableObjcInterop)
    }

Looking at this further. Is there any reason that the embed-bitcode job doesn't use the targetVariant parameter. Seems like it should, but the c++ driver doesn't.

Copy link
Member

Choose a reason for hiding this comment

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

Hmm. I see what you mean. We can keep it like this, and maybe there’s some future refactoring we can do. I worry about maintainability when we’re doing the same argument translation in several places.

Regarding -target-variant, yes, I think we should pass it through for bitcode compilation. It gets embedded in the binary. This is probably a bug in the C++ driver

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should I add the -target-variant here?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, please add the -target-variant

var jobOutputs: [TypedVirtualPath] = []
let job = try compileJob(primaryInputs: primaryInputs, outputType: .llvmBitcode, allOutputs: &jobOutputs)
jobs.append(job)
for input in job.outputs.filter({ $0.type == .llvmBitcode }) {
Copy link
Member

Choose a reason for hiding this comment

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

This is really nice and clean, thanks!

@DougGregor
Copy link
Member

@swift-ci test

@DougGregor
Copy link
Member

@cltnschlosser Mind if I go ahead and merge this? The -target-variant change can come in later

@cltnschlosser
Copy link
Contributor Author

@cltnschlosser Mind if I go ahead and merge this? The -target-variant change can come in later

Yep, sounds good

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

Successfully merging this pull request may close these issues.

2 participants