Skip to content

Commit

Permalink
Update wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
lerno committed Jul 24, 2024
1 parent abdaca0 commit 34fc985
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 19 deletions.
34 changes: 22 additions & 12 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ jobs:
fail-fast: false
matrix:
build_type: [Release, Debug]
llvm_version: [15, 16, 17, 18, 19]
llvm_version: [17, 18, 19]

steps:
- uses: actions/checkout@v4
Expand All @@ -220,9 +220,6 @@ jobs:
- name: Install Clang ${{matrix.llvm_version}}
run: |
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
if [[ "${{matrix.llvm_version}}" < 16 ]]; then
sudo apt remove libllvm15
fi
if [[ "${{matrix.llvm_version}}" < 18 ]]; then
sudo add-apt-repository "deb http://apt.llvm.org/focal/ llvm-toolchain-focal-${{matrix.llvm_version}} main"
sudo apt-get update
Expand Down Expand Up @@ -349,8 +346,7 @@ jobs:
fail-fast: false
matrix:
build_type: [Release, Debug]
llvm_version: [16]

llvm_version: [17, 18]
steps:
- uses: actions/checkout@v4
- name: Install common deps
Expand All @@ -360,7 +356,7 @@ jobs:
- name: Install Clang ${{matrix.llvm_version}}
run: |
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
if [[ "${{matrix.llvm_version}}" < 17 ]]; then
if [[ "${{matrix.llvm_version}}" < 19 ]]; then
sudo add-apt-repository "deb http://apt.llvm.org/focal/ llvm-toolchain-focal-${{matrix.llvm_version}} main"
else
sudo add-apt-repository "deb http://apt.llvm.org/focal/ llvm-toolchain-focal main"
Expand All @@ -369,7 +365,22 @@ jobs:
sudo apt-get install -y clang-${{matrix.llvm_version}} llvm-${{matrix.llvm_version}} llvm-${{matrix.llvm_version}}-dev lld-${{matrix.llvm_version}} liblld-${{matrix.llvm_version}}-dev
sudo apt-get install -y libmlir-${{matrix.llvm_version}} libmlir-${{matrix.llvm_version}}-dev mlir-${{matrix.llvm_version}}-tools
sudo apt-get install -y libpolly-${{matrix.llvm_version}}-dev
- name: CMake Old
if: matrix.llvm_version < 18
run: |
cmake -B build \
-G Ninja \
-DCMAKE_BUILD_TYPE=${{matrix.build_type}} \
-DCMAKE_C_COMPILER=clang-${{matrix.llvm_version}} \
-DCMAKE_CXX_COMPILER=clang++-${{matrix.llvm_version}} \
-DCMAKE_LINKER=lld-link-${{matrix.llvm_version}} \
-DCMAKE_OBJCOPY=llvm-objcopy-${{matrix.llvm_version}} \
-DCMAKE_STRIP=llvm-strip-${{matrix.llvm_version}} \
-DCMAKE_DLLTOOL=llvm-dlltool-${{matrix.llvm_version}} \
-DC3_LLVM_VERSION=${{matrix.llvm_version}}
cmake --build build
- name: CMake
if: matrix.llvm_version >= 18
run: |
cmake -B build \
-G Ninja \
Expand All @@ -380,9 +391,8 @@ jobs:
-DCMAKE_OBJCOPY=llvm-objcopy-${{matrix.llvm_version}} \
-DCMAKE_STRIP=llvm-strip-${{matrix.llvm_version}} \
-DCMAKE_DLLTOOL=llvm-dlltool-${{matrix.llvm_version}} \
-DC3_LLVM_VERSION=${{matrix.llvm_version}}
-DC3_LLVM_VERSION=${{matrix.llvm_version}}.1
cmake --build build
- name: Compile and run some examples
run: |
cd resources
Expand Down Expand Up @@ -434,7 +444,7 @@ jobs:
python3 src/tester.py ../build/c3c test_suite/
- name: bundle_output
if: matrix.llvm_version == 16
if: matrix.llvm_version == 17
run: |
mkdir linux
cp -r lib linux
Expand All @@ -443,7 +453,7 @@ jobs:
tar czf c3-ubuntu-20-${{matrix.build_type}}.tar.gz linux
- name: upload artifacts
if: matrix.llvm_version == 16
if: matrix.llvm_version == 17
uses: actions/upload-artifact@v3
with:
name: c3-ubuntu-20-${{matrix.build_type}}
Expand All @@ -456,7 +466,7 @@ jobs:
fail-fast: false
matrix:
build_type: [Release, Debug]
llvm_version: [15, 16, 17, 18]
llvm_version: [17, 18]
steps:
- uses: actions/checkout@v4
- name: Download LLVM
Expand Down
17 changes: 10 additions & 7 deletions wrapper/src/wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#include "llvm-c/TargetMachine.h"
#include "llvm-c/Target.h"
#include "llvm/IR/Verifier.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Function.h"
#include "llvm/Passes/PassBuilder.h"
#include "llvm/Passes/StandardInstrumentations.h"
#include "llvm/Support/CBindingWrapping.h"
Expand All @@ -25,8 +27,8 @@
#include "llvm/Transforms/Scalar/GVN.h"
#include "llvm/Transforms/Scalar/JumpThreading.h"
#include "llvm/Transforms/InstCombine/InstCombine.h"
#include "llvm/TargetParser/Triple.h"
#include "llvm/Analysis/GlobalsModRef.h"
static_assert(LLVM_VERSION_MAJOR >= 17, "Unsupported LLVM version, 17+ is needed.");

