Skip to content

Commit

Permalink
Merge pull request #2701 from 0xdaryl/machine
Browse files Browse the repository at this point in the history
Misc. Machine class cleanup
  • Loading branch information
vijaysun-omr authored Jun 28, 2018
2 parents 767ddae + c735938 commit 9c8787d
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 161 deletions.
4 changes: 2 additions & 2 deletions compiler/aarch64/codegen/OMRMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include "infra/Assert.hpp"

OMR::ARM64::Machine::Machine(TR::CodeGenerator *cg) :
OMR::Machine(cg, NUM_ARM64_GPR, NUM_ARM64_FPR)
OMR::Machine(cg)
{
_registerFile = (TR::RealRegister **)cg->trMemory()->allocateMemory(sizeof(TR::RealRegister *)*TR::RealRegister::NumRegisters, heapAlloc);
self()->initializeRegisterFile();
Expand Down Expand Up @@ -385,7 +385,7 @@ void OMR::ARM64::Machine::initializeRegisterFile()
TR::RealRegister::Free,
TR::RealRegister::v9,
self()->cg());

_registerFile[TR::RealRegister::v10] = new (self()->cg()->trHeapMemory()) TR::RealRegister(TR_FPR,
0,
TR::RealRegister::Free,
Expand Down
12 changes: 6 additions & 6 deletions compiler/arm/codegen/OMRMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,17 @@ static void registerCopy(TR::Instruction *precedingI,
TR::RealRegister *sReg,
TR::CodeGenerator *cg);

OMR::ARM::Machine::Machine(TR::CodeGenerator *cg): OMR::Machine(cg, NUM_ARM_GPR, NUM_ARM_FPR)
OMR::ARM::Machine::Machine(TR::CodeGenerator *cg) :
OMR::Machine(cg)
{
self()->initializeRegisterFile();
}


TR::RealRegister *OMR::ARM::Machine::findBestFreeRegister(TR_RegisterKinds rk,
bool excludeGPR0,
bool considerUnlatched,
bool isSinglePrecision)
bool excludeGPR0,
bool considerUnlatched,
bool isSinglePrecision)
{
int first;
int last;
Expand Down Expand Up @@ -104,7 +105,7 @@ TR::RealRegister *OMR::ARM::Machine::freeBestRegister(TR::Instruction *curre
TR_RegisterKinds rk,
TR::RealRegister *forced,
bool excludeGPR0,
bool isSinglePrecision)
bool isSinglePrecision)
{
TR::Register *candidates[NUM_ARM_MAXR];
TR::Compilation *comp = self()->cg()->comp();
Expand All @@ -116,7 +117,6 @@ TR::RealRegister *OMR::ARM::Machine::freeBestRegister(TR::Instruction *curre
TR_ARMOpCodes opCode;
int numCandidates = 0;
int first, last;
//TR::RealRegister::TR_States crtemp_state;

if (forced != NULL)
{
Expand Down
26 changes: 1 addition & 25 deletions compiler/codegen/OMRMachine.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2016 IBM Corp. and others
* Copyright (c) 2000, 2018 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -33,27 +33,3 @@

#include "codegen/Machine.hpp" // for TR::Machine
#include "codegen/Machine_inlines.hpp"

uint8_t
OMR::Machine::getNumberOfGPRs()
{
return self()->getNumberOfRegisters(TR_GPR);
}

uint8_t
OMR::Machine::getNumberOfFPRs()
{
return self()->getNumberOfRegisters(TR_FPR);
}

uint8_t
OMR::Machine::setNumberOfGPRs(uint8_t numIntRegs)
{
return self()->setNumberOfRegisters(TR_GPR,numIntRegs);
}

uint8_t
OMR::Machine::setNumberOfFPRs(uint8_t numFPRegs)
{
return self()->setNumberOfRegisters(TR_FPR,numFPRegs);
}
57 changes: 3 additions & 54 deletions compiler/codegen/OMRMachine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,81 +35,30 @@ namespace OMR { typedef OMR::Machine MachineConnector; }
#include <stdint.h> // for uint8_t, uint32_t
#include "env/TRMemory.hpp" // for TR_Memory, etc
#include "infra/Annotations.hpp" // for OMR_EXTENSIBLE
#include "codegen/RegisterConstants.hpp"

namespace TR { class CodeGenerator; }
namespace TR { class RealRegister; }
namespace TR { class Machine; }

namespace OMR
{

class OMR_EXTENSIBLE Machine
{
uint8_t _numberRegisters[NumRegisterKinds];
TR_GlobalRegisterNumber _firstGlobalRegisterNumber[NumRegisterKinds];
TR_GlobalRegisterNumber _lastGlobalRegisterNumber[NumRegisterKinds];
TR_GlobalRegisterNumber _lastRealRegisterGlobalRegisterNumber;
TR_GlobalRegisterNumber _overallLastGlobalRegisterNumber;
TR::CodeGenerator *_cg;

public:
public:

TR_ALLOC(TR_Memory::Machine)

Machine() : _lastRealRegisterGlobalRegisterNumber(-1), _overallLastGlobalRegisterNumber(-1)
Machine(TR::CodeGenerator *cg) :
_cg(cg)
{
for(uint32_t i=0;i<NumRegisterKinds;i++)
{
_numberRegisters[i]=-1;
_firstGlobalRegisterNumber[i]=0;
_lastGlobalRegisterNumber[i]=-1;
}
}

// TODO: numVRFRegs should probably be explicitly set to 0 instead of defaulting to 0
Machine(TR::CodeGenerator *cg, uint8_t numIntRegs, uint8_t numFPRegs, uint8_t numVRFRegs = 0) : _lastRealRegisterGlobalRegisterNumber(-1), _overallLastGlobalRegisterNumber(-1), _cg(cg)
{
for(uint32_t i=0;i<NumRegisterKinds;i++)
{
_numberRegisters[i]=0;
_firstGlobalRegisterNumber[i]=0;
_lastGlobalRegisterNumber[i]=-1;
}
_numberRegisters[TR_GPR] = numIntRegs;
_numberRegisters[TR_FPR] = numFPRegs;
_numberRegisters[TR_VRF] = numVRFRegs; // TODO vrf gra : needs this but every platform will need to pass numVRFRegs in
}

inline TR::Machine * self();

TR::CodeGenerator *cg() {return _cg;}

uint8_t getNumberOfRegisters(TR_RegisterKinds rk) { return _numberRegisters[rk]; }

// Lets try and use the genericly named method above. These are only for backward compatibility
uint8_t getNumberOfGPRs();
uint8_t getNumberOfFPRs();

// GlobalRegisterNumbers consiste of real registers in the order of assignment preference. All register kinds combined
TR_GlobalRegisterNumber getFirstGlobalRegisterNumber(TR_RegisterKinds rk) { return _firstGlobalRegisterNumber[rk]; }
TR_GlobalRegisterNumber getLastGlobalRegisterNumber(TR_RegisterKinds rk) { return _lastGlobalRegisterNumber[rk]; }
TR_GlobalRegisterNumber getLastRealRegisterGlobalRegisterNumber() { return _lastRealRegisterGlobalRegisterNumber; }
TR_GlobalRegisterNumber getLastGlobalRegisterNumber() { return _overallLastGlobalRegisterNumber; }
virtual TR::RealRegister *getRealRegister(TR_GlobalRegisterNumber grn) {return NULL; }
TR_GlobalRegisterNumber getNextGlobalRegisterNumber() { return (++_overallLastGlobalRegisterNumber); }

protected:
// setters should only be used by specific machine class initializers

uint8_t setNumberOfRegisters(TR_RegisterKinds rk, uint8_t num) { return (_numberRegisters[rk] = num); }
uint8_t setNumberOfGPRs(uint8_t numIntRegs);
uint8_t setNumberOfFPRs(uint8_t numFPRegs);

TR_GlobalRegisterNumber setFirstGlobalRegisterNumber(TR_RegisterKinds rk, TR_GlobalRegisterNumber grn) { return (_firstGlobalRegisterNumber[rk]=grn); }
TR_GlobalRegisterNumber setLastGlobalRegisterNumber(TR_RegisterKinds rk, TR_GlobalRegisterNumber grn) { return (_lastGlobalRegisterNumber[rk]=grn); }
TR_GlobalRegisterNumber setLastRealRegisterGlobalRegisterNumber(TR_GlobalRegisterNumber grn) { _overallLastGlobalRegisterNumber=grn; return (_lastRealRegisterGlobalRegisterNumber=grn); }

};

}
Expand Down
9 changes: 5 additions & 4 deletions compiler/p/codegen/OMRMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,11 @@ static bool boundNext(TR::Instruction *currentInstruction, int32_t realNum, TR::
return true;
}

OMR::Power::Machine::Machine(TR::CodeGenerator *cg): OMR::Machine(cg, NUM_PPC_GPR, NUM_PPC_FPR),
numLockedGPRs(-1),
numLockedFPRs(-1),
numLockedVRFs(-1)
OMR::Power::Machine::Machine(TR::CodeGenerator *cg) :
OMR::Machine(cg),
numLockedGPRs(-1),
numLockedFPRs(-1),
numLockedVRFs(-1)
{
_registerFile = (TR::RealRegister **)cg->trMemory()->allocateMemory(sizeof(TR::RealRegister *)*TR::RealRegister::NumRegisters, heapAlloc);
self()->initializeRegisterFile();
Expand Down
5 changes: 3 additions & 2 deletions compiler/x/codegen/OMRMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,16 @@ OMR::X86::Machine::Machine
TR::Register **xmmGlobalRegisters,
uint32_t *globalRegisterNumberToRealRegisterMap
)
: OMR::Machine(cg, numIntRegs, numFPRegs),
: OMR::Machine(cg),
_registerFile(registerFile),
_registerAssociations(registerAssociations),
_numGlobalGPRs(numGlobalGPRs),
_numGlobal8BitGPRs(numGlobal8BitGPRs),
_numGlobalFPRs(numGlobalFPRs),
_xmmGlobalRegisters(xmmGlobalRegisters),
_globalRegisterNumberToRealRegisterMap(globalRegisterNumberToRealRegisterMap),
_spilledRegistersList(NULL)
_spilledRegistersList(NULL),
_numGPRs(numIntRegs)
{
self()->initializeFPStackRegisterFile();
_fpTopOfStack = TR_X86FPStackRegister::fpStackEmpty;
Expand Down
7 changes: 7 additions & 0 deletions compiler/x/codegen/OMRMachine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ class OMR_EXTENSIBLE Machine : public OMR::Machine
TR::RealRegister **_registerFile;
TR::Register **_registerAssociations;

/**
* Number of general purpose registers
*/
int8_t _numGPRs;

// Floating point stack pseudo-registers: they can be mapped to real
// registers on demand, based on their relative position from the top of
// stack marker.
Expand Down Expand Up @@ -135,6 +140,8 @@ class OMR_EXTENSIBLE Machine : public OMR::Machine
uint32_t* getGlobalRegisterTable(const struct TR::X86LinkageProperties&);
int32_t getGlobalReg(TR::RealRegister::RegNum reg);

uint8_t getNumberOfGPRs() { return _numGPRs; }

TR::RealRegister *getX86RealRegister(TR::RealRegister::RegNum regNum)
{
return _registerFile[regNum];
Expand Down
52 changes: 1 addition & 51 deletions compiler/z/codegen/OMRMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ OMR::Z::Machine::getGPRSize()
// Constructor

OMR::Z::Machine::Machine(TR::CodeGenerator * cg)
: OMR::Machine(cg, NUM_S390_GPR, NUM_S390_FPR, NUM_S390_VRF), _lastGlobalGPRRegisterNumber(-1), _last8BitGlobalGPRRegisterNumber(-1),
: OMR::Machine(cg), _lastGlobalGPRRegisterNumber(-1), _last8BitGlobalGPRRegisterNumber(-1),
_lastGlobalFPRRegisterNumber(-1), _lastGlobalCCRRegisterNumber(-1), _lastVolatileNonLinkGPR(-1), _lastLinkageGPR(-1),
_lastVolatileNonLinkFPR(-1), _lastLinkageFPR(-1), _firstGlobalAccessRegisterNumber(-1), _lastGlobalAccessRegisterNumber(-1), _globalEnvironmentRegisterNumber(-1), _globalCAARegisterNumber(-1), _globalParentDSARegisterNumber(-1),
_globalReturnAddressRegisterNumber(-1),_globalEntryPointRegisterNumber(-1)
Expand Down Expand Up @@ -5976,42 +5976,6 @@ OMR::Z::Machine::coerceRegisterAssignment(TR::Instruction
return cursor;
}

uint64_t OMR::Z::Machine::filterColouredRegisterConflicts(TR::Register *targetRegister, TR::Register *siblingRegister,
TR::Instruction *currInst)
{
uint64_t mask=0xffffffff;
TR::Compilation *comp = self()->cg()->comp();
TR::list<TR::Register *> conflictRegs(getTypedAllocator<TR::Register*>(comp->allocator()));

if(currInst->defsAnyRegister(targetRegister))
{
currInst->getDefinedRegisters(conflictRegs);
for(auto reg = conflictRegs.begin(); reg != conflictRegs.end(); ++reg)
{
TR::Register *cr=(*reg)->getRealRegister() ? NULL : (*reg)->getAssignedRegister();
if (cr && targetRegister != (*reg) && (*reg)->getAssignedRegister() != targetRegister &&
(siblingRegister == NULL || (*reg) != siblingRegister))
{
mask &= ~toRealRegister(cr)->getRealRegisterMask();
}
}
}

currInst->getUsedRegisters(conflictRegs);
for(auto reg = conflictRegs.begin(); reg != conflictRegs.end(); ++reg)
{
TR::Register *cr=(*reg)->getRealRegister() ? NULL : (*reg)->getAssignedRegister();
if (cr && targetRegister != (*reg) && (*reg)->getAssignedRegister() != targetRegister &&
(siblingRegister == NULL || (*reg) != siblingRegister))
{
mask &= ~toRealRegister(cr)->getRealRegisterMask();
}
}

return mask;

}


////////////////////////////////////////////////////////////////////////////////
// OMR::Z::Machine::initializeRegisterFile
Expand Down Expand Up @@ -6759,7 +6723,6 @@ OMR::Z::Machine::initializeGlobalRegisterTable()
}
}

self()->setLastRealRegisterGlobalRegisterNumber(p-1);
self()->setLastGlobalCCRRegisterNumber(p-1);

return _globalRegisterNumberToRealRegisterMap;
Expand Down Expand Up @@ -6895,8 +6858,6 @@ OMR::Z::Machine::initializeGlobalRegisterTable()
self()->setLastLinkageFPR(41);
#endif

self()->setLastRealRegisterGlobalRegisterNumber(41);

self()->setLastGlobalFPRRegisterNumber(41); // Index of last global FPR
self()->setLastGlobalCCRRegisterNumber(41); // Index of last global CCR

Expand Down Expand Up @@ -7078,79 +7039,68 @@ OMR::Z::Machine::releaseLiteralPoolRegister()
TR_GlobalRegisterNumber
OMR::Z::Machine::setFirstGlobalAccessRegisterNumber(TR_GlobalRegisterNumber reg)
{
self()->setFirstGlobalRegisterNumber(TR_AR,reg);
return _firstGlobalAccessRegisterNumber = reg;
}

TR_GlobalRegisterNumber
OMR::Z::Machine::setLastGlobalAccessRegisterNumber(TR_GlobalRegisterNumber reg)
{
self()->setLastGlobalRegisterNumber(TR_AR,reg);
return _lastGlobalAccessRegisterNumber = reg;
}

TR_GlobalRegisterNumber
OMR::Z::Machine::setLastGlobalGPRRegisterNumber(TR_GlobalRegisterNumber reg)
{
self()->setLastGlobalRegisterNumber(TR_GPR,reg);
return _lastGlobalGPRRegisterNumber = reg;
}

TR_GlobalRegisterNumber
OMR::Z::Machine::setLastGlobalHPRRegisterNumber(TR_GlobalRegisterNumber reg)
{
self()->setLastGlobalRegisterNumber(TR_HPR,reg);
return _lastGlobalHPRRegisterNumber = reg;
}

TR_GlobalRegisterNumber
OMR::Z::Machine::setFirstGlobalGPRRegisterNumber(TR_GlobalRegisterNumber reg)
{
self()->setFirstGlobalRegisterNumber(TR_GPR,reg);
return _firstGlobalGPRRegisterNumber = reg;
}

TR_GlobalRegisterNumber
OMR::Z::Machine::setFirstGlobalHPRRegisterNumber(TR_GlobalRegisterNumber reg)
{
self()->setFirstGlobalRegisterNumber(TR_HPR,reg);
return _firstGlobalHPRRegisterNumber = reg;
}

TR_GlobalRegisterNumber
OMR::Z::Machine::setFirstGlobalFPRRegisterNumber(TR_GlobalRegisterNumber reg)
{
self()->setFirstGlobalRegisterNumber(TR_FPR, reg);
self()->setFirstOverlappedGlobalFPRRegisterNumber(reg);
return _firstGlobalFPRRegisterNumber = reg;
}

TR_GlobalRegisterNumber
OMR::Z::Machine::setLastGlobalFPRRegisterNumber(TR_GlobalRegisterNumber reg)
{
self()->setLastGlobalRegisterNumber(TR_FPR,reg);
self()->setLastOverlappedGlobalFPRRegisterNumber(reg);
return _lastGlobalFPRRegisterNumber = reg;
}

TR_GlobalRegisterNumber
OMR::Z::Machine::setFirstGlobalVRFRegisterNumber(TR_GlobalRegisterNumber reg)
{
self()->setFirstGlobalRegisterNumber(TR_VRF,reg);
return _firstGlobalVRFRegisterNumber = reg;
}

TR_GlobalRegisterNumber
OMR::Z::Machine::setLastGlobalVRFRegisterNumber(TR_GlobalRegisterNumber reg)
{
self()->setLastGlobalRegisterNumber(TR_VRF,reg);
return _lastGlobalVRFRegisterNumber = reg;
}

TR_GlobalRegisterNumber
OMR::Z::Machine::setLastGlobalCCRRegisterNumber(TR_GlobalRegisterNumber reg)
{
self()->setLastGlobalRegisterNumber(TR_CCR,reg);
return _lastGlobalCCRRegisterNumber=reg;
}

Expand Down
Loading

0 comments on commit 9c8787d

Please sign in to comment.