Skip to content

Commit 60db197

Browse files
committed
add generic getImmEncoding()
1 parent 65fd44e commit 60db197

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCCodeEmitter.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,24 @@ PPCMCCodeEmitter::getVSRpEvenEncoding(const MCInst &MI, unsigned OpNo,
206206
return RegBits;
207207
}
208208

209+
template <MCFixupKind Fixup>
210+
uint64_t PPCMCCodeEmitter::getImmEncoding(const MCInst &MI, unsigned OpNo,
211+
SmallVectorImpl<MCFixup> &Fixups,
212+
const MCSubtargetInfo &STI) const {
213+
const MCOperand &MO = MI.getOperand(OpNo);
214+
assert(!MO.isReg() && "Not expecting a register for this operand.");
215+
if (MO.isImm())
216+
return getMachineOpValue(MI, MO, Fixups, STI);
217+
218+
uint32_t Offset=0;
219+
if (Fixup == PPC::fixup_ppc_half16)
220+
Offset = IsLittleEndian ? 0 : 2;
221+
222+
// Add a fixup for the immediate field.
223+
addFixup(Fixups, Offset, MO.getExpr(), Fixup);
224+
return 0;
225+
}
226+
209227
unsigned PPCMCCodeEmitter::getImm16Encoding(const MCInst &MI, unsigned OpNo,
210228
SmallVectorImpl<MCFixup> &Fixups,
211229
const MCSubtargetInfo &STI) const {

llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCCodeEmitter.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ class PPCMCCodeEmitter : public MCCodeEmitter {
4747
unsigned getAbsCondBrEncoding(const MCInst &MI, unsigned OpNo,
4848
SmallVectorImpl<MCFixup> &Fixups,
4949
const MCSubtargetInfo &STI) const;
50+
template <MCFixupKind Fixup>
51+
uint64_t getImmEncoding(const MCInst &MI, unsigned OpNo,
52+
SmallVectorImpl<MCFixup> &Fixups,
53+
const MCSubtargetInfo &STI) const;
5054
unsigned getImm16Encoding(const MCInst &MI, unsigned OpNo,
5155
SmallVectorImpl<MCFixup> &Fixups,
5256
const MCSubtargetInfo &STI) const;

llvm/lib/Target/PowerPC/PPCRegisterInfo.td

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,7 @@ def PPCS16ImmAsmOperand : AsmOperandClass {
743743
}
744744
def s16imm : Operand<i32> {
745745
let PrintMethod = "printS16ImmOperand";
746-
let EncoderMethod = "getImm16Encoding";
746+
let EncoderMethod = "getImmEncoding<PPC::fixup_ppc_half16>";
747747
let ParserMatchClass = PPCS16ImmAsmOperand;
748748
let DecoderMethod = "decodeSImmOperand<16>";
749749
let OperandType = "OPERAND_IMMEDIATE";
@@ -754,7 +754,7 @@ def PPCU16ImmAsmOperand : AsmOperandClass {
754754
}
755755
def u16imm : Operand<i32> {
756756
let PrintMethod = "printU16ImmOperand";
757-
let EncoderMethod = "getImm16Encoding";
757+
let EncoderMethod = "getImmEncoding<PPC::fixup_ppc_half16>";
758758
let ParserMatchClass = PPCU16ImmAsmOperand;
759759
let DecoderMethod = "decodeUImmOperand<16>";
760760
let OperandType = "OPERAND_IMMEDIATE";
@@ -768,7 +768,7 @@ def s17imm : Operand<i32> {
768768
// to accept immediates in the range -65536..65535 for compatibility with
769769
// the GNU assembler. The operand is treated as 16-bit otherwise.
770770
let PrintMethod = "printS16ImmOperand";
771-
let EncoderMethod = "getImm16Encoding";
771+
let EncoderMethod = "getImmEncoding<PPC::fixup_ppc_half16>";
772772
let ParserMatchClass = PPCS17ImmAsmOperand;
773773
let DecoderMethod = "decodeSImmOperand<16>";
774774
let OperandType = "OPERAND_IMMEDIATE";
@@ -780,14 +780,14 @@ def PPCS34ImmAsmOperand : AsmOperandClass {
780780
}
781781
def s34imm : Operand<i64> {
782782
let PrintMethod = "printS34ImmOperand";
783-
let EncoderMethod = "getImm34EncodingNoPCRel";
783+
let EncoderMethod = "getImmEncoding<PPC::fixup_ppc_imm34>";
784784
let ParserMatchClass = PPCS34ImmAsmOperand;
785785
let DecoderMethod = "decodeSImmOperand<34>";
786786
let OperandType = "OPERAND_IMMEDIATE";
787787
}
788788
def s34imm_pcrel : Operand<i64> {
789789
let PrintMethod = "printS34ImmOperand";
790-
let EncoderMethod = "getImm34EncodingPCRel";
790+
let EncoderMethod = "getImmEncoding<PPC::fixup_ppc_pcrel34>";
791791
let ParserMatchClass = PPCS34ImmAsmOperand;
792792
let DecoderMethod = "decodeSImmOperand<34>";
793793
let OperandType = "OPERAND_IMMEDIATE";

0 commit comments

Comments
 (0)