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

Added Target CPU workspace override

This commit is contained in:
Brian Fiete 2022-01-25 07:04:54 -05:00
parent 91e856fc0b
commit 125d5c0c8c
14 changed files with 34 additions and 13 deletions

View file

@ -127,7 +127,7 @@ namespace IDE.Compiler
[CallingConvention(.Stdcall), CLink]
static extern void BfCompiler_SetOptions(void* bfCompiler,
void* hotProject, int32 hotIdx, char8* targetTriple, int32 toolsetType, int32 simdSetting, int32 allocStackCount, int32 maxWorkerThreads,
void* hotProject, int32 hotIdx, char8* targetTriple, char8* targetCPU, int32 toolsetType, int32 simdSetting, int32 allocStackCount, int32 maxWorkerThreads,
OptionFlags optionsFlags, char8* mallocName, char8* freeName);
[CallingConvention(.Stdcall), CLink]
@ -302,12 +302,12 @@ namespace IDE.Compiler
}
public void SetOptions(BfProject hotProject, int32 hotIdx,
String targetTriple, int32 toolsetType, int32 simdSetting, int32 allocStackCount, int32 maxWorkerThreads,
String targetTriple, String targetCPU, int32 toolsetType, int32 simdSetting, int32 allocStackCount, int32 maxWorkerThreads,
OptionFlags optionFlags, String mallocFuncName, String freeFuncName)
{
BfCompiler_SetOptions(mNativeBfCompiler,
(hotProject != null) ? hotProject.mNativeBfProject : null, hotIdx,
targetTriple, toolsetType, simdSetting, allocStackCount, maxWorkerThreads, optionFlags, mallocFuncName, freeFuncName);
targetTriple, targetCPU, toolsetType, simdSetting, allocStackCount, maxWorkerThreads, optionFlags, mallocFuncName, freeFuncName);
}
public void ForceRebuild()
@ -699,8 +699,8 @@ namespace IDE.Compiler
//Debug.WriteLine("HandleOptions SetOptions:{0:X}", (int)optionFlags);
SetOptions(hotBfProject, hotIdx,
targetTriple, (int32)options.mToolsetType, (int32)options.mBfSIMDSetting, (int32)options.mAllocStackTraceDepth, (int32)gApp.mSettings.mCompilerSettings.mWorkerThreads,
optionFlags, mallocLinkName, freeLinkName);
targetTriple, options.mTargetCPU, (int32)options.mToolsetType, (int32)options.mBfSIMDSetting, (int32)options.mAllocStackTraceDepth,
(int32)gApp.mSettings.mCompilerSettings.mWorkerThreads, optionFlags, mallocLinkName, freeLinkName);
if (!mIsResolveOnly)
{

View file

@ -240,6 +240,8 @@ namespace IDE
[Reflect]
public IntermediateType mIntermediateType;
[Reflect]
public String mTargetCPU = new String() ~ delete _;
[Reflect]
public BuildOptions.SIMDSetting mBfSIMDSetting = .SSE2;
[Reflect]
public BuildOptions.BfOptimizationLevel mBfOptimizationLevel;
@ -317,6 +319,7 @@ namespace IDE
mIncrementalBuild = prev.mIncrementalBuild;
mIntermediateType = prev.mIntermediateType;
mTargetCPU.Set(prev.mTargetCPU);
mBfSIMDSetting = prev.mBfSIMDSetting;
mBfOptimizationLevel = prev.mBfOptimizationLevel;
mCSIMDSetting = prev.mCSIMDSetting;
@ -738,6 +741,7 @@ namespace IDE
data.ConditionalAdd("Toolset", options.mToolsetType, ToolsetType.GetDefaultFor(platformType, isRelease));
data.ConditionalAdd("BuildKind", options.mBuildKind, isTest ? .Test : .Normal);
data.ConditionalAdd("TargetCPU", options.mTargetCPU);
data.ConditionalAdd("BfSIMDSetting", options.mBfSIMDSetting, .SSE2);
if (platformType == .Windows)
data.ConditionalAdd("BfOptimizationLevel", options.mBfOptimizationLevel, isRelease ? .O2 : (platformName == "Win64") ? .OgPlus : .O0);
@ -1041,6 +1045,7 @@ namespace IDE
options.mToolsetType = data.GetEnum<ToolsetType>("Toolset", ToolsetType.GetDefaultFor(platformType, isRelease));
options.mBuildKind = data.GetEnum<BuildKind>("BuildKind", isTest ? .Test : .Normal);
data.GetString("TargetCPU", options.mTargetCPU);
options.mBfSIMDSetting = data.GetEnum<BuildOptions.SIMDSetting>("BfSIMDSetting", .SSE2);
if (platformType == .Windows)
options.mBfOptimizationLevel = data.GetEnum<BuildOptions.BfOptimizationLevel>("BfOptimizationLevel", isRelease ? .O2 : (platformName == "Win64") ? .OgPlus : .O0);

View file

@ -775,6 +775,7 @@ namespace IDE.ui
return false;
});
allocPropEntry.mOnUpdate();
AddPropertiesItem(category, "Target CPU", "mTargetCPU");
AddPropertiesItem(category, "SIMD Instructions", "mBfSIMDSetting");
AddPropertiesItem(category, "Optimization Level", "mBfOptimizationLevel",
scope String[] ( "O0", "O1", "O2", "O3", "Og", "Og+"));

View file

@ -1117,7 +1117,9 @@ void BeIRCodeGen::HandleNextCmd()
case BfIRCmd_Module_SetTargetTriple:
{
CMD_PARAM(String, targetTriple);
mBeModule->mTargetTriple = targetTriple;
CMD_PARAM(String, targetCPU);
mBeModule->mTargetTriple = targetTriple;
mBeModule->mTargetCPU = targetCPU;
}
break;
case BfIRCmd_Module_AddModuleFlag:

View file

@ -16040,13 +16040,16 @@ BeMCOperand BeMCContext::AllocBinaryOp(BeMCInstKind instKind, const BeMCOperand&
}
void BeMCContext::Generate(BeFunction* function)
{
{
BP_ZONE_F("BeMCContext::Generate %s", function->mName.c_str());
mBeFunction = function;
mDbgFunction = mBeFunction->mDbgFunction;
mModule = function->mModule;
if (!mModule->mTargetCPU.IsEmpty())
mModule->mBeIRCodeGen->Fail(StrFormat("Cannot set Target CPU '%s' for +Og optimization. Considering compiling under a different optimization setting.", mModule->mTargetCPU.c_str()));
//mDbgPreferredRegs[15] = X64Reg_RCX;
//mDbgPreferredRegs[7] = X64Reg_RCX;
/*mDbgPreferredRegs[14] = X64Reg_RAX;

View file

@ -1769,6 +1769,9 @@ BeModule::BeModule(const StringImpl& moduleName, BeContext* context)
void BeModule::Hash(BeHashContext& hashCtx)
{
hashCtx.MixinStr(mTargetTriple);
hashCtx.MixinStr(mTargetCPU);
hashCtx.Mixin(mConfigConsts64.size());
for (auto configConst : mConfigConsts64)
configConst->HashContent(hashCtx);

View file

@ -2271,6 +2271,7 @@ public:
BeContext* mContext;
String mModuleName;
String mTargetTriple;
String mTargetCPU;
BeBlock* mActiveBlock;
int mInsertPos;
BeDbgLoc* mCurDbgLoc;

View file

@ -9651,7 +9651,7 @@ static BfPlatformType GetPlatform(StringView str)
}
BF_EXPORT void BF_CALLTYPE BfCompiler_SetOptions(BfCompiler* bfCompiler, BfProject* hotProject, int hotIdx,
const char* targetTriple, int toolsetType, int simdSetting, int allocStackCount, int maxWorkerThreads,
const char* targetTriple, const char* targetCPU, int toolsetType, int simdSetting, int allocStackCount, int maxWorkerThreads,
BfCompilerOptionFlags optionFlags, char* mallocLinkName, char* freeLinkName)
{
BfLogSys(bfCompiler->mSystem, "BfCompiler_SetOptions\n");
@ -9664,6 +9664,7 @@ BF_EXPORT void BF_CALLTYPE BfCompiler_SetOptions(BfCompiler* bfCompiler, BfProje
options->mHotProject = hotProject;
options->mHotCompileIdx = hotIdx;
options->mTargetTriple = targetTriple;
options->mTargetCPU = targetCPU;
if (options->mTargetTriple.StartsWith("x86_64-"))
options->mMachineType = BfMachineType_x64;

View file

@ -96,6 +96,7 @@ public:
int32 mForceRebuildIdx;
BfCompileOnDemandKind mCompileOnDemandKind;
String mTargetTriple;
String mTargetCPU;
BfPlatformType mPlatformType;
BfMachineType mMachineType;
int mCLongSize;

View file

@ -2020,9 +2020,9 @@ void BfIRBuilder::WriteIR(const StringImpl& fileName)
NEW_CMD_INSERTED;
}
void BfIRBuilder::Module_SetTargetTriple(const StringImpl& targetTriple)
void BfIRBuilder::Module_SetTargetTriple(const StringImpl& targetTriple, const StringImpl& targetCPU)
{
WriteCmd(BfIRCmd_Module_SetTargetTriple, targetTriple);
WriteCmd(BfIRCmd_Module_SetTargetTriple, targetTriple, targetCPU);
NEW_CMD_INSERTED;
}

View file

@ -1167,7 +1167,7 @@ public:
void RemoveIRCodeGen();
void WriteIR(const StringImpl& fileName);
void Module_SetTargetTriple(const StringImpl& targetTriple);
void Module_SetTargetTriple(const StringImpl& targetTriple, const StringImpl& targetCPU);
void Module_AddModuleFlag(const StringImpl& flag, int val);
BfIRType GetPrimitiveType(BfTypeCode typeCode);

View file

@ -1645,7 +1645,7 @@ void BfIRCodeGen::InitTarget()
llvm::Triple theTriple = llvm::Triple(mLLVMModule->getTargetTriple());
llvm::CodeGenOpt::Level optLvl = llvm::CodeGenOpt::None;
String cpuName = "";
String cpuName = mTargetCPU;
String arch = "";
// Get the target specific parser.
@ -1761,7 +1761,10 @@ void BfIRCodeGen::HandleNextCmd()
case BfIRCmd_Module_SetTargetTriple:
{
CMD_PARAM(String, targetTriple);
CMD_PARAM(String, targetCPU);
mTargetTriple.Set(targetTriple);
mTargetCPU = targetCPU;
if (targetTriple.IsEmpty())
mLLVMModule->setTargetTriple(llvm::sys::getDefaultTargetTriple());
else

View file

@ -89,6 +89,7 @@ public:
BumpAllocator mAlloc;
BfTargetTriple mTargetTriple;
String mTargetCPU;
String mModuleName;
llvm::LLVMContext* mLLVMContext;
llvm::Module* mLLVMModule;

View file

@ -1012,7 +1012,7 @@ void BfModule::FinishInit()
mBfIRBuilder->Start(mModuleName, mCompiler->mSystem->mPtrSize, IsOptimized());
mBfIRBuilder->Module_SetTargetTriple(mCompiler->mOptions.mTargetTriple);
mBfIRBuilder->Module_SetTargetTriple(mCompiler->mOptions.mTargetTriple, mCompiler->mOptions.mTargetCPU);
mBfIRBuilder->SetBackend(IsTargetingBeefBackend());