diff options
| author | Paul Osmialowski <pawel.osmialowski@arm.com> | 2016-05-13 18:00:09 +0000 |
|---|---|---|
| committer | Paul Osmialowski <pawel.osmialowski@arm.com> | 2016-05-13 18:00:09 +0000 |
| commit | 4f5b3be7f1c7b506896540fce862742e699aacd7 (patch) | |
| tree | 91c322161b0a51a6ff5b574780e5bb558a9058aa /llvm/lib/Target | |
| parent | 2f64c20284002675b1c5b214a629d95077e651ce (diff) | |
| download | bcm5719-llvm-4f5b3be7f1c7b506896540fce862742e699aacd7.tar.gz bcm5719-llvm-4f5b3be7f1c7b506896540fce862742e699aacd7.zip | |
add support for -print-imm-hex for AArch64
Most immediates are printed in Aarch64InstPrinter using 'formatImm' macro,
but not all of them.
Implementation contains following rules:
- floating point immediates are always printed as decimal
- signed integer immediates are printed depends on flag settings
(for negative values 'formatImm' macro prints the value as i.e -0x01
which may be convenient when imm is an address or offset)
- logical immediates are always printed as hex
- the 64-bit immediate for advSIMD, encoded in "a:b:c:d:e:f:g:h" is always printed as hex
- the 64-bit immedaite in exception generation instructions like:
brk, dcps1, dcps2, dcps3, hlt, hvc, smc, svc is always printed as hex
- the rest of immediates is printed depends on availability
of -print-imm-hex
Signed-off-by: Maciej Gabka <maciej.gabka@arm.com>
Signed-off-by: Paul Osmialowski <pawel.osmialowski@arm.com>
Differential Revision: http://reviews.llvm.org/D16929
llvm-svn: 269446
Diffstat (limited to 'llvm/lib/Target')
| -rw-r--r-- | llvm/lib/Target/AArch64/AArch64InstrFormats.td | 8 | ||||
| -rw-r--r-- | llvm/lib/Target/AArch64/InstPrinter/AArch64InstPrinter.cpp | 31 | ||||
| -rw-r--r-- | llvm/lib/Target/AArch64/InstPrinter/AArch64InstPrinter.h | 4 |
3 files changed, 26 insertions, 17 deletions
diff --git a/llvm/lib/Target/AArch64/AArch64InstrFormats.td b/llvm/lib/Target/AArch64/AArch64InstrFormats.td index caade48a877..99bd86448c5 100644 --- a/llvm/lib/Target/AArch64/AArch64InstrFormats.td +++ b/llvm/lib/Target/AArch64/AArch64InstrFormats.td @@ -496,7 +496,7 @@ def imm0_65535 : Operand<i32>, ImmLeaf<i32, [{ return ((uint32_t)Imm) < 65536; }]> { let ParserMatchClass = Imm0_65535Operand; - let PrintMethod = "printHexImm"; + let PrintMethod = "printImmHex"; } // imm0_255 predicate - True if the immediate is in the range [0,255]. @@ -505,7 +505,7 @@ def imm0_255 : Operand<i32>, ImmLeaf<i32, [{ return ((uint32_t)Imm) < 256; }]> { let ParserMatchClass = Imm0_255Operand; - let PrintMethod = "printHexImm"; + let PrintMethod = "printImm"; } // imm0_127 predicate - True if the immediate is in the range [0,127] @@ -514,7 +514,7 @@ def imm0_127 : Operand<i32>, ImmLeaf<i32, [{ return ((uint32_t)Imm) < 128; }]> { let ParserMatchClass = Imm0_127Operand; - let PrintMethod = "printHexImm"; + let PrintMethod = "printImm"; } // NOTE: These imm0_N operands have to be of type i64 because i64 is the size @@ -1549,7 +1549,7 @@ class ADRI<bit page, string asm, Operand adr, list<dag> pattern> def movimm32_imm : Operand<i32> { let ParserMatchClass = Imm0_65535Operand; let EncoderMethod = "getMoveWideImmOpValue"; - let PrintMethod = "printHexImm"; + let PrintMethod = "printImm"; } def movimm32_shift : Operand<i32> { let PrintMethod = "printShifter"; diff --git a/llvm/lib/Target/AArch64/InstPrinter/AArch64InstPrinter.cpp b/llvm/lib/Target/AArch64/InstPrinter/AArch64InstPrinter.cpp index d8a81082437..06883712e7a 100644 --- a/llvm/lib/Target/AArch64/InstPrinter/AArch64InstPrinter.cpp +++ b/llvm/lib/Target/AArch64/InstPrinter/AArch64InstPrinter.cpp @@ -928,14 +928,21 @@ void AArch64InstPrinter::printOperand(const MCInst *MI, unsigned OpNo, unsigned Reg = Op.getReg(); O << getRegisterName(Reg); } else if (Op.isImm()) { - O << '#' << Op.getImm(); + printImm(MI, OpNo, STI, O); } else { assert(Op.isExpr() && "unknown operand kind in printOperand"); Op.getExpr()->print(O, &MAI); } } -void AArch64InstPrinter::printHexImm(const MCInst *MI, unsigned OpNo, +void AArch64InstPrinter::printImm(const MCInst *MI, unsigned OpNo, + const MCSubtargetInfo &STI, + raw_ostream &O) { + const MCOperand &Op = MI->getOperand(OpNo); + O << "#" << formatImm(Op.getImm()); +} + +void AArch64InstPrinter::printImmHex(const MCInst *MI, unsigned OpNo, const MCSubtargetInfo &STI, raw_ostream &O) { const MCOperand &Op = MI->getOperand(OpNo); @@ -981,12 +988,12 @@ void AArch64InstPrinter::printAddSubImm(const MCInst *MI, unsigned OpNum, assert(Val == MO.getImm() && "Add/sub immediate out of range!"); unsigned Shift = AArch64_AM::getShiftValue(MI->getOperand(OpNum + 1).getImm()); - O << '#' << Val; + O << '#' << formatImm(Val); if (Shift != 0) printShifter(MI, OpNum + 1, STI, O); if (CommentStream) - *CommentStream << '=' << (Val << Shift) << '\n'; + *CommentStream << '=' << formatImm(Val << Shift) << '\n'; } else { assert(MO.isExpr() && "Unexpected operand type!"); MO.getExpr()->print(O, &MAI); @@ -1104,14 +1111,14 @@ template<int Scale> void AArch64InstPrinter::printImmScale(const MCInst *MI, unsigned OpNum, const MCSubtargetInfo &STI, raw_ostream &O) { - O << '#' << Scale * MI->getOperand(OpNum).getImm(); + O << '#' << formatImm(Scale * MI->getOperand(OpNum).getImm()); } void AArch64InstPrinter::printUImm12Offset(const MCInst *MI, unsigned OpNum, unsigned Scale, raw_ostream &O) { const MCOperand MO = MI->getOperand(OpNum); if (MO.isImm()) { - O << "#" << (MO.getImm() * Scale); + O << "#" << formatImm(MO.getImm() * Scale); } else { assert(MO.isExpr() && "Unexpected operand type!"); MO.getExpr()->print(O, &MAI); @@ -1123,7 +1130,7 @@ void AArch64InstPrinter::printAMIndexedWB(const MCInst *MI, unsigned OpNum, const MCOperand MO1 = MI->getOperand(OpNum + 1); O << '[' << getRegisterName(MI->getOperand(OpNum).getReg()); if (MO1.isImm()) { - O << ", #" << (MO1.getImm() * Scale); + O << ", #" << formatImm(MO1.getImm() * Scale); } else { assert(MO1.isExpr() && "Unexpected operand type!"); O << ", "; @@ -1142,7 +1149,7 @@ void AArch64InstPrinter::printPrefetchOp(const MCInst *MI, unsigned OpNum, if (Valid) O << Name; else - O << '#' << prfop; + O << '#' << formatImm(prfop); } void AArch64InstPrinter::printPSBHintOp(const MCInst *MI, unsigned OpNum, @@ -1155,7 +1162,7 @@ void AArch64InstPrinter::printPSBHintOp(const MCInst *MI, unsigned OpNum, if (Valid) O << Name; else - O << '#' << psbhintop; + O << '#' << formatImm(psbhintop); } void AArch64InstPrinter::printFPImmOperand(const MCInst *MI, unsigned OpNum, @@ -1310,7 +1317,7 @@ void AArch64InstPrinter::printAlignedLabel(const MCInst *MI, unsigned OpNum, // If the label has already been resolved to an immediate offset (say, when // we're running the disassembler), just print the immediate. if (Op.isImm()) { - O << "#" << (Op.getImm() * 4); + O << "#" << formatImm(Op.getImm() * 4); return; } @@ -1335,7 +1342,7 @@ void AArch64InstPrinter::printAdrpLabel(const MCInst *MI, unsigned OpNum, // If the label has already been resolved to an immediate offset (say, when // we're running the disassembler), just print the immediate. if (Op.isImm()) { - O << "#" << (Op.getImm() * (1 << 12)); + O << "#" << formatImm(Op.getImm() * (1 << 12)); return; } @@ -1396,7 +1403,7 @@ void AArch64InstPrinter::printSystemPStateField(const MCInst *MI, unsigned OpNo, if (Valid) O << Name.upper(); else - O << "#" << Val; + O << "#" << formatImm(Val); } void AArch64InstPrinter::printSIMDType10Operand(const MCInst *MI, unsigned OpNo, diff --git a/llvm/lib/Target/AArch64/InstPrinter/AArch64InstPrinter.h b/llvm/lib/Target/AArch64/InstPrinter/AArch64InstPrinter.h index ea68d9848b4..65dca99ed04 100644 --- a/llvm/lib/Target/AArch64/InstPrinter/AArch64InstPrinter.h +++ b/llvm/lib/Target/AArch64/InstPrinter/AArch64InstPrinter.h @@ -49,7 +49,9 @@ protected: // Operand printers void printOperand(const MCInst *MI, unsigned OpNo, const MCSubtargetInfo &STI, raw_ostream &O); - void printHexImm(const MCInst *MI, unsigned OpNo, const MCSubtargetInfo &STI, + void printImm(const MCInst *MI, unsigned OpNo, const MCSubtargetInfo &STI, + raw_ostream &O); + void printImmHex(const MCInst *MI, unsigned OpNo, const MCSubtargetInfo &STI, raw_ostream &O); void printPostIncOperand(const MCInst *MI, unsigned OpNo, unsigned Imm, raw_ostream &O); |