#define LINK_SIG \
bool link(llvm::ArrayRef<const char *> args, llvm::raw_ostream &stdoutOS, \
Expand Down Expand Up @@ -132,7 +134,7 @@ extern "C" {


bool llvm_run_passes(LLVMModuleRef m, LLVMTargetMachineRef tm,
LLVMPasses *passes)
LLVMPasses *passes)
{
llvm::TargetMachine *Machine = reinterpret_cast<llvm::TargetMachine *>(tm);
llvm::Module *Mod = llvm::unwrap(m);
Expand All @@ -144,8 +146,9 @@ bool llvm_run_passes(LLVMModuleRef m, LLVMTargetMachineRef tm,
PTO.SLPVectorization = passes->opt.slp_vectorize;
PTO.MergeFunctions = passes->opt.merge_functions;
PTO.CallGraphProfile = true; // We always use integrated ASM
#if LLVM_VERSION_MAJOR > 16
PTO.UnifiedLTO = false;

#endif
llvm::PassBuilder PB(Machine, PTO, std::nullopt, &PIC);

llvm::LoopAnalysisManager LAM;
Expand Down Expand Up @@ -197,9 +200,9 @@ bool llvm_run_passes(LLVMModuleRef m, LLVMTargetMachineRef tm,
if (passes->sanitizer.mem_sanitize)
{
llvm::MemorySanitizerOptions options(passes->sanitizer.mem_track_origins,
passes->sanitizer.recover,
passes->is_kernel,
passes->sanitizer.mem_retval);
passes->sanitizer.recover,
passes->is_kernel,
passes->sanitizer.mem_retval);

MPM.addPass(llvm::MemorySanitizerPass(options));
if (passes->opt_level != LLVM_O0)
Expand Down Expand Up @@ -236,7 +239,7 @@ bool llvm_run_passes(LLVMModuleRef m, LLVMTargetMachineRef tm,
use_globals_gc,
!is_windows,
passes->sanitizer.asan_use_global_dstor
? llvm::AsanDtorKind::Global
? llvm::AsanDtorKind::Global
: llvm::AsanDtorKind::None));
}
if (passes->sanitizer.hwaddress_sanitize)
Expand Down

0 comments on commit 34fc985

Please sign in to comment.