Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove getFieldAddress #79060

Merged
merged 5 commits into from
Dec 3, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions src/coreclr/inc/corinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ The first 4 options are mutually exclusive
have managed thread local statics, which work through the HELPER. Support for this is considered
legacy, and going forward, the EE should

* <NONE> This is a normal static field. Its address in memory is determined by getFieldAddress. (see
* <NONE> This is a normal static field. Its address in memory is determined by getFieldInfo. (see
also CORINFO_FLG_STATIC_IN_HEAP).


Expand Down Expand Up @@ -1611,7 +1611,7 @@ struct CORINFO_CALL_INFO
CORINFO_LOOKUP codePointerLookup;
};

CORINFO_CONST_LOOKUP instParamLookup; // Used by Ready-to-Run
CORINFO_CONST_LOOKUP instParamLookup;

bool wrapperDelegateInvoke;
};
Expand Down Expand Up @@ -3188,13 +3188,6 @@ class ICorDynamicInfo : public ICorStaticInfo
void **ppIndirection = NULL
) = 0;


// return the data's address (for static fields only)
virtual void* getFieldAddress(
CORINFO_FIELD_HANDLE field,
void **ppIndirection = NULL
) = 0;

//------------------------------------------------------------------------------
// getReadonlyStaticFieldValue: returns true and the actual field's value if the given
// field represents a statically initialized readonly field of any type.
Expand Down
4 changes: 0 additions & 4 deletions src/coreclr/inc/icorjitinfoimpl_generated.h
Original file line number Diff line number Diff line change
Expand Up @@ -617,10 +617,6 @@ unsigned getClassDomainID(
CORINFO_CLASS_HANDLE cls,
void** ppIndirection) override;

void* getFieldAddress(
CORINFO_FIELD_HANDLE field,
void** ppIndirection) override;

