Skip to content

Commit

Permalink
Android: Default to cortex-a8 CPU for ARMv7-A (#3439)
Browse files Browse the repository at this point in the history
Hardcoded instead of pre-setting ldc2.conf for the prebuilt Android
packages, and thus simplifying cross-compilation (e.g., issue #3437).

Also use `core2` instead of `x86-64` for Android x86_64.
  • Loading branch information
kinke authored Jun 1, 2020
1 parent cf8e90a commit 3e859c9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
4 changes: 0 additions & 4 deletions .azure-pipelines/posix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ steps:
chmod 755 llvm-$ARCH/bin/llvm-config
# Set up DFLAGS for cross-compiling/linking with host ldmd2
DFLAGS="-mtriple=$LLVM_TRIPLE -L-L$PWD/ldc-build-runtime.tmp/lib -gcc=$PWD/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/bin/$ARCH-linux-${androidEnv}21-clang"
if [ "$ARCH" = "armv7a" ]; then DFLAGS="$DFLAGS -mcpu=cortex-a8"; fi
set +x
echo "##vso[task.setvariable variable=DFLAGS]$DFLAGS"
displayName: 'Android: Set up cross-compilation'
Expand All @@ -159,8 +158,6 @@ steps:
installDir=$PWD/install
mkdir build-$ARCH
cd build-$ARCH
DEFAULT_LDC_SWITCHES=''
if [ "$ARCH" = "armv7a" ]; then DEFAULT_LDC_SWITCHES=" \"-mcpu=cortex-a8\","; fi
IFS=$'\n' extraFlags=( $(xargs -n1 <<<"$EXTRA_CMAKE_FLAGS $EXTRA_CMAKE_FLAGS_ANDROID") )
cmake -G Ninja $BUILD_SOURCESDIRECTORY \
-DCMAKE_BUILD_TYPE=Release \
Expand All @@ -169,7 +166,6 @@ steps:
-DCMAKE_INSTALL_PREFIX=$installDir \
-DINCLUDE_INSTALL_DIR=$installDir/import \
-DD_LINKER_ARGS="-L$PWD/../ldc-build-runtime.tmp/lib;-lphobos2-ldc;-ldruntime-ldc" \
-DADDITIONAL_DEFAULT_LDC_SWITCHES="$DEFAULT_LDC_SWITCHES" \
"${extraFlags[@]}"
ninja -j$PARALLEL_JOBS -v ldc2 ldmd2 ldc-build-runtime ldc-profdata ldc-prune-cache
displayName: 'Android: Cross-compile LDC executables'
Expand Down
24 changes: 16 additions & 8 deletions driver/targetmachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,13 @@ static std::string getX86TargetCPU(const llvm::Triple &triple) {
if (triple.isOSDarwin()) {
return triple.isArch64Bit() ? "core2" : "yonah";
}

// All x86 devices running Android have core2 as their common
// denominator.
if (triple.getEnvironment() == llvm::Triple::Android) {
return "core2";
}

// Everything else goes to x86-64 in 64-bit mode.
if (triple.isArch64Bit()) {
return "x86-64";
Expand All @@ -146,18 +153,20 @@ static std::string getX86TargetCPU(const llvm::Triple &triple) {
if (triple.getOSName().startswith("dragonfly")) {
return "i486";
}
// All x86 devices running Android have core2 as their common
// denominator. This makes a better choice than pentium4.
if (triple.getEnvironment() == llvm::Triple::Android) {
return "core2";

// Fallback to p4.
}
// Fallback to p4.
return "pentium4";
}

static std::string getARMTargetCPU(const llvm::Triple &triple) {
auto defaultCPU = llvm::ARM::getDefaultCPU(triple.getArchName());

// 32-bit Android: default to cortex-a8
if (defaultCPU == "generic" &&
triple.getEnvironment() == llvm::Triple::Android) {
return "cortex-a8";
}

if (!defaultCPU.empty())
return std::string(defaultCPU);

Expand Down Expand Up @@ -291,8 +300,7 @@ const llvm::Target *lookupTarget(const std::string &arch, llvm::Triple &triple,

if (!target) {
errorMsg = "invalid target architecture '" + arch +
"', see "
"-version for a list of supported targets.";
"', see -version for a list of supported targets.";
return nullptr;
}

Expand Down

0 comments on commit 3e859c9

Please sign in to comment.