Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -2963,17 +2963,17 @@ public void msr(SystemRegister systemRegister, Register src) {

public void annotatePatchingImmediate(int pos, Instruction instruction, int operandSizeBits, int offsetBits, int shift) {
if (codePatchingAnnotationConsumer != null) {
codePatchingAnnotationConsumer.accept(new OperandDataAnnotation(pos, instruction, operandSizeBits, offsetBits, shift));
codePatchingAnnotationConsumer.accept(new SingleInstructionAnnotation(pos, instruction, operandSizeBits, offsetBits, shift));
}
}

void annotatePatchingImmediateNativeAddress(int pos, int operandSizeBits, int numInstrs) {
void annotateImmediateMovSequence(int pos, int numInstrs) {
if (codePatchingAnnotationConsumer != null) {
codePatchingAnnotationConsumer.accept(new MovSequenceAnnotation(pos, operandSizeBits, numInstrs));
codePatchingAnnotationConsumer.accept(new MovSequenceAnnotation(pos, numInstrs));
}
}

public static class OperandDataAnnotation extends CodeAnnotation {
public static class SingleInstructionAnnotation extends CodeAnnotation {

/**
* The size of the operand, in bytes.
Expand All @@ -2983,7 +2983,7 @@ public static class OperandDataAnnotation extends CodeAnnotation {
public final Instruction instruction;
public final int shift;

OperandDataAnnotation(int instructionPosition, Instruction instruction, int operandSizeBits, int offsetBits, int shift) {
SingleInstructionAnnotation(int instructionPosition, Instruction instruction, int operandSizeBits, int offsetBits, int shift) {
super(instructionPosition);
this.operandSizeBits = operandSizeBits;
this.offsetBits = offsetBits;
Expand All @@ -2997,12 +2997,10 @@ public static class MovSequenceAnnotation extends CodeAnnotation {
/**
* The size of the operand, in bytes.
*/
public final int operandSizeBits;
public final int numInstrs;

MovSequenceAnnotation(int instructionPosition, int operandSizeBits, int numInstrs) {
MovSequenceAnnotation(int instructionPosition, int numInstrs) {
super(instructionPosition);
this.operandSizeBits = operandSizeBits;
this.numInstrs = numInstrs;
}
}
Expand Down
31 changes: 17 additions & 14 deletions ...alvm.compiler.asm.aarch64/src/org/graalvm/compiler/asm/aarch64/AArch64MacroAssembler.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -339,10 +339,13 @@ public void mov(int size, Register dst, Register src) {
* Generates a 64-bit immediate move code sequence.
*
* @param dst general purpose register. May not be null, stackpointer or zero-register.
* @param imm
* @param imm the value to move into the register
* @param annotateImm Flag denoting if annotation should be added.
*/
private void mov64(Register dst, long imm) {
private void mov64(Register dst, long imm, boolean annotateImm) {
// We have to move all non zero parts of the immediate in 16-bit chunks
int numMovs = 0;
int pos = position();
boolean firstMove = true;
for (int offset = 0; offset < 64; offset += 16) {
int chunk = (int) (imm >> offset) & NumUtil.getNbitNumberInt(16);
Expand All @@ -355,8 +358,12 @@ private void mov64(Register dst, long imm) {
} else {
movk(64, dst, chunk, offset);
}
++numMovs;
}
assert !firstMove;
if (annotateImm) {
annotateImmediateMovSequence(pos, numMovs);
}
}

/**
Expand All @@ -378,7 +385,6 @@ public void mov(Register dst, long imm) {
*/
public void mov(Register dst, long imm, boolean annotateImm) {
assert dst.getRegisterCategory().equals(CPU);
int pos = position();
if (imm == 0L) {
movx(dst, zr);
} else if (LogicalImmediateTable.isRepresentable(true, imm) != LogicalImmediateTable.Representable.NO) {
Expand All @@ -391,10 +397,7 @@ public void mov(Register dst, long imm, boolean annotateImm) {
mov(dst, (int) imm);
sxt(64, 32, dst, dst);
} else {
mov64(dst, imm);
if (annotateImm) {
annotatePatchingImmediateNativeAddress(pos, 64, 4);
}
mov64(dst, imm, annotateImm);
}
}

Expand Down Expand Up @@ -448,7 +451,7 @@ public void movNativeAddress(Register dst, long imm, boolean annotateImm) {
}
}
if (annotateImm) {
annotatePatchingImmediateNativeAddress(pos, 48, 3);
annotateImmediateMovSequence(pos, 3);
}
assert !firstMove;
}
Expand Down Expand Up @@ -1805,24 +1808,24 @@ public interface MacroInstruction {
}

/**
* Emits elf patchable adrp add sequence.
* Emits elf patchable adrp ldr sequence.
*/
public void adrAddRel(int srcSize, Register result, AArch64Address a) {
public void adrpLdr(int srcSize, Register result, AArch64Address a) {
if (codePatchingAnnotationConsumer != null) {
codePatchingAnnotationConsumer.accept(new ADRADDPRELMacroInstruction(position()));
codePatchingAnnotationConsumer.accept(new AdrpLdrMacroInstruction(position()));
}
super.adrp(a.getBase());
this.ldr(srcSize, result, a);
}

public static class ADRADDPRELMacroInstruction extends CodeAnnotation implements MacroInstruction {
public ADRADDPRELMacroInstruction(int position) {
public static class AdrpLdrMacroInstruction extends CodeAnnotation implements MacroInstruction {
public AdrpLdrMacroInstruction(int position) {
super(position);
}

@Override
public String toString() {
return "ADR_PREL_PG";
return "ADRP_LDR";
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void emitCode(CompilationResultBuilder crb, AArch64MacroAssembler masm) {
// Pure symbol reference: the data contains the symbol's address, load it
Register resultRegister = asRegister(result);
AArch64Address address = AArch64Address.createScaledImmediateAddress(resultRegister, 0x0);
masm.adrAddRel(64, resultRegister, address);
masm.adrpLdr(64, resultRegister, address);
crb.compilationResult.recordDataPatch(before, new CGlobalDataReference(dataInfo));
} else {
// Data: load its address
Expand Down
30 changes: 15 additions & 15 deletions ...ed/code/aarch64/AArch64HostedPatcher.java → ...rch64/SingleInstructionHostedPatcher.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

import org.graalvm.compiler.asm.Assembler.CodeAnnotation;
import org.graalvm.compiler.asm.aarch64.AArch64Assembler;
import org.graalvm.compiler.asm.aarch64.AArch64Assembler.OperandDataAnnotation;
import org.graalvm.compiler.asm.aarch64.AArch64Assembler.SingleInstructionAnnotation;
import org.graalvm.compiler.asm.aarch64.AArch64MacroAssembler;
import org.graalvm.compiler.code.CompilationResult;
import org.graalvm.nativeimage.hosted.Feature;
Expand Down Expand Up @@ -62,12 +62,12 @@ public Consumer<CodeAnnotation> newConsumer(CompilationResult compilationResult)
return new Consumer<CodeAnnotation>() {
@Override
public void accept(CodeAnnotation annotation) {
if (annotation instanceof OperandDataAnnotation) {
compilationResult.addAnnotation(new AArch64HostedPatcher(annotation.instructionPosition, (OperandDataAnnotation) annotation));
if (annotation instanceof SingleInstructionAnnotation) {
compilationResult.addAnnotation(new SingleInstructionHostedPatcher(annotation.instructionPosition, (SingleInstructionAnnotation) annotation));
} else if (annotation instanceof AArch64Assembler.MovSequenceAnnotation) {
compilationResult.addAnnotation(new AArch64MovSequenceHostedPatcher(annotation.instructionPosition, (AArch64Assembler.MovSequenceAnnotation) annotation));
} else if (annotation instanceof AArch64MacroAssembler.ADRADDPRELMacroInstruction) {
compilationResult.addAnnotation(new ADRADDPRELMacroInstructionHostedPatcher((AArch64MacroAssembler.ADRADDPRELMacroInstruction) annotation));
compilationResult.addAnnotation(new MovSequenceHostedPatcher(annotation.instructionPosition, (AArch64Assembler.MovSequenceAnnotation) annotation));
} else if (annotation instanceof AArch64MacroAssembler.AdrpLdrMacroInstruction) {
compilationResult.addAnnotation(new AdrpLdrMacroInstructionHostedPatcher((AArch64MacroAssembler.AdrpLdrMacroInstruction) annotation));
} else if (annotation instanceof AArch64MacroAssembler.AdrpAddMacroInstruction) {
compilationResult.addAnnotation(new AdrpAddMacroInstructionHostedPatcher((AArch64MacroAssembler.AdrpAddMacroInstruction) annotation));
}
Expand All @@ -78,10 +78,10 @@ public void accept(CodeAnnotation annotation) {
}
}

public class AArch64HostedPatcher extends CompilationResult.CodeAnnotation implements HostedPatcher {
private final OperandDataAnnotation annotation;
public class SingleInstructionHostedPatcher extends CompilationResult.CodeAnnotation implements HostedPatcher {
private final SingleInstructionAnnotation annotation;

public AArch64HostedPatcher(int instructionStartPosition, OperandDataAnnotation annotation) {
public SingleInstructionHostedPatcher(int instructionStartPosition, SingleInstructionAnnotation annotation) {
super(instructionStartPosition);
this.annotation = annotation;
}
Expand Down Expand Up @@ -145,10 +145,10 @@ public void relocate(Reference ref, RelocatableBuffer relocs, int compStart) {
}
}

class ADRADDPRELMacroInstructionHostedPatcher extends CompilationResult.CodeAnnotation implements HostedPatcher {
private final AArch64MacroAssembler.ADRADDPRELMacroInstruction macroInstruction;
class AdrpLdrMacroInstructionHostedPatcher extends CompilationResult.CodeAnnotation implements HostedPatcher {
private final AArch64MacroAssembler.AdrpLdrMacroInstruction macroInstruction;

ADRADDPRELMacroInstructionHostedPatcher(AArch64MacroAssembler.ADRADDPRELMacroInstruction macroInstruction) {
AdrpLdrMacroInstructionHostedPatcher(AArch64MacroAssembler.AdrpLdrMacroInstruction macroInstruction) {
super(macroInstruction.instructionPosition);
this.macroInstruction = macroInstruction;
}
Expand Down Expand Up @@ -201,10 +201,10 @@ public boolean equals(Object obj) {
}
}

class AArch64MovSequenceHostedPatcher extends CompilationResult.CodeAnnotation implements HostedPatcher {
class MovSequenceHostedPatcher extends CompilationResult.CodeAnnotation implements HostedPatcher {
private final AArch64Assembler.MovSequenceAnnotation annotation;

AArch64MovSequenceHostedPatcher(int instructionStartPosition, AArch64Assembler.MovSequenceAnnotation annotation) {
MovSequenceHostedPatcher(int instructionStartPosition, AArch64Assembler.MovSequenceAnnotation annotation) {
super(instructionStartPosition);
this.annotation = annotation;
}
Expand All @@ -215,7 +215,7 @@ public void patch(int codePos, int relative, byte[] code) {
int curValue = relative - (4 * annotation.numInstrs); // n 32-bit instrs to patch n 16-bit
// movs

int bitsRemaining = annotation.operandSizeBits;
int bitsRemaining = annotation.numInstrs * 8;

for (int i = 0; i < 4 * annotation.numInstrs; i = i + 4) {
if (bitsRemaining >= 8) {
Expand Down