1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-10 20:42:21 +02:00

Added changes to support CompilerExplorer

This commit is contained in:
Brian Fiete 2019-10-11 05:58:08 -07:00
parent c97b074fee
commit c9e0ab6089
20 changed files with 389 additions and 156 deletions

View file

@ -497,7 +497,10 @@ void BfCodeGenThread::RunLoop()
BP_ZONE("BfCodeGen::RunLoop.LLVM.OBJ");
String outFileName;
outFileName = request->mOutFileName + BF_OBJ_EXT;
if (request->mOptions.mAsmKind != BfAsmKind_None)
outFileName = request->mOutFileName + ".s";
else
outFileName = request->mOutFileName + BF_OBJ_EXT;
if (!llvmIRCodeGen->WriteObjectFile(outFileName, request->mOptions))
{
result.mType = BfCodeGenResult_Failed;

View file

@ -5529,7 +5529,7 @@ void BfCompiler::CompileReified()
if (typeDef->mIsPartial)
continue;
bool isAlwaysInclude = typeDef->mIsAlwaysInclude;
bool isAlwaysInclude = (typeDef->mIsAlwaysInclude) || (typeDef->mProject->mAlwaysIncludeAll);
if (typeDef->mProject->IsTestProject())
{

View file

@ -149,7 +149,8 @@ void BfContext::AssignModule(BfType* type)
BF_ASSERT(!typeInst->mModule->mIsReified);
}
BfModule* module;
BfModule* module = NULL;
bool needsModuleInit = false;
// We used to have this "IsReified" check, but we DO want to create modules for unreified types even if they remain unused.
// What was that IsReified check catching?
@ -166,20 +167,46 @@ void BfContext::AssignModule(BfType* type)
BF_ASSERT(typeProcessEntry->mType->mContext == this);
BfLogSysM("HandleTypeWorkItem: %p -> %p\n", type, typeProcessEntry->mType);
mCompiler->mStats.mTypesQueued++;
mCompiler->UpdateCompletion();
mCompiler->UpdateCompletion();
}
else
{
auto typeInst = type->ToTypeInstance();
BF_ASSERT(typeInst != NULL);
String moduleName = GenerateModuleName(typeInst);
module = new BfModule(this, moduleName);
module->mIsReified = typeInst->mIsReified;
module->mProject = typeInst->mTypeDef->mProject;
typeInst->mModule = module;
BF_ASSERT(!mLockModules);
mModules.push_back(module);
auto project = typeInst->mTypeDef->mProject;
if ((project->mSingleModule) && (typeInst->mIsReified))
{
BfModule** modulePtr = NULL;
if (mProjectModule.TryAdd(project, NULL, &modulePtr))
{
String moduleName = project->mName;
module = new BfModule(this, moduleName);
module->mIsReified = true;
module->mProject = project;
typeInst->mModule = module;
BF_ASSERT(!mLockModules);
mModules.push_back(module);
*modulePtr = module;
needsModuleInit = true;
}
else
{
module = *modulePtr;
typeInst->mModule = module;
}
}
else
{
String moduleName = GenerateModuleName(typeInst);
module = new BfModule(this, moduleName);
module->mIsReified = typeInst->mIsReified;
module->mProject = project;
typeInst->mModule = module;
BF_ASSERT(!mLockModules);
mModules.push_back(module);
needsModuleInit = true;
}
}
auto localTypeInst = type->ToTypeInstance();
@ -191,7 +218,7 @@ void BfContext::AssignModule(BfType* type)
module->mOwnedTypeInstances.push_back(localTypeInst);
}
if (!module->mIsScratchModule)
if (needsModuleInit)
module->Init();
}

View file

@ -289,6 +289,7 @@ public:
BfModule* mScratchModule;
BfModule* mUnreifiedModule;
HashSet<String> mUsedModuleNames;
Dictionary<BfProject*, BfModule*> mProjectModule;
Array<BfModule*> mModules;
Array<BfModule*> mDeletingModules;
HashSet<BfTypeInstance*> mFailTypes; // All types handled after a failure need to be rebuild on subsequent compile

View file

