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

Deduplicate some HWI codegen code #65302

Merged
merged 3 commits into from
Feb 23, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
137 changes: 135 additions & 2 deletions src/coreclr/jit/codegen.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ class CodeGen final : public CodeGenInterface

static bool genShouldRoundFP();

GenTreeIndir indirForm(var_types type, GenTree* base);
GenTreeStoreInd storeIndirForm(var_types type, GenTree* base, GenTree* data);
static GenTreeIndir indirForm(var_types type, GenTree* base);
static GenTreeStoreInd storeIndirForm(var_types type, GenTree* base, GenTree* data);

GenTreeIntCon intForm(var_types type, ssize_t value);

Expand Down Expand Up @@ -1410,6 +1410,139 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
void inst_RV_SH(instruction ins, emitAttr size, regNumber reg, unsigned val, insFlags flags = INS_FLAGS_DONT_CARE);

#if defined(TARGET_XARCH)

enum class OperandKind{
ClsVar, // [CLS_VAR_ADDR] - "C" in the emitter.
Local, // [Local or spill temp + offset] - "S" in the emitter.
Indir, // [base+index*scale+disp] - "A" in the emitter.
Imm, // immediate - "I" in the emitter.
Reg // reg - "R" in the emitter.
};

class OperandDesc
{
OperandKind m_kind;
union {
struct
{
CORINFO_FIELD_HANDLE m_fieldHnd;
};
struct
{
int m_varNum;
uint16_t m_offset;
};
struct
{
GenTree* m_addr;
GenTreeIndir* m_indir;
var_types m_indirType;
};
struct
{
ssize_t m_immediate;
bool m_immediateNeedsReloc;
};
struct
{
regNumber m_reg;
};
};

public:
OperandDesc(CORINFO_FIELD_HANDLE fieldHnd) : m_kind(OperandKind::ClsVar), m_fieldHnd(fieldHnd)
{
}

OperandDesc(int varNum, uint16_t offset) : m_kind(OperandKind::Local), m_varNum(varNum), m_offset(offset)
{
}

OperandDesc(GenTreeIndir* indir)
: m_kind(OperandKind::Indir), m_addr(indir->Addr()), m_indir(indir), m_indirType(indir->TypeGet())
{
}

OperandDesc(var_types indirType, GenTree* addr)
: m_kind(OperandKind::Indir), m_addr(addr), m_indir(nullptr), m_indirType(indirType)
{
}

OperandDesc(ssize_t immediate, bool immediateNeedsReloc)
: m_kind(OperandKind::Imm), m_immediate(immediate), m_immediateNeedsReloc(immediateNeedsReloc)
{
}

OperandDesc(regNumber reg) : m_kind(OperandKind::Reg), m_reg(reg)
{
}

OperandKind GetKind() const
{
return m_kind;
}

CORINFO_FIELD_HANDLE GetFieldHnd() const
{
assert(m_kind == OperandKind::ClsVar);
return m_fieldHnd;
}

int GetVarNum() const
{
assert(m_kind == OperandKind::Local);
return m_varNum;
}

int GetLclOffset() const
{
assert(m_kind == OperandKind::Local);
return m_offset;
}

// TODO-Cleanup: instead of this rather unsightly workaround with
// "indirForm", create a new abstraction for address modes to pass
// to the emitter (or at least just use "addr"...).
GenTreeIndir* GetIndirForm(GenTreeIndir* pIndirForm)
{
if (m_indir == nullptr)
{
GenTreeIndir indirForm = CodeGen::indirForm(m_indirType, m_addr);
memcpy(pIndirForm, &indirForm, sizeof(GenTreeIndir));
}
else
{
pIndirForm = m_indir;
}

return pIndirForm;
}

ssize_t GetImmediate() const
{
assert(m_kind == OperandKind::Imm);
return m_immediate;
}

bool ImmediateNeedsReloc() const
{
assert(m_kind == OperandKind::Imm);
return m_immediateNeedsReloc;
}

regNumber GetReg() const
{
return m_reg;
}

bool IsContained() const
{
return m_kind != OperandKind::Reg;
}
};

OperandDesc genOperandDesc(GenTree* op);

void inst_RV_RV_IV(instruction ins, emitAttr size, regNumber reg1, regNumber reg2, unsigned ival);
void inst_RV_TT_IV(instruction ins, emitAttr attr, regNumber reg1, GenTree* rmOp, int ival);
void inst_RV_RV_TT(instruction ins, emitAttr size, regNumber targetReg, regNumber op1Reg, GenTree* op2, bool isRMW);
Expand Down
5 changes: 2 additions & 3 deletions src/coreclr/jit/codegencommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10924,13 +10924,12 @@ const char* CodeGen::siStackVarName(size_t offs, size_t size, unsigned reg, unsi
/*****************************************************************************/
#endif // !defined(DEBUG)
#endif // defined(LATE_DISASM)
/*****************************************************************************/

//------------------------------------------------------------------------
// indirForm: Make a temporary indir we can feed to pattern matching routines
// in cases where we don't want to instantiate all the indirs that happen.
//
GenTreeIndir CodeGen::indirForm(var_types type, GenTree* base)
/* static */ GenTreeIndir CodeGen::indirForm(var_types type, GenTree* base)
{
GenTreeIndir i(GT_IND, type, base, nullptr);
i.SetRegNum(REG_NA);
Expand All @@ -10942,7 +10941,7 @@ GenTreeIndir CodeGen::indirForm(var_types type, GenTree* base)
// indirForm: Make a temporary indir we can feed to pattern matching routines
// in cases where we don't want to instantiate all the indirs that happen.
//
GenTreeStoreInd CodeGen::storeIndirForm(var_types type, GenTree* base, GenTree* data)
/* static */ GenTreeStoreInd CodeGen::storeIndirForm(var_types type, GenTree* base, GenTree* data)
{
GenTreeStoreInd i(type, base, data);
i.SetRegNum(REG_NA);
Expand Down
7 changes: 5 additions & 2 deletions src/coreclr/jit/gentree.h
Original file line number Diff line number Diff line change
Expand Up @@ -6086,12 +6086,15 @@ struct GenTreeIndir : public GenTreeOp
}

#if DEBUGGABLE_GENTREE
protected:
friend GenTree;
// Used only for GenTree::GetVtableForOper()
GenTreeIndir() : GenTreeOp()
{
}
#else
// Used by XARCH codegen to construct temporary trees to pass to the emitter.
GenTreeIndir() : GenTreeOp(GT_NOP, TYP_UNDEF)
{
}
#endif
};

Expand Down
Loading