1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-08 03:28:20 +02:00

Linux updates for LLVM

This commit is contained in:
Brian Fiete 2024-05-06 12:43:52 -04:00
parent d5b0e6d06d
commit c5dee2f8bc
7 changed files with 89 additions and 58 deletions

View file

@ -185,29 +185,29 @@ else()
X86Target.cpp
)
include_directories(
../extern/llvm-project_13_0_1/llvm/include
../extern/llvm-project_13_0_1/llvm/lib/Target
include_directories(h
../extern/llvm-project_18_1_4/llvm/include
../extern/llvm-project_18_1_4/llvm/lib/Target18_1_4
)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
include_directories(
../extern/llvm_linux_13_0_1/include
../extern/llvm_linux_13_0_1/lib/Target/X86
../extern/llvm_linux_13_0_1/lib/Target/AArch64
../extern/llvm_linux_18_1_4/include
../extern/llvm_linux_18_1_4/lib/Target/X86
../extern/llvm_linux_18_1_4/lib/Target/AArch64
)
set(LLVM_LIB "${CMAKE_CURRENT_SOURCE_DIR}/../extern/llvm_linux_13_0_1/lib")
set(LLVM_LIB "${CMAKE_CURRENT_SOURCE_DIR}/../extern/llvm_linux_18_1_4/lib")
else()
include_directories(
../extern/llvm_linux_rel_13_0_1/include
../extern/llvm_linux_rel_13_0_1/lib/Target/X86
../extern/llvm_linux_rel_13_0_1/lib/Target/AArch64
../extern/llvm_linux_rel_18_1_4/include
../extern/llvm_linux_rel_18_1_4/lib/Target/X86
../extern/llvm_linux_rel_18_1_4/lib/Target/AArch64
)
set(LLVM_LIB "${CMAKE_CURRENT_SOURCE_DIR}/../extern/llvm_linux_rel_13_0_1/lib")
set(LLVM_LIB "${CMAKE_CURRENT_SOURCE_DIR}/../extern/llvm_linux_rel_18_1_4/lib")
endif()
execute_process(
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/../extern/llvm_linux_13_0_1/bin/llvm-config --system-libs --link-static
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/../extern/llvm_linux_18_1_4/bin/llvm-config --system-libs --link-static
OUTPUT_VARIABLE LLVM_SYSTEM_LIBS
OUTPUT_STRIP_TRAILING_WHITESPACE
RESULT_VARIABLE EXEC_RESULT
@ -220,8 +220,8 @@ else()
message(FATAL_ERROR "llvm-config couldn't be executed: ${EXEC_RESULT}")
endif()
endif()
message(STATUS "Found LLVM 13.0.1 (local build)")
message(STATUS "Found LLVM 18.1.4 (local build)")
set(TARGET_LIBS_OS "${LLVM_SYSTEM_LIBS}")

View file

@ -3283,12 +3283,15 @@ void COFF::ParseCompileUnit_Symbols(DbgCompileUnit* compileUnit, uint8* sectionD
break;
case /*S_INLINEES*/0x1168:
break;
case 0x1176:
break;
case 0x1178:
break;
case 0x1179:
break;
case 0x1176:
case 0x1178:
case 0x1179:
case 0x117A:
case 0x117B:
case 0x117C:
case 0x117D:
case 0x117E:
case 0x117F:
case 0x1180:
break;
case 7:

View file

@ -1181,7 +1181,7 @@ void BfIRCodeGen::Read(BfIRTypedValue& typedValue, BfIRCodeGenEntry** codeGenEnt
llvm::ConstantInt::get(llvm::Type::getInt32Ty(*mLLVMContext), idx1)};
auto compositeType = GetTypeMember(target.mTypeEx, 0);
int elemIdx = BF_MIN(idx1, (int)compositeType->mMembers.mSize - 1);
int elemIdx = BF_MAX(BF_MIN(idx1, (int)compositeType->mMembers.mSize - 1), 0);
auto elemType = GetTypeMember(compositeType, elemIdx);
auto constant = llvm::dyn_cast<llvm::Constant>(target.mValue);
@ -4709,7 +4709,15 @@ void BfIRCodeGen::HandleNextCmd()
{
CMD_PARAM_NOTRANS(llvm::Value*, instValue);
BF_ASSERT(llvm::isa<llvm::Instruction>(instValue));
((llvm::Instruction*)instValue)->setDebugLoc(llvm::DebugLoc());
if (llvm::dyn_cast<llvm::DbgDeclareInst>(instValue))
{
printf("BfIRCmd_ClearDebugLocationInst on DbgDeclareInst in %s\n", mModuleName.c_str());
}
else
{
((llvm::Instruction*)instValue)->setDebugLoc(llvm::DebugLoc());
}
}
break;
case BfIRCmd_ClearDebugLocationInstLast:
@ -4720,7 +4728,14 @@ void BfIRCodeGen::HandleNextCmd()
if (!bb->empty())
{
auto& inst = bb->back();
inst.setDebugLoc(llvm::DebugLoc());
if (llvm::dyn_cast<llvm::DbgDeclareInst>(&inst))
{
printf("BfIRCmd_ClearDebugLocationInstLast on DbgDeclareInst\n");
}
else
{
inst.setDebugLoc(llvm::DebugLoc());
}
}
}
}
@ -4729,7 +4744,14 @@ void BfIRCodeGen::HandleNextCmd()
{
CMD_PARAM_NOTRANS(llvm::Value*, instValue);
BF_ASSERT(llvm::isa<llvm::Instruction>(instValue));
((llvm::Instruction*)instValue)->setDebugLoc(mIRBuilder->getCurrentDebugLocation());
if ((llvm::dyn_cast<llvm::DbgDeclareInst>(instValue)) && (!mIRBuilder->getCurrentDebugLocation()))
{
printf("BfIRCmd_UpdateDebugLocation NULL on DbgDeclareInst\n");
}
else
{
((llvm::Instruction*)instValue)->setDebugLoc(mIRBuilder->getCurrentDebugLocation());
}
}
break;
case BfIRCmd_SetCurrentDebugLocation:
@ -5394,15 +5416,20 @@ void BfIRCodeGen::HandleNextCmd()
llvm::Instruction* insertBeforeInst = NULL;
if (insertBefore != NULL)
insertBeforeInst = llvm::dyn_cast<llvm::Instruction>(insertBefore);
if (insertBeforeInst != NULL)
// Protect against lack of debug location
if (mIRBuilder->getCurrentDebugLocation())
{
SetResult(curId, mDIBuilder->insertDeclare(val, (llvm::DILocalVariable*)varInfo, mDIBuilder->createExpression(),
mIRBuilder->getCurrentDebugLocation(), insertBeforeInst));
}
else
{
SetResult(curId, mDIBuilder->insertDeclare(val, (llvm::DILocalVariable*)varInfo, mDIBuilder->createExpression(),
mIRBuilder->getCurrentDebugLocation(), mIRBuilder->GetInsertBlock()));
if (insertBeforeInst != NULL)
{
SetResult(curId, mDIBuilder->insertDeclare(val, (llvm::DILocalVariable*)varInfo, mDIBuilder->createExpression(),
mIRBuilder->getCurrentDebugLocation(), insertBeforeInst));
}
else
{
SetResult(curId, mDIBuilder->insertDeclare(val, (llvm::DILocalVariable*)varInfo, mDIBuilder->createExpression(),
mIRBuilder->getCurrentDebugLocation(), mIRBuilder->GetInsertBlock()));
}
}
}
break;