@ -3415,7 +3415,8 @@ static void AddFunctionSimplificationPasses(llvm::legacy::PassManagerBase &MPM,
//if (EnableGVNHoist)
if (options.mEnableGVNHoist)
MPM.add(llvm::createGVNHoistPass());
if (options.mEnableGVNSink) {
if (options.mEnableGVNSink)
{
MPM.add(llvm::createGVNSinkPass());
MPM.add(llvm::createCFGSimplificationPass());
}
@ -4047,7 +4048,7 @@ bool BfIRCodeGen::WriteObjectFile(const StringImpl& outFileName, const BfCodeGen
{
// Ask the target to add backend passes as necessary.
if (target->addPassesToEmitFile(PM, out, NULL,
llvm::TargetMachine::CGFT_ObjectFile,
(codeGenOptions.mAsmKind != BfAsmKind_None) ? llvm::TargetMachine::CGFT_AssemblyFile : llvm::TargetMachine::CGFT_ObjectFile,
//TargetMachine::CGFT_AssemblyFile,
noVerify /*, StartAfterID, StopAfterID*/))
{
@ -4110,6 +4111,12 @@ const char* BfIRCodeGen::GetIntrinsicName(int intrinId)
return gIntrinEntries[intrinId].mName;
}
void BfIRCodeGen::SetAsmKind(BfAsmKind asmKind)
{
const char* args[] = {"", (asmKind == BfAsmKind_ATT) ? "-x86-asm-syntax=att" : "-x86-asm-syntax=intel" };
llvm::cl::ParseCommandLineOptions(2, args);
}
#ifdef BF_PLATFORM_LINUX
//HACK: I don't know why this is needed, but we get link errors if we don't have it.
int BF_LinuxFixLinkage()

View file

@ -141,6 +141,7 @@ public:
static int GetIntrinsicId(const StringImpl& name);
static const char* GetIntrinsicName(int intrinId);
static void SetAsmKind(BfAsmKind asmKind);
};
NS_BF_END

View file

@ -4407,11 +4407,6 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary<int, int>& usedStrin
typeFlags |= BfTypeFlags_Union;
if (type->IsDelegate())
typeFlags |= BfTypeFlags_Delegate;
if (typeInstance != NULL)
{
if (typeInstance->mTypeDef == mCompiler->mPointerTTypeDef)
typeFlags |= BfTypeFlags_Sys_PointerT;
}
if (type->WantsGCMarking())
typeFlags |= BfTypeFlags_WantsMarking;
@ -20413,7 +20408,7 @@ void BfModule::DbgFinish()
needForceLinking = true;
}
if (needForceLinking)
if ((needForceLinking) && (mProject->mCodeGenOptions.mAsmKind == BfAsmKind_None))
{
BfMethodState methodState;
SetAndRestoreValue<BfMethodState*> prevMethodState(mCurMethodState, &methodState);
@ -20510,13 +20505,6 @@ bool BfModule::Finish()
BF_ASSERT((int)mOutFileNames.size() >= mExtensionCount);
bool writeModule = mBfIRBuilder->HasExports();
// if ((!writeModule) && (!IsOptimized()))
// {
// CreateForceLinkMarker(this);
// mHasForceLinkMarker = true;
// writeModule = true;
// }
String outputPath;
BfCodeGenOptions codeGenOptions = mProject->mCodeGenOptions;

View file

@ -3468,6 +3468,11 @@ void BfModule::DoTypeInstanceMethodProcessing(BfTypeInstance* typeInstance)
attributes = attributes->mNextAttribute;
}
if ((mProject != NULL) && (mProject->mAlwaysIncludeAll) && (methodDef->mBody != NULL))
{
implRequired = true;
declRequired = true;
}
if (typeInstance->IsInterface())
declRequired = true;
@ -8671,7 +8676,9 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp
// * <-> Var
if ((typedVal.mType->IsVar()) || (toType->IsVar()))
{
BF_ASSERT((mCurMethodInstance->mIsUnspecialized) || (mCurMethodState->mClosureState != NULL) || (mHadVarUsage));
BF_ASSERT(((mCurMethodInstance != NULL) && (mCurMethodInstance->mIsUnspecialized)) ||
((mCurMethodState != NULL) && (mCurMethodState->mClosureState != NULL)) ||
(mHadVarUsage));
return GetDefaultValue(toType);
}

View file

@ -9,6 +9,7 @@
#include "BfAutoComplete.h"
#include "BfResolvePass.h"
#include "MemReporter.h"
#include "BfIRCodeGen.h"
#include "BeefySysLib/util/AllocDebug.h"
@ -840,8 +841,11 @@ bool BfTypeDef::HasSource(BfSource* source)
BfProject::BfProject()
{
mDisabled = false;
mSingleModule = false;
mTargetType = BfTargetType_BeefConsoleApplication;
mBuildConfigChanged = false;
mSingleModule = false;
mAlwaysIncludeAll = false;
mSystem = NULL;
mIdx = -1;
}
@ -3588,7 +3592,7 @@ BF_EXPORT void BF_CALLTYPE BfProject_SetDisabled(BfProject* bfProject, bool disa
}
BF_EXPORT void BF_CALLTYPE BfProject_SetOptions(BfProject* bfProject, int targetType, const char* startupObject, const char* preprocessorMacros,
int optLevel, int ltoType, bool mergeFunctions, bool combineLoads, bool vectorizeLoops, bool vectorizeSLP)
int optLevel, int ltoType, BfProjectFlags flags)
{
bfProject->mTargetType = (BfTargetType)targetType;
bfProject->mStartupObject = startupObject;
@ -3596,11 +3600,27 @@ BF_EXPORT void BF_CALLTYPE BfProject_SetOptions(BfProject* bfProject, int target
BfCodeGenOptions codeGenOptions;
codeGenOptions.mOptLevel = (BfOptLevel)optLevel;
codeGenOptions.mLTOType = (BfLTOType)ltoType;
codeGenOptions.mMergeFunctions = mergeFunctions;
codeGenOptions.mLoadCombine = combineLoads;
codeGenOptions.mLoopVectorize = vectorizeLoops;
codeGenOptions.mSLPVectorize = vectorizeSLP;
codeGenOptions.mMergeFunctions = (flags & BfProjectFlags_MergeFunctions) != 0;
codeGenOptions.mLoadCombine = (flags & BfProjectFlags_CombineLoads) != 0;
codeGenOptions.mLoopVectorize = (flags & BfProjectFlags_VectorizeLoops) != 0;
codeGenOptions.mSLPVectorize = (flags & BfProjectFlags_VectorizeSLP) != 0;
if ((flags & BfProjectFlags_AsmOutput) != 0)
{
static bool setLLVMAsmKind = false;
if ((flags & BfProjectFlags_AsmOutput_ATT) != 0)
codeGenOptions.mAsmKind = BfAsmKind_ATT;
else
codeGenOptions.mAsmKind = BfAsmKind_Intel;
if (!setLLVMAsmKind)
{
setLLVMAsmKind = true;
BfIRCodeGen::SetAsmKind(codeGenOptions.mAsmKind);
}
}
bfProject->mCodeGenOptions = codeGenOptions;
bfProject->mSingleModule = (flags & BfProjectFlags_SingleModule) != 0;
bfProject->mAlwaysIncludeAll = (flags & BfProjectFlags_AlwaysIncludeAll) != 0;
bfProject->mPreprocessorMacros.Clear();

View file

@ -154,7 +154,7 @@ enum BfTypeFlags
BfTypeFlags_SizedArray = 0x0800,
BfTypeFlags_Splattable = 0x1000,
BfTypeFlags_Union = 0x2000,
BfTypeFlags_Sys_PointerT = 0x4000,
//
BfTypeFlags_WantsMarking = 0x8000,
BfTypeFlags_Delegate = 0x10000,
BfTypeFlags_HasDestructor = 0x20000,
@ -209,6 +209,13 @@ enum BfSIMDSetting
BfSIMDSetting_AVX2,
};
enum BfAsmKind
{
BfAsmKind_None,
BfAsmKind_ATT,
BfAsmKind_Intel,
};
enum BfOptLevel
{
BfOptLevel_NotSet = -1,
@ -240,8 +247,9 @@ struct BfCodeGenOptions
bool mIsHotCompile;
bool mWriteObj;
BfAsmKind mAsmKind;
bool mWriteToLib;
bool mWriteLLVMIR;
bool mWriteLLVMIR;
int16 mVirtualMethodOfs;
int16 mDynSlotOfs;
@ -289,8 +297,9 @@ struct BfCodeGenOptions
BfCodeGenOptions()
{
mIsHotCompile = false;
mIsHotCompile = false;
mWriteObj = true;
mAsmKind = BfAsmKind_None;
mWriteToLib = false;
mWriteLLVMIR = false;
mVirtualMethodOfs = 0;
@ -921,6 +930,19 @@ enum BfTargetType
BfTargetType_BeefTest
};
enum BfProjectFlags
{
BfProjectFlags_None = 0,
BfProjectFlags_MergeFunctions = 1,
BfProjectFlags_CombineLoads = 2,
BfProjectFlags_VectorizeLoops = 4,
BfProjectFlags_VectorizeSLP = 8,
BfProjectFlags_SingleModule = 0x10,
BfProjectFlags_AsmOutput = 0x20,
BfProjectFlags_AsmOutput_ATT = 0x40,
BfProjectFlags_AlwaysIncludeAll = 0x80,
};
class BfProject
{
public:
@ -930,6 +952,8 @@ public:
BfTargetType mTargetType;
BfCodeGenOptions mCodeGenOptions;
bool mDisabled;
bool mSingleModule;
bool mAlwaysIncludeAll;
int mIdx;
String mStartupObject;