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

Update for ocl-open-140 branch #327

Merged
merged 1 commit into from
Mar 23, 2022
Merged
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
71 changes: 71 additions & 0 deletions .github/workflows/check-in-tree-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: In-tree build

on:
push:
branches:
- 'ocl-open-*'
paths-ignore: # no need to check build for:
- 'docs/**' # documentation
- '**.md' # README
pull_request:
branches:
- 'ocl-open-*'
paths-ignore: # no need to check build for:
- 'docs/**' # documentation
- '**.md' # README
schedule:
# Weekly build on Mondays
# Ideally, we might want to simplify our regular nightly build as we
# probably don't need every configuration to be built every day: most of
# them are only necessary in pre-commits to avoid breakages
- cron: 0 0 * * 0

env:
LLVM_VERSION: 14

jobs:
build_and_test_linux:
name: Linux
strategy:
matrix:
build_type: [Release]
include:
- build_type: Release
fail-fast: false
runs-on: ubuntu-18.04
steps:
- name: setup git config
run: |
git config --global user.email "<>"
git config --global user.name "GitHub Actions Bot"
- name: Checkout LLVM sources
uses: actions/checkout@v2
with:
repository: llvm/llvm-project
ref: release/14.x
path: llvm-project
- name: Checkout the translator sources
uses: actions/checkout@v2
with:
repository: KhronosGroup/SPIRV-LLVM-Translator
ref: llvm_release_140
path: llvm-project/SPIRV-LLVM-Translator
- name: Checkout opencl-clang sources
uses: actions/checkout@v2
with:
path: llvm-project/opencl-clang
- name: Configure
run: |
mkdir build && cd build
cmake ${{ github.workspace }}/llvm-project/llvm \
-DLLVM_ENABLE_PROJECTS="clang" \
-DLLVM_EXTERNAL_PROJECTS="llvm-spirv;opencl-clang" \
-DLLVM_EXTERNAL_LLVM_SPIRV_SOURCE_DIR=${{ github.workspace }}/llvm-project/SPIRV-LLVM-Translator \
-DLLVM_EXTERNAL_OPENCL_CLANG_SOURCE_DIR=${{ github.workspace }}/llvm-project/opencl-clang \
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \
-DLLVM_TARGETS_TO_BUILD="X86" \
-G "Unix Makefiles"
- name: Build
run: |
cd build
make opencl-clang -j2
14 changes: 7 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
add_definitions(-DUSE_PREBUILT_LLVM)

if(NOT PREFERRED_LLVM_VERSION)
set(PREFERRED_LLVM_VERSION "13.0.0")
set(PREFERRED_LLVM_VERSION "14.0.0")
endif(NOT PREFERRED_LLVM_VERSION)
message(STATUS "[OPENCL-CLANG] Looking for LLVM version ${PREFERRED_LLVM_VERSION}")
find_package(LLVM ${PREFERRED_LLVM_VERSION} REQUIRED)
Expand Down Expand Up @@ -80,13 +80,13 @@ set(TARGET_NAME ${COMMON_CLANG_LIBRARY_NAME}${BUILD_PLATFORM} )
if(NOT USE_PREBUILT_LLVM)

if(NOT LLVM_EXTERNAL_CLANG_SOURCE_DIR)
set(LLVM_BASE_REVISION release_13)
set(LLVM_BASE_REVISION release_14)
set(CLANG_SOURCE_DIR ${LLVM_SOURCE_DIR}/tools/clang)
set(CLANG_BASE_REVISION release_13)
set(CLANG_BASE_REVISION release_14)
elseif(EXISTS "${LLVM_EXTERNAL_CLANG_SOURCE_DIR}/CMakeLists.txt")
set(LLVM_BASE_REVISION release/13.x)
set(LLVM_BASE_REVISION release/14.x)
set(CLANG_SOURCE_DIR "${LLVM_EXTERNAL_CLANG_SOURCE_DIR}")
set(CLANG_BASE_REVISION release/13.x)
set(CLANG_BASE_REVISION release/14.x)
endif()
if(EXISTS ${CLANG_SOURCE_DIR})
message(STATUS "[OPENCL-CLANG] Using Clang source code direcotry: ${CLANG_SOURCE_DIR}")
Expand Down Expand Up @@ -121,8 +121,8 @@ if(NOT USE_PREBUILT_LLVM)
)
endif()

