Skip to content

Commit

Permalink
Add static MemoryReference creation helpers
Browse files Browse the repository at this point in the history
-Added static helper for each MemoryReference constructor
-Renamed/refactored withDisplacement and withLabel helpers to createWithDisplacement
 and createWithLabel to match naming convention of other helpers

Signed-off-by: Jackie Midroni <jackie.midroni@mail.utoronto.ca>
  • Loading branch information
Jackie Midroni committed Sep 10, 2020
1 parent 58b0c18 commit 2554ffc
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 31 deletions.
12 changes: 11 additions & 1 deletion compiler/p/codegen/MemoryReference.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class OMR_EXTENSIBLE MemoryReference : public OMR::MemoryReferenceConnector
{
private:

//TODO: get rid of extra int paramenter once legacy constructor is removed and replaced
MemoryReference(TR::Register *br,
int64_t disp,
uint8_t len,
Expand All @@ -59,6 +60,7 @@ class OMR_EXTENSIBLE MemoryReference : public OMR::MemoryReferenceConnector
TR::CodeGenerator *cg) :
OMR::MemoryReferenceConnector(br, ir, len, cg) {}

//TODO: legacy constructor - should be replaced by int64_t version (called by withDisplacement)
MemoryReference(TR::Register *br,
int32_t disp,
uint8_t len,
Expand All @@ -74,7 +76,15 @@ class OMR_EXTENSIBLE MemoryReference : public OMR::MemoryReferenceConnector
MemoryReference(TR::Node *node, MemoryReference& mr, int32_t n, uint32_t len, TR::CodeGenerator *cg):
OMR::MemoryReferenceConnector(node, mr, n, len, cg) {}

static TR::MemoryReference *withDisplacement(TR::CodeGenerator *cg, TR::Register *baseReg, int64_t displacement, int8_t length);
static TR::MemoryReference *create(TR::CodeGenerator *cg);
static TR::MemoryReference *createWithLabel(TR::CodeGenerator *cg, TR::LabelSymbol *label, int64_t offset, int8_t length);
static TR::MemoryReference *createWithIndexReg(TR::CodeGenerator *cg, TR::Register *baseReg, TR::Register *indexReg, uint8_t length);
static TR::MemoryReference *createWithDisplacement(TR::CodeGenerator *cg, TR::Register *baseReg, int64_t displacement, int8_t length);
static TR::MemoryReference *createWithRootLoadOrStore(TR::CodeGenerator *cg, TR::Node *rootLoadOrStore, uint32_t length);
static TR::MemoryReference *createWithSymRef(TR::CodeGenerator *cg, TR::Node *node, TR::SymbolReference *symRef, uint32_t length);
static TR::MemoryReference *createWithMemRef(TR::CodeGenerator *cg, TR::Node *node, TR::MemoryReference& memRef, int32_t displacement, uint32_t length);

//Keeping the old version of the createWithLabel helper here to make sure OpenJ9 doesn't break
static TR::MemoryReference *withLabel(TR::CodeGenerator *cg, TR::LabelSymbol *label, int64_t offset, int8_t length);
};
}
Expand Down
33 changes: 32 additions & 1 deletion compiler/p/codegen/OMRMemoryReference.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,42 @@ class TR_OpaqueClassBlock;

static TR::RealRegister::RegNum choose_rX(TR::Instruction *, TR::RealRegister *);

TR::MemoryReference *TR::MemoryReference::withDisplacement(TR::CodeGenerator *cg, TR::Register *baseReg, int64_t displacement, int8_t length)
TR::MemoryReference *TR::MemoryReference::create(TR::CodeGenerator *cg)
{
return new (cg->trHeapMemory()) TR::MemoryReference(cg);
}

TR::MemoryReference *TR::MemoryReference::createWithLabel(TR::CodeGenerator *cg, TR::LabelSymbol *label, int64_t offset, int8_t length)
{
return new (cg->trHeapMemory()) TR::MemoryReference(label, offset, length, cg);
}

TR::MemoryReference *TR::MemoryReference::createWithIndexReg(TR::CodeGenerator *cg, TR::Register *baseReg, TR::Register *indexReg, uint8_t length)
{
return new (cg->trHeapMemory()) TR::MemoryReference(baseReg, indexReg, length, cg);
}

TR::MemoryReference *TR::MemoryReference::createWithDisplacement(TR::CodeGenerator *cg, TR::Register *baseReg, int64_t displacement, int8_t length)
{
return new (cg->trHeapMemory()) TR::MemoryReference(baseReg, displacement, length, cg, 0);
}

TR::MemoryReference *TR::MemoryReference::createWithRootLoadOrStore(TR::CodeGenerator *cg, TR::Node *rootLoadOrStore, uint32_t length)
{
return new (cg->trHeapMemory()) TR::MemoryReference(rootLoadOrStore, length, cg);
}

TR::MemoryReference *TR::MemoryReference::createWithSymRef(TR::CodeGenerator *cg, TR::Node *node, TR::SymbolReference *symRef, uint32_t length)
{
return new (cg->trHeapMemory()) TR::MemoryReference(node, symRef, length, cg);
}

TR::MemoryReference *TR::MemoryReference::createWithMemRef(TR::CodeGenerator *cg, TR::Node *node, TR::MemoryReference& memRef, int32_t displacement, uint32_t length)
{
return new (cg->trHeapMemory()) TR::MemoryReference(node, memRef, displacement, length, cg);
}

