From ffc45dd5754e87bcd3c78380bac10ae7a10f66dd Mon Sep 17 00:00:00 2001 From: Mike Danes Date: Sun, 8 May 2016 20:41:31 +0300 Subject: [PATCH] Define LSRA's RefType enum via macros --- src/jit/lsra.cpp | 69 ++++++++++++++++------------------------- src/jit/lsra.h | 17 ++-------- src/jit/lsra_reftypes.h | 21 +++++++++++++ 3 files changed, 50 insertions(+), 57 deletions(-) create mode 100644 src/jit/lsra_reftypes.h diff --git a/src/jit/lsra.cpp b/src/jit/lsra.cpp index 091b4c605c..9458d8c53b 100644 --- a/src/jit/lsra.cpp +++ b/src/jit/lsra.cpp @@ -280,43 +280,6 @@ bool isSingleRegister(regMaskTP regMask) return (regMask != RBM_NONE && genMaxOneBit(regMask)); } -#ifdef DEBUG -// TODO-Cleanup: Consider using a #include file with custom #defines for both defining -// the enum as well as the string array -const char * refTypeNames [RefTypeBound]; -const char* shortRefTypeNames[RefTypeBound]; -void initRefTypeNames() -{ - refTypeNames[RefTypeInvalid] = "RefTypeInvalid"; - refTypeNames[RefTypeDef] = "RefTypeDef"; - refTypeNames[RefTypeUse] = "RefTypeUse"; - refTypeNames[RefTypeKill] = "RefTypeKill"; - refTypeNames[RefTypeBB] = "RefTypeBB"; - refTypeNames[RefTypeFixedReg] = "RefTypeFixedReg"; - refTypeNames[RefTypeParamDef] = "RefTypeParamDef"; - refTypeNames[RefTypeDummyDef] = "RefTypeDummyDef"; - refTypeNames[RefTypeExpUse] = "RefTypeExpUse"; - refTypeNames[RefTypeZeroInit] = "RefTypeZeroInit"; - refTypeNames[RefTypeUpperVectorSaveDef] = "RefTypeUpperVectorSaveDef"; - refTypeNames[RefTypeUpperVectorSaveUse] = "RefTypeUpperVectorSaveUse"; - refTypeNames[RefTypeKillGCRefs] = "RefTypeKillGCRefs"; - - shortRefTypeNames[RefTypeInvalid] = "Invl"; - shortRefTypeNames[RefTypeDef] = "Def "; - shortRefTypeNames[RefTypeUse] = "Use "; - shortRefTypeNames[RefTypeKill] = "Kill"; - shortRefTypeNames[RefTypeBB] = "BB "; - shortRefTypeNames[RefTypeFixedReg] = "Fixd"; - shortRefTypeNames[RefTypeParamDef] = "Parm"; - shortRefTypeNames[RefTypeDummyDef] = "DDef"; - shortRefTypeNames[RefTypeExpUse] = "ExpU"; - shortRefTypeNames[RefTypeZeroInit] = "Zero"; - shortRefTypeNames[RefTypeUpperVectorSaveDef] = "UVSv"; - shortRefTypeNames[RefTypeUpperVectorSaveUse] = "UVRs"; - shortRefTypeNames[RefTypeKillGCRefs] = "KlGC"; -} -#endif // DEBUG - /***************************************************************************** * Inline functions for RegRecord *****************************************************************************/ @@ -1001,7 +964,6 @@ LinearScan::LinearScan(Compiler * theCompiler) intervalCount = 0; maxNodeLocation = 0; activeRefPosition = nullptr; - initRefTypeNames(); // Get the value of the environment variable that controls stress for register allocation lsraStressMask = JitConfig.JitStressRegs(); @@ -8922,6 +8884,28 @@ void dumpRegMask(regMaskTP regs) } } +static const char* getRefTypeName(RefType refType) +{ + switch (refType) + { +#define DEF_REFTYPE(memberName, memberValue, shortName) case memberName: return #memberName; +#include "lsra_reftypes.h" +#undef DEF_REFTYPE + default: return nullptr; + } +} + +static const char* getRefTypeShortName(RefType refType) +{ + switch (refType) + { +#define DEF_REFTYPE(memberName, memberValue, shortName) case memberName: return shortName; +#include "lsra_reftypes.h" +#undef DEF_REFTYPE + default: return nullptr; + } +} + void RefPosition::dump() { printf("#%-3u", nextRefPosition->rpNum); - printf(" %s ", refTypeNames[refType]); + printf(" %s ", getRefTypeName(refType)); if (this->isPhysRegRef) this->getReg()->tinyDump(); @@ -10191,20 +10175,20 @@ LinearScan::dumpRefPositionShort(RefPosition* refPosition, BasicBlock* currentBl delayChar = 'D'; } } - printf(" %s%c%c ", shortRefTypeNames[refPosition->refType], lastUseChar, delayChar); + printf(" %s%c%c ", getRefTypeShortName(refPosition->refType), lastUseChar, delayChar); } else if (refPosition->isPhysRegRef) { RegRecord* regRecord = refPosition->getReg(); printf(regNameFormat, getRegName(regRecord->regNum)); - printf(" %s ", shortRefTypeNames[refPosition->refType]); + printf(" %s ", getRefTypeShortName(refPosition->refType)); } else { assert(refPosition->refType == RefTypeKillGCRefs); // There's no interval or reg name associated with this. printf(regNameFormat, " "); - printf(" %s ", shortRefTypeNames[refPosition->refType]); + printf(" %s ", getRefTypeShortName(refPosition->refType)); } } @@ -10532,7 +10516,6 @@ LinearScan::verifyFinalAllocation() break; case RefTypeInvalid: - case RefTypeBound: // for these 'currentRefPosition->refType' values, No action to take break; } diff --git a/src/jit/lsra.h b/src/jit/lsra.h index 079c7ebf5b..caef054c81 100644 --- a/src/jit/lsra.h +++ b/src/jit/lsra.h @@ -77,20 +77,9 @@ struct LsraBlockInfo // The low order 2 bits will be 1 for defs, and 2 for uses enum RefType : unsigned char { - RefTypeInvalid = 0x00, - RefTypeDef = 0x01, - RefTypeUse = 0x02, - RefTypeKill = 0x04, - RefTypeBB = 0x08, - RefTypeFixedReg = 0x10, - RefTypeExpUse = (0x20 | RefTypeUse), - RefTypeParamDef = (0x10 | RefTypeDef), - RefTypeDummyDef = (0x20 | RefTypeDef), - RefTypeZeroInit = (0x30 | RefTypeDef), - RefTypeUpperVectorSaveDef = (0x40 | RefTypeDef), - RefTypeUpperVectorSaveUse = (0x40 | RefTypeUse), - RefTypeKillGCRefs = 0x80, - RefTypeBound, +#define DEF_REFTYPE(memberName, memberValue, shortName) memberName = memberValue, +#include "lsra_reftypes.h" +#undef DEF_REFTYPE }; // position in a block (for resolution) diff --git a/src/jit/lsra_reftypes.h b/src/jit/lsra_reftypes.h new file mode 100644 index 0000000000..20780bd1cf --- /dev/null +++ b/src/jit/lsra_reftypes.h @@ -0,0 +1,21 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +// memberName - enum member name +// memberValue - enum member value +// shortName - short name string +// DEF_REFTYPE(memberName , memberValue , shortName ) + DEF_REFTYPE(RefTypeInvalid , 0x00 , "Invl" ) + DEF_REFTYPE(RefTypeDef , 0x01 , "Def " ) + DEF_REFTYPE(RefTypeUse , 0x02 , "Use " ) + DEF_REFTYPE(RefTypeKill , 0x04 , "Kill" ) + DEF_REFTYPE(RefTypeBB , 0x08 , "BB " ) + DEF_REFTYPE(RefTypeFixedReg , 0x10 , "Fixd" ) + DEF_REFTYPE(RefTypeExpUse , (0x20 | RefTypeUse), "ExpU" ) + DEF_REFTYPE(RefTypeParamDef , (0x10 | RefTypeDef), "Parm" ) + DEF_REFTYPE(RefTypeDummyDef , (0x20 | RefTypeDef), "DDef" ) + DEF_REFTYPE(RefTypeZeroInit , (0x30 | RefTypeDef), "Zero" ) + DEF_REFTYPE(RefTypeUpperVectorSaveDef, (0x40 | RefTypeDef), "UVSv" ) + DEF_REFTYPE(RefTypeUpperVectorSaveUse, (0x40 | RefTypeUse), "UVRs" ) + DEF_REFTYPE(RefTypeKillGCRefs , 0x80 , "KlGC" ) -- 2.34.1