set(SPIRV_BASE_REVISION llvm_release_130)
set(TARGET_BRANCH "ocl-open-130")
set(SPIRV_BASE_REVISION llvm_release_140)
set(TARGET_BRANCH "ocl-open-140")
get_filename_component(LLVM_MONOREPO_DIR ${LLVM_SOURCE_DIR} DIRECTORY)
set(LLVM_PATCHES_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/patches/llvm
${CMAKE_CURRENT_SOURCE_DIR}/patches/clang)
Expand Down
12 changes: 5 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
[![Build Status](https://travis-ci.com/intel/opencl-clang.svg?branch=master)](https://travis-ci.com/intel/opencl-clang)

opencl-clang is a thin wrapper library around clang. The library has
OpenCL-oriented API and is capable to compile OpenCL C kernels to SPIR-V
modules.
Expand All @@ -25,9 +23,9 @@ Before the build all dependencies must be downloaded and laid out as follows:
This can be done using the following commands:
```bash
cd <workspace>
git clone https://github.com/llvm/llvm-project.git . -b release/13.x
git clone https://github.com/KhronosGroup/SPIRV-LLVM-Translator.git -b llvm_release_130
git clone https://github.com/intel/opencl-clang.git -b ocl-open-130
git clone https://github.com/llvm/llvm-project.git . -b release/14.x
git clone https://github.com/KhronosGroup/SPIRV-LLVM-Translator.git -b llvm_release_140
git clone https://github.com/intel/opencl-clang.git -b ocl-open-140
```

Then we need to create a build directory and run the build:
Expand Down Expand Up @@ -58,7 +56,7 @@ documented in [Embedding LLVM in your project](https://llvm.org/docs/CMake.html#
Commands to checkout sources and build:
```bash
cd <workspace>
git clone https://github.com/intel/opencl-clang.git -b ocl-open-130
git clone https://github.com/intel/opencl-clang.git -b ocl-open-140
mkdir build && cd build
cmake ../opencl-clang
make all -j`nproc`
Expand All @@ -68,7 +66,7 @@ make all -j`nproc`

##### Preferred LLVM version

By default, opencl-clang's cmake script is searching for LLVM 13.0.0. You can
By default, opencl-clang's cmake script is searching for LLVM 14.0.0. You can
override target version of LLVM by using the `PREFERRED_LLVM_VERSION` cmake
option:

Expand Down
21 changes: 18 additions & 3 deletions cmake/modules/CMakeFunctions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,11 @@ endfunction()
# Then all patches from the `patches_dir` are committed to the `target_branch`.
# Does nothing if the `target_branch` is already checked out in the `repo_dir`.
#
function(apply_patches repo_dir patches_dir base_revision target_branch)
file(GLOB patches ${patches_dir}/*.patch)
function(apply_patches repo_dir patches_dir base_revision target_branch ret)
foreach(patches_dir ${patches_dir})
file(GLOB patches_in_dir ${patches_dir}/*.patch)
list(APPEND patches ${patches_in_dir})
endforeach()
if(NOT patches)
message(STATUS "[OPENCL-CLANG] No patches in ${patches_dir}")
return()
Expand All @@ -105,7 +108,9 @@ function(apply_patches repo_dir patches_dir base_revision target_branch)
ERROR_QUIET
OUTPUT_QUIET
)
if(patches_needed) # The target branch doesn't exist
if(patches_needed EQUAL 128) # not a git repo
set(ret_not_git_repo 1)
elseif(patches_needed) # The target branch doesn't exist
list(SORT patches)
is_valid_revision(${repo_dir} ${base_revision} exists_base_rev)

Expand Down Expand Up @@ -139,8 +144,12 @@ function(apply_patches repo_dir patches_dir base_revision target_branch)
WORKING_DIRECTORY ${repo_dir}
OUTPUT_VARIABLE patching_log
ERROR_QUIET
RESULT_VARIABLE ret_apply_patch
)
message(STATUS "[OPENCL-CLANG] Not present - ${patching_log}")
if (ret_apply_patch)
break()
endif()
endif()
endforeach(patch)
else() # The target branch already exists
Expand All @@ -149,8 +158,14 @@ function(apply_patches repo_dir patches_dir base_revision target_branch)
WORKING_DIRECTORY ${repo_dir}
ERROR_QUIET
OUTPUT_QUIET
RESULT_VARIABLE ret_check_out
)
endif()
if (NOT (ret_not_git_repo OR ret_check_out OR ret_apply_patch))
set(${ret} True PARENT_SCOPE)
else()
message(FATAL_ERROR "[OPENCL-CLANG] Failed to apply patch!")
endif()
endfunction()

# Usage
Expand Down
6 changes: 3 additions & 3 deletions options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ OpenCLArgList *OpenCLOptTable::ParseArgs(const char *szOptions,
}

unsigned prev = index;
Arg *pArg = ParseOneArg(*pArgs, index);
std::unique_ptr<Arg> pArg = ParseOneArg(*pArgs, index);
assert(index > prev && "Parser failed to consume argument.");

// Check for missing argument error.
Expand All @@ -101,8 +101,8 @@ OpenCLArgList *OpenCLOptTable::ParseArgs(const char *szOptions,
break;
}

m_synthesizedArgs.emplace_back(std::unique_ptr<llvm::opt::Arg>(pArg));
pArgs->append(pArg);
pArgs->append(pArg.get());
m_synthesizedArgs.emplace_back(std::move(pArg));
}
return pArgs.release();
}
41 changes: 27 additions & 14 deletions patches/clang/0001-Remove-__IMAGE_SUPPORT__-macro-for-SPIR.patch
Original file line number Diff line number Diff line change
@@ -1,34 +1,33 @@
From 8b8ef4b0b24c12d3ab645acabd3cee58bff6ebc9 Mon Sep 17 00:00:00 2001
From: haonanya <haonan.yang@intel.com>
Date: Sat, 8 May 2021 15:18:02 +0800
Subject: [PATCH] Remove __IMAGE_SUPPORT__ macro for SPIR since SPIR doesn't
require image support
From 1ca45b5f5725a447ded14c0096df39f2751c4e9a Mon Sep 17 00:00:00 2001
From: Haonan Yang <haonan.yang@intel.com>
Date: Fri, 25 Feb 2022 10:36:57 +0800
Subject: [PATCH] Remove __IMAGE_SUPPORT__ macro for SPIR

Signed-off-by: haonanya <haonan.yang@intel.com>
Signed-off-by: Haonan Yang <haonan.yang@intel.com>
---
clang/lib/Frontend/InitPreprocessor.cpp | 3 ---
clang/test/Preprocessor/predefined-macros.c | 2 --
2 files changed, 5 deletions(-)
clang/test/Preprocessor/predefined-macros.c | 4 ----
2 files changed, 7 deletions(-)

diff --git a/clang/lib/Frontend/InitPreprocessor.cpp b/clang/lib/Frontend/InitPreprocessor.cpp
index 41b08ed56134..4e6fc0321b0e 100644
index e259ab47c558..0bfdd62f17a2 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
@@ -1161,9 +1161,6 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
@@ -1234,9 +1234,6 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
// OpenCL definitions.
if (LangOpts.OpenCL) {
InitializeOpenCLFeatureTestMacros(TI, LangOpts, Builder);
-
- if (TI.getTriple().isSPIR())
- if (TI.getTriple().isSPIR() || TI.getTriple().isSPIRV())
- Builder.defineMacro("__IMAGE_SUPPORT__");
}

if (TI.hasInt128Type() && LangOpts.CPlusPlus && LangOpts.GNUMode) {
diff --git a/clang/test/Preprocessor/predefined-macros.c b/clang/test/Preprocessor/predefined-macros.c
index e406b9a70570..88606518c7de 100644
index 0b67cbe233ca..aad4a6f05563 100644
--- a/clang/test/Preprocessor/predefined-macros.c
+++ b/clang/test/Preprocessor/predefined-macros.c
@@ -188,14 +188,12 @@
@@ -207,28 +207,24 @@

// RUN: %clang_cc1 %s -E -dM -o - -x cl -triple spir-unknown-unknown \
// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-SPIR
Expand All @@ -43,6 +42,20 @@ index e406b9a70570..88606518c7de 100644
// CHECK-SPIR64-DAG: #define __SPIR__ 1
// CHECK-SPIR64-DAG: #define __SPIR64__ 1
// CHECK-SPIR64-NOT: #define __SPIR32__ 1

// RUN: %clang_cc1 %s -E -dM -o - -x cl -triple spirv32-unknown-unknown \
// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-SPIRV32
-// CHECK-SPIRV32-DAG: #define __IMAGE_SUPPORT__ 1
// CHECK-SPIRV32-DAG: #define __SPIRV__ 1
// CHECK-SPIRV32-DAG: #define __SPIRV32__ 1
// CHECK-SPIRV32-NOT: #define __SPIRV64__ 1

// RUN: %clang_cc1 %s -E -dM -o - -x cl -triple spirv64-unknown-unknown \
// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-SPIRV64
-// CHECK-SPIRV64-DAG: #define __IMAGE_SUPPORT__ 1
// CHECK-SPIRV64-DAG: #define __SPIRV__ 1
// CHECK-SPIRV64-DAG: #define __SPIRV64__ 1
// CHECK-SPIRV64-NOT: #define __SPIRV32__ 1
--
2.17.1
2.29.2