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

Drop support for LLVM12 #6686

Merged
merged 19 commits into from
Apr 8, 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
2 changes: 2 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ Checks: >
-*,
bugprone-*,
-bugprone-branch-clone,
-bugprone-easily-swappable-parameters,
-bugprone-exception-escape,
-bugprone-implicit-widening-of-multiplication-result,
-bugprone-integer-division,
-bugprone-narrowing-conversions,
-bugprone-reserved-identifier,
Expand Down
12 changes: 10 additions & 2 deletions .github/workflows/packaging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,20 @@ jobs:
env:
CMAKE_CXX_COMPILER_LAUNCHER: ccache
CMAKE_C_COMPILER_LAUNCHER: ccache
LLVM_ROOT: /usr/lib/llvm-12
LLVM_ROOT: /usr/lib/llvm-13
steps:
- name: Install dependencies
run: |
wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null \
| gpg --dearmor - | sudo tee /etc/apt/trusted.gpg.d/kitware.gpg >/dev/null
sudo apt-add-repository 'deb https://apt.kitware.com/ubuntu/ focal main'
# from apt.llvm.org
# wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add -
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 15CF4D18AF4F7421
sudo apt-add-repository "deb https://apt.llvm.org/$(lsb_release -sc)/ llvm-toolchain-$(lsb_release -sc)-13 main"
sudo apt update
sudo apt install cmake ninja-build doxygen ccache
sudo apt install llvm-12-dev liblld-12-dev clang-12 libclang-12-dev libjpeg-dev libpng-dev
sudo apt install llvm-13-dev liblld-13-dev clang-13 libclang-13-dev libjpeg-dev libpng-dev
sudo apt install lintian dpkg-dev
- name: Check out sources
uses: actions/checkout@v2
Expand All @@ -37,6 +41,10 @@ jobs:
# Specifically use the CMake version that comes with Ubuntu.
- name: Install dependencies
run: |
# from apt.llvm.org
# wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add -
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 15CF4D18AF4F7421
sudo apt-add-repository "deb https://apt.llvm.org/$(lsb_release -sc)/ llvm-toolchain-$(lsb_release -sc)-13 main"
sudo apt update
sudo apt install cmake ninja-build libc6-dev-arm64-cross gcc-aarch64-linux-gnu g++-aarch64-linux-gnu qemu-user
- name: Check out sources
Expand Down
12 changes: 8 additions & 4 deletions .github/workflows/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,17 @@ jobs:
- uses: actions/checkout@v2
- name: Install clang-tidy
run: |
# from apt.llvm.org
# wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add -
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 15CF4D18AF4F7421
sudo apt-add-repository "deb https://apt.llvm.org/$(lsb_release -sc)/ llvm-toolchain-$(lsb_release -sc)-13 main"
sudo apt-get update
sudo apt-get install llvm-12 clang-12 liblld-12-dev libclang-12-dev clang-tidy-12 ninja-build
sudo apt-get install llvm-13 clang-13 liblld-13-dev libclang-13-dev clang-tidy-13 ninja-build
- name: Run clang-tidy
run: |
export CC=clang-12
export CXX=clang++-12
export CLANG_TIDY_LLVM_INSTALL_DIR=/usr/lib/llvm-12
export CC=clang-13
export CXX=clang++-13
export CLANG_TIDY_LLVM_INSTALL_DIR=/usr/lib/llvm-13
./run-clang-tidy.sh
check_cmake_file_lists:
name: Check CMake file lists
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -1066,7 +1066,7 @@ $(BUILD_DIR)/initmod.%_32_debug.ll: $(SRC_DIR)/runtime/%.cpp $(BUILD_DIR)/clang_
@mkdir -p $(@D)
$(CLANG) $(CXX_WARNING_FLAGS) -g -DDEBUG_RUNTIME -O3 $(RUNTIME_CXX_FLAGS) -fpic -m32 -target $(RUNTIME_TRIPLE_32) -DCOMPILING_HALIDE_RUNTIME -DBITS_32 -emit-llvm -S $(SRC_DIR)/runtime/$*.cpp -o $@ -MMD -MP -MF $(BUILD_DIR)/initmod.$*_32_debug.d