View file

@ -1258,8 +1258,8 @@ void BfModule::SetupIRBuilder(bool dbgVerifyCodeGen)
// code as we walk the AST
//mBfIRBuilder->mDbgVerifyCodeGen = true;
if (
(mModuleName == "BeefTest_LLVMType")
|| (mModuleName == "System_ValueType")
(mModuleName == "vdata")
|| (mModuleName == "")
//|| (mModuleName == "Tests_FuncRefs")
)
mBfIRBuilder->mDbgVerifyCodeGen = true;

View file

@ -43,13 +43,13 @@ else
echo "Ninja isn't installed, consider installing it for faster build speeds."
fi
LLVM_CONFIG=$(command -v llvm-config-13 2>/dev/null || command -v llvm-config 2>/dev/null)
LLVM_CONFIG=$(command -v llvm-config-18 2>/dev/null || command -v llvm-config 2>/dev/null)
LLVM_FOUND=0
if [ -n "$LLVM_CONFIG" ]; then
LLVM_VERSION=$($LLVM_CONFIG --version)
LLVM_MAJOR_VERSION=$(echo "$LLVM_VERSION" | cut -d. -f1)
if [ "$LLVM_MAJOR_VERSION" = "13" ]; then
if [ "$LLVM_MAJOR_VERSION" = "18" ]; then
LLVM_FOUND=1
fi
fi
@ -59,8 +59,8 @@ set -e
### Dependencies ###
if [ ! -f ../extern/llvm_linux_13_0_1/_Done.txt ] && [ $LLVM_FOUND == 0 ]; then
echo "ERROR: LLVM 13 was not detected on your system. Please install the package 'llvm-13-dev' and try again." >&2
if [ ! -f ../extern/llvm_linux_18_1_4/_Done.txt ] && [ $LLVM_FOUND == 0 ]; then
echo "ERROR: LLVM 18 was not detected on your system. Please install the package 'llvm-18-dev' and try again." >&2
echo "ERROR: As an alternative, you can compile LLVM from source using the script 'extern/llvm_build.sh'." >&2
exit
fi

View file

