Skip to content

Commit

Permalink
LLVM 17 support
Browse files Browse the repository at this point in the history
automatic-locals pass: fix to read strategy from Module
add dump to IsolateRegions
fix name conflict of pocl's VUA pass ("uniformity")
IsolateRegions.cc: fix iterating over Regions
implement a print-pocl-cfg pass
fix CallingConv -> unreachable bug
linker.cpp: add extra check for CallingConv
  • Loading branch information
franz committed Nov 23, 2023
1 parent a421006 commit b165b29
Show file tree
Hide file tree
Showing 77 changed files with 4,410 additions and 2,341 deletions.
3 changes: 3 additions & 0 deletions config.h.in.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@

#cmakedefine LLVM_MAJOR @LLVM_VERSION_MAJOR@

// minimum LLVM version at which to enable new PM
#define MIN_LLVM_NEW_PASSMANAGER 15

#cmakedefine LLVM_BUILD_MODE_DEBUG

#ifndef LLVM_VERSION
Expand Down
12 changes: 12 additions & 0 deletions include/pocl.h
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,18 @@ struct _cl_command_node
char *readonly_flag_list;
};

/**
* Enumeration for different modes of converting automatic locals
*/
typedef enum
{
POCL_AUTOLOCALS_TO_ARGS_NEVER = 0,
POCL_AUTOLOCALS_TO_ARGS_ALWAYS = 1,
// convert autolocals to args only if there are dynamic local memory function
// arguments in the kernel.
POCL_AUTOLOCALS_TO_ARGS_ONLY_IF_DYNAMIC_LOCALS_PRESENT = 2,
} pocl_autolocals_to_args_strategy;

#define CLANG_MAJOR LLVM_MAJOR
#include "_libclang_versions_checks.h"

Expand Down
51 changes: 21 additions & 30 deletions lib/CL/devices/cuda/pocl-ptx-gen.cc
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
/* pocl-ptx-gen.cc - PTX code generation functions
Copyright (c) 2016-2017 James Price / University of Bristol
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
Copyright (c) 2016-2017 James Price / University of Bristol
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to
deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
*/

#include "config.h"
Expand All @@ -37,7 +37,6 @@
#include "llvm/IR/Function.h"
#include "llvm/IR/InstIterator.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/LegacyPassManager.h"
#include "llvm/IR/Metadata.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Verifier.h"
Expand All @@ -56,15 +55,11 @@
#include "llvm/Target/TargetMachine.h"
#include "llvm/Target/TargetOptions.h"
#include "llvm/Transforms/IPO.h"
#include "llvm/Transforms/IPO/PassManagerBuilder.h"
#include "llvm/Transforms/Utils/Cloning.h"

#include <llvm/PassInfo.h>
#include <llvm/PassRegistry.h>

#include <llvm/Analysis/TargetLibraryInfo.h>
#include <llvm/Analysis/TargetTransformInfo.h>
#include <llvm/IR/LegacyPassManager.h>

#include <set>
#include <optional>
Expand Down Expand Up @@ -708,7 +703,7 @@ int linkLibDevice(llvm::Module *Module, const char *LibDevicePath) {
return -1;
}

llvm::legacy::PassManager Passes;
// llvm::legacy::PassManager Passes;

