Skip to content
Closed
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
2 changes: 1 addition & 1 deletion .github/workflows/builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Builds

on: [push, pull_request]
env:
llvm: 17
llvm: 19

jobs:
nix-build:
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,22 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
llvm: [12, 13, 14, 15, 16, 17, 18]
llvm: [12, 13, 14, 15, 16, 17, 18, 19]
env:
- CC: gcc
CXX: g++
asan: [OFF]
regression-tests: [true]

include:
- llvm: 18
- llvm: 19
env:
CC: clang
CXX: clang++
asan: OFF
regression-tests: true

- llvm: 18
- llvm: 19
env:
CC: gcc
CXX: g++
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ __pycache__/
*.py[cod]
*$py.class


# Build files
.Python
/build*/
Expand Down
8 changes: 7 additions & 1 deletion diffkemp/llvm_ir/optimiser.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Functions for optimizations of LLVM IR."""
from diffkemp.utils import get_opt_command
from diffkemp.simpll.library import get_llvm_version
from subprocess import check_call, CalledProcessError
import os

Expand All @@ -14,7 +15,12 @@ def opt_llvm(llvm_file):
Run basic simplification passes and -constmerge to remove
duplicate constants that might have come from linked files.
"""
passes = [("lowerswitch", "function"),
if get_llvm_version().major < 19:
lower_switch_pass_name = "lowerswitch"
else:
lower_switch_pass_name = "lower-switch"

passes = [(lower_switch_pass_name, "function"),
("mem2reg", "function"),
("loop-simplify", "function"),
("simplifycfg", "function"),
Expand Down
2 changes: 1 addition & 1 deletion diffkemp/simpll/DifferentialFunctionComparator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ int DifferentialFunctionComparator::cmpGEPs(const GEPOperator *GEPL,

if (MemberNameL == DI->StructFieldNames.end()
|| MemberNameR == DI->StructFieldNames.end()
|| !MemberNameL->second.equals(MemberNameR->second))
|| !(MemberNameL->second == MemberNameR->second))
if (int Res = cmpValues(idxL->get(), idxR->get()))
RETURN_WITH_LOG(Res);

Expand Down
2 changes: 2 additions & 0 deletions diffkemp/simpll/SimpLL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#include "Output.h"
#include "Utils.h"

#include <llvm/Support/ManagedStatic.h>

using namespace llvm;

// Command line options
Expand Down
67 changes: 63 additions & 4 deletions diffkemp/simpll/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <iostream>
#include <llvm/Analysis/AliasAnalysis.h>
#include <llvm/BinaryFormat/Dwarf.h>
#include <llvm/IR/Constants.h>
#include <llvm/IR/DIBuilder.h>
#include <llvm/IR/DebugInfo.h>
#include <llvm/IR/Instruction.h>
Expand All @@ -41,19 +42,21 @@

#if LLVM_VERSION_MAJOR >= 18

bool hasSuffix(StringRef ref, StringRef suffix) {
bool hasSuffix(StringRef ref, StringRef suffix) noexcept {
return ref.ends_with(suffix);
}

bool hasPrefix(StringRef ref, StringRef prefix) {
bool hasPrefix(StringRef ref, StringRef prefix) noexcept {
return ref.starts_with(prefix);
}

#else

bool hasSuffix(StringRef ref, StringRef suffix) { return ref.endswith(suffix); }
bool hasSuffix(StringRef ref, StringRef suffix) noexcept {
return ref.endswith(suffix);
}

bool hasPrefix(StringRef ref, StringRef prefix) {
bool hasPrefix(StringRef ref, StringRef prefix) noexcept {
return ref.startswith(prefix);
}

Expand Down Expand Up @@ -404,6 +407,60 @@ void findAndReplace(std::string &input, std::string find, std::string replace) {
}
}

#if LLVM_VERSION_MAJOR >= 19

const Instruction *getConstExprAsInstruction(const ConstantExpr *CEx) {
SmallVector<Value *, 4> ValueOperands(CEx->op_begin(), CEx->op_end());
ArrayRef<Value *> Ops(ValueOperands);

switch (CEx->getOpcode()) {
case Instruction::Trunc:
#if LLVM_VERSION_MAJOR >= 21
case Instruction::PtrToAddr:
#endif
case Instruction::PtrToInt:
case Instruction::IntToPtr:
case Instruction::BitCast:
case Instruction::AddrSpaceCast:
return CastInst::Create((Instruction::CastOps)CEx->getOpcode(),
Ops[0],
CEx->getType(),
"");
case Instruction::InsertElement:
return InsertElementInst::Create(Ops[0], Ops[1], Ops[2], "");
case Instruction::ExtractElement:
return ExtractElementInst::Create(Ops[0], Ops[1], "");
case Instruction::ShuffleVector:
return new ShuffleVectorInst(Ops[0], Ops[1], CEx->getShuffleMask(), "");

case Instruction::GetElementPtr: {
const auto *GO = cast<GEPOperator>(CEx);
return GetElementPtrInst::Create(GO->getSourceElementType(),
Ops[0],
Ops.slice(1),
GO->getNoWrapFlags(),
"");
}
default:
assert(CEx->getNumOperands() == 2 && "Must be binary operator?");
BinaryOperator *BO = BinaryOperator::Create(
(Instruction::BinaryOps)CEx->getOpcode(), Ops[0], Ops[1], "");
if (isa<OverflowingBinaryOperator>(BO)) {
BO->setHasNoUnsignedWrap(
CEx->getRawSubclassOptionalData()
& OverflowingBinaryOperator::NoUnsignedWrap);
BO->setHasNoSignedWrap(CEx->getRawSubclassOptionalData()
& OverflowingBinaryOperator::NoSignedWrap);
}
if (isa<PossiblyExactOperator>(BO))
BO->setIsExact(CEx->getRawSubclassOptionalData()
& PossiblyExactOperator::IsExact);
return BO;
}
}

#else

/// Convert constant expression to instruction. (Copied from LLVM and modified
/// to work outside the ConstantExpr class; otherwise the function is the same,
/// the only purpose of copying the function is making it work on constant
Expand Down Expand Up @@ -478,6 +535,8 @@ const Instruction *getConstExprAsInstruction(const ConstantExpr *CEx) {
}
}

#endif

/// Generates human-readable C-like identifier for type.
std::string getIdentifierForType(Type *Ty) {
if (auto STy = dyn_cast<StructType>(Ty)) {
Expand Down
6 changes: 3 additions & 3 deletions diffkemp/simpll/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,9 @@ const AllocaInst *getAllocaOp(const InstType *Inst) {
}

/// LLVM Version independent predicate whether string ref contains some suffix.
bool hasSuffix(StringRef ref, StringRef suffix);
///
bool hasSuffix(StringRef ref, StringRef suffix) noexcept;

/// LLVM Version independent predicate whether string ref contains some prefix.
bool hasPrefix(StringRef ref, StringRef prefix);
bool hasPrefix(StringRef ref, StringRef prefix) noexcept;

#endif // DIFFKEMP_SIMPLL_UTILS_H
9 changes: 9 additions & 0 deletions diffkemp/simpll/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Python interface for the SimpLL library.
"""
from diffkemp.simpll.simpll_lib import ffi, lib
import collections


def _ptrarray_to_list(ptrarray):
Expand Down Expand Up @@ -156,3 +157,11 @@ def get_child(self, sysctl_name):

def get_data(self, sysctl_name):
return self._get_global_variable(sysctl_name, lib.getData)


def get_llvm_version():
Version = collections.namedtuple("Version", ["major", "minor", "patch"])
version = ffi.new("int[3]")

lib.getLlvmVersion(version)
return Version(version[0], version[1], version[2])
11 changes: 10 additions & 1 deletion diffkemp/simpll/library/FFI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@
#include "library/DiffKempUtils.h"
#include "library/SysctlTable.h"
#include "passes/CalledFunctionsAnalysis.h"
#include <cstring>

#include <llvm/Support/ManagedStatic.h>
#include <llvm/Transforms/Utils/Cloning.h>

#include <cstring>
#include <unordered_map>

/// Map to store LLVMContext objects for modules.
Expand Down Expand Up @@ -323,5 +326,11 @@ void preprocessModuleC(void *Mod, struct builtin_patterns PatternsC) {
preprocessModule(*LLVMMod, nullptr, nullptr, Patterns);
}

void getLlvmVersion(int *out) {
out[0] = LLVM_VERSION_MAJOR;
out[1] = LLVM_VERSION_MINOR;
out[2] = LLVM_VERSION_PATCH;
}

void shutdownSimpLL() { llvm_shutdown(); }
} // extern "C"
2 changes: 2 additions & 0 deletions diffkemp/simpll/library/FFI.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ void parseAndRunSimpLL(const char *ModL,
/// won't be run again when the module is compared.
void preprocessModuleC(void *Mod, struct builtin_patterns PatternsC);

void getLlvmVersion(int *out);

void shutdownSimpLL();

// CFFI_DECLARATIONS_END
Expand Down
1 change: 0 additions & 1 deletion diffkemp/simpll/llvm-lib/18/FunctionComparator.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ class FunctionComparator {
const Function *F2,
GlobalNumberState *GN)
: FnL(F1), FnR(F2), GlobalNumbers(GN) {}
// virtual ~FunctionComparator() = default;

/// Test whether the two functions have equivalent behaviour.
virtual int compare();
Expand Down
Loading
Loading