Skip to content

Commit

Permalink
Merge pull request #4589 from Akira1Saitoh/aarch64AddRelocationMetaDa…
Browse files Browse the repository at this point in the history
…taToAConst2

AArch64: Add AOT relocation to address constant
  • Loading branch information
knn-k authored Jan 7, 2020
2 parents 4d5712b + 95dacb0 commit 99d05d8
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 4 deletions.
12 changes: 12 additions & 0 deletions compiler/aarch64/codegen/OMRCodeGenerator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ namespace OMR { typedef OMR::ARM64::CodeGenerator CodeGeneratorConnector; }

#include "codegen/RegisterConstants.hpp"
#include "infra/Annotations.hpp"
#include "runtime/Runtime.hpp"

class TR_ARM64OutOfLineCodeSection;
namespace TR { class ARM64LinkageProperties; }
Expand All @@ -63,6 +64,17 @@ extern TR::Instruction *loadConstant64(TR::CodeGenerator *cg, TR::Node *node, in

extern TR::Instruction *loadAddressConstant(TR::CodeGenerator *cg, TR::Node *node, intptr_t value, TR::Register *trgReg, TR::Instruction *cursor=NULL, bool isPicSite=false, int16_t typeAddress=-1);

/* @brief Generates instruction for loading address constant to register using constant data snippet
* @param[in] cg : CodeGenerator
* @param[in] node: node
* @param[in] address : address
* @param[in] trgReg : target register
* @param[in] reloKind : relocation kind
* @param[in] cursor : instruction cursor
* @return generated instruction
*/
extern TR::Instruction *loadAddressConstantInSnippet(TR::CodeGenerator *cg, TR::Node *node, intptrj_t address, TR::Register *trgReg, TR_ExternalRelocationTargetKind reloKind, TR::Instruction *cursor=NULL);

/**
* @brief Helper function for encoding immediate value of logic instructions.
* @param[in] value : immediate value to encode
Expand Down
10 changes: 10 additions & 0 deletions compiler/aarch64/codegen/OMRTreeEvaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "codegen/ARM64Instruction.hpp"
#include "codegen/ARM64ShiftCode.hpp"
#include "codegen/CodeGenerator.hpp"
#include "codegen/ConstantDataSnippet.hpp"
#include "codegen/GenerateInstructions.hpp"
#include "codegen/Linkage.hpp"
#include "codegen/Linkage_inlines.hpp"
Expand All @@ -36,6 +37,15 @@
#include "il/ParameterSymbol.hpp"
#include "il/StaticSymbol.hpp"

TR::Instruction *loadAddressConstantInSnippet(TR::CodeGenerator *cg, TR::Node *node, intptrj_t address, TR::Register *targetRegister, TR_ExternalRelocationTargetKind reloKind, TR::Instruction *cursor)
{
// We use LDR literal to load a value from the snippet. Offset to PC will be patched by LabelRelative24BitRelocation
auto snippet = cg->findOrCreate8ByteConstant(node, address);
auto labelSym = snippet->getSnippetLabel();
snippet->setReloType(reloKind);
return generateTrg1ImmSymInstruction(cg, TR::InstOpCode::ldrx, node, targetRegister, 0, labelSym, cursor);
}

TR::Instruction *loadConstant32(TR::CodeGenerator *cg, TR::Node *node, int32_t value, TR::Register *trgReg, TR::Instruction *cursor)
{
TR::Instruction *insertingInstructions = cursor;
Expand Down
28 changes: 24 additions & 4 deletions compiler/aarch64/codegen/UnaryEvaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
*******************************************************************************/

#include "codegen/CodeGenerator.hpp"
#include "codegen/ConstantDataSnippet.hpp"
#include "codegen/GenerateInstructions.hpp"
#include "codegen/TreeEvaluator.hpp"
#include "il/Node.hpp"
Expand Down Expand Up @@ -55,10 +56,29 @@ TR::Register *OMR::ARM64::TreeEvaluator::cconstEvaluator(TR::Node *node, TR::Cod

TR::Register *OMR::ARM64::TreeEvaluator::aconstEvaluator(TR::Node *node, TR::CodeGenerator *cg)
{
TR::Register *tempReg = cg->allocateRegister();
intptrj_t address = node->getLongInt();
loadConstant64(cg, node, address, tempReg);
return node->setRegister(tempReg);
if (cg->profiledPointersRequireRelocation() &&
(node->isMethodPointerConstant() || node->isClassPointerConstant()))
{
TR::Register *trgReg = node->setRegister(cg->allocateRegister());
TR_ExternalRelocationTargetKind reloKind = TR_NoRelocation;
if (node->isMethodPointerConstant())
{
reloKind = TR_MethodPointer;
if (node->getInlinedSiteIndex() == -1)
reloKind = TR_RamMethod;
}
else if (node->isClassPointerConstant())
reloKind = TR_ClassPointer;

TR_ASSERT(reloKind != TR_NoRelocation, "relocation kind shouldn't be TR_NoRelocation");
loadAddressConstantInSnippet(cg, node, node->getAddress(), trgReg, reloKind);

return trgReg;
}

TR::Register *tempReg = node->setRegister(cg->allocateRegister());
loadConstant64(cg, node, node->getAddress(), tempReg, NULL);
return tempReg;
}

TR::Register *OMR::ARM64::TreeEvaluator::lconstEvaluator(TR::Node *node, TR::CodeGenerator *cg)
Expand Down

0 comments on commit 99d05d8

Please sign in to comment.