Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
204 changes: 204 additions & 0 deletions .github/workflows/compilation_on_hexagon.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

name: compilation on hexagon (qemu user-mode)

on:
pull_request:
types:
- opened
- synchronize
paths:
- ".github/workflows/build_llvm_libraries.yml"
- ".github/workflows/compilation_on_hexagon.yml"
- "build-scripts/**"
- "core/**"
- "!core/deps/**"
- "product-mini/**"
- "tests/wamr-test-suites/**"
- "wamr-compiler/**"
push:
branches:
- main
- "dev/**"
paths:
- ".github/workflows/build_llvm_libraries.yml"
- ".github/workflows/compilation_on_hexagon.yml"
- "build-scripts/**"
- "core/**"
- "!core/deps/**"
- "product-mini/**"
- "tests/wamr-test-suites/**"
- "wamr-compiler/**"
workflow_dispatch:

# Cancel any in-flight jobs for the same PR/branch so there's only one active
# at a time
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

permissions:
contents: read

jobs:
build_llvm_libraries:
permissions:
contents: read
actions: write
uses: ./.github/workflows/build_llvm_libraries.yml
with:
os: "ubuntu-22.04"
arch: "X86 Hexagon"

build_wamrc:
needs: [build_llvm_libraries]
runs-on: ubuntu-22.04
steps:
- name: checkout
uses: actions/checkout@v6.0.2

- name: Get LLVM libraries
id: retrieve_llvm_libs
uses: actions/cache@v5
with:
path: |
./core/deps/llvm/build/bin
./core/deps/llvm/build/include
./core/deps/llvm/build/lib
./core/deps/llvm/build/libexec
./core/deps/llvm/build/share
key: ${{ needs.build_llvm_libraries.outputs.cache_key }}

- name: Quit if cache miss
if: steps.retrieve_llvm_libs.outputs.cache-hit != 'true'
run: echo "::error::can not get prebuilt llvm libraries" && exit 1

- name: Build wamrc
run: |
mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
cmake --build . --config Release --parallel $(nproc)
working-directory: wamr-compiler

- name: Upload wamrc
uses: actions/upload-artifact@v7.0.1
with:
name: wamrc-hexagon
path: wamr-compiler/build/wamrc

build_iwasm:
runs-on: ubuntu-22.04
steps:
- name: checkout
uses: actions/checkout@v6.0.2

- name: Install QEMU user-mode
run: sudo apt-get update && sudo apt-get install -y qemu-user

- name: Install clang-22 and lld-22
run: |
wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | sudo tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc
echo "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-22 main" | sudo tee /etc/apt/sources.list.d/llvm-22.list
sudo apt-get update
sudo apt-get install -y clang-22 lld-22

