Skip to content

Commit 8c31246

Browse files
zlfnsohnryang
andauthored
Support LLVM-19 (#211)
Co-authored-by: sohnryang <loop.infinitely@gmail.com>
1 parent 5341f88 commit 8c31246

File tree

7 files changed

+36
-39
lines changed

7 files changed

+36
-39
lines changed

.github/workflows/main.yml

+11-11
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 17 all
36-
sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-17 160
37-
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-17 160
38-
sudo update-alternatives --install /usr/bin/lli lli /usr/bin/lli-17 160
39-
sudo update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-17 160
35+
sudo ./llvm.sh 19 all
36+
sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-19 160
37+
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-19 160
38+
sudo update-alternatives --install /usr/bin/lli lli /usr/bin/lli-19 160
39+
sudo update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-19 160
4040
4141
- name: Setup LLVM and GCC (MacOS)
4242
if: ${{ runner.os == 'macOS' }}
4343
run: |
44-
brew install llvm@17
45-
echo "$(brew --prefix llvm@17)/bin" >> $GITHUB_PATH
46-
echo "CC=$(brew --prefix llvm@17)/bin/clang" >> $GITHUB_ENV
47-
echo "CXX=$(brew --prefix llvm@17)/bin/clang++" >> $GITHUB_ENV
44+
brew install llvm@19
45+
echo "$(brew --prefix llvm@19)/bin" >> $GITHUB_PATH
46+
echo "CC=$(brew --prefix llvm@19)/bin/clang" >> $GITHUB_ENV
47+
echo "CXX=$(brew --prefix llvm@19)/bin/clang++" >> $GITHUB_ENV
4848
cd /usr/local/bin
4949
ln -s gcc-11 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-17/cmake
68+
cmake -S . -B build -DLLVM_INCLUDE_TESTS=On -DLLVM_DIR=/usr/lib/llvm-19/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-17.0.6
87+
ref: llvmorg-19.1.1
8888

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

CMakeLists.txt

+1-1
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.4.3)
5-
find_package(LLVM 17 REQUIRED CONFIG)
5+
find_package(LLVM 19 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

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ On Debian and derivatives, install the llvm-dev package via:
2929
~# apt install llvm-dev clang ninja-build
3030
```
3131

32-
Note: this project uses LLVM 17, so make sure that the package manager is installing it and not some other version. At the time of writing, Ubuntu installs version 14.
32+
Note: this project uses LLVM 19, so make sure that the package manager is installing it and not some other version. At the time of writing, Ubuntu installs version 14.
3333

3434
Or compile LLVM yourself:
3535
-----------------------------
@@ -41,7 +41,7 @@ The first step is to compile LLVM on your machine
4141
```sh
4242
~$ git clone https://github.com/llvm/llvm-project.git
4343
~$ cd llvm-project
44-
llvm-project$ git checkout release/17.x
44+
llvm-project$ git checkout tags/19.1.1
4545
llvm-project$ mkdir llvm/build
4646
llvm-project$ cd llvm/build
4747
build$ cmake .. -G "Ninja" -DCMAKE_BUILD_TYPE=Debug -DLLVM_PARALLEL_LINK_JOBS=1

lib/Target/CBackend/CBackend.cpp

+7-10
Original file line numberDiff line numberDiff line change
@@ -755,10 +755,10 @@ bool CWriter::isStandardMain(const FunctionType *FTy) {
755755
const Type *T = FTy->getContainedType(i);
756756
const StringRef CType = MainArgs.begin()[i].first;
757757

758-
if (CType.equals("int") && !T->isIntegerTy())
758+
if (CType == "int" && !T->isIntegerTy())
759759
return false;
760760

761-
if (CType.equals("char **") && !T->isPointerTy())
761+
if (CType == "char **" && !T->isPointerTy())
762762
return false;
763763
}
764764

@@ -1251,26 +1251,22 @@ void CWriter::printConstant(Constant *CPV, enum OperandContext Context) {
12511251
Out << " >> ";
12521252
break;
12531253
case Instruction::ICmp:
1254-
switch (CE->getPredicate()) {
1254+
switch ((dyn_cast<ICmpInst>(CE->getAsInstruction()))->getUnsignedPredicate()) {
12551255
case ICmpInst::ICMP_EQ:
12561256
Out << " == ";
12571257
break;
12581258
case ICmpInst::ICMP_NE:
12591259
Out << " != ";
12601260
break;
1261-
case ICmpInst::ICMP_SLT:
12621261
case ICmpInst::ICMP_ULT:
12631262
Out << " < ";
12641263
break;
1265-
case ICmpInst::ICMP_SLE:
12661264
case ICmpInst::ICMP_ULE:
12671265
Out << " <= ";
12681266
break;
1269-
case ICmpInst::ICMP_SGT:
12701267
case ICmpInst::ICMP_UGT:
12711268
Out << " > ";
12721269
break;
1273-
case ICmpInst::ICMP_SGE:
12741270
case ICmpInst::ICMP_UGE:
12751271
Out << " >= ";
12761272
break;
@@ -1290,12 +1286,13 @@ void CWriter::printConstant(Constant *CPV, enum OperandContext Context) {
12901286
case Instruction::FCmp: {
12911287
Out << '(';
12921288
bool NeedsClosingParens = printConstExprCast(CE);
1293-
if (CE->getPredicate() == FCmpInst::FCMP_FALSE)
1289+
FCmpInst *CmpInst = dyn_cast<FCmpInst>(CE->getAsInstruction());
1290+
const auto Pred = CmpInst -> getPredicate();
1291+
if (Pred == FCmpInst::FCMP_FALSE)
12941292
Out << "0";
1295-
else if (CE->getPredicate() == FCmpInst::FCMP_TRUE)
1293+
else if (Pred == FCmpInst::FCMP_TRUE)
12961294
Out << "1";
12971295
else {
1298-
const auto Pred = (CmpInst::Predicate)CE->getPredicate();
12991296
headerUseFCmpOp(Pred);
13001297
Out << "llvm_fcmp_" << getCmpPredicateName(Pred) << "(";
13011298
printConstant(CE->getOperand(0), ContextCasted);

lib/Target/CBackend/CTargetMachine.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ bool CTargetMachine::addPassesToEmitFile(PassManagerBase &PM,
2525
bool DisableVerify,
2626
MachineModuleInfoWrapperPass *MMI) {
2727

28-
if (FileType != CodeGenFileType::CGFT_AssemblyFile)
28+
if (FileType != CodeGenFileType::AssemblyFile)
2929
return true;
3030

3131
PM.add(new TargetPassConfig(*this, PM));
@@ -38,7 +38,7 @@ bool CTargetMachine::addPassesToEmitFile(PassManagerBase &PM,
3838
PM.add(createUnreachableBlockEliminationPass());
3939

4040
// Lower atomic operations to libcalls
41-
PM.add(createAtomicExpandPass());
41+
PM.add(createAtomicExpandLegacyPass());
4242

4343
// Lower vector operations into shuffle sequences
4444
PM.add(createExpandReductionsPass());

lib/Target/CBackend/CTargetMachine.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class CTargetMachine : public LLVMTargetMachine {
4646
public:
4747
CTargetMachine(const Target &T, const Triple &TT, StringRef CPU, StringRef FS,
4848
const TargetOptions &Options, std::optional<Reloc::Model> RM,
49-
std::optional<CodeModel::Model> CM, CodeGenOpt::Level OL,
49+
std::optional<CodeModel::Model> CM, CodeGenOptLevel OL,
5050
bool /*JIT*/)
5151
: LLVMTargetMachine(T, "", TT, CPU, FS, Options,
5252
RM.value_or(Reloc::Static),

tools/llvm-cbe/llvm-cbe.cpp

+12-12
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ static ToolOutputFile *GetOutputStream(const char *TargetName,
109109
OutputFilename = GetFileNameRoot(InputFilename);
110110

111111
switch (codegen::getFileType()) {
112-
case CodeGenFileType::CGFT_AssemblyFile:
112+
case CodeGenFileType::AssemblyFile:
113113
if (TargetName[0] == 'c') {
114114
if (TargetName[1] == 0)
115115
OutputFilename += ".cbe.c";
@@ -121,13 +121,13 @@ static ToolOutputFile *GetOutputStream(const char *TargetName,
121121
OutputFilename += ".s";
122122
break;
123123

124-
case CodeGenFileType::CGFT_ObjectFile:
124+
case CodeGenFileType::ObjectFile:
125125
if (OS == Triple::Win32)
126126
OutputFilename += ".obj";
127127
else
128128
OutputFilename += ".o";
129129
break;
130-
case CodeGenFileType::CGFT_Null:
130+
case CodeGenFileType::Null:
131131
OutputFilename += ".null";
132132
break;
133133
}
@@ -137,10 +137,10 @@ static ToolOutputFile *GetOutputStream(const char *TargetName,
137137
// Decide if we need "binary" output.
138138
bool Binary = false;
139139
switch (codegen::getFileType()) {
140-
case CodeGenFileType::CGFT_AssemblyFile:
140+
case CodeGenFileType::AssemblyFile:
141141
break;
142-
case CodeGenFileType::CGFT_ObjectFile:
143-
case CodeGenFileType::CGFT_Null:
142+
case CodeGenFileType::ObjectFile:
143+
case CodeGenFileType::Null:
144144
Binary = true;
145145
break;
146146
}
@@ -260,7 +260,7 @@ static int compileModule(char **argv, LLVMContext &Context) {
260260
FeaturesStr = Features.getString();
261261
}
262262

263-
CodeGenOpt::Level OLvl = CodeGenOpt::Default;
263+
CodeGenOptLevel OLvl = CodeGenOptLevel::Default;
264264

265265
switch (OptLevel) {
266266
default:
@@ -269,16 +269,16 @@ static int compileModule(char **argv, LLVMContext &Context) {
269269
case ' ':
270270
break;
271271
case '0':
272-
OLvl = CodeGenOpt::None;
272+
OLvl = CodeGenOptLevel::None;
273273
break;
274274
case '1':
275-
OLvl = CodeGenOpt::Less;
275+
OLvl = CodeGenOptLevel::Less;
276276
break;
277277
case '2':
278-
OLvl = CodeGenOpt::Default;
278+
OLvl = CodeGenOptLevel::Default;
279279
break;
280280
case '3':
281-
OLvl = CodeGenOpt::Aggressive;
281+
OLvl = CodeGenOptLevel::Aggressive;
282282
break;
283283
}
284284

@@ -330,7 +330,7 @@ static int compileModule(char **argv, LLVMContext &Context) {
330330
PM.add(createTargetTransformInfoWrapperPass(Target.getTargetIRAnalysis()));
331331

332332
if (mc::getExplicitRelaxAll()) {
333-
if (codegen::getFileType() != CodeGenFileType::CGFT_ObjectFile)
333+
if (codegen::getFileType() != CodeGenFileType::ObjectFile)
334334
errs() << argv[0]
335335
<< ": warning: ignoring -mc-relax-all because filetype != obj\n";
336336
}

0 commit comments

Comments
 (0)