ifneq (,$(findstring $(LLVM_VERSION_TIMES_10), 120 130))
ifneq (,$(findstring $(LLVM_VERSION_TIMES_10), 130))
# For LLVM14+, we must add elementtype() annotations to some of our LLVM IR;
# earlier versions either don't understand that keyword at all, or don't support
# the uses we have for it. Rather than forking these sources, for now we'll just
Expand Down Expand Up @@ -2185,7 +2185,7 @@ $(BUILD_DIR)/clang_ok:
@exit 1
endif

ifneq (,$(findstring $(LLVM_VERSION_TIMES_10), 120 130 140, 150))
ifneq (,$(findstring $(LLVM_VERSION_TIMES_10), 130 140, 150))
LLVM_OK=yes
endif

Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,14 @@ issue.

### TL;DR

Have llvm-12.0 (or greater) installed and run `make` in the root directory of
Have llvm-13.0 (or greater) installed and run `make` in the root directory of
the repository (where this README is).

### Acquiring LLVM

At any point in time, building Halide requires either the latest stable version
of LLVM, the previous stable version of LLVM, and trunk. At the time of writing,
this means versions 13.0 and 12.0 are supported, but 11.0 is not. The commands
this means versions 14.0 and 13.0 are supported, but 12.0 is not. The commands
`llvm-config` and `clang` must be somewhere in the path.

If your OS does not have packages for LLVM, you can find binaries for it at
Expand All @@ -130,7 +130,7 @@ If you want to build it yourself, first check it out from GitHub:
% git clone --depth 1 --branch llvmorg-13.0.0 https://github.com/llvm/llvm-project.git
```

(If you want to build LLVM 12.x, use branch `release/12.x`; for current trunk,
(If you want to build LLVM 13.x, use branch `release/13.x`; for current trunk,
use `main`)

Then build it like so:
Expand Down Expand Up @@ -285,7 +285,7 @@ Subsets of the tests can be selected with `-L` and include `correctness`,
#### Building LLVM (optional)

Follow these steps if you want to build LLVM yourself. First, download LLVM's
sources (these instructions use the latest 12.0 release)
sources (these instructions use the latest 13.0 release)

```
D:\> git clone --depth 1 --branch llvmorg-13.0.0 https://github.com/llvm/llvm-project.git
Expand Down
4 changes: 2 additions & 2 deletions dependencies/llvm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
message(STATUS "Using ClangConfig.cmake in: ${Clang_DIR}")

if (LLVM_PACKAGE_VERSION VERSION_LESS 12.0)
message(FATAL_ERROR "LLVM version must be 12.0 or newer")
if (LLVM_PACKAGE_VERSION VERSION_LESS 13.0)
message(FATAL_ERROR "LLVM version must be 13.0 or newer")
endif ()

if (LLVM_PACKAGE_VERSION VERSION_GREATER 15.0)
Expand Down
4 changes: 2 additions & 2 deletions packaging/ubuntu/config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ set(CPACK_DEBIAN_HALIDE_DOCUMENTATION_PACKAGE_ARCHITECTURE all)

# Package dependencies.
# TODO: figure out how to get LLVM major version piped in here.
set(CPACK_DEBIAN_HALIDE_RUNTIME_PACKAGE_DEPENDS "llvm-12 (>= 12.0.0)")
set(CPACK_DEBIAN_HALIDE_DEVELOPMENT_PACKAGE_DEPENDS "llvm-12-dev (>= 12.0.0), liblld-12-dev (>= 12.0.0)")
set(CPACK_DEBIAN_HALIDE_RUNTIME_PACKAGE_DEPENDS "llvm-13 (>= 13.0.0)")
set(CPACK_DEBIAN_HALIDE_DEVELOPMENT_PACKAGE_DEPENDS "llvm-13-dev (>= 13.0.0), liblld-13-dev (>= 13.0.0)")
set(CPACK_DEBIAN_HALIDE_DOCUMENTATION_PACKAGE_DEPENDS "")