bool getReadonlyStaticFieldValue(
CORINFO_FIELD_HANDLE field,
uint8_t* buffer,
Expand Down
10 changes: 5 additions & 5 deletions src/coreclr/inc/jiteeversionguid.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ typedef const GUID *LPCGUID;
#define GUID_DEFINED
#endif // !GUID_DEFINED

constexpr GUID JITEEVersionIdentifier = { /* 0330a175-dd05-4760-840f-a1a4c47284d3 */
0x330a175,
0xdd05,
0x4760,
{0x84, 0xf, 0xa1, 0xa4, 0xc4, 0x72, 0x84, 0xd3}
constexpr GUID JITEEVersionIdentifier = { /* aaa9536e-1295-4741-a7d9-6c09a5b01512 */
0xaaa9536e,
0x1295,
0x4741,
{0xa7, 0xd9, 0x6c, 0x9, 0xa5, 0xb0, 0x15, 0x12}
};

//////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
1 change: 0 additions & 1 deletion src/coreclr/jit/ICorJitInfo_names_generated.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ DEF_CLR_API(getCallInfo)
DEF_CLR_API(canAccessFamily)
DEF_CLR_API(isRIDClassDomainID)
DEF_CLR_API(getClassDomainID)
DEF_CLR_API(getFieldAddress)
DEF_CLR_API(getReadonlyStaticFieldValue)
DEF_CLR_API(getStaticFieldCurrentClass)
DEF_CLR_API(getVarArgsHandle)
Expand Down
10 changes: 0 additions & 10 deletions src/coreclr/jit/ICorJitInfo_wrapper_generated.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1474,16 +1474,6 @@ unsigned WrapICorJitInfo::getClassDomainID(
return temp;
}

void* WrapICorJitInfo::getFieldAddress(
CORINFO_FIELD_HANDLE field,
void** ppIndirection)
{
API_ENTER(getFieldAddress);
void* temp = wrapHnd->getFieldAddress(field, ppIndirection);
API_LEAVE(getFieldAddress);
return temp;
}

bool WrapICorJitInfo::getReadonlyStaticFieldValue(
CORINFO_FIELD_HANDLE field,
uint8_t* buffer,
Expand Down
1 change: 0 additions & 1 deletion src/coreclr/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -5714,7 +5714,6 @@ class Compiler
GenTree* fgMorphField(GenTree* tree, MorphAddrContext* mac);
GenTree* fgMorphExpandInstanceField(GenTree* tree, MorphAddrContext* mac);
GenTree* fgMorphExpandTlsFieldAddr(GenTree* tree);
GenTree* fgMorphExpandStaticField(GenTree* tree);
bool fgCanFastTailCall(GenTreeCall* call, const char** failReason);
#if FEATURE_FASTTAILCALL
bool fgCallHasMustCopyByrefParameter(GenTreeCall* callee);
Expand Down
5 changes: 1 addition & 4 deletions src/coreclr/jit/emitarm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4012,10 +4012,7 @@ void emitter::emitIns_R_C(instruction ins, emitAttr attr, regNumber reg, CORINFO
}
else
{
assert(!jitStaticFldIsGlobAddr(fldHnd));
addr = (ssize_t)emitComp->info.compCompHnd->getFieldAddress(fldHnd, NULL);
if (addr == NULL)
NO_WAY("could not obtain address of static field");
assert(!"Normal statics are expected to be handled in the importer");
}

// We can use reg to load the constant address,
Expand Down
7 changes: 2 additions & 5 deletions src/coreclr/jit/emitxarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12967,11 +12967,8 @@ BYTE* emitter::emitOutputCV(BYTE* dst, instrDesc* id, code_t code, CnsVal* addc)
}
else
{
addr = (BYTE*)emitComp->info.compCompHnd->getFieldAddress(fldh, nullptr);
if (addr == nullptr)
{
NO_WAY("could not obtain address of static field");
}
assert(jitStaticFldIsGlobAddr(fldh));
addr = nullptr;
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/coreclr/jit/fginline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1601,7 +1601,8 @@ Statement* Compiler::fgInlinePrependStatements(InlineInfo* inlineInfo)
GenTree* op2 = argNode->AsOp()->gtOp2;
if (op1->IsCall() &&
((op1->AsCall()->gtCallMoreFlags & GTF_CALL_M_HELPER_SPECIAL_DCE) != 0) &&
(op2->gtOper == GT_FIELD) && ((op2->gtFlags & GTF_EXCEPT) == 0))
op2->OperIs(GT_IND) && op2->gtGetOp1()->IsIconHandle() &&
((op2->gtFlags & GTF_EXCEPT) == 0))
{
JITDUMP("\nPerforming special dce on unused arg [%06u]:"
" actual arg [%06u] helper call [%06u]\n",
Expand Down
10 changes: 10 additions & 0 deletions src/coreclr/jit/gentree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18073,6 +18073,16 @@ CORINFO_CLASS_HANDLE Compiler::gtGetClassHandle(GenTree* tree, bool* pIsExact, b
}
}
}
else if (base->IsIconHandle(GTF_ICON_CONST_PTR, GTF_ICON_STATIC_HDL))
{
// Check if we have IND(ICON_HANDLE) that represents a static field
FieldSeq* fldSeq = base->AsIntCon()->gtFieldSeq;
if ((fldSeq != nullptr) && (fldSeq->GetOffset() == base->AsIntCon()->IconValue()))
{
CORINFO_FIELD_HANDLE fldHandle = base->AsIntCon()->gtFieldSeq->GetFieldHandle();
objClass = gtGetFieldClassHandle(fldHandle, pIsExact, pIsNonNull);
}
}
}

break;
Expand Down
6 changes: 6 additions & 0 deletions src/coreclr/jit/gentree.h
Original file line number Diff line number Diff line change
Expand Up @@ -2211,6 +2211,12 @@ struct GenTree
return (gtOper == GT_CNS_INT) && ((gtFlags & GTF_ICON_HDL_MASK) == handleType);
}

