Skip to content

Commit a4e7364

Browse files
authored
make it build with llvm 22 (#240)
1 parent 83f1bea commit a4e7364

6 files changed

Lines changed: 39 additions & 31 deletions

File tree

‎.github/workflows/main.yml‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,19 @@ jobs:
3232
run: |
3333
wget https://apt.llvm.org/llvm.sh
3434
chmod +x llvm.sh
35-
sudo ./llvm.sh 20 all
36-
sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-20 160
37-
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-20 160
38-
sudo update-alternatives --install /usr/bin/lli lli /usr/bin/lli-20 160
39-
sudo update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-20 160
35+
sudo ./llvm.sh 22 all
36+
sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-22 160
37+
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-22 160
38+
sudo update-alternatives --install /usr/bin/lli lli /usr/bin/lli-22 160
39+
sudo update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-22 160
4040
4141
- name: Setup LLVM and GCC (MacOS)
4242
if: ${{ runner.os == 'macOS' }}
4343
run: |
44-
brew install llvm@20 gcc@14
45-
echo "$(brew --prefix llvm@20)/bin" >> $GITHUB_PATH
46-
echo "CC=$(brew --prefix llvm@20)/bin/clang" >> $GITHUB_ENV
47-
echo "CXX=$(brew --prefix llvm@20)/bin/clang++" >> $GITHUB_ENV
44+
brew install llvm@22 gcc@14
45+
echo "$(brew --prefix llvm@22)/bin" >> $GITHUB_PATH
46+
echo "CC=$(brew --prefix llvm@22)/bin/clang" >> $GITHUB_ENV
47+
echo "CXX=$(brew --prefix llvm@22)/bin/clang++" >> $GITHUB_ENV
4848
cd /usr/local/bin
4949
ln -s `which gcc-14` gcc
5050
@@ -65,7 +65,7 @@ jobs:
6565
- name: Build
6666
run: |
6767
mkdir build
68-
cmake -S . -B build -DLLVM_INCLUDE_TESTS=On -DLLVM_DIR=/usr/lib/llvm-20/cmake
68+
cmake -S . -B build -DLLVM_INCLUDE_TESTS=On -DLLVM_DIR=/usr/lib/llvm-22/cmake
6969
cmake --build build
7070
7171
- name: Test
@@ -84,7 +84,7 @@ jobs:
8484
uses: actions/checkout@master
8585
with:
8686
repository: llvm/llvm-project
87-
ref: llvmorg-20.1.8
87+
ref: llvmorg-22.1.8
8888

8989
- name: Checkout
9090
uses: actions/checkout@v7

‎CMakeLists.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ if (NOT DEFINED LLVM_VERSION_MAJOR)
22
project(llvm-cbe)
33
set (USE_SYSTEM_LLVM 1)
44
cmake_minimum_required(VERSION 3.20.0)
5-
find_package(LLVM 20.1 REQUIRED CONFIG)
5+
find_package(LLVM 22.1 REQUIRED CONFIG)
66
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
77
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
88
message(STATUS "LLVM_INCLUDE_DIRS: ${LLVM_INCLUDE_DIRS}")

‎README.md‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ This LLVM C backend has been resurrected by Julia Computing with various improve
66
Installation instructions
77
=========================
88

9-
This version of the LLVM C backend works with LLVM 20, for older versions please check the [tags](https://github.com/JuliaHubOSS/llvm-cbe/tags).
9+
This version of the LLVM C backend works with LLVM 22, for older versions please check the [tags](https://github.com/JuliaHubOSS/llvm-cbe/tags).
1010

1111
Step 1: Installing LLVM
1212
=======================
@@ -26,10 +26,10 @@ On CentOS, install the llvm-devel package:
2626

2727
On Debian and derivatives, install the llvm-dev package via:
2828
```sh
29-
~$ apt install llvm-20-dev clang-20 ninja-build
29+
~$ apt install llvm-22-dev clang-22 ninja-build
3030
```
3131

32-
Note: this project uses LLVM 20, so make sure that the package manager is installing it and not some other version. At the time of writing, [`Ubuntu 24.04 LTS` installs version 18](https://launchpad.net/ubuntu/noble/+package/llvm-dev).
32+
Note: this project uses LLVM 22, so make sure that the package manager is installing it and not some other version. At the time of writing, [`Ubuntu 24.04 LTS` installs version 18](https://launchpad.net/ubuntu/noble/+package/llvm-dev).
3333

3434
Or compile LLVM yourself:
3535
-----------------------------
@@ -39,7 +39,7 @@ The first step is to compile LLVM on your machine
3939
(this assumes an in-tree build, but out-of-tree will also work):
4040

4141
```sh
42-
~$ git clone --single-branch --branch llvmorg-20.1.8 --depth 1 https://github.com/llvm/llvm-project.git
42+
~$ git clone --single-branch --branch llvmorg-22.1.8 --depth 1 https://github.com/llvm/llvm-project.git
4343
~$ cd llvm-project
4444
llvm-project$ mkdir llvm/build
4545
llvm-project$ cd llvm/build
@@ -77,7 +77,7 @@ If llvm-cbe compiles, you should be able to run it with the following commands.
7777
llvm-cbe$ cd test/selectionsort
7878
selectionsort$ ls
7979
main.c
80-
selectionsort$ clang-20 -S -emit-llvm -g main.c
80+
selectionsort$ clang-22 -S -emit-llvm -g main.c
8181
selectionsort$ ls
8282
main.c main.ll
8383
selectionsort$ ../../build/tools/llvm-cbe/llvm-cbe main.ll

‎lib/Target/CBackend/CBackend.cpp‎

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2664,10 +2664,10 @@ void CWriter::generateHeader(Module &M) {
26642664
Out << " __HIDDEN__";
26652665
}
26662666

2667-
unsigned Alignment = I->getAlignment();
2668-
if (Alignment != 0) {
2667+
MaybeAlign Alignment = I->getAlign();
2668+
if (Alignment) {
26692669
headerUseFunctionAlign();
2670-
Out << " __FUNCTIONALIGN__(" << Alignment << ") ";
2670+
Out << " __FUNCTIONALIGN__(" << Alignment->value() << ") ";
26712671
}
26722672

26732673
if (I->hasName() && I->getName()[0] == 1)
@@ -2704,9 +2704,13 @@ void CWriter::generateHeader(Module &M) {
27042704
Out << "__thread ";
27052705

27062706
Type *ElTy = I->getValueType();
2707-
unsigned Alignment = I->getAliaseeObject()->getAlignment();
2708-
bool IsOveraligned =
2709-
Alignment && Alignment > TD->getABITypeAlign(ElTy).value();
2707+
GlobalObject *Aliasee = I->getAliaseeObject();
2708+
MaybeAlign AliaseeAlign = isa<Function>(Aliasee)
2709+
? cast<Function>(Aliasee)->getAlign()
2710+
: cast<GlobalVariable>(Aliasee)->getAlign();
2711+
unsigned Alignment = AliaseeAlign ? AliaseeAlign->value() : 0;
2712+
bool IsOveraligned = !ElTy->isFunctionTy() && Alignment &&
2713+
Alignment > TD->getABITypeAlign(ElTy).value();
27102714
if (IsOveraligned) {
27112715
headerUseAligns();
27122716
Out << "__PREFIXALIGN__(" << Alignment << ") ";
@@ -5338,7 +5342,8 @@ void CWriter::visitInlineAsm(CallInst &CI) {
53385342
}
53395343

53405344
// Fix up the asm string for gcc and emit it.
5341-
Out << "__asm__ volatile (\"" << gccifyAsm(as->getAsmString()) << "\"\n";
5345+
Out << "__asm__ volatile (\"" << gccifyAsm(as->getAsmString().str())
5346+
<< "\"\n";
53425347
Out << " :";
53435348

53445349
unsigned ValueCount = 0;

‎lib/Target/CBackend/CTargetMachine.h‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ namespace llvm {
2323

2424
class CTargetLowering : public TargetLowering {
2525
public:
26-
explicit CTargetLowering(const TargetMachine &TM) : TargetLowering(TM) {
26+
CTargetLowering(const TargetMachine &TM, const TargetSubtargetInfo &STI)
27+
: TargetLowering(TM, STI) {
2728
setMaxAtomicSizeInBitsSupported(0);
2829
}
2930
};
@@ -36,8 +37,9 @@ class CTargetSubtargetInfo : public TargetSubtargetInfo {
3637
ArrayRef<SubtargetFeatureKV>(),
3738
ArrayRef<SubtargetSubTypeKV>(), nullptr, nullptr,
3839
nullptr, nullptr, nullptr, nullptr),
39-
Lowering(TM) {}
40+
Lowering(TM, *this) {}
4041
bool enableAtomicExpand() const override;
42+
const TargetRegisterInfo *getRegisterInfo() const override { return nullptr; }
4143
const TargetLowering *getTargetLowering() const override;
4244
const CTargetLowering Lowering;
4345
};

‎tools/llvm-cbe/llvm-cbe.cpp‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ static int compileModule(char **argv, LLVMContext &Context) {
230230

231231
// If we are supposed to override the target triple, do so now.
232232
if (!TargetTriple.empty())
233-
mod->setTargetTriple(Triple::normalize(TargetTriple));
233+
mod->setTargetTriple(Triple(Triple::normalize(TargetTriple)));
234234
TheTriple = Triple(mod->getTargetTriple());
235235
} else {
236236
TheTriple = Triple(Triple::normalize(TargetTriple));
@@ -284,9 +284,10 @@ static int compileModule(char **argv, LLVMContext &Context) {
284284

285285
TargetOptions Options;
286286
Options.AllowFPOpFusion = codegen::getFuseFPOps();
287-
Options.UnsafeFPMath = codegen::getEnableUnsafeFPMath();
288287
Options.NoInfsFPMath = codegen::getEnableNoInfsFPMath();
289288
Options.NoNaNsFPMath = codegen::getEnableNoNaNsFPMath();
289+
Options.NoSignedZerosFPMath = codegen::getEnableNoSignedZerosFPMath();
290+
Options.NoTrappingFPMath = codegen::getEnableNoTrappingFPMath();
290291
Options.HonorSignDependentRoundingFPMathOption =
291292
codegen::getEnableHonorSignDependentRoundingFPMath();
292293
if (codegen::getFloatABIForCalls() != FloatABI::Default)
@@ -296,9 +297,9 @@ static int compileModule(char **argv, LLVMContext &Context) {
296297

297298
// Jackson Korba 9/30/14
298299
// OwningPtr<targetMachine>
299-
std::unique_ptr<TargetMachine> target(TheTarget->createTargetMachine(
300-
TheTriple.getTriple(), codegen::getMCPU(), FeaturesStr, Options,
301-
llvm::codegen::getRelocModel()));
300+
std::unique_ptr<TargetMachine> target(
301+
TheTarget->createTargetMachine(TheTriple, codegen::getMCPU(), FeaturesStr,
302+
Options, llvm::codegen::getRelocModel()));
302303
assert(target.get() && "Could not allocate target machine!");
303304
assert(mod && "Should have exited after outputting help!");
304305
TargetMachine &Target = *target.get();

0 commit comments

Comments
 (0)