@ -9,6 +9,7 @@ git clone --depth 1 --branch llvmorg-18.1.4 --config core.autocrlf=false https:/
@IF EXIST llvm_win64_18_1_4 GOTO HAS_CONFIG
mkdir llvm_win64_18_1_4
cd llvm_win64_18_1_4
@REM cmake ../llvm-project_18_1_4/llvm -G"Visual Studio 17 2022" -Ax64 -Thost=x64 -DLLVM_ENABLE_PROJECTS=clang -D CMAKE_MSVC_RUNTIME_LIBRARY="MultiThreaded$<$<CONFIG:Debug>:Debug>" -DLLVM_TARGETS_TO_BUILD="AArch64;ARM;X86;WebAssembly"
cmake ../llvm-project_18_1_4/llvm -G"Visual Studio 17 2022" -Ax64 -Thost=x64 -D CMAKE_MSVC_RUNTIME_LIBRARY="MultiThreaded$<$<CONFIG:Debug>:Debug>" -DLLVM_TARGETS_TO_BUILD="AArch64;ARM;X86;WebAssembly"
@IF %ERRORLEVEL% NEQ 0 GOTO HADERROR
@GOTO DOBUILD

40
extern/llvm_build.sh vendored
View file

@ -14,34 +14,34 @@ do
fi
done
if [ ! -d llvm-project_13_0_1 ]; then
if [ -f llvm-13.0.1.src.tar.xz ]; then # if user downloaded llvm-13.0.1.src.tar.xz then use it instead
tar -xf llvm-13.0.1.src.tar.xz
mkdir llvm-project_13_0_1
mv llvm-13.0.1.src llvm-project_13_0_1/llvm
else # shallow git clone llvm repo if llvm-13.0.1.src.tar.xz does not exists
git clone --depth 1 --branch llvmorg-13.0.1 https://github.com/llvm/llvm-project.git llvm-project_13_0_1
if [ ! -d llvm-project_18_1_4 ]; then
if [ -f llvm-18.1.4.src.tar.xz ]; then # if user downloaded llvm-18.1.4.src.tar.xz then use it instead
tar -xf llvm-18.1.4.src.tar.xz
mkdir llvm-project_18_1_4
mv llvm-18.1.4.src llvm-project_18_1_4/llvm
else # shallow git clone llvm repo if llvm-18.1.4.src.tar.xz does not exists
git clone --depth 1 --branch llvmorg-18.1.4 https://github.com/llvm/llvm-project.git llvm-project_18_1_4
fi
fi #end if llvm-project_13_0_1 exists
fi #end if llvm-project_18_1_4 exists
if [ ! -d llvm_linux_13_0_1 ]; then
mkdir llvm_linux_13_0_1
if [ ! -d llvm_linux_18_1_4 ]; then
mkdir llvm_linux_18_1_4
fi
if [ ! -d llvm_linux_13_0_1/bin ] || [ $FORCE_BUILD == 1 ]; then
cd llvm_linux_13_0_1
cmake $USE_NINJA ../llvm-project_13_0_1/llvm -DLLVM_TARGETS_TO_BUILD="AArch64;ARM;X86;WebAssembly" -DCMAKE_BUILD_TYPE:String="Debug"
if [ ! -d llvm_linux_18_1_4/bin ] || [ $FORCE_BUILD == 1 ]; then
cd llvm_linux_18_1_4
cmake $USE_NINJA ../llvm-project_18_1_4/llvm -DLLVM_TARGETS_TO_BUILD="AArch64;ARM;X86;WebAssembly" -DCMAKE_BUILD_TYPE:String="Debug"
cmake --build . -t $(cat ../llvm_targets.txt)
cd ..
fi
if [ ! -d llvm_linux_rel_13_0_1 ]; then
mkdir llvm_linux_rel_13_0_1
if [ ! -d llvm_linux_rel_18_1_4 ]; then
mkdir llvm_linux_rel_18_1_4
fi
if [ ! -d llvm_linux_rel_13_0_1/bin ] || [ $FORCE_BUILD == 1 ]; then
cd llvm_linux_rel_13_0_1
cmake $USE_NINJA ../llvm-project_13_0_1/llvm -DLLVM_TARGETS_TO_BUILD="AArch64;ARM;X86;WebAssembly" -DCMAKE_BUILD_TYPE:String="Release"
if [ ! -d llvm_linux_rel_18_1_4/bin ] || [ $FORCE_BUILD == 1 ]; then
cd llvm_linux_rel_18_1_4
cmake $USE_NINJA ../llvm-project_18_1_4/llvm -DLLVM_TARGETS_TO_BUILD="AArch64;ARM;X86;WebAssembly" -DCMAKE_BUILD_TYPE:String="Release"
cmake --build . -t $(cat ../llvm_targets.txt)
cd ..
fi
@ -50,6 +50,6 @@ if [ ! -d ../IDE/dist/llvm/bin ]; then
mkdir ../IDE/dist/llvm
mkdir ../IDE/dist/llvm/bin
fi
cp llvm_linux_rel_13_0_1/bin/llvm-ar ../IDE/dist/llvm/bin
cp llvm_linux_rel_18_1_4/bin/llvm-ar ../IDE/dist/llvm/bin
echo done > llvm_linux_13_0_1/_Done.txt
echo done > llvm_linux_18_1_4/_Done.txt