Skip to content

Commit e3c0948

Browse files
author
Bob McWhirter
committed
Cleanup on aisle aarch64.
Renaming methods to better match what they do. Renaming classes to better express what they do.
1 parent bfbc827 commit e3c0948

File tree

4 files changed

+39
-38
lines changed

4 files changed

+39
-38
lines changed

compiler/src/org.graalvm.compiler.asm.aarch64/src/org/graalvm/compiler/asm/aarch64/AArch64Assembler.java

100644100755
Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2963,17 +2963,17 @@ public void msr(SystemRegister systemRegister, Register src) {
29632963

29642964
public void annotatePatchingImmediate(int pos, Instruction instruction, int operandSizeBits, int offsetBits, int shift) {
29652965
if (codePatchingAnnotationConsumer != null) {
2966-
codePatchingAnnotationConsumer.accept(new OperandDataAnnotation(pos, instruction, operandSizeBits, offsetBits, shift));
2966+
codePatchingAnnotationConsumer.accept(new SingleInstructionAnnotation(pos, instruction, operandSizeBits, offsetBits, shift));
29672967
}
29682968
}
29692969

2970-
void annotatePatchingImmediateNativeAddress(int pos, int operandSizeBits, int numInstrs) {
2970+
void annotateImmediateMovSequence(int pos, int numInstrs) {
29712971
if (codePatchingAnnotationConsumer != null) {
2972-
codePatchingAnnotationConsumer.accept(new MovSequenceAnnotation(pos, operandSizeBits, numInstrs));
2972+
codePatchingAnnotationConsumer.accept(new MovSequenceAnnotation(pos, numInstrs));
29732973
}
29742974
}
29752975

2976-
public static class OperandDataAnnotation extends CodeAnnotation {
2976+
public static class SingleInstructionAnnotation extends CodeAnnotation {
29772977

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

2986-
OperandDataAnnotation(int instructionPosition, Instruction instruction, int operandSizeBits, int offsetBits, int shift) {
2986+
SingleInstructionAnnotation(int instructionPosition, Instruction instruction, int operandSizeBits, int offsetBits, int shift) {
29872987
super(instructionPosition);
29882988
this.operandSizeBits = operandSizeBits;
29892989
this.offsetBits = offsetBits;
@@ -2997,12 +2997,10 @@ public static class MovSequenceAnnotation extends CodeAnnotation {
29972997
/**
29982998
* The size of the operand, in bytes.
29992999
*/
3000-
public final int operandSizeBits;
30013000
public final int numInstrs;
30023001

3003-
MovSequenceAnnotation(int instructionPosition, int operandSizeBits, int numInstrs) {
3002+
MovSequenceAnnotation(int instructionPosition, int numInstrs) {
30043003
super(instructionPosition);
3005-
this.operandSizeBits = operandSizeBits;
30063004
this.numInstrs = numInstrs;
30073005
}
30083006
}

compiler/src/org.graalvm.compiler.asm.aarch64/src/org/graalvm/compiler/asm/aarch64/AArch64MacroAssembler.java

100644100755
Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -339,10 +339,13 @@ public void mov(int size, Register dst, Register src) {
339339
* Generates a 64-bit immediate move code sequence.
340340
*
341341
* @param dst general purpose register. May not be null, stackpointer or zero-register.
342-
* @param imm
342+
* @param imm the value to move into the register
343+
* @param annotateImm Flag denoting if annotation should be added.
343344
*/
344-
private void mov64(Register dst, long imm) {
345+
private void mov64(Register dst, long imm, boolean annotateImm) {
345346
// We have to move all non zero parts of the immediate in 16-bit chunks
347+
int numMovs = 0;
348+
int pos = position();
346349
boolean firstMove = true;
347350
for (int offset = 0; offset < 64; offset += 16) {
348351
int chunk = (int) (imm >> offset) & NumUtil.getNbitNumberInt(16);
@@ -355,8 +358,12 @@ private void mov64(Register dst, long imm) {
355358
} else {
356359
movk(64, dst, chunk, offset);
357360
}
361+
++numMovs;
358362
}
359363
assert !firstMove;
364+
if (annotateImm) {
365+
annotateImmediateMovSequence(pos, numMovs);
366+
}
360367
}
361368

362369
/**
@@ -378,7 +385,6 @@ public void mov(Register dst, long imm) {
378385
*/
379386
public void mov(Register dst, long imm, boolean annotateImm) {
380387
assert dst.getRegisterCategory().equals(CPU);
381-
int pos = position();
382388
if (imm == 0L) {
383389
movx(dst, zr);
384390
} else if (LogicalImmediateTable.isRepresentable(true, imm) != LogicalImmediateTable.Representable.NO) {
@@ -391,10 +397,7 @@ public void mov(Register dst, long imm, boolean annotateImm) {
391397
mov(dst, (int) imm);
392398
sxt(64, 32, dst, dst);
393399
} else {
394-
mov64(dst, imm);
395-
if (annotateImm) {
396-
annotatePatchingImmediateNativeAddress(pos, 64, 4);
397-
}
400+
mov64(dst, imm, annotateImm);
398401
}
399402
}
400403

@@ -448,7 +451,7 @@ public void movNativeAddress(Register dst, long imm, boolean annotateImm) {
448451
}
449452
}
450453
if (annotateImm) {
451-
annotatePatchingImmediateNativeAddress(pos, 48, 3);
454+
annotateImmediateMovSequence(pos, 3);
452455
}
453456
assert !firstMove;
454457
}
@@ -1805,24 +1808,24 @@ public interface MacroInstruction {
18051808
}
18061809

18071810
/**
1808-
* Emits elf patchable adrp add sequence.
1811+
* Emits elf patchable adrp ldr sequence.
18091812
*/
1810-
public void adrAddRel(int srcSize, Register result, AArch64Address a) {
1813+
public void adrpLdr(int srcSize, Register result, AArch64Address a) {
18111814
if (codePatchingAnnotationConsumer != null) {
1812-
codePatchingAnnotationConsumer.accept(new ADRADDPRELMacroInstruction(position()));
1815+
codePatchingAnnotationConsumer.accept(new AdrpLdrMacroInstruction(position()));
18131816
}
18141817
super.adrp(a.getBase());
18151818
this.ldr(srcSize, result, a);
18161819
}
18171820

1818-
public static class ADRADDPRELMacroInstruction extends CodeAnnotation implements MacroInstruction {
1819-
public ADRADDPRELMacroInstruction(int position) {
1821+
public static class AdrpLdrMacroInstruction extends CodeAnnotation implements MacroInstruction {
1822+
public AdrpLdrMacroInstruction(int position) {
18201823
super(position);
18211824
}
18221825

18231826
@Override
18241827
public String toString() {
1825-
return "ADR_PREL_PG";
1828+
return "ADRP_LDR";
18261829
}
18271830

18281831
@Override

substratevm/src/com.oracle.svm.core.graal/src/com/oracle/svm/core/graal/code/aarch64/AArch64CGlobalDataLoadAddressOp.java

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public void emitCode(CompilationResultBuilder crb, AArch64MacroAssembler masm) {
6464
// Pure symbol reference: the data contains the symbol's address, load it
6565
Register resultRegister = asRegister(result);
6666
AArch64Address address = AArch64Address.createScaledImmediateAddress(resultRegister, 0x0);
67-
masm.adrAddRel(64, resultRegister, address);
67+
masm.adrpLdr(64, resultRegister, address);
6868
crb.compilationResult.recordDataPatch(before, new CGlobalDataReference(dataInfo));
6969
} else {
7070
// Data: load its address
Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
import org.graalvm.compiler.asm.Assembler.CodeAnnotation;
3030
import org.graalvm.compiler.asm.aarch64.AArch64Assembler;
31-
import org.graalvm.compiler.asm.aarch64.AArch64Assembler.OperandDataAnnotation;
31+
import org.graalvm.compiler.asm.aarch64.AArch64Assembler.SingleInstructionAnnotation;
3232
import org.graalvm.compiler.asm.aarch64.AArch64MacroAssembler;
3333
import org.graalvm.compiler.code.CompilationResult;
3434
import org.graalvm.nativeimage.hosted.Feature;
@@ -62,12 +62,12 @@ public Consumer<CodeAnnotation> newConsumer(CompilationResult compilationResult)
6262
return new Consumer<CodeAnnotation>() {
6363
@Override
6464
public void accept(CodeAnnotation annotation) {
65-
if (annotation instanceof OperandDataAnnotation) {
66-
compilationResult.addAnnotation(new AArch64HostedPatcher(annotation.instructionPosition, (OperandDataAnnotation) annotation));
65+
if (annotation instanceof SingleInstructionAnnotation) {
66+
compilationResult.addAnnotation(new SingleInstructionHostedPatcher(annotation.instructionPosition, (SingleInstructionAnnotation) annotation));
6767
} else if (annotation instanceof AArch64Assembler.MovSequenceAnnotation) {
68-
compilationResult.addAnnotation(new AArch64MovSequenceHostedPatcher(annotation.instructionPosition, (AArch64Assembler.MovSequenceAnnotation) annotation));
69-
} else if (annotation instanceof AArch64MacroAssembler.ADRADDPRELMacroInstruction) {
70-
compilationResult.addAnnotation(new ADRADDPRELMacroInstructionHostedPatcher((AArch64MacroAssembler.ADRADDPRELMacroInstruction) annotation));
68+
compilationResult.addAnnotation(new MovSequenceHostedPatcher(annotation.instructionPosition, (AArch64Assembler.MovSequenceAnnotation) annotation));
69+
} else if (annotation instanceof AArch64MacroAssembler.AdrpLdrMacroInstruction) {
70+
compilationResult.addAnnotation(new AdrpLdrMacroInstructionHostedPatcher((AArch64MacroAssembler.AdrpLdrMacroInstruction) annotation));
7171
} else if (annotation instanceof AArch64MacroAssembler.AdrpAddMacroInstruction) {
7272
compilationResult.addAnnotation(new AdrpAddMacroInstructionHostedPatcher((AArch64MacroAssembler.AdrpAddMacroInstruction) annotation));
7373
}
@@ -78,10 +78,10 @@ public void accept(CodeAnnotation annotation) {
7878
}
7979
}
8080

81-
public class AArch64HostedPatcher extends CompilationResult.CodeAnnotation implements HostedPatcher {
82-
private final OperandDataAnnotation annotation;
81+
public class SingleInstructionHostedPatcher extends CompilationResult.CodeAnnotation implements HostedPatcher {
82+
private final SingleInstructionAnnotation annotation;
8383

84-
public AArch64HostedPatcher(int instructionStartPosition, OperandDataAnnotation annotation) {
84+
public SingleInstructionHostedPatcher(int instructionStartPosition, SingleInstructionAnnotation annotation) {
8585
super(instructionStartPosition);
8686
this.annotation = annotation;
8787
}
@@ -145,10 +145,10 @@ public void relocate(Reference ref, RelocatableBuffer relocs, int compStart) {
145145
}
146146
}
147147

148-
class ADRADDPRELMacroInstructionHostedPatcher extends CompilationResult.CodeAnnotation implements HostedPatcher {
149-
private final AArch64MacroAssembler.ADRADDPRELMacroInstruction macroInstruction;
148+
class AdrpLdrMacroInstructionHostedPatcher extends CompilationResult.CodeAnnotation implements HostedPatcher {
149+
private final AArch64MacroAssembler.AdrpLdrMacroInstruction macroInstruction;
150150

151-
ADRADDPRELMacroInstructionHostedPatcher(AArch64MacroAssembler.ADRADDPRELMacroInstruction macroInstruction) {
151+
AdrpLdrMacroInstructionHostedPatcher(AArch64MacroAssembler.AdrpLdrMacroInstruction macroInstruction) {
152152
super(macroInstruction.instructionPosition);
153153
this.macroInstruction = macroInstruction;
154154
}
@@ -201,10 +201,10 @@ public boolean equals(Object obj) {
201201
}
202202
}
203203

204-
class AArch64MovSequenceHostedPatcher extends CompilationResult.CodeAnnotation implements HostedPatcher {
204+
class MovSequenceHostedPatcher extends CompilationResult.CodeAnnotation implements HostedPatcher {
205205
private final AArch64Assembler.MovSequenceAnnotation annotation;
206206

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

218-
int bitsRemaining = annotation.operandSizeBits;
218+
int bitsRemaining = annotation.numInstrs * 8;
219219

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

0 commit comments

Comments
 (0)