template <typename... T>
bool IsIconHandle(GenTreeFlags handleType, T... rest) const
{
return IsIconHandle(handleType) || IsIconHandle(rest...);
}

// Return just the part of the flags corresponding to the GTF_ICON_*_HDL flag.
// For non-icon handle trees, returns GTF_EMPTY.
GenTreeFlags GetIconHandleFlag() const
Expand Down
93 changes: 43 additions & 50 deletions src/coreclr/jit/importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1443,9 +1443,9 @@ GenTree* Compiler::impNormStructVal(GenTree* structVal, CORINFO_CLASS_HANDLE str
// In case of a chained GT_COMMA case, we sink the last
// GT_COMMA below the blockNode addr.
GenTree* blockNodeAddr = blockNode->AsOp()->gtOp1;
assert(blockNodeAddr->gtType == TYP_BYREF);
assert(blockNodeAddr->TypeIs(TYP_BYREF, TYP_I_IMPL));
GenTree* commaNode = parent;
commaNode->gtType = TYP_BYREF;
commaNode->gtType = blockNodeAddr->gtType;
commaNode->AsOp()->gtOp2 = blockNodeAddr;
blockNode->AsOp()->gtOp1 = commaNode;
if (parent == structVal)
Expand Down Expand Up @@ -4199,6 +4199,9 @@ GenTree* Compiler::impImportStaticFieldAccess(CORINFO_RESOLVED_TOKEN* pResolvedT
FieldSeq::FieldKind fieldKind =
isSharedStatic ? FieldSeq::FieldKind::SharedStatic : FieldSeq::FieldKind::SimpleStatic;

bool hasConstAddr = (pFieldInfo->fieldAccessor == CORINFO_FIELD_STATIC_ADDRESS) ||
(pFieldInfo->fieldAccessor == CORINFO_FIELD_STATIC_RVA_ADDRESS);

FieldSeq* innerFldSeq;
FieldSeq* outerFldSeq;
if (isBoxedStatic)
Expand All @@ -4208,18 +4211,15 @@ GenTree* Compiler::impImportStaticFieldAccess(CORINFO_RESOLVED_TOKEN* pResolvedT
}
else
{
bool hasKnownAddr = (pFieldInfo->fieldAccessor == CORINFO_FIELD_STATIC_ADDRESS) ||
(pFieldInfo->fieldAccessor == CORINFO_FIELD_STATIC_RVA_ADDRESS);

ssize_t offset;
if (hasKnownAddr)
if (hasConstAddr)
{
// Change SimpleStatic to SimpleStaticKnownAddress
assert(fieldKind == FieldSeq::FieldKind::SimpleStatic);
fieldKind = FieldSeq::FieldKind::SimpleStaticKnownAddress;

offset = reinterpret_cast<ssize_t>(info.compCompHnd->getFieldAddress(pResolvedToken->hField));
assert(offset != 0);
assert(pFieldInfo->fieldLookup.accessType == IAT_VALUE);
offset = reinterpret_cast<ssize_t>(pFieldInfo->fieldLookup.addr);
}
else
{
Expand All @@ -4230,6 +4230,7 @@ GenTree* Compiler::impImportStaticFieldAccess(CORINFO_RESOLVED_TOKEN* pResolvedT
outerFldSeq = nullptr;
}

bool isStaticReadOnlyInitedRef = false;
GenTree* op1;
switch (pFieldInfo->fieldAccessor)
{
Expand Down Expand Up @@ -4322,53 +4323,41 @@ GenTree* Compiler::impImportStaticFieldAccess(CORINFO_RESOLVED_TOKEN* pResolvedT

default:
{
// Do we need the address of a static field?
//
if (access & CORINFO_ACCESS_ADDRESS)
// TODO-CQ: enable this optimization for 32 bit targets.
#ifdef TARGET_64BIT
if (!isBoxedStatic && (lclTyp == TYP_REF) && ((access & CORINFO_ACCESS_ADDRESS) == 0))
{
void** pFldAddr = nullptr;
void* fldAddr = info.compCompHnd->getFieldAddress(pResolvedToken->hField, (void**)&pFldAddr);

// We should always be able to access this static's address directly.
assert(pFldAddr == nullptr);

// Create the address node.
GenTreeFlags handleKind = isBoxedStatic ? GTF_ICON_STATIC_BOX_PTR : GTF_ICON_STATIC_HDL;
op1 = gtNewIconHandleNode((size_t)fldAddr, handleKind, innerFldSeq);
INDEBUG(op1->AsIntCon()->gtTargetHandle = reinterpret_cast<size_t>(pResolvedToken->hField));

if (pFieldInfo->fieldFlags & CORINFO_FLG_FIELD_INITCLASS)
bool isSpeculative = true;
if ((info.compCompHnd->getStaticFieldCurrentClass(pResolvedToken->hField, &isSpeculative) !=
NO_CLASS_HANDLE))
{
op1->gtFlags |= GTF_ICON_INITCLASS;
isStaticReadOnlyInitedRef = !isSpeculative;
}
}
else // We need the value of a static field
{
op1 = gtNewFieldRef(lclTyp, pResolvedToken->hField);

if (pFieldInfo->fieldFlags & CORINFO_FLG_FIELD_INITCLASS)
{
op1->gtFlags |= GTF_FLD_INITCLASS;
}

if (isBoxedStatic)
{
op1->ChangeType(TYP_REF); // points at boxed object
op1 = gtNewOperNode(GT_ADD, TYP_BYREF, op1, gtNewIconNode(TARGET_POINTER_SIZE, outerFldSeq));

if (varTypeIsStruct(lclTyp))
{
// Constructor adds GTF_GLOB_REF. Note that this is *not* GTF_EXCEPT.
op1 = gtNewObjNode(pFieldInfo->structType, op1);
}
else
{
op1 = gtNewOperNode(GT_IND, lclTyp, op1);
op1->gtFlags |= (GTF_GLOB_REF | GTF_IND_NONFAULTING);
}
}
#endif // TARGET_64BIT

return op1;
assert(hasConstAddr);
assert(pFieldInfo->fieldLookup.addr != nullptr);
assert(pFieldInfo->fieldLookup.accessType == IAT_VALUE);
size_t fldAddr = reinterpret_cast<size_t>(pFieldInfo->fieldLookup.addr);
GenTreeFlags handleKind;
if (isBoxedStatic)
{
handleKind = GTF_ICON_STATIC_BOX_PTR;
}
else if (isStaticReadOnlyInitedRef)
{
handleKind = GTF_ICON_CONST_PTR;
}
else
{
handleKind = GTF_ICON_STATIC_HDL;
}
op1 = gtNewIconHandleNode(fldAddr, handleKind, innerFldSeq);
INDEBUG(op1->AsIntCon()->gtTargetHandle = reinterpret_cast<size_t>(pResolvedToken->hField));
if (pFieldInfo->fieldFlags & CORINFO_FLG_FIELD_INITCLASS)
{
op1->gtFlags |= GTF_ICON_INITCLASS;
}
break;
}
Expand All @@ -4392,6 +4381,10 @@ GenTree* Compiler::impImportStaticFieldAccess(CORINFO_RESOLVED_TOKEN* pResolvedT
op1 = gtNewOperNode(GT_IND, lclTyp, op1);
op1->gtFlags |= GTF_GLOB_REF;
}
if (isStaticReadOnlyInitedRef)
{
op1->gtFlags |= (GTF_IND_INVARIANT | GTF_IND_NONFAULTING | GTF_IND_NONNULL);
}
}

return op1;
Expand Down
Loading