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

Support LLVM-19 #211

Merged
merged 1 commit into from
Oct 17, 2024
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
22 changes: 11 additions & 11 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,19 @@ jobs:
run: |
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
sudo ./llvm.sh 17 all
sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-17 160
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-17 160
sudo update-alternatives --install /usr/bin/lli lli /usr/bin/lli-17 160
sudo update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-17 160
sudo ./llvm.sh 19 all
sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-19 160
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-19 160
sudo update-alternatives --install /usr/bin/lli lli /usr/bin/lli-19 160
sudo update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-19 160

- name: Setup LLVM and GCC (MacOS)
if: ${{ runner.os == 'macOS' }}
run: |
brew install llvm@17
echo "$(brew --prefix llvm@17)/bin" >> $GITHUB_PATH
echo "CC=$(brew --prefix llvm@17)/bin/clang" >> $GITHUB_ENV
echo "CXX=$(brew --prefix llvm@17)/bin/clang++" >> $GITHUB_ENV
brew install llvm@19
echo "$(brew --prefix llvm@19)/bin" >> $GITHUB_PATH
echo "CC=$(brew --prefix llvm@19)/bin/clang" >> $GITHUB_ENV
echo "CXX=$(brew --prefix llvm@19)/bin/clang++" >> $GITHUB_ENV
cd /usr/local/bin
ln -s gcc-11 gcc

Expand All @@ -65,7 +65,7 @@ jobs:
- name: Build
run: |
mkdir build
cmake -S . -B build -DLLVM_INCLUDE_TESTS=On -DLLVM_DIR=/usr/lib/llvm-17/cmake
cmake -S . -B build -DLLVM_INCLUDE_TESTS=On -DLLVM_DIR=/usr/lib/llvm-19/cmake
cmake --build build

- name: Test
Expand All @@ -84,7 +84,7 @@ jobs:
uses: actions/checkout@master
with:
repository: llvm/llvm-project
ref: llvmorg-17.0.6
ref: llvmorg-19.1.1

- name: Checkout
uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ if (NOT DEFINED LLVM_VERSION_MAJOR)
project(llvm-cbe)
set (USE_SYSTEM_LLVM 1)
cmake_minimum_required(VERSION 3.4.3)
find_package(LLVM 17 REQUIRED CONFIG)
find_package(LLVM 19 REQUIRED CONFIG)
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
message(STATUS "LLVM_INCLUDE_DIRS: ${LLVM_INCLUDE_DIRS}")
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ On Debian and derivatives, install the llvm-dev package via:
~# apt install llvm-dev clang ninja-build
```

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.
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.

Or compile LLVM yourself:
-----------------------------
Expand All @@ -41,7 +41,7 @@ The first step is to compile LLVM on your machine
```sh
~$ git clone https://github.com/llvm/llvm-project.git
~$ cd llvm-project
llvm-project$ git checkout release/17.x
llvm-project$ git checkout tags/19.1.1
llvm-project$ mkdir llvm/build
llvm-project$ cd llvm/build
build$ cmake .. -G "Ninja" -DCMAKE_BUILD_TYPE=Debug -DLLVM_PARALLEL_LINK_JOBS=1
Expand Down
17 changes: 7 additions & 10 deletions lib/Target/CBackend/CBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -755,10 +755,10 @@ bool CWriter::isStandardMain(const FunctionType *FTy) {
const Type *T = FTy->getContainedType(i);
const StringRef CType = MainArgs.begin()[i].first;

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

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

Expand Down Expand Up @@ -1251,26 +1251,22 @@ void CWriter::printConstant(Constant *CPV, enum OperandContext Context) {
Out << " >> ";
break;
case Instruction::ICmp:
switch (CE->getPredicate()) {
switch ((dyn_cast<ICmpInst>(CE->getAsInstruction()))->getUnsignedPredicate()) {
case ICmpInst::ICMP_EQ:
Out << " == ";
break;
case ICmpInst::ICMP_NE:
Out << " != ";
break;
case ICmpInst::ICMP_SLT:
case ICmpInst::ICMP_ULT:
Out << " < ";
break;
case ICmpInst::ICMP_SLE:
case ICmpInst::ICMP_ULE:
Out << " <= ";
break;
case ICmpInst::ICMP_SGT:
case ICmpInst::ICMP_UGT:
Out << " > ";
break;
case ICmpInst::ICMP_SGE:
case ICmpInst::ICMP_UGE:
Out << " >= ";
break;
Expand All @@ -1290,12 +1286,13 @@ void CWriter::printConstant(Constant *CPV, enum OperandContext Context) {
case Instruction::FCmp: {
Out << '(';
bool NeedsClosingParens = printConstExprCast(CE);
if (CE->getPredicate() == FCmpInst::FCMP_FALSE)
FCmpInst *CmpInst = dyn_cast<FCmpInst>(CE->getAsInstruction());
const auto Pred = CmpInst -> getPredicate();
if (Pred == FCmpInst::FCMP_FALSE)
Out << "0";
else if (CE->getPredicate() == FCmpInst::FCMP_TRUE)
else if (Pred == FCmpInst::FCMP_TRUE)
Out << "1";
else {
const auto Pred = (CmpInst::Predicate)CE->getPredicate();
headerUseFCmpOp(Pred);
Out << "llvm_fcmp_" << getCmpPredicateName(Pred) << "(";
printConstant(CE->getOperand(0), ContextCasted);
Expand Down
4 changes: 2 additions & 2 deletions lib/Target/CBackend/CTargetMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ bool CTargetMachine::addPassesToEmitFile(PassManagerBase &PM,
bool DisableVerify,
MachineModuleInfoWrapperPass *MMI) {

if (FileType != CodeGenFileType::CGFT_AssemblyFile)
if (FileType != CodeGenFileType::AssemblyFile)
return true;

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

// Lower atomic operations to libcalls
PM.add(createAtomicExpandPass());
PM.add(createAtomicExpandLegacyPass());

// Lower vector operations into shuffle sequences
PM.add(createExpandReductionsPass());
Expand Down
2 changes: 1 addition & 1 deletion lib/Target/CBackend/CTargetMachine.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class CTargetMachine : public LLVMTargetMachine {
public:
CTargetMachine(const Target &T, const Triple &TT, StringRef CPU, StringRef FS,
const TargetOptions &Options, std::optional<Reloc::Model> RM,
std::optional<CodeModel::Model> CM, CodeGenOpt::Level OL,
std::optional<CodeModel::Model> CM, CodeGenOptLevel OL,
bool /*JIT*/)
: LLVMTargetMachine(T, "", TT, CPU, FS, Options,
RM.value_or(Reloc::Static),
Expand Down
24 changes: 12 additions & 12 deletions tools/llvm-cbe/llvm-cbe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ static ToolOutputFile *GetOutputStream(const char *TargetName,
OutputFilename = GetFileNameRoot(InputFilename);

switch (codegen::getFileType()) {
case CodeGenFileType::CGFT_AssemblyFile:
case CodeGenFileType::AssemblyFile:
if (TargetName[0] == 'c') {
if (TargetName[1] == 0)
OutputFilename += ".cbe.c";
Expand All @@ -121,13 +121,13 @@ static ToolOutputFile *GetOutputStream(const char *TargetName,
OutputFilename += ".s";
break;

case CodeGenFileType::CGFT_ObjectFile:
case CodeGenFileType::ObjectFile:
if (OS == Triple::Win32)
OutputFilename += ".obj";
else
OutputFilename += ".o";
break;
case CodeGenFileType::CGFT_Null:
case CodeGenFileType::Null:
OutputFilename += ".null";
break;
}
Expand All @@ -137,10 +137,10 @@ static ToolOutputFile *GetOutputStream(const char *TargetName,
// Decide if we need "binary" output.
bool Binary = false;
switch (codegen::getFileType()) {
case CodeGenFileType::CGFT_AssemblyFile:
case CodeGenFileType::AssemblyFile:
break;
case CodeGenFileType::CGFT_ObjectFile:
case CodeGenFileType::CGFT_Null:
case CodeGenFileType::ObjectFile:
case CodeGenFileType::Null:
Binary = true;
break;
}
Expand Down Expand Up @@ -260,7 +260,7 @@ static int compileModule(char **argv, LLVMContext &Context) {
FeaturesStr = Features.getString();
}

CodeGenOpt::Level OLvl = CodeGenOpt::Default;
CodeGenOptLevel OLvl = CodeGenOptLevel::Default;

switch (OptLevel) {
default:
Expand All @@ -269,16 +269,16 @@ static int compileModule(char **argv, LLVMContext &Context) {
case ' ':
break;
case '0':
OLvl = CodeGenOpt::None;
OLvl = CodeGenOptLevel::None;
break;
case '1':
OLvl = CodeGenOpt::Less;
OLvl = CodeGenOptLevel::Less;
break;
case '2':
OLvl = CodeGenOpt::Default;
OLvl = CodeGenOptLevel::Default;
break;
case '3':
OLvl = CodeGenOpt::Aggressive;
OLvl = CodeGenOptLevel::Aggressive;
break;
}

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

if (mc::getExplicitRelaxAll()) {
if (codegen::getFileType() != CodeGenFileType::CGFT_ObjectFile)
if (codegen::getFileType() != CodeGenFileType::ObjectFile)
errs() << argv[0]
<< ": warning: ignoring -mc-relax-all because filetype != obj\n";
}
Expand Down
Loading