Skip to content

Commit c43c930

Browse files
author
Jim Grosbach
committed
Implement a few more binary encoding bits. Still very early stage proof-of-
concept level stuff at this point, but it is generally working for those instructions that know how to map the operands. This patch fills in the register operands for add/sub/or/etc instructions and adds the conditional execution predicate encoding. llvm-svn: 116112
1 parent 2a14088 commit c43c930

File tree

3 files changed

+58
-1
lines changed

3 files changed

+58
-1
lines changed

llvm/lib/Target/ARM/ARMInstrInfo.td

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,9 +481,17 @@ multiclass AsI1_bin_irs<bits<4> opcod, string opc,
481481
def rr : AsI1<opcod, (outs GPR:$dst), (ins GPR:$a, GPR:$b), DPFrm,
482482
iir, opc, "\t$dst, $a, $b",
483483
[(set GPR:$dst, (opnode GPR:$a, GPR:$b))]> {
484+
bits<4> Rd;
485+
bits<4> Rn;
486+
bits<4> Rm;
487+
bits<4> Cond;
484488
let Inst{11-4} = 0b00000000;
485489
let Inst{25} = 0;
486490
let isCommutable = Commutable;
491+
let Inst{3-0} = Rm;
492+
let Inst{15-12} = Rd;
493+
let Inst{19-16} = Rn;
494+
let Inst{31-28} = Cond;
487495
}
488496
def rs : AsI1<opcod, (outs GPR:$dst), (ins GPR:$a, so_reg:$b), DPSoRegFrm,
489497
iis, opc, "\t$dst, $a, $b",
@@ -907,20 +915,24 @@ let isReturn = 1, isTerminator = 1, isBarrier = 1 in {
907915
def BX_RET : AI<(outs), (ins), BrMiscFrm, IIC_Br,
908916
"bx", "\tlr", [(ARMretflag)]>,
909917
Requires<[IsARM, HasV4T]> {
918+
bits<4> Cond;
910919
let Inst{3-0} = 0b1110;
911920
let Inst{7-4} = 0b0001;
912921
let Inst{19-8} = 0b111111111111;
913922
let Inst{27-20} = 0b00010010;
923+
let Inst{31-28} = Cond;
914924
}
915925

916926
// ARMV4 only
917927
def MOVPCLR : AI<(outs), (ins), BrMiscFrm, IIC_Br,
918928
"mov", "\tpc, lr", [(ARMretflag)]>,
919929
Requires<[IsARM, NoV4T]> {
930+
bits<4> Cond;
920931
let Inst{11-0} = 0b000000001110;
921932
let Inst{15-12} = 0b1111;
922933
let Inst{19-16} = 0b0000;
923934
let Inst{27-20} = 0b00011010;
935+
let Inst{31-28} = Cond;
924936
}
925937
}
926938

@@ -930,21 +942,27 @@ let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in {
930942
def BRIND : AXI<(outs), (ins GPR:$dst), BrMiscFrm, IIC_Br, "bx\t$dst",
931943
[(brind GPR:$dst)]>,
932944
Requires<[IsARM, HasV4T]> {
945+
bits<4> Rm;
946+
933947
let Inst{7-4} = 0b0001;
934948
let Inst{19-8} = 0b111111111111;
935949
let Inst{27-20} = 0b00010010;
936950
let Inst{31-28} = 0b1110;
951+
let Inst{3-0} = Rm;
937952
}
938953

939954
// ARMV4 only
940955
def MOVPCRX : AXI<(outs), (ins GPR:$dst), BrMiscFrm, IIC_Br, "mov\tpc, $dst",
941956
[(brind GPR:$dst)]>,
942957
Requires<[IsARM, NoV4T]> {
958+
bits<4> Rm;
959+
943960
let Inst{11-4} = 0b00000000;
944961
let Inst{15-12} = 0b1111;
945962
let Inst{19-16} = 0b0000;
946963
let Inst{27-20} = 0b00011010;
947964
let Inst{31-28} = 0b1110;
965+
let Inst{3-0} = Rm;
948966
}
949967
}
950968

@@ -981,9 +999,11 @@ let isCall = 1,
981999
IIC_Br, "blx\t$func",
9821000
[(ARMcall GPR:$func)]>,
9831001
Requires<[IsARM, HasV5T, IsNotDarwin]> {
1002+
bits<4> Rm;
9841003
let Inst{7-4} = 0b0011;
9851004
let Inst{19-8} = 0b111111111111;
9861005
let Inst{27-20} = 0b00010010;
1006+
let Inst{3-0} = Rm;
9871007
}
9881008

9891009
// ARMv4T
@@ -1493,16 +1513,26 @@ def STM_UPD : AXI4st<(outs GPR:$wb), (ins addrmode4:$addr, pred:$p,
14931513
let neverHasSideEffects = 1 in
14941514
def MOVr : AsI1<0b1101, (outs GPR:$dst), (ins GPR:$src), DPFrm, IIC_iMOVr,
14951515
"mov", "\t$dst, $src", []>, UnaryDP {
1516+
bits<4> Rd;
1517+
bits<4> Rm;
1518+
14961519
let Inst{11-4} = 0b00000000;
14971520
let Inst{25} = 0;
1521+
let Inst{3-0} = Rm;
1522+
let Inst{15-12} = Rd;
14981523
}
14991524

15001525
// A version for the smaller set of tail call registers.
15011526
let neverHasSideEffects = 1 in
15021527
def MOVr_TC : AsI1<0b1101, (outs tcGPR:$dst), (ins tcGPR:$src), DPFrm,
15031528
IIC_iMOVr, "mov", "\t$dst, $src", []>, UnaryDP {
1529+
bits<4> Rd;
1530+
bits<4> Rm;
1531+
15041532
let Inst{11-4} = 0b00000000;
15051533
let Inst{25} = 0;
1534+
let Inst{3-0} = Rm;
1535+
let Inst{15-12} = Rd;
15061536
}
15071537

15081538
def MOVs : AsI1<0b1101, (outs GPR:$dst), (ins so_reg:$src),

llvm/lib/Target/ARM/ARMMCCodeEmitter.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,25 @@ EmitImmediate(const MCOperand &DispOp, unsigned Size, MCFixupKind FixupKind,
106106
assert(0 && "ARMMCCodeEmitter::EmitImmediate() not yet implemented.");
107107
}
108108

109+
/// getMachineOpValue - Return binary encoding of operand. If the machine
110+
/// operand requires relocation, record the relocation and return zero.
111+
unsigned ARMMCCodeEmitter::getMachineOpValue(const MCInst &MI,
112+
const MCOperand &MO) const {
113+
if (MO.isReg())
114+
// FIXME: Should shifted register stuff be handled as part of this? Maybe.
115+
return getARMRegisterNumbering(MO.getReg());
116+
else if (MO.isImm())
117+
// FIXME: This is insufficient. Shifted immediates and all that... (blech).
118+
return static_cast<unsigned>(MO.getImm());
119+
else {
120+
#ifndef NDEBUG
121+
errs() << MO;
122+
#endif
123+
llvm_unreachable(0);
124+
}
125+
return 0;
126+
}
127+
109128
void ARMMCCodeEmitter::
110129
EncodeInstruction(const MCInst &MI, raw_ostream &OS,
111130
SmallVectorImpl<MCFixup> &Fixups) const {

llvm/test/MC/ARM/simple-encoding.ll

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,18 @@ define i32 @foo(i32 %a, i32 %b) nounwind ssp {
99
entry:
1010
; CHECK: foo
1111
; CHECK: 0xf0,0x00,0xf0,0x07
12-
; CHECK: 0x1e,0xff,0x2f,0x01
12+
; CHECK: 0x1e,0xff,0x2f,0xe1
1313

1414
tail call void @llvm.trap()
1515
ret i32 undef
1616
}
1717

18+
define i32 @f2(i32 %a, i32 %b) nounwind readnone ssp {
19+
entry:
20+
; CHECK: f2
21+
; CHECK: 0x00,0x00,0x81,0xe0
22+
; CHECK: 0x1e,0xff,0x2f,0xe1
23+
%add = add nsw i32 %b, %a
24+
ret i32 %add
25+
}
1826
declare void @llvm.trap() nounwind

0 commit comments

Comments
 (0)