From 565d5be3a5b109bb7dfd245fae3b261e05cc08bb Mon Sep 17 00:00:00 2001 From: Tanner Gooding Date: Sat, 2 Jun 2018 08:29:36 -0700 Subject: [PATCH] Moving the getHWIntrinsicInfo and getHWIntrinsicName methods to be static methods on HWIntrinsicInfo --- src/jit/codegenarm64.cpp | 4 ++-- src/jit/compiler.h | 1 - src/jit/gentree.cpp | 7 ++----- src/jit/hwintrinsicArm64.cpp | 31 ++++++++++++++++++------------- src/jit/hwintrinsicArm64.h | 11 +++++++++-- src/jit/hwintrinsicxarch.cpp | 21 +++++++++++++++++---- src/jit/hwintrinsicxarch.h | 11 +++++++++-- src/jit/lowerarmarch.cpp | 4 ++-- src/jit/lsraarm64.cpp | 2 +- 9 files changed, 60 insertions(+), 32 deletions(-) diff --git a/src/jit/codegenarm64.cpp b/src/jit/codegenarm64.cpp index 9441051..5fa3015 100644 --- a/src/jit/codegenarm64.cpp +++ b/src/jit/codegenarm64.cpp @@ -4898,7 +4898,7 @@ instruction CodeGen::getOpForHWIntrinsic(GenTreeHWIntrinsic* node, var_types ins unsigned int instrTypeIndex = varTypeIsFloating(instrType) ? 0 : varTypeIsUnsigned(instrType) ? 2 : 1; - instruction ins = compiler->getHWIntrinsicInfo(intrinsicID).instrs[instrTypeIndex]; + instruction ins = HWIntrinsicInfo::lookup(intrinsicID).instrs[instrTypeIndex]; assert(ins != INS_invalid); return ins; @@ -4919,7 +4919,7 @@ void CodeGen::genHWIntrinsic(GenTreeHWIntrinsic* node) { NamedIntrinsic intrinsicID = node->gtHWIntrinsicId; - switch (compiler->getHWIntrinsicInfo(intrinsicID).form) + switch (HWIntrinsicInfo::lookup(intrinsicID).form) { case HWIntrinsicInfo::UnaryOp: genHWIntrinsicUnaryOp(node); diff --git a/src/jit/compiler.h b/src/jit/compiler.h index ed50fb3..2b054f6 100644 --- a/src/jit/compiler.h +++ b/src/jit/compiler.h @@ -3036,7 +3036,6 @@ protected: InstructionSet lookupHWIntrinsicISA(const char* className); NamedIntrinsic lookupHWIntrinsic(const char* className, const char* methodName); bool impCheckImmediate(GenTree* immediateOp, unsigned int max); - const HWIntrinsicInfo& getHWIntrinsicInfo(NamedIntrinsic); #endif // _TARGET_ARM64_ #endif // FEATURE_HW_INTRINSICS GenTree* impArrayAccessIntrinsic(CORINFO_CLASS_HANDLE clsHnd, diff --git a/src/jit/gentree.cpp b/src/jit/gentree.cpp index 5c0ab71..90a8dc9 100644 --- a/src/jit/gentree.cpp +++ b/src/jit/gentree.cpp @@ -12,6 +12,7 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX */ #include "jitpch.h" +#include "hwintrinsic.h" #include "simd.h" #ifdef _MSC_VER @@ -10813,10 +10814,6 @@ extern const char* const simdIntrinsicNames[] = { }; #endif // FEATURE_SIMD -#ifdef FEATURE_HW_INTRINSICS -extern const char* getHWIntrinsicName(NamedIntrinsic intrinsic); -#endif // FEATURE_HW_INTRINSICS - /*****************************************************************************/ void Compiler::gtDispTree(GenTree* tree, @@ -11143,7 +11140,7 @@ void Compiler::gtDispTree(GenTree* tree, printf(" %s %s", tree->gtHWIntrinsic.gtSIMDBaseType == TYP_UNKNOWN ? "" : varTypeName(tree->gtHWIntrinsic.gtSIMDBaseType), - getHWIntrinsicName(tree->gtHWIntrinsic.gtHWIntrinsicId)); + HWIntrinsicInfo::lookupName(tree->gtHWIntrinsic.gtHWIntrinsicId)); } #endif // FEATURE_HW_INTRINSICS diff --git a/src/jit/hwintrinsicArm64.cpp b/src/jit/hwintrinsicArm64.cpp index 0a8130e..c64ff6e 100644 --- a/src/jit/hwintrinsicArm64.cpp +++ b/src/jit/hwintrinsicArm64.cpp @@ -44,17 +44,22 @@ static const HWIntrinsicInfo hwIntrinsicInfoArray[] = { }; // clang-format on -extern const char* getHWIntrinsicName(NamedIntrinsic intrinsic) +//------------------------------------------------------------------------ +// lookup: Gets the HWIntrinsicInfo associated with a given NamedIntrinsic +// +// Arguments: +// id -- The NamedIntrinsic associated with the HWIntrinsic to lookup +// +// Return Value: +// The HWIntrinsicInfo associated with id +const HWIntrinsicInfo& HWIntrinsicInfo::lookup(NamedIntrinsic id) { - return hwIntrinsicInfoArray[intrinsic - NI_HW_INTRINSIC_START - 1].intrinsicName; -} + assert(id != NI_Illegal); -const HWIntrinsicInfo& Compiler::getHWIntrinsicInfo(NamedIntrinsic intrinsic) -{ - assert(intrinsic > NI_HW_INTRINSIC_START); - assert(intrinsic < NI_HW_INTRINSIC_END); + assert(id > NI_HW_INTRINSIC_START); + assert(id < NI_HW_INTRINSIC_END); - return hwIntrinsicInfoArray[intrinsic - NI_HW_INTRINSIC_START - 1]; + return hwIntrinsicInfoArray[id - NI_HW_INTRINSIC_START - 1]; } //------------------------------------------------------------------------ @@ -102,19 +107,19 @@ NamedIntrinsic Compiler::lookupHWIntrinsic(const char* className, const char* me for (int i = 0; i < NI_HW_INTRINSIC_END - NI_HW_INTRINSIC_START; i++) { if ((isaFlag & hwIntrinsicInfoArray[i].isaflags) && - strcmp(methodName, hwIntrinsicInfoArray[i].intrinsicName) == 0) + strcmp(methodName, hwIntrinsicInfoArray[i].name) == 0) { if (compSupports(isa)) { // Intrinsic is supported on platform - result = hwIntrinsicInfoArray[i].intrinsicID; + result = hwIntrinsicInfoArray[i].id; } else { // When the intrinsic class is not supported // Return NI_ARM64_PlatformNotSupported for all intrinsics // Return NI_ARM64_IsSupported_False for the IsSupported property - result = (hwIntrinsicInfoArray[i].intrinsicID != NI_ARM64_IsSupported_True) + result = (hwIntrinsicInfoArray[i].id != NI_ARM64_IsSupported_True) ? NI_ARM64_PlatformNotSupported : NI_ARM64_IsSupported_False; } @@ -210,7 +215,7 @@ GenTree* Compiler::impHWIntrinsic(NamedIntrinsic intrinsic, var_types simdBaseType = TYP_UNKNOWN; unsigned simdSizeBytes = 0; - switch (getHWIntrinsicInfo(intrinsic).form) + switch (HWIntrinsicInfo::lookup(intrinsic).form) { case HWIntrinsicInfo::SimdBinaryOp: case HWIntrinsicInfo::SimdInsertOp: @@ -243,7 +248,7 @@ GenTree* Compiler::impHWIntrinsic(NamedIntrinsic intrinsic, simdType = getSIMDTypeForSize(simdSizeBytes); } - switch (getHWIntrinsicInfo(intrinsic).form) + switch (HWIntrinsicInfo::lookup(intrinsic).form) { case HWIntrinsicInfo::IsSupported: return gtNewIconNode((intrinsic == NI_ARM64_IsSupported_True) ? 1 : 0); diff --git a/src/jit/hwintrinsicArm64.h b/src/jit/hwintrinsicArm64.h index b7bc6e7..c0d3ffd 100644 --- a/src/jit/hwintrinsicArm64.h +++ b/src/jit/hwintrinsicArm64.h @@ -44,12 +44,19 @@ struct HWIntrinsicInfo LowerCmpUZero = (1UL << 0), // Unsigned zero compare form must be lowered }; - NamedIntrinsic intrinsicID; - const char* intrinsicName; + NamedIntrinsic id; + const char* name; uint64_t isaflags; Form form; Flags flags; instruction instrs[3]; + + static const HWIntrinsicInfo& lookup(NamedIntrinsic id); + + static const char* lookupName(NamedIntrinsic id) + { + return lookup(id).name; + } }; #endif // FEATURE_HW_INTRINSICS diff --git a/src/jit/hwintrinsicxarch.cpp b/src/jit/hwintrinsicxarch.cpp index 48b2d67..633a853 100644 --- a/src/jit/hwintrinsicxarch.cpp +++ b/src/jit/hwintrinsicxarch.cpp @@ -15,9 +15,22 @@ static const HWIntrinsicInfo hwIntrinsicInfoArray[] = { #include "hwintrinsiclistxarch.h" }; -extern const char* getHWIntrinsicName(NamedIntrinsic intrinsic) +//------------------------------------------------------------------------ +// lookup: Gets the HWIntrinsicInfo associated with a given NamedIntrinsic +// +// Arguments: +// id -- The NamedIntrinsic associated with the HWIntrinsic to lookup +// +// Return Value: +// The HWIntrinsicInfo associated with id +const HWIntrinsicInfo& HWIntrinsicInfo::lookup(NamedIntrinsic id) { - return hwIntrinsicInfoArray[intrinsic - NI_HW_INTRINSIC_START - 1].intrinsicName; + assert(id != NI_Illegal); + + assert(id > NI_HW_INTRINSIC_START); + assert(id < NI_HW_INTRINSIC_END); + + return hwIntrinsicInfoArray[id - NI_HW_INTRINSIC_START - 1]; } //------------------------------------------------------------------------ @@ -124,9 +137,9 @@ NamedIntrinsic Compiler::lookupHWIntrinsic(const char* methodName, InstructionSe { for (int i = 0; i < NI_HW_INTRINSIC_END - NI_HW_INTRINSIC_START - 1; i++) { - if (isa == hwIntrinsicInfoArray[i].isa && strcmp(methodName, hwIntrinsicInfoArray[i].intrinsicName) == 0) + if (isa == hwIntrinsicInfoArray[i].isa && strcmp(methodName, hwIntrinsicInfoArray[i].name) == 0) { - result = hwIntrinsicInfoArray[i].intrinsicID; + result = hwIntrinsicInfoArray[i].id; break; } } diff --git a/src/jit/hwintrinsicxarch.h b/src/jit/hwintrinsicxarch.h index 17f5fa8..820f12d 100644 --- a/src/jit/hwintrinsicxarch.h +++ b/src/jit/hwintrinsicxarch.h @@ -127,8 +127,8 @@ enum HWIntrinsicFlag : unsigned int struct HWIntrinsicInfo { - NamedIntrinsic intrinsicID; - const char* intrinsicName; + NamedIntrinsic id; + const char* name; InstructionSet isa; int ival; unsigned simdSize; @@ -136,6 +136,13 @@ struct HWIntrinsicInfo instruction ins[10]; HWIntrinsicCategory category; HWIntrinsicFlag flags; + + static const HWIntrinsicInfo& lookup(NamedIntrinsic id); + + static const char* lookupName(NamedIntrinsic id) + { + return lookup(id).name; + } }; #endif // FEATURE_HW_INTRINSICS diff --git a/src/jit/lowerarmarch.cpp b/src/jit/lowerarmarch.cpp index 90582c8..47998fe 100644 --- a/src/jit/lowerarmarch.cpp +++ b/src/jit/lowerarmarch.cpp @@ -494,7 +494,7 @@ void Lowering::LowerSIMD(GenTreeSIMD* simdNode) void Lowering::LowerHWIntrinsic(GenTreeHWIntrinsic* node) { auto intrinsicID = node->gtHWIntrinsicId; - auto intrinsicInfo = comp->getHWIntrinsicInfo(node->gtHWIntrinsicId); + auto intrinsicInfo = HWIntrinsicInfo::lookup(node->gtHWIntrinsicId); // // Lower unsupported Unsigned Compare Zero intrinsics to their trivial transformations @@ -876,7 +876,7 @@ void Lowering::ContainCheckHWIntrinsic(GenTreeHWIntrinsic* node) op2 = argList->Rest()->Current(); } - switch (comp->getHWIntrinsicInfo(node->gtHWIntrinsicId).form) + switch (HWIntrinsicInfo::lookup(node->gtHWIntrinsicId).form) { case HWIntrinsicInfo::SimdExtractOp: if (op2->IsCnsIntOrI()) diff --git a/src/jit/lsraarm64.cpp b/src/jit/lsraarm64.cpp index b4a540b..fbca9ae 100644 --- a/src/jit/lsraarm64.cpp +++ b/src/jit/lsraarm64.cpp @@ -1051,7 +1051,7 @@ int LinearScan::BuildHWIntrinsic(GenTreeHWIntrinsic* intrinsicTree) bool op3IsDelayFree = false; // Create internal temps, and handle any other special requirements. - switch (compiler->getHWIntrinsicInfo(intrinsicID).form) + switch (HWIntrinsicInfo::lookup(intrinsicID).form) { case HWIntrinsicInfo::Sha1HashOp: assert((numArgs == 3) && (op2 != nullptr) && (op3 != nullptr)); -- 2.7.4