- name: Install CodeLinaro Hexagon toolchain
run: |
wget -q https://artifacts.codelinaro.org/artifactory/codelinaro-toolchain-for-hexagon/22.1.4_/hexagon-debs-22.1.4_.tar.gz
mkdir hexagon-debs
tar xf hexagon-debs-22.1.4_.tar.gz -C hexagon-debs
sudo dpkg -i hexagon-debs/*.deb

- name: Cross-compile iwasm for Hexagon
run: |
cmake -S product-mini/platforms/hexagon \
-B build-hexagon \
-DCMAKE_TOOLCHAIN_FILE=${GITHUB_WORKSPACE}/build-scripts/toolchains/hexagon_linux_musl.cmake \
-DCMAKE_BUILD_TYPE=Release \
-DWAMR_DISABLE_HW_BOUND_CHECK=1 \
-DWAMR_BUILD_SHRUNK_MEMORY=0 \
-DWAMR_BUILD_SPEC_TEST=1 \
-DWAMR_BUILD_LIBC_WASI=0
cmake --build build-hexagon --parallel $(nproc)

- name: Verify iwasm binary
run: |
file build-hexagon/iwasm
qemu-hexagon -cpu v67 build-hexagon/iwasm --version

- name: Upload iwasm
uses: actions/upload-artifact@v7.0.1
with:
name: iwasm-hexagon
path: build-hexagon/iwasm

spec_test:
needs: [build_iwasm, build_wamrc]
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
test_option:
- "-s spec -b -P"
- "-s spec -b -S -P"
running_mode:
- "classic-interp"
- "fast-interp"
- "aot"
exclude:
# SIMD AOT needs further validation
- test_option: "-s spec -b -S -P"
running_mode: "aot"
steps:
- name: checkout
uses: actions/checkout@v6.0.2

- name: Install QEMU user-mode
run: sudo apt-get update && sudo apt-get install -y qemu-user

- name: Download iwasm artifact
uses: actions/download-artifact@v4.2.0
with:
name: iwasm-hexagon
path: ./

- name: Download wamrc artifact
if: matrix.running_mode == 'aot'
uses: actions/download-artifact@v4.2.0
with:
name: wamrc-hexagon
path: ./

- name: Set up iwasm wrapper
run: |
chmod +x ./iwasm
# Place the real Hexagon binary at a known path
mv ./iwasm ./iwasm-hexagon-real
# Create a wrapper that invokes iwasm via qemu-hexagon user-mode.
# Use the linux platform path since Hexagon runs Linux and this
# avoids needing to teach every host-tool lookup about "hexagon".
mkdir -p product-mini/platforms/linux/build
printf '#!/bin/sh\nexec qemu-hexagon -cpu v67 %s/iwasm-hexagon-real "$@"\n' \
"${GITHUB_WORKSPACE}" > product-mini/platforms/linux/build/iwasm
chmod +x product-mini/platforms/linux/build/iwasm
# Verify it works
product-mini/platforms/linux/build/iwasm --version

- name: Set up wamrc
if: matrix.running_mode == 'aot'
run: |
chmod +x ./wamrc
mkdir -p wamr-compiler/build
cp ./wamrc wamr-compiler/build/wamrc

- name: Run spec tests
timeout-minutes: 60
run: |
./test_wamr.sh ${{ matrix.test_option }} \
-m HEXAGON \
-t ${{ matrix.running_mode }} \
-j linux \
-Q \
${{ matrix.running_mode == 'aot' && format('-A {0}/wamr-compiler/build/wamrc', github.workspace) || '' }}
working-directory: ./tests/wamr-test-suites
2 changes: 2 additions & 0 deletions build-scripts/config_common.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ elseif (WAMR_BUILD_TARGET STREQUAL "RISCV32_ILP32")
add_definitions(-DBUILD_TARGET_RISCV32_ILP32)
elseif (WAMR_BUILD_TARGET STREQUAL "ARC")
add_definitions(-DBUILD_TARGET_ARC)
elseif (WAMR_BUILD_TARGET STREQUAL "HEXAGON")
add_definitions(-DBUILD_TARGET_HEXAGON)
else ()
message (FATAL_ERROR "-- WAMR build target isn't set")
endif ()
Expand Down
22 changes: 22 additions & 0 deletions build-scripts/toolchains/hexagon_linux_musl.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

# CMake toolchain file for cross-compiling to Hexagon Linux (musl)
# Requires CodeLinaro hexagon-unknown-linux-musl toolchain and clang-22/lld-22.

set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR hexagon)

set(CMAKE_C_COMPILER hexagon-unknown-linux-musl-clang)
set(CMAKE_CXX_COMPILER hexagon-unknown-linux-musl-clang++)
set(CMAKE_ASM_COMPILER hexagon-unknown-linux-musl-clang)
set(CMAKE_AR llvm-ar-22)
set(CMAKE_RANLIB llvm-ranlib-22)

set(CMAKE_C_FLAGS_INIT "-mv68 -G0")
set(CMAKE_CXX_FLAGS_INIT "-mv68 -G0")
set(CMAKE_EXE_LINKER_FLAGS_INIT "-static")

set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
18 changes: 17 additions & 1 deletion core/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
&& !defined(BUILD_TARGET_RISCV32_ILP32D) \
&& !defined(BUILD_TARGET_RISCV32_ILP32F) \
&& !defined(BUILD_TARGET_RISCV32_ILP32) \
&& !defined(BUILD_TARGET_ARC)
&& !defined(BUILD_TARGET_ARC) \
&& !defined(BUILD_TARGET_HEXAGON)
/* clang-format on */
#if defined(__x86_64__) || defined(__x86_64)
#define BUILD_TARGET_X86_64
Expand Down Expand Up @@ -52,6 +53,8 @@
#define BUILD_TARGET_RISCV32_ILP32D
#elif defined(__arc__)
#define BUILD_TARGET_ARC
#elif defined(__hexagon__)
#define BUILD_TARGET_HEXAGON
#else
#error "Build target isn't set"
#endif
Expand Down Expand Up @@ -276,6 +279,19 @@
#endif
#endif

/* Whether the CPU supports unaligned SIMD/vector memory access.
* Some architectures have dedicated unaligned-load vector instructions,
* allowing V128 access at any alignment even when scalar loads require
* natural alignment. */
#ifndef WASM_CPU_SUPPORTS_UNALIGNED_SIMD_ACCESS
#if defined(BUILD_TARGET_X86_32) || defined(BUILD_TARGET_X86_64) \
|| defined(BUILD_TARGET_AARCH64) || defined(BUILD_TARGET_HEXAGON)
#define WASM_CPU_SUPPORTS_UNALIGNED_SIMD_ACCESS 1
#else
#define WASM_CPU_SUPPORTS_UNALIGNED_SIMD_ACCESS 0
#endif
#endif

/* WASM Interpreter labels-as-values feature */
#ifndef WASM_ENABLE_LABELS_AS_VALUES
#ifdef __GNUC__
Expand Down
4 changes: 4 additions & 0 deletions core/iwasm/aot/aot_loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ GET_U16_FROM_ADDR(const uint8 *p)
#define E_MACHINE_ARC_COMPACT 93 /* ARC International ARCompact */
#define E_MACHINE_ARC_COMPACT2 195 /* Synopsys ARCompact V2 */
#define E_MACHINE_XTENSA 94 /* Tensilica Xtensa Architecture */
#define E_MACHINE_HEXAGON 164 /* Qualcomm Hexagon */
#define E_MACHINE_RISCV 243 /* RISC-V 32/64 */
#define E_MACHINE_WIN_I386 0x14c /* Windows i386 architecture */
#define E_MACHINE_WIN_X86_64 0x8664 /* Windows x86-64 architecture */
Expand Down Expand Up @@ -432,6 +433,9 @@ get_aot_file_target(AOTTargetInfo *target_info, char *target_buf,
case E_MACHINE_ARC_COMPACT2:
machine_type = "arc";
break;
case E_MACHINE_HEXAGON:
machine_type = "hexagon";
break;
default:
set_error_buf_v(error_buf, error_buf_size,
"unknown machine type %d", target_info->e_machine);
Expand Down
Loading
Loading