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:
parent
079574a4e7
commit
e2dad5f838
8 changed files with 110 additions and 11 deletions
|
@ -804,6 +804,9 @@ void BfIRCodeGen::Read(llvm::Metadata*& llvmMD)
|
|||
|
||||
void BfIRCodeGen::AddNop()
|
||||
{
|
||||
if ((mTargetTriple.GetMachineType() != BfMachineType_x86) && (mTargetTriple.GetMachineType() != BfMachineType_x64))
|
||||
return;
|
||||
|
||||
if (mNopInlineAsm == NULL)
|
||||
{
|
||||
llvm::SmallVector<llvm::Type*, 8> paramTypes;
|
||||
|
@ -945,6 +948,7 @@ void BfIRCodeGen::HandleNextCmd()
|
|||
case BfIRCmd_Module_SetTargetTriple:
|
||||
{
|
||||
CMD_PARAM(String, targetTriple);
|
||||
mTargetTriple.Set(targetTriple);
|
||||
if (targetTriple.IsEmpty())
|
||||
mLLVMModule->setTargetTriple(llvm::sys::getDefaultTargetTriple());
|
||||
else
|
||||
|
@ -2089,13 +2093,20 @@ void BfIRCodeGen::HandleNextCmd()
|
|||
{
|
||||
if (args.size() == 0)
|
||||
{
|
||||
// Compiler barrier
|
||||
if ((mTargetTriple.GetMachineType() != BfMachineType_x86) && (mTargetTriple.GetMachineType() != BfMachineType_x64))
|
||||
{
|
||||
Fail("Unable to create compiler barrier on this platform");
|
||||
}
|
||||
else
|
||||
{
|
||||
// Compiler barrier
|
||||
|
||||
llvm::SmallVector<llvm::Type*, 8> paramTypes;
|
||||
llvm::FunctionType* funcType = llvm::FunctionType::get(llvm::Type::getVoidTy(*mLLVMContext), paramTypes, false);
|
||||
auto fenceFunc = llvm::InlineAsm::get(funcType,
|
||||
"", "~{memory},~{dirflag},~{fpsr},~{flags}", true, false, llvm::InlineAsm::AD_ATT);
|
||||
mIRBuilder->CreateCall(fenceFunc);
|
||||
llvm::SmallVector<llvm::Type*, 8> paramTypes;
|
||||
llvm::FunctionType* funcType = llvm::FunctionType::get(llvm::Type::getVoidTy(*mLLVMContext), paramTypes, false);
|
||||
auto fenceFunc = llvm::InlineAsm::get(funcType,
|
||||
"", "~{memory},~{dirflag},~{fpsr},~{flags}", true, false, llvm::InlineAsm::AD_ATT);
|
||||
mIRBuilder->CreateCall(fenceFunc);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -2611,6 +2622,10 @@ void BfIRCodeGen::HandleNextCmd()
|
|||
CMD_PARAM(bool, useAsm);
|
||||
auto curLLVMFunc = mActiveFunction;
|
||||
auto irBuilder = mIRBuilder;
|
||||
|
||||
if ((mTargetTriple.GetMachineType() != BfMachineType_x86) && (mTargetTriple.GetMachineType() != BfMachineType_x64))
|
||||
useAsm = false;
|
||||
|
||||
if (!useAsm)
|
||||
{
|
||||
// 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)
|
||||
{
|
||||
llvm::Intrinsic::ID intrin = llvm::Intrinsic::getIntrinsicForGCCBuiltin("x86", name.c_str());
|
||||
if (intrin != llvm::Intrinsic::not_intrinsic)
|
||||
return (int)intrin;
|
||||
// llvm::Intrinsic::ID intrin = llvm::Intrinsic::getIntrinsicForGCCBuiltin("x86", name.c_str());
|
||||
// if (intrin != llvm::Intrinsic::not_intrinsic)
|
||||
// return (int)intrin;
|
||||
|
||||
auto itr = std::lower_bound(std::begin(gIntrinEntries), std::end(gIntrinEntries), name);
|
||||
if (itr != std::end(gIntrinEntries) && strcmp(itr->mName, name.c_str()) == 0)
|
||||
|
@ -4163,8 +4178,14 @@ void BfIRCodeGen::StaticInit()
|
|||
LLVMInitializeX86TargetInfo();
|
||||
LLVMInitializeX86Target();
|
||||
LLVMInitializeX86TargetMC();
|
||||
LLVMInitializeX86AsmPrinter();
|
||||
LLVMInitializeX86AsmParser();
|
||||
LLVMInitializeX86Disassembler();
|
||||
|
||||
LLVMInitializeAArch64TargetInfo();
|
||||
LLVMInitializeAArch64Target();
|
||||
LLVMInitializeAArch64TargetMC();
|
||||
LLVMInitializeAArch64AsmPrinter();
|
||||
//LLVMInitializeAArch64Parser();
|
||||
//LLVMInitializeX86Disassembler();
|
||||
}
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include "BfIRBuilder.h"
|
||||
#include "BfSystem.h"
|
||||
#include "BfTargetTriple.h"
|
||||
|
||||
NS_BF_BEGIN
|
||||
|
||||
|
@ -53,6 +54,7 @@ class BfIRCodeGen : public BfIRCodeGenBase
|
|||
public:
|
||||
BfIRBuilder* mBfIRBuilder;
|
||||
|
||||
BfTargetTriple mTargetTriple;
|
||||
String mModuleName;
|
||||
llvm::LLVMContext* mLLVMContext;
|
||||
llvm::Module* mLLVMModule;
|
||||
|
|
|
@ -206,8 +206,10 @@ enum BfCustomAttributeFlags
|
|||
|
||||
enum BfMachineType
|
||||
{
|
||||
BfMachineType_Unknown,
|
||||
BfMachineType_x86,
|
||||
BfMachineType_x64
|
||||
BfMachineType_x64,
|
||||
BfMachineType_AArch64
|
||||
};
|
||||
|
||||
enum BfToolsetType
|
||||
|
|
42
IDEHelper/Compiler/BfTargetTriple.cpp
Normal file
42
IDEHelper/Compiler/BfTargetTriple.cpp
Normal 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;
|
||||
}
|
24
IDEHelper/Compiler/BfTargetTriple.h
Normal file
24
IDEHelper/Compiler/BfTargetTriple.h
Normal 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
|
|
@ -327,6 +327,7 @@
|
|||
<ClCompile Include="Compiler\BfSourcePositionFinder.cpp" />
|
||||
<ClCompile Include="Compiler\BfStmtEvaluator.cpp" />
|
||||
<ClCompile Include="Compiler\BfSystem.cpp" />
|
||||
<ClCompile Include="Compiler\BfTargetTriple.cpp" />
|
||||
<ClCompile Include="Compiler\BfUtil.cpp" />
|
||||
<ClCompile Include="Compiler\BfVarDeclChecker.cpp" />
|
||||
<ClCompile Include="Compiler\MemReporter.cpp" />
|
||||
|
@ -390,6 +391,7 @@
|
|||
<ClInclude Include="Compiler\BfSourceClassifier.h" />
|
||||
<ClInclude Include="Compiler\BfSourcePositionFinder.h" />
|
||||
<ClInclude Include="Compiler\BfSystem.h" />
|
||||
<ClInclude Include="Compiler\BfTargetTriple.h" />
|
||||
<ClInclude Include="Compiler\BfType.h" />
|
||||
<ClInclude Include="Compiler\BfCompiler.h" />
|
||||
<ClInclude Include="Compiler\BfUtil.h" />
|
||||
|
|
|
@ -202,6 +202,9 @@
|
|||
<ClCompile Include="Compiler\BfVarDeclChecker.cpp">
|
||||
<Filter>Debugger</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Compiler\BfTargetTriple.cpp">
|
||||
<Filter>Debugger</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Compiler\BfAst.h">
|
||||
|
@ -383,5 +386,8 @@
|
|||
</ClInclude>
|
||||
<ClInclude Include="NetManager.h" />
|
||||
<ClInclude Include="Compiler\BfVarDeclChecker.h" />
|
||||
<ClInclude Include="Compiler\BfTargetTriple.h">
|
||||
<Filter>Compiler</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
Loading…
Add table
Add a link
Reference in a new issue