//Keeping the old version of the createWithLabel helper here to make sure OpenJ9 doesn't break
TR::MemoryReference *TR::MemoryReference::withLabel(TR::CodeGenerator *cg, TR::LabelSymbol *label, int64_t offset, int8_t length)
{
return new (cg->trHeapMemory()) TR::MemoryReference(label, offset, length, cg);
Expand Down
3 changes: 2 additions & 1 deletion compiler/p/codegen/OMRMemoryReference.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class OMR_EXTENSIBLE MemoryReference : public OMR::MemoryReference
// The extra int parameter at the end is needed to ensure that this constructor is never
// ambiguous with the legacy constructor taking an int32_t for its displacement. This detail
// is hidden from other code, since this constructor can only be used by calling the
// MemoryReference::withDisplacement helper. Once the legacy constructor is removed, the extra
// MemoryReference::createWithDisplacement helper. Once the legacy constructor is removed, the extra
// parameter here can also be removed.
MemoryReference(
TR::Register *br,
Expand Down Expand Up @@ -119,6 +119,7 @@ class OMR_EXTENSIBLE MemoryReference : public OMR::MemoryReference
uint8_t len,
TR::CodeGenerator *cg);

//TODO: legacy constructor - should be replaced by int64_t version (called by createWithDisplacement)
MemoryReference(
TR::Register *br,
int32_t disp,
Expand Down
16 changes: 8 additions & 8 deletions fvtest/compilerunittest/p/BinaryEncoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,7 @@ TEST_P(PPCTrg1MemPCRelativeEncodingTest, encode) {
std::get<0>(GetParam()),
fakeNode,
cg()->machine()->getRealRegister(std::get<1>(GetParam())),
TR::MemoryReference::withLabel(cg(), label, std::get<3>(GetParam()), 0)
TR::MemoryReference::createWithLabel(cg(), label, std::get<3>(GetParam()), 0)
);

label->setCodeLocation(reinterpret_cast<uint8_t*>(getAlignedBuf()) + std::get<2>(GetParam()));
Expand All @@ -840,7 +840,7 @@ TEST_P(PPCTrg1MemPCRelativeEncodingTest, encodePrefixCrossingBoundary) {
std::get<0>(GetParam()),
fakeNode,
cg()->machine()->getRealRegister(std::get<1>(GetParam())),
TR::MemoryReference::withLabel(cg(), label, std::get<3>(GetParam()), 0)
TR::MemoryReference::createWithLabel(cg(), label, std::get<3>(GetParam()), 0)
);

label->setCodeLocation(reinterpret_cast<uint8_t*>(getAlignedBuf()) + 64 + std::get<2>(GetParam()));
Expand All @@ -858,7 +858,7 @@ TEST_P(PPCTrg1MemPCRelativeEncodingTest, encodeWithRelocation) {
std::get<0>(GetParam()),
fakeNode,
cg()->machine()->getRealRegister(std::get<1>(GetParam())),
TR::MemoryReference::withLabel(cg(), label, std::get<3>(GetParam()), 0)
TR::MemoryReference::createWithLabel(cg(), label, std::get<3>(GetParam()), 0)
);

auto size = encodeInstruction(instr)._words.size() * 4;
Expand All @@ -878,7 +878,7 @@ TEST_P(PPCTrg1MemPCRelativeEncodingTest, encodePrefixCrossingBoundaryWithRelocat
std::get<0>(GetParam()),
fakeNode,
cg()->machine()->getRealRegister(std::get<1>(GetParam())),
TR::MemoryReference::withLabel(cg(), label, std::get<3>(GetParam()), 0)
TR::MemoryReference::createWithLabel(cg(), label, std::get<3>(GetParam()), 0)
);

auto size = encodeInstruction(instr, 60)._words.size() * 4;
Expand Down Expand Up @@ -996,7 +996,7 @@ TEST_P(PPCMemSrc1PCRelativeEncodingTest, encode) {
cg(),
std::get<0>(GetParam()),
fakeNode,
TR::MemoryReference::withLabel(cg(), label, std::get<3>(GetParam()), 0),
TR::MemoryReference::createWithLabel(cg(), label, std::get<3>(GetParam()), 0),
cg()->machine()->getRealRegister(std::get<1>(GetParam()))
);

Expand All @@ -1014,7 +1014,7 @@ TEST_P(PPCMemSrc1PCRelativeEncodingTest, encodePrefixCrossingBoundary) {
cg(),
std::get<0>(GetParam()),
fakeNode,
TR::MemoryReference::withLabel(cg(), label, std::get<3>(GetParam()), 0),
TR::MemoryReference::createWithLabel(cg(), label, std::get<3>(GetParam()), 0),
cg()->machine()->getRealRegister(std::get<1>(GetParam()))
);

Expand All @@ -1032,7 +1032,7 @@ TEST_P(PPCMemSrc1PCRelativeEncodingTest, encodeWithRelocation) {
cg(),
std::get<0>(GetParam()),
fakeNode,
TR::MemoryReference::withLabel(cg(), label, std::get<3>(GetParam()), 0),
TR::MemoryReference::createWithLabel(cg(), label, std::get<3>(GetParam()), 0),
cg()->machine()->getRealRegister(std::get<1>(GetParam()))
);

Expand All @@ -1052,7 +1052,7 @@ TEST_P(PPCMemSrc1PCRelativeEncodingTest, encodePrefixCrossingBoundaryWithRelocat
cg(),
std::get<0>(GetParam()),
fakeNode,
TR::MemoryReference::withLabel(cg(), label, std::get<3>(GetParam()), 0),
TR::MemoryReference::createWithLabel(cg(), label, std::get<3>(GetParam()), 0),
cg()->machine()->getRealRegister(std::get<1>(GetParam()))
);

Expand Down
Loading

0 comments on commit 2554ffc

Please sign in to comment.