# Sets up package dependencies based on CPack component dependencies
Expand Down
12 changes: 6 additions & 6 deletions run-clang-tidy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ FIX=$1
# are using to build Halide itself. If you don't have LLVM12 installed,
# you can usually install what you need easily via:
#
# sudo apt-get install llvm-12 clang-12 libclang-12-dev clang-tidy-12
# export CLANG_TIDY_LLVM_INSTALL_DIR=/usr/lib/llvm-12
# sudo apt-get install llvm-13 clang-13 libclang-13-dev clang-tidy-13
# export CLANG_TIDY_LLVM_INSTALL_DIR=/usr/lib/llvm-13

[ -z "$CLANG_TIDY_LLVM_INSTALL_DIR" ] && echo "CLANG_TIDY_LLVM_INSTALL_DIR must point to an LLVM installation dir for this script." && exit
echo CLANG_TIDY_LLVM_INSTALL_DIR = ${CLANG_TIDY_LLVM_INSTALL_DIR}

VERSION=$(${CLANG_TIDY_LLVM_INSTALL_DIR}/bin/clang-tidy --version)
if [[ ${VERSION} =~ .*version\ 12.* ]]
if [[ ${VERSION} =~ .*version\ 13.* ]]
then
echo "clang-tidy version 12 found."
echo "clang-tidy version 13 found."
else
echo "CLANG_TIDY_LLVM_INSTALL_DIR must point to an LLVM 12 install!"
echo "CLANG_TIDY_LLVM_INSTALL_DIR must point to an LLVM 13 install!"
exit 1
fi

Expand All @@ -49,7 +49,7 @@ cmake -DCMAKE_BUILD_TYPE=Debug \
# We must populate the includes directory to check things outside of src/
cmake --build ${CLANG_TIDY_BUILD_DIR} --target HalideIncludes

RUN_CLANG_TIDY=${CLANG_TIDY_LLVM_INSTALL_DIR}/share/clang/run-clang-tidy.py
RUN_CLANG_TIDY=${CLANG_TIDY_LLVM_INSTALL_DIR}/bin/run-clang-tidy

# We deliberately skip apps/ and test/ for now, as the compile commands won't include
# generated headers files from Generators.
Expand Down
9 changes: 0 additions & 9 deletions src/CodeGen_Internal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -611,11 +611,6 @@ void get_target_options(const llvm::Module &module, llvm::TargetOptions &options
options.HonorSignDependentRoundingFPMathOption = !per_instruction_fast_math_flags;
options.NoZerosInBSS = false;
options.GuaranteedTailCallOpt = false;
#if LLVM_VERSION >= 130
// nothing
#else
options.StackAlignmentOverride = 0;
#endif
options.FunctionSections = true;
options.UseInitArray = true;
options.FloatABIType =
Expand Down Expand Up @@ -690,11 +685,7 @@ void set_function_attributes_for_target(llvm::Function *fn, const Target &t) {
void embed_bitcode(llvm::Module *M, const string &halide_command) {
// Save llvm.compiler.used and remote it.
SmallVector<Constant *, 2> used_array;
#if LLVM_VERSION >= 130
SmallVector<GlobalValue *, 4> used_globals;
#else
SmallPtrSet<GlobalValue *, 4> used_globals;
#endif
llvm::Type *used_element_type = llvm::Type::getInt8Ty(M->getContext())->getPointerTo(0);
GlobalVariable *used = collectUsedGlobalVariables(*M, used_globals, true);
for (auto *GV : used_globals) {
Expand Down
56 changes: 0 additions & 56 deletions src/CodeGen_LLVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,21 +147,12 @@ namespace {

llvm::Value *CreateConstGEP1_32(IRBuilderBase *builder, llvm::Type *gep_type,
Value *ptr, unsigned index) {
#if LLVM_VERSION >= 130
return builder->CreateConstGEP1_32(gep_type, ptr, index);
#else
(void)gep_type;
return builder->CreateConstGEP1_32(ptr, index);
#endif
}

llvm::Value *CreateInBoundsGEP(IRBuilderBase *builder, llvm::Type *gep_type,
Value *ptr, ArrayRef<Value *> index_list) {
#if LLVM_VERSION >= 130
return builder->CreateInBoundsGEP(gep_type, ptr, index_list);
#else
return builder->CreateInBoundsGEP(ptr, index_list);
#endif
}

// Get the LLVM linkage corresponding to a Halide linkage type.
Expand Down Expand Up @@ -1126,25 +1117,14 @@ void CodeGen_LLVM::optimize_module() {
// 21.04 -> 14.78 using current ToT release build. (See also https://reviews.llvm.org/rL358304)
pto.ForgetAllSCEVInLoopUnroll = true;

#if LLVM_VERSION >= 130
llvm::PassBuilder pb(tm.get(), pto);
#else
llvm::PassBuilder pb(/*DebugLogging*/ false, tm.get(), pto);
#endif

bool debug_pass_manager = false;
// These analysis managers have to be declared in this order.
#if LLVM_VERSION >= 130
llvm::LoopAnalysisManager lam;
llvm::FunctionAnalysisManager fam;
llvm::CGSCCAnalysisManager cgam;
llvm::ModuleAnalysisManager mam;
#else
llvm::LoopAnalysisManager lam(debug_pass_manager);
llvm::FunctionAnalysisManager fam(debug_pass_manager);
llvm::CGSCCAnalysisManager cgam(debug_pass_manager);
llvm::ModuleAnalysisManager mam(debug_pass_manager);
#endif

llvm::AAManager aa = pb.buildDefaultAAPipeline();
fam.registerPass([&] { return std::move(aa); });
Expand All @@ -1155,11 +1135,7 @@ void CodeGen_LLVM::optimize_module() {
pb.registerFunctionAnalyses(fam);
pb.registerLoopAnalyses(lam);
pb.crossRegisterProxies(lam, fam, cgam, mam);
#if LLVM_VERSION >= 130
ModulePassManager mpm;
#else
ModulePassManager mpm(debug_pass_manager);
#endif

#if LLVM_VERSION >= 140
using OptimizationLevel = llvm::OptimizationLevel;
Expand Down Expand Up @@ -1246,15 +1222,9 @@ void CodeGen_LLVM::optimize_module() {
}
}

#if LLVM_VERSION >= 130
if (tm) {
tm->registerPassBuilderCallbacks(pb);
}
#else
if (tm) {
tm->registerPassBuilderCallbacks(pb, debug_pass_manager);
}
#endif

mpm = pb.buildPerModuleDefaultPipeline(level, debug_pass_manager);
mpm.run(*module, mam);
Expand Down Expand Up @@ -2376,11 +2346,7 @@ llvm::Value *CodeGen_LLVM::codegen_dense_vector_load(const Type &type, const std
Instruction *load_inst;
if (vpred != nullptr) {
Value *slice_mask = slice_vector(vpred, i, slice_lanes);
#if LLVM_VERSION >= 130
load_inst = builder->CreateMaskedLoad(slice_type, vec_ptr, llvm::Align(align_bytes), slice_mask);
#else
load_inst = builder->CreateMaskedLoad(vec_ptr, llvm::Align(align_bytes), slice_mask);
#endif
} else {
load_inst = builder->CreateAlignedLoad(slice_type, vec_ptr, llvm::Align(align_bytes));
}
Expand Down Expand Up @@ -2467,20 +2433,11 @@ void CodeGen_LLVM::codegen_atomic_rmw(const Store *op) {
Value *ptr = codegen_buffer_pointer(op->name,
op->value.type(),
op->index);
#if LLVM_VERSION >= 130
if (value_type.is_float()) {
builder->CreateAtomicRMW(AtomicRMWInst::FAdd, ptr, val, llvm::MaybeAlign(), AtomicOrdering::Monotonic);
} else {
builder->CreateAtomicRMW(AtomicRMWInst::Add, ptr, val, llvm::MaybeAlign(), AtomicOrdering::Monotonic);
}
#else
// llvm 9 has FAdd which can be used for atomic floats.
if (value_type.is_float()) {
builder->CreateAtomicRMW(AtomicRMWInst::FAdd, ptr, val, AtomicOrdering::Monotonic);
} else {
builder->CreateAtomicRMW(AtomicRMWInst::Add, ptr, val, AtomicOrdering::Monotonic);
}
#endif
} else {
Value *index = codegen(op->index);
// Scalarize vector store.
Expand All @@ -2489,19 +2446,11 @@ void CodeGen_LLVM::codegen_atomic_rmw(const Store *op) {
Value *idx = builder->CreateExtractElement(index, lane);
Value *v = builder->CreateExtractElement(val, lane);
Value *ptr = codegen_buffer_pointer(op->name, value_type.element_of(), idx);
#if LLVM_VERSION >= 130
if (value_type.is_float()) {
builder->CreateAtomicRMW(AtomicRMWInst::FAdd, ptr, v, llvm::MaybeAlign(), AtomicOrdering::Monotonic);
} else {
builder->CreateAtomicRMW(AtomicRMWInst::Add, ptr, v, llvm::MaybeAlign(), AtomicOrdering::Monotonic);
}
#else
if (value_type.is_float()) {
builder->CreateAtomicRMW(AtomicRMWInst::FAdd, ptr, v, AtomicOrdering::Monotonic);
} else {
builder->CreateAtomicRMW(AtomicRMWInst::Add, ptr, v, AtomicOrdering::Monotonic);
}
#endif
}
}
} else {
Expand Down Expand Up @@ -2564,13 +2513,8 @@ void CodeGen_LLVM::codegen_atomic_rmw(const Store *op) {
val = builder->CreateBitCast(val, int_type);
cmp_val = builder->CreateBitCast(cmp_val, int_type);
}
#if LLVM_VERSION >= 130
Value *cmpxchg_pair = builder->CreateAtomicCmpXchg(
ptr, cmp_val, val, llvm::MaybeAlign(), AtomicOrdering::Monotonic, AtomicOrdering::Monotonic);
#else
Value *cmpxchg_pair = builder->CreateAtomicCmpXchg(
ptr, cmp_val, val, AtomicOrdering::Monotonic, AtomicOrdering::Monotonic);
#endif
Value *val_loaded = builder->CreateExtractValue(cmpxchg_pair, 0, "val_loaded");
Value *success = builder->CreateExtractValue(cmpxchg_pair, 1, "success");
if (need_bit_cast) {
Expand Down
6 changes: 0 additions & 6 deletions src/CodeGen_PTX_Dev.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,6 @@ string CodeGen_PTX_Dev::march() const {

string CodeGen_PTX_Dev::mcpu() const {
if (target.has_feature(Target::CUDACapability86)) {
user_assert(LLVM_VERSION >= 130) << "The linked LLVM version does not support cuda compute capability 8.6\n";
return "sm_86";
} else if (target.has_feature(Target::CUDACapability80)) {
return "sm_80";
Expand Down Expand Up @@ -615,11 +614,6 @@ vector<char> CodeGen_PTX_Dev::compile_to_src() {
options.HonorSignDependentRoundingFPMathOption = false;
options.NoZerosInBSS = false;
options.GuaranteedTailCallOpt = false;
#if LLVM_VERSION >= 130
// nothing
#else
options.StackAlignmentOverride = 0;
#endif

std::unique_ptr<TargetMachine>
target_machine(llvm_target->createTargetMachine(triple.str(),
Expand Down
Loading