// Run internalize to mark all non-kernel functions as internal.
auto PreserveKernel = [=](const llvm::GlobalValue &GV) {
Expand All @@ -731,12 +726,8 @@ int linkLibDevice(llvm::Module *Module, const char *LibDevicePath) {
Module->addModuleFlag(ReflectFlag);

// Run optimization passes to clean up unused functions etc.
llvm::PassManagerBuilder Builder;
Builder.OptLevel = 3;
Builder.SizeLevel = 0;
Builder.populateModulePassManager(Passes);
populateModulePM(Passes, Module, 3, 0);

Passes.run(*Module);
return 0;
}

Expand Down
12 changes: 0 additions & 12 deletions lib/CL/pocl_cl.h
Original file line number Diff line number Diff line change
Expand Up @@ -803,18 +803,6 @@ typedef struct pocl_global_mem_t {
cl_ulong total_alloc_limit;
} pocl_global_mem_t;

/**
* Enumeration for different modes of converting automatic locals
*/
typedef enum
{
POCL_AUTOLOCALS_TO_ARGS_NEVER = 0,
POCL_AUTOLOCALS_TO_ARGS_ALWAYS = 1,
// convert autolocals to args only if there are dynamic local memory function
// arguments in the kernel.
POCL_AUTOLOCALS_TO_ARGS_ONLY_IF_DYNAMIC_LOCALS_PRESENT = 2,
} pocl_autolocals_to_args_strategy;

#define NUM_OPENCL_IMAGE_TYPES 6

struct _cl_device_id {
Expand Down
3 changes: 3 additions & 0 deletions lib/CL/pocl_llvm_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ POCL_EXPORT bool getModuleBoolMetadata (const llvm::Module &mod,
void clearKernelPasses();
void clearTargetMachines();

POCL_EXPORT void populateModulePM (void *Passes, void *Module, unsigned OptL,
unsigned SizeL, bool Vectorize = true);

extern std::string CurrentWgMethod;

extern const char *PoclGVarPrefix;
Expand Down
5 changes: 3 additions & 2 deletions lib/CL/pocl_llvm_build.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ IGNORE_COMPILER_WARNING("-Wstrict-aliasing")
#include <llvm/IR/Module.h>
#include <llvm/IR/Verifier.h>


#ifndef LLVM_OLDER_THAN_11_0
#if LLVM_VERSION_MAJOR > 15
#include "llvm/TargetParser/Host.h"
#elif LLVM_VERSION_MAJOR > 10
#include "llvm/Support/Host.h"
#endif

Expand Down
49 changes: 29 additions & 20 deletions lib/CL/pocl_llvm_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,48 +22,57 @@
THE SOFTWARE.
*/

#include "config.h"
#include "pocl_debug.h"
#include "pocl_file_util.h"
#include "pocl_llvm.h"
#include "pocl_llvm_api.h"
#include "pocl_runtime_config.h"
#include <unistd.h>

#include "CompilerWarnings.h"
IGNORE_COMPILER_WARNING("-Wunused-parameter")

IGNORE_COMPILER_WARNING("-Wmaybe-uninitialized")
#include <llvm/ADT/StringRef.h>
#include <llvm/ADT/StringMap.h>
#if LLVM_VERSION_MAJOR < 16
#include <llvm/ADT/Triple.h>
#else
#include <llvm/TargetParser/Triple.h>
#endif
POP_COMPILER_DIAGS
IGNORE_COMPILER_WARNING("-Wunused-parameter")

#include <llvm/Support/Host.h>
#include <llvm/Support/TargetSelect.h>
#include <llvm/Support/SourceMgr.h>
#include <llvm/Support/Signals.h>

#include <llvm/IR/Constants.h>
#include <llvm/IR/DiagnosticInfo.h>
#include <llvm/IR/DiagnosticPrinter.h>
#include <llvm/IR/LLVMContext.h>
#include <llvm/IR/Module.h>

#include <llvm/Target/TargetMachine.h>

#include <llvm/IRReader/IRReader.h>

#include <llvm/Bitcode/BitcodeReader.h>
#include <llvm/Bitcode/BitcodeWriter.h>

#include <llvm/Support/raw_os_ostream.h>
#include <llvm/PassRegistry.h>

#include <llvm/IR/LegacyPassManager.h>
#define PassManager legacy::PassManager

#include <llvm/InitializePasses.h>
#include <llvm/Support/CommandLine.h>
#include <llvm-c/Core.h>

#if LLVM_VERSION_MAJOR < 16
#include <llvm/IR/LegacyPassManager.h>
#include <llvm/PassInfo.h>
#include <llvm/PassRegistry.h>
#include <llvm/Support/Host.h>
#else
#include <llvm/Analysis/CGSCCPassManager.h>
#include <llvm/Analysis/LoopAnalysisManager.h>
#include <llvm/Passes/PassBuilder.h>
#include <llvm/TargetParser/Host.h>
#endif

#include "config.h"
#include "pocl_debug.h"
#include "pocl_file_util.h"
#include "pocl_llvm.h"
#include "pocl_llvm_api.h"
#include "pocl_runtime_config.h"

#include <unistd.h>

using namespace llvm;

#include <string>
Expand Down

0 comments on commit b165b29

Please sign in to comment.