1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-08 11:38:21 +02:00

Added TargetTriple, fixed asm stuff for non-x86 LLVM

This commit is contained in:
Brian Fiete 2019-10-17 06:30:17 -07:00
parent 079574a4e7
commit e2dad5f838
8 changed files with 110 additions and 11 deletions

View file

@ -804,6 +804,9 @@ void BfIRCodeGen::Read(llvm::Metadata*& llvmMD)
void BfIRCodeGen::AddNop() void BfIRCodeGen::AddNop()
{ {
if ((mTargetTriple.GetMachineType() != BfMachineType_x86) && (mTargetTriple.GetMachineType() != BfMachineType_x64))
return;
if (mNopInlineAsm == NULL) if (mNopInlineAsm == NULL)
{ {
llvm::SmallVector<llvm::Type*, 8> paramTypes; llvm::SmallVector<llvm::Type*, 8> paramTypes;
@ -945,6 +948,7 @@ void BfIRCodeGen::HandleNextCmd()
case BfIRCmd_Module_SetTargetTriple: case BfIRCmd_Module_SetTargetTriple:
{ {
CMD_PARAM(String, targetTriple); CMD_PARAM(String, targetTriple);
mTargetTriple.Set(targetTriple);
if (targetTriple.IsEmpty()) if (targetTriple.IsEmpty())
mLLVMModule->setTargetTriple(llvm::sys::getDefaultTargetTriple()); mLLVMModule->setTargetTriple(llvm::sys::getDefaultTargetTriple());
else else
@ -2088,6 +2092,12 @@ void BfIRCodeGen::HandleNextCmd()
case BfIRIntrinsic_AtomicFence: case BfIRIntrinsic_AtomicFence:
{ {
if (args.size() == 0) if (args.size() == 0)
{
if ((mTargetTriple.GetMachineType() != BfMachineType_x86) && (mTargetTriple.GetMachineType() != BfMachineType_x64))
{
Fail("Unable to create compiler barrier on this platform");
}
else
{ {
// Compiler barrier // Compiler barrier
@ -2096,6 +2106,7 @@ void BfIRCodeGen::HandleNextCmd()
auto fenceFunc = llvm::InlineAsm::get(funcType, auto fenceFunc = llvm::InlineAsm::get(funcType,
"", "~{memory},~{dirflag},~{fpsr},~{flags}", true, false, llvm::InlineAsm::AD_ATT); "", "~{memory},~{dirflag},~{fpsr},~{flags}", true, false, llvm::InlineAsm::AD_ATT);
mIRBuilder->CreateCall(fenceFunc); mIRBuilder->CreateCall(fenceFunc);
}
break; break;
} }
@ -2611,6 +2622,10 @@ void BfIRCodeGen::HandleNextCmd()
CMD_PARAM(bool, useAsm); CMD_PARAM(bool, useAsm);
auto curLLVMFunc = mActiveFunction; auto curLLVMFunc = mActiveFunction;
auto irBuilder = mIRBuilder; auto irBuilder = mIRBuilder;
if ((mTargetTriple.GetMachineType() != BfMachineType_x86) && (mTargetTriple.GetMachineType() != BfMachineType_x64))
useAsm = false;
if (!useAsm) if (!useAsm)
{ {
// This is generates slower code than the inline asm in debug mode, but can optimize well in release // This is generates slower code than the inline asm in debug mode, but can optimize well in release
@ -4098,9 +4113,9 @@ bool BfIRCodeGen::WriteIR(const StringImpl& outFileName, StringImpl& error)
int BfIRCodeGen::GetIntrinsicId(const StringImpl& name) int BfIRCodeGen::GetIntrinsicId(const StringImpl& name)
{ {
llvm::Intrinsic::ID intrin = llvm::Intrinsic::getIntrinsicForGCCBuiltin("x86", name.c_str()); // llvm::Intrinsic::ID intrin = llvm::Intrinsic::getIntrinsicForGCCBuiltin("x86", name.c_str());
if (intrin != llvm::Intrinsic::not_intrinsic) // if (intrin != llvm::Intrinsic::not_intrinsic)
return (int)intrin; // return (int)intrin;
auto itr = std::lower_bound(std::begin(gIntrinEntries), std::end(gIntrinEntries), name); auto itr = std::lower_bound(std::begin(gIntrinEntries), std::end(gIntrinEntries), name);
if (itr != std::end(gIntrinEntries) && strcmp(itr->mName, name.c_str()) == 0) if (itr != std::end(gIntrinEntries) && strcmp(itr->mName, name.c_str()) == 0)
@ -4163,8 +4178,14 @@ void BfIRCodeGen::StaticInit()
LLVMInitializeX86TargetInfo(); LLVMInitializeX86TargetInfo();
LLVMInitializeX86Target(); LLVMInitializeX86Target();
LLVMInitializeX86TargetMC(); LLVMInitializeX86TargetMC();
LLVMInitializeX86AsmPrinter();
LLVMInitializeX86AsmParser();
LLVMInitializeX86Disassembler();
LLVMInitializeAArch64TargetInfo(); LLVMInitializeAArch64TargetInfo();
LLVMInitializeAArch64Target(); LLVMInitializeAArch64Target();
LLVMInitializeAArch64TargetMC(); LLVMInitializeAArch64TargetMC();
LLVMInitializeAArch64AsmPrinter();
//LLVMInitializeAArch64Parser();
//LLVMInitializeX86Disassembler();
} }

View file

@ -2,6 +2,7 @@
#include "BfIRBuilder.h" #include "BfIRBuilder.h"
#include "BfSystem.h" #include "BfSystem.h"
#include "BfTargetTriple.h"
NS_BF_BEGIN NS_BF_BEGIN
@ -53,6 +54,7 @@ class BfIRCodeGen : public BfIRCodeGenBase
public: public:
BfIRBuilder* mBfIRBuilder; BfIRBuilder* mBfIRBuilder;
BfTargetTriple mTargetTriple;
String mModuleName; String mModuleName;
llvm::LLVMContext* mLLVMContext; llvm::LLVMContext* mLLVMContext;
llvm::Module* mLLVMModule; llvm::Module* mLLVMModule;

View file

@ -206,8 +206,10 @@ enum BfCustomAttributeFlags
enum BfMachineType enum BfMachineType
{ {
BfMachineType_Unknown,
BfMachineType_x86, BfMachineType_x86,
BfMachineType_x64 BfMachineType_x64,
BfMachineType_AArch64
}; };
enum BfToolsetType enum BfToolsetType

View file

@ -0,0 +1,42 @@
#include "BfTargetTriple.h"
USING_NS_BF;
BfTargetTriple::BfTargetTriple()
{
mParsed = true;
mMachineType = BfMachineType_Unknown;
}
BfTargetTriple::BfTargetTriple(const StringImpl& targetTriple)
{
mParsed = false;
mMachineType = BfMachineType_Unknown;
mTargetTriple = targetTriple;
}
void BfTargetTriple::Parse()
{
if (mTargetTriple.StartsWith("x86_64"))
mMachineType = BfMachineType_x64;
else if ((mTargetTriple.StartsWith("i686")) || (mTargetTriple.StartsWith("x86")))
mMachineType = BfMachineType_x64;
else if ((mTargetTriple.StartsWith("aarch64")) || (mTargetTriple.StartsWith("arm64")))
mMachineType = BfMachineType_AArch64;
else
mMachineType = BfMachineType_Unknown;
mParsed = true;
}
void BfTargetTriple::Set(const StringImpl& targetTriple)
{
mTargetTriple = targetTriple;
mParsed = false;
}
BfMachineType BfTargetTriple::GetMachineType()
{
if (!mParsed)
Parse();
return mMachineType;
}

View file

@ -0,0 +1,24 @@
#pragma once
#include "BfSystem.h"
NS_BF_BEGIN
class BfTargetTriple
{
public:
String mTargetTriple;
bool mParsed;
BfMachineType mMachineType;
public:
void Parse();
public:
BfTargetTriple();
BfTargetTriple(const StringImpl& targetTriple);
void Set(const StringImpl& targetTriple);
BfMachineType GetMachineType();
};
NS_BF_END

View file

@ -327,6 +327,7 @@
<ClCompile Include="Compiler\BfSourcePositionFinder.cpp" /> <ClCompile Include="Compiler\BfSourcePositionFinder.cpp" />
<ClCompile Include="Compiler\BfStmtEvaluator.cpp" /> <ClCompile Include="Compiler\BfStmtEvaluator.cpp" />
<ClCompile Include="Compiler\BfSystem.cpp" /> <ClCompile Include="Compiler\BfSystem.cpp" />
<ClCompile Include="Compiler\BfTargetTriple.cpp" />
<ClCompile Include="Compiler\BfUtil.cpp" /> <ClCompile Include="Compiler\BfUtil.cpp" />
<ClCompile Include="Compiler\BfVarDeclChecker.cpp" /> <ClCompile Include="Compiler\BfVarDeclChecker.cpp" />
<ClCompile Include="Compiler\MemReporter.cpp" /> <ClCompile Include="Compiler\MemReporter.cpp" />
@ -390,6 +391,7 @@
<ClInclude Include="Compiler\BfSourceClassifier.h" /> <ClInclude Include="Compiler\BfSourceClassifier.h" />
<ClInclude Include="Compiler\BfSourcePositionFinder.h" /> <ClInclude Include="Compiler\BfSourcePositionFinder.h" />
<ClInclude Include="Compiler\BfSystem.h" /> <ClInclude Include="Compiler\BfSystem.h" />
<ClInclude Include="Compiler\BfTargetTriple.h" />
<ClInclude Include="Compiler\BfType.h" /> <ClInclude Include="Compiler\BfType.h" />
<ClInclude Include="Compiler\BfCompiler.h" /> <ClInclude Include="Compiler\BfCompiler.h" />
<ClInclude Include="Compiler\BfUtil.h" /> <ClInclude Include="Compiler\BfUtil.h" />

View file

@ -202,6 +202,9 @@
<ClCompile Include="Compiler\BfVarDeclChecker.cpp"> <ClCompile Include="Compiler\BfVarDeclChecker.cpp">
<Filter>Debugger</Filter> <Filter>Debugger</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="Compiler\BfTargetTriple.cpp">
<Filter>Debugger</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="Compiler\BfAst.h"> <ClInclude Include="Compiler\BfAst.h">
@ -383,5 +386,8 @@
</ClInclude> </ClInclude>
<ClInclude Include="NetManager.h" /> <ClInclude Include="NetManager.h" />
<ClInclude Include="Compiler\BfVarDeclChecker.h" /> <ClInclude Include="Compiler\BfVarDeclChecker.h" />
<ClInclude Include="Compiler\BfTargetTriple.h">
<Filter>Compiler</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
</Project> </Project>