From 602c7f318fefa986588a4f8f3327c47e6dbdb2aa Mon Sep 17 00:00:00 2001 From: Brian Fiete Date: Wed, 27 Jul 2022 12:26:36 -0400 Subject: [PATCH] Trimmed trailing whitespace --- IDEHelper/Backend/BeCOFFObject.cpp | 366 ++++++++++---------- IDEHelper/Backend/BeCOFFObject.h | 34 +- IDEHelper/Backend/BeContext.cpp | 29 +- IDEHelper/Backend/BeContext.h | 34 +- IDEHelper/Backend/BeDbgModule.h | 1 - IDEHelper/Backend/BeIRCodeGen.cpp | 411 +++++++++++------------ IDEHelper/Backend/BeIRCodeGen.h | 30 +- IDEHelper/Backend/BeLibManger.cpp | 98 +++--- IDEHelper/Backend/BeLibManger.h | 11 +- IDEHelper/Backend/BeMCContext.cpp | 521 ++++++++++++++--------------- IDEHelper/Backend/BeMCContext.h | 16 +- IDEHelper/Backend/BeModule.cpp | 341 +++++++++---------- IDEHelper/Backend/BeModule.h | 270 ++++++++------- 13 files changed, 1049 insertions(+), 1113 deletions(-) diff --git a/IDEHelper/Backend/BeCOFFObject.cpp b/IDEHelper/Backend/BeCOFFObject.cpp index e01f4a0b..6a7a8354 100644 --- a/IDEHelper/Backend/BeCOFFObject.cpp +++ b/IDEHelper/Backend/BeCOFFObject.cpp @@ -74,15 +74,15 @@ void BeInlineLineBuilder::Update(BeDbgCodeEmission* codeEmission) } void BeInlineLineBuilder::Start(BeDbgCodeEmission* codeEmission) -{ +{ //mCurLine = codeEmission->mDbgLoc->mDbgInlinedAt->mLine; int lineOfs = codeEmission->mDbgLoc->mLine - mCurLine; int codeOfs = codeEmission->mPos - mCurCodePos; - + auto usingFile = codeEmission->mDbgLoc->mDbgInlinedAt->GetDbgFile(); auto wantFile = codeEmission->mDbgLoc->GetDbgFile(); - + mData.push_back(CodeViewInfo::BA_OP_ChangeLineOffset); WriteSigned(lineOfs); @@ -93,10 +93,10 @@ void BeInlineLineBuilder::Start(BeDbgCodeEmission* codeEmission) }*/ mData.push_back(CodeViewInfo::BA_OP_ChangeCodeOffset); - Compress(codeOfs); + Compress(codeOfs); mCurLine = codeEmission->mDbgLoc->mLine; - mCurCodePos = codeEmission->mPos; + mCurCodePos = codeEmission->mPos; /*mData.push_back(CodeViewInfo::BA_OP_ChangeLineOffset); WriteSigned(-mStartDbgLoc->mDbgInlinedAt->mLine - 1); @@ -122,14 +122,14 @@ void BeInlineLineBuilder::End(BeDbgCodeEmission* codeEmission) BeCOFFObject::BeCOFFObject() { mWriteToLib = false; - mBSSPos = 0; + mBSSPos = 0; mCurTagId = 0x1000; mCurStringId = 0; mCurJumpTableIdx = 0; mBeModule = NULL; mTTagStartPos = -1; mSTagStartPos = -1; - mSectionStartPos = -1; + mSectionStartPos = -1; mTypesLocked = false; mTimestamp = 0; mPerfManager = NULL; @@ -178,11 +178,11 @@ void BeCOFFObject::ToString(BeMDNode* mdNode, String& str) else { BF_FATAL("err"); - } + } } int BeCOFFObject::GetCVRegNum(X64CPURegister reg, int bits) -{ +{ if (bits == 8) { switch (reg) @@ -361,7 +361,7 @@ int BeCOFFObject::GetCVRegNum(X64CPURegister reg, int bits) case X64Reg_XMM72: return CV_AMD64_XMM7_2; case X64Reg_XMM73: return CV_AMD64_XMM7_3; } - + return 0; } @@ -400,7 +400,7 @@ void BeCOFFObject::DbgEncodeString(DynMemStream& memStream, const StringImpl& st } void BeCOFFObject::DbgMakeFuncType(BeDbgFunction* dbgFunc) -{ +{ if (dbgFunc->mCvTypeId != -1) return; @@ -435,12 +435,12 @@ void BeCOFFObject::DbgMakeFuncType(BeDbgFunction* dbgFunc) for (auto paramType : dbgFunc->mType->mParams) DbgGetTypeId(paramType); - bool hasThis = dbgFunc->HasThis(); + bool hasThis = dbgFunc->HasThis(); /*auto argListResultPair = mArgListSet.insert(dbgFunc); if (!argListResultPair.second) - { - dbgFunc->mCvArgListId = (*argListResultPair.first)->mCvArgListId; + { + dbgFunc->mCvArgListId = (*argListResultPair.first)->mCvArgListId; } else*/ @@ -457,12 +457,12 @@ void BeCOFFObject::DbgMakeFuncType(BeDbgFunction* dbgFunc) outT.Write((int32)(dbgFunc->mType->mParams.size() - (hasThis ? 1 : 0))); for (int paramIdx = hasThis ? 1 : 0; paramIdx < (int)dbgFunc->mType->mParams.size(); paramIdx++) { - BeDbgType* dbgType = dbgFunc->mType->mParams[paramIdx]; + BeDbgType* dbgType = dbgFunc->mType->mParams[paramIdx]; outT.Write(DbgGetTypeId(dbgType)); } DbgTEndTag(); } - + dbgFunc->mCvTypeId = mCurTagId++; DbgTStartTag(); @@ -504,7 +504,7 @@ void BeCOFFObject::DbgMakeFuncType(BeDbgFunction* dbgFunc) void BeCOFFObject::DbgMakeFunc(BeDbgFunction* dbgFunc) { auto& outT = mDebugTSect.mData; - BF_ASSERT(dbgFunc->mCvTypeId == -1); + BF_ASSERT(dbgFunc->mCvTypeId == -1); DbgMakeFuncType(dbgFunc); @@ -534,7 +534,7 @@ void BeCOFFObject::DbgMakeFunc(BeDbgFunction* dbgFunc) void BeCOFFObject::DbgTAlign() { int curPos = mDebugTSect.mData.GetPos(); - // Perform alignment + // Perform alignment int addPadding = (4 - (curPos & 3)) % 4; while (addPadding > 0) { @@ -544,17 +544,17 @@ void BeCOFFObject::DbgTAlign() } void BeCOFFObject::DbgTStartTag() -{ +{ BF_ASSERT(mTTagStartPos == -1); mTTagStartPos = mDebugTSect.mData.GetPos(); mDebugTSect.mData.Write((int16)0); } void BeCOFFObject::DbgTEndTag() -{ +{ BF_ASSERT(mTTagStartPos != -1); DbgTAlign(); - int tagSize = mDebugTSect.mData.GetPos() - mTTagStartPos; + int tagSize = mDebugTSect.mData.GetPos() - mTTagStartPos; BF_ASSERT(tagSize <= 0xFFFF); *((int16*)&mDebugTSect.mData.mData[mTTagStartPos]) = (int16)(tagSize - 2); mTTagStartPos = -1; @@ -576,20 +576,20 @@ int BeCOFFObject::DbgGetTypeId(BeDbgType* dbgType, bool doDefine) auto& outT = mDebugTSect.mData; auto structType = BeValueDynCast(dbgType); - + if (structType != NULL) { - //lfClass classInfo; + //lfClass classInfo; //BF_CLEAR_VALUE(classInfo); - //classInfo.leaf = LF_STRUCTURE; - - CV_prop_t structProp = { 0 }; + //classInfo.leaf = LF_STRUCTURE; + + CV_prop_t structProp = { 0 }; if (structType->mAlign == 1) structProp.packed = true; int fieldListTag = 0; - int memberCount = 0; + int memberCount = 0; if (doDefine) { // Pass over all needed types first to make sure we generate any forward references we'll need @@ -598,18 +598,18 @@ int BeCOFFObject::DbgGetTypeId(BeDbgType* dbgType, bool doDefine) DbgGetTypeId(structType->mDerivedFrom); for (auto member : structType->mMembers) { - auto type = member->mType; + auto type = member->mType; DbgGetTypeId(type); } for (auto func : structType->mMethods) - DbgMakeFuncType(func); + DbgMakeFuncType(func); fieldListTag = mCurTagId++; //int tagStartPos = -1; DbgTStartTag(); outT.Write((int16)LF_FIELDLIST); - + if (structType->mDerivedFrom != NULL) { outT.Write((int16)LF_BCLASS); @@ -629,7 +629,7 @@ int BeCOFFObject::DbgGetTypeId(BeDbgType* dbgType, bool doDefine) int extFieldListTag = mCurTagId++; outT.Write((int16)LF_INDEX); - outT.Write((int16)0); // Padding + outT.Write((int16)0); // Padding outT.Write((int32)extFieldListTag); // Padding DbgTEndTag(); @@ -639,7 +639,7 @@ int BeCOFFObject::DbgGetTypeId(BeDbgType* dbgType, bool doDefine) }; for (auto member : structType->mMembers) - { + { _CheckFieldOverflow(); if (member->mIsStatic) @@ -657,7 +657,7 @@ int BeCOFFObject::DbgGetTypeId(BeDbgType* dbgType, bool doDefine) outT.Write(*(int16*)&attr); outT.Write(DbgGetTypeId(member->mType)); if (!member->mIsStatic) - DbgEncodeConstant(outT, member->mOffset); + DbgEncodeConstant(outT, member->mOffset); DbgEncodeString(outT, member->mName); memberCount++; DbgTAlign(); @@ -706,15 +706,15 @@ int BeCOFFObject::DbgGetTypeId(BeDbgType* dbgType, bool doDefine) outT.Write((int32)0); //derivedfrom - should we ever set this? outT.Write((int32)0); //vshape if (doDefine) - DbgEncodeConstant(outT, structType->mSize); + DbgEncodeConstant(outT, structType->mSize); else DbgEncodeConstant(outT, 0); String fullName; - ToString(structType, fullName); + ToString(structType, fullName); - DbgEncodeString(outT, fullName); + DbgEncodeString(outT, fullName); DbgTEndTag(); // LF_STRUCTURE - + if (doDefine) dbgType->mCvDefTypeId = mCurTagId++; else @@ -753,9 +753,9 @@ int BeCOFFObject::DbgGetTypeId(BeDbgType* dbgType, bool doDefine) return dbgType->mCvDefTypeId; } - + return dbgType->mCvDeclTypeId; - } + } else if (auto enumType = BeValueDynCast(dbgType)) { int fieldListId = 0; @@ -766,14 +766,14 @@ int BeCOFFObject::DbgGetTypeId(BeDbgType* dbgType, bool doDefine) //int tagStartPos = -1; DbgTStartTag(); outT.Write((int16)LF_FIELDLIST); - + for (auto member : enumType->mMembers) - { + { outT.Write((int16)LF_ENUMERATE); CV_fldattr_t attr = { 0 }; attr.access = 3; // public - outT.Write(*(int16*)&attr); + outT.Write(*(int16*)&attr); DbgEncodeConstant(outT, member->mValue); DbgEncodeString(outT, member->mName); DbgTAlign(); @@ -789,13 +789,13 @@ int BeCOFFObject::DbgGetTypeId(BeDbgType* dbgType, bool doDefine) //int32 elementId = DbgGetTypeId(enumType->mElementType); - CV_prop_t structProp = { 0 }; + CV_prop_t structProp = { 0 }; if (!enumType->mIsFullyDefined) structProp.fwdref = 1; DbgTStartTag(); outT.Write((int16)LF_ENUM); - outT.Write((int16)enumType->mMembers.size()); + outT.Write((int16)enumType->mMembers.size()); outT.Write(*(int16*)&structProp); outT.Write(elementId); outT.Write((int32)fieldListId); @@ -833,7 +833,7 @@ int BeCOFFObject::DbgGetTypeId(BeDbgType* dbgType, bool doDefine) break; case llvm::dwarf::DW_ATE_float: switch (dbgBasicType->mSize) - { + { case 4: dbgBasicType->mCvDefTypeId = T_REAL32; break; case 8: dbgBasicType->mCvDefTypeId = T_REAL64; break; } @@ -914,10 +914,10 @@ int BeCOFFObject::DbgGetTypeId(BeDbgType* dbgType, bool doDefine) int32 elementId = DbgGetTypeId(ptrType->mElement); DbgTStartTag(); - outT.Write((int16)LF_POINTER); + outT.Write((int16)LF_POINTER); outT.Write(elementId); outT.Write(*(int32*)&attr); - DbgTEndTag(); + DbgTEndTag(); dbgType->mCvDeclTypeId = dbgType->mCvDefTypeId = mCurTagId++; return dbgType->mCvDefTypeId; } @@ -930,23 +930,23 @@ int BeCOFFObject::DbgGetTypeId(BeDbgType* dbgType, bool doDefine) int32 elementId = DbgGetTypeId(refType->mElement); DbgTStartTag(); - outT.Write((int16)LF_POINTER); + outT.Write((int16)LF_POINTER); outT.Write(elementId); - outT.Write(*(int32*)&attr); + outT.Write(*(int32*)&attr); DbgTEndTag(); dbgType->mCvDeclTypeId = dbgType->mCvDefTypeId = mCurTagId++; return dbgType->mCvDefTypeId; } else if (auto constType = BeValueDynCast(dbgType)) - { - CV_modifier_t attr = { 0 }; + { + CV_modifier_t attr = { 0 }; attr.MOD_const = 1; int32 elementId = DbgGetTypeId(BeValueDynCast(constType->mElement)); DbgTStartTag(); - outT.Write((int16)LF_MODIFIER); + outT.Write((int16)LF_MODIFIER); outT.Write(elementId); - outT.Write(*(int16*)&attr); + outT.Write(*(int16*)&attr); DbgTEndTag(); dbgType->mCvDeclTypeId = dbgType->mCvDefTypeId = mCurTagId++; return dbgType->mCvDefTypeId; @@ -958,7 +958,7 @@ int BeCOFFObject::DbgGetTypeId(BeDbgType* dbgType, bool doDefine) else if (auto arrayType = BeValueDynCast(dbgType)) { int32 elementId = DbgGetTypeId(arrayType->mElement); - + DbgTStartTag(); outT.Write((int16)LF_ARRAY); outT.Write((int32)elementId); @@ -968,11 +968,10 @@ int BeCOFFObject::DbgGetTypeId(BeDbgType* dbgType, bool doDefine) DbgTEndTag(); dbgType->mCvDeclTypeId = dbgType->mCvDefTypeId = mCurTagId++; return dbgType->mCvDefTypeId; - } + } else BF_FATAL("NotImpl"); - BF_FATAL("Invalid type"); return -1; } @@ -986,12 +985,12 @@ void BeCOFFObject::DbgGenerateTypeInfo() outT.Write((int)CV_SIGNATURE_C13); for (auto mdNode : mBeModule->mDbgModule->mTypes) - { + { bool defineType = true; if (auto dbgStructType = BeValueDynCast(mdNode)) { if (!dbgStructType->mIsFullyDefined) - defineType = false; + defineType = false; } if (defineType) @@ -1010,8 +1009,8 @@ void BeCOFFObject::DbgGenerateTypeInfo() void BeCOFFObject::DbgStartSection(int sectionNum) { - auto& outS = mDebugSSect.mData; - BF_ASSERT(mSectionStartPos == -1); + auto& outS = mDebugSSect.mData; + BF_ASSERT(mSectionStartPos == -1); outS.Write((int32)sectionNum); outS.Write(0); // Temporary - size mSectionStartPos = outS.GetPos(); @@ -1019,9 +1018,9 @@ void BeCOFFObject::DbgStartSection(int sectionNum) void BeCOFFObject::DbgEndSection() { - auto& outS = mDebugSSect.mData; - int totalLen = outS.GetPos() - mSectionStartPos; - *((int32*)&outS.mData[mSectionStartPos - 4]) = totalLen; + auto& outS = mDebugSSect.mData; + int totalLen = outS.GetPos() - mSectionStartPos; + *((int32*)&outS.mData[mSectionStartPos - 4]) = totalLen; mSectionStartPos = -1; while ((outS.GetPos() & 3) != 0) outS.Write((uint8)0); @@ -1030,12 +1029,12 @@ void BeCOFFObject::DbgEndSection() void BeCOFFObject::DbgStartVarDefRange(BeDbgFunction* dbgFunc, BeDbgVariable* dbgVar, const BeDbgVariableLoc& varLoc, int offset, int range) { BF_ASSERT(range >= 0); - + auto funcSym = GetSymbol(dbgFunc->mValue); auto varType = BeValueDynCast(dbgVar->mType); - auto& outS = mDebugSSect.mData; + auto& outS = mDebugSSect.mData; if (varLoc.mKind == BeDbgVariableLoc::Kind_SymbolAddr) { BF_FATAL("Not supported"); @@ -1079,10 +1078,9 @@ void BeCOFFObject::DbgStartVarDefRange(BeDbgFunction* dbgFunc, BeDbgVariable* db reloc.mSymTableIdx = funcSym->mIdx; mDebugSSect.mRelocs.push_back(reloc); outS.Write((int16)0); // section - outS.Write((int16)range); // Range + outS.Write((int16)range); // Range } - void BeCOFFObject::DbgEndLineBlock(BeDbgFunction* dbgFunc, const Array& emissions, int blockStartPos, int emissionStartIdx, int lineCount) { auto& outS = mDebugSSect.mData; @@ -1111,7 +1109,7 @@ void BeCOFFObject::DbgEndLineBlock(BeDbgFunction* dbgFunc, const Array 0) { @@ -1137,23 +1135,23 @@ void BeCOFFObject::DbgSEndTag() } void BeCOFFObject::DbgOutputLocalVar(BeDbgFunction* dbgFunc, BeDbgVariable* dbgVar) -{ +{ auto varType = BeValueDynCast(dbgVar->mType); // CodeView only allows 16-bit lengths, so we need to split ranges for very long spans if (dbgVar->mDeclEnd - dbgVar->mDeclStart > 0xFFFF) - { + { int splitPos = dbgVar->mDeclStart + 0xFFFF; BeDbgVariable varStart = *dbgVar; varStart.mDeclEnd = splitPos; Array* startArrs[2] = { &varStart.mSavedRanges, &varStart.mGaps }; for (auto& arr : startArrs) - { + { for (int arrIdx = 0; arrIdx < (int)arr->size(); arrIdx++) { auto& gap = (*arr)[arrIdx]; - + int gapStart = gap.mOffset; int gapEnd = gap.mOffset + gap.mLength; @@ -1186,17 +1184,17 @@ void BeCOFFObject::DbgOutputLocalVar(BeDbgFunction* dbgFunc, BeDbgVariable* dbgV { auto& gap = (*arr)[arrIdx]; - int gapStart = gap.mOffset; + int gapStart = gap.mOffset; if (gapStart < splitPos) gapStart = splitPos; if (gap.mLength == -1) - { + { gap.mOffset = gapStart; continue; } - int gapEnd = gap.mOffset + gap.mLength; + int gapEnd = gap.mOffset + gap.mLength; if (gapEnd < splitPos) gapEnd = splitPos; @@ -1229,13 +1227,13 @@ void BeCOFFObject::DbgOutputLocalVar(BeDbgFunction* dbgFunc, BeDbgVariable* dbgV outS.Write(*(int16*)&flags); bool isConst = false; - String varName = dbgVar->mName; + String varName = dbgVar->mName; bool isGlobal = false; // { auto checkVal = dbgVar->mValue; - + if (auto beCast = BeValueDynCast(checkVal)) checkVal = beCast->mTarget; if (auto beGlobal = BeValueDynCast(checkVal)) @@ -1278,8 +1276,8 @@ void BeCOFFObject::DbgOutputLocalVar(BeDbgFunction* dbgFunc, BeDbgVariable* dbgV { declEnd = dbgFunc->mCodeLen; if ((dbgVar->mGaps.size() == 1) && (dbgVar->mGaps[0].mOffset == dbgVar->mDeclStart) && (dbgVar->mGaps[0].mLength == -1) && (!isConst)) - { - // Variable not used + { + // Variable not used declEnd = dbgVar->mDeclStart; } } @@ -1294,7 +1292,7 @@ void BeCOFFObject::DbgOutputLocalVar(BeDbgFunction* dbgFunc, BeDbgVariable* dbgV continue; if (gap.mLength == -1) - { + { // Not a real gap, and not an unused variable indicator if (gap.mOffset > dbgVar->mDeclStart) continue; @@ -1348,7 +1346,7 @@ void BeCOFFObject::DbgOutputLocalVars(BeInlineLineBuilder* curInlineBuilder, BeD { auto& outS = mDebugSSect.mData; for (auto dbgVar : curInlineBuilder->mVariables) - { + { if (dbgVar == NULL) continue; DbgOutputLocalVar(dbgFunc, dbgVar); @@ -1362,15 +1360,15 @@ void BeCOFFObject::DbgGenerateModuleInfo() auto& outS = mDebugSSect.mData; outS.Write((int)CV_SIGNATURE_C13); - + Array fileDataPositions; Array inlinees; - + // Funcs for (auto dbgFunc : mBeModule->mDbgModule->mFuncs) { if (dbgFunc->mValue == NULL) - continue; + continue; if (dbgFunc->mCvFuncId == -1) continue; @@ -1380,9 +1378,9 @@ void BeCOFFObject::DbgGenerateModuleInfo() auto funcSym = GetSymbol(dbgFunc->mValue, false); if (funcSym == NULL) continue; - + DbgStartSection(DEBUG_S_SYMBOLS); - + DbgSStartTag(); if (dbgFunc->mValue->mLinkageType == BfIRLinkageType_Internal) outS.Write((int16)S_LPROC32_ID); @@ -1394,7 +1392,7 @@ void BeCOFFObject::DbgGenerateModuleInfo() outS.Write((int32)BF_MAX(dbgFunc->mCodeLen, 0)); // CodeSize outS.Write((int32)0); // DbgStart outS.Write((int32)0); // DbgEnd - outS.Write(dbgFunc->mCvFuncId); + outS.Write(dbgFunc->mCvFuncId); BeMCRelocation reloc; reloc.mKind = BeMCRelocationKind_SECREL; @@ -1402,7 +1400,7 @@ void BeCOFFObject::DbgGenerateModuleInfo() reloc.mSymTableIdx = funcSym->mIdx; mDebugSSect.mRelocs.push_back(reloc); outS.Write((int32)0); // off - + reloc.mKind = BeMCRelocationKind_SECTION; reloc.mOffset = outS.GetPos(); reloc.mSymTableIdx = funcSym->mIdx; @@ -1420,7 +1418,7 @@ void BeCOFFObject::DbgGenerateModuleInfo() fullName += "::"; fullName += dbgFunc->mName; DbgEncodeString(outS, fullName); - DbgSEndTag(); + DbgSEndTag(); BeInlineLineBuilder* curInlineBuilder = NULL; BeDbgLoc* curDbgLoc = NULL; @@ -1437,28 +1435,28 @@ void BeCOFFObject::DbgGenerateModuleInfo() if (curDbgLoc != newDbgLoc) { curDbgLoc = newDbgLoc; - int newInlineDepth = newDbgLoc->GetInlineDepth(); + int newInlineDepth = newDbgLoc->GetInlineDepth(); int curInlineDepth = 0; if (curInlineBuilder != NULL) curInlineDepth = curInlineBuilder->mStartDbgLoc->GetInlineDepth(); - + int depthMatch = 0; if (curInlineBuilder != NULL) - depthMatch = curDbgLoc->GetInlineMatchDepth(curInlineBuilder->mStartDbgLoc); + depthMatch = curDbgLoc->GetInlineMatchDepth(curInlineBuilder->mStartDbgLoc); while (curInlineDepth > depthMatch) - { + { curInlineBuilder->End(&codeEmission); inlineStack.pop_back(); if (inlineStack.empty()) curInlineBuilder = NULL; else - curInlineBuilder = inlineStack.back(); + curInlineBuilder = inlineStack.back(); curInlineDepth--; } // Check for new inlines while (newInlineDepth > curInlineDepth) - { + { auto inlineBuilder = inlineBuilders.Alloc(); // If we add more than one inline depth at a time then we need to set startDbgLoc appropriately int inlineIdx = newInlineDepth - curInlineDepth - 2; @@ -1472,7 +1470,7 @@ void BeCOFFObject::DbgGenerateModuleInfo() inlinees.Add(dbgFunc); inlineBuilder->mCurLine = dbgFunc->mLine; - inlineBuilder->Start(&codeEmission); + inlineBuilder->Start(&codeEmission); curInlineBuilder = inlineBuilder; inlineStack.push_back(curInlineBuilder); curInlineDepth++; @@ -1482,18 +1480,18 @@ void BeCOFFObject::DbgGenerateModuleInfo() } if (curInlineBuilder != NULL) - curInlineBuilder->Update(&codeEmission); - } + curInlineBuilder->Update(&codeEmission); + } } BF_ASSERT(inlineStack.empty()); for (auto dbgVar : dbgFunc->mVariables) { - if ((dbgVar == NULL) || (dbgVar->mDeclDbgLoc == NULL)) + if ((dbgVar == NULL) || (dbgVar->mDeclDbgLoc == NULL)) continue; if (dbgVar->mDeclDbgLoc->mDbgInlinedAt == NULL) continue; - + BeInlineLineBuilder* inlineBuilder = NULL; if (inlineMap.TryGetValue(dbgVar->mDeclDbgLoc->mDbgInlinedAt, &inlineBuilder)) { @@ -1504,19 +1502,19 @@ void BeCOFFObject::DbgGenerateModuleInfo() // Emit inlines and variables int inlineBuilderIdx = 0; - + curInlineBuilder = NULL; - + for (auto dbgVar : dbgFunc->mVariables) - { - if ((dbgVar == NULL) || (dbgVar->mDeclDbgLoc == NULL)) + { + if ((dbgVar == NULL) || (dbgVar->mDeclDbgLoc == NULL)) continue; if (dbgVar->mDeclDbgLoc->mDbgInlinedAt == NULL) DbgOutputLocalVar(dbgFunc, dbgVar); } while ((inlineBuilderIdx < (int)inlineBuilders.size()) || (curInlineBuilder != NULL) /*|| (varIdx < (int)dbgFunc->mVariables.size())*/) - { + { BeInlineLineBuilder* newInlineBuilder = NULL; int curInlineDepth = 0; @@ -1549,7 +1547,7 @@ void BeCOFFObject::DbgGenerateModuleInfo() if (inlineStack.empty()) curInlineBuilder = NULL; else - curInlineBuilder = inlineStack.back(); + curInlineBuilder = inlineStack.back(); } if (newInlineDepth > curInlineDepth) @@ -1562,7 +1560,7 @@ void BeCOFFObject::DbgGenerateModuleInfo() auto inlinedDbgFunc = newInlineBuilder->mStartDbgLoc->GetDbgFunc(); if (inlinedDbgFunc->mCvFuncId == -1) DbgMakeFunc(inlinedDbgFunc); - outS.Write(inlinedDbgFunc->mCvFuncId); + outS.Write(inlinedDbgFunc->mCvFuncId); outS.Write(&newInlineBuilder->mData[0], (int)newInlineBuilder->mData.size()); DbgSEndTag(); newInlineDepth++; @@ -1575,8 +1573,8 @@ void BeCOFFObject::DbgGenerateModuleInfo() // This can fail if an inlined method is not emitted contiguously, or if multiple copies of the same method // get inlined at exactly the same DbgLoc -- which isn't possible in Beef //BF_ASSERT(curInlineBuilder == newInlineBuilder); - } - + } + DbgSStartTag(); outS.Write((int16)S_PROC_ID_END); DbgSEndTag(); @@ -1611,21 +1609,21 @@ void BeCOFFObject::DbgGenerateModuleInfo() curDbgLoc = NULL; BeDbgFile* curFile = NULL; - int lastBlockStartPos = -1; - int lineCount = 0; + int lastBlockStartPos = -1; + int lineCount = 0; Array emissions; - emissions.Reserve(dbgFunc->mEmissions.size()); + emissions.Reserve(dbgFunc->mEmissions.size()); for (int emissionIdx = 0; emissionIdx < (int)dbgFunc->mEmissions.size(); emissionIdx++) { auto& codeEmission = dbgFunc->mEmissions[emissionIdx]; auto rootDbgLoc = codeEmission.mDbgLoc->GetRoot(); - + bool doEmission = true; if (!emissions.empty()) { if (rootDbgLoc == emissions.back().mDbgLoc) - doEmission = false; + doEmission = false; } if (doEmission) @@ -1636,7 +1634,7 @@ void BeCOFFObject::DbgGenerateModuleInfo() emissions.push_back(newEmission); } } - + /// { int fileDataPos = 0; @@ -1656,7 +1654,7 @@ void BeCOFFObject::DbgGenerateModuleInfo() for (int emissionIdx = 0; emissionIdx < (int)emissions.size(); emissionIdx++) { auto& codeEmission = emissions[emissionIdx]; - + auto dbgLoc = codeEmission.mDbgLoc; BeDbgFile* dbgFile = dbgLoc->GetDbgFile(); @@ -1669,9 +1667,9 @@ void BeCOFFObject::DbgGenerateModuleInfo() emissionStartIdx = emissionIdx; } - curDbgLoc = dbgLoc; + curDbgLoc = dbgLoc; curDbgFile = dbgFile; - + lastBlockStartPos = outS.GetPos(); outS.Write((int32)fileDataPositions[dbgFile->mIdx]); outS.Write((int32)0); // placeholder nLines @@ -1691,29 +1689,29 @@ void BeCOFFObject::DbgGenerateModuleInfo() if (curDbgLoc != NULL) DbgEndLineBlock(dbgFunc, emissions, lastBlockStartPos, emissionStartIdx, lineCount); DbgEndSection(); // DEBUG_S_LINES - } + } if (!inlinees.empty()) - { + { DbgStartSection(DEBUG_S_INLINEELINES); outS.Write((int32)0); // Lines type for (auto inlinedDbgFunc : inlinees) - { - BF_ASSERT(inlinedDbgFunc->mCvFuncId != -1); + { + BF_ASSERT(inlinedDbgFunc->mCvFuncId != -1); outS.Write(inlinedDbgFunc->mCvFuncId); - + auto dbgFile = inlinedDbgFunc->mFile; outS.Write((int32)fileDataPositions[dbgFile->mIdx]); outS.Write((int32)inlinedDbgFunc->mLine + 1); } DbgEndSection(); - } + } - // Global variables + // Global variables { - bool startedSymbols = false; + bool startedSymbols = false; for (auto dbgGlobalVar : mBeModule->mDbgModule->mGlobalVariables) - { + { auto gvSym = GetSymbol(dbgGlobalVar->mValue); if (gvSym == NULL) { @@ -1722,24 +1720,24 @@ void BeCOFFObject::DbgGenerateModuleInfo() } if (!startedSymbols) - { + { DbgStartSection(DEBUG_S_SYMBOLS); startedSymbols = true; } DbgSStartTag(); bool isTLS = false; - if (auto beGlobalVar = BeValueDynCast(dbgGlobalVar->mValue)) + if (auto beGlobalVar = BeValueDynCast(dbgGlobalVar->mValue)) isTLS = beGlobalVar->mIsTLS; - + if (isTLS) outS.Write(dbgGlobalVar->mIsLocalToUnit ? (int16)S_LTHREAD32 : (int16)S_GTHREAD32); else outS.Write(dbgGlobalVar->mIsLocalToUnit ? (int16)S_LDATA32 : (int16)S_GDATA32); - + outS.Write(DbgGetTypeId(BeValueDynCast(dbgGlobalVar->mType))); - BF_ASSERT(dbgGlobalVar->mValue != NULL); + BF_ASSERT(dbgGlobalVar->mValue != NULL); BeMCRelocation reloc; reloc.mKind = BeMCRelocationKind_SECREL; @@ -1761,7 +1759,7 @@ void BeCOFFObject::DbgGenerateModuleInfo() if (startedSymbols) DbgEndSection(); // DEBUG_S_SYMBOLS - } + } bool startedUDT = false; for (auto dbgType : mBeModule->mDbgModule->mTypes) @@ -1798,7 +1796,7 @@ void BeCOFFObject::DbgGenerateModuleInfo() if (dbgFile->mMD5Hash.IsZero()) { - outS.Write((int32)0); // hashLen, hashType, padding + outS.Write((int32)0); // hashLen, hashType, padding } else { @@ -1838,8 +1836,8 @@ void BeCOFFObject::AlignConst(BeCOFFSection& sect, BeConstant* constVal) } void BeCOFFObject::WriteConst(BeCOFFSection& sect, BeConstant* constVal) -{ - auto beType = constVal->GetType(); +{ + auto beType = constVal->GetType(); if (auto globalVar = BeValueDynCast(constVal)) { auto sym = GetSymbol(globalVar); @@ -1892,7 +1890,7 @@ void BeCOFFObject::WriteConst(BeCOFFSection& sect, BeConstant* constVal) } else BF_FATAL("Invalid StructConst type"); - } + } else if (auto constStr = BeValueDynCast(constVal)) { sect.mData.Write((void*)constStr->mString.c_str(), (int)constStr->mString.length() + 1); @@ -1905,8 +1903,8 @@ void BeCOFFObject::WriteConst(BeCOFFSection& sect, BeConstant* constVal) { if (auto globalVar = BeValueDynCast(constGep->mTarget)) { - BF_ASSERT(constGep->mIdx0 == 0); - + BF_ASSERT(constGep->mIdx0 == 0); + int64 dataOfs = 0; if (globalVar->mType->mTypeCode == BeTypeCode_Struct) { @@ -1944,7 +1942,7 @@ void BeCOFFObject::WriteConst(BeCOFFSection& sect, BeConstant* constVal) else if (beType->IsComposite()) { BF_ASSERT(constVal->mInt64 == 0); - + int64 zero = 0; int sizeLeft = beType->mSize; while (sizeLeft > 0) @@ -1985,7 +1983,7 @@ void BeCOFFObject::Generate(BeModule* module) InitSect(mDebugTSect, ".debug$T", IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_ALIGN_4BYTES | IMAGE_SCN_MEM_DISCARDABLE | IMAGE_SCN_MEM_READ, true, false); } InitSect(mPDataSect, ".pdata", IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_ALIGN_4BYTES | IMAGE_SCN_MEM_READ, true, false); - + mTextSect.mData.mData.Reserve(4096); BfSizedVector globalVarSyms; @@ -2005,7 +2003,7 @@ void BeCOFFObject::Generate(BeModule* module) sym->mIsStatic = globalVar->mLinkageType == BfIRLinkageType_Internal; sym->mSymKind = BeMCSymbolKind_External; sym->mIdx = (int)mSymbols.size() - 1; - sym->mIsTLS = globalVar->mIsTLS; + sym->mIsTLS = globalVar->mIsTLS; globalVarSyms.push_back(sym); mSymbolMap[globalVar] = sym; @@ -2015,7 +2013,7 @@ void BeCOFFObject::Generate(BeModule* module) { auto globalVar = module->mGlobalVariables[globalVarIdx]; - if ((globalVar->mRefCount == 0) && (globalVar->mInitializer == NULL)) + if ((globalVar->mRefCount == 0) && (globalVar->mInitializer == NULL)) continue; auto sym = globalVarSyms[globalVarIdx]; @@ -2037,7 +2035,7 @@ void BeCOFFObject::Generate(BeModule* module) mRDataSect.mAlign = BF_MAX(mRDataSect.mAlign, globalVar->mAlign); AlignConst(mRDataSect, constVal); - sym->mValue = mRDataSect.mData.GetSize(); + sym->mValue = mRDataSect.mData.GetSize(); WriteConst(mRDataSect, constVal); } else if (globalVar->mIsTLS) @@ -2085,8 +2083,8 @@ void BeCOFFObject::Generate(BeModule* module) mBSSSect.mSizeOverride = (mBSSSect.mSizeOverride + globalVar->mAlign - 1) & ~(globalVar->mAlign - 1); mBSSSect.mAlign = BF_MAX(mBSSSect.mAlign, globalVar->mAlign); sym->mValue = mBSSSect.mSizeOverride; - mBSSSect.mSizeOverride += globalVar->mType->mSize; - } + mBSSSect.mSizeOverride += globalVar->mType->mSize; + } } if (globalVar->mStorageKind == BfIRStorageKind_Export) @@ -2113,10 +2111,10 @@ void BeCOFFObject::Generate(BeModule* module) { auto func = mFuncWorkList[0]; mFuncWorkList.RemoveAt(0); - + module->mActiveFunction = func; if (!func->IsDecl()) - { + { BeMCSymbol* sym = GetSymbol(func); BF_ASSERT(sym != NULL); sym->mValue = mTextSect.mData.GetSize(); @@ -2138,7 +2136,7 @@ void BeCOFFObject::Generate(BeModule* module) InitSect(mDirectiveSect, ".drectve", IMAGE_SCN_LNK_INFO | IMAGE_SCN_LNK_REMOVE | IMAGE_SCN_ALIGN_1BYTES, true, false); mDirectiveSect.mData.Write((void*)mDirectives.c_str(), (int)mDirectives.length()); } - + if (hasDebugInfo) { DbgGenerateTypeInfo(); @@ -2153,7 +2151,7 @@ void BeCOFFObject::Generate(BeModule* module) bool BeCOFFObject::Generate(BeModule* module, const StringImpl& fileName) { BP_ZONE_F("BeCOFFObject::Generate %s", fileName.c_str()); - AutoPerf perf("BeCOFFObject::Generate", mPerfManager); + AutoPerf perf("BeCOFFObject::Generate", mPerfManager); if (mWriteToLib) { @@ -2171,13 +2169,13 @@ bool BeCOFFObject::Generate(BeModule* module, const StringImpl& fileName) return false; for (auto sym : mSymbols) - { + { if (sym->mIsStatic) continue; if (((sym->mSymKind == BeMCSymbolKind_External) && (sym->mSectionNum != 0)) || ((sym->mSymKind == BeMCSymbolKind_Function))) - { + { libEntry->AddSymbol(sym->mName); } } @@ -2228,7 +2226,7 @@ void BeCOFFObject::Finish() memset(§Hdr, 0, sizeof(sectHdr)); BeCOFFSection* sect = mUsedSections[sectNum]; strcpy(sectHdr.mName, sect->mSectName.c_str()); - + int characteristics = sect->mCharacteristics; if (sect->mAlign != 0) { @@ -2246,8 +2244,8 @@ void BeCOFFObject::Finish() else if (sect->mAlign == 4) characteristics |= IMAGE_SCN_ALIGN_4BYTES; else if (sect->mAlign == 2) characteristics |= IMAGE_SCN_ALIGN_2BYTES; } - - sectData[sectNum] = sect; + + sectData[sectNum] = sect; int dataSize = sect->mData.GetSize(); if (dataSize != 0) { @@ -2267,9 +2265,9 @@ void BeCOFFObject::Finish() filePos += sizeof(COFFRelocation); } else - { + { sectHdr.mNumberOfRelocations = (int)sect->mRelocs.size(); - } + } filePos += (int)sect->mRelocs.size() * sizeof(COFFRelocation); } } @@ -2281,8 +2279,8 @@ void BeCOFFObject::Finish() sectHdr.mCharacteristics = characteristics; BF_ASSERT(characteristics != 0); } - - header.mPointerToSymbolTable = filePos; + + header.mPointerToSymbolTable = filePos; header.mNumberOfSymbols = (int)mSymbols.size(); mStream->WriteT(header); @@ -2323,7 +2321,7 @@ void BeCOFFObject::Finish() coffReloc.mVirtualAddress = reloc.mOffset; coffReloc.mSymbolTableIndex = reloc.mSymTableIdx; coffReloc.mType = IMAGE_REL_AMD64_ABSOLUTE; - + switch (reloc.mKind) { case BeMCRelocationKind_ADDR32NB: @@ -2350,7 +2348,7 @@ void BeCOFFObject::Finish() } BF_ASSERT(mStream->GetPos() == filePos); - + SizedArray symInfoVec; symInfoVec.reserve(mSymbols.size() + 16); @@ -2358,8 +2356,8 @@ void BeCOFFObject::Finish() { //BP_ZONE("Finish - AddSym"); - if (sym->mSymKind == BeMCSymbolKind_AuxPlaceholder) - continue; + if (sym->mSymKind == BeMCSymbolKind_AuxPlaceholder) + continue; PE_SymInfo symInfo; memset(&symInfo, 0, sizeof(symInfo)); @@ -2370,9 +2368,9 @@ void BeCOFFObject::Finish() symInfo.mNameOfs[1] = strTablePos + 4; } else - strcpy(symInfo.mName, sym->mName.c_str()); + strcpy(symInfo.mName, sym->mName.c_str()); if (sym->mSymKind == BeMCSymbolKind_SectionDef) - { + { symInfo.mSectionNum = sym->mSectionNum; symInfo.mStorageClass = IMAGE_SYM_CLASS_STATIC; symInfo.mNumOfAuxSymbols = 1; @@ -2390,41 +2388,41 @@ void BeCOFFObject::Finish() auxSymInfo.mSelection = 2; // Pick any (only applicable for COMDAT but ignored elsewhere) auxSymInfo.mUnused = 0; auxSymInfo.mUnused2 = 0; - auxSymInfo.mUnused3 = 0; + auxSymInfo.mUnused3 = 0; symInfoVec.push_back(*(PE_SymInfo*)&auxSymInfo); continue; } else if (sym->mSymKind == BeMCSymbolKind_SectionRef) { - symInfo.mSectionNum = sym->mSectionNum; - symInfo.mStorageClass = IMAGE_SYM_CLASS_SECTION; + symInfo.mSectionNum = sym->mSectionNum; + symInfo.mStorageClass = IMAGE_SYM_CLASS_SECTION; } else if (sym->mSymKind == BeMCSymbolKind_Function) { symInfo.mValue = sym->mValue; - symInfo.mSectionNum = mTextSect.mSectionIdx + 1; + symInfo.mSectionNum = mTextSect.mSectionIdx + 1; symInfo.mType = 0x20; //DT_FUNCTION if (sym->mIsStatic) symInfo.mStorageClass = IMAGE_SYM_CLASS_STATIC; else symInfo.mStorageClass = IMAGE_SYM_CLASS_EXTERNAL; - } + } else if (sym->mSymKind == BeMCSymbolKind_COMDAT) { symInfo.mValue = sym->mValue; - symInfo.mSectionNum = sym->mSectionNum; + symInfo.mSectionNum = sym->mSectionNum; symInfo.mStorageClass = IMAGE_SYM_CLASS_EXTERNAL; } else - { + { if (sym->mIsStatic) symInfo.mStorageClass = IMAGE_SYM_CLASS_STATIC; else symInfo.mStorageClass = IMAGE_SYM_CLASS_EXTERNAL; symInfo.mValue = sym->mValue; symInfo.mSectionNum = sym->mSectionNum; - } + } symInfoVec.push_back(symInfo); } if (!symInfoVec.IsEmpty()) @@ -2437,7 +2435,7 @@ void BeCOFFObject::Finish() } BeMCSymbol* BeCOFFObject::GetSymbol(BeValue* value, bool allowCreate) -{ +{ /*auto itr = mSymbolMap.find(value); if (itr != mSymbolMap.end()) return itr->second;*/ @@ -2446,7 +2444,7 @@ BeMCSymbol* BeCOFFObject::GetSymbol(BeValue* value, bool allowCreate) return *symbolPtr; if (allowCreate) - { + { if (auto func = BeValueDynCast(value)) { mFuncWorkList.Add(func); @@ -2475,7 +2473,7 @@ BeMCSymbol* BeCOFFObject::GetSymbol(BeValue* value, bool allowCreate) } BeMCSymbol* BeCOFFObject::GetSymbolRef(const StringImpl& name) -{ +{ /*auto itr = mNamedSymbolMap.find(name); if (itr != mNamedSymbolMap.end()) return itr->second;*/ @@ -2502,8 +2500,8 @@ void BeCOFFObject::MarkSectionUsed(BeCOFFSection& sect, bool getSectSymbol) if (getSectSymbol) { //TODO: We previously only did sectionDefs when we needed the SelectionNum value, but - // omitting this causes the MS linker to throw "multiple '' sections found with different - // attributes (0000000000) errors. This change could potentially break LIB creation in the + // omitting this causes the MS linker to throw "multiple '' sections found with different + // attributes (0000000000) errors. This change could potentially break LIB creation in the // linker. Verify it still works. if (((sect.mCharacteristics & IMAGE_SCN_LNK_COMDAT) != 0) || (true)) { @@ -2524,7 +2522,7 @@ void BeCOFFObject::MarkSectionUsed(BeCOFFSection& sect, bool getSectSymbol) else { // It's important for the linker's import library output to include - // section refs and not section defs, even when they aren't an external + // section refs and not section defs, even when they aren't an external // reference BeMCSymbol* sym; sym = mSymbols.Alloc(); @@ -2549,8 +2547,8 @@ BeMCSymbol* BeCOFFObject::GetCOMDAT(const StringImpl& name, void* data, int size BeCOFFSection mRData8Sect; auto* rdataSect = mDynSects.Alloc(); - int characteristics = IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_LNK_COMDAT | IMAGE_SCN_MEM_READ; - InitSect(*rdataSect, ".rdata", characteristics, true, true); + int characteristics = IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_LNK_COMDAT | IMAGE_SCN_MEM_READ; + InitSect(*rdataSect, ".rdata", characteristics, true, true); rdataSect->mAlign = align; auto sym = mSymbols.Alloc(); @@ -2559,9 +2557,9 @@ BeMCSymbol* BeCOFFObject::GetCOMDAT(const StringImpl& name, void* data, int size sym->mIdx = (int)mSymbols.size() - 1; sym->mSectionNum = rdataSect->mSectionIdx + 1; sym->mValue = rdataSect->mData.GetPos(); - mNamedSymbolMap[name] = sym; - rdataSect->mData.Write(data, size); - return sym; + mNamedSymbolMap[name] = sym; + rdataSect->mData.Write(data, size); + return sym; } BeCOFFSection* BeCOFFObject::CreateSect(const StringImpl& name, int characteristics, bool makeSectSymbol) diff --git a/IDEHelper/Backend/BeCOFFObject.h b/IDEHelper/Backend/BeCOFFObject.h index 78ce5a40..b69ca7a6 100644 --- a/IDEHelper/Backend/BeCOFFObject.h +++ b/IDEHelper/Backend/BeCOFFObject.h @@ -26,7 +26,7 @@ public: bool mIsStatic; bool mIsTLS; BeMCSymbolKind mSymKind; - int mValue; + int mValue; int mIdx; int mSectionNum; @@ -169,7 +169,7 @@ public: return false; for (int i = 0; i < (int)lhs->mType->mParams.size(); i++) if (lhs->mType->mParams[i] != rhs->mType->mParams[i]) - return false; + return false; return true; } }; @@ -215,16 +215,16 @@ public: PerfManager* mPerfManager; DataStream* mStream; BumpAllocator mAlloc; - BeModule* mBeModule; - OwnedVector mSymbols; + BeModule* mBeModule; + OwnedVector mSymbols; OwnedVector mDynSects; uint32 mTimestamp; BeCOFFSection mTextSect; BeCOFFSection mDataSect; - BeCOFFSection mRDataSect; - BeCOFFSection mBSSSect; - BeCOFFSection mTLSSect; + BeCOFFSection mRDataSect; + BeCOFFSection mBSSSect; + BeCOFFSection mTLSSect; BeCOFFSection mPDataSect; BeCOFFSection mXDataSect; BeCOFFSection mDebugSSect; @@ -234,8 +234,8 @@ public: int mBSSPos; Array mUsedSections; Dictionary mSymbolMap; - Dictionary mNamedSymbolMap; - HashSet mArgListSet; + Dictionary mNamedSymbolMap; + HashSet mArgListSet; HashSet mFuncTypeSet; Deque mFuncWorkList; int mTTagStartPos; @@ -244,10 +244,10 @@ public: int mSectionStartPos; int mCurStringId; int mCurJumpTableIdx; - bool mTypesLocked; + bool mTypesLocked; String mDirectives; -public: +public: void ToString(BeMDNode* mdNode, String& str); int GetCVRegNum(X64CPURegister reg, int bits); @@ -255,10 +255,10 @@ public: void DbgTStartTag(); void DbgTEndTag(); void DbgEncodeConstant(DynMemStream& memStream, int64 val); - void DbgEncodeString(DynMemStream& memStream, const StringImpl& str); + void DbgEncodeString(DynMemStream& memStream, const StringImpl& str); void DbgMakeFuncType(BeDbgFunction* dbgFunc); void DbgMakeFunc(BeDbgFunction* dbgFunc); - int DbgGetTypeId(BeDbgType* dbgType, bool doDefine = false); + int DbgGetTypeId(BeDbgType* dbgType, bool doDefine = false); void DbgGenerateTypeInfo(); void DbgSAlign(); @@ -270,18 +270,18 @@ public: void DbgEndSection(); void DbgStartVarDefRange(BeDbgFunction* dbgFunc, BeDbgVariable* dbgVar, const BeDbgVariableLoc& varLoc, int offset, int range); void DbgEndLineBlock(BeDbgFunction* dbgFunc, const Array& emissions, int blockStartPos, int emissionStartIdx, int lineCount); - void DbgGenerateModuleInfo(); + void DbgGenerateModuleInfo(); void InitSect(BeCOFFSection& sect, const StringImpl& name, int characteristics, bool addNow, bool makeSectSymbol); void AlignConst(BeCOFFSection& sect, BeConstant* constVal); void WriteConst(BeCOFFSection& sect, BeConstant* constVal); - + void Generate(BeModule* module); public: - BeCOFFObject(); + BeCOFFObject(); void Finish(); - bool Generate(BeModule* module, const StringImpl& fileName); + bool Generate(BeModule* module, const StringImpl& fileName); BeMCSymbol* GetSymbol(BeValue* value, bool allowCreate = true); BeMCSymbol* GetSymbolRef(const StringImpl& name); void MarkSectionUsed(BeCOFFSection& sect, bool getSectSymbol = false); diff --git a/IDEHelper/Backend/BeContext.cpp b/IDEHelper/Backend/BeContext.cpp index 21c7c707..ed457419 100644 --- a/IDEHelper/Backend/BeContext.cpp +++ b/IDEHelper/Backend/BeContext.cpp @@ -28,7 +28,7 @@ BeType* BeContext::GetPrimitiveType(BeTypeCode typeCode) primType->mTypeCode = typeCode; switch (typeCode) { - case BeTypeCode_None: + case BeTypeCode_None: primType->mSize = 0; primType->mAlign = 0; break; @@ -80,24 +80,24 @@ BeStructType* BeContext::CreateStruct(const StringImpl& name) BeStructType* structType = mTypes.Alloc(); structType->mContext = this; structType->mTypeCode = BeTypeCode_Struct; - structType->mName = name; + structType->mName = name; structType->mIsOpaque = true; return structType; } BeStructType* BeContext::CreateStruct(const SizedArrayImpl& types) -{ - BeStructType** valuePtr = NULL; - if (mAnonymousStructMap.TryGetValueWith(types, &valuePtr)) - return *valuePtr; +{ + BeStructType** valuePtr = NULL; + if (mAnonymousStructMap.TryGetValueWith(types, &valuePtr)) + return *valuePtr; Array key; for (auto type : types) key.Add(type); - + BeStructType* structType = CreateStruct(""); SetStructBody(structType, types, false); - mAnonymousStructMap.TryAdd(key, structType); + mAnonymousStructMap.TryAdd(key, structType); return structType; } @@ -109,7 +109,7 @@ BePointerType* BeContext::GetPointerTo(BeType* beType) pointerType->mTypeCode = BeTypeCode_Pointer; pointerType->mElementType = beType; pointerType->mSize = mPointerSize; - pointerType->mAlign = mPointerSize; + pointerType->mAlign = mPointerSize; beType->mPointerType = pointerType; /*if (beType->IsSizedArray()) @@ -197,12 +197,12 @@ bool BeContext::AreTypesEqual(BeType* lhs, BeType* rhs) { if (lhs == rhs) return true; - + if (lhs->mTypeCode != rhs->mTypeCode) return false; switch (lhs->mTypeCode) - { + { case BeTypeCode_None: case BeTypeCode_NullPtr: case BeTypeCode_Boolean: @@ -214,7 +214,7 @@ bool BeContext::AreTypesEqual(BeType* lhs, BeType* rhs) case BeTypeCode_Double: return true; case BeTypeCode_Pointer: - return AreTypesEqual(((BePointerType*)lhs)->mElementType, ((BePointerType*)rhs)->mElementType); + return AreTypesEqual(((BePointerType*)lhs)->mElementType, ((BePointerType*)rhs)->mElementType); case BeTypeCode_SizedArray: { auto lhsSizedArray = (BeSizedArrayType*)lhs; @@ -222,7 +222,7 @@ bool BeContext::AreTypesEqual(BeType* lhs, BeType* rhs) if (lhsSizedArray->mLength != rhsSizedArray->mLength) return false; return AreTypesEqual(lhsSizedArray->mElementType, rhsSizedArray->mElementType); - } + } case BeTypeCode_Vector: { auto lhsSizedArray = (BeVectorType*)lhs; @@ -233,5 +233,4 @@ bool BeContext::AreTypesEqual(BeType* lhs, BeType* rhs) } } return false; -} - +} \ No newline at end of file diff --git a/IDEHelper/Backend/BeContext.h b/IDEHelper/Backend/BeContext.h index 20d24152..e65f69f9 100644 --- a/IDEHelper/Backend/BeContext.h +++ b/IDEHelper/Backend/BeContext.h @@ -88,7 +88,6 @@ public: virtual ~BeType() { - } int GetStride() @@ -120,7 +119,6 @@ public: { return (mTypeCode == BeTypeCode_Float) || (mTypeCode == BeTypeCode_Double); } - bool IsStruct() { @@ -159,10 +157,10 @@ public: } virtual void HashContent(BeHashContext& hashCtx) - { + { BF_ASSERT(mTypeCode < BeTypeCode_Struct); hashCtx.Mixin(mTypeCode); - } + } }; class BeStructMember @@ -174,21 +172,21 @@ public: class BeStructType : public BeType { -public: +public: BeContext* mContext; String mName; - Array mMembers; + Array mMembers; bool mIsPacked; bool mIsOpaque; - + virtual void HashContent(BeHashContext& hashCtx) override - { + { hashCtx.MixinStr(mName); hashCtx.Mixin(mMembers.size()); for (auto& member : mMembers) { member.mType->HashReference(hashCtx); - hashCtx.Mixin(member.mByteOffset); + hashCtx.Mixin(member.mByteOffset); } hashCtx.Mixin(mIsPacked); hashCtx.Mixin(mIsOpaque); @@ -213,9 +211,9 @@ public: BeContext* mContext; BeType* mElementType; int mLength; - + virtual void HashContent(BeHashContext& hashCtx) override - { + { hashCtx.Mixin(BeTypeCode_SizedArray); hashCtx.Mixin(mLength); mElementType->HashReference(hashCtx); @@ -247,27 +245,27 @@ class BeFunctionType : public BeType { public: String mName; - BeType* mReturnType; + BeType* mReturnType; Array mParams; bool mIsVarArg; - + virtual void HashContent(BeHashContext& hashCtx) override { hashCtx.Mixin(BeTypeCode_Function); hashCtx.MixinStr(mName); - mReturnType->HashReference(hashCtx); + mReturnType->HashReference(hashCtx); hashCtx.Mixin(mParams.size()); for (auto& param : mParams) { param.mType->HashReference(hashCtx); } - hashCtx.Mixin(mIsVarArg); + hashCtx.Mixin(mIsVarArg); } }; class BeContext { -public: +public: int mPointerSize; //BumpAllocator mAlloc; BeType* mPrimitiveTypes[BeTypeCode_COUNT]; @@ -278,8 +276,8 @@ public: void NotImpl(); public: - BeContext(); - BeType* GetPrimitiveType(BeTypeCode typeCode); + BeContext(); + BeType* GetPrimitiveType(BeTypeCode typeCode); BeType* GetVoidPtrType(); BeStructType* CreateStruct(const StringImpl& name); BeStructType* CreateStruct(const SizedArrayImpl& types); diff --git a/IDEHelper/Backend/BeDbgModule.h b/IDEHelper/Backend/BeDbgModule.h index e40ce902..0c0cf57f 100644 --- a/IDEHelper/Backend/BeDbgModule.h +++ b/IDEHelper/Backend/BeDbgModule.h @@ -8,4 +8,3 @@ NS_BF_BEGIN NS_BF_END - diff --git a/IDEHelper/Backend/BeIRCodeGen.cpp b/IDEHelper/Backend/BeIRCodeGen.cpp index 7d4ee7d7..64d09dbb 100644 --- a/IDEHelper/Backend/BeIRCodeGen.cpp +++ b/IDEHelper/Backend/BeIRCodeGen.cpp @@ -231,7 +231,7 @@ BeIRCodeGen::BeIRCodeGen() mBeContext = NULL; mBeModule = NULL; mHasDebugLoc = false; - mDebugging = false; + mDebugging = false; mCmdCount = 0; } @@ -239,7 +239,7 @@ BeIRCodeGen::~BeIRCodeGen() { BF_ASSERT(mSavedDebugLocs.size() == 0); delete mBeModule; - delete mBeContext; + delete mBeContext; delete mStream; } @@ -254,7 +254,7 @@ void BeIRCodeGen::Hash(BeHashContext& hashCtx) hashCtx.Mixin(mPtrSize); hashCtx.Mixin(mIsOptimized); if (mBeModule != NULL) - mBeModule->Hash(hashCtx); + mBeModule->Hash(hashCtx); Array structHashList; @@ -385,7 +385,7 @@ BeType* BeIRCodeGen::GetBeType(BfTypeCode typeCode, bool& isSigned) isSigned = true; beTypeCode = BeTypeCode_Float; break; - case BfTypeCode_Double: + case BfTypeCode_Double: isSigned = true; beTypeCode = BeTypeCode_Double; break; @@ -395,7 +395,7 @@ BeType* BeIRCodeGen::GetBeType(BfTypeCode typeCode, bool& isSigned) } BeIRTypeEntry& BeIRCodeGen::GetTypeEntry(int typeId) -{ +{ BeIRTypeEntry& typeEntry = mTypes[typeId]; if (typeEntry.mTypeId == -1) typeEntry.mTypeId = typeId; @@ -482,7 +482,7 @@ void BeIRCodeGen::ProcessBfIRData(const BfSizedArray& buffer) { BP_ZONE("BeIRCodeGen::ProcessBfIRData"); - Init(buffer); + Init(buffer); Process(); } @@ -490,7 +490,7 @@ BfTypeCode BeIRCodeGen::GetTypeCode(BeType * type, bool isSigned) { switch (type->mTypeCode) { - case BeTypeCode_Int8: + case BeTypeCode_Int8: return (isSigned) ? BfTypeCode_Int8 : BfTypeCode_UInt8; case BeTypeCode_Int16: return (isSigned) ? BfTypeCode_Int16 : BfTypeCode_UInt16; @@ -518,7 +518,7 @@ void BeIRCodeGen::SetResult(int id, BeValue* value) void BeIRCodeGen::SetResult(int id, BeType* type) { BeIRCodeGenEntry entry; - entry.mKind = BeIRCodeGenEntryKind_Type; + entry.mKind = BeIRCodeGenEntryKind_Type; entry.mBeType = type; mResults.TryAdd(id, entry); } @@ -549,7 +549,6 @@ int64 BeIRCodeGen::ReadSLEB128() byteVal = mStream->Read(); val |= ((int64)(byteVal & 0x7f)) << shift; shift += 7; - } while (byteVal >= 128); // Sign extend negative numbers. if ((byteVal & 0x40) && (shift < 64)) @@ -700,7 +699,7 @@ void BeIRCodeGen::Read(BeValue*& beValue) CMD_PARAM(bool, isTLS); BF_ASSERT(varType != NULL); - + auto globalVariable = mBeModule->mGlobalVariables.Alloc(); globalVariable->mModule = mBeModule; globalVariable->mType = varType; @@ -710,7 +709,7 @@ void BeIRCodeGen::Read(BeValue*& beValue) globalVariable->mName = name; globalVariable->mIsTLS = isTLS; globalVariable->mAlign = varType->mAlign; - globalVariable->mUnnamedAddr = false; + globalVariable->mUnnamedAddr = false; globalVariable->mStorageKind = BfIRStorageKind_Normal; if (initializer != NULL) BF_ASSERT(varType->mAlign > 0); @@ -723,16 +722,16 @@ void BeIRCodeGen::Read(BeValue*& beValue) beValue->mRefCount++; BE_MEM_END("ParamType_Const_GlobalVar"); return; - } + } else if ((constType == BfConstType_BitCast) || (constType == BfConstType_BitCastNull)) - { + { CMD_PARAM(BeConstant*, target); CMD_PARAM(BeType*, toType); auto castedVal = mBeModule->mAlloc.Alloc(); castedVal->mInt64 = target->mInt64; castedVal->mType = toType; - castedVal->mTarget = target; + castedVal->mTarget = target; BF_ASSERT(target->GetType() != NULL); BF_ASSERT(!target->GetType()->IsComposite()); beValue = castedVal; @@ -742,12 +741,12 @@ void BeIRCodeGen::Read(BeValue*& beValue) else if (constType == BfConstType_GEP32_1) { CMD_PARAM(BeConstant*, target); - CMD_PARAM(int, idx0); + CMD_PARAM(int, idx0); BF_ASSERT(target->GetType()->IsPointer()); auto gepConstant = mBeModule->mAlloc.Alloc(); gepConstant->mTarget = target; - gepConstant->mIdx0 = idx0; + gepConstant->mIdx0 = idx0; beValue = gepConstant; BE_MEM_END("ParamType_Const_GEP32_1"); @@ -758,7 +757,7 @@ void BeIRCodeGen::Read(BeValue*& beValue) CMD_PARAM(BeConstant*, target); CMD_PARAM(int, idx0); CMD_PARAM(int, idx1); - + BF_ASSERT(target->GetType()->IsPointer()); auto gepConstant = mBeModule->mAlloc.Alloc(); gepConstant->mTarget = target; @@ -772,11 +771,11 @@ void BeIRCodeGen::Read(BeValue*& beValue) else if (constType == BfConstType_ExtractValue) { CMD_PARAM(BeConstant*, target); - CMD_PARAM(int, idx0); - + CMD_PARAM(int, idx0); + auto gepConstant = mBeModule->mAlloc.Alloc(); gepConstant->mTarget = target; - gepConstant->mIdx0 = idx0; + gepConstant->mIdx0 = idx0; beValue = gepConstant; BE_MEM_END("ParamType_Const_ExtractValue"); @@ -794,7 +793,7 @@ void BeIRCodeGen::Read(BeValue*& beValue) auto castedVal = mBeModule->mAlloc.Alloc(); castedVal->mInt64 = target->mInt64; castedVal->mType = toType; - castedVal->mTarget = target; + castedVal->mTarget = target; BF_ASSERT(target->GetType() != NULL); beValue = castedVal; BE_MEM_END("ParamType_Const_PtrToInt"); @@ -858,11 +857,11 @@ void BeIRCodeGen::Read(BeValue*& beValue) } auto constStruct = mBeModule->mOwnedValues.Alloc(); - constStruct->mType = type; + constStruct->mType = type; for (int i = 0; i < (int)values.size(); i++) { auto val = values[i]; - BeConstant* constant = BeValueDynCast(val); + BeConstant* constant = BeValueDynCast(val); if (type->IsSizedArray()) { @@ -882,7 +881,7 @@ void BeIRCodeGen::Read(BeValue*& beValue) { BF_ASSERT(type->IsStruct()); auto structType = (BeStructType*)type; - auto valType = constant->GetType(); + auto valType = constant->GetType(); if (structType->mIsOpaque) { Fail("ConstAgg with opaque struct"); @@ -922,7 +921,7 @@ void BeIRCodeGen::Read(BeValue*& beValue) } else if (constType == BfConstType_Undef) { - CMD_PARAM(BeType*, type); + CMD_PARAM(BeType*, type); auto constUndef = mBeModule->mOwnedValues.Alloc(); constUndef->mType = type; beValue = constUndef; @@ -940,7 +939,7 @@ void BeIRCodeGen::Read(BeValue*& beValue) CMD_PARAM(BeType*, type); CMD_PARAM(BeValue*, value); mReflectDataMap[type] = value; - beValue = value; + beValue = value; return; } @@ -969,26 +968,26 @@ void BeIRCodeGen::Read(BeValue*& beValue) } else if (typeCode == BfTypeCode_None) { - beValue = NULL; + beValue = NULL; BE_MEM_END("ParamType_Const_None"); } else if (typeCode == BfTypeCode_NullPtr) { - CMD_PARAM(BeType*, nullType); - beValue = mBeModule->GetConstantNull((BePointerType*)nullType); + CMD_PARAM(BeType*, nullType); + beValue = mBeModule->GetConstantNull((BePointerType*)nullType); BE_MEM_END("ParamType_Const_NullPtr"); } else if (BfIRBuilder::IsInt(typeCode)) - { + { int64 intVal = ReadSLEB128(); - auto constVal = mBeModule->GetConstant(llvmConstType, intVal); + auto constVal = mBeModule->GetConstant(llvmConstType, intVal); beValue = constVal; BE_MEM_END("ParamType_Const_Int"); } else { BF_FATAL("Unhandled"); - } + } } else if (paramType == BfIRParamType_Arg) { @@ -997,7 +996,7 @@ void BeIRCodeGen::Read(BeValue*& beValue) BE_MEM_END("ParamType_Arg"); } else if (paramType == BfIRParamType_StreamId_Abs8) - { + { int cmdId = mStream->Read(); auto& result = mResults[cmdId]; BF_ASSERT(result.mKind == BeIRCodeGenEntryKind_Value); @@ -1005,13 +1004,13 @@ void BeIRCodeGen::Read(BeValue*& beValue) BE_MEM_END("ParamType_StreamId"); } else if (paramType == BfIRParamType_StreamId_Rel) - { + { int cmdId = mCmdCount - (int)ReadSLEB128(); auto& result = mResults[cmdId]; BF_ASSERT(result.mKind == BeIRCodeGenEntryKind_Value); beValue = result.mBeValue; BE_MEM_END("ParamType_StreamId"); - } + } else { int cmdId = mCmdCount - (paramType - BfIRParamType_StreamId_Back1) - 1; @@ -1019,7 +1018,7 @@ void BeIRCodeGen::Read(BeValue*& beValue) BF_ASSERT(result.mKind == BeIRCodeGenEntryKind_Value); beValue = result.mBeValue; BE_MEM_END("ParamType_StreamId"); - } + } if (beValue != NULL) beValue->mRefCount++; @@ -1052,7 +1051,7 @@ void BeIRCodeGen::Read(BeFunction*& beFunc) return; } auto& result = mResults[streamId]; - BF_ASSERT(result.mKind == BeIRCodeGenEntryKind_Value); + BF_ASSERT(result.mKind == BeIRCodeGenEntryKind_Value); BF_ASSERT(BeValueDynCast(result.mBeValue)); beFunc = (BeFunction*)result.mBeValue; BE_MEM_END("BeFunction"); @@ -1097,7 +1096,7 @@ void BeIRCodeGen::HandleNextCmd() BfIRCmd cmd = (BfIRCmd)mStream->Read(); mCmdCount++; -#ifdef CODEGEN_TRACK +#ifdef CODEGEN_TRACK gBEMemReporter.BeginSection(gIRCmdNames[cmd]); gBEMemReporter.Add(1); #endif @@ -1111,11 +1110,11 @@ void BeIRCodeGen::HandleNextCmd() CMD_PARAM(bool, isOptimized); BF_ASSERT(mBeModule == NULL); - mPtrSize = ptrSize; + mPtrSize = ptrSize; mIsOptimized = isOptimized; mBeContext = new BeContext(); mBeModule = new BeModule(moduleName, mBeContext); - mBeModule->mBeIRCodeGen = this; + mBeModule->mBeIRCodeGen = this; mBeContext->mPointerSize = ptrSize; for (auto constInt : mConfigConsts) @@ -1163,7 +1162,7 @@ void BeIRCodeGen::HandleNextCmd() case BfIRCmd_SetType: { CMD_PARAM(int, typeId); - CMD_PARAM(BeType*, type); + CMD_PARAM(BeType*, type); auto& typeEntry = GetTypeEntry(typeId); typeEntry.mBeType = type; if (typeEntry.mInstBeType == NULL) @@ -1176,7 +1175,7 @@ void BeIRCodeGen::HandleNextCmd() CMD_PARAM(BeType*, type); GetTypeEntry(typeId).mInstBeType = type; } - break; + break; case BfIRCmd_PrimitiveType: { BfTypeCode typeCode = (BfTypeCode)mStream->Read(); @@ -1186,7 +1185,7 @@ void BeIRCodeGen::HandleNextCmd() break; case BfIRCmd_CreateStruct: { - CMD_PARAM(String, typeName); + CMD_PARAM(String, typeName); SetResult(curId, mBeContext->CreateStruct(typeName)); } break; @@ -1198,13 +1197,13 @@ void BeIRCodeGen::HandleNextCmd() } break; case BfIRCmd_StructSetBody: - { + { CMD_PARAM(BeType*, type); CMD_PARAM(CmdParamVec, members); CMD_PARAM(int, instSize); CMD_PARAM(int, instAlign); CMD_PARAM(bool, isPacked); - BF_ASSERT(type->mTypeCode == BeTypeCode_Struct); + BF_ASSERT(type->mTypeCode == BeTypeCode_Struct); auto structType = (BeStructType*)type; mBeContext->SetStructBody(structType, members, isPacked); structType->mSize = instSize; @@ -1229,14 +1228,14 @@ void BeIRCodeGen::HandleNextCmd() CMD_PARAM(BeIRTypeEntry*, typeEntry); SetResult(curId, mBeContext->GetPointerTo(typeEntry->mInstBeType)); } - break; + break; case BfIRCmd_GetType: { CMD_PARAM(BeValue*, value); auto type = value->GetType(); SetResult(curId, type); } - break; + break; case BfIRCmd_GetPointerToFuncType: { CMD_PARAM(BeFunctionType*, funcType); @@ -1255,24 +1254,24 @@ void BeIRCodeGen::HandleNextCmd() CMD_PARAM(int, length); SetResult(curId, mBeContext->CreateSizedArrayType(elementType, length)); } - break; + break; case BfIRCmd_GetVectorType: { CMD_PARAM(BeType*, elementType); CMD_PARAM(int, length); SetResult(curId, mBeContext->CreateVectorType(elementType, length)); } - break; + break; case BfIRCmd_CreateConstAgg: - { + { CMD_PARAM(BeType*, type); CMD_PARAM(CmdParamVec, values); auto constStruct = mBeModule->mOwnedValues.Alloc(); constStruct->mType = type; - + if (type->IsStruct()) - { + { FixValues((BeStructType*)type, values); BF_ASSERT(((BeStructType*)type)->mMembers.size() == values.size()); @@ -1314,10 +1313,10 @@ void BeIRCodeGen::HandleNextCmd() beConst->mType = type; SetResult(curId, beConst); } - break; + break; case BfIRCmd_CreateConstString: { - CMD_PARAM(String, str); + CMD_PARAM(String, str); auto constStruct = mBeModule->mOwnedValues.Alloc(); constStruct->mString = str; auto charType = mBeContext->GetPrimitiveType(BeTypeCode_Int8); @@ -1351,7 +1350,7 @@ void BeIRCodeGen::HandleNextCmd() } break; case BfIRCmd_NumericCast: - { + { CMD_PARAM(BeValue*, val); CMD_PARAM(bool, valIsSigned); @@ -1365,20 +1364,20 @@ void BeIRCodeGen::HandleNextCmd() BfTypeCode valTypeCode = GetTypeCode(valType, valIsSigned); if (auto srcCastConstant = BeValueDynCast(val)) - { + { BeType* toType = GetBeType(typeCode, valIsSigned); auto castedVal = mBeModule->mAlloc.Alloc(); castedVal->mInt64 = srcCastConstant->mInt64; castedVal->mType = toType; castedVal->mTarget = srcCastConstant->mTarget; - + SetResult(curId, castedVal); break; } - + bool toSigned = false; - auto toBeType = GetBeType(typeCode, toSigned); + auto toBeType = GetBeType(typeCode, toSigned); BeValue* retVal = mBeModule->CreateNumericCast(val, toBeType, valIsSigned, toSigned); SetResult(curId, retVal); } @@ -1401,13 +1400,13 @@ void BeIRCodeGen::HandleNextCmd() { CMD_PARAM(BeValue*, lhs); CMD_PARAM(BeValue*, rhs); - SetResult(curId, mBeModule->CreateCmp(BeCmpKind_SLT, lhs, rhs)); + SetResult(curId, mBeModule->CreateCmp(BeCmpKind_SLT, lhs, rhs)); } break; case BfIRCmd_CmpULT: { CMD_PARAM(BeValue*, lhs); - CMD_PARAM(BeValue*, rhs); + CMD_PARAM(BeValue*, rhs); SetResult(curId, mBeModule->CreateCmp(BeCmpKind_ULT, lhs, rhs)); } break; @@ -1421,7 +1420,7 @@ void BeIRCodeGen::HandleNextCmd() case BfIRCmd_CmpULE: { CMD_PARAM(BeValue*, lhs); - CMD_PARAM(BeValue*, rhs); + CMD_PARAM(BeValue*, rhs); SetResult(curId, mBeModule->CreateCmp(BeCmpKind_ULE, lhs, rhs)); } break; @@ -1435,7 +1434,7 @@ void BeIRCodeGen::HandleNextCmd() case BfIRCmd_CmpUGT: { CMD_PARAM(BeValue*, lhs); - CMD_PARAM(BeValue*, rhs); + CMD_PARAM(BeValue*, rhs); SetResult(curId, mBeModule->CreateCmp(BeCmpKind_UGT, lhs, rhs)); } break; @@ -1449,14 +1448,14 @@ void BeIRCodeGen::HandleNextCmd() case BfIRCmd_CmpUGE: { CMD_PARAM(BeValue*, lhs); - CMD_PARAM(BeValue*, rhs); + CMD_PARAM(BeValue*, rhs); SetResult(curId, mBeModule->CreateCmp(BeCmpKind_UGE, lhs, rhs)); } break; case BfIRCmd_Add: { CMD_PARAM(BeValue*, lhs); - CMD_PARAM(BeValue*, rhs); + CMD_PARAM(BeValue*, rhs); CMD_PARAM(int8, overflowCheckKind); SetResult(curId, mBeModule->CreateBinaryOp(BeBinaryOpKind_Add, lhs, rhs, (BfOverflowCheckKind)overflowCheckKind)); } @@ -1487,7 +1486,7 @@ void BeIRCodeGen::HandleNextCmd() case BfIRCmd_UDiv: { CMD_PARAM(BeValue*, lhs); - CMD_PARAM(BeValue*, rhs); + CMD_PARAM(BeValue*, rhs); SetResult(curId, mBeModule->CreateBinaryOp(BeBinaryOpKind_UDivide, lhs, rhs)); } break; @@ -1508,42 +1507,42 @@ void BeIRCodeGen::HandleNextCmd() case BfIRCmd_And: { CMD_PARAM(BeValue*, lhs); - CMD_PARAM(BeValue*, rhs); + CMD_PARAM(BeValue*, rhs); SetResult(curId, mBeModule->CreateBinaryOp(BeBinaryOpKind_BitwiseAnd, lhs, rhs)); } break; case BfIRCmd_Or: { CMD_PARAM(BeValue*, lhs); - CMD_PARAM(BeValue*, rhs); + CMD_PARAM(BeValue*, rhs); SetResult(curId, mBeModule->CreateBinaryOp(BeBinaryOpKind_BitwiseOr, lhs, rhs)); } break; case BfIRCmd_Xor: { CMD_PARAM(BeValue*, lhs); - CMD_PARAM(BeValue*, rhs); + CMD_PARAM(BeValue*, rhs); SetResult(curId, mBeModule->CreateBinaryOp(BeBinaryOpKind_ExclusiveOr, lhs, rhs)); } break; case BfIRCmd_Shl: { CMD_PARAM(BeValue*, lhs); - CMD_PARAM(BeValue*, rhs); + CMD_PARAM(BeValue*, rhs); SetResult(curId, mBeModule->CreateBinaryOp(BeBinaryOpKind_LeftShift, lhs, rhs)); } break; case BfIRCmd_AShr: { CMD_PARAM(BeValue*, lhs); - CMD_PARAM(BeValue*, rhs); + CMD_PARAM(BeValue*, rhs); SetResult(curId, mBeModule->CreateBinaryOp(BeBinaryOpKind_ARightShift, lhs, rhs)); } break; case BfIRCmd_LShr: { CMD_PARAM(BeValue*, lhs); - CMD_PARAM(BeValue*, rhs); + CMD_PARAM(BeValue*, rhs); SetResult(curId, mBeModule->CreateBinaryOp(BeBinaryOpKind_RightShift, lhs, rhs)); } break; @@ -1552,7 +1551,7 @@ void BeIRCodeGen::HandleNextCmd() CMD_PARAM(BeValue*, val); auto negInst = mBeModule->AllocInst(); - negInst->mValue = val; + negInst->mValue = val; SetResult(curId, negInst); } break; @@ -1594,7 +1593,7 @@ void BeIRCodeGen::HandleNextCmd() numericCastInst->mValue = val; numericCastInst->mValSigned = false; numericCastInst->mToType = beType; - numericCastInst->mToSigned = isSigned; + numericCastInst->mToSigned = isSigned; SetResult(curId, numericCastInst); } break; @@ -1602,7 +1601,7 @@ void BeIRCodeGen::HandleNextCmd() { CMD_PARAM(BeValue*, val); CMD_PARAM(BeType*, toType); - + auto bitcastInst = mBeModule->AllocInst(); bitcastInst->mValue = val; bitcastInst->mToType = toType; @@ -1649,26 +1648,26 @@ void BeIRCodeGen::HandleNextCmd() { CMD_PARAM(BeValue*, val); BF_ASSERT(val->GetType()->IsPointer()); - SetResult(curId, mBeModule->CreateCmp(BeCmpKind_EQ, val, mBeModule->GetConstantNull((BePointerType*)val->GetType()))); + SetResult(curId, mBeModule->CreateCmp(BeCmpKind_EQ, val, mBeModule->GetConstantNull((BePointerType*)val->GetType()))); } break; case BfIRCmd_IsNotNull: { CMD_PARAM(BeValue*, val); BF_ASSERT(val->GetType()->IsPointer()); - SetResult(curId, mBeModule->CreateCmp(BeCmpKind_NE, val, mBeModule->GetConstantNull((BePointerType*)val->GetType()))); + SetResult(curId, mBeModule->CreateCmp(BeCmpKind_NE, val, mBeModule->GetConstantNull((BePointerType*)val->GetType()))); } break; case BfIRCmd_ExtractValue: { CMD_PARAM(BeValue*, val); CMD_PARAM(int, idx); - + BF_ASSERT(val->GetType()->IsComposite()); auto extractValueInst = mBeModule->AllocInst(); extractValueInst->mAggVal = val; - extractValueInst->mIdx = idx; + extractValueInst->mIdx = idx; SetResult(curId, extractValueInst); } break; @@ -1681,7 +1680,7 @@ void BeIRCodeGen::HandleNextCmd() auto insertValueInst = mBeModule->AllocInst(); insertValueInst->mAggVal = agg; insertValueInst->mMemberVal = val; - insertValueInst->mIdx = idx; + insertValueInst->mIdx = idx; SetResult(curId, insertValueInst); } break; @@ -1691,18 +1690,18 @@ void BeIRCodeGen::HandleNextCmd() if (type->IsStruct()) { BF_ASSERT(!((BeStructType*)type)->mIsOpaque); - } + } auto allocaInst = mBeModule->CreateAlloca(type); allocaInst->mAlign = type->mAlign; - SetResult(curId, allocaInst); + SetResult(curId, allocaInst); } break; case BfIRCmd_AllocaArray: { CMD_PARAM(BeType*, type); CMD_PARAM(BeValue*, arraySize); - + if (auto constant = BeValueDynCast(arraySize)) { //BF_ASSERT(constant->mInt64 >= 0); @@ -1710,9 +1709,9 @@ void BeIRCodeGen::HandleNextCmd() auto allocaInst = mBeModule->AllocInst(); allocaInst->mType = type; - allocaInst->mAlign = type->mAlign; + allocaInst->mAlign = type->mAlign; allocaInst->mArraySize = arraySize; - + SetResult(curId, allocaInst); } break; @@ -1722,7 +1721,7 @@ void BeIRCodeGen::HandleNextCmd() CMD_PARAM(int, alignment); auto inst = BeValueDynCast(val); - inst->mAlign = alignment; + inst->mAlign = alignment; //TODO: Implement /*inst->setAlignment(alignment);*/ } @@ -1756,7 +1755,7 @@ void BeIRCodeGen::HandleNextCmd() break; case BfIRCmd_LifetimeSoftEnd: { - CMD_PARAM(BeValue*, val); + CMD_PARAM(BeValue*, val); auto inst = mBeModule->AllocInst(); inst->mPtr = val; SetResult(curId, inst); @@ -1773,7 +1772,7 @@ void BeIRCodeGen::HandleNextCmd() case BfIRCmd_ValueScopeStart: { auto inst = mBeModule->AllocInst(); - SetResult(curId, inst); + SetResult(curId, inst); } break; case BfIRCmd_ValueScopeRetain: @@ -1784,7 +1783,7 @@ void BeIRCodeGen::HandleNextCmd() } break; case BfIRCmd_ValueScopeSoftEnd: - { + { CMD_PARAM(BeValue*, val); auto inst = mBeModule->AllocInst(); inst->mScopeStart = (BeValueScopeStartInst*)val; @@ -1794,7 +1793,7 @@ void BeIRCodeGen::HandleNextCmd() } break; case BfIRCmd_ValueScopeHardEnd: - { + { CMD_PARAM(BeValue*, val); auto inst = mBeModule->AllocInst(); inst->mScopeStart = (BeValueScopeStartInst*)val; @@ -1820,7 +1819,7 @@ void BeIRCodeGen::HandleNextCmd() case BfIRCmd_Load: { CMD_PARAM(BeValue*, val); -#ifdef _DEBUG +#ifdef _DEBUG auto ptrType = val->GetType(); BF_ASSERT(ptrType->IsPointer()); // We call via a function pointer so there's never a reason to allow loading of a funcPtr @@ -1836,7 +1835,7 @@ void BeIRCodeGen::HandleNextCmd() } #endif - CMD_PARAM(bool, isVolatile); + CMD_PARAM(bool, isVolatile); SetResult(curId, mBeModule->CreateLoad(val, isVolatile)); } break; @@ -1896,7 +1895,7 @@ void BeIRCodeGen::HandleNextCmd() #ifdef _DEBUG auto ptrType = ptr->GetType(); - auto valType = val->GetType(); + auto valType = val->GetType(); if ((!ptrType->IsPointer()) || (!mBeContext->AreTypesEqual(((BePointerType*)ptrType)->mElementType, valType))) { String errStr; @@ -1915,7 +1914,7 @@ void BeIRCodeGen::HandleNextCmd() break; case BfIRCmd_MemSet: { - auto inst = mBeModule->AllocInst(); + auto inst = mBeModule->AllocInst(); Read(inst->mAddr); Read(inst->mVal); Read(inst->mSize); @@ -1946,11 +1945,11 @@ void BeIRCodeGen::HandleNextCmd() { CMD_PARAM(BeType*, varType); CMD_PARAM(bool, isConstant); - BfIRLinkageType linkageType = (BfIRLinkageType)mStream->Read(); + BfIRLinkageType linkageType = (BfIRLinkageType)mStream->Read(); CMD_PARAM(StringT<256>, name); CMD_PARAM(bool, isTLS); CMD_PARAM(BeConstant*, initializer); - + BF_ASSERT(varType != NULL); auto globalVariable = mBeModule->mGlobalVariables.Alloc(); @@ -1959,7 +1958,7 @@ void BeIRCodeGen::HandleNextCmd() globalVariable->mIsConstant = isConstant; globalVariable->mLinkageType = linkageType; globalVariable->mInitializer = initializer; - globalVariable->mName = name; + globalVariable->mName = name; globalVariable->mIsTLS = isTLS; globalVariable->mUnnamedAddr = false; globalVariable->mStorageKind = BfIRStorageKind_Normal; @@ -1970,8 +1969,8 @@ void BeIRCodeGen::HandleNextCmd() BF_ASSERT(mBeContext->AreTypesEqual(varType, initializer->GetType())); } else - globalVariable->mAlign = -1; - + globalVariable->mAlign = -1; + SetResult(curId, globalVariable); } break; @@ -1982,18 +1981,18 @@ void BeIRCodeGen::HandleNextCmd() BF_ASSERT(BeValueDynCast(val) != NULL); - ((BeGlobalVariable*)val)->mUnnamedAddr = true; + ((BeGlobalVariable*)val)->mUnnamedAddr = true; } break; case BfIRCmd_GlobalVar_SetInitializer: { CMD_PARAM(BeValue*, val); CMD_PARAM(BeConstant*, initializer); - + BF_ASSERT(BeValueDynCast(val) != NULL); auto globalVariable = (BeGlobalVariable*)val; - globalVariable->mInitializer = initializer; + globalVariable->mInitializer = initializer; if (globalVariable->mInitializer != NULL) { @@ -2027,7 +2026,7 @@ void BeIRCodeGen::HandleNextCmd() BF_ASSERT(BeValueDynCast(val) != NULL); auto globalVariable = (BeGlobalVariable*)val; - globalVariable->mStorageKind = (BfIRStorageKind)storageKind; + globalVariable->mStorageKind = (BfIRStorageKind)storageKind; } break; case BfIRCmd_GlobalStringPtr: @@ -2050,11 +2049,11 @@ void BeIRCodeGen::HandleNextCmd() globalVariable->mAlign = 1; globalVariable->mUnnamedAddr = false; - auto castedVal = mBeModule->mAlloc.Alloc(); + auto castedVal = mBeModule->mAlloc.Alloc(); castedVal->mType = mBeContext->GetPointerTo(charType); castedVal->mTarget = globalVariable; SetResult(curId, castedVal); - + //SetResult(curId, globalVariable); } break; @@ -2069,7 +2068,7 @@ void BeIRCodeGen::HandleNextCmd() { CMD_PARAM(String, name); CMD_PARAM(bool, addNow); - auto block = mBeModule->CreateBlock(name); + auto block = mBeModule->CreateBlock(name); if (addNow) mBeModule->AddBlock(mActiveFunction, block); @@ -2085,7 +2084,7 @@ void BeIRCodeGen::HandleNextCmd() auto bb = mBeModule->CreateBlock(name); mBeModule->CreateBr(bb); mBeModule->AddBlock(mActiveFunction, bb); - mBeModule->SetInsertPoint(bb); + mBeModule->SetInsertPoint(bb); newBlock = bb; } SetResult(curId, newBlock); @@ -2094,7 +2093,7 @@ void BeIRCodeGen::HandleNextCmd() case BfIRCmd_AddBlock: { CMD_PARAM(BeBlock*, block); - mBeModule->AddBlock(mActiveFunction, block); + mBeModule->AddBlock(mActiveFunction, block); } break; case BfIRCmd_DropBlocks: @@ -2103,10 +2102,10 @@ void BeIRCodeGen::HandleNextCmd() auto& basicBlockList = mActiveFunction->mBlocks; int postExitBlockIdx = -1; - /*auto itr = basicBlockList.begin(); + /*auto itr = basicBlockList.begin(); while (itr != basicBlockList.end()) { - auto block = *itr; + auto block = *itr; if (block == startingBlock) { basicBlockList.erase(itr, basicBlockList.end()); @@ -2128,21 +2127,21 @@ void BeIRCodeGen::HandleNextCmd() case BfIRCmd_MergeBlockDown: { CMD_PARAM(BeBlock*, fromBlock); - CMD_PARAM(BeBlock*, intoBlock); + CMD_PARAM(BeBlock*, intoBlock); for (auto inst : fromBlock->mInstructions) inst->mParentBlock = intoBlock; if (!fromBlock->mInstructions.IsEmpty()) intoBlock->mInstructions.Insert(0, &fromBlock->mInstructions[0], fromBlock->mInstructions.size()); mBeModule->RemoveBlock(mActiveFunction, fromBlock); } - break; + break; case BfIRCmd_GetInsertBlock: { SetResult(curId, mBeModule->mActiveBlock); } break; case BfIRCmd_SetInsertPoint: - { + { CMD_PARAM(BeBlock*, block); mBeModule->SetInsertPoint(block); } @@ -2161,9 +2160,9 @@ void BeIRCodeGen::HandleNextCmd() break; case BfIRCmd_DeleteBlock: { - CMD_PARAM(BeBlock*, block); + CMD_PARAM(BeBlock*, block); } - break; + break; case BfIRCmd_EraseInstFromParent: { CMD_PARAM(BeValue*, instVal); @@ -2172,7 +2171,7 @@ void BeIRCodeGen::HandleNextCmd() bool wasRemoved = inst->mParentBlock->mInstructions.Remove(inst); BF_ASSERT(wasRemoved); #ifdef _DEBUG - inst->mWasRemoved = true; + inst->mWasRemoved = true; #endif } break; @@ -2186,7 +2185,7 @@ void BeIRCodeGen::HandleNextCmd() { CMD_PARAM(BeBlock*, block); auto inst = mBeModule->CreateBr(block); - inst->mIsFake = true; + inst->mIsFake = true; } break; case BfIRCmd_CreateBr_NoCollapse: @@ -2220,15 +2219,15 @@ void BeIRCodeGen::HandleNextCmd() auto switchInst = mBeModule->AllocInstOwned(); switchInst->mValue = val; switchInst->mDefaultBlock = dest; - switchInst->mCases.Reserve(numCases); + switchInst->mCases.Reserve(numCases); SetResult(curId, switchInst); } break; case BfIRCmd_AddSwitchCase: - { + { CMD_PARAM(BeValue*, switchVal); CMD_PARAM(BeValue*, caseVal); - CMD_PARAM(BeBlock*, caseBlock); + CMD_PARAM(BeBlock*, caseBlock); BeSwitchCase switchCase; switchCase.mValue = (BeConstant*)caseVal; @@ -2269,7 +2268,7 @@ void BeIRCodeGen::HandleNextCmd() } break; case BfIRCmd_GetIntrinsic: - { + { CMD_PARAM(String, intrinName); CMD_PARAM(int, intrinId); CMD_PARAM(BeType*, returnType); @@ -2283,7 +2282,7 @@ void BeIRCodeGen::HandleNextCmd() } break; case BfIRCmd_CreateFunctionType: - { + { CMD_PARAM(BeType*, resultType); CMD_PARAM(CmdParamVec, paramTypes); CMD_PARAM(bool, isVarArg); @@ -2296,7 +2295,7 @@ void BeIRCodeGen::HandleNextCmd() CMD_PARAM(BeFunctionType*, type); BfIRLinkageType linkageType = (BfIRLinkageType)mStream->Read(); CMD_PARAM(String, name); - SetResult(curId, mBeModule->CreateFunction(type, linkageType, name)); + SetResult(curId, mBeModule->CreateFunction(type, linkageType, name)); } break; case BfIRCmd_SetFunctionName: @@ -2309,7 +2308,6 @@ void BeIRCodeGen::HandleNextCmd() break; case BfIRCmd_EnsureFunctionPatchable: { - } break; case BfIRCmd_RemapBindFunction: @@ -2350,25 +2348,25 @@ void BeIRCodeGen::HandleNextCmd() dbgGlobalVariable->mDecl = decl; }*/ } - + SetResult(curId, mBeModule->CreateLoad(beFunc->mRemapBindVar, false)); } else - SetResult(curId, func); + SetResult(curId, func); } break; case BfIRCmd_SetActiveFunction: { - CMD_PARAM(BeFunction*, func); + CMD_PARAM(BeFunction*, func); mActiveFunction = func; mBeModule->mActiveFunction = func; } break; case BfIRCmd_CreateCall: - { + { CMD_PARAM(BeValue*, func); CMD_PARAM(CmdParamVec, args); - + #ifdef BE_EXTRA_CHECKS auto funcPtrType = func->GetType(); if (funcPtrType != NULL) @@ -2420,7 +2418,7 @@ void BeIRCodeGen::HandleNextCmd() BF_ASSERT(func->GetTypeId() == BeIntrinsic::TypeId); } #endif - SetResult(curId, mBeModule->CreateCall(func, args)); + SetResult(curId, mBeModule->CreateCall(func, args)); } break; case BfIRCmd_SetCallCallingConv: @@ -2433,7 +2431,7 @@ void BeIRCodeGen::HandleNextCmd() case BfIRCmd_SetFuncCallingConv: { CMD_PARAM(BeFunction*, func); - BfIRCallingConv callingConv = (BfIRCallingConv)mStream->Read(); + BfIRCallingConv callingConv = (BfIRCallingConv)mStream->Read(); func->mCallingConv = callingConv; } break; @@ -2446,9 +2444,9 @@ void BeIRCodeGen::HandleNextCmd() break; case BfIRCmd_SetCallAttribute: { - CMD_PARAM(BeValue*, callInstVal); + CMD_PARAM(BeValue*, callInstVal); CMD_PARAM(int, paramIdx); - BfIRAttribute attribute = (BfIRAttribute)mStream->Read(); + BfIRAttribute attribute = (BfIRAttribute)mStream->Read(); BeCallInst* callInst = (BeCallInst*)callInstVal; if (attribute == BfIRAttribute_NoReturn) callInst->mNoReturn = true; @@ -2503,7 +2501,7 @@ void BeIRCodeGen::HandleNextCmd() else if (attribute == BfIRAttribute_NoCapture) callInst->mArgs[argIdx - 1].mNoCapture = true; else if (attribute == BfIRAttribute_ByVal) - { + { } else BF_FATAL("Unhandled"); @@ -2511,10 +2509,10 @@ void BeIRCodeGen::HandleNextCmd() else { if (attribute == BfIRAttribute_NoReturn) - callInst->mNoReturn = true; + callInst->mNoReturn = true; else BF_FATAL("Unhandled"); - } + } } break; case BfIRCmd_Call_AddAttribute1: @@ -2523,7 +2521,7 @@ void BeIRCodeGen::HandleNextCmd() CMD_PARAM(int, argIdx); BfIRAttribute attribute = (BfIRAttribute)mStream->Read(); CMD_PARAM(int, arg); - + BeCallInst* callInst = BeValueDynCast(inst); if (callInst != NULL) { @@ -2578,7 +2576,7 @@ void BeIRCodeGen::HandleNextCmd() if (attribute == BfIRAttribute_VarRet) func->mIsVarReturn = true; else if (attribute == BFIRAttribute_AlwaysInline) - func->mAlwaysInline = true; + func->mAlwaysInline = true; else if (attribute == BFIRAttribute_NoUnwind) func->mNoUnwind = true; else if (attribute == BFIRAttribute_UWTable) @@ -2602,7 +2600,7 @@ void BeIRCodeGen::HandleNextCmd() } else BF_FATAL("Unhandled"); - } + } } break; case BfIRCmd_Func_AddAttribute1: @@ -2610,15 +2608,15 @@ void BeIRCodeGen::HandleNextCmd() CMD_PARAM(BeFunction*, func); CMD_PARAM(int, argIdx); BfIRAttribute attribute = (BfIRAttribute)mStream->Read(); - CMD_PARAM(int, arg); + CMD_PARAM(int, arg); // This is for adding things like Dereferencable, which we don't use if (argIdx > 0) { if (attribute == BfIRAttribute_Dereferencable) func->mParams[argIdx - 1].mDereferenceableSize = arg; - else if (attribute == BfIRAttribute_ByVal) - func->mParams[argIdx - 1].mByValSize = arg; + else if (attribute == BfIRAttribute_ByVal) + func->mParams[argIdx - 1].mByValSize = arg; else BF_FATAL("Unhandled"); } @@ -2632,9 +2630,9 @@ void BeIRCodeGen::HandleNextCmd() CMD_PARAM(int, argIdx); CMD_PARAM(String, name); if (argIdx > 0) - func->mParams[argIdx - 1].mName = name; + func->mParams[argIdx - 1].mName = name; } - break; + break; case BfIRCmd_Func_DeleteBody: { CMD_PARAM(BeFunction*, func); @@ -2658,7 +2656,7 @@ void BeIRCodeGen::HandleNextCmd() case BfIRCmd_Func_SetLinkage: { CMD_PARAM(BeFunction*, func); - BfIRLinkageType linkageType = (BfIRLinkageType)mStream->Read(); + BfIRLinkageType linkageType = (BfIRLinkageType)mStream->Read(); func->mLinkageType = linkageType; } break; @@ -2682,7 +2680,7 @@ void BeIRCodeGen::HandleNextCmd() { mBeModule->SetCurrentDebugLocation(NULL); } - break; + break; case BfIRCmd_ClearDebugLocationInst: { CMD_PARAM(BeValue*, instValue); @@ -2696,7 +2694,7 @@ void BeIRCodeGen::HandleNextCmd() { auto inst = mBeModule->mActiveBlock->mInstructions.back(); inst->mDbgLoc = NULL; - } + } } break; case BfIRCmd_UpdateDebugLocation: @@ -2718,7 +2716,7 @@ void BeIRCodeGen::HandleNextCmd() break; case BfIRCmd_Nop: { - mBeModule->CreateNop(); + mBeModule->CreateNop(); } break; case BfIRCmd_EnsureInstructionAt: @@ -2728,7 +2726,6 @@ void BeIRCodeGen::HandleNextCmd() break; case BfIRCmd_StatementStart: { - } break; case BfIRCmd_ObjectAccessCheck: @@ -2747,7 +2744,7 @@ void BeIRCodeGen::HandleNextCmd() CMD_PARAM(int32, error); auto inst = mBeModule->AllocInst(); - inst->mError = error; + inst->mError = error; SetResult(curId, inst); } break; @@ -2831,7 +2828,6 @@ void BeIRCodeGen::HandleNextCmd() typeEntry.mInstDIType->resolveCycles(); } mDIBuilder->finalize();*/ - } break; case BfIRCmd_DbgCreateCompileUnit: @@ -2844,7 +2840,7 @@ void BeIRCodeGen::HandleNextCmd() CMD_PARAM(String, flags); CMD_PARAM(int, runtimeVer); CMD_PARAM(bool, linesOnly); - + mBeModule->mDbgModule->mFileName = fileName; mBeModule->mDbgModule->mDirectory = directory; mBeModule->mDbgModule->mProducer = producer; @@ -2861,17 +2857,17 @@ void BeIRCodeGen::HandleNextCmd() CMD_PARAM(Val128, md5Hash); auto dbgFile = mBeModule->mDbgModule->mFiles.Alloc(); - dbgFile->mFileName = fileName; + dbgFile->mFileName = fileName; dbgFile->mDirectory = directory; dbgFile->mMD5Hash = md5Hash; dbgFile->mIdx = (int)mBeModule->mDbgModule->mFiles.size() - 1; - SetResult(curId, dbgFile); + SetResult(curId, dbgFile); } break; case BfIRCmd_DbgGetCurrentLocation: { - SetResult(curId, mBeModule->mCurDbgLoc); + SetResult(curId, mBeModule->mCurDbgLoc); } break; case BfIRCmd_DbgSetType: @@ -2935,7 +2931,7 @@ void BeIRCodeGen::HandleNextCmd() auto dbgNamespace = mBeModule->mOwnedValues.Alloc(); dbgNamespace->mScope = scope; dbgNamespace->mName = name; - SetResult(curId, dbgNamespace); + SetResult(curId, dbgNamespace); } break; case BfIRCmd_DbgCreateImportedModule: @@ -2959,7 +2955,7 @@ void BeIRCodeGen::HandleNextCmd() dbgType->mSize = (int)(sizeInBits / 8); dbgType->mAlign = (int)(alignInBits / 8); dbgType->mEncoding = encoding; - + SetResult(curId, dbgType); } break; @@ -2974,21 +2970,21 @@ void BeIRCodeGen::HandleNextCmd() CMD_PARAM(int, flags); CMD_PARAM(BeMDNode*, derivedFrom); CMD_PARAM(CmdParamVec, members); - + auto dbgType = mBeModule->mDbgModule->mTypes.Alloc(); dbgType->mScope = context; dbgType->mName = name; dbgType->mSize = (int)(sizeInBits / 8); - dbgType->mAlign = (int)(alignInBits / 8); + dbgType->mAlign = (int)(alignInBits / 8); dbgType->mDerivedFrom = BeValueDynCast(derivedFrom); dbgType->mDefFile = (BeDbgFile*)file; dbgType->mDefLine = lineNum - 1; - dbgType->mIsFullyDefined = true; + dbgType->mIsFullyDefined = true; dbgType->SetMembers(members); - + SetResult(curId, dbgType); } - break; + break; case BfIRCmd_DbgCreateEnumerationType: { CMD_PARAM(BeMDNode*, context); @@ -2996,10 +2992,10 @@ void BeIRCodeGen::HandleNextCmd() CMD_PARAM(BeMDNode*, file); CMD_PARAM(int, lineNum); CMD_PARAM(int64, sizeInBits); - CMD_PARAM(int64, alignInBits); + CMD_PARAM(int64, alignInBits); CMD_PARAM(CmdParamVec, members); CMD_PARAM(BeMDNode*, underlyingType); - + auto dbgType = mBeModule->mDbgModule->mTypes.Alloc(); dbgType->mScope = context; dbgType->mName = name; @@ -3012,7 +3008,7 @@ void BeIRCodeGen::HandleNextCmd() if (auto enumMember = BeValueDynCast(member)) { dbgType->mMembers.push_back(enumMember); - } + } else NotImpl(); } @@ -3023,9 +3019,9 @@ void BeIRCodeGen::HandleNextCmd() } break; case BfIRCmd_DbgCreatePointerType: - { + { CMD_PARAM(BeMDNode*, elementTypeNode); - + BeDbgType* elementType = BeValueDynCast(elementTypeNode); if (elementType == NULL) { @@ -3038,7 +3034,7 @@ void BeIRCodeGen::HandleNextCmd() dbgType->mTypeId = bfPtrType->mTypeId; SetResult(curId, dbgType); break; - } + } } BeDbgType* useType = elementType->FindDerivedType(BeDbgPointerType::TypeId); @@ -3050,7 +3046,7 @@ void BeIRCodeGen::HandleNextCmd() dbgType->mAlign = mPtrSize; elementType->mDerivedTypes.PushFront(dbgType, &mBeModule->mAlloc); useType = dbgType; - } + } SetResult(curId, useType); } @@ -3058,7 +3054,7 @@ void BeIRCodeGen::HandleNextCmd() case BfIRCmd_DbgCreateReferenceType: { CMD_PARAM(BeMDNode*, elementTypeNode); - + BeDbgType* elementType = BeValueDynCast(elementTypeNode); if (elementType == NULL) { @@ -3073,7 +3069,7 @@ void BeIRCodeGen::HandleNextCmd() break; } } - + auto useType = mBeModule->mDbgModule->CreateReferenceType(elementType); SetResult(curId, useType); } @@ -3082,7 +3078,7 @@ void BeIRCodeGen::HandleNextCmd() { CMD_PARAM(BeMDNode*, elementTypeNode); - BeDbgType* elementType = BeValueDynCast(elementTypeNode); + BeDbgType* elementType = BeValueDynCast(elementTypeNode); if (elementType == NULL) { auto dbgType = mBeModule->mDbgModule->mTypes.Alloc(); @@ -3113,7 +3109,7 @@ void BeIRCodeGen::HandleNextCmd() // Does the artificial thing do anything for us actually? auto dbgType = diType; - SetResult(curId, dbgType); + SetResult(curId, dbgType); } break; case BfIRCmd_DbgCreateArrayType: @@ -3160,13 +3156,13 @@ void BeIRCodeGen::HandleNextCmd() dbgType->mScope = scope; dbgType->mName = name; dbgType->mSize = (int)(sizeInBits / 8); - dbgType->mAlign = (int)(alignInBits / 8); + dbgType->mAlign = (int)(alignInBits / 8); //dbgType->mDefFile = (BeDbgFile*)file; //dbgType->mDefLine = line - 1; SetResult(curId, dbgType); } else - NotImpl(); + NotImpl(); } break; case BfIRCmd_DbgCreateForwardDecl: @@ -3181,7 +3177,7 @@ void BeIRCodeGen::HandleNextCmd() { auto dbgType = mBeModule->mDbgModule->mTypes.Alloc(); dbgType->mScope = scope; - dbgType->mName = name; + dbgType->mName = name; dbgType->mDefFile = (BeDbgFile*)file; dbgType->mDefLine = line; SetResult(curId, dbgType); @@ -3194,7 +3190,7 @@ void BeIRCodeGen::HandleNextCmd() SetResult(curId, dbgType); } else - NotImpl(); + NotImpl(); } break; case BfIRCmd_DbgCreateSizedForwardDecl: @@ -3206,7 +3202,7 @@ void BeIRCodeGen::HandleNextCmd() CMD_PARAM(int, line); CMD_PARAM(int64, sizeInBits); CMD_PARAM(int64, alignInBits); - + if (tag == llvm::dwarf::DW_TAG_structure_type) { auto dbgType = mBeModule->mDbgModule->mTypes.Alloc(); @@ -3220,7 +3216,7 @@ void BeIRCodeGen::HandleNextCmd() } else if (tag == llvm::dwarf::DW_TAG_enumeration_type) { - auto dbgType = mBeModule->mDbgModule->mTypes.Alloc(); + auto dbgType = mBeModule->mDbgModule->mTypes.Alloc(); dbgType->mScope = scope; dbgType->mName = name; dbgType->mSize = (int)(sizeInBits / 8); @@ -3238,14 +3234,14 @@ void BeIRCodeGen::HandleNextCmd() CMD_PARAM(int64, alignInBits); if (auto dbgType = BeValueDynCast(mdType)) - { + { dbgType->mSize = (int)(sizeInBits / 8); dbgType->mAlign = (int)(alignInBits / 8); - } + } } break; case BfIRCmd_DbgReplaceAllUses: - { + { CMD_PARAM(BeMDNode*, diPrevNode); CMD_PARAM(BeMDNode*, diNewNode); /*diPrevNode->replaceAllUsesWith(diNewNode); */ @@ -3263,12 +3259,12 @@ void BeIRCodeGen::HandleNextCmd() { CMD_PARAM(BeMDNode*, diNode); CMD_PARAM(BeMDNode*, diBaseType); - CMD_PARAM(CmdParamVec, members); - + CMD_PARAM(CmdParamVec, members); + if (auto dbgType = BeValueDynCast(diNode)) { dbgType->SetMembers(members); - } + } else if (auto dbgType = BeValueDynCast(diNode)) { dbgType->mElementType = BeValueDynCast(diBaseType); @@ -3322,7 +3318,7 @@ void BeIRCodeGen::HandleNextCmd() CMD_PARAM(BeMDNode*, type); CMD_PARAM(int, flags); CMD_PARAM(BeConstant*, val); - + BF_ASSERT(type != NULL); auto dbgMember = mBeModule->mOwnedValues.Alloc(); @@ -3355,8 +3351,8 @@ void BeIRCodeGen::HandleNextCmd() CMD_PARAM(String, name); CMD_PARAM(String, linkageName); CMD_PARAM(BeMDNode*, file); - CMD_PARAM(int, lineNum); - CMD_PARAM(BeMDNode*, type); + CMD_PARAM(int, lineNum); + CMD_PARAM(BeMDNode*, type); CMD_PARAM(bool, isLocalToUnit); CMD_PARAM(bool, isDefinition); CMD_PARAM(int, vk); @@ -3382,14 +3378,14 @@ void BeIRCodeGen::HandleNextCmd() dbgFunc->mIsStaticMethod = (flags & llvm::DINode::FlagStaticMember) != 0; dbgFunc->mFlags = flags; - for (auto arg : genericArgs) + for (auto arg : genericArgs) { BF_ASSERT(arg != NULL); dbgFunc->mGenericArgs.Add(BeValueDynCast(arg)); } for (auto genericConstValue : genericConstValueArgs) dbgFunc->mGenericConstValueArgs.Add(genericConstValue); - + if (dbgFunc->mValue != NULL) dbgFunc->mValue->mDbgFunction = dbgFunc; dbgFunc->mIdx = (int)mBeModule->mDbgModule->mFuncs.size(); @@ -3404,15 +3400,15 @@ void BeIRCodeGen::HandleNextCmd() CMD_PARAM(String, name); CMD_PARAM(String, linkageName); CMD_PARAM(BeMDNode*, file); - CMD_PARAM(int, lineNum); - CMD_PARAM(BeMDNode*, type); + CMD_PARAM(int, lineNum); + CMD_PARAM(BeMDNode*, type); CMD_PARAM(bool, isLocalToUnit); - CMD_PARAM(bool, isDefinition); + CMD_PARAM(bool, isDefinition); CMD_PARAM(int, scopeLine); CMD_PARAM(int, flags); CMD_PARAM(bool, isOptimized); CMD_PARAM(BeValue*, fn); - + auto dbgFunc = mBeModule->mOwnedValues.Alloc(); dbgFunc->mScope = context; dbgFunc->mFile = (BeDbgFile*)file; @@ -3430,12 +3426,11 @@ void BeIRCodeGen::HandleNextCmd() } else { - }*/ if (dbgFunc->mValue != NULL) dbgFunc->mValue->mDbgFunction = dbgFunc; dbgFunc->mIdx = (int)mBeModule->mDbgModule->mFuncs.size(); - mBeModule->mDbgModule->mFuncs.push_back(dbgFunc); + mBeModule->mDbgModule->mFuncs.push_back(dbgFunc); SetResult(curId, dbgFunc); } @@ -3471,7 +3466,7 @@ void BeIRCodeGen::HandleNextCmd() dbgFunc->mVariables.Insert(argIdx, dbgVar); } //mActiveFunction->mDbgFunction->mVariables.push_back(dbgVar); - + //dbgVar->mValue = mBeModule->GetArgument(argNo - 1); SetResult(curId, dbgVar); @@ -3572,11 +3567,11 @@ void BeIRCodeGen::HandleNextCmd() CMD_PARAM(BeMDNode*, file); CMD_PARAM(int, lineNum); CMD_PARAM(BeMDNode*, type); - CMD_PARAM(bool, isLocalToUnit); + CMD_PARAM(bool, isLocalToUnit); CMD_PARAM(BeConstant*, val); CMD_PARAM(BeMDNode*, decl); - auto dbgGlobalVariable = mBeModule->mDbgModule->mGlobalVariables.Alloc(); + auto dbgGlobalVariable = mBeModule->mDbgModule->mGlobalVariables.Alloc(); dbgGlobalVariable->mContext = context; dbgGlobalVariable->mName = name; dbgGlobalVariable->mLinkageName = linkageName; @@ -3602,10 +3597,10 @@ void BeIRCodeGen::HandleNextCmd() dbgLexicalBlock->mFile = (BeDbgFile*)file; dbgLexicalBlock->mScope = scope; dbgLexicalBlock->mId = mBeModule->mCurLexBlockId++; - + SetResult(curId, dbgLexicalBlock); } - break; + break; case BfIRCmd_DbgCreateAnnotation: { CMD_PARAM(BeMDNode*, scope); @@ -3618,13 +3613,13 @@ void BeIRCodeGen::HandleNextCmd() BeDbgType** dbgTypePtr; if (mOnDemandTypeMap.TryAdd(beType, NULL, &dbgTypePtr)) { - auto dbgType = mBeModule->mDbgModule->mTypes.Alloc(); + auto dbgType = mBeModule->mDbgModule->mTypes.Alloc(); dbgType->mSize = beType->mSize; dbgType->mAlign = beType->mAlign; dbgType->mEncoding = llvm::dwarf::DW_ATE_signed; *dbgTypePtr = dbgType; } - + auto dbgVar = mBeModule->mOwnedValues.Alloc(); dbgVar->mName = "#" + name; dbgVar->mType = *dbgTypePtr; @@ -3635,7 +3630,7 @@ void BeIRCodeGen::HandleNextCmd() auto inst = mBeModule->AllocInst(); inst->mValue = value; inst->mDbgVar = dbgVar; - inst->mIsValue = true; + inst->mIsValue = true; } else NotImpl(); @@ -3644,9 +3639,9 @@ void BeIRCodeGen::HandleNextCmd() default: BF_FATAL("Unhandled"); break; - } + } -#ifdef CODEGEN_TRACK +#ifdef CODEGEN_TRACK gBEMemReporter.EndSection(); gBEMemReporterSize += mStream->GetReadPos() - curId; @@ -3656,7 +3651,7 @@ void BeIRCodeGen::HandleNextCmd() void BeIRCodeGen::SetConfigConst(int idx, int value) { BF_ASSERT(idx == (int)mConfigConsts.size()); - mConfigConsts.Add(value); + mConfigConsts.Add(value); } BeValue* BeIRCodeGen::GetBeValue(int id) @@ -3724,4 +3719,4 @@ void BeIRCodeGen::SetState(const BeState& state) mBeModule->mCurDbgLoc = state.mCurDbgLoc; mBeModule->mPrevDbgLocInline = state.mPrevDbgLocInline; mBeModule->mLastDbgLoc = state.mLastDbgLoc; -} +} \ No newline at end of file diff --git a/IDEHelper/Backend/BeIRCodeGen.h b/IDEHelper/Backend/BeIRCodeGen.h index e18426ba..cc99faa6 100644 --- a/IDEHelper/Backend/BeIRCodeGen.h +++ b/IDEHelper/Backend/BeIRCodeGen.h @@ -75,40 +75,40 @@ class BeIRCodeGen : public BfIRCodeGenBase { public: bool mDebugging; - - BfIRBuilder* mBfIRBuilder; + + BfIRBuilder* mBfIRBuilder; BeFunction* mActiveFunction; BeContext* mBeContext; - BeModule* mBeModule; - Array mSavedDebugLocs; - bool mHasDebugLoc; + BeModule* mBeModule; + Array mSavedDebugLocs; + bool mHasDebugLoc; int mCmdCount; Dictionary mResults; - Dictionary mTypes; + Dictionary mTypes; Dictionary mOnDemandTypeMap; Dictionary mReflectDataMap; - Array mConfigConsts; + Array mConfigConsts; -public: +public: void FatalError(const StringImpl& str); void NotImpl(); BfTypeCode GetTypeCode(BeType* type, bool isSigned); void SetResult(int id, BeValue* value); void SetResult(int id, BeType* type); void SetResult(int id, BeBlock* value); - void SetResult(int id, BeMDNode* md); + void SetResult(int id, BeMDNode* md); BeType* GetBeType(BfTypeCode typeCode, bool& isSigned); - BeIRTypeEntry& GetTypeEntry(int typeId); + BeIRTypeEntry& GetTypeEntry(int typeId); void FixValues(BeStructType* structType, CmdParamVec& values); public: BeIRCodeGen(); - ~BeIRCodeGen(); + ~BeIRCodeGen(); void Hash(BeHashContext& hashCtx); bool IsModuleEmpty(); @@ -127,12 +127,12 @@ public: void Read(BeConstant*& beConstant); void Read(BeFunction*& beFunc); void Read(BeBlock*& beBlock); - void Read(BeMDNode*& beMD); + void Read(BeMDNode*& beMD); template void Read(SizedArrayImpl& vec) { - int len = (int)ReadSLEB128(); + int len = (int)ReadSLEB128(); for (int i = 0; i < len; i++) { T result; @@ -140,11 +140,11 @@ public: vec.push_back(result); } } - + void Init(const BfSizedArray& buffer); void Process(); - virtual void ProcessBfIRData(const BfSizedArray& buffer) override; + virtual void ProcessBfIRData(const BfSizedArray& buffer) override; virtual void HandleNextCmd() override; virtual void SetConfigConst(int idx, int value) override; diff --git a/IDEHelper/Backend/BeLibManger.cpp b/IDEHelper/Backend/BeLibManger.cpp index 22590719..30fc23f0 100644 --- a/IDEHelper/Backend/BeLibManger.cpp +++ b/IDEHelper/Backend/BeLibManger.cpp @@ -1,4 +1,3 @@ - #pragma warning(disable:4996) #include "BeLibManger.h" #include "BeefySysLib/util/BeefPerf.h" @@ -37,7 +36,7 @@ bool BeLibFile::ReadLib() mOldFileStream.Read(fileId, 8); if (strncmp(fileId, "!\n", 8) != 0) return false; - + const char* libStrTable = NULL; Dictionary pendingLibEntryMap; @@ -62,18 +61,18 @@ bool BeLibFile::ReadLib() mOldFileStream.Read(data, len); int numSymbols = FromBigEndian(*(int32*)data); - + uint8* strTab = data + 4 + numSymbols * 4; for (int symIdx = 0; symIdx < numSymbols; symIdx++) - { + { const char* str = (char*)strTab; strTab += strlen((char*)strTab) + 1; int offset = FromBigEndian(((int32*)(data + 4))[symIdx]); - - BeLibEntry* pendingEntry; - + + BeLibEntry* pendingEntry; + BeLibEntry** pendingEntryPtr = NULL; if (!pendingLibEntryMap.TryAdd(offset, NULL, &pendingEntryPtr)) { @@ -93,7 +92,6 @@ bool BeLibFile::ReadLib() } else { - } } else if (strncmp(header.mName, "// ", 3) == 0) @@ -115,7 +113,7 @@ bool BeLibFile::ReadLib() fileName.Append(&libStrTable[tabIdx], checkIdx - tabIdx); break; } - } + } } else { @@ -125,9 +123,9 @@ bool BeLibFile::ReadLib() fileName.Append(&header.mName[0], i); } } - + BeLibEntry* libEntry = NULL; - + if (!pendingLibEntryMap.TryGetValue(headerFilePos, &libEntry)) { libEntry = new BeLibEntry(); @@ -171,11 +169,11 @@ bool BeLibFile::ReadLib() } bool BeLibFile::Init(const StringImpl& filePath, bool moveFile) -{ - bool isInitialized = false; +{ + bool isInitialized = false; if (FileExists(filePath)) - { + { String altName; if (moveFile) { @@ -196,14 +194,14 @@ bool BeLibFile::Init(const StringImpl& filePath, bool moveFile) if (!mOldFileStream.Open(altName, "rb")) return false; - + if (!ReadLib()) return false; - } - - String newLibName = filePath; + } + + String newLibName = filePath; mFilePath = newLibName; - + return true; } @@ -212,9 +210,9 @@ bool BeLibFile::Finish() BP_ZONE("BeLibFile::Finish"); //mOldEntries.clear(); - - Dictionary* libEntryMaps[2] = { &mEntries, &mOldEntries }; - + + Dictionary* libEntryMaps[2] = { &mEntries, &mOldEntries }; + Array libEntries; bool isAllReferenced = true; @@ -241,7 +239,7 @@ bool BeLibFile::Finish() } if (!mFileStream.Open(mFilePath, "wb")) - { + { mFailed = true; return false; } @@ -255,7 +253,7 @@ bool BeLibFile::Finish() mFileStream.Write("!\n", 8); - std::sort(libEntries.begin(), libEntries.end(), + std::sort(libEntries.begin(), libEntries.end(), [&](BeLibEntry* lhs, BeLibEntry* rhs) { return lhs->mName < rhs->mName; @@ -263,12 +261,12 @@ bool BeLibFile::Finish() int longNamesSize = 0; - int tabSize = 4; // num symbols + int tabSize = 4; // num symbols int numSymbols = 0; for (auto libEntry : libEntries) { if (libEntry->mName.length() > 15) - { + { longNamesSize += (int)libEntry->mName.length() + 2; } @@ -277,28 +275,27 @@ bool BeLibFile::Finish() numSymbols++; tabSize += 4; // Offset tabSize += (int)sym.length() + 1; // String table - } + } } - + // Determine where all these entries will be placed int predictPos = mFileStream.GetPos() + sizeof(BeLibMemberHeader) + BF_ALIGN(tabSize, 2); if (longNamesSize > 0) - predictPos += sizeof(BeLibMemberHeader) + BF_ALIGN(longNamesSize, 2); + predictPos += sizeof(BeLibMemberHeader) + BF_ALIGN(longNamesSize, 2); for (auto libEntry : libEntries) { libEntry->mNewDataPos = predictPos; - + predictPos += sizeof(BeLibMemberHeader); - predictPos += BF_ALIGN(libEntry->mLength, 2); + predictPos += BF_ALIGN(libEntry->mLength, 2); } int tabStartPos = mFileStream.GetPos(); - - + BeLibMemberHeader header; - header.Init("/", "0", tabSize); + header.Init("/", "0", tabSize); mFileStream.WriteT(header); mFileStream.Write(ToBigEndian((int32)numSymbols)); @@ -308,7 +305,7 @@ bool BeLibFile::Finish() for (auto& sym : libEntry->mSymbols) { mFileStream.Write((int32)ToBigEndian(libEntry->mNewDataPos)); - } + } } // String map table @@ -317,11 +314,11 @@ bool BeLibFile::Finish() for (auto& sym : libEntry->mSymbols) { mFileStream.Write((uint8*)sym.c_str(), (int)sym.length() + 1); - } + } } int actualTabSize = mFileStream.GetPos() - tabStartPos - sizeof(BeLibMemberHeader); - + //return true; if ((tabSize % 2) != 0) @@ -332,16 +329,16 @@ bool BeLibFile::Finish() // Create long names table if (longNamesSize > 0) { - header.Init("//", "0", longNamesSize); + header.Init("//", "0", longNamesSize); mFileStream.WriteT(header); for (auto libEntry : libEntries) { - if (libEntry->mName.length() > 15) + if (libEntry->mName.length() > 15) { mFileStream.Write((uint8*)libEntry->mName.c_str(), (int)libEntry->mName.length()); mFileStream.Write("/\n", 2); - } + } } if ((longNamesSize % 2) != 0) @@ -357,9 +354,9 @@ bool BeLibFile::Finish() String entryName; if (libEntry->mName.length() > 15) - { - char idxStr[32]; - _itoa(longNamesPos, idxStr, 10); + { + char idxStr[32]; + _itoa(longNamesPos, idxStr, 10); entryName = "/"; entryName += idxStr; longNamesPos += (int)libEntry->mName.length() + 2; @@ -370,7 +367,7 @@ bool BeLibFile::Finish() entryName += "/"; } - header.Init(entryName.c_str(), "644", libEntry->mLength); + header.Init(entryName.c_str(), "644", libEntry->mLength); mFileStream.WriteT(header); if (libEntry->mOldDataPos != -1) @@ -383,11 +380,11 @@ bool BeLibFile::Finish() } else if (libEntry->mData.size() != 0) { - mFileStream.Write((uint8*)&libEntry->mData[0], (int)libEntry->mData.size()); + mFileStream.Write((uint8*)&libEntry->mData[0], (int)libEntry->mData.size()); } if ((libEntry->mLength % 2) != 0) - mFileStream.Write((uint8)0); + mFileStream.Write((uint8)0); } mFileStream.Close(); @@ -448,7 +445,7 @@ BeLibEntry* BeLibManager::AddFile(const StringImpl& filePath, void* data, int si libFile = *libFilePtr; } else - { + { libFile = new BeLibFile(); *libFilePtr = libFile; @@ -485,7 +482,7 @@ BeLibEntry* BeLibManager::AddFile(const StringImpl& filePath, void* data, int si // It's possible that we rebuild a type (generic, probably), decide we don't have any refs so we delete the type, // but then we specialize methods and then have to recreate it. Thus two entries here. delete *libEntryPtr; - } + } libEntry = new BeLibEntry(); libEntry->mLibFile = libFile; *libEntryPtr = libEntry; @@ -494,7 +491,7 @@ BeLibEntry* BeLibManager::AddFile(const StringImpl& filePath, void* data, int si libEntry->mName = fileName; libEntry->mData.Insert(0, (uint8*)data, size); libEntry->mLength = size; - + return libEntry; } @@ -533,5 +530,4 @@ String BeLibManager::GetLibFilePath(const StringImpl& objFilePath) BeLibManager* BeLibManager::Get() { return &gBfLibManager; -} - +} \ No newline at end of file diff --git a/IDEHelper/Backend/BeLibManger.h b/IDEHelper/Backend/BeLibManger.h index a1634e79..3d073eb0 100644 --- a/IDEHelper/Backend/BeLibManger.h +++ b/IDEHelper/Backend/BeLibManger.h @@ -39,7 +39,7 @@ struct BeLibMemberHeader memcpy(mDate, "0", 1); memcpy(mMode, mode, strlen(mode)); - char sizeStr[32]; + char sizeStr[32]; sprintf(sizeStr, "%d", size); memcpy(mSize, sizeStr, strlen(sizeStr)); } @@ -60,7 +60,7 @@ public: Array mData; BeLibEntry* mNextWithSameName; -public: +public: BeLibEntry() { mReferenced = false; @@ -84,7 +84,7 @@ public: String mFilePath; String mOldFilePath; FileStream mOldFileStream; - FileStream mFileStream; + FileStream mFileStream; Dictionary mOldEntries; Dictionary mEntries; bool mFailed; @@ -107,7 +107,7 @@ public: Dictionary mLibFiles; Array mErrors; -public: +public: BeLibManager(); ~BeLibManager(); @@ -118,8 +118,7 @@ public: void Finish(); static String GetLibFilePath(const StringImpl& objFilePath); - static BeLibManager* Get(); + static BeLibManager* Get(); }; - NS_BF_END diff --git a/IDEHelper/Backend/BeMCContext.cpp b/IDEHelper/Backend/BeMCContext.cpp index 8f156c02..ac7755d3 100644 --- a/IDEHelper/Backend/BeMCContext.cpp +++ b/IDEHelper/Backend/BeMCContext.cpp @@ -251,7 +251,6 @@ BeVTrackingList* BeVTrackingContext::AddFiltered(BeVTrackingList* list, SizedArr else newList->mNumChanges = 0; - return newList; } @@ -301,7 +300,6 @@ BeVTrackingList* BeVTrackingContext::AddFiltered(BeVTrackingList* list, int idx, else newList->mNumChanges = 0; - return newList; } @@ -460,7 +458,6 @@ BeVTrackingList* BeVTrackingContext::SetChanges(BeVTrackingList* prevDestEntry, return newList; } - BeVTrackingList* BeVTrackingContext::ClearFiltered(BeVTrackingList* list, const SizedArrayImpl& indices) { /*int newSize = list->mSize - indices.size(); @@ -894,7 +891,7 @@ void BeMCColorizer::Prepare() //node->mWantsReg = false; //vregInfo->mReg = X64Reg_None; - //continue; + //continue; } if ((vregInfo->mRefCount > 0) || (vregInfo->mIsRetVal)) @@ -1046,7 +1043,7 @@ void BeMCColorizer::GenerateRegCosts() auto restoreInst = mcBlock->mInstructions[restoreIdx]; // Any vregs alive during this call will incur a cost of saving/restoring if we allocate onto a volatile register. - // If the vreg is either input-only or output-only (short lived temporary) then we can map it directly to a volatile register + // If the vreg is either input-only or output-only (short lived temporary) then we can map it directly to a volatile register for (int vregIdx : *inst->mLiveness) { if (vregIdx >= mContext->mLivenessContext.mNumItems) @@ -1271,8 +1268,8 @@ void BeMCColorizer::AssignRegs(RegKind regKind) { highestReg = X64Reg_M128_XMM14; // Leave X64Reg_M128_XMM15 as a scratch reg validRegs = { - X64Reg_M128_XMM0, X64Reg_M128_XMM1, X64Reg_M128_XMM2, X64Reg_M128_XMM3, - X64Reg_M128_XMM4, X64Reg_M128_XMM5, X64Reg_M128_XMM6, X64Reg_M128_XMM7, + X64Reg_M128_XMM0, X64Reg_M128_XMM1, X64Reg_M128_XMM2, X64Reg_M128_XMM3, + X64Reg_M128_XMM4, X64Reg_M128_XMM5, X64Reg_M128_XMM6, X64Reg_M128_XMM7, X64Reg_M128_XMM8, X64Reg_M128_XMM9, X64Reg_M128_XMM10, X64Reg_M128_XMM11, X64Reg_M128_XMM12, X64Reg_M128_XMM13, X64Reg_M128_XMM14 /*, X64Reg_M128_XMM15*/}; } @@ -1415,7 +1412,7 @@ void BeMCColorizer::AssignRegs(RegKind regKind) { BP_ZONE("Spill"); - // We need to spill! + // We need to spill! int bestSpillVReg = -1; for (int regPassIdx = 0; regPassIdx < 2; regPassIdx++) { @@ -1432,7 +1429,7 @@ void BeMCColorizer::AssignRegs(RegKind regKind) if (bestSpillVReg != -1) break; - // Order by mem cost + // Order by mem cost orderedSpillList.reserve(vregGraph.size()); for (int graphIdx = 0; graphIdx < (int)vregGraph.size(); graphIdx++) { @@ -1504,7 +1501,6 @@ void BeMCColorizer::AssignRegs(RegKind regKind) dbgStr += StrFormat("VReg %d ", vregIdx); }*/ - BeMCVRegInfo* vregInfo = mContext->mVRegInfo[vregIdx]; Node* node = &mNodes[vregIdx]; @@ -1544,12 +1540,12 @@ void BeMCColorizer::AssignRegs(RegKind regKind) } } auto bestReg = X64Reg_None; - int bestRegCost = 0x07FFFFFF; // 0x0FFFFFFF is considered illegal for a reg, so set the mem cost to lower than that...; + int bestRegCost = 0x07FFFFFF; // 0x0FFFFFFF is considered illegal for a reg, so set the mem cost to lower than that...; // This is the cost of just leaving the vreg as a memory access. In cases where we bind to a volatile // register, we need to consider the cost of preserving and restoring that register across calls, so // it cases where we have just a few accesses to this vreg but it spans a lot of calls then we just - // leave it as memory + // leave it as memory if (!vregInfo->mForceReg) bestRegCost = node->mMemCost; @@ -1944,7 +1940,7 @@ void BeMCContext::Fail(const StringImpl& str) BeDumpContext dumpCtx; errStr += "\n DbgLoc : "; dumpCtx.ToString(errStr, mActiveInst->mDbgLoc); - } + } BfpSystem_FatalError(errStr.c_str(), "FATAL ERROR"); } @@ -2289,13 +2285,13 @@ BeMCOperand BeMCContext::GetOperand(BeValue* value, bool allowMetaResult, bool a auto result = mcVal; - // We assume we never do both an idx0 and idx1 at once. Fix if we change that. + // We assume we never do both an idx0 and idx1 at once. Fix if we change that. int byteOffset = 0; BeType* elementType = ptrType->mElementType; byteOffset += gepConstant->mIdx0 * ptrType->mElementType->GetStride(); - + result = AllocRelativeVirtualReg(ptrType, result, GetImmediate(byteOffset), 1); - // The def is primary to create a single 'master location' for the GEP vreg to become legalized before use + // The def is primary to create a single 'master location' for the GEP vreg to become legalized before use auto vregInfo = GetVRegInfo(result); vregInfo->mDefOnFirstUse = true; result.mKind = BeMCOperandKind_VReg; @@ -2314,7 +2310,7 @@ BeMCOperand BeMCContext::GetOperand(BeValue* value, bool allowMetaResult, bool a auto result = mcVal; - // We assume we never do both an idx0 and idx1 at once. Fix if we change that. + // We assume we never do both an idx0 and idx1 at once. Fix if we change that. int byteOffset = 0; BeType* elementType = NULL; byteOffset += gepConstant->mIdx0 * ptrType->mElementType->GetStride(); @@ -2343,7 +2339,7 @@ BeMCOperand BeMCContext::GetOperand(BeValue* value, bool allowMetaResult, bool a auto elementPtrType = mModule->mContext->GetPointerTo(elementType); result = AllocRelativeVirtualReg(elementPtrType, result, GetImmediate(byteOffset), 1); - // The def is primary to create a single 'master location' for the GEP vreg to become legalized before use + // The def is primary to create a single 'master location' for the GEP vreg to become legalized before use auto vregInfo = GetVRegInfo(result); vregInfo->mDefOnFirstUse = true; result.mKind = BeMCOperandKind_VReg; @@ -2388,7 +2384,6 @@ BeMCOperand BeMCContext::GetOperand(BeValue* value, bool allowMetaResult, bool a break; case BeDbgVariable::TypeId: { - } } @@ -2586,7 +2581,7 @@ BeMCOperand BeMCContext::TryToVector(BeValue* value) auto operand = GetOperand(value); auto type = GetType(operand); if (!type->IsPointer()) - return operand; + return operand; return CreateLoad(operand); } @@ -2626,7 +2621,7 @@ BeType* BeMCContext::GetType(const BeMCOperand& operand) case BeMCOperandKind_Immediate_i8: return mModule->mContext->GetPrimitiveType(BeTypeCode_Int8); break; case BeMCOperandKind_Immediate_i16: return mModule->mContext->GetPrimitiveType(BeTypeCode_Int16); break; case BeMCOperandKind_Immediate_i32: return mModule->mContext->GetPrimitiveType(BeTypeCode_Int32); break; - case BeMCOperandKind_Immediate_i64: + case BeMCOperandKind_Immediate_i64: case BeMCOperandKind_Immediate_HomeSize: return mModule->mContext->GetPrimitiveType(BeTypeCode_Int64); break; case BeMCOperandKind_Immediate_Null: return operand.mType; break; case BeMCOperandKind_Immediate_f32: @@ -2746,7 +2741,7 @@ BeMCInst* BeMCContext::AllocInst(BeMCInstKind instKind, const BeMCOperand& arg0, } BeMCInst* BeMCContext::AllocInst(BeMCInstKind instKind, const BeMCOperand& arg0, const BeMCOperand& arg1, int insertIdx) -{ +{ auto mcInst = AllocInst(insertIdx); mcInst->mKind = instKind; mcInst->mArg0 = arg0; @@ -2766,7 +2761,7 @@ void BeMCContext::MergeInstFlags(BeMCInst* prevInst, BeMCInst* inst, BeMCInst* n void BeMCContext::RemoveInst(BeMCBlock* block, int instIdx, bool needChangesMerged, bool removeFromList) { // If neither the instruction before or after this one shares the vregsInitialized flags, then we need to - // merge down our Changes to the next instruction + // merge down our Changes to the next instruction auto inst = block->mInstructions[instIdx]; if (instIdx > 0) { @@ -2791,7 +2786,6 @@ void BeMCContext::RemoveInst(BeMCBlock* block, int instIdx, bool needChangesMerg block->mInstructions.RemoveAt(instIdx); } - BeMCOperand BeMCContext::GetCallArgVReg(int argIdx, BeTypeCode typeCode) { int pIdx = argIdx; @@ -2858,7 +2852,7 @@ BeMCOperand BeMCContext::GetCallArgVReg(int argIdx, BeTypeCode typeCode) } BeMCOperand BeMCContext::CreateCall(const BeMCOperand &func, const SizedArrayImpl& args, BeType* retType, BfIRCallingConv callingConv, bool structRet, bool noReturn, bool isVarArg) -{ +{ SizedArray opArgs; for (auto itr = args.begin(); itr != args.end(); ++itr) { @@ -2900,7 +2894,7 @@ static bool NeedsDecompose(BeConstant* constant) for (auto& val : arrayConst->mMemberValues) { if (NeedsDecompose(val)) - return true; + return true; } return false; } @@ -2912,14 +2906,14 @@ static bool NeedsDecompose(BeConstant* constant) else if (auto castConst = BeValueDynCast(constant)) { return true; - } + } else if (auto castConst = BeValueDynCast(constant)) { if (auto targetConstant = BeValueDynCast(castConst->mValue)) return NeedsDecompose(targetConstant); } else if (auto castConst = BeValueDynCast(constant)) - { + { return NeedsDecompose(castConst->mTarget); } else if (auto castConst = BeValueDynCast(constant)) @@ -2931,10 +2925,10 @@ static bool NeedsDecompose(BeConstant* constant) } void BeMCContext::CreateStore(BeMCInstKind instKind, const BeMCOperand& val, const BeMCOperand& ptr) -{ +{ BeMCOperand mcVal = val; BeMCOperand mcPtr = ptr; - + if (mcVal.mKind == BeMCOperandKind_ConstAgg) { if (auto aggConst = BeValueDynCast(mcVal.mConstant)) @@ -2944,9 +2938,9 @@ void BeMCContext::CreateStore(BeMCInstKind instKind, const BeMCOperand& val, con int offset = 0; auto aggType = aggConst->GetType(); - + for (int memberIdx = 0; memberIdx < (int)aggConst->mMemberValues.size(); memberIdx++) - { + { auto val = aggConst->mMemberValues[memberIdx]; BeType* elemType = NULL; if (aggType->IsSizedArray()) @@ -2959,7 +2953,7 @@ void BeMCContext::CreateStore(BeMCInstKind instKind, const BeMCOperand& val, con } if (elemType->mSize == 0) continue; - + auto destOperand = AllocVirtualReg(mModule->mContext->GetPointerTo(elemType)); auto vregInfo = GetVRegInfo(destOperand); vregInfo->mDefOnFirstUse = true; @@ -3055,7 +3049,7 @@ BeMCOperand BeMCContext::CreateCall(const BeMCOperand& func, const SizedArrayImp }; SizedArray<_ShadowReg, 8> shadowRegs; - + mMaxCallParamCount = BF_MAX(mMaxCallParamCount, argCount); for (int argIdx = args.size() - 1; argIdx >= 0; argIdx--) { @@ -3597,7 +3591,7 @@ void BeMCContext::CreateCondBr(BeMCBlock* mcBlock, BeMCOperand& testVal, const B brInstIdx = checkIdx; checkInst->mArg0 = landinglabel; found = true; - // Don't break, if we're are chained to another PHI then we need to modify all the labels + // Don't break, if we're are chained to another PHI then we need to modify all the labels isFalseCmpResult = false; if ((checkIdx >= 2) && (checkInst->mKind == BeMCInstKind_Br)) @@ -3610,7 +3604,6 @@ void BeMCContext::CreateCondBr(BeMCBlock* mcBlock, BeMCOperand& testVal, const B isFalseCmpResult = true; } } - } } }; @@ -3703,7 +3696,7 @@ void BeMCContext::CreatePhiAssign(BeMCBlock* mcBlock, const BeMCOperand& testVal { SetAndRestoreValue prevActiveBlock(mActiveBlock, block); for (int checkIdx = (int)block->mInstructions.size() - 1; checkIdx >= 0; checkIdx--) - { + { auto checkInst = block->mInstructions[checkIdx]; if ((checkInst->mArg0.mKind == BeMCOperandKind_Block) && (checkInst->mArg0.mBlock == phi->mBlock)) @@ -3717,18 +3710,18 @@ void BeMCContext::CreatePhiAssign(BeMCBlock* mcBlock, const BeMCOperand& testVal auto prevDest = checkInst->mArg0; checkInst->mArg0 = falseLabel; - checkInst->mArg1.mCmpKind = BeModule::InvertCmp(checkInst->mArg1.mCmpKind); + checkInst->mArg1.mCmpKind = BeModule::InvertCmp(checkInst->mArg1.mCmpKind); int insertIdx = checkIdx + 1; SetAndRestoreValue prevInsertIdxRef(mInsertInstIdxRef, &insertIdx); CreateStore(BeMCInstKind_Mov, phiVal.mValue, OperandToAddr(result)); AllocInst(BeMCInstKind_Br, prevDest); - AllocInst(BeMCInstKind_Label, falseLabel); + AllocInst(BeMCInstKind_Label, falseLabel); } else - { + { int insertIdx = checkIdx; - SetAndRestoreValue prevInsertIdxRef(mInsertInstIdxRef, &insertIdx); + SetAndRestoreValue prevInsertIdxRef(mInsertInstIdxRef, &insertIdx); CreateStore(BeMCInstKind_Mov, phiVal.mValue, OperandToAddr(result)); } @@ -3901,7 +3894,7 @@ bool BeMCContext::ContainsNonOffsetRef(const BeMCOperand& checkOperand, const Be // For all values that we are certain we will immediately use, we directly do a Def preceding its first use. // For Allocas in the head, however, we may not use that memory for a long time so we imply the Def location -// in DoDefPass. That allows us to limit how long that vreg will hold onto a register, reducing register +// in DoDefPass. That allows us to limit how long that vreg will hold onto a register, reducing register // contention. BeMCInst* BeMCContext::CreateDefineVReg(const BeMCOperand& vreg, int insertIdx) { @@ -4214,26 +4207,26 @@ bool BeMCContext::CouldBeReg(const BeMCOperand& operand) // { // if (operand.mKind != BeMCOperandKind_VReg) // return false; -// +// // auto vregInfo = GetVRegInfo(operand); // if ((vregInfo->mIsRetVal) && (mCompositeRetVRegIdx != -1) && (mCompositeRetVRegIdx != operand.mVRegIdx)) // { // return CouldBeReg(BeMCOperand::FromVReg(mCompositeRetVRegIdx)); // } -// +// // if (vregInfo->mReg != X64Reg_None) // return true; -// +// // if (vregInfo->mForceMem) // return false; -// +// // if (vregInfo->mIsExpr) // { // if (vregInfo->mRelOffset) -// return false; +// return false; // return CouldBeReg(vregInfo->mRelTo); // } -// +// // return !vregInfo->mType->IsNonVectorComposite(); // } @@ -4261,7 +4254,7 @@ void BeMCContext::MarkLive(BeVTrackingList* liveRegs, SizedArrayImpl& newRe if (!mColorizer.mNodes.empty()) { - // Is new + // Is new for (int i = 0; i < liveRegs->mSize; i++) { int checkReg = liveRegs->mEntries[i]; @@ -4411,7 +4404,7 @@ void BeMCContext::GenerateLiveness(BeMCBlock* block, BeVTrackingGenContext* genC //if (mDebugging) debugging = true; //if (mBeFunction->mName == "?Draw@DarkEditWidgetContent@dark@theme@Beefy@@UEAAXPEAVGraphics@gfx@4@@Z") //debugging = true; - //"?DrawEntry@DrawContext@PerfView@BeefPerf@@QEAAXPEAVGraphics@gfx@Beefy@@PEAVTrackNodeEntry@23@MM@Z") + //"?DrawEntry@DrawContext@PerfView@BeefPerf@@QEAAXPEAVGraphics@gfx@Beefy@@PEAVTrackNodeEntry@23@MM@Z") //debugging &= mcColorizer != NULL; if (debugging) @@ -4554,7 +4547,7 @@ void BeMCContext::GenerateLiveness(BeMCBlock* block, BeVTrackingGenContext* genC // It's possible this vregsInitialized is equivalent to the one in 'inst', but also merged with another 'inst' // during legalization. We need to avoid uninitializing vregs if that's the case. - // the entry above this + // the entry above this if (inst->mVRegsInitialized->ContainsChange(vregIdxEx)) continue; @@ -4572,7 +4565,7 @@ void BeMCContext::GenerateLiveness(BeMCBlock* block, BeVTrackingGenContext* genC if (!mVRegInitializedContext.IsSet(inst->mVRegsInitialized, inst->mArg0.mVRegIdx)) { // There are some rare cases with conditional branches where one branch will have a vreg marked as - // initialized, which causes the variable to be marked as live, which propagates upward into the block + // initialized, which causes the variable to be marked as live, which propagates upward into the block // containing a variable declaration, before the actual def point DedupPushBack(removeVec, inst->mArg0.mVRegIdx); } @@ -4581,8 +4574,8 @@ void BeMCContext::GenerateLiveness(BeMCBlock* block, BeVTrackingGenContext* genC } // This is used for clearing out things like usage of inline return values, which will be accessed after their - // lifetime end (the lifetime ends inside the inlined method but the value is used afterward, in the inlining - // function. This will emit as a load of a dbgVar, so we need to drill down into the relTo values + // lifetime end (the lifetime ends inside the inlined method but the value is used afterward, in the inlining + // function. This will emit as a load of a dbgVar, so we need to drill down into the relTo values if (inst->mKind == BeMCInstKind_LifetimeStart) { BEMC_ASSERT(inst->mArg0.IsVRegAny()); @@ -4902,52 +4895,52 @@ X64CPURegister BeMCContext::ResizeRegister(X64CPURegister reg, int numBytes) switch (reg) { case X64Reg_XMM0_f32: - case X64Reg_XMM0_f64: + case X64Reg_XMM0_f64: case X64Reg_M128_XMM0: return X64Reg_M128_XMM0; case X64Reg_XMM1_f32: - case X64Reg_XMM1_f64: + case X64Reg_XMM1_f64: case X64Reg_M128_XMM1: return X64Reg_M128_XMM1; case X64Reg_XMM2_f32: - case X64Reg_XMM2_f64: + case X64Reg_XMM2_f64: case X64Reg_M128_XMM2: return X64Reg_M128_XMM2; case X64Reg_XMM3_f32: - case X64Reg_XMM3_f64: + case X64Reg_XMM3_f64: case X64Reg_M128_XMM3: return X64Reg_M128_XMM3; case X64Reg_XMM4_f32: - case X64Reg_XMM4_f64: + case X64Reg_XMM4_f64: case X64Reg_M128_XMM4: return X64Reg_M128_XMM4; case X64Reg_XMM5_f32: - case X64Reg_XMM5_f64: + case X64Reg_XMM5_f64: case X64Reg_M128_XMM5: return X64Reg_M128_XMM5; case X64Reg_XMM6_f32: - case X64Reg_XMM6_f64: + case X64Reg_XMM6_f64: case X64Reg_M128_XMM6: return X64Reg_M128_XMM6; case X64Reg_XMM7_f32: - case X64Reg_XMM7_f64: + case X64Reg_XMM7_f64: case X64Reg_M128_XMM7: return X64Reg_M128_XMM7; case X64Reg_XMM8_f32: - case X64Reg_XMM8_f64: + case X64Reg_XMM8_f64: case X64Reg_M128_XMM8: return X64Reg_M128_XMM8; case X64Reg_XMM9_f32: - case X64Reg_XMM9_f64: + case X64Reg_XMM9_f64: case X64Reg_M128_XMM9: return X64Reg_M128_XMM9; case X64Reg_XMM10_f32: - case X64Reg_XMM10_f64: + case X64Reg_XMM10_f64: case X64Reg_M128_XMM10: return X64Reg_M128_XMM10; case X64Reg_XMM11_f32: - case X64Reg_XMM11_f64: + case X64Reg_XMM11_f64: case X64Reg_M128_XMM11: return X64Reg_M128_XMM11; case X64Reg_XMM12_f32: - case X64Reg_XMM12_f64: + case X64Reg_XMM12_f64: case X64Reg_M128_XMM12: return X64Reg_M128_XMM12; case X64Reg_XMM13_f32: - case X64Reg_XMM13_f64: + case X64Reg_XMM13_f64: case X64Reg_M128_XMM13: return X64Reg_M128_XMM13; case X64Reg_XMM14_f32: - case X64Reg_XMM14_f64: + case X64Reg_XMM14_f64: case X64Reg_M128_XMM14: return X64Reg_M128_XMM14; case X64Reg_XMM15_f32: - case X64Reg_XMM15_f64: + case X64Reg_XMM15_f64: case X64Reg_M128_XMM15: return X64Reg_M128_XMM15; } } @@ -5018,52 +5011,52 @@ X64CPURegister BeMCContext::ResizeRegister(X64CPURegister reg, int numBytes) case X64Reg_R15: return X64Reg_R15; case X64Reg_XMM0_f32: - case X64Reg_XMM0_f64: + case X64Reg_XMM0_f64: case X64Reg_M128_XMM0: return X64Reg_XMM0_f64; case X64Reg_XMM1_f32: - case X64Reg_XMM1_f64: + case X64Reg_XMM1_f64: case X64Reg_M128_XMM1: return X64Reg_XMM1_f64; case X64Reg_XMM2_f32: - case X64Reg_XMM2_f64: + case X64Reg_XMM2_f64: case X64Reg_M128_XMM2: return X64Reg_XMM2_f64; case X64Reg_XMM3_f32: - case X64Reg_XMM3_f64: + case X64Reg_XMM3_f64: case X64Reg_M128_XMM3: return X64Reg_XMM3_f64; case X64Reg_XMM4_f32: - case X64Reg_XMM4_f64: + case X64Reg_XMM4_f64: case X64Reg_M128_XMM4: return X64Reg_XMM4_f64; case X64Reg_XMM5_f32: - case X64Reg_XMM5_f64: + case X64Reg_XMM5_f64: case X64Reg_M128_XMM5: return X64Reg_XMM5_f64; case X64Reg_XMM6_f32: - case X64Reg_XMM6_f64: + case X64Reg_XMM6_f64: case X64Reg_M128_XMM6: return X64Reg_XMM6_f64; case X64Reg_XMM7_f32: - case X64Reg_XMM7_f64: + case X64Reg_XMM7_f64: case X64Reg_M128_XMM7: return X64Reg_XMM7_f64; case X64Reg_XMM8_f32: - case X64Reg_XMM8_f64: + case X64Reg_XMM8_f64: case X64Reg_M128_XMM8: return X64Reg_XMM8_f64; case X64Reg_XMM9_f32: - case X64Reg_XMM9_f64: + case X64Reg_XMM9_f64: case X64Reg_M128_XMM9: return X64Reg_XMM9_f64; case X64Reg_XMM10_f32: - case X64Reg_XMM10_f64: + case X64Reg_XMM10_f64: case X64Reg_M128_XMM10: return X64Reg_XMM10_f64; case X64Reg_XMM11_f32: - case X64Reg_XMM11_f64: + case X64Reg_XMM11_f64: case X64Reg_M128_XMM11: return X64Reg_XMM11_f64; case X64Reg_XMM12_f32: - case X64Reg_XMM12_f64: + case X64Reg_XMM12_f64: case X64Reg_M128_XMM12: return X64Reg_XMM12_f64; case X64Reg_XMM13_f32: - case X64Reg_XMM13_f64: + case X64Reg_XMM13_f64: case X64Reg_M128_XMM13: return X64Reg_XMM13_f64; case X64Reg_XMM14_f32: - case X64Reg_XMM14_f64: + case X64Reg_XMM14_f64: case X64Reg_M128_XMM14: return X64Reg_XMM14_f64; case X64Reg_XMM15_f32: - case X64Reg_XMM15_f64: + case X64Reg_XMM15_f64: case X64Reg_M128_XMM15: return X64Reg_XMM15_f64; } return reg; @@ -5134,52 +5127,52 @@ X64CPURegister BeMCContext::ResizeRegister(X64CPURegister reg, int numBytes) case X64Reg_R15: return X64Reg_R15D; case X64Reg_XMM0_f32: - case X64Reg_XMM0_f64: + case X64Reg_XMM0_f64: case X64Reg_M128_XMM0: return X64Reg_XMM0_f32; case X64Reg_XMM1_f32: - case X64Reg_XMM1_f64: + case X64Reg_XMM1_f64: case X64Reg_M128_XMM1: return X64Reg_XMM1_f32; case X64Reg_XMM2_f32: - case X64Reg_XMM2_f64: + case X64Reg_XMM2_f64: case X64Reg_M128_XMM2: return X64Reg_XMM2_f32; case X64Reg_XMM3_f32: - case X64Reg_XMM3_f64: + case X64Reg_XMM3_f64: case X64Reg_M128_XMM3: return X64Reg_XMM3_f32; case X64Reg_XMM4_f32: - case X64Reg_XMM4_f64: + case X64Reg_XMM4_f64: case X64Reg_M128_XMM4: return X64Reg_XMM4_f32; case X64Reg_XMM5_f32: - case X64Reg_XMM5_f64: + case X64Reg_XMM5_f64: case X64Reg_M128_XMM5: return X64Reg_XMM5_f32; case X64Reg_XMM6_f32: - case X64Reg_XMM6_f64: + case X64Reg_XMM6_f64: case X64Reg_M128_XMM6: return X64Reg_XMM6_f32; case X64Reg_XMM7_f32: - case X64Reg_XMM7_f64: + case X64Reg_XMM7_f64: case X64Reg_M128_XMM7: return X64Reg_XMM7_f32; case X64Reg_XMM8_f32: - case X64Reg_XMM8_f64: + case X64Reg_XMM8_f64: case X64Reg_M128_XMM8: return X64Reg_XMM8_f32; case X64Reg_XMM9_f32: - case X64Reg_XMM9_f64: + case X64Reg_XMM9_f64: case X64Reg_M128_XMM9: return X64Reg_XMM9_f32; case X64Reg_XMM10_f32: - case X64Reg_XMM10_f64: + case X64Reg_XMM10_f64: case X64Reg_M128_XMM10: return X64Reg_XMM10_f32; case X64Reg_XMM11_f32: - case X64Reg_XMM11_f64: + case X64Reg_XMM11_f64: case X64Reg_M128_XMM11: return X64Reg_XMM11_f32; case X64Reg_XMM12_f32: - case X64Reg_XMM12_f64: + case X64Reg_XMM12_f64: case X64Reg_M128_XMM12: return X64Reg_XMM12_f32; case X64Reg_XMM13_f32: - case X64Reg_XMM13_f64: + case X64Reg_XMM13_f64: case X64Reg_M128_XMM13: return X64Reg_XMM13_f32; case X64Reg_XMM14_f32: - case X64Reg_XMM14_f64: + case X64Reg_XMM14_f64: case X64Reg_M128_XMM14: return X64Reg_XMM14_f32; case X64Reg_XMM15_f32: - case X64Reg_XMM15_f64: + case X64Reg_XMM15_f64: case X64Reg_M128_XMM15: return X64Reg_XMM15_f32; } } @@ -5330,52 +5323,52 @@ X64CPURegister BeMCContext::GetFullRegister(X64CPURegister reg) switch (reg) { case X64Reg_XMM0_f32: - case X64Reg_XMM0_f64: + case X64Reg_XMM0_f64: case X64Reg_M128_XMM0: return X64Reg_M128_XMM0; case X64Reg_XMM1_f32: - case X64Reg_XMM1_f64: + case X64Reg_XMM1_f64: case X64Reg_M128_XMM1: return X64Reg_M128_XMM1; case X64Reg_XMM2_f32: - case X64Reg_XMM2_f64: + case X64Reg_XMM2_f64: case X64Reg_M128_XMM2: return X64Reg_M128_XMM2; case X64Reg_XMM3_f32: - case X64Reg_XMM3_f64: + case X64Reg_XMM3_f64: case X64Reg_M128_XMM3: return X64Reg_M128_XMM3; case X64Reg_XMM4_f32: - case X64Reg_XMM4_f64: + case X64Reg_XMM4_f64: case X64Reg_M128_XMM4: return X64Reg_M128_XMM4; case X64Reg_XMM5_f32: - case X64Reg_XMM5_f64: + case X64Reg_XMM5_f64: case X64Reg_M128_XMM5: return X64Reg_M128_XMM5; case X64Reg_XMM6_f32: - case X64Reg_XMM6_f64: + case X64Reg_XMM6_f64: case X64Reg_M128_XMM6: return X64Reg_M128_XMM6; case X64Reg_XMM7_f32: - case X64Reg_XMM7_f64: + case X64Reg_XMM7_f64: case X64Reg_M128_XMM7: return X64Reg_M128_XMM7; case X64Reg_XMM8_f32: - case X64Reg_XMM8_f64: + case X64Reg_XMM8_f64: case X64Reg_M128_XMM8: return X64Reg_M128_XMM8; case X64Reg_XMM9_f32: - case X64Reg_XMM9_f64: + case X64Reg_XMM9_f64: case X64Reg_M128_XMM9: return X64Reg_M128_XMM9; case X64Reg_XMM10_f32: - case X64Reg_XMM10_f64: + case X64Reg_XMM10_f64: case X64Reg_M128_XMM10: return X64Reg_M128_XMM10; case X64Reg_XMM11_f32: - case X64Reg_XMM11_f64: + case X64Reg_XMM11_f64: case X64Reg_M128_XMM11: return X64Reg_M128_XMM11; case X64Reg_XMM12_f32: - case X64Reg_XMM12_f64: + case X64Reg_XMM12_f64: case X64Reg_M128_XMM12: return X64Reg_M128_XMM12; case X64Reg_XMM13_f32: - case X64Reg_XMM13_f64: + case X64Reg_XMM13_f64: case X64Reg_M128_XMM13: return X64Reg_M128_XMM13; case X64Reg_XMM14_f32: - case X64Reg_XMM14_f64: + case X64Reg_XMM14_f64: case X64Reg_M128_XMM14: return X64Reg_M128_XMM14; case X64Reg_XMM15_f32: - case X64Reg_XMM15_f64: + case X64Reg_XMM15_f64: case X64Reg_M128_XMM15: return X64Reg_M128_XMM15; } return ResizeRegister(reg, 8); @@ -5512,7 +5505,7 @@ uint8 BeMCContext::GetREX(const BeMCOperand& r, const BeMCOperand& rm, bool is64 case X64Reg_XMM12_f64: case X64Reg_XMM13_f64: case X64Reg_XMM14_f64: case X64Reg_XMM15_f64: case X64Reg_XMM8_f32: case X64Reg_XMM9_f32: case X64Reg_XMM10_f32: case X64Reg_XMM11_f32: case X64Reg_XMM12_f32: case X64Reg_XMM13_f32: case X64Reg_XMM14_f32: case X64Reg_XMM15_f32: - case X64Reg_M128_XMM8: case X64Reg_M128_XMM9: case X64Reg_M128_XMM10: case X64Reg_M128_XMM11: + case X64Reg_M128_XMM8: case X64Reg_M128_XMM9: case X64Reg_M128_XMM10: case X64Reg_M128_XMM11: case X64Reg_M128_XMM12: case X64Reg_M128_XMM13: case X64Reg_M128_XMM14: case X64Reg_M128_XMM15: is64BitExR = true; } @@ -5599,7 +5592,7 @@ uint8 BeMCContext::EncodeRegNum(X64CPURegister regNum) case X64Reg_XMM0_f64: case X64Reg_M128_XMM0: case X64Reg_XMM8_f32: - case X64Reg_XMM8_f64: + case X64Reg_XMM8_f64: case X64Reg_M128_XMM8: return 0; case X64Reg_CL: @@ -5626,7 +5619,7 @@ uint8 BeMCContext::EncodeRegNum(X64CPURegister regNum) case X64Reg_R10D: case X64Reg_R10W: case X64Reg_R10B: - case X64Reg_MM2: + case X64Reg_MM2: case X64Reg_XMM2_f32: case X64Reg_XMM2_f64: case X64Reg_M128_XMM2: @@ -5642,7 +5635,7 @@ uint8 BeMCContext::EncodeRegNum(X64CPURegister regNum) case X64Reg_R11D: case X64Reg_R11W: case X64Reg_R11B: - case X64Reg_MM3: + case X64Reg_MM3: case X64Reg_XMM3_f32: case X64Reg_XMM3_f64: case X64Reg_M128_XMM3: @@ -5659,7 +5652,7 @@ uint8 BeMCContext::EncodeRegNum(X64CPURegister regNum) case X64Reg_R12D: case X64Reg_R12W: case X64Reg_R12B: - case X64Reg_MM4: + case X64Reg_MM4: case X64Reg_XMM4_f32: case X64Reg_XMM4_f64: case X64Reg_M128_XMM4: @@ -5675,7 +5668,7 @@ uint8 BeMCContext::EncodeRegNum(X64CPURegister regNum) case X64Reg_R13D: case X64Reg_R13W: case X64Reg_R13B: - case X64Reg_MM5: + case X64Reg_MM5: case X64Reg_XMM5_f32: case X64Reg_XMM5_f64: case X64Reg_M128_XMM5: @@ -5692,7 +5685,7 @@ uint8 BeMCContext::EncodeRegNum(X64CPURegister regNum) case X64Reg_R14D: case X64Reg_R14W: case X64Reg_R14B: - case X64Reg_MM6: + case X64Reg_MM6: case X64Reg_XMM6_f32: case X64Reg_XMM6_f64: case X64Reg_M128_XMM6: @@ -5709,7 +5702,7 @@ uint8 BeMCContext::EncodeRegNum(X64CPURegister regNum) case X64Reg_R15D: case X64Reg_R15W: case X64Reg_R15B: - case X64Reg_MM7: + case X64Reg_MM7: case X64Reg_XMM7_f32: case X64Reg_XMM7_f64: case X64Reg_M128_XMM7: @@ -5742,12 +5735,12 @@ void BeMCContext::ValidateRMResult(const BeMCOperand& operand, BeRMParamsInfo& r //TODO: WTF- this previous version just seems to be wrong! Why did think this was true? the REX.X and REX.B flags fix these // in a SIB, the base can't be R13 (which is RBP+REX), and the scaled index can't be R12 (which is RSP+REX) - //if ((regB != X64Reg_None) && + //if ((regB != X64Reg_None) && // ((regA == X64Reg_R13) || (regB == X64Reg_R12))) - //{ + //{ // // We can't just swap the regs if we have a scale applied // if (bScale != 1) - // { + // { // if (errorVReg != NULL) // *errorVReg = -2; // Scale error // return BeMCRMMode_Invalid; @@ -5913,12 +5906,11 @@ void BeMCContext::GetRMParams(const BeMCOperand& operand, BeRMParamsInfo& rmInfo // A deref can only stand alone, and no double-derefs if ((vregInfo->mRelOffset) || (vregInfo->mRelOffsetScale != 1) || (operand.mKind == BeMCOperandKind_VRegLoad)) { - BF_ASSERT(vregInfo->mRelTo.IsVRegAny()); rmInfo.mErrorVReg = vregInfo->mRelTo.mVRegIdx; // For some reason we had changed this to: //*errorVReg = operand.mVRegIdx; - // This doesn't work, it's the deref that we want to isolate, otherwise we just end up creating another invalid expression + // This doesn't work, it's the deref that we want to isolate, otherwise we just end up creating another invalid expression rmInfo.mMode = BeMCRMMode_Invalid; return; } @@ -6116,7 +6108,6 @@ void BeMCContext::GetValAddr(const BeMCOperand& operand, X64CPURegister& reg, in offset = mStackSize + vregInfo->mFrameOffset; } - int BeMCContext::GetHighestVRegRef(const BeMCOperand& operand) { if (!operand.IsVRegAny()) @@ -6354,7 +6345,7 @@ void BeMCContext::EmitModRM(int rx, BeMCOperand rm, int relocOfs) BeRMParamsInfo rmInfo; GetRMParams(rm, rmInfo); - //BF_ASSERT(resultType != BeMCRMMode_Invalid); + //BF_ASSERT(resultType != BeMCRMMode_Invalid); BF_ASSERT(rmInfo.mMode == BeMCRMMode_Deref); EmitModRMRel(rx, rmInfo.mRegA, rmInfo.mRegB, rmInfo.mBScale, rmInfo.mDisp); return; @@ -6668,7 +6659,6 @@ void BeMCContext::InitializedPassHelper(BeMCBlock* mcBlock, BeVTrackingGenContex } } - if ((inst->mResult) && (inst->mResult.mKind == BeMCOperandKind_CmpResult)) { auto& cmpResult = mCmpResults[inst->mResult.mCmpResultIdx]; @@ -6715,7 +6705,6 @@ void BeMCContext::InitializedPassHelper(BeMCBlock* mcBlock, BeVTrackingGenContex } } - if (inst->mKind == BeMCInstKind_LifetimeEnd) { // In some cases we can have a dbg variable that actually points to a global variable (due to macros/inlining/etc), so this check is for that case: @@ -6965,7 +6954,6 @@ void BeMCContext::ReplaceVRegsInit(BeMCBlock* mcBlock, int startInstIdx, BeVTrac // This pass does bottom-up initialization for "simple" vregs (ie: not variables) void BeMCContext::SimpleInitializedPass() { - } void BeMCContext::GenerateVRegInitFlags(BeVTrackingGenContext& genCtx) @@ -7082,7 +7070,7 @@ bool BeMCContext::DoInitializedPass() // Unused block - clear almost all instructions int newIdx = 0; // for (int instIdx = 0; instIdx < (int)mcBlock->mInstructions.size(); instIdx++) - // { + // { // auto inst = mcBlock->mInstructions[instIdx]; // if (inst->mKind == BeMCInstKind_ValueScopeHardEnd) // { @@ -7357,7 +7345,6 @@ void BeMCContext::DoSplitLargeBlocks() } } } - } void BeMCContext::DetectLoops() @@ -7583,7 +7570,7 @@ void BeMCContext::DoInstCombinePass() SetCurrentInst(inst); //TODO: Remove - // if we've remapped other vregs onto this that aren't dead, then we can't end the value lifetime but we + // if we've remapped other vregs onto this that aren't dead, then we can't end the value lifetime but we // must end the lifetime of the visible debug variable /*if (inst->mKind == BeMCInstKind_LifetimeEnd) { @@ -7732,7 +7719,7 @@ void BeMCContext::DoInstCombinePass() if ((vregInfo->IsDirectRelTo()) && (vregInfo->mDbgVariable == NULL) && (CheckVRegEqualityRange(mcBlock, instIdx, mcLoaded, mcAddr, regRemaps, true))) { // If the source value doesn't change in the lifetime of the loaded value then - // we can just map directly to the source - no copy needed. + // we can just map directly to the source - no copy needed. inst->mKind = BeMCInstKind_Def; AddRegRemap(inst->mArg0.mVRegIdx, vregInfoDest->mRelTo.mVRegIdx, regRemaps, true); continue; @@ -7923,8 +7910,8 @@ void BeMCContext::DoInstCombinePass() } else { - // If we're dealing with a non-Mov instruction, then the values of both of these vregs will - // be different after the instruction, so we can only map them if the incoming vreg will be dead + // If we're dealing with a non-Mov instruction, then the values of both of these vregs will + // be different after the instruction, so we can only map them if the incoming vreg will be dead // afterwards. If both are dbgVariables then we can't allow them to coeexist because the user // could edit one of the values in the debugger and we don't want the other one changing. if ((nextNextInst != NULL) && @@ -7941,8 +7928,8 @@ void BeMCContext::DoInstCombinePass() if (vregInfoDest->mIsRetVal) { - // We don't do a remap for this return value optimization, because we want both vregs - // to still show in the debugger - even though they will point to the same address + // We don't do a remap for this return value optimization, because we want both vregs + // to still show in the debugger - even though they will point to the same address // now (in the case of a struct return) vregInfoCheck->SetRetVal(); //BF_ASSERT(mCompositeRetVRegIdx != -1); @@ -8015,11 +8002,10 @@ void BeMCContext::DoInstCombinePass() } } - // For the form // %vreg0, %vreg1 // Test %vreg0, 1 - // Remove test, because the BinOp will already set the correct flags + // Remove test, because the BinOp will already set the correct flags if ((nextInst->mKind == BeMCInstKind_Test) && (nextInst->mArg1.IsImmediateInt()) && (nextInst->mArg1.mImmediate == 1) && (nextInst->mArg0 == inst->mArg0)) { @@ -8079,7 +8065,7 @@ void BeMCContext::DoInstCombinePass() // For the form: // %vreg2 = %vreg0, %vreg1 - // If %vreg0 ends its life on this instruction, + // If %vreg0 ends its life on this instruction, // Replace all instances of %vreg2 with %vreg0 if ((inst->mResult.mKind == BeMCOperandKind_VReg) && (inst->mArg0.mKind == BeMCOperandKind_VReg) && (inst->mResult != inst->mArg0)) @@ -8122,7 +8108,7 @@ void BeMCContext::DoInstCombinePass() if (!hadInvalidInst) { - // We return after this, we don't need to restore volatiles + // We return after this, we don't need to restore volatiles inst->mArg1 = BeMCOperand::FromPreserveFlag(BeMCPreserveFlag_NoRestore); continue; } @@ -8166,12 +8152,12 @@ void BeMCContext::DoInstCombinePass() } } - // For the form: + // For the form: // %vreg0 = CmpToBool // Test %vreg0, %vreg0 // CondBr %label, eq - // If %vreg0 has no other references, convert to: - // CondBr %label, + // If %vreg0 has no other references, convert to: + // CondBr %label, if ((inst->mKind == BeMCInstKind_CmpToBool) && (nextInst->mKind == BeMCInstKind_Test) && (nextInst->mArg0 == nextInst->mArg1) && (nextNextInst->mKind == BeMCInstKind_CondBr) && @@ -8221,7 +8207,6 @@ void BeMCContext::DoInstCombinePass() int* prevBestVRegIdxPtr = NULL; if (defMap.TryGetValue(remapTo, &prevBestVRegIdxPtr)) { - } else defMap[remapTo] = bestVRegIdx; @@ -8235,7 +8220,7 @@ void BeMCContext::DoInstCombinePass() Array<_RemapEntry> initRemaps; - // We have a many-to-one relation so we have to use both a + // We have a many-to-one relation so we have to use both a HashSet keepDefs; for (auto& defPair : defMap) keepDefs.Add(defPair.mValue); @@ -8392,7 +8377,7 @@ void BeMCContext::DoRegAssignPass() BP_ZONE("BeMCContext::DoRegAssignPass"); bool generateLiveness = true; - // + // if (generateLiveness) { for (auto& node : mColorizer.mNodes) @@ -8457,18 +8442,17 @@ void BeMCContext::DoRegAssignPass() #endif } - void BeMCContext::DoFrameObjPass() { - BF_ASSERT(mBlocks.size() == 1); + BF_ASSERT(mBlocks.size() == 1); SetCurrentInst(NULL); // MS x64 ABI requires a "home address" of 4 intptrs when we call a function, plus whatever - // we need for calls with more than 4 params. + // we need for calls with more than 4 params. // If we're doing UseBP, we have to allocate these at call time int homeSize = BF_ALIGN(BF_MAX(mMaxCallParamCount, 4) * 8, 16); - + mStackSize = 0; if (mUseBP) @@ -8524,7 +8508,7 @@ void BeMCContext::DoFrameObjPass() } } - // If we have dynamic stack resizing then we have a stack frame and must be 16-byte aligned + // If we have dynamic stack resizing then we have a stack frame and must be 16-byte aligned // even if we're a leaf function bool mHasFramePointer = false; @@ -8537,7 +8521,7 @@ void BeMCContext::DoFrameObjPass() //if (!mUseBP) { // MS x64 ABI requires a "home address" of 4 intptrs when we call a function, plus whatever - // we need for calls with more than 4 params. + // we need for calls with more than 4 params. // If we're doing UseBP, we have to allocate these at call time if (mMaxCallParamCount != -1) { @@ -8559,7 +8543,7 @@ void BeMCContext::DoFrameObjPass() } mActiveBlock = mBlocks[0]; - + if (mUseBP) { AllocInst(BeMCInstKind_Unwind_SetBP, 0); @@ -9048,7 +9032,7 @@ bool BeMCContext::DoLegalization() { // Only allow short-lived forceRegs instIdx += 2; - //origOperand.mVRegIdx = scratchReg.mVRegIdx; + //origOperand.mVRegIdx = scratchReg.mVRegIdx; origOperand = newOperand; } else @@ -9152,7 +9136,7 @@ bool BeMCContext::DoLegalization() bool isIncOrDec = false; isIncOrDec = (((inst->mKind == BeMCInstKind_Add) || (inst->mKind == BeMCInstKind_Sub)) && (arg1.IsImmediateInt()) && (arg1.mImmediate == 1)); - + if ((!isIncOrDec) && (!isIntMul) && (!isIntDiv)) { if ((arg0.MayBeMemory()) && (arg1.MayBeMemory())) @@ -9188,7 +9172,7 @@ bool BeMCContext::DoLegalization() if (badOps) { - // On X64 we can never have an instruction where both args are memory so we create a short-lived scratch vreg + // On X64 we can never have an instruction where both args are memory so we create a short-lived scratch vreg // and run another reg pass to generate register access // From: a, b @@ -9196,7 +9180,7 @@ bool BeMCContext::DoLegalization() // mov scratch, b // a, scratch auto targetType = GetType(inst->mArg0); - + if ((targetType->IsFloat()) && (!inst->mResult) && (arg0.IsVReg()) && (arg1.IsImmediateFloat())) { auto vregInfo0 = GetVRegInfo(arg0); @@ -9216,7 +9200,7 @@ bool BeMCContext::DoLegalization() continue; } } - + if (!targetType->IsNonVectorComposite()) { auto scratchType = GetType(inst->mArg1); @@ -9296,7 +9280,7 @@ bool BeMCContext::DoLegalization() { // From: b = Sub a, b // To: Neg b - // Add b, a + // Add b, a AllocInst(BeMCInstKind_Add, inst->mResult, inst->mArg0, instIdx + 1); inst->mKind = BeMCInstKind_Neg; inst->mArg0 = inst->mResult; @@ -9395,7 +9379,7 @@ bool BeMCContext::DoLegalization() if (!mLivenessContext.IsSet(nextInst->mLiveness, underlyingVRegIdx)) { // Convert a "Mul %vreg0, %vreg1" - // To + // To // Mul %reg1, %vreg0 // Mov %vreg0, %reg1 // This only works if %reg1 dies after this instruction and this is @@ -9426,14 +9410,13 @@ bool BeMCContext::DoLegalization() if (inst->mKind == BeMCInstKind_Call) { - // Convert from // Mov %reg0, // .. // Call %reg0 // To "Call " // This is a common case for virtual dispatch where complex address expressions get actualized - // but then we end up with an 'extra' vreg + // but then we end up with an 'extra' vreg if (inst->mArg0.IsVReg()) { auto vregInfo = GetVRegInfo(inst->mArg0); @@ -9624,7 +9607,7 @@ bool BeMCContext::DoLegalization() //if (vregExprChangeSet.find(errorVRegIdx) != vregExprChangeSet.end()) if (vregExprChangeSet.Contains(rmInfo.mErrorVReg)) { - // This means we have already modified some dependent vregs, so we may be legalized already. + // This means we have already modified some dependent vregs, so we may be legalized already. // Wait till next iteration to determine that. BF_ASSERT(!isFinalRun); isValid = true; // @@ -9674,8 +9657,8 @@ bool BeMCContext::DoLegalization() else { // We don't want to have too many concurrent ForceReg vregs at once, since that causes too much register pressure and - // can cause register allocation to fail at the extreme end. The scratchReg adds another ForceReg for the lifetime - // of the def vreg, so if the def vreg doesn't immediately die and there are already too many ForceRegs active then + // can cause register allocation to fail at the extreme end. The scratchReg adds another ForceReg for the lifetime + // of the def vreg, so if the def vreg doesn't immediately die and there are already too many ForceRegs active then // we need to actualize ourselves bool actualizeSelf = false; if (instIdx < mcBlock->mInstructions.size() - 2) @@ -9707,7 +9690,7 @@ bool BeMCContext::DoLegalization() } else { - // This may be a local variable that failed to be assigned to a reg, create a scratch local with a forced reg + // This may be a local variable that failed to be assigned to a reg, create a scratch local with a forced reg auto errorVReg = BeMCOperand::FromVReg(rmInfo.mErrorVReg); auto errorVRegLoad = BeMCOperand::ToLoad(errorVReg); @@ -9738,7 +9721,7 @@ bool BeMCContext::DoLegalization() } else if ((vregInfo->mRelTo == errorVRegLoad) || (vregInfo->mRelOffset == errorVRegLoad)) { - auto scratchType = GetType(errorVRegLoad); + auto scratchType = GetType(errorVRegLoad); auto scratchReg = AllocVirtualReg(scratchType, 2, false); auto scratchVRegInfo = mVRegInfo[scratchReg.mVRegIdx]; @@ -9850,8 +9833,6 @@ bool BeMCContext::DoLegalization() break; } - - if (!mVRegInitializedContext.IsSet(inst->mVRegsInitialized, vregIdx)) { if ((dbgVar->mPendingInitType != BfIRInitType_NotNeeded) && (dbgVar->mPendingInitType != BfIRInitType_NotNeeded_AliveOnDecl)) @@ -10117,7 +10098,7 @@ bool BeMCContext::DoLegalization() if (preserveRDX) DisableRegister(inst->mArg0, X64Reg_RDX); AllocInst(BeMCInstKind_Mov, inst->mArg0, mcRemaindier, instIdx++ + 1); - } + } } else { @@ -10186,8 +10167,8 @@ bool BeMCContext::DoLegalization() AllocInst(BeMCInstKind_PreserveVolatiles, BeMCOperand::FromReg(X64Reg_RAX), instIdx++); DisableRegister(inst->mArg0, X64Reg_RAX); - DisableRegister(inst->mArg1, X64Reg_RAX); - + DisableRegister(inst->mArg1, X64Reg_RAX); + AllocInst(BeMCInstKind_Mov, BeMCOperand::FromReg(X64Reg_AL), inst->mArg1, instIdx++); AllocInst(BeMCInstKind_Shl, BeMCOperand::FromReg(X64Reg_AX), BeMCOperand::FromImmediate(8), instIdx++); AllocInst(BeMCInstKind_Mov, BeMCOperand::FromReg(X64Reg_AL), inst->mArg0, instIdx++); @@ -10232,7 +10213,7 @@ bool BeMCContext::DoLegalization() AllocInst(BeMCInstKind_RestoreVolatiles, BeMCOperand::FromReg(X64Reg_RDX), instIdx++ + 1); AllocInst(BeMCInstKind_RestoreVolatiles, BeMCOperand::FromReg(X64Reg_RAX), instIdx++ + 1); - isFinalRun = false; + isFinalRun = false; break; } @@ -10246,26 +10227,26 @@ bool BeMCContext::DoLegalization() } if (inst->mArg0.IsNativeReg()) - { + { auto vregInfo1 = GetVRegInfo(inst->mArg1); if (vregInfo1 != NULL) { auto arg1 = GetFixedOperand(inst->mArg1); if ((arg1.IsNativeReg()) && (inst->mArg0.mReg == arg1.mReg) && ((ResizeRegister(arg1.mReg, 8) == X64Reg_RAX) || (ResizeRegister(arg1.mReg, 8) == X64Reg_RDX))) - { + { DisableRegister(inst->mArg1, X64Reg_RAX); DisableRegister(inst->mArg1, X64Reg_RDX); isFinalRun = false; } } } - + if (!handled) { if (inst->mResult) { - // The 3-op form of MUL must be in "reg, r/m64, imm" form + // The 3-op form of MUL must be in "reg, r/m64, imm" form if (!inst->mArg1.IsImmediateInt()) { SoftFail("Not supported"); @@ -10327,7 +10308,6 @@ bool BeMCContext::DoLegalization() case BeMCInstKind_Add: case BeMCInstKind_Sub: { - } break; case BeMCInstKind_Shl: @@ -10428,7 +10408,7 @@ bool BeMCContext::DoLegalization() { NotImpl(); //mcBlock->RemoveInst(instIdx); - //instIdx--; + //instIdx--; } else { @@ -10601,7 +10581,7 @@ bool BeMCContext::DoLegalization() isFinalRun = false; } continue; - } + } else // Struct = Struct { auto arg0Addr = OperandToAddr(arg0); @@ -10615,7 +10595,6 @@ bool BeMCContext::DoLegalization() OutputDebugStrF(" Mov MemCpy\n"); break; } - } if ((arg0Type->IsFloat()) && (arg1Type->IsIntable())) @@ -10656,9 +10635,9 @@ bool BeMCContext::DoLegalization() } else if ((!isSignedExt) || (arg1Type->mSize < 4)) { - // Int->Float conversions only work on 32 and 64-bit signed values, so we + // Int->Float conversions only work on 32 and 64-bit signed values, so we // zero-extend into a larger scratch vreg and then we do the signed conversion on that. - // Convert from + // Convert from // mov float, uint // to // mov scratch int, uint @@ -10693,7 +10672,7 @@ bool BeMCContext::DoLegalization() if ((arg0Type->mTypeCode == BeTypeCode_Double) && (arg1.IsImmediate())) { // One option would be to do a "movsd xmm, .rdata" to load up the immediate... - // and that would leave arg0 with the possibility of binding to a register + // and that would leave arg0 with the possibility of binding to a register // in a subsequent reg pass, but we don't do that. //ReplaceWithNewVReg(inst->mArg1, instIdx, true); @@ -10837,7 +10816,7 @@ bool BeMCContext::DoLegalization() case BeMCInstKind_Load: { // And Load gets converted to a "Load %reg0, [%reg1]" - // So both mArg0 and mArg1 must be a register + // So both mArg0 and mArg1 must be a register if (!IsAddressable(arg1)) { // Convert to @@ -10865,7 +10844,7 @@ bool BeMCContext::DoLegalization() break; case BeMCInstKind_Store: { - // Store gets converted to a "Store [reg], reg" + // Store gets converted to a "Store [reg], reg" if (!IsAddressable(arg0)) { // Convert to @@ -11399,7 +11378,7 @@ void BeMCContext::DoRegFinalization() } // This is similar to an optimization we have in DoLegalization, but it allows for directRelTo's to match - // We can't match those in DoLegalization because it would alter the liveness + // We can't match those in DoLegalization because it would alter the liveness if (inst->mKind == BeMCInstKind_Mov) { // Useless mov, remove it @@ -11446,7 +11425,6 @@ void BeMCContext::DoRegFinalization() { if (inst->mArg1.IsNativeReg()) { - } }*/ @@ -11685,7 +11663,7 @@ void BeMCContext::DoRegFinalization() if (isFinalPass) { - // We've failed to reorder + // We've failed to reorder int deferredIdx = 0; for (int instIdx = preserveIdx + 1; instIdx < instEndIdx; instIdx++) @@ -11702,7 +11680,7 @@ void BeMCContext::DoRegFinalization() auto reg = GetFullRegister(inst->mArg0.mReg); if (regFailed[(int)reg]) { - // Convert + // Convert // Mov , vreg0 // To // Push vreg0 @@ -11739,8 +11717,8 @@ void BeMCContext::DoRegFinalization() } else { - // Use R11 or XMM5 as our temporary - they are the least likely volatiles to be - // allocated, so we may not need to restore them after using them + // Use R11 or XMM5 as our temporary - they are the least likely volatiles to be + // allocated, so we may not need to restore them after using them X64CPURegister scratchReg; if (pushType->mTypeCode == BeTypeCode_Float) @@ -11896,8 +11874,8 @@ BeMCInstForm BeMCContext::GetInstForm(BeMCInst* inst) switch (arg1Type->mTypeCode) { case BeTypeCode_Float: return BeMCInstForm_XMM64_FRM32; - case BeTypeCode_Double: return BeMCInstForm_XMM64_FRM64; - case BeTypeCode_Int32: return BeMCInstForm_XMM64_RM32; + case BeTypeCode_Double: return BeMCInstForm_XMM64_FRM64; + case BeTypeCode_Int32: return BeMCInstForm_XMM64_RM32; case BeTypeCode_Int64: return BeMCInstForm_XMM64_RM64; case BeTypeCode_Pointer: return BeMCInstForm_XMM64_RM64; default: NotImpl(); @@ -11960,7 +11938,7 @@ BeMCInstForm BeMCContext::GetInstForm(BeMCInst* inst) else NotImpl(); } - } + } if ((arg1.IsImmediate()) && (arg0Type != NULL)) // MOV r/m64, imm32 { @@ -12287,7 +12265,7 @@ void BeMCContext::EmitStdInst(BeMCInstForm instForm, BeMCInst * inst, uint8 opco case BeMCInstForm_RM16_IMM8: EmitInst(BeMCInstForm_RM16_IMM8, opcode_rm_imm8, opcode_rm_imm8_rx, inst); break; case BeMCInstForm_RM32_IMM8: EmitInst(BeMCInstForm_RM32_IMM8, opcode_rm_imm8, opcode_rm_imm8_rx, inst); break; case BeMCInstForm_RM64_IMM8: EmitInst(BeMCInstForm_RM64_IMM8, opcode_rm_imm8, opcode_rm_imm8_rx, inst); break; - // These immediate forms assume an expansion to imm32, OR the register size for 8 and 16 bit registers + // These immediate forms assume an expansion to imm32, OR the register size for 8 and 16 bit registers case BeMCInstForm_RM32_IMM16: EmitInst(BeMCInstForm_RM32_IMM32, opcode_rm_imm, opcode_rm_imm_rx, inst); break; case BeMCInstForm_RM16_IMM16: EmitInst(BeMCInstForm_RM16_IMM16, opcode_rm_imm, opcode_rm_imm_rx, inst); break; case BeMCInstForm_RM64_IMM16: EmitInst(BeMCInstForm_RM64_IMM32, opcode_rm_imm, opcode_rm_imm_rx, inst); break; @@ -12345,7 +12323,7 @@ bool BeMCContext::EmitStdXMMInst(BeMCInstForm instForm, BeMCInst* inst, uint8 op } if (arg1Type->IsFloat()) - { + { if (elemType == BeTypeCode_Double) Emit(0x66); EmitREX(arg1, arg1, false); @@ -12353,7 +12331,7 @@ bool BeMCContext::EmitStdXMMInst(BeMCInstForm instForm, BeMCInst* inst, uint8 op EmitModRM(arg1, arg1); Emit(0); } - + if (elemType == BeTypeCode_Double) Emit(0x66); EmitREX(arg0, arg1, is64Bit); @@ -12370,7 +12348,7 @@ bool BeMCContext::EmitStdXMMInst(BeMCInstForm instForm, BeMCInst* inst, uint8 op // } NOP; - break; + break; } return false; @@ -12538,7 +12516,7 @@ bool BeMCContext::EmitIntBitwiseXMMInst(BeMCInstForm instForm, BeMCInst* inst, u auto arg0 = GetFixedOperand(inst->mArg0); auto arg1 = GetFixedOperand(inst->mArg1); - auto arg0Type = GetType(inst->mArg0); + auto arg0Type = GetType(inst->mArg0); if (arg0Type->IsExplicitVectorType()) { @@ -12546,7 +12524,7 @@ bool BeMCContext::EmitIntBitwiseXMMInst(BeMCInstForm instForm, BeMCInst* inst, u if ((vecType->mElementType->mTypeCode == BeTypeCode_Int8) || (vecType->mElementType->mTypeCode == BeTypeCode_Int16) || (vecType->mElementType->mTypeCode == BeTypeCode_Int32)) - { + { arg1 = IntXMMGetPacked(arg1, vecType); Emit(0x66); @@ -12940,7 +12918,7 @@ void BeMCContext::DoCodeEmission() bool allowEmission = true; if (inst->mKind == BeMCInstKind_DbgDecl) { - // We need to separate out dbgDecls if we are attempting to extend a previous one, + // We need to separate out dbgDecls if we are attempting to extend a previous one, // otherwise wait for a real instruction if (dbgExtendLifetime) { @@ -13042,7 +13020,6 @@ void BeMCContext::DoCodeEmission() dbgStr += StrFormat("#### %d Dbg End Gap %s\n", funcCodePos, dbgVar->mName.c_str()); } } - } } else // Removed @@ -13085,7 +13062,7 @@ void BeMCContext::DoCodeEmission() } // Finish range for variables exiting liveness. Since liveness is built in end-to-start order, - // an "add" means that the NEXT instruction won't have this entry (if the next entry doesn't share + // an "add" means that the NEXT instruction won't have this entry (if the next entry doesn't share // the exact liveness value) if ((inst->mLiveness != NULL) && (inst->mLiveness != vregsLive)) { @@ -13130,8 +13107,8 @@ void BeMCContext::DoCodeEmission() dbgStr += StrFormat("#### %d Dbg Setting LifetimeExtend %s\n", funcCodePos, dbgVar->mName.c_str()); } dbgVar->mDeclLifetimeExtend = dbgExtendLifetime; - //if (dbgExtendLifetime) - //dbgVar->mDeclEnd++; + //if (dbgExtendLifetime) + //dbgVar->mDeclEnd++; } } } @@ -13256,7 +13233,7 @@ void BeMCContext::DoCodeEmission() BF_ASSERT((uint)dbgVar->mDeclEnd >= (uint)dbgVar->mDeclStart); } } - } + } break; case BeMCInstKind_ValueScopeSoftEnd: break; @@ -13346,7 +13323,7 @@ void BeMCContext::DoCodeEmission() X64CPURegister srcReg = X64Reg_R11; int destOfs = 0; int srcOfs = 0; - + if (inst->mArg1) { BF_ASSERT(inst->mArg1.mKind == BeMCOperandKind_VRegPair); @@ -13465,7 +13442,7 @@ void BeMCContext::DoCodeEmission() Emit(0x8B); Emit(0x04 | (EncodeRegNum(vregInfo->mReg) << 3)); Emit(0x25); mOut.Write((int32)0x58); - // mov tlsReg, qword ptr [tlsReg + 8*rax] + // mov tlsReg, qword ptr [tlsReg + 8*rax] EmitREX(tlsOperand, tlsOperand, true); Emit(0x8B); EmitModRMRel(EncodeRegNum(vregInfo->mReg), vregInfo->mReg, X64Reg_RAX, 8, 0); @@ -13473,7 +13450,7 @@ void BeMCContext::DoCodeEmission() } break; case BeMCInstKind_PreserveVolatiles: - { + { for (int vregIdx : *inst->mLiveness) { if (vregIdx >= mLivenessContext.mNumItems) @@ -13557,7 +13534,7 @@ void BeMCContext::DoCodeEmission() } lastLabelIdx = inst->mArg0.mLabelIdx; labelPositions[inst->mArg0.mLabelIdx] = funcCodePos; - // This ensures we can't jump back into the hot jump area + // This ensures we can't jump back into the hot jump area break; case BeMCInstKind_Nop: Emit(0x90); @@ -13850,8 +13827,8 @@ void BeMCContext::DoCodeEmission() EmitREX(arg0, arg1, true); Emit(0x0F); Emit(0x10); - if (arg1.IsImmediateInt()) - arg1.mKind = BeMCOperandKind_Immediate_int32x4; + if (arg1.IsImmediateInt()) + arg1.mKind = BeMCOperandKind_Immediate_int32x4; EmitModRM(arg0, arg1); } @@ -13878,7 +13855,7 @@ void BeMCContext::DoCodeEmission() Emit(0x0F); Emit(0x54); EmitModRM(xmm15, imm1); - // PACKUSWB xmm15, xmm15 + // PACKUSWB xmm15, xmm15 Emit(0x66); EmitREX(xmm15, xmm15, true); Emit(0x0F); Emit(0x67); EmitModRM(xmm15, xmm15); @@ -13921,8 +13898,7 @@ void BeMCContext::DoCodeEmission() } else if ((arg0Type->mTypeCode == BeTypeCode_Int32) || (arg0Type->mTypeCode == BeTypeCode_Int64)) { - - // For 64-bit writes, we would like to use 32-bit zero extension but we resort to the full + // For 64-bit writes, we would like to use 32-bit zero extension but we resort to the full // 64-bits if necessary auto arg0 = inst->mArg0; if (arg0Type->mTypeCode == BeTypeCode_Int64) @@ -14168,7 +14144,6 @@ void BeMCContext::DoCodeEmission() if (inst->mArg1.IsSymbol()) { BF_ASSERT(inst->mArg0.IsNativeReg()); - } switch (instForm) @@ -14279,7 +14254,7 @@ void BeMCContext::DoCodeEmission() BF_ASSERT(inst->mArg1.IsImmediate()); // Is there a performance benefit to properly using MOVAPD vs MOVAPS if we only // use this register for double storage? - // MOVAPS + // MOVAPS EmitREX(inst->mArg0, BeMCOperand(), false); Emit(0x0F); Emit(0x29); EmitModRMRel(EncodeRegNum(inst->mArg0.mReg), X64Reg_RSP, X64Reg_None, 1, (int)inst->mArg1.mImmediate); @@ -14336,7 +14311,7 @@ void BeMCContext::DoCodeEmission() BF_ASSERT(inst->mArg1.IsImmediate()); // Is there a performance benefit to properly using MOVAPD vs MOVAPS if we only // use this register for double storage? - // MOVAPS + // MOVAPS EmitREX(inst->mArg0, BeMCOperand(), false); Emit(0x0F); Emit(0x28); // Push always uses RSP (required for stack unwinding), but Pop uses RBP when applicable @@ -14588,7 +14563,7 @@ void BeMCContext::DoCodeEmission() } //Fallthrough case BeMCInstKind_IMul: - { + { if (instForm == BeMCInstForm_XMM128_RM128) { if (arg0Type->IsExplicitVectorType()) @@ -14604,7 +14579,7 @@ void BeMCContext::DoCodeEmission() else { Emit(0x38); Emit(0x40); // PMULLD - } + } EmitModRM(arg0, arg1); break; } @@ -14622,7 +14597,7 @@ void BeMCContext::DoCodeEmission() BF_ASSERT(inst->mArg1.IsImmediate()); if ((inst->mArg0.IsNativeReg()) && (!inst->mDisableShortForm) && ((inst->mArg1.mImmediate == 2) || (inst->mArg1.mImmediate == 4) || (inst->mArg1.mImmediate == 8))) - { + { // LEA form auto resultType = GetType(inst->mArg0); if (resultType->mTypeCode != BeTypeCode_Int8) @@ -14744,7 +14719,7 @@ void BeMCContext::DoCodeEmission() case BeTypeCode_Int16: BF_ASSERT((inst->mArg0.IsNativeReg()) && (inst->mArg0.mReg == X64Reg_AX)); // XOR dx, dx - Emit(0x66); Emit(0x31); Emit(0xD2); + Emit(0x66); Emit(0x31); Emit(0xD2); // DIV rm Emit(0x66); EmitREX(BeMCOperand::FromReg(X64Reg_AX), inst->mArg1, false); @@ -14950,7 +14925,7 @@ void BeMCContext::DoCodeEmission() NotImpl(); } - //XOR arg0, arg0 + //XOR arg0, arg0 modInst.mKind = BeMCInstKind_Xor; modInst.mArg1 = modInst.mArg0; EmitStdInst(instForm, &modInst, 0x31, 0x33, 0x81, 0x6, 0x83, 0x6); @@ -14970,14 +14945,14 @@ void BeMCContext::DoCodeEmission() } break; case BeMCInstKind_Or: - { + { if (EmitIntBitwiseXMMInst(instForm, inst, 0xEB)) //POR break; EmitStdInst(instForm, inst, 0x09, 0x0B, 0x81, 0x1, 0x83, 0x1); } break; case BeMCInstKind_Xor: - { + { if (EmitIntBitwiseXMMInst(instForm, inst, 0xEF)) //PXOR break; if (EmitPackedXMMInst(instForm, inst, 0x57)) @@ -15023,16 +14998,16 @@ void BeMCContext::DoCodeEmission() case BeMCInstKind_Shl: Emit(0xF1); // PSLLW break; - case BeMCInstKind_Shr: + case BeMCInstKind_Shr: Emit(0xD1); // PSRLW break; - case BeMCInstKind_Sar: + case BeMCInstKind_Sar: Emit(0xE1); // PSRAW break; } EmitModRM(arg0, arg1); - } + } break; } @@ -15048,7 +15023,7 @@ void BeMCContext::DoCodeEmission() case BeMCInstKind_Sar: rx = 7; break; - } + } bool handled = false; switch (instForm) @@ -15148,7 +15123,7 @@ void BeMCContext::DoCodeEmission() BeMCJump jump; jump.mCodeOffset = funcCodePos; jump.mLabelIdx = inst->mArg0.mLabelIdx; - // Speculatively make it a short jump + // Speculatively make it a short jump jump.mJumpKind = 0; jump.mCmpKind = BeCmpKind_None; deferredJumps.push_back(jump); @@ -15215,7 +15190,6 @@ void BeMCContext::DoCodeEmission() } break; } - } //mOut.Write((uint8)0xC3); break; @@ -15283,7 +15257,7 @@ void BeMCContext::DoCodeEmission() if ((jump.mJumpKind == 0) && ((offset < -0x80) || (offset > 0x7F))) { - // Extend this guy into a rel32 + // Extend this guy into a rel32 int adjustFrom = jump.mCodeOffset + 2; int adjustBytes = 3; if (jump.mCmpKind != BeCmpKind_None) @@ -15301,7 +15275,6 @@ void BeMCContext::DoCodeEmission() codeVec[jump.mCodeOffset + 1 + textSectStartPos] = GetJumpOpCode(jump.mCmpKind, true); } - #define CODE_OFFSET_ADJUST(val) if (val >= adjustFrom) val += adjustBytes for (auto& labelPosition : labelPositions) CODE_OFFSET_ADJUST(labelPosition); @@ -15341,7 +15314,7 @@ void BeMCContext::DoCodeEmission() didWidening = true; } - //TODO: Test extending into a long jump + //TODO: Test extending into a long jump if (jump.mJumpKind == 0) codeVec[jump.mCodeOffset + 1 + textSectStartPos] = (uint8)offset; @@ -15500,7 +15473,7 @@ void BeMCContext::DoCodeEmission() mCOFFObject->mPDataSect.mRelocs.push_back(reloc); mCOFFObject->mPDataSect.mData.Write((int32)codeLen); - // XDATA pos + // XDATA pos reloc.mKind = BeMCRelocationKind_ADDR32NB; reloc.mOffset = mCOFFObject->mPDataSect.mData.GetPos(); reloc.mSymTableIdx = mCOFFObject->mXDataSect.mSymbolIdx; @@ -15590,7 +15563,7 @@ void BeMCContext::HandleParams() int regIdxOfs = 0; int paramOfs = 0; auto retType = mBeFunction->GetFuncType()->mReturnType; - + X64CPURegister compositeRetReg = X64Reg_None; bool flipFirstRegs = false; if (mBeFunction->HasStructRet()) @@ -15731,7 +15704,7 @@ void BeMCContext::HandleParams() paramVRegInfo->mFrameOffset = paramIdx * 8 + 8; CreateDefineVReg(paramVReg); } - //paramVRegInfo->mDbgVariable = mDbgFunction->mParams[paramIdx]; + //paramVRegInfo->mDbgVariable = mDbgFunction->mParams[paramIdx]; mValueToOperand[beArg] = paramVReg; } @@ -16144,7 +16117,7 @@ void BeMCContext::Generate(BeFunction* function) mDbgPreferredRegs[32] = X64Reg_R8;*/ //mDbgPreferredRegs[8] = X64Reg_RAX; - mDebugging = (function->mName == "?CheckMatch@?$StringSplitEnumeratorBase@D@System@bf@@IEAA_NXZ"); + mDebugging = (function->mName == "?stbi__gif_load_next@6$StbImage@StbImageBeef@bf@@SAPEAEPEAVstbi__context@123@PEAVstbi__gif@123@PEAHHPEAE@Z"); // || (function->mName == "?MethodA@TestProgram@BeefTest@bf@@CAXXZ"); // || (function->mName == "?Hey@Blurg@bf@@SAXXZ") // ; @@ -16225,7 +16198,7 @@ void BeMCContext::Generate(BeFunction* function) mHasVAStart = true; break; } - } + } } break; case BeMemSetInst::TypeId: @@ -16476,7 +16449,7 @@ void BeMCContext::Generate(BeFunction* function) doSignExtension = true; if (mcValue.IsImmediate()) - doSignExtension = false; + doSignExtension = false; if (doSignExtension) { @@ -16510,21 +16483,21 @@ void BeMCContext::Generate(BeFunction* function) // { // BeMCPhi* origPhi = mcValue.mPhi; // BeMCPhi* newPhi = mPhiAlloc.Alloc(); - // + // // *newPhi = *origPhi; // BF_SWAP(newPhi->mBrTrue, newPhi->mBrFalse); // result.mKind = BeMCOperandKind_Phi; // result.mPhi = newPhi; // break; // } - // + // // if (mcValue.mKind == BeMCOperandKind_CmpResult) // { // auto origCmpResult = mCmpResults[mcValue.mCmpResultIdx]; - // + // // auto cmpResultIdx = (int)mCmpResults.size(); // BeCmpResult cmpResult; - // cmpResult.mCmpKind = BeModule::InvertCmp(origCmpResult.mCmpKind); + // cmpResult.mCmpKind = BeModule::InvertCmp(origCmpResult.mCmpKind); // mCmpResults.push_back(cmpResult); // result.mKind = BeMCOperandKind_CmpResult; // result.mCmpResultIdx = cmpResultIdx; @@ -16605,9 +16578,9 @@ void BeMCContext::Generate(BeFunction* function) switch (castedInst->mOpKind) { - case BeBinaryOpKind_Add: result = AllocBinaryOp(BeMCInstKind_Add, mcLHS, mcRHS, BeMCBinIdentityKind_Any_IsZero, - ((castedInst->mOverflowCheckKind & BfOverflowCheckKind_Signed) != 0) ? BeMCOverflowCheckKind_O : - ((castedInst->mOverflowCheckKind & BfOverflowCheckKind_Unsigned) != 0) ? BeMCOverflowCheckKind_B : BeMCOverflowCheckKind_None); + case BeBinaryOpKind_Add: result = AllocBinaryOp(BeMCInstKind_Add, mcLHS, mcRHS, BeMCBinIdentityKind_Any_IsZero, + ((castedInst->mOverflowCheckKind & BfOverflowCheckKind_Signed) != 0) ? BeMCOverflowCheckKind_O : + ((castedInst->mOverflowCheckKind & BfOverflowCheckKind_Unsigned) != 0) ? BeMCOverflowCheckKind_B : BeMCOverflowCheckKind_None); break; case BeBinaryOpKind_Subtract: result = AllocBinaryOp(BeMCInstKind_Sub, mcLHS, mcRHS, BeMCBinIdentityKind_Right_IsZero, ((castedInst->mOverflowCheckKind & BfOverflowCheckKind_Signed) != 0) ? BeMCOverflowCheckKind_O : @@ -16696,7 +16669,7 @@ void BeMCContext::Generate(BeFunction* function) auto cmpResultIdx = (int)mCmpResults.size(); BeCmpResult cmpResult; - cmpResult.mCmpKind = castedInst->mCmpKind; + cmpResult.mCmpKind = castedInst->mCmpKind; if (valType->IsFloat()) { @@ -16928,7 +16901,7 @@ void BeMCContext::Generate(BeFunction* function) ptrValue = AllocVirtualReg(intType); auto vregInfo = mVRegInfo[ptrValue.mVRegIdx]; vregInfo->mIsExpr = true; - vregInfo->mRelTo = BeMCOperand::FromReg(X64Reg_RSP); + vregInfo->mRelTo = BeMCOperand::FromReg(X64Reg_RSP); vregInfo->mRelOffset.mKind = BeMCOperandKind::BeMCOperandKind_Immediate_HomeSize; CreateDefineVReg(ptrValue); } @@ -17166,7 +17139,6 @@ void BeMCContext::Generate(BeFunction* function) CreateDefineVReg(result); //TODO: Always correct? result.mKind = BeMCOperandKind_VReg; - } else SoftFail("Invalid GEP", inst->mDbgLoc); @@ -17308,11 +17280,10 @@ void BeMCContext::Generate(BeFunction* function) } }*/ - result.mKind = BeMCOperandKind_Phi; result.mPhi = mcPhi; - // DefPhi is important because when we convert a CondBr of a PHI, because we will need to create jumps to the correct + // DefPhi is important because when we convert a CondBr of a PHI, because we will need to create jumps to the correct // location when we create it as a value (specifically in the bool case) AllocInst(BeMCInstKind_DefPhi, result); } @@ -17358,7 +17329,7 @@ void BeMCContext::Generate(BeFunction* function) BF_ASSERT(retVal.IsVReg()); auto vregInfo = GetVRegInfo(retVal); - vregInfo->SetRetVal(); + vregInfo->SetRetVal(); } else if (retType->IsVector()) { @@ -17437,7 +17408,7 @@ void BeMCContext::Generate(BeFunction* function) { auto mcLHS = TryToVector(castedInst->mArgs[0].mValue); BeMCOperand mcRHS; - + if ((intrin->mKind == BfIRIntrinsic_SAR) || (intrin->mKind == BfIRIntrinsic_SHL) || (intrin->mKind == BfIRIntrinsic_SHR)) @@ -17486,12 +17457,12 @@ void BeMCContext::Generate(BeFunction* function) break; // case BfIRIntrinsic_Cast: // { -// +// // } // break; case BfIRIntrinsic_Not: { - auto mcLHS = TryToVector(castedInst->mArgs[0].mValue); + auto mcLHS = TryToVector(castedInst->mArgs[0].mValue); BeMCOperand mcRHS = BeMCOperand::FromImmediate(-1); result = AllocBinaryOp(BeMCInstKind_Xor, mcLHS, mcRHS, BeMCBinIdentityKind_None); break; } @@ -17848,7 +17819,7 @@ void BeMCContext::Generate(BeFunction* function) { auto valPtr = GetOperand(castedInst->mArgs[0].mValue); auto idx = GetOperand(castedInst->mArgs[1].mValue); - + auto valType = GetType(valPtr); if (!valType->IsPointer()) { @@ -17864,13 +17835,13 @@ void BeMCContext::Generate(BeFunction* function) } auto vectorType = (BeVectorType*)valType; - + auto elementPtrType = mModule->mContext->GetPointerTo(vectorType->mElementType); result = AllocVirtualReg(elementPtrType); CreateDefineVReg(result); auto vregInfo = GetVRegInfo(result); - vregInfo->mRelTo = valPtr; + vregInfo->mRelTo = valPtr; vregInfo->mRelOffset = idx; vregInfo->mRelOffsetScale = vectorType->mElementType->mSize; vregInfo->mIsExpr = true; @@ -17940,13 +17911,13 @@ void BeMCContext::Generate(BeFunction* function) auto mcType = GetOperand(castedInst->mArgs[2].mValue); BeType* beType = mModule->mBeIRCodeGen->GetBeTypeById((int32)mcType.mImmediate); - + auto mcList = AllocVirtualReg(mModule->mContext->GetPointerTo(mModule->mContext->GetPrimitiveType(BeTypeCode_NullPtr))); CreateDefineVReg(mcList); auto listVRegInfo = GetVRegInfo(mcList); listVRegInfo->mRelTo = mcListPtr; listVRegInfo->mIsExpr = true; - + auto mcSrc = AllocVirtualReg(mModule->mContext->GetPointerTo(beType)); CreateDefineVReg(mcSrc); auto srcVRegInfo = GetVRegInfo(mcSrc); @@ -17985,7 +17956,7 @@ void BeMCContext::Generate(BeFunction* function) CreateDefineVReg(vaStartVal); AllocInst(BeMCInstKind_Mov, BeMCOperand::ToLoad(destVal), BeMCOperand::FromVRegAddr(vaStartVal.mVRegIdx)); - } + } break; default: SoftFail(StrFormat("Intrinsic not handled: '%s'", intrin->mName.c_str()), castedInst->mDbgLoc); @@ -18092,9 +18063,9 @@ void BeMCContext::Generate(BeFunction* function) isFirstBlock = false; } mCurDbgLoc = NULL; - - BEMC_ASSERT(valueScopeStack.size() == 0); - BEMC_ASSERT(retCount == 1); + + BEMC_ASSERT(valueScopeStack.size() == 0); + BEMC_ASSERT(retCount == 1); bool wantDebug = mDebugging; //wantDebug |= function->mName == "?__BfCtor@SpriteBatchRenderer@Repo@bf@@QEAAXTint@@@Z"; @@ -18238,4 +18209,4 @@ void BeMCContext::Generate(BeFunction* function) } DoCodeEmission(); -} +} \ No newline at end of file diff --git a/IDEHelper/Backend/BeMCContext.h b/IDEHelper/Backend/BeMCContext.h index 8a5f2c2e..3f22e05b 100644 --- a/IDEHelper/Backend/BeMCContext.h +++ b/IDEHelper/Backend/BeMCContext.h @@ -14,7 +14,6 @@ NS_BF_BEGIN class BeMCAddInst { public: - }; struct BeVTrackingBits @@ -109,9 +108,7 @@ public: DiffIterator& operator++() { - } - };*/ Iterator begin() @@ -198,7 +195,7 @@ enum BeMCOperandKind BeMCOperandKind_Immediate_f64, BeMCOperandKind_Immediate_f32_Packed128, BeMCOperandKind_Immediate_f64_Packed128, - BeMCOperandKind_Immediate_int32x4, + BeMCOperandKind_Immediate_int32x4, BeMCOperandKind_ConstAgg, BeMCOperandKind_Block, BeMCOperandKind_Label, @@ -769,14 +766,14 @@ class BeMCVRegInfo { public: X64CPURegister mReg; - X64CPURegister mNaturalReg; // From param + X64CPURegister mNaturalReg; // From param BeType* mType; int mAlign; int mFrameOffset; // 0 = 'RBP' (probably first local var or saved RBP), 8 means retAddr bool mRegNumPinned; bool mHasDynLife; bool mDoConservativeLife; // Keep alive through 'init' as well as 'uninit' - bool mIsExpr; // Not an actual value, something like 'mRelTo + mRelOffset' + bool mIsExpr; // Not an actual value, something like 'mRelTo + mRelOffset' bool mWantsExprActualize; bool mWantsExprOffsetActualize; bool mChainLifetimeEnd; // Kill relTo's when we are killed @@ -794,7 +791,7 @@ public: bool mDisableR13; // Special case when this vreg is used in an ModRM scale, which isn't allowed bool mDisableRAX; // Special case when RAX must be preserved (ie: For IDIV) bool mDisableRDX; // Special case when RDX must be preserved (ie: For IDIV) - bool mDisableEx; // Disable any registers that require a REX + bool mDisableEx; // Disable any registers that require a REX int mVRegAffinity; // Try to match the mReg of this vreg BeMCOperand mRelTo; int mRelOffsetScale; @@ -804,7 +801,7 @@ public: bool mFoundLastUse; bool mMustExist; // Regs we must be able to debug - // Must be refreshed with RefreshRefCounts + // Must be refreshed with RefreshRefCounts int mRefCount; int mAssignCount; @@ -961,7 +958,6 @@ enum BeTrackKind BeTrackKind_COUNT = 2 }; - // BeVTrackingEntry is immutable -- the Set/Clear/Merge methods allocate new entries if // the requested change produces a new liveness set class BeVTrackingContext @@ -1476,7 +1472,7 @@ public: void EmitStdInst(BeMCInstForm instForm, BeMCInst* inst, uint8 opcode_rm_r, uint8 opcode_r_rm, uint8 opcode_rm_imm, uint8 opcode_rm_imm_rx, uint8 opcode_rm_imm8, uint8 opcode_rm_imm8_rx); bool EmitStdXMMInst(BeMCInstForm instForm, BeMCInst* inst, uint8 opcode); bool EmitStdXMMInst(BeMCInstForm instForm, BeMCInst* inst, uint8 opcode, uint8 opcode_dest_frm); - bool EmitPackedXMMInst(BeMCInstForm instForm, BeMCInst* inst, uint8 opcode); + bool EmitPackedXMMInst(BeMCInstForm instForm, BeMCInst* inst, uint8 opcode); bool EmitIntXMMInst(BeMCInstForm instForm, BeMCInst* inst, uint8 opcode); bool EmitIntBitwiseXMMInst(BeMCInstForm instForm, BeMCInst* inst, uint8 opcode); void EmitAggMov(const BeMCOperand& dest, const BeMCOperand& src); diff --git a/IDEHelper/Backend/BeModule.cpp b/IDEHelper/Backend/BeModule.cpp index 93e3f1da..71f7109a 100644 --- a/IDEHelper/Backend/BeModule.cpp +++ b/IDEHelper/Backend/BeModule.cpp @@ -64,16 +64,16 @@ BeValue* BeInliner::Remap(BeValue* srcValue) return itr->second;*/ if (mValueMap.TryGetValue(srcValue, &valuePtr)) return *valuePtr; - - BeMDNode* wrapMDNode = NULL; + + BeMDNode* wrapMDNode = NULL; if (auto dbgFunction = BeValueDynCast(srcValue)) - { - wrapMDNode = dbgFunction; + { + wrapMDNode = dbgFunction; } if (auto dbgLexBlock = BeValueDynCast(srcValue)) { - wrapMDNode = dbgLexBlock; + wrapMDNode = dbgLexBlock; } if (auto callInst = BeValueDynCast(srcValue)) @@ -83,9 +83,9 @@ BeValue* BeInliner::Remap(BeValue* srcValue) } if (wrapMDNode != NULL) - { + { auto destMDNode = mOwnedValueVec->Alloc(); - destMDNode->mScope = wrapMDNode; + destMDNode->mScope = wrapMDNode; mValueMap[srcValue] = destMDNode; return destMDNode; } @@ -107,13 +107,13 @@ BeDbgLoc* BeInliner::ExtendInlineDbgLoc(BeDbgLoc* srcInlineAt) BeDbgLoc** dbgLocPtr = NULL; if (mInlinedAtMap.TryGetValue(srcInlineAt, &dbgLocPtr)) return *dbgLocPtr; - + auto dbgLoc = mModule->mAlloc.Alloc(); dbgLoc->mLine = srcInlineAt->mLine; dbgLoc->mColumn = srcInlineAt->mColumn; dbgLoc->mDbgScope = (BeMDNode*)Remap(srcInlineAt->mDbgScope); dbgLoc->mIdx = mModule->mCurDbgLocIdx++; - dbgLoc->mDbgInlinedAt = ExtendInlineDbgLoc(srcInlineAt->mDbgInlinedAt); + dbgLoc->mDbgInlinedAt = ExtendInlineDbgLoc(srcInlineAt->mDbgInlinedAt); mInlinedAtMap[srcInlineAt] = dbgLoc; return dbgLoc; @@ -130,7 +130,7 @@ void BeInliner::AddInst(BeInst* destInst, BeInst* srcInst) } else { - BeDbgLoc* inlinedAt = ExtendInlineDbgLoc(mSrcDbgLoc->mDbgInlinedAt); + BeDbgLoc* inlinedAt = ExtendInlineDbgLoc(mSrcDbgLoc->mDbgInlinedAt); mModule->SetCurrentDebugLocation(mSrcDbgLoc->mLine, mSrcDbgLoc->mColumn, (BeMDNode*)Remap(mSrcDbgLoc->mDbgScope), inlinedAt); mDestDbgLoc = mModule->mCurDbgLoc; } @@ -138,7 +138,7 @@ void BeInliner::AddInst(BeInst* destInst, BeInst* srcInst) if (srcInst != NULL) destInst->mName = srcInst->mName; - + destInst->mDbgLoc = mDestDbgLoc; destInst->mParentBlock = mDestBlock; mDestBlock->mInstructions.push_back(destInst); @@ -156,7 +156,6 @@ void BeInliner::Visit(BeBlock* beBlock) void BeInliner::Visit(BeArgument* beArgument) { - } void BeInliner::Visit(BeInst* beInst) @@ -166,7 +165,7 @@ void BeInliner::Visit(BeInst* beInst) void BeInliner::Visit(BeNopInst* nopInst) { - auto destNopInst = AllocInst(nopInst); + auto destNopInst = AllocInst(nopInst); } void BeInliner::Visit(BeUnreachableInst* unreachableInst) @@ -188,7 +187,7 @@ void BeInliner::Visit(BeUndefValueInst* undefValue) void BeInliner::Visit(BeExtractValueInst* extractValue) { auto destExtractValue = AllocInst(extractValue); - destExtractValue->mAggVal = Remap(extractValue->mAggVal); + destExtractValue->mAggVal = Remap(extractValue->mAggVal); destExtractValue->mIdx = extractValue->mIdx; } @@ -233,7 +232,7 @@ void BeInliner::Visit(BeBinaryOpInst* binaryOpInst) auto destBinaryOp = AllocInst(binaryOpInst); destBinaryOp->mOpKind = binaryOpInst->mOpKind; destBinaryOp->mLHS = Remap(binaryOpInst->mLHS); - destBinaryOp->mRHS = Remap(binaryOpInst->mRHS); + destBinaryOp->mRHS = Remap(binaryOpInst->mRHS); } void BeInliner::Visit(BeCmpInst* cmpInst) @@ -285,19 +284,19 @@ void BeInliner::Visit(BeAliasValueInst* aliasValueInst) void BeInliner::Visit(BeLifetimeExtendInst* lifetimeExtendInst) { auto destlifetimeExtendInst = AllocInst(lifetimeExtendInst); - destlifetimeExtendInst->mPtr = Remap(lifetimeExtendInst->mPtr); + destlifetimeExtendInst->mPtr = Remap(lifetimeExtendInst->mPtr); } void BeInliner::Visit(BeLifetimeStartInst* lifetimeStartInst) { auto destlifetimeStartInst = AllocInst(lifetimeStartInst); - destlifetimeStartInst->mPtr = Remap(lifetimeStartInst->mPtr); + destlifetimeStartInst->mPtr = Remap(lifetimeStartInst->mPtr); } void BeInliner::Visit(BeLifetimeEndInst* lifetimeEndInst) { auto destlifetimeEndInst = AllocInst(lifetimeEndInst); - destlifetimeEndInst->mPtr = Remap(lifetimeEndInst->mPtr); + destlifetimeEndInst->mPtr = Remap(lifetimeEndInst->mPtr); } void BeInliner::Visit(BeLifetimeSoftEndInst* lifetimeEndInst) @@ -310,7 +309,7 @@ void BeInliner::Visit(BeLifetimeFenceInst* lifetimeFenceInst) { auto destlifetimeFenceInst = AllocInst(lifetimeFenceInst); destlifetimeFenceInst->mFenceBlock = (BeBlock*)Remap(lifetimeFenceInst->mFenceBlock); - destlifetimeFenceInst->mPtr = Remap(lifetimeFenceInst->mPtr); + destlifetimeFenceInst->mPtr = Remap(lifetimeFenceInst->mPtr); } void BeInliner::Visit(BeValueScopeStartInst* valueScopeStartInst) @@ -334,14 +333,14 @@ void BeInliner::Visit(BeValueScopeEndInst* valueScopeEndInst) void BeInliner::Visit(BeLoadInst* loadInst) { auto destLoadInst = AllocInst(loadInst); - destLoadInst->mTarget = Remap(loadInst->mTarget); + destLoadInst->mTarget = Remap(loadInst->mTarget); } void BeInliner::Visit(BeStoreInst* storeInst) { auto destStoreInst = AllocInst(storeInst); destStoreInst->mPtr = Remap(storeInst->mPtr); - destStoreInst->mVal = Remap(storeInst->mVal); + destStoreInst->mVal = Remap(storeInst->mVal); } void BeInliner::Visit(BeSetCanMergeInst* setCanMergeInst) @@ -380,26 +379,24 @@ void BeInliner::Visit(BeCondBrInst* condBrInst) auto destCondBrInst = AllocInst(condBrInst); destCondBrInst->mCond = Remap(condBrInst->mCond); destCondBrInst->mTrueBlock = (BeBlock*)Remap(condBrInst->mTrueBlock); - destCondBrInst->mFalseBlock = (BeBlock*)Remap(condBrInst->mFalseBlock); + destCondBrInst->mFalseBlock = (BeBlock*)Remap(condBrInst->mFalseBlock); } void BeInliner::Visit(BePhiIncoming* phiIncomingInst) { - } void BeInliner::Visit(BePhiInst* phiInst) -{ +{ auto destPhiInst = AllocInst(phiInst); for (auto incoming : phiInst->mIncoming) { auto destPhiIncoming = mAlloc->Alloc(); - destPhiIncoming->mValue = Remap(incoming->mValue); + destPhiIncoming->mValue = Remap(incoming->mValue); destPhiIncoming->mBlock = (BeBlock*)Remap(incoming->mBlock); destPhiInst->mIncoming.push_back(destPhiIncoming); } - destPhiInst->mType = phiInst->mType; } @@ -434,7 +431,7 @@ void BeInliner::Visit(BeCallInst* callInst) destCallInst->mArgs.push_back(copiedArg); } destCallInst->mNoReturn = callInst->mNoReturn; - destCallInst->mTailCall = callInst->mTailCall; + destCallInst->mTailCall = callInst->mTailCall; } void BeInliner::Visit(BeDbgDeclareInst* dbgDeclareInst) @@ -468,7 +465,7 @@ void BeConstant::GetData(BeConstData& data) data.mData.Insert(data.mData.mSize, (uint8*)&f, sizeof(float)); } else - { + { data.mData.Insert(data.mData.mSize, &mUInt8, type->mSize); } } @@ -478,7 +475,7 @@ void BeConstant::HashContent(BeHashContext& hashCtx) hashCtx.Mixin(TypeId); mType->HashReference(hashCtx); if (mType->mTypeCode < BeTypeCode_Struct) - { + { hashCtx.Mixin(mUInt64); } else if (mType->IsPointer()) @@ -510,7 +507,7 @@ BeType* BeGEP1Constant::GetType() } BeType* BeGEP2Constant::GetType() -{ +{ BePointerType* ptrType = (BePointerType*)mTarget->GetType(); BF_ASSERT(ptrType->mTypeCode == BeTypeCode_Pointer); if (ptrType->mElementType->mTypeCode == BeTypeCode_SizedArray) @@ -539,7 +536,7 @@ BeType* BeGEP2Constant::GetType() BeType* BeExtractValueConstant::GetType() { - BeType* type = mTarget->GetType(); + BeType* type = mTarget->GetType(); if (type->mTypeCode == BeTypeCode_SizedArray) { BeSizedArrayType* arrayType = (BeSizedArrayType*)type; @@ -658,10 +655,10 @@ BeModule* BeInst::GetModule() } void BeInst::SetName(const StringImpl& name) -{ +{ char* nameStr = (char*)GetModule()->mAlloc.AllocBytes((int)name.length() + 1); strcpy(nameStr, name.c_str()); - mName = nameStr; + mName = nameStr; } BeType* BeLoadInst::GetType() @@ -692,7 +689,7 @@ BeType* BeExtractValueInst::GetType() } BF_ASSERT(aggType->mTypeCode == BeTypeCode_Struct); BeStructType* structType = (BeStructType*)aggType; - return structType->mMembers[mIdx].mType; + return structType->mMembers[mIdx].mType; } BeType* BeInsertValueInst::GetType() @@ -717,10 +714,9 @@ BeType * BeValueScopeStartInst::GetType() return context->GetPrimitiveType(BeTypeCode_Int32); } - BeType* BeGEPInst::GetType() { - if (mIdx1 == NULL) + if (mIdx1 == NULL) return mPtr->GetType(); BePointerType* ptrType = (BePointerType*)mPtr->GetType(); @@ -763,8 +759,8 @@ BeType* BeCallInst::GetType() auto type = mFunc->GetType(); if (type == NULL) { - if (auto intrin = BeValueDynCast(mFunc)) - return intrin->mReturnType; + if (auto intrin = BeValueDynCast(mFunc)) + return intrin->mReturnType; return type; } while (type->mTypeCode == BeTypeCode_Pointer) @@ -871,7 +867,7 @@ BeDbgFile* BeDbgLoc::GetDbgFile() } else if (auto dbgFunc = BeValueDynCast(checkScope)) { - return dbgFunc->mFile; + return dbgFunc->mFile; } else if (auto dbgLexBlock = BeValueDynCast(checkScope)) { @@ -894,9 +890,9 @@ BeDbgLoc* BeDbgLoc::GetInlinedAt(int idx) } BeDbgLoc* BeDbgLoc::GetRoot() -{ +{ auto checkDbgLoc = this; - while (checkDbgLoc->mDbgInlinedAt != NULL) + while (checkDbgLoc->mDbgInlinedAt != NULL) checkDbgLoc = checkDbgLoc->mDbgInlinedAt; return checkDbgLoc; } @@ -1027,7 +1023,7 @@ void BeDbgEnumType::SetMembers(SizedArrayImpl& members) if (auto enumMember = BeValueDynCast(member)) { mMembers.push_back(enumMember); - } + } else BF_FATAL("bad"); } @@ -1053,7 +1049,7 @@ void BeDumpContext::ToString(StringImpl& str, BeValue* value, bool showType, boo } if (auto dbgType = BeValueDynCast(mdNode)) - { + { str += StrFormat("DbgTypeId: %d", dbgType->mTypeId); return; } @@ -1081,7 +1077,7 @@ void BeDumpContext::ToString(StringImpl& str, BeValue* value, bool showType, boo } if (auto dbgFunc = BeValueDynCast(mdNode)) - { + { if (auto parentType = BeValueDynCast(dbgFunc->mScope)) { ToString(str, dbgFunc->mScope); @@ -1095,7 +1091,7 @@ void BeDumpContext::ToString(StringImpl& str, BeValue* value, bool showType, boo str += dbgFunc->mName; if (mdDrillDown) - { + { str += ":"; ToString(str, dbgFunc->mFile, true, true); } @@ -1112,9 +1108,9 @@ void BeDumpContext::ToString(StringImpl& str, BeValue* value, bool showType, boo ToString(str, lexBlock->mScope); return; } - + if (auto dbgType = BeValueDynCast(mdNode)) - { + { if (dbgType->mEncoding == llvm::dwarf::DW_ATE_address) { if (dbgType->mSize == 0) @@ -1187,7 +1183,7 @@ void BeDumpContext::ToString(StringImpl& str, BeValue* value, bool showType, boo } if (auto dbgType = BeValueDynCast(mdNode)) - { + { if ((BeValueDynCast(dbgType->mScope) != NULL) || (BeValueDynCast(dbgType->mScope) != NULL)) { @@ -1202,7 +1198,7 @@ void BeDumpContext::ToString(StringImpl& str, BeValue* value, bool showType, boo } if (auto dbgType = BeValueDynCast(mdNode)) - { + { if ((BeValueDynCast(dbgType->mScope) != NULL) || (BeValueDynCast(dbgType->mScope) != NULL)) { @@ -1217,7 +1213,7 @@ void BeDumpContext::ToString(StringImpl& str, BeValue* value, bool showType, boo } if (auto dbgType = BeValueDynCast(mdNode)) - { + { if ((BeValueDynCast(dbgType->mScope) != NULL) || (BeValueDynCast(dbgType->mScope) != NULL)) { @@ -1232,7 +1228,7 @@ void BeDumpContext::ToString(StringImpl& str, BeValue* value, bool showType, boo } if (auto dbgType = BeValueDynCast(mdNode)) - { + { ToString(str, dbgType->mElement); str += "["; str += StrFormat("%d", dbgType->mNumElements); @@ -1262,7 +1258,7 @@ void BeDumpContext::ToString(StringImpl& str, BeValue* value, bool showType, boo } if (auto dbgMember = BeValueDynCast(mdNode)) - { + { if (dbgMember->mIsStatic) str += "static "; ToString(str, dbgMember->mType); @@ -1273,14 +1269,14 @@ void BeDumpContext::ToString(StringImpl& str, BeValue* value, bool showType, boo str += " offset:"; str += StrFormat("%d", dbgMember->mOffset); } - + if (dbgMember->mStaticValue != NULL) str += " " + ToString(dbgMember->mStaticValue); return; } if (auto dbgMember = BeValueDynCast(mdNode)) - { + { str += dbgMember->mName; str += " "; str += StrFormat("%lld", dbgMember->mValue); @@ -1308,13 +1304,13 @@ void BeDumpContext::ToString(StringImpl& str, BeValue* value, bool showType, boo } if (auto constantGEP = BeValueDynCast(value)) - { + { str += "ConstGEP2 "; ToString(str, constantGEP->mTarget); str += StrFormat(" %d %d", constantGEP->mIdx0, constantGEP->mIdx1); return; } - + if (auto constantExtract = BeValueDynCast(value)) { str += "ConstExtract "; @@ -1339,10 +1335,10 @@ void BeDumpContext::ToString(StringImpl& str, BeValue* value, bool showType, boo str += "%"; str += param.mName; } - + return; } - + if (auto func = BeValueDynCast(value)) { str += func->mName; @@ -1350,7 +1346,7 @@ void BeDumpContext::ToString(StringImpl& str, BeValue* value, bool showType, boo } if (auto constant = BeValueDynCast(value)) - { + { if (showType) { BeModule::ToString(str, constant->mType); @@ -1361,7 +1357,7 @@ void BeDumpContext::ToString(StringImpl& str, BeValue* value, bool showType, boo switch (constant->mType->mTypeCode) { - case BeTypeCode_Struct: + case BeTypeCode_Struct: case BeTypeCode_SizedArray: case BeTypeCode_Vector: for (int valIdx = 0; valIdx < (int)constant->mMemberValues.size(); valIdx++) @@ -1369,7 +1365,7 @@ void BeDumpContext::ToString(StringImpl& str, BeValue* value, bool showType, boo if (valIdx > 0) str += ", "; ToString(str, constant->mMemberValues[valIdx], false); - } + } break; default: BF_FATAL("NotImpl"); @@ -1392,7 +1388,7 @@ void BeDumpContext::ToString(StringImpl& str, BeValue* value, bool showType, boo } if (auto constant = BeValueDynCast(value)) - { + { ToString(str, constant->mType); str += " cast "; ToString(str, constant->mTarget); @@ -1409,7 +1405,7 @@ void BeDumpContext::ToString(StringImpl& str, BeValue* value, bool showType, boo } if (auto constant = BeValueDynCast(value)) - { + { ToString(str, constant->GetType()); str += " gep ("; ToString(str, constant->mTarget); @@ -1427,7 +1423,7 @@ void BeDumpContext::ToString(StringImpl& str, BeValue* value, bool showType, boo } if (auto constant = BeValueDynCast(value)) - { + { ToString(str, constant->GetType()); str += " ("; for (int i = 0; i < constant->mMemberValues.size(); i++) @@ -1441,7 +1437,7 @@ void BeDumpContext::ToString(StringImpl& str, BeValue* value, bool showType, boo } if (auto constant = BeValueDynCast(value)) - { + { ToString(str, constant->GetType()); str += " \""; str += SlashString(constant->mString, true, true); @@ -1489,7 +1485,7 @@ void BeDumpContext::ToString(StringImpl& str, BeValue* value, bool showType, boo case BeTypeCode_Struct: case BeTypeCode_SizedArray: case BeTypeCode_Vector: - str += "zeroinitializer"; + str += "zeroinitializer"; return; case BeTypeCode_Function: BF_FATAL("Notimpl"); @@ -1515,10 +1511,9 @@ void BeDumpContext::ToString(StringImpl& str, BeValue* value, bool showType, boo ToString(str, callInst->mInlineResult); return; } - } + } - - BeType* resultType = NULL; + BeType* resultType = NULL; const char* wantNamePtr = NULL; if (auto instVal = BeValueDynCast(value)) { @@ -1526,7 +1521,7 @@ void BeDumpContext::ToString(StringImpl& str, BeValue* value, bool showType, boo if ((instVal->mName != NULL) && (instVal->mName[0] != 0)) wantNamePtr = instVal->mName; } - + String* valueNamePtr = NULL; if (mValueNameMap.TryGetValue(value, &valueNamePtr)) { @@ -1540,16 +1535,16 @@ void BeDumpContext::ToString(StringImpl& str, BeValue* value, bool showType, boo str += *valueNamePtr; return; } - + if (auto beBlock = BeValueDynCast(value)) { if (!beBlock->mName.IsEmpty()) wantNamePtr = beBlock->mName.c_str(); } - + StringT<64> useName; if (wantNamePtr != NULL) - useName += wantNamePtr; + useName += wantNamePtr; while (true) { int* idxPtr = NULL; @@ -1557,13 +1552,13 @@ void BeDumpContext::ToString(StringImpl& str, BeValue* value, bool showType, boo break; int checkIdx = (*idxPtr)++; - + char str[32]; - sprintf(str, "%d", checkIdx); + sprintf(str, "%d", checkIdx); useName += str; } - mValueNameMap[value] = useName; + mValueNameMap[value] = useName; if ((showType) && (resultType != NULL)) { BeModule::ToString(str, resultType); @@ -1599,7 +1594,7 @@ void BeDumpContext::ToString(StringImpl& str, BeType* type) } void BeDumpContext::ToString(StringImpl& str, BeDbgFunction* dbgFunction, bool showScope) -{ +{ if (dbgFunction->mIsStaticMethod) str += "static "; if (dbgFunction->mIsLocalToUnit) @@ -1610,7 +1605,7 @@ void BeDumpContext::ToString(StringImpl& str, BeDbgFunction* dbgFunction, bool s str += StrFormat("virtual(%d) ", dbgFunction->mVIndex); str += ToString(dbgFunction->mType->mReturnType); - str += " "; + str += " "; if ((showScope) && (dbgFunction->mScope != NULL)) { @@ -1632,7 +1627,7 @@ void BeDumpContext::ToString(StringImpl& str, BeDbgFunction* dbgFunction, bool s str += dbgFunction->mName; if (needsQuote) str += "\""; - + if (!dbgFunction->mGenericArgs.IsEmpty()) { str += "<"; @@ -1682,7 +1677,7 @@ void BeDumpContext::ToString(StringImpl& str, BeDbgFunction* dbgFunction, bool s { str += " Link:"; str += dbgFunction->mLinkageName; - } + } } String BeDumpContext::ToString(BeDbgFunction* dbgFunction) @@ -1722,7 +1717,7 @@ void BeDumpContext::ToString(StringImpl& str, BeCmpKind cmpKind) case BeCmpKind_NO: str += "no"; return; default: str += "???"; - } + } } String BeDumpContext::ToString(BeCmpKind cmpKind) @@ -1735,7 +1730,7 @@ String BeDumpContext::ToString(BeCmpKind cmpKind) void BeDumpContext::ToString(StringImpl& str, BeBinaryOpKind opKind) { switch (opKind) - { + { case BeBinaryOpKind_Add: str += "+"; return; case BeBinaryOpKind_Subtract: str += "-"; return; case BeBinaryOpKind_Multiply: str += "*"; return; @@ -1751,7 +1746,7 @@ void BeDumpContext::ToString(StringImpl& str, BeBinaryOpKind opKind) case BeBinaryOpKind_ARightShift: str += "A>>"; return; default: str += "???"; - } + } } String BeDumpContext::ToString(BeBinaryOpKind opKind) @@ -1800,11 +1795,11 @@ BeModule::BeModule(const StringImpl& moduleName, BeContext* context) mCeMachine = NULL; mPrevDbgLocInline = NULL; mCurDbgLocIdx = 0; - mCurLexBlockId = 0; + mCurLexBlockId = 0; } void BeModule::Hash(BeHashContext& hashCtx) -{ +{ hashCtx.MixinStr(mTargetTriple); hashCtx.MixinStr(mTargetCPU); @@ -1813,7 +1808,7 @@ void BeModule::Hash(BeHashContext& hashCtx) configConst->HashContent(hashCtx); if (mDbgModule != NULL) - mDbgModule->HashReference(hashCtx); + mDbgModule->HashReference(hashCtx); if (!mFunctions.IsEmpty()) { @@ -1828,26 +1823,26 @@ void BeModule::Hash(BeHashContext& hashCtx) beFunction->HashReference(hashCtx); } } - + if (!mGlobalVariables.IsEmpty()) { std::sort(mGlobalVariables.begin(), mGlobalVariables.end(), [](BeGlobalVariable* lhs, BeGlobalVariable* rhs) { return (lhs->mName < rhs->mName); }); - + for (auto& beGlobalVar : mGlobalVariables) { if (beGlobalVar->mInitializer != NULL) beGlobalVar->HashReference(hashCtx); } - } + } } #define DELETE_ENTRY(i) delete mOwnedValues[i]; mOwnedValues[i] = NULL BeModule::~BeModule() -{ +{ delete mDbgModule; } @@ -1893,23 +1888,23 @@ String BeModule::ToString(BeFunction* wantFunc) Dictionary dbgLocs; StringT<128*1024> str; - + SetAndRestoreValue prevActiveFunc(mActiveFunction, NULL); BeDumpContext dc; - + if (wantFunc == NULL) { str += "Module: "; str += mModuleName; str += "\n"; str += "Target: "; str += mTargetTriple; str += "\n"; if (mDbgModule != NULL) - { + { str += "FileName: "; str += mDbgModule->mFileName; str += "\n"; str += "Directory: "; str += mDbgModule->mDirectory; str += "\n"; - str += "Producer: "; str += mDbgModule->mProducer; str += "\n"; + str += "Producer: "; str += mDbgModule->mProducer; str += "\n"; } - + for (int i = 0; i < (int)mConfigConsts64.size(); i++) { if (i == 0) @@ -1932,7 +1927,7 @@ String BeModule::ToString(BeFunction* wantFunc) } str += "\n"; - str += "; Global variables\n"; + str += "; Global variables\n"; for (int gvIdx = 0; gvIdx < (int)mGlobalVariables.size(); gvIdx++) { auto gv = mGlobalVariables[gvIdx]; @@ -1977,7 +1972,7 @@ String BeModule::ToString(BeFunction* wantFunc) if (dbgGlobalVar->mIsLocalToUnit) str += "internal "; dc.ToString(str, dbgGlobalVar->mType); - + if (dbgGlobalVar->mValue != NULL) { str += " "; @@ -1997,8 +1992,8 @@ String BeModule::ToString(BeFunction* wantFunc) str += dbgGlobalVar->mLinkageName; } str += "\n"; - } - + } + str += "\n"; } @@ -2007,7 +2002,7 @@ String BeModule::ToString(BeFunction* wantFunc) { if (auto dbgStructType = BeValueDynCast(dbgType)) { - dc.ToString(str, dbgStructType); + dc.ToString(str, dbgStructType); str += " = {"; if (dbgStructType->mSize != -1) { @@ -2041,7 +2036,7 @@ String BeModule::ToString(BeFunction* wantFunc) str += ","; str += "\n "; - dc.ToString(str, dbgStructType->mMethods[methodIdx], false); + dc.ToString(str, dbgStructType->mMethods[methodIdx], false); } str += "}"; } @@ -2056,11 +2051,11 @@ String BeModule::ToString(BeFunction* wantFunc) str += "\n Size: "; str += StrFormat("%d", dbgEnumType->mSize); str += "\n Align : "; - str += StrFormat("%d", dbgEnumType->mAlign); + str += StrFormat("%d", dbgEnumType->mAlign); } if (dbgEnumType->mElementType != NULL) { - str += "\n Underlying: "; + str += "\n Underlying: "; dc.ToString(str, dbgEnumType->mElementType); } if (!dbgEnumType->mMembers.IsEmpty()) @@ -2102,7 +2097,7 @@ String BeModule::ToString(BeFunction* wantFunc) continue; mActiveFunction = func; - + Dictionary valueNameMap; HashSet seenNames; @@ -2116,13 +2111,13 @@ String BeModule::ToString(BeFunction* wantFunc) str += func->mName; str += "("; for (int paramIdx = 0; paramIdx < (int)funcType->mParams.size(); paramIdx++) - { + { auto& typeParam = funcType->mParams[paramIdx]; auto& param = func->mParams[paramIdx]; if (paramIdx > 0) str += ", "; ToString(str, typeParam.mType); - + if (param.mStructRet) str += " sret"; if (param.mNoAlias) @@ -2258,7 +2253,7 @@ String BeModule::ToString(BeFunction* wantFunc) str += ":\n"; for (auto inst : beBlock->mInstructions) - { + { if (inst->mDbgLoc != NULL) { if ((inst->mDbgLoc != lastDbgLoc) && (lastDbgLoc != NULL)) @@ -2269,7 +2264,7 @@ String BeModule::ToString(BeFunction* wantFunc) // } if ((inst->mDbgLoc->mDbgInlinedAt != lastDbgLoc->mDbgInlinedAt) && (inst->mDbgLoc->mDbgInlinedAt != NULL)) - { + { prevDbgLocs.Clear(); auto prevInlinedAt = lastDbgLoc->mDbgInlinedAt; while (prevInlinedAt != NULL) @@ -2293,7 +2288,7 @@ String BeModule::ToString(BeFunction* wantFunc) str += " "; if (inst->CanBeReferenced()) - { + { str += dc.ToString(inst, false); str += " = "; } @@ -2331,7 +2326,7 @@ String BeModule::ToString(BeFunction* wantFunc) str += dc.ToString(castedInst->mRHS, false); } break;*/ - DISPLAY_INST3(BeCmpInst, "cmp", mCmpKind, mLHS, mRHS); + DISPLAY_INST3(BeCmpInst, "cmp", mCmpKind, mLHS, mRHS); DISPLAY_INST1(BeObjectAccessCheckInst, "objectAccessCheck", mValue); case BeAllocaInst::TypeId: { @@ -2348,7 +2343,7 @@ String BeModule::ToString(BeFunction* wantFunc) } break; DISPLAY_INST1(BeAliasValueInst, "aliasvalue", mPtr); - DISPLAY_INST1(BeLifetimeStartInst, "lifetime.start", mPtr); + DISPLAY_INST1(BeLifetimeStartInst, "lifetime.start", mPtr); DISPLAY_INST1(BeLifetimeEndInst, "lifetime.end", mPtr); DISPLAY_INST1(BeLifetimeSoftEndInst, "lifetime.softEnd", mPtr); DISPLAY_INST2(BeLifetimeFenceInst, "lifetime.fence", mFenceBlock, mPtr); @@ -2383,7 +2378,7 @@ String BeModule::ToString(BeFunction* wantFunc) DISPLAY_INST0(BeFenceInst, "fence"); DISPLAY_INST0(BeStackSaveInst, "stackSave"); DISPLAY_INST1(BeStackRestoreInst, "stackRestore", mStackVal); - DISPLAY_INST3(BeGEPInst, "gep", mPtr, mIdx0, mIdx1); + DISPLAY_INST3(BeGEPInst, "gep", mPtr, mIdx0, mIdx1); //DISPLAY_INST1(BeBrInst, "br", mTargetBlock); case BeBrInst::TypeId: { @@ -2399,7 +2394,7 @@ String BeModule::ToString(BeFunction* wantFunc) break; DISPLAY_INST3(BeCondBrInst, "condbr", mCond, mTrueBlock, mFalseBlock); - + case BeRetInst::TypeId: { auto castedInst = (BeRetInst*)inst; @@ -2445,7 +2440,7 @@ String BeModule::ToString(BeFunction* wantFunc) if (arg.mNoAlias) str += " noalias"; if (arg.mNoCapture) - str += " nocapture"; + str += " nocapture"; if (arg.mDereferenceableSize != -1) str += StrFormat(" dereferenceable(%d)", arg.mDereferenceableSize); } @@ -2459,17 +2454,17 @@ String BeModule::ToString(BeFunction* wantFunc) auto castedInst = (BePhiInst*)inst; str += "phi "; dc.ToString(str, castedInst->mType); - str += " "; + str += " "; for (int argIdx = 0; argIdx < (int)castedInst->mIncoming.size(); argIdx++) { if (argIdx > 0) str += ", "; - str += "["; + str += "["; dc.ToString(str, castedInst->mIncoming[argIdx]->mValue); str += ", "; dc.ToString(str, castedInst->mIncoming[argIdx]->mBlock); str += "]"; - } + } } break; case BeSwitchInst::TypeId: @@ -2499,7 +2494,7 @@ String BeModule::ToString(BeFunction* wantFunc) str += " "; if (auto dbgVariable = castedInst->mDbgVar) - { + { switch (dbgVariable->mInitType) { case BfIRInitType_NotNeeded: str += " noinit"; break; @@ -2543,13 +2538,13 @@ String BeModule::ToString(BeFunction* wantFunc) BeDbgLoc* inlinedAt = inst->mDbgLoc->mDbgInlinedAt; while (inlinedAt != NULL) - { + { str += StrFormat("#%d", inlinedAt->mIdx); inlinedAt = inlinedAt->mDbgInlinedAt; } } str += "]"; - } + } } str += "\n"; @@ -2558,7 +2553,6 @@ String BeModule::ToString(BeFunction* wantFunc) str += "}\n"; - if (func->mDbgFunction != NULL) { str += " DbgFunc: "; @@ -2579,14 +2573,14 @@ String BeModule::ToString(BeFunction* wantFunc) str += "\n"; } - + for (auto& dbgLocPair : dbgLocs) { - auto dbgLoc = dbgLocPair.mValue; + auto dbgLoc = dbgLocPair.mValue; dc.ToString(str, dbgLocPair.mValue); str += "\n"; } - str += "\n"; + str += "\n"; return str; } @@ -2603,7 +2597,7 @@ void BeModule::Print(BeFunction* func) void BeModule::PrintValue(BeValue* val) { - BeDumpContext dumpCtx; + BeDumpContext dumpCtx; String str; dumpCtx.ToString(str, val); str += "\n"; @@ -2627,7 +2621,7 @@ void BeModule::DoInlining(BeFunction* func) if (func->mDidInlinePass) return; - // Set this true here so we don't recurse on the same function + // Set this true here so we don't recurse on the same function func->mDidInlinePass = true; int numHeadAllocas = 0; @@ -2637,11 +2631,11 @@ void BeModule::DoInlining(BeFunction* func) // From head to resume std::unordered_multimap inlineResumesMap; - - // From resume to head - std::unordered_multimap inlineHeadMap; - bool hadInlining = false; + // From resume to head + std::unordered_multimap inlineHeadMap; + + bool hadInlining = false; std::function& funcInlined)> _DoInlining; _DoInlining = [&](int& blockIdx, BeBlock* endBlock, std::unordered_set& funcInlined) @@ -2681,14 +2675,14 @@ void BeModule::DoInlining(BeFunction* func) auto _CheckBlock = [&](BeBlock* checkBlock) { for (auto inst : checkBlock->mInstructions) - { + { switch (inst->GetTypeId()) { case BeBrInst::TypeId: { auto castedInst = (BeBrInst*)inst; if (castedInst->mTargetBlock == beBlock) - { + { found = true; } } @@ -2698,7 +2692,7 @@ void BeModule::DoInlining(BeFunction* func) auto castedInst = (BeCondBrInst*)inst; if ((castedInst->mTrueBlock == beBlock) || (castedInst->mFalseBlock == beBlock)) - { + { found = true; } } @@ -2775,7 +2769,7 @@ void BeModule::DoInlining(BeFunction* func) inliner.mModule = this; inliner.mSrcFunc = inlineFunc; inliner.mDestFunc = func; - inliner.mCallInst = callInst; + inliner.mCallInst = callInst; if ((func->mDbgFunction != NULL) && (inlineFunc->mDbgFunction != NULL)) { @@ -2792,7 +2786,7 @@ void BeModule::DoInlining(BeFunction* func) destDbgGlobalVar->mInitType = dbgGlobalVar->mInitType; if (dbgGlobalVar->mValue != NULL) { - BF_ASSERT(BeValueDynCast(dbgGlobalVar->mValue) != NULL); + BF_ASSERT(BeValueDynCast(dbgGlobalVar->mValue) != NULL); destDbgGlobalVar->mValue = dbgGlobalVar->mValue; } else @@ -2834,7 +2828,7 @@ void BeModule::DoInlining(BeFunction* func) inlineResumesMap.insert(std::make_pair(headBlock, returnBlock)); inlineHeadMap.insert(std::make_pair(returnBlock, headBlock)); - std::vector destBlocks; + std::vector destBlocks; for (int argIdx = 0; argIdx < (int)callInst->mArgs.size(); argIdx++) { @@ -2884,7 +2878,7 @@ void BeModule::DoInlining(BeFunction* func) destAlloca->mArraySize = allocaInst->mArraySize; destAlloca->mAlign = allocaInst->mAlign; destAlloca->mNoChkStk = allocaInst->mNoChkStk; - destAlloca->mForceMem = allocaInst->mForceMem; + destAlloca->mForceMem = allocaInst->mForceMem; destAlloca->mName = allocaInst->mName; auto destBlock = func->mBlocks[0]; @@ -2926,7 +2920,7 @@ void BeModule::DoInlining(BeFunction* func) auto brInst = mAlloc.Alloc(); inliner.AddInst(brInst, retInst); - auto fenceInst = mAlloc.Alloc(); + auto fenceInst = mAlloc.Alloc(); fenceInst->mFenceBlock = beBlock; fenceInst->mPtr = callInst->mInlineResult; inliner.AddInst(fenceInst, retInst); @@ -2943,7 +2937,7 @@ void BeModule::DoInlining(BeFunction* func) /*if (callInst->mInlineResult != NULL) { - auto fenceInst = mAlloc.Alloc(); + auto fenceInst = mAlloc.Alloc(); fenceInst->mPtr = callInst->mInlineResult; beBlock->mInstructions.push_back(fenceInst); }*/ @@ -2983,7 +2977,6 @@ void BeModule::DoInlining(BeFunction* func) return lhsInlinePos->mIdx < rhsInlinePos->mIdx; }); }*/ - } void BeModule::DoInlining() @@ -3114,7 +3107,7 @@ void BeModule::ToString(StringImpl& str, BeType* type) return; case BeTypeCode_Function: { - auto funcType = (BeFunctionType*)type; + auto funcType = (BeFunctionType*)type; ToString(str, funcType->mReturnType); str += "("; for (int paramIdx = 0; paramIdx < (int)funcType->mParams.size(); paramIdx++) @@ -3158,19 +3151,19 @@ void BeModule::ToString(StringImpl& str, BeType* type) void BeModule::SetActiveFunction(BeFunction* function) { - mActiveFunction = function; + mActiveFunction = function; } BeArgument* BeModule::GetArgument(int argIdx) { - while ((int)argIdx >= mArgs.size()) + while ((int)argIdx >= mArgs.size()) { auto arg = mAlloc.Alloc(); arg->mModule = this; arg->mArgIdx = (int)mArgs.size(); mArgs.push_back(arg); } - + return mArgs[argIdx]; } @@ -3184,12 +3177,12 @@ BeBlock* BeModule::CreateBlock(const StringImpl& name) void BeModule::AddBlock(BeFunction* function, BeBlock* block) { block->mFunction = function; - function->mBlocks.push_back(block); + function->mBlocks.push_back(block); } void BeModule::RemoveBlock(BeFunction* function, BeBlock* block) { - bool didRemove = function->mBlocks.Remove(block); + bool didRemove = function->mBlocks.Remove(block); BF_ASSERT(didRemove); #ifdef _DEBUG for (auto inst : block->mInstructions) @@ -3223,7 +3216,7 @@ BeFunction* BeModule::CreateFunction(BeFunctionType* funcType, BfIRLinkageType l func->mLinkageType = linkageType; func->mParams.Resize(funcType->mParams.size()); mFunctions.push_back(func); - + #ifdef _DEBUG // It IS possible hit this, especially if we have multiple intrinsics mapping to 'malloc' for example //BF_ASSERT(mFunctionMap.TryAdd(name, func)); @@ -3257,12 +3250,12 @@ void BeModule::SetCurrentDebugLocation(int line, int column, BeMDNode* dbgScope, mCurDbgLoc->mLine = line; mCurDbgLoc->mColumn = column; mCurDbgLoc->mDbgScope = dbgScope; - mCurDbgLoc->mDbgInlinedAt = dbgInlinedAt; + mCurDbgLoc->mDbgInlinedAt = dbgInlinedAt; mCurDbgLoc->mIdx = mCurDbgLocIdx++; if ((dbgInlinedAt != NULL) && (!dbgInlinedAt->mHadInline)) { - dbgInlinedAt->mHadInline = true; + dbgInlinedAt->mHadInline = true; } mLastDbgLoc = mCurDbgLoc; @@ -3272,7 +3265,7 @@ BeDbgLoc* BeModule::DupDebugLocation(BeDbgLoc* dbgLoc) { if (dbgLoc == NULL) return dbgLoc; - + auto newDbgLoc = mAlloc.Alloc(); newDbgLoc->mLine = dbgLoc->mLine; newDbgLoc->mColumn = dbgLoc->mColumn; @@ -3324,7 +3317,7 @@ BeBitCastInst * BeModule::CreateBitCast(BeValue* value, BeType* toType) { auto inst = mAlloc.Alloc(); inst->mValue = value; - inst->mToType = toType; + inst->mToType = toType; AddInst(inst); return inst; } @@ -3364,7 +3357,7 @@ BeAllocaInst* BeModule::CreateAlloca(BeType* type) } BeLoadInst* BeModule::CreateLoad(BeValue* value, bool isVolatile) -{ +{ auto inst = mAlloc.Alloc(); inst->mTarget = value; inst->mIsVolatile = isVolatile; @@ -3408,7 +3401,7 @@ BeStoreInst* BeModule::CreateAlignedStore(BeValue* val, BeValue* ptr, int alignm } BeGEPInst* BeModule::CreateGEP(BeValue* ptr, BeValue* idx0, BeValue* idx1) -{ +{ #ifdef _DEBUG BF_ASSERT(ptr->GetType()->IsPointer()); #endif @@ -3416,10 +3409,10 @@ BeGEPInst* BeModule::CreateGEP(BeValue* ptr, BeValue* idx0, BeValue* idx1) auto inst = mAlloc.Alloc(); inst->mPtr = ptr; inst->mIdx0 = idx0; - inst->mIdx1 = idx1; - AddInst(inst); - -#ifdef _DEBUG + inst->mIdx1 = idx1; + AddInst(inst); + +#ifdef _DEBUG inst->GetType(); #endif @@ -3469,11 +3462,11 @@ BeSetRetInst* BeModule::CreateSetRet(BeValue* value, int returnTypeId) } BeCallInst* BeModule::CreateCall(BeValue* func, const SizedArrayImpl& args) -{ +{ auto inst = mOwnedValues.Alloc(); inst->mFunc = func; if (!args.IsEmpty()) - { + { inst->mArgs.resize(args.size()); for (int i = 0; i < (int)args.size(); i++) inst->mArgs[i].mValue = args[i]; @@ -3509,8 +3502,8 @@ BeConstant* BeModule::GetConstant(BeType* type, int64 intVal) break; default: constant->mInt64 = intVal; - } - + } + return constant; } @@ -3524,16 +3517,16 @@ BeConstant* BeModule::GetConstant(BeType* type, bool boolVal) BeConstant* BeModule::GetConstantNull(BePointerType* type) { - auto constant = mAlloc.Alloc(); + auto constant = mAlloc.Alloc(); if (type == NULL) constant->mType = mContext->GetPrimitiveType(BeTypeCode_NullPtr); else - constant->mType = type; + constant->mType = type; return constant; } BeDbgReferenceType * BeDbgModule::CreateReferenceType(BeDbgType* elementType) -{ +{ BeDbgType* useType = elementType->FindDerivedType(BeDbgReferenceType::TypeId); if (useType == NULL) { @@ -3552,7 +3545,7 @@ void BeDbgModule::HashContent(BeHashContext & hashCtx) hashCtx.MixinStr(mDirectory); hashCtx.MixinStr(mProducer); - BeDumpContext dc; + BeDumpContext dc; String lhsName; String rhsName; @@ -3560,12 +3553,12 @@ void BeDbgModule::HashContent(BeHashContext & hashCtx) { auto _GetName = [&](BeDbgFunction* func, String& str) { - if (!func->mLinkageName.IsEmpty()) - str.Append(func->mLinkageName); - else - dc.ToString(str, func); + if (!func->mLinkageName.IsEmpty()) + str.Append(func->mLinkageName); + else + dc.ToString(str, func); }; - + Array unrefFuncs; for (auto dbgFunc : mFuncs) { @@ -3574,12 +3567,12 @@ void BeDbgModule::HashContent(BeHashContext & hashCtx) } std::sort(unrefFuncs.begin(), unrefFuncs.end(), [&](BeDbgFunction* lhs, BeDbgFunction* rhs) - { + { lhsName.Clear(); _GetName(lhs, lhsName); rhsName.Clear(); - _GetName(rhs, rhsName); + _GetName(rhs, rhsName); int cmp = String::Compare(lhsName, rhsName, false); if (cmp != 0) @@ -3600,7 +3593,7 @@ void BeDbgModule::HashContent(BeHashContext & hashCtx) if (lhs->mLine != rhs->mLine) return lhs->mLine < rhs->mLine; - + return lhs->mIdx < rhs->mIdx; }); @@ -3636,4 +3629,4 @@ void BeDbgModule::HashContent(BeHashContext & hashCtx) for (auto globalVar : mGlobalVariables) globalVar->HashReference(hashCtx); } -} +} \ No newline at end of file diff --git a/IDEHelper/Backend/BeModule.h b/IDEHelper/Backend/BeModule.h index 066f1062..637e527d 100644 --- a/IDEHelper/Backend/BeModule.h +++ b/IDEHelper/Backend/BeModule.h @@ -68,7 +68,7 @@ public: virtual void Visit(BeValue* beValue) {} virtual void Visit(BeBlock* beBlock) {} - virtual void Visit(BeArgument* beArgument) {} + virtual void Visit(BeArgument* beArgument) {} virtual void Visit(BeInst* beInst) {} virtual void Visit(BeNopInst* nopInst) {} virtual void Visit(BeUnreachableInst* unreachableInst) {} @@ -76,10 +76,10 @@ public: virtual void Visit(BeUndefValueInst* undefValue) {} virtual void Visit(BeExtractValueInst* extractValue) {} virtual void Visit(BeInsertValueInst* insertValue) {} - virtual void Visit(BeNumericCastInst* castInst) {} - virtual void Visit(BeBitCastInst* castInst) {} - virtual void Visit(BeNegInst* negInst) {} - virtual void Visit(BeNotInst* notInst) {} + virtual void Visit(BeNumericCastInst* castInst) {} + virtual void Visit(BeBitCastInst* castInst) {} + virtual void Visit(BeNegInst* negInst) {} + virtual void Visit(BeNotInst* notInst) {} virtual void Visit(BeBinaryOpInst* binaryOpInst) {} virtual void Visit(BeFenceInst* fenceInst) {} virtual void Visit(BeStackSaveInst* stackSaveInst) {} @@ -108,8 +108,8 @@ public: virtual void Visit(BeSwitchInst* switchInst) {} virtual void Visit(BeRetInst* retInst) {} virtual void Visit(BeCallInst* callInst) {} - - //virtual void Visit(BeDbgVariable* dbgVariable) {} + + //virtual void Visit(BeDbgVariable* dbgVariable) {} virtual void Visit(BeDbgDeclareInst* dbgDeclareInst) {} }; @@ -122,15 +122,15 @@ class BeInliner : public BeValueVisitor public: BumpAllocator* mAlloc; OwnedVector* mOwnedValueVec; - Dictionary mValueMap; + Dictionary mValueMap; Dictionary mInlinedAtMap; - + BeModule* mModule; BeFunction* mSrcFunc; BeFunction* mDestFunc; - BeCallInst* mCallInst; - BeBlock* mDestBlock; - BeDbgLoc* mSrcDbgLoc; + BeCallInst* mCallInst; + BeBlock* mDestBlock; + BeDbgLoc* mSrcDbgLoc; BeDbgLoc* mDestDbgLoc; public: @@ -158,7 +158,7 @@ public: auto inst = mOwnedValueVec->Alloc(); AddInst(inst, srcInst); return inst; - } + } virtual void Visit(BeValue* beValue) override; virtual void Visit(BeBlock* beBlock) override; @@ -202,7 +202,7 @@ public: virtual void Visit(BeSwitchInst* switchInst) override; virtual void Visit(BeRetInst* retInst) override; virtual void Visit(BeCallInst* callInst) override; - + virtual void Visit(BeDbgDeclareInst* dbgDeclareInst) override; }; @@ -212,7 +212,7 @@ public: int mRefCount; #ifdef _DEBUG bool mLifetimeEnded; - bool mWasRemoved; + bool mWasRemoved; BeValue() { mLifetimeEnded = false; @@ -228,12 +228,11 @@ public: virtual ~BeValue() { - } static const int TypeId = 0; virtual void Accept(BeValueVisitor* beVisitor) = 0; - virtual bool TypeIdIsA(int typeId) = 0; + virtual bool TypeIdIsA(int typeId) = 0; virtual BeValue* DynCast(int typeId) { if (TypeIdIsA(typeId)) @@ -246,7 +245,6 @@ public: } virtual int GetTypeId() { return TypeId; } - public: virtual BeType* GetType() { @@ -255,7 +253,6 @@ public: virtual void SetName(const StringImpl& name) { - } }; @@ -310,8 +307,8 @@ class BeConstant : public BeValue { public: BE_VALUE_TYPE(BeConstant, BeValue); - - BeType* mType; + + BeType* mType; union { bool mBool; @@ -325,7 +322,7 @@ public: uint8 mUInt8; uint8 mChar; uint32 mChar32; - double mDouble; + double mDouble; //BeType* mTypeParam; //BeGlobalVariable* mGlobalVar; BeConstant* mTarget; @@ -338,7 +335,7 @@ public: return false; } - virtual BeType* GetType(); + virtual BeType* GetType(); virtual void GetData(BeConstData& data); virtual void HashContent(BeHashContext& hashCtx) override; }; @@ -365,7 +362,7 @@ class BeGEP1Constant : public BeConstant { public: BE_VALUE_TYPE(BeGEP1Constant, BeConstant); - int mIdx0; + int mIdx0; virtual BeType* GetType(); @@ -373,14 +370,14 @@ public: { hashCtx.Mixin(TypeId); mTarget->HashReference(hashCtx); - hashCtx.Mixin(mIdx0); + hashCtx.Mixin(mIdx0); } }; class BeGEP2Constant : public BeConstant { public: - BE_VALUE_TYPE(BeGEP2Constant, BeConstant); + BE_VALUE_TYPE(BeGEP2Constant, BeConstant); int mIdx0; int mIdx1; @@ -388,7 +385,7 @@ public: virtual void HashContent(BeHashContext& hashCtx) override { - hashCtx.Mixin(TypeId); + hashCtx.Mixin(TypeId); mTarget->HashReference(hashCtx); hashCtx.Mixin(mIdx0); hashCtx.Mixin(mIdx1); @@ -399,7 +396,7 @@ class BeExtractValueConstant : public BeConstant { public: BE_VALUE_TYPE(BeExtractValueConstant, BeConstant); - int mIdx0; + int mIdx0; virtual BeType* GetType(); @@ -407,14 +404,14 @@ public: { hashCtx.Mixin(TypeId); mTarget->HashReference(hashCtx); - hashCtx.Mixin(mIdx0); + hashCtx.Mixin(mIdx0); } }; class BeStructConstant : public BeConstant { public: - BE_VALUE_TYPE(BeStructConstant, BeConstant); + BE_VALUE_TYPE(BeStructConstant, BeConstant); SizedArray mMemberValues; @@ -434,25 +431,25 @@ class BeUndefConstant : public BeConstant { public: BE_VALUE_TYPE(BeUndefConstant, BeConstant); - + virtual void HashContent(BeHashContext& hashCtx) override { hashCtx.Mixin(mType); - hashCtx.Mixin(TypeId); + hashCtx.Mixin(TypeId); } }; class BeStringConstant : public BeConstant { public: - BE_VALUE_TYPE(BeStringConstant, BeConstant); + BE_VALUE_TYPE(BeStringConstant, BeConstant); String mString; virtual void HashContent(BeHashContext& hashCtx) override { hashCtx.Mixin(TypeId); - hashCtx.MixinStr(mString); + hashCtx.MixinStr(mString); } }; @@ -471,8 +468,8 @@ public: int mAlign; bool mUnnamedAddr; - virtual BeType* GetType(); - + virtual BeType* GetType(); + virtual void HashContent(BeHashContext& hashCtx) override { hashCtx.Mixin(TypeId); @@ -485,12 +482,12 @@ public: hashCtx.Mixin(mIsTLS); hashCtx.Mixin(mAlign); hashCtx.Mixin(mUnnamedAddr); - } + } virtual void GetData(BeConstData& data) override { data.mConsts.Add({ (int)data.mData.size(), this }); - data.mData.Insert(data.mData.size(), (uint8)0, 8); + data.mData.Insert(data.mData.size(), (uint8)0, 8); } }; @@ -522,13 +519,13 @@ class BeIntrinsic : public BeValue { public: BE_VALUE_TYPE(BeIntrinsic, BeValue); - + String mName; BfIRIntrinsic mKind; BeType* mReturnType; BeIntrinsic() - { + { mReturnType = NULL; } @@ -536,7 +533,7 @@ public: { hashCtx.Mixin(TypeId); hashCtx.Mixin(mKind); - } + } }; class BeFunction : public BeConstant @@ -544,15 +541,15 @@ class BeFunction : public BeConstant public: BE_VALUE_TYPE(BeFunction, BeConstant); - BeModule* mModule; + BeModule* mModule; #ifdef _DEBUG StringT<256> mName; #else String mName; #endif - BfIRLinkageType mLinkageType; + BfIRLinkageType mLinkageType; bool mIsVarReturn; - bool mAlwaysInline; + bool mAlwaysInline; bool mNoUnwind; bool mUWTable; bool mNoReturn; @@ -561,10 +558,10 @@ public: bool mIsDLLExport; bool mIsDLLImport; BfIRCallingConv mCallingConv; - Array mBlocks; + Array mBlocks; Array mParams; BeDbgFunction* mDbgFunction; - BeGlobalVariable* mRemapBindVar; + BeGlobalVariable* mRemapBindVar; public: BeFunction() @@ -575,15 +572,15 @@ public: mDbgFunction = NULL; mIsVarReturn = false; mAlwaysInline = false; - mDidInlinePass = false; + mDidInlinePass = false; mNoUnwind = false; mUWTable = false; mNoReturn = false; mNoFramePointerElim = false; mIsDLLExport = false; mIsDLLImport = false; - mRemapBindVar = NULL; - } + mRemapBindVar = NULL; + } BeFunctionType* GetFuncType() { @@ -600,7 +597,7 @@ public: { return (!mParams.IsEmpty()) && (mParams[0].mStructRet); } - + virtual void HashContent(BeHashContext& hashCtx) override; }; @@ -614,12 +611,11 @@ public: BeFunction* mFunction; public: - bool IsEmpty(); + bool IsEmpty(); virtual void HashContent(BeHashContext& hashCtx) override; }; - ////////////////////////////////////////////////////////////////////////// class BeInst : public BeValue @@ -630,8 +626,8 @@ public: BeBlock* mParentBlock; const char* mName; BeDbgLoc* mDbgLoc; - -public: + +public: BeContext* GetContext(); BeModule* GetModule(); @@ -640,7 +636,7 @@ public: return GetType() != NULL; } - virtual void SetName(const StringImpl& name) override; + virtual void SetName(const StringImpl& name) override; BeInst() { @@ -650,7 +646,7 @@ public: } virtual void HashInst(BeHashContext& hashCtx) = 0; - virtual void HashContent(BeHashContext& hashCtx) override; + virtual void HashContent(BeHashContext& hashCtx) override; }; class BeNopInst : public BeInst @@ -707,7 +703,7 @@ class BeExtractValueInst : public BeInst public: BE_VALUE_TYPE(BeExtractValueInst, BeInst); - BeValue* mAggVal; + BeValue* mAggVal; int mIdx; virtual BeType* GetType() override; @@ -769,7 +765,7 @@ public: BeValue* mValue; BeType* mToType; - + virtual BeType* GetType() override; virtual void HashInst(BeHashContext& hashCtx) override @@ -777,7 +773,7 @@ public: hashCtx.Mixin(TypeId); mValue->HashReference(hashCtx); mToType->HashReference(hashCtx); - } + } }; class BeNegInst : public BeInst @@ -785,7 +781,7 @@ class BeNegInst : public BeInst public: BE_VALUE_TYPE(BeNegInst, BeInst); - BeValue* mValue; + BeValue* mValue; virtual BeType* GetType() override; virtual void HashInst(BeHashContext& hashCtx) override @@ -823,15 +819,15 @@ enum BeBinaryOpKind BeBinaryOpKind_BitwiseAnd, BeBinaryOpKind_BitwiseOr, BeBinaryOpKind_ExclusiveOr, - BeBinaryOpKind_LeftShift, - BeBinaryOpKind_RightShift, + BeBinaryOpKind_LeftShift, + BeBinaryOpKind_RightShift, BeBinaryOpKind_ARightShift, BeBinaryOpKind_Equality, BeBinaryOpKind_InEquality, BeBinaryOpKind_GreaterThan, BeBinaryOpKind_LessThan, BeBinaryOpKind_GreaterThanOrEqual, - BeBinaryOpKind_LessThanOrEqual, + BeBinaryOpKind_LessThanOrEqual, }; class BeBinaryOpInst : public BeInst @@ -844,7 +840,7 @@ public: BeValue* mLHS; BeValue* mRHS; - virtual BeType* GetType() override; + virtual BeType* GetType() override; virtual void HashInst(BeHashContext& hashCtx) override { @@ -920,7 +916,7 @@ public: bool mForceMem; public: - virtual BeType* GetType() override; + virtual BeType* GetType() override; virtual void HashInst(BeHashContext& hashCtx) override { @@ -1034,7 +1030,7 @@ public: virtual void HashInst(BeHashContext& hashCtx) override { - hashCtx.Mixin(TypeId); + hashCtx.Mixin(TypeId); } }; @@ -1043,7 +1039,7 @@ class BeValueScopeRetainInst : public BeInst public: BE_VALUE_TYPE(BeValueScopeRetainInst, BeInst); - BeValue* mValue; + BeValue* mValue; virtual void HashInst(BeHashContext& hashCtx) override { @@ -1054,7 +1050,7 @@ public: class BeValueScopeEndInst : public BeInst { -public: +public: BE_VALUE_TYPE(BeValueScopeEndInst, BeInst); BeValueScopeStartInst* mScopeStart; @@ -1077,7 +1073,7 @@ public: bool mIsVolatile; public: - virtual BeType* GetType() override; + virtual BeType* GetType() override; virtual void HashInst(BeHashContext& hashCtx) override { @@ -1144,7 +1140,7 @@ public: virtual void HashInst(BeHashContext& hashCtx) override { - hashCtx.Mixin(TypeId); + hashCtx.Mixin(TypeId); } }; @@ -1155,7 +1151,7 @@ public: virtual void HashInst(BeHashContext& hashCtx) override { - hashCtx.Mixin(TypeId); + hashCtx.Mixin(TypeId); } virtual BeType* GetType() override @@ -1278,7 +1274,7 @@ class BeSwitchCase { public: BeConstant* mValue; - BeBlock* mBlock; + BeBlock* mBlock; }; class BeSwitchInst : public BeInst @@ -1338,7 +1334,7 @@ public: bool mStructRet; bool mZExt; bool mNoAlias; - bool mNoCapture; + bool mNoCapture; Arg() { mValue = NULL; @@ -1352,14 +1348,14 @@ public: }; public: - BE_VALUE_TYPE(BeCallInst, BeInst); + BE_VALUE_TYPE(BeCallInst, BeInst); BeValue* mInlineResult; BeValue* mFunc; SizedArray mArgs; BfIRCallingConv mCallingConv; bool mNoReturn; - bool mTailCall; + bool mTailCall; virtual BeType* GetType() override; @@ -1369,7 +1365,7 @@ public: mFunc = NULL; mCallingConv = BfIRCallingConv_CDecl; mNoReturn = false; - mTailCall = false; + mTailCall = false; } virtual void HashInst(BeHashContext& hashCtx) override @@ -1379,7 +1375,7 @@ public: mInlineResult->HashReference(hashCtx); mFunc->HashReference(hashCtx); for (auto& arg : mArgs) - { + { arg.mValue->HashReference(hashCtx); hashCtx.Mixin(arg.mStructRet); hashCtx.Mixin(arg.mZExt); @@ -1388,7 +1384,7 @@ public: } hashCtx.Mixin(mCallingConv); hashCtx.Mixin(mNoReturn); - hashCtx.Mixin(mTailCall); + hashCtx.Mixin(mTailCall); } bool HasStructRet() @@ -1405,9 +1401,9 @@ public: BE_VALUE_TYPE(BeComptimeError, BeInst); public: - int mError; + int mError; -public: +public: virtual void HashInst(BeHashContext& hashCtx) override { hashCtx.Mixin(TypeId); @@ -1424,7 +1420,7 @@ public: int mTypeId; BeType* mResultType; -public: +public: virtual BeType* GetType() override { return mResultType; @@ -1476,7 +1472,7 @@ public: } virtual void HashInst(BeHashContext& hashCtx) override - { + { hashCtx.Mixin(TypeId); mValue->HashReference(hashCtx); hashCtx.Mixin(mTypeId); @@ -1554,7 +1550,7 @@ public: struct BeDumpContext { -public: +public: Dictionary mValueNameMap; Dictionary mSeenNames; @@ -1588,7 +1584,6 @@ public: bool mIsValue; virtual void HashInst(BeHashContext& hashCtx) override; - }; class BeMDNode : public BeValue @@ -1599,7 +1594,6 @@ public: public: virtual ~BeMDNode() { - } virtual void HashContent(BeHashContext& hashCtx) override @@ -1620,20 +1614,20 @@ public: int mColumn; BeMDNode* mDbgScope; BeDbgLoc* mDbgInlinedAt; - int mIdx; + int mIdx; bool mHadInline; public: BeDbgLoc() - { + { } - int GetInlineDepth(); + int GetInlineDepth(); int GetInlineMatchDepth(BeDbgLoc* other); BeDbgLoc* GetInlinedAt(int idx = 0); BeDbgLoc* GetRoot(); BeDbgFunction* GetDbgFunc(); - BeDbgFile* GetDbgFile(); + BeDbgFile* GetDbgFile(); virtual void HashContent(BeHashContext& hashCtx) override { @@ -1645,7 +1639,7 @@ public: else hashCtx.Mixin(-1); if (mDbgInlinedAt != NULL) - mDbgInlinedAt->HashReference(hashCtx); + mDbgInlinedAt->HashReference(hashCtx); } }; @@ -1660,7 +1654,7 @@ public: BeBlock* mLastBeBlock; int mId; - virtual void HashContent(BeHashContext& hashCtx) override; + virtual void HashContent(BeHashContext& hashCtx) override; }; class BeDbgNamespace : public BeMDNode @@ -1687,16 +1681,16 @@ public: public: int mTypeId; - + BeDbgTypeId() { mTypeId = -1; } - + virtual void HashContent(BeHashContext& hashCtx) override { hashCtx.Mixin(TypeId); - hashCtx.Mixin(mTypeId); + hashCtx.Mixin(mTypeId); } }; @@ -1704,7 +1698,7 @@ class BeDbgType : public BeMDNode { public: BE_VALUE_TYPE(BeDbgType, BeMDNode); - + public: int mSize; int mAlign; @@ -1744,7 +1738,7 @@ public: BE_VALUE_TYPE(BeDbgBasicType, BeDbgType); public: - String mName; + String mName; int mEncoding; virtual void HashContent(BeHashContext& hashCtx) override @@ -1763,7 +1757,7 @@ public: BE_VALUE_TYPE(BeDbgArrayType, BeDbgType); public: - BeDbgType* mElement; + BeDbgType* mElement; int mNumElements; virtual void HashContent(BeHashContext& hashCtx) override @@ -1772,7 +1766,7 @@ public: hashCtx.Mixin(mSize); hashCtx.Mixin(mAlign); hashCtx.Mixin(mNumElements); - mElement->HashReference(hashCtx); + mElement->HashReference(hashCtx); } }; @@ -1824,10 +1818,10 @@ public: class BeDbgPointerType : public BeDbgType { public: - BE_VALUE_TYPE(BeDbgPointerType, BeDbgType); + BE_VALUE_TYPE(BeDbgPointerType, BeDbgType); public: - BeDbgType* mElement; + BeDbgType* mElement; virtual void HashContent(BeHashContext& hashCtx) override { @@ -1862,7 +1856,7 @@ public: int mFlags; int mOffset; bool mIsStatic; - BeValue* mStaticValue; + BeValue* mStaticValue; public: BeDbgStructMember() @@ -1895,7 +1889,7 @@ public: public: BeDbgType* mReturnType; Array mParams; - + public: virtual void HashContent(BeHashContext& hashCtx) override { @@ -1954,9 +1948,9 @@ public: Kind_SymbolAddr }; - Kind mKind; - X64CPURegister mReg; - int mOfs; + Kind mKind; + X64CPURegister mReg; + int mOfs; public: BeDbgVariableLoc() @@ -1974,7 +1968,7 @@ public: public: String mName; - BeMDNode* mType; + BeMDNode* mType; BeValue* mValue; int mParamNum; BfIRInitType mInitType; @@ -1984,13 +1978,13 @@ public: BeDbgLoc* mDeclDbgLoc; BeDbgVariableLoc mPrimaryLoc; - BeDbgVariableLoc mSavedLoc; + BeDbgVariableLoc mSavedLoc; int mDeclStart; - int mDeclEnd; - int mDeclMCBlockId; + int mDeclEnd; + int mDeclMCBlockId; bool mDeclLifetimeExtend; bool mDbgLifeEnded; - bool mIsValue; // Value vs Addr + bool mIsValue; // Value vs Addr Array mSavedRanges; Array mGaps; @@ -2027,7 +2021,7 @@ public: if (mScope != NULL) mScope->HashReference(hashCtx); if (mDeclDbgLoc != NULL) - mDeclDbgLoc->HashReference(hashCtx); + mDeclDbgLoc->HashReference(hashCtx); // The others only get filled in after generation -- not part of hash } @@ -2065,8 +2059,8 @@ public: bool mIncludedAsMember; int mFlags; int mVK; - int mVIndex; - + int mVIndex; + Array mVariables; int mPrologSize; int mCodeLen; @@ -2089,9 +2083,9 @@ public: mIsLocalToUnit = false; mVK = -1; mVIndex = -1; - mIsStaticMethod = true; + mIsStaticMethod = true; mIncludedAsMember = false; - mPrologSize = 0; + mPrologSize = 0; mCodeLen = -1; mCvTypeId = -1; mCvFuncId = -1; @@ -2128,7 +2122,7 @@ public: return ((mVariables.size() > 0) && (mVariables[0]->mName == "this")); }*/ } - + virtual void HashContent(BeHashContext& hashCtx) override; }; @@ -2166,7 +2160,7 @@ public: public: BeDbgStructType() { - mScope = NULL; + mScope = NULL; mDerivedFrom = NULL; mIsStatic = false; mIsFullyDefined = false; @@ -2236,12 +2230,12 @@ public: BE_VALUE_TYPE(BeDbgFile, BeMDNode); public: - String mFileName; + String mFileName; String mDirectory; Val128 mMD5Hash; - int mIdx; + int mIdx; - void ToString(String& str); + void ToString(String& str); void GetFilePath(String& outStr); virtual void HashContent(BeHashContext& hashCtx) override @@ -2295,7 +2289,7 @@ public: String mFileName; String mDirectory; String mProducer; - + OwnedVector mFiles; OwnedVector mNamespaces; OwnedVector mGlobalVariables; @@ -2303,7 +2297,7 @@ public: OwnedVector mTypes; Array mFuncs; // Does not include methods in structs - virtual void HashContent(BeHashContext& hashCtx) override; + virtual void HashContent(BeHashContext& hashCtx) override; BeDbgReferenceType* CreateReferenceType(BeDbgType* dbgType); }; @@ -2330,18 +2324,18 @@ public: int mInsertPos; BeDbgLoc* mCurDbgLoc; BeDbgLoc* mPrevDbgLocInline; - BeDbgLoc* mLastDbgLoc; - Array mArgs; - Array mFunctions; + BeDbgLoc* mLastDbgLoc; + Array mArgs; + Array mFunctions; Dictionary mFunctionMap; int mCurDbgLocIdx; - int mCurLexBlockId; + int mCurLexBlockId; BeDbgModule* mDbgModule; CeMachine* mCeMachine; -public: - void AddInst(BeInst* inst); +public: + void AddInst(BeInst* inst); static void ToString(StringImpl& str, BeType* type); static void StructToString(StringImpl& str, BeStructType* type); @@ -2362,7 +2356,7 @@ public: } public: - BeModule(const StringImpl& moduleName, BeContext* context); + BeModule(const StringImpl& moduleName, BeContext* context); ~BeModule(); void Hash(BeHashContext& hashCtx); @@ -2375,11 +2369,11 @@ public: void DoInlining(BeFunction* func); void DoInlining(); - static BeCmpKind InvertCmp(BeCmpKind cmpKind); - static BeCmpKind SwapCmpSides(BeCmpKind cmpKind); + static BeCmpKind InvertCmp(BeCmpKind cmpKind); + static BeCmpKind SwapCmpSides(BeCmpKind cmpKind); void SetActiveFunction(BeFunction* function); BeArgument* GetArgument(int arg); - BeBlock* CreateBlock(const StringImpl& name); + BeBlock* CreateBlock(const StringImpl& name); void AddBlock(BeFunction* function, BeBlock* block); void RemoveBlock(BeFunction* function, BeBlock* block); BeBlock* GetInsertBlock(); @@ -2395,9 +2389,9 @@ public: /// BeNopInst* CreateNop(); BeUndefValueInst* CreateUndefValue(BeType* type); - BeNumericCastInst* CreateNumericCast(BeValue* value, BeType* toType, bool valSigned, bool toSigned); + BeNumericCastInst* CreateNumericCast(BeValue* value, BeType* toType, bool valSigned, bool toSigned); BeBitCastInst* CreateBitCast(BeValue* value, BeType* toType);; - BeCmpInst* CreateCmp(BeCmpKind cmpKind, BeValue* lhs, BeValue* rhs); + BeCmpInst* CreateCmp(BeCmpKind cmpKind, BeValue* lhs, BeValue* rhs); BeBinaryOpInst* CreateBinaryOp(BeBinaryOpKind opKind, BeValue* lhs, BeValue* rhs, BfOverflowCheckKind overflowCheckKind = BfOverflowCheckKind_None); BeAllocaInst* CreateAlloca(BeType* type); @@ -2407,19 +2401,17 @@ public: BeStoreInst* CreateAlignedStore(BeValue* val, BeValue* ptr, int alignment, bool isVolatile); BeGEPInst* CreateGEP(BeValue* ptr, BeValue* idx0, BeValue* idx1); - BeBrInst* CreateBr(BeBlock* block); + BeBrInst* CreateBr(BeBlock* block); BeCondBrInst* CreateCondBr(BeValue* cond, BeBlock* trueBlock, BeBlock* falseBlock); BeRetInst* CreateRetVoid(); - BeRetInst* CreateRet(BeValue* value); + BeRetInst* CreateRet(BeValue* value); BeSetRetInst* CreateSetRet(BeValue* value, int returnTypeId); BeCallInst* CreateCall(BeValue* func, const SizedArrayImpl& args); - - BeConstant* GetConstant(BeType* type, double floatVal); BeConstant* GetConstant(BeType* type, int64 intVal); BeConstant* GetConstant(BeType* type, bool boolVal); - BeConstant* GetConstantNull(BePointerType* type); + BeConstant* GetConstantNull(BePointerType* type); }; NS_BF_END \ No newline at end of file