Skip to content

Commit f4b9893

Browse files
authored
Merge pull request #293 from cpc/llvm-22
LLVM 22 support without RISC-V
2 parents 94e802b + 2149ef5 commit f4b9893

File tree

17 files changed

+309
-168
lines changed

17 files changed

+309
-168
lines changed

openasip/Makefile.am

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
SUBDIRS = src data conf opset hdb compressors icdecoder_plugins \
22
scripts manual cost_estimator_plugins explorer doc tools
33

4-
SUBDIRS += scheduler
5-
SUBDIRS += bclib
6-
SUBDIRS += newlib-1.17.0/tce-llvm
7-
SUBDIRS += newlib-1.17.0/tcele-llvm
4+
SUBDIRS += scheduler
5+
SUBDIRS += bclib
6+
SUBDIRS += newlib-1.17.0/tce-llvm
7+
SUBDIRS += newlib-1.17.0/tcele-llvm
88
SUBDIRS += newlib-1.17.0/tcele64-llvm
9+
if RISCV
910
SUBDIRS += newlib-1.17.0/riscv-llvm
11+
endif
1012

1113
AUTOMAKE_OPTIONS = foreign
1214

openasip/configure.ac

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ AC_PATH_PROGS([LLVM_CONFIG], [llvmtce-config llvm-config], [$llvmDir/bin])
464464
llvmConf=$LLVM_CONFIG
465465
],
466466
[llvmDir=""
467-
AC_PATH_PROGS([LLVM_CONFIG], [llvmtce-config])
467+
AC_PATH_PROGS([LLVM_CONFIG], [llvmtce-config llvm-config])
468468
llvmConf=$LLVM_CONFIG
469469
]
470470
)
@@ -547,6 +547,8 @@ if test x"$LLVM_INCLUDEDIR" == x/usr/include/llvm; then
547547
LLVM_INCLUDEDIR=/usr/include
548548
fi
549549
550+
ENABLE_RISCV=true
551+
550552
case "$LLVM_VERSION" in
551553
21*)
552554
AC_DEFINE([LLVM_21], [], "Using LLVM 21")
@@ -555,12 +557,27 @@ case "$LLVM_VERSION" in
555557
LLVM_SHARED_LIB_FILE=$LLVM_LIBDIR/libLLVM-$LLVM_LIBRARYVERSION$LIBRARY_SUFFIX
556558
LLVM_SHARED_LIB=-lLLVMTCE
557559
LLVM_LDFLAGS="$($llvmConf --ldflags) $LLVM_SHARED_LIB"
558-
# This patch should be unnecessary in LLVM 21, it seems to have a wide
559-
# range of vector datatypes up to 4096.
560-
AC_DEFINE([LLVM_HAS_CUSTOM_VECTOR_EXTENSION], [2], "LLVM has the wide custom vector extension patch(wide)")
561-
AC_SUBST([LLVM_HAS_CUSTOM_VECTOR_EXTENSION], ["2"])
562560
;;
563-
561+
22.*)
562+
AC_DEFINE([LLVM_22], [], "Using LLVM 22 (git)")
563+
LLVM_VERSION=22
564+
LLVM_LIBRARYVERSION=22git
565+
LLVM_SHARED_LIB_FILE=$LLVM_LIBDIR/libLLVM-$LLVM_LIBRARYVERSION$LIBRARY_SUFFIX
566+
LLVM_SHARED_LIB=-lLLVM-22git
567+
LLVM_LDFLAGS="$($llvmConf --ldflags) $LLVM_SHARED_LIB"
568+
# The upstream LLVM doesn't (yet) have the RISC-V customization support.
569+
ENABLE_RISCV=false
570+
;;
571+
23.*)
572+
AC_DEFINE([LLVM_23], [], "Using LLVM 23 (git)")
573+
LLVM_VERSION=23
574+
LLVM_LIBRARYVERSION=23git
575+
LLVM_SHARED_LIB_FILE=$LLVM_LIBDIR/libLLVM-$LLVM_LIBRARYVERSION$LIBRARY_SUFFIX
576+
LLVM_SHARED_LIB=-lLLVM-23git
577+
LLVM_LDFLAGS="$($llvmConf --ldflags) $LLVM_SHARED_LIB"
578+
# The upstream LLVM doesn't (yet) have the RISC-V customization support.
579+
ENABLE_RISCV=false
580+
;;
564581
*)
565582
AC_MSG_NOTICE(
566583
[
@@ -577,6 +594,15 @@ AC_MSG_NOTICE([
577594
])
578595

579596

597+
AM_CONDITIONAL([RISCV], test x$ENABLE_RISCV = xtrue)
598+
599+
600+
# The patch for SIMD is not needed any more in the recent LLVMs.
601+
# TODO: remove this macro.
602+
AC_DEFINE([LLVM_HAS_CUSTOM_VECTOR_EXTENSION], [2],
603+
"LLVM has the wide custom vector extension patch(wide)")
604+
AC_SUBST([LLVM_HAS_CUSTOM_VECTOR_EXTENSION], ["2"])
605+
580606
if test ! -e $LLVM_SHARED_LIB_FILE;
581607
then
582608
# Try the alternative location where llvm.org/apt packages install it.
@@ -1567,6 +1593,9 @@ $srcdir/newlib-1.17.0/configure --prefix=$prefix --target=tcele64-llvm --disable
15671593
2>&1 | egrep -v "to force reconfigure";
15681594
])
15691595

1596+
if test x$ENABLE_RISCV = xtrue;
1597+
then
1598+
15701599
AC_CONFIG_COMMANDS_POST ([
15711600
echo "=== Configuring newlib for riscv =====";
15721601
# make srcdir absolute
@@ -1587,6 +1616,16 @@ $srcdir/newlib-1.17.0/configure --prefix=$prefix --target=riscv --disable-multil
15871616
2>&1 | egrep -v "to force reconfigure";
15881617
])
15891618

1619+
rm -f ../testsuite/systemtest_long/bintools/RISCV/tcetest_custom_ops.sh.disabled
1620+
rm -f ../testsuite/systemtest_long/procgen/RISCV/tcetest_stdlib.sh.disabled
1621+
1622+
else
1623+
1624+
touch ../testsuite/systemtest_long/bintools/RISCV/tcetest_custom_ops.sh.disabled
1625+
touch ../testsuite/systemtest_long/procgen/RISCV/tcetest_stdlib.sh.disabled
1626+
1627+
fi
1628+
15901629
# Generate config.status and launch it. config.status then
15911630
# performs all configuration actions.
15921631
AC_OUTPUT
@@ -1646,7 +1685,7 @@ if test x"$LLVM_VERSION" = x
16461685
then
16471686
echo "NOTE! Supported LLVM version not found. Compiling C programs is disabled."
16481687
else
1649-
echo "Found LLVM version $LLVM_VERSION"
1688+
echo "Found LLVM version $LLVM_VERSION".
16501689
fi
16511690

16521691

openasip/src/applibs/LLVMBackend/LLVMBackend.cc

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -621,9 +621,9 @@ LLVMBackend::compile(
621621
std::string featureString ="";
622622

623623
// run registering code, which should have been done by LLVM
624-
625-
// Initialize targets first. needs
626-
// #include <llvm/Target/TargetSelecty.h>,
624+
625+
// Initialize targets first. needs
626+
// #include <llvm/Target/TargetSelecty.h>,
627627
// whose defines collide with tce_config.h
628628

629629
//InitializeAllTargets();
@@ -633,9 +633,11 @@ LLVMBackend::compile(
633633
LLVMInitializeTCETargetInfo();
634634
LLVMInitializeTCETarget();
635635

636+
llvm::Triple targetTriple(targetStr);
637+
636638
// get registered target machine and set plugin.
637639
const Target* tceTarget =
638-
TargetRegistry::lookupTarget(targetStr, errorStr);
640+
TargetRegistry::lookupTarget(targetTriple, errorStr);
639641
Target* nonconst_target = const_cast<Target*>(tceTarget);
640642

641643
if (!tceTarget) {
@@ -653,7 +655,9 @@ LLVMBackend::compile(
653655
std::string cpuStr = "tce";
654656

655657
TargetOptions Options;
658+
#if LLVM_MAJOR_VERSION < 22
656659
Options.UnsafeFPMath = false; //EnableUnsafeFPMath;
660+
#endif
657661
Options.NoInfsFPMath = false; //EnableNoInfsFPMath;
658662
Options.NoNaNsFPMath = false; //EnableNoNaNsFPMath;
659663
Options.HonorSignDependentRoundingFPMathOption = false;
@@ -684,10 +688,9 @@ LLVMBackend::compile(
684688
Options.GuaranteedTailCallOpt = true; //EnableGuaranteedTailCallOpt;
685689

686690
TCETargetMachine* targetMachine =
687-
static_cast<TCETargetMachine*>(
688-
tceTarget->createTargetMachine(
689-
targetStr, cpuStr, featureString, Options,
690-
Reloc::Model::Static));
691+
static_cast<TCETargetMachine*>(tceTarget->createTargetMachine(
692+
targetTriple, cpuStr, featureString, Options,
693+
Reloc::Model::Static));
691694

692695
if (!targetMachine) {
693696
errs() << "Could not create tce target machine" << "\n";

openasip/src/applibs/LLVMBackend/LowerMissingInstructions.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
* Convert instruction which are not supported by the machine to
2828
* function calls.
2929
*
30+
* We perform this because there is no binary linker in the compiler chain
31+
* which would be required by the regular libcall conversion in the LLVM
32+
* code generation.
33+
*
3034
* NOTE: Right now system is limited to replace only those operations, which
3135
* use only one bitwidth integers for example i1.icmp.i32.i32 cannot
3236
* be lowered to function call.

openasip/src/applibs/LLVMBackend/TCEStubSubTarget.cc

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,14 @@ using namespace llvm;
4343
TCEStubSubTarget::TCEStubSubTarget(
4444
const Triple& TT, const StringRef& CPU, const StringRef& FS,
4545
const TCEStubTargetMachine& TM)
46-
:
47-
#if LLVM_MAJOR_VERSION < 21
48-
TargetSubtargetInfo(
49-
TT, CPU, FS, FS, ArrayRef<SubtargetFeatureKV>(),
50-
ArrayRef<SubtargetSubTypeKV>(), NULL, NULL, NULL, NULL, NULL, NULL),
51-
#else
52-
TargetSubtargetInfo(
46+
: TargetSubtargetInfo(
5347
TT, CPU, FS, FS, llvm::ArrayRef<llvm::StringRef>(),
5448
ArrayRef<SubtargetFeatureKV>(), ArrayRef<SubtargetSubTypeKV>(),
5549
NULL, NULL, NULL, NULL, NULL, NULL),
50+
#if LLVM_MAJOR_VERSION < 22
51+
TLI(TM)
52+
#else
53+
TLI(TM, *this)
5654
#endif
57-
TLI(TM) {
55+
{
5856
}

openasip/src/applibs/LLVMBackend/TDGen.cc

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,7 +1068,7 @@ TDGen::write32bitRegisterInfo(std::ostream& o) {
10681068
for (; i < regs32bit_.size(); i++) {
10691069
std::string regName = "I" + Conversion::toString(i);
10701070
writeRegisterDef(o, regs32bit_[i], regName, "R32", "", GPR);
1071-
1071+
10721072
if (!regsInRFClasses_.count(regs32bit_[i].rf)) {
10731073
regsInRFClasses_[regs32bit_[i].rf] = std::vector<std::string>();
10741074
}
@@ -1078,12 +1078,12 @@ TDGen::write32bitRegisterInfo(std::ostream& o) {
10781078
}
10791079

10801080
o << std::endl;
1081-
1081+
10821082
if (!mach_.is64bit()) {
10831083
// Bypass registers
10841084
for (size_t j = 0; j < 256; ++j) {
10851085
std::string regName = "BP" + Conversion::toString(j);
1086-
1086+
10871087
o << "def " << regName << " : "
10881088
<< "R32<\"ByPass_Regs"
10891089
<< "\", []>, DwarfRegNum<"
@@ -3575,13 +3575,23 @@ TDGen::writeInstrInfo(std::ostream& os) {
35753575
createConstantMaterializationPatterns(os);
35763576
createConstShiftPatterns(os);
35773577
createBoolAndHalfLoadPatterns(os);
3578+
3579+
os << std::endl;
3580+
#if LLVM_MAJOR_VERSION > 21
3581+
if (mach_.is64bit())
3582+
os << "defm : RemapAllTargetPseudoPointerOperands<R64IRegs>;"
3583+
<< std::endl;
3584+
else
3585+
os << "defm : RemapAllTargetPseudoPointerOperands<R32IRegs>;"
3586+
<< std::endl;
3587+
#endif
35783588
}
35793589

35803590
void TDGen::writeCallDefRegs(std::ostream& o) {
35813591
for (unsigned i = 0; i < resRegNames_.size(); i++) {
35823592
if (i > 0) o << ", ";
35833593
o << resRegNames_[i];
3584-
}
3594+
}
35853595
for (unsigned i = 0; i < gprRegNames_.size(); i++) {
35863596
o << ", " << gprRegNames_[i];
35873597
}

openasip/src/applibs/LLVMBackend/passes/LowerIntrinsics.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,11 @@ IGNORE_COMPILER_WARNING("-Wunused-parameter")
4949
#include <llvm/IR/Function.h>
5050
#include <llvm/Pass.h>
5151
#include <llvm/Passes/PassBuilder.h>
52+
#if LLVM_MAJOR_VERSION < 22
5253
#include <llvm/Passes/PassPlugin.h>
54+
#else
55+
#include <llvm/Plugins/PassPlugin.h>
56+
#endif
5357
#include <llvm/CodeGen/IntrinsicLowering.h>
5458

5559
POP_COMPILER_DIAGS

openasip/src/applibs/LLVMBackend/plugin/TCEDAGToDAGISel.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ class TCEDAGToDAGISel : public llvm::SelectionDAGISel {
5858
public:
5959
static char ID;
6060

61+
TCEDAGToDAGISel() = delete;
62+
6163
explicit TCEDAGToDAGISel(llvm::TCETargetMachine& tm);
6264
virtual ~TCEDAGToDAGISel();
6365

0 commit comments

Comments
 (0)