From dcf1ea08e542fe2b25edb66f1bf6a27c357f1b3f Mon Sep 17 00:00:00 2001 From: Richard Trieu Date: Sat, 11 May 2019 00:13:01 +0000 Subject: [ARC] Move InstPrinter files to MCTargetDesc. NFC For some targets, there is a circular dependency between InstPrinter and MCTargetDesc. Merging them together will fix this. For the other targets, the merging is to maintain consistency so all targets will have the same structure. llvm-svn: 360488 --- llvm/lib/Target/ARC/ARCAsmPrinter.cpp | 2 +- llvm/lib/Target/ARC/CMakeLists.txt | 1 - llvm/lib/Target/ARC/InstPrinter/ARCInstPrinter.cpp | 179 --------------------- llvm/lib/Target/ARC/InstPrinter/ARCInstPrinter.h | 45 ------ llvm/lib/Target/ARC/InstPrinter/CMakeLists.txt | 3 - llvm/lib/Target/ARC/InstPrinter/LLVMBuild.txt | 22 --- llvm/lib/Target/ARC/LLVMBuild.txt | 3 +- .../lib/Target/ARC/MCTargetDesc/ARCInstPrinter.cpp | 179 +++++++++++++++++++++ llvm/lib/Target/ARC/MCTargetDesc/ARCInstPrinter.h | 45 ++++++ .../Target/ARC/MCTargetDesc/ARCMCTargetDesc.cpp | 2 +- llvm/lib/Target/ARC/MCTargetDesc/CMakeLists.txt | 1 + llvm/lib/Target/ARC/MCTargetDesc/LLVMBuild.txt | 2 +- 12 files changed, 229 insertions(+), 255 deletions(-) delete mode 100644 llvm/lib/Target/ARC/InstPrinter/ARCInstPrinter.cpp delete mode 100644 llvm/lib/Target/ARC/InstPrinter/ARCInstPrinter.h delete mode 100644 llvm/lib/Target/ARC/InstPrinter/CMakeLists.txt delete mode 100644 llvm/lib/Target/ARC/InstPrinter/LLVMBuild.txt create mode 100644 llvm/lib/Target/ARC/MCTargetDesc/ARCInstPrinter.cpp create mode 100644 llvm/lib/Target/ARC/MCTargetDesc/ARCInstPrinter.h (limited to 'llvm/lib/Target/ARC') diff --git a/llvm/lib/Target/ARC/ARCAsmPrinter.cpp b/llvm/lib/Target/ARC/ARCAsmPrinter.cpp index 487360ebc13..668f6ca7a15 100644 --- a/llvm/lib/Target/ARC/ARCAsmPrinter.cpp +++ b/llvm/lib/Target/ARC/ARCAsmPrinter.cpp @@ -17,7 +17,7 @@ #include "ARCSubtarget.h" #include "ARCTargetMachine.h" #include "ARCTargetStreamer.h" -#include "InstPrinter/ARCInstPrinter.h" +#include "MCTargetDesc/ARCInstPrinter.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/StringExtras.h" #include "llvm/CodeGen/AsmPrinter.h" diff --git a/llvm/lib/Target/ARC/CMakeLists.txt b/llvm/lib/Target/ARC/CMakeLists.txt index b99ba203aad..a1604792f6e 100644 --- a/llvm/lib/Target/ARC/CMakeLists.txt +++ b/llvm/lib/Target/ARC/CMakeLists.txt @@ -27,6 +27,5 @@ add_llvm_target(ARCCodeGen ) add_subdirectory(Disassembler) -add_subdirectory(InstPrinter) add_subdirectory(MCTargetDesc) add_subdirectory(TargetInfo) diff --git a/llvm/lib/Target/ARC/InstPrinter/ARCInstPrinter.cpp b/llvm/lib/Target/ARC/InstPrinter/ARCInstPrinter.cpp deleted file mode 100644 index e3e0ea48995..00000000000 --- a/llvm/lib/Target/ARC/InstPrinter/ARCInstPrinter.cpp +++ /dev/null @@ -1,179 +0,0 @@ -//===- ARCInstPrinter.cpp - ARC MCInst to assembly syntax -------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// -// -// This class prints an ARC MCInst to a .s file. -// -//===----------------------------------------------------------------------===// - -#include "ARCInstPrinter.h" -#include "MCTargetDesc/ARCInfo.h" -#include "llvm/ADT/StringExtras.h" -#include "llvm/MC/MCExpr.h" -#include "llvm/MC/MCInst.h" -#include "llvm/MC/MCInstrInfo.h" -#include "llvm/MC/MCSymbol.h" -#include "llvm/Support/Casting.h" -#include "llvm/Support/Debug.h" -#include "llvm/Support/raw_ostream.h" - -using namespace llvm; - -#define DEBUG_TYPE "asm-printer" - -#include "ARCGenAsmWriter.inc" - -template -static const char *BadConditionCode(T cc) { - LLVM_DEBUG(dbgs() << "Unknown condition code passed: " << cc << "\n"); - return "{unknown-cc}"; -} - -static const char *ARCBRCondCodeToString(ARCCC::BRCondCode BRCC) { - switch (BRCC) { - case ARCCC::BREQ: - return "eq"; - case ARCCC::BRNE: - return "ne"; - case ARCCC::BRLT: - return "lt"; - case ARCCC::BRGE: - return "ge"; - case ARCCC::BRLO: - return "lo"; - case ARCCC::BRHS: - return "hs"; - } - return BadConditionCode(BRCC); -} - -static const char *ARCCondCodeToString(ARCCC::CondCode CC) { - switch (CC) { - case ARCCC::EQ: - return "eq"; - case ARCCC::NE: - return "ne"; - case ARCCC::P: - return "p"; - case ARCCC::N: - return "n"; - case ARCCC::HS: - return "hs"; - case ARCCC::LO: - return "lo"; - case ARCCC::GT: - return "gt"; - case ARCCC::GE: - return "ge"; - case ARCCC::VS: - return "vs"; - case ARCCC::VC: - return "vc"; - case ARCCC::LT: - return "lt"; - case ARCCC::LE: - return "le"; - case ARCCC::HI: - return "hi"; - case ARCCC::LS: - return "ls"; - case ARCCC::PNZ: - return "pnz"; - case ARCCC::AL: - return "al"; - case ARCCC::NZ: - return "nz"; - case ARCCC::Z: - return "z"; - } - return BadConditionCode(CC); -} - -void ARCInstPrinter::printRegName(raw_ostream &OS, unsigned RegNo) const { - OS << StringRef(getRegisterName(RegNo)).lower(); -} - -void ARCInstPrinter::printInst(const MCInst *MI, raw_ostream &O, - StringRef Annot, const MCSubtargetInfo &STI) { - printInstruction(MI, O); - printAnnotation(O, Annot); -} - -static void printExpr(const MCExpr *Expr, const MCAsmInfo *MAI, - raw_ostream &OS) { - int Offset = 0; - const MCSymbolRefExpr *SRE; - - if (const auto *CE = dyn_cast(Expr)) { - OS << "0x"; - OS.write_hex(CE->getValue()); - return; - } - - if (const auto *BE = dyn_cast(Expr)) { - SRE = dyn_cast(BE->getLHS()); - const auto *CE = dyn_cast(BE->getRHS()); - assert(SRE && CE && "Binary expression must be sym+const."); - Offset = CE->getValue(); - } else { - SRE = dyn_cast(Expr); - assert(SRE && "Unexpected MCExpr type."); - } - assert(SRE->getKind() == MCSymbolRefExpr::VK_None); - - // Symbols are prefixed with '@' - OS << '@'; - SRE->getSymbol().print(OS, MAI); - - if (Offset) { - if (Offset > 0) - OS << '+'; - OS << Offset; - } -} - -void ARCInstPrinter::printOperand(const MCInst *MI, unsigned OpNum, - raw_ostream &O) { - const MCOperand &Op = MI->getOperand(OpNum); - if (Op.isReg()) { - printRegName(O, Op.getReg()); - return; - } - - if (Op.isImm()) { - O << Op.getImm(); - return; - } - - assert(Op.isExpr() && "unknown operand kind in printOperand"); - printExpr(Op.getExpr(), &MAI, O); -} - -void ARCInstPrinter::printMemOperandRI(const MCInst *MI, unsigned OpNum, - raw_ostream &O) { - const MCOperand &base = MI->getOperand(OpNum); - const MCOperand &offset = MI->getOperand(OpNum + 1); - assert(base.isReg() && "Base should be register."); - assert(offset.isImm() && "Offset should be immediate."); - printRegName(O, base.getReg()); - O << "," << offset.getImm(); -} - -void ARCInstPrinter::printPredicateOperand(const MCInst *MI, unsigned OpNum, - raw_ostream &O) { - - const MCOperand &Op = MI->getOperand(OpNum); - assert(Op.isImm() && "Predicate operand is immediate."); - O << ARCCondCodeToString((ARCCC::CondCode)Op.getImm()); -} - -void ARCInstPrinter::printBRCCPredicateOperand(const MCInst *MI, unsigned OpNum, - raw_ostream &O) { - const MCOperand &Op = MI->getOperand(OpNum); - assert(Op.isImm() && "Predicate operand is immediate."); - O << ARCBRCondCodeToString((ARCCC::BRCondCode)Op.getImm()); -} diff --git a/llvm/lib/Target/ARC/InstPrinter/ARCInstPrinter.h b/llvm/lib/Target/ARC/InstPrinter/ARCInstPrinter.h deleted file mode 100644 index 5ea58407f9e..00000000000 --- a/llvm/lib/Target/ARC/InstPrinter/ARCInstPrinter.h +++ /dev/null @@ -1,45 +0,0 @@ -//===- ARCInstPrinter.h - Convert ARC MCInst to assembly syntax -*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// -/// -/// \file -/// This file contains the declaration of the ARCInstPrinter class, -/// which is used to print ARC MCInst to a .s file. -/// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_LIB_TARGET_ARC_INSTPRINTER_ARCINSTPRINTER_H -#define LLVM_LIB_TARGET_ARC_INSTPRINTER_ARCINSTPRINTER_H - -#include "llvm/MC/MCInstPrinter.h" - -namespace llvm { - -class ARCInstPrinter : public MCInstPrinter { -public: - ARCInstPrinter(const MCAsmInfo &MAI, const MCInstrInfo &MII, - const MCRegisterInfo &MRI) - : MCInstPrinter(MAI, MII, MRI) {} - - // Autogenerated by tblgen. - void printInstruction(const MCInst *MI, raw_ostream &O); - static const char *getRegisterName(unsigned RegNo); - - void printRegName(raw_ostream &OS, unsigned RegNo) const override; - void printInst(const MCInst *MI, raw_ostream &O, StringRef Annot, - const MCSubtargetInfo &STI) override; - -private: - void printMemOperandRI(const MCInst *MI, unsigned OpNum, raw_ostream &O); - void printOperand(const MCInst *MI, unsigned OpNum, raw_ostream &O); - void printPredicateOperand(const MCInst *MI, unsigned OpNum, raw_ostream &O); - void printBRCCPredicateOperand(const MCInst *MI, unsigned OpNum, - raw_ostream &O); -}; -} // end namespace llvm - -#endif // LLVM_LIB_TARGET_ARC_INSTPRINTER_ARCINSTPRINTER_H diff --git a/llvm/lib/Target/ARC/InstPrinter/CMakeLists.txt b/llvm/lib/Target/ARC/InstPrinter/CMakeLists.txt deleted file mode 100644 index fd6b469cdfb..00000000000 --- a/llvm/lib/Target/ARC/InstPrinter/CMakeLists.txt +++ /dev/null @@ -1,3 +0,0 @@ -add_llvm_library(LLVMARCAsmPrinter - ARCInstPrinter.cpp - ) diff --git a/llvm/lib/Target/ARC/InstPrinter/LLVMBuild.txt b/llvm/lib/Target/ARC/InstPrinter/LLVMBuild.txt deleted file mode 100644 index 5133da1ef12..00000000000 --- a/llvm/lib/Target/ARC/InstPrinter/LLVMBuild.txt +++ /dev/null @@ -1,22 +0,0 @@ -;===- ./lib/Target/ARC/InstPrinter/LLVMBuild.txt -------------*- Conf -*--===; -; -; Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -; See https://llvm.org/LICENSE.txt for license information. -; SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -; -;===------------------------------------------------------------------------===; -; -; This is an LLVMBuild description file for the components in this subdirectory. -; -; For more information on the LLVMBuild system, please see: -; -; http://llvm.org/docs/LLVMBuild.html -; -;===------------------------------------------------------------------------===; - -[component_0] -type = Library -name = ARCAsmPrinter -parent = ARC -required_libraries = MC Support -add_to_library_groups = ARC diff --git a/llvm/lib/Target/ARC/LLVMBuild.txt b/llvm/lib/Target/ARC/LLVMBuild.txt index a8113f65e3a..365805a0d79 100644 --- a/llvm/lib/Target/ARC/LLVMBuild.txt +++ b/llvm/lib/Target/ARC/LLVMBuild.txt @@ -15,7 +15,7 @@ ;===------------------------------------------------------------------------===; [common] -subdirectories = Disassembler InstPrinter MCTargetDesc TargetInfo +subdirectories = Disassembler MCTargetDesc TargetInfo [component_0] type = TargetGroup @@ -38,7 +38,6 @@ required_libraries = Support Target TransformUtils - ARCAsmPrinter ARCDesc ARCInfo add_to_library_groups = ARC diff --git a/llvm/lib/Target/ARC/MCTargetDesc/ARCInstPrinter.cpp b/llvm/lib/Target/ARC/MCTargetDesc/ARCInstPrinter.cpp new file mode 100644 index 00000000000..e3e0ea48995 --- /dev/null +++ b/llvm/lib/Target/ARC/MCTargetDesc/ARCInstPrinter.cpp @@ -0,0 +1,179 @@ +//===- ARCInstPrinter.cpp - ARC MCInst to assembly syntax -------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This class prints an ARC MCInst to a .s file. +// +//===----------------------------------------------------------------------===// + +#include "ARCInstPrinter.h" +#include "MCTargetDesc/ARCInfo.h" +#include "llvm/ADT/StringExtras.h" +#include "llvm/MC/MCExpr.h" +#include "llvm/MC/MCInst.h" +#include "llvm/MC/MCInstrInfo.h" +#include "llvm/MC/MCSymbol.h" +#include "llvm/Support/Casting.h" +#include "llvm/Support/Debug.h" +#include "llvm/Support/raw_ostream.h" + +using namespace llvm; + +#define DEBUG_TYPE "asm-printer" + +#include "ARCGenAsmWriter.inc" + +template +static const char *BadConditionCode(T cc) { + LLVM_DEBUG(dbgs() << "Unknown condition code passed: " << cc << "\n"); + return "{unknown-cc}"; +} + +static const char *ARCBRCondCodeToString(ARCCC::BRCondCode BRCC) { + switch (BRCC) { + case ARCCC::BREQ: + return "eq"; + case ARCCC::BRNE: + return "ne"; + case ARCCC::BRLT: + return "lt"; + case ARCCC::BRGE: + return "ge"; + case ARCCC::BRLO: + return "lo"; + case ARCCC::BRHS: + return "hs"; + } + return BadConditionCode(BRCC); +} + +static const char *ARCCondCodeToString(ARCCC::CondCode CC) { + switch (CC) { + case ARCCC::EQ: + return "eq"; + case ARCCC::NE: + return "ne"; + case ARCCC::P: + return "p"; + case ARCCC::N: + return "n"; + case ARCCC::HS: + return "hs"; + case ARCCC::LO: + return "lo"; + case ARCCC::GT: + return "gt"; + case ARCCC::GE: + return "ge"; + case ARCCC::VS: + return "vs"; + case ARCCC::VC: + return "vc"; + case ARCCC::LT: + return "lt"; + case ARCCC::LE: + return "le"; + case ARCCC::HI: + return "hi"; + case ARCCC::LS: + return "ls"; + case ARCCC::PNZ: + return "pnz"; + case ARCCC::AL: + return "al"; + case ARCCC::NZ: + return "nz"; + case ARCCC::Z: + return "z"; + } + return BadConditionCode(CC); +} + +void ARCInstPrinter::printRegName(raw_ostream &OS, unsigned RegNo) const { + OS << StringRef(getRegisterName(RegNo)).lower(); +} + +void ARCInstPrinter::printInst(const MCInst *MI, raw_ostream &O, + StringRef Annot, const MCSubtargetInfo &STI) { + printInstruction(MI, O); + printAnnotation(O, Annot); +} + +static void printExpr(const MCExpr *Expr, const MCAsmInfo *MAI, + raw_ostream &OS) { + int Offset = 0; + const MCSymbolRefExpr *SRE; + + if (const auto *CE = dyn_cast(Expr)) { + OS << "0x"; + OS.write_hex(CE->getValue()); + return; + } + + if (const auto *BE = dyn_cast(Expr)) { + SRE = dyn_cast(BE->getLHS()); + const auto *CE = dyn_cast(BE->getRHS()); + assert(SRE && CE && "Binary expression must be sym+const."); + Offset = CE->getValue(); + } else { + SRE = dyn_cast(Expr); + assert(SRE && "Unexpected MCExpr type."); + } + assert(SRE->getKind() == MCSymbolRefExpr::VK_None); + + // Symbols are prefixed with '@' + OS << '@'; + SRE->getSymbol().print(OS, MAI); + + if (Offset) { + if (Offset > 0) + OS << '+'; + OS << Offset; + } +} + +void ARCInstPrinter::printOperand(const MCInst *MI, unsigned OpNum, + raw_ostream &O) { + const MCOperand &Op = MI->getOperand(OpNum); + if (Op.isReg()) { + printRegName(O, Op.getReg()); + return; + } + + if (Op.isImm()) { + O << Op.getImm(); + return; + } + + assert(Op.isExpr() && "unknown operand kind in printOperand"); + printExpr(Op.getExpr(), &MAI, O); +} + +void ARCInstPrinter::printMemOperandRI(const MCInst *MI, unsigned OpNum, + raw_ostream &O) { + const MCOperand &base = MI->getOperand(OpNum); + const MCOperand &offset = MI->getOperand(OpNum + 1); + assert(base.isReg() && "Base should be register."); + assert(offset.isImm() && "Offset should be immediate."); + printRegName(O, base.getReg()); + O << "," << offset.getImm(); +} + +void ARCInstPrinter::printPredicateOperand(const MCInst *MI, unsigned OpNum, + raw_ostream &O) { + + const MCOperand &Op = MI->getOperand(OpNum); + assert(Op.isImm() && "Predicate operand is immediate."); + O << ARCCondCodeToString((ARCCC::CondCode)Op.getImm()); +} + +void ARCInstPrinter::printBRCCPredicateOperand(const MCInst *MI, unsigned OpNum, + raw_ostream &O) { + const MCOperand &Op = MI->getOperand(OpNum); + assert(Op.isImm() && "Predicate operand is immediate."); + O << ARCBRCondCodeToString((ARCCC::BRCondCode)Op.getImm()); +} diff --git a/llvm/lib/Target/ARC/MCTargetDesc/ARCInstPrinter.h b/llvm/lib/Target/ARC/MCTargetDesc/ARCInstPrinter.h new file mode 100644 index 00000000000..5ea58407f9e --- /dev/null +++ b/llvm/lib/Target/ARC/MCTargetDesc/ARCInstPrinter.h @@ -0,0 +1,45 @@ +//===- ARCInstPrinter.h - Convert ARC MCInst to assembly syntax -*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +/// +/// \file +/// This file contains the declaration of the ARCInstPrinter class, +/// which is used to print ARC MCInst to a .s file. +/// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIB_TARGET_ARC_INSTPRINTER_ARCINSTPRINTER_H +#define LLVM_LIB_TARGET_ARC_INSTPRINTER_ARCINSTPRINTER_H + +#include "llvm/MC/MCInstPrinter.h" + +namespace llvm { + +class ARCInstPrinter : public MCInstPrinter { +public: + ARCInstPrinter(const MCAsmInfo &MAI, const MCInstrInfo &MII, + const MCRegisterInfo &MRI) + : MCInstPrinter(MAI, MII, MRI) {} + + // Autogenerated by tblgen. + void printInstruction(const MCInst *MI, raw_ostream &O); + static const char *getRegisterName(unsigned RegNo); + + void printRegName(raw_ostream &OS, unsigned RegNo) const override; + void printInst(const MCInst *MI, raw_ostream &O, StringRef Annot, + const MCSubtargetInfo &STI) override; + +private: + void printMemOperandRI(const MCInst *MI, unsigned OpNum, raw_ostream &O); + void printOperand(const MCInst *MI, unsigned OpNum, raw_ostream &O); + void printPredicateOperand(const MCInst *MI, unsigned OpNum, raw_ostream &O); + void printBRCCPredicateOperand(const MCInst *MI, unsigned OpNum, + raw_ostream &O); +}; +} // end namespace llvm + +#endif // LLVM_LIB_TARGET_ARC_INSTPRINTER_ARCINSTPRINTER_H diff --git a/llvm/lib/Target/ARC/MCTargetDesc/ARCMCTargetDesc.cpp b/llvm/lib/Target/ARC/MCTargetDesc/ARCMCTargetDesc.cpp index 07713024809..5739866993b 100644 --- a/llvm/lib/Target/ARC/MCTargetDesc/ARCMCTargetDesc.cpp +++ b/llvm/lib/Target/ARC/MCTargetDesc/ARCMCTargetDesc.cpp @@ -11,9 +11,9 @@ //===----------------------------------------------------------------------===// #include "ARCMCTargetDesc.h" +#include "ARCInstPrinter.h" #include "ARCMCAsmInfo.h" #include "ARCTargetStreamer.h" -#include "InstPrinter/ARCInstPrinter.h" #include "llvm/MC/MCDwarf.h" #include "llvm/MC/MCInstrInfo.h" #include "llvm/MC/MCRegisterInfo.h" diff --git a/llvm/lib/Target/ARC/MCTargetDesc/CMakeLists.txt b/llvm/lib/Target/ARC/MCTargetDesc/CMakeLists.txt index 243198d253f..108fb93cafa 100644 --- a/llvm/lib/Target/ARC/MCTargetDesc/CMakeLists.txt +++ b/llvm/lib/Target/ARC/MCTargetDesc/CMakeLists.txt @@ -1,4 +1,5 @@ add_llvm_library(LLVMARCDesc + ARCInstPrinter.cpp ARCMCTargetDesc.cpp ARCMCAsmInfo.cpp ) diff --git a/llvm/lib/Target/ARC/MCTargetDesc/LLVMBuild.txt b/llvm/lib/Target/ARC/MCTargetDesc/LLVMBuild.txt index 6abf96e066e..5d2e0e6face 100644 --- a/llvm/lib/Target/ARC/MCTargetDesc/LLVMBuild.txt +++ b/llvm/lib/Target/ARC/MCTargetDesc/LLVMBuild.txt @@ -18,5 +18,5 @@ type = Library name = ARCDesc parent = ARC -required_libraries = MC Support ARCAsmPrinter ARCInfo +required_libraries = MC Support ARCInfo add_to_library_groups = ARC -- cgit v1.2.3