[llvm-commits] [llvm] r170288 - in /llvm/trunk/lib/Target/XCore: CMakeLists.txt InstPrinter/ InstPrinter/CMakeLists.txt InstPrinter/LLVMBuild.txt InstPrinter/Makefile InstPrinter/XCoreInstPrinter.cpp InstPrinter/XCoreInstPrinter.h LLVMBuild.txt MCTargetDesc/LLVMBuild.txt MCTargetDesc/XCoreMCTargetDesc.cpp Makefile XCore.td XCoreAsmPrinter.cpp XCoreMCInstLower.cpp XCoreMCInstLower.h
Sean Silva
silvas at purdue.edu
Sun Dec 16 11:32:29 PST 2012
Good to see XCore getting some love!
+#ifndef XCOREMCINSTLOWER_H
+#define XCOREMCINSTLOWER_H
+#include "llvm/ADT/SmallVector.h"
Why do you need SmallVector.h in this header?
+/// XCoreMCInstLower - This class is used to lower an MachineInstr into an
+// MCInst.
New code should follow the recommended doxygen style:
<http://llvm.org/docs/CodingStandards.html#doxygen-use-in-documentation-comments>
+ } else if (!(SRE = dyn_cast<MCSymbolRefExpr>(Expr))) {
+ assert(false && "Unexpected MCExpr type.");
You can probably use isa<> instead of dyn_cast<> here. Also use
llvm_unreachable instead of "assert(false)".
-- Sean Silva
On Sun, Dec 16, 2012 at 9:20 AM, Richard Osborne <richard at xmos.com> wrote:
> Author: friedgold
> Date: Sun Dec 16 10:20:48 2012
> New Revision: 170288
>
> URL: http://llvm.org/viewvc/llvm-project?rev=170288&view=rev
> Log:
> Change XCoreAsmPrinter to lower MachineInstrs to MCInsts before emission.
>
> This change adds XCoreMCInstLower to do the lowering to MCInst and
> XCoreInstPrinter to print the MCInsts.
>
> Added:
> llvm/trunk/lib/Target/XCore/InstPrinter/
> llvm/trunk/lib/Target/XCore/InstPrinter/CMakeLists.txt
> llvm/trunk/lib/Target/XCore/InstPrinter/LLVMBuild.txt
> - copied, changed from r170286, llvm/trunk/lib/Target/XCore/MCTargetDesc/LLVMBuild.txt
> llvm/trunk/lib/Target/XCore/InstPrinter/Makefile
> llvm/trunk/lib/Target/XCore/InstPrinter/XCoreInstPrinter.cpp
> llvm/trunk/lib/Target/XCore/InstPrinter/XCoreInstPrinter.h
> llvm/trunk/lib/Target/XCore/XCoreMCInstLower.cpp
> llvm/trunk/lib/Target/XCore/XCoreMCInstLower.h
> Modified:
> llvm/trunk/lib/Target/XCore/CMakeLists.txt
> llvm/trunk/lib/Target/XCore/LLVMBuild.txt
> llvm/trunk/lib/Target/XCore/MCTargetDesc/LLVMBuild.txt
> llvm/trunk/lib/Target/XCore/MCTargetDesc/XCoreMCTargetDesc.cpp
> llvm/trunk/lib/Target/XCore/Makefile
> llvm/trunk/lib/Target/XCore/XCore.td
> llvm/trunk/lib/Target/XCore/XCoreAsmPrinter.cpp
>
> Modified: llvm/trunk/lib/Target/XCore/CMakeLists.txt
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/XCore/CMakeLists.txt?rev=170288&r1=170287&r2=170288&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Target/XCore/CMakeLists.txt (original)
> +++ llvm/trunk/lib/Target/XCore/CMakeLists.txt Sun Dec 16 10:20:48 2012
> @@ -15,6 +15,7 @@
> XCoreISelDAGToDAG.cpp
> XCoreISelLowering.cpp
> XCoreMachineFunctionInfo.cpp
> + XCoreMCInstLower.cpp
> XCoreRegisterInfo.cpp
> XCoreSubtarget.cpp
> XCoreTargetMachine.cpp
> @@ -24,5 +25,6 @@
>
> add_dependencies(LLVMXCoreCodeGen intrinsics_gen)
>
> +add_subdirectory(InstPrinter)
> add_subdirectory(TargetInfo)
> add_subdirectory(MCTargetDesc)
>
> Added: llvm/trunk/lib/Target/XCore/InstPrinter/CMakeLists.txt
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/XCore/InstPrinter/CMakeLists.txt?rev=170288&view=auto
> ==============================================================================
> --- llvm/trunk/lib/Target/XCore/InstPrinter/CMakeLists.txt (added)
> +++ llvm/trunk/lib/Target/XCore/InstPrinter/CMakeLists.txt Sun Dec 16 10:20:48 2012
> @@ -0,0 +1,7 @@
> +include_directories( ${CMAKE_CURRENT_BINARY_DIR}/.. ${CMAKE_CURRENT_SOURCE_DIR}/.. )
> +
> +add_llvm_library(LLVMXCoreAsmPrinter
> + XCoreInstPrinter.cpp
> + )
> +
> +add_dependencies(LLVMXCoreAsmPrinter XCoreCommonTableGen)
>
> Copied: llvm/trunk/lib/Target/XCore/InstPrinter/LLVMBuild.txt (from r170286, llvm/trunk/lib/Target/XCore/MCTargetDesc/LLVMBuild.txt)
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/XCore/InstPrinter/LLVMBuild.txt?p2=llvm/trunk/lib/Target/XCore/InstPrinter/LLVMBuild.txt&p1=llvm/trunk/lib/Target/XCore/MCTargetDesc/LLVMBuild.txt&r1=170286&r2=170288&rev=170288&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Target/XCore/MCTargetDesc/LLVMBuild.txt (original)
> +++ llvm/trunk/lib/Target/XCore/InstPrinter/LLVMBuild.txt Sun Dec 16 10:20:48 2012
> @@ -1,4 +1,4 @@
> -;===- ./lib/Target/XCore/MCTargetDesc/LLVMBuild.txt ------------*- Conf -*--===;
> +;===- ./lib/Target/XCore/InstPrinter/LLVMBuild.txt -------------*- Conf -*--===;
> ;
> ; The LLVM Compiler Infrastructure
> ;
> @@ -17,7 +17,7 @@
>
> [component_0]
> type = Library
> -name = XCoreDesc
> +name = XCoreAsmPrinter
> parent = XCore
> -required_libraries = MC XCoreInfo
> +required_libraries = MC Support
> add_to_library_groups = XCore
>
> Added: llvm/trunk/lib/Target/XCore/InstPrinter/Makefile
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/XCore/InstPrinter/Makefile?rev=170288&view=auto
> ==============================================================================
> --- llvm/trunk/lib/Target/XCore/InstPrinter/Makefile (added)
> +++ llvm/trunk/lib/Target/XCore/InstPrinter/Makefile Sun Dec 16 10:20:48 2012
> @@ -0,0 +1,16 @@
> +##===- lib/Target/XCore/AsmPrinter/Makefile ----------------*- Makefile -*-===##
> +#
> +# The LLVM Compiler Infrastructure
> +#
> +# This file is distributed under the University of Illinois Open Source
> +# License. See LICENSE.TXT for details.
> +#
> +##===----------------------------------------------------------------------===##
> +
> +LEVEL = ../../../..
> +LIBRARYNAME = LLVMXCoreAsmPrinter
> +
> +# Hack: we need to include 'main' xcore target directory to grab private headers
> +CPP.Flags += -I$(PROJ_OBJ_DIR)/.. -I$(PROJ_SRC_DIR)/..
> +
> +include $(LEVEL)/Makefile.common
>
> Added: llvm/trunk/lib/Target/XCore/InstPrinter/XCoreInstPrinter.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/XCore/InstPrinter/XCoreInstPrinter.cpp?rev=170288&view=auto
> ==============================================================================
> --- llvm/trunk/lib/Target/XCore/InstPrinter/XCoreInstPrinter.cpp (added)
> +++ llvm/trunk/lib/Target/XCore/InstPrinter/XCoreInstPrinter.cpp Sun Dec 16 10:20:48 2012
> @@ -0,0 +1,96 @@
> +//===-- XCoreInstPrinter.cpp - Convert XCore MCInst to assembly syntax ----===//
> +//
> +// The LLVM Compiler Infrastructure
> +//
> +// This file is distributed under the University of Illinois Open Source
> +// License. See LICENSE.TXT for details.
> +//
> +//===----------------------------------------------------------------------===//
> +//
> +// This class prints an XCore MCInst to a .s file.
> +//
> +//===----------------------------------------------------------------------===//
> +
> +#define DEBUG_TYPE "asm-printer"
> +#include "XCoreInstPrinter.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/ErrorHandling.h"
> +#include "llvm/Support/raw_ostream.h"
> +using namespace llvm;
> +
> +#include "XCoreGenAsmWriter.inc"
> +
> +void XCoreInstPrinter::printRegName(raw_ostream &OS, unsigned RegNo) const {
> + OS << StringRef(getRegisterName(RegNo)).lower();
> +}
> +
> +void XCoreInstPrinter::printInst(const MCInst *MI, raw_ostream &O,
> + StringRef Annot) {
> + printInstruction(MI, O);
> + printAnnotation(O, Annot);
> +}
> +
> +void XCoreInstPrinter::
> +printInlineJT(const MCInst *MI, int opNum, raw_ostream &O) {
> + report_fatal_error("can't handle InlineJT");
> +}
> +
> +void XCoreInstPrinter::
> +printInlineJT32(const MCInst *MI, int opNum, raw_ostream &O) {
> + report_fatal_error("can't handle InlineJT32");
> +}
> +
> +static void printExpr(const MCExpr *Expr, raw_ostream &OS) {
> + int Offset = 0;
> + const MCSymbolRefExpr *SRE;
> +
> + if (const MCBinaryExpr *BE = dyn_cast<MCBinaryExpr>(Expr)) {
> + SRE = dyn_cast<MCSymbolRefExpr>(BE->getLHS());
> + const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(BE->getRHS());
> + assert(SRE && CE && "Binary expression must be sym+const.");
> + Offset = CE->getValue();
> + } else if (!(SRE = dyn_cast<MCSymbolRefExpr>(Expr))) {
> + assert(false && "Unexpected MCExpr type.");
> + }
> + assert(SRE->getKind() == MCSymbolRefExpr::VK_None);
> +
> + OS << SRE->getSymbol();
> +
> + if (Offset) {
> + if (Offset > 0)
> + OS << '+';
> + OS << Offset;
> + }
> +}
> +
> +void XCoreInstPrinter::
> +printOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O) {
> + const MCOperand &Op = MI->getOperand(OpNo);
> + 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(), O);
> +}
> +
> +void XCoreInstPrinter::
> +printMemOperand(const MCInst *MI, int opNum, raw_ostream &O) {
> + printOperand(MI, opNum, O);
> +
> + if (MI->getOperand(opNum+1).isImm() && MI->getOperand(opNum+1).getImm() == 0)
> + return;
> +
> + O << "+";
> + printOperand(MI, opNum+1, O);
> +}
>
> Added: llvm/trunk/lib/Target/XCore/InstPrinter/XCoreInstPrinter.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/XCore/InstPrinter/XCoreInstPrinter.h?rev=170288&view=auto
> ==============================================================================
> --- llvm/trunk/lib/Target/XCore/InstPrinter/XCoreInstPrinter.h (added)
> +++ llvm/trunk/lib/Target/XCore/InstPrinter/XCoreInstPrinter.h Sun Dec 16 10:20:48 2012
> @@ -0,0 +1,42 @@
> +//== XCoreInstPrinter.h - Convert XCore MCInst to assembly syntax -*- C++ -*-=//
> +//
> +// The LLVM Compiler Infrastructure
> +//
> +// This file is distributed under the University of Illinois Open Source
> +// License. See LICENSE.TXT for details.
> +//
> +//===----------------------------------------------------------------------===//
> +//
> +// This class prints a XCore MCInst to a .s file.
> +//
> +//===----------------------------------------------------------------------===//
> +
> +#ifndef XCOREINSTPRINTER_H
> +#define XCOREINSTPRINTER_H
> +#include "llvm/MC/MCInstPrinter.h"
> +
> +namespace llvm {
> +
> +class TargetMachine;
> +
> +class XCoreInstPrinter : public MCInstPrinter {
> +public:
> + XCoreInstPrinter(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);
> +
> + virtual void printRegName(raw_ostream &OS, unsigned RegNo) const;
> + virtual void printInst(const MCInst *MI, raw_ostream &O, StringRef Annot);
> +private:
> + void printInlineJT(const MCInst *MI, int opNum, raw_ostream &O);
> + void printInlineJT32(const MCInst *MI, int opNum, raw_ostream &O);
> + void printOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O);
> + void printMemOperand(const MCInst *MI, int opNum, raw_ostream &O);
> +};
> +} // end namespace llvm
> +
> +#endif
>
> Modified: llvm/trunk/lib/Target/XCore/LLVMBuild.txt
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/XCore/LLVMBuild.txt?rev=170288&r1=170287&r2=170288&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Target/XCore/LLVMBuild.txt (original)
> +++ llvm/trunk/lib/Target/XCore/LLVMBuild.txt Sun Dec 16 10:20:48 2012
> @@ -16,7 +16,7 @@
> ;===------------------------------------------------------------------------===;
>
> [common]
> -subdirectories = MCTargetDesc TargetInfo
> +subdirectories = InstPrinter MCTargetDesc TargetInfo
>
> [component_0]
> type = TargetGroup
>
> Modified: llvm/trunk/lib/Target/XCore/MCTargetDesc/LLVMBuild.txt
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/XCore/MCTargetDesc/LLVMBuild.txt?rev=170288&r1=170287&r2=170288&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Target/XCore/MCTargetDesc/LLVMBuild.txt (original)
> +++ llvm/trunk/lib/Target/XCore/MCTargetDesc/LLVMBuild.txt Sun Dec 16 10:20:48 2012
> @@ -19,5 +19,5 @@
> type = Library
> name = XCoreDesc
> parent = XCore
> -required_libraries = MC XCoreInfo
> +required_libraries = MC XCoreAsmPrinter XCoreInfo
> add_to_library_groups = XCore
>
> Modified: llvm/trunk/lib/Target/XCore/MCTargetDesc/XCoreMCTargetDesc.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/XCore/MCTargetDesc/XCoreMCTargetDesc.cpp?rev=170288&r1=170287&r2=170288&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Target/XCore/MCTargetDesc/XCoreMCTargetDesc.cpp (original)
> +++ llvm/trunk/lib/Target/XCore/MCTargetDesc/XCoreMCTargetDesc.cpp Sun Dec 16 10:20:48 2012
> @@ -13,6 +13,7 @@
>
> #include "XCoreMCTargetDesc.h"
> #include "XCoreMCAsmInfo.h"
> +#include "InstPrinter/XCoreInstPrinter.h"
> #include "llvm/MC/MCCodeGenInfo.h"
> #include "llvm/MC/MCInstrInfo.h"
> #include "llvm/MC/MCRegisterInfo.h"
> @@ -69,6 +70,15 @@
> return X;
> }
>
> +static MCInstPrinter *createXCoreMCInstPrinter(const Target &T,
> + unsigned SyntaxVariant,
> + const MCAsmInfo &MAI,
> + const MCInstrInfo &MII,
> + const MCRegisterInfo &MRI,
> + const MCSubtargetInfo &STI) {
> + return new XCoreInstPrinter(MAI, MII, MRI);
> +}
> +
> // Force static initialization.
> extern "C" void LLVMInitializeXCoreTargetMC() {
> // Register the MC asm info.
> @@ -87,4 +97,8 @@
> // Register the MC subtarget info.
> TargetRegistry::RegisterMCSubtargetInfo(TheXCoreTarget,
> createXCoreMCSubtargetInfo);
> +
> + // Register the MCInstPrinter
> + TargetRegistry::RegisterMCInstPrinter(TheXCoreTarget,
> + createXCoreMCInstPrinter);
> }
>
> Modified: llvm/trunk/lib/Target/XCore/Makefile
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/XCore/Makefile?rev=170288&r1=170287&r2=170288&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Target/XCore/Makefile (original)
> +++ llvm/trunk/lib/Target/XCore/Makefile Sun Dec 16 10:20:48 2012
> @@ -17,7 +17,7 @@
> XCoreGenDAGISel.inc XCoreGenCallingConv.inc \
> XCoreGenSubtargetInfo.inc
>
> -DIRS = TargetInfo MCTargetDesc
> +DIRS = InstPrinter TargetInfo MCTargetDesc
>
> include $(LEVEL)/Makefile.common
>
>
> Modified: llvm/trunk/lib/Target/XCore/XCore.td
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/XCore/XCore.td?rev=170288&r1=170287&r2=170288&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Target/XCore/XCore.td (original)
> +++ llvm/trunk/lib/Target/XCore/XCore.td Sun Dec 16 10:20:48 2012
> @@ -41,7 +41,13 @@
> // Declare the target which we are implementing
> //===----------------------------------------------------------------------===//
>
> +def XCoreAsmWriter : AsmWriter {
> + string AsmWriterClassName = "InstPrinter";
> + bit isMCAsmWriter = 1;
> +}
> +
> def XCore : Target {
> // Pull in Instruction Info:
> let InstructionSet = XCoreInstrInfo;
> + let AssemblyWriters = [XCoreAsmWriter];
> }
>
> Modified: llvm/trunk/lib/Target/XCore/XCoreAsmPrinter.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/XCore/XCoreAsmPrinter.cpp?rev=170288&r1=170287&r2=170288&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Target/XCore/XCoreAsmPrinter.cpp (original)
> +++ llvm/trunk/lib/Target/XCore/XCoreAsmPrinter.cpp Sun Dec 16 10:20:48 2012
> @@ -15,6 +15,8 @@
> #define DEBUG_TYPE "asm-printer"
> #include "XCore.h"
> #include "XCoreInstrInfo.h"
> +#include "XCoreMCInstLower.h"
> +#include "InstPrinter/XCoreInstPrinter.h"
> #include "XCoreSubtarget.h"
> #include "XCoreTargetMachine.h"
> #include "llvm/ADT/SmallString.h"
> @@ -30,6 +32,7 @@
> #include "llvm/DebugInfo.h"
> #include "llvm/DerivedTypes.h"
> #include "llvm/MC/MCAsmInfo.h"
> +#include "llvm/MC/MCInst.h"
> #include "llvm/MC/MCStreamer.h"
> #include "llvm/MC/MCSymbol.h"
> #include "llvm/Module.h"
> @@ -52,16 +55,17 @@
> namespace {
> class XCoreAsmPrinter : public AsmPrinter {
> const XCoreSubtarget &Subtarget;
> + XCoreMCInstLower MCInstLowering;
> void PrintDebugValueComment(const MachineInstr *MI, raw_ostream &OS);
> public:
> explicit XCoreAsmPrinter(TargetMachine &TM, MCStreamer &Streamer)
> - : AsmPrinter(TM, Streamer), Subtarget(TM.getSubtarget<XCoreSubtarget>()){}
> + : AsmPrinter(TM, Streamer), Subtarget(TM.getSubtarget<XCoreSubtarget>()),
> + MCInstLowering(*this) {}
>
> virtual const char *getPassName() const {
> return "XCore Assembly Printer";
> }
>
> - void printMemOperand(const MachineInstr *MI, int opNum, raw_ostream &O);
> void printInlineJT(const MachineInstr *MI, int opNum, raw_ostream &O,
> const std::string &directive = ".jmptable");
> void printInlineJT32(const MachineInstr *MI, int opNum, raw_ostream &O) {
> @@ -75,18 +79,14 @@
> void emitArrayBound(MCSymbol *Sym, const GlobalVariable *GV);
> virtual void EmitGlobalVariable(const GlobalVariable *GV);
>
> - void printInstruction(const MachineInstr *MI, raw_ostream &O); // autogen'd.
> - static const char *getRegisterName(unsigned RegNo);
> -
> void EmitFunctionEntryLabel();
> void EmitInstruction(const MachineInstr *MI);
> + void EmitFunctionBodyStart();
> void EmitFunctionBodyEnd();
> virtual MachineLocation getDebugValueLocation(const MachineInstr *MI) const;
> };
> } // end of anonymous namespace
>
> -#include "XCoreGenAsmWriter.inc"
> -
> void XCoreAsmPrinter::emitArrayBound(MCSymbol *Sym, const GlobalVariable *GV) {
> assert(((GV->hasExternalLinkage() ||
> GV->hasWeakLinkage()) ||
> @@ -177,6 +177,10 @@
> OutStreamer.EmitRawText("\t.cc_bottom " + Twine(GVSym->getName()) + ".data");
> }
>
> +void XCoreAsmPrinter::EmitFunctionBodyStart() {
> + MCInstLowering.Initialize(Mang, &MF->getContext());
> +}
> +
> /// EmitFunctionBodyEnd - Targets can override this to emit stuff after
> /// the last basic block in the function.
> void XCoreAsmPrinter::EmitFunctionBodyEnd() {
> @@ -192,17 +196,6 @@
> OutStreamer.EmitLabel(CurrentFnSym);
> }
>
> -void XCoreAsmPrinter::printMemOperand(const MachineInstr *MI, int opNum,
> - raw_ostream &O) {
> - printOperand(MI, opNum, O);
> -
> - if (MI->getOperand(opNum+1).isImm() && MI->getOperand(opNum+1).getImm() == 0)
> - return;
> -
> - O << "+";
> - printOperand(MI, opNum+1, O);
> -}
> -
> void XCoreAsmPrinter::
> printInlineJT(const MachineInstr *MI, int opNum, raw_ostream &O,
> const std::string &directive) {
> @@ -225,7 +218,7 @@
> const MachineOperand &MO = MI->getOperand(opNum);
> switch (MO.getType()) {
> case MachineOperand::MO_Register:
> - O << getRegisterName(MO.getReg());
> + O << XCoreInstPrinter::getRegisterName(MO.getReg());
> break;
> case MachineOperand::MO_Immediate:
> O << MO.getImm();
> @@ -270,7 +263,7 @@
> return AsmPrinter::PrintAsmOperand(MI, OpNo, AsmVariant, ExtraCode, O);
> }
>
> -printOperand(MI, OpNo, O);
> + printOperand(MI, OpNo, O);
> return false;
> }
>
> @@ -317,15 +310,30 @@
> }
> case XCore::ADD_2rus:
> if (MI->getOperand(2).getImm() == 0) {
> - O << "\tmov " << getRegisterName(MI->getOperand(0).getReg()) << ", "
> - << getRegisterName(MI->getOperand(1).getReg());
> + O << "\tmov "
> + << XCoreInstPrinter::getRegisterName(MI->getOperand(0).getReg()) << ", "
> + << XCoreInstPrinter::getRegisterName(MI->getOperand(1).getReg());
> OutStreamer.EmitRawText(O.str());
> return;
> }
> break;
> + case XCore::BR_JT:
> + case XCore::BR_JT32:
> + O << "\tbru "
> + << XCoreInstPrinter::getRegisterName(MI->getOperand(1).getReg()) << '\n';
> + if (MI->getOpcode() == XCore::BR_JT)
> + printInlineJT(MI, 0, O);
> + else
> + printInlineJT32(MI, 0, O);
> + O << '\n';
> + OutStreamer.EmitRawText(O.str());
> + return;
> }
> - printInstruction(MI, O);
> - OutStreamer.EmitRawText(O.str());
> +
> + MCInst TmpInst;
> + MCInstLowering.Lower(MI, TmpInst);
> +
> + OutStreamer.EmitInstruction(TmpInst);
> }
>
> // Force static initialization.
>
> Added: llvm/trunk/lib/Target/XCore/XCoreMCInstLower.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/XCore/XCoreMCInstLower.cpp?rev=170288&view=auto
> ==============================================================================
> --- llvm/trunk/lib/Target/XCore/XCoreMCInstLower.cpp (added)
> +++ llvm/trunk/lib/Target/XCore/XCoreMCInstLower.cpp Sun Dec 16 10:20:48 2012
> @@ -0,0 +1,116 @@
> +//===-- XCoreMCInstLower.cpp - Convert XCore MachineInstr to MCInst -------===//
> +//
> +// The LLVM Compiler Infrastructure
> +//
> +// This file is distributed under the University of Illinois Open Source
> +// License. See LICENSE.TXT for details.
> +//
> +//===----------------------------------------------------------------------===//
> +//
> +// This file contains code to lower XCore MachineInstrs to their corresponding
> +// MCInst records.
> +//
> +//===----------------------------------------------------------------------===//
> +#include "XCoreMCInstLower.h"
> +#include "llvm/CodeGen/AsmPrinter.h"
> +#include "llvm/CodeGen/MachineFunction.h"
> +#include "llvm/CodeGen/MachineInstr.h"
> +#include "llvm/CodeGen/MachineOperand.h"
> +#include "llvm/MC/MCContext.h"
> +#include "llvm/MC/MCExpr.h"
> +#include "llvm/MC/MCInst.h"
> +#include "llvm/Target/Mangler.h"
> +
> +using namespace llvm;
> +
> +XCoreMCInstLower::XCoreMCInstLower(class AsmPrinter &asmprinter)
> +: Printer(asmprinter) {}
> +
> +void XCoreMCInstLower::Initialize(Mangler *M, MCContext *C) {
> + Mang = M;
> + Ctx = C;
> +}
> +
> +MCOperand XCoreMCInstLower::LowerSymbolOperand(const MachineOperand &MO,
> + MachineOperandType MOTy,
> + unsigned Offset) const {
> + MCSymbolRefExpr::VariantKind Kind = MCSymbolRefExpr::VK_None;
> + const MCSymbol *Symbol;
> +
> + switch (MOTy) {
> + case MachineOperand::MO_MachineBasicBlock:
> + Symbol = MO.getMBB()->getSymbol();
> + break;
> + case MachineOperand::MO_GlobalAddress:
> + Symbol = Mang->getSymbol(MO.getGlobal());
> + Offset += MO.getOffset();
> + break;
> + case MachineOperand::MO_BlockAddress:
> + Symbol = Printer.GetBlockAddressSymbol(MO.getBlockAddress());
> + Offset += MO.getOffset();
> + break;
> + case MachineOperand::MO_ExternalSymbol:
> + Symbol = Printer.GetExternalSymbolSymbol(MO.getSymbolName());
> + Offset += MO.getOffset();
> + break;
> + case MachineOperand::MO_JumpTableIndex:
> + Symbol = Printer.GetJTISymbol(MO.getIndex());
> + break;
> + case MachineOperand::MO_ConstantPoolIndex:
> + Symbol = Printer.GetCPISymbol(MO.getIndex());
> + Offset += MO.getOffset();
> + break;
> + default:
> + llvm_unreachable("<unknown operand type>");
> + }
> +
> + const MCSymbolRefExpr *MCSym = MCSymbolRefExpr::Create(Symbol, Kind, *Ctx);
> +
> + if (!Offset)
> + return MCOperand::CreateExpr(MCSym);
> +
> + // Assume offset is never negative.
> + assert(Offset > 0);
> +
> + const MCConstantExpr *OffsetExpr = MCConstantExpr::Create(Offset, *Ctx);
> + const MCBinaryExpr *Add = MCBinaryExpr::CreateAdd(MCSym, OffsetExpr, *Ctx);
> + return MCOperand::CreateExpr(Add);
> +}
> +
> +MCOperand XCoreMCInstLower::LowerOperand(const MachineOperand &MO,
> + unsigned offset) const {
> + MachineOperandType MOTy = MO.getType();
> +
> + switch (MOTy) {
> + default: llvm_unreachable("unknown operand type");
> + case MachineOperand::MO_Register:
> + // Ignore all implicit register operands.
> + if (MO.isImplicit()) break;
> + return MCOperand::CreateReg(MO.getReg());
> + case MachineOperand::MO_Immediate:
> + return MCOperand::CreateImm(MO.getImm() + offset);
> + case MachineOperand::MO_MachineBasicBlock:
> + case MachineOperand::MO_GlobalAddress:
> + case MachineOperand::MO_ExternalSymbol:
> + case MachineOperand::MO_JumpTableIndex:
> + case MachineOperand::MO_ConstantPoolIndex:
> + case MachineOperand::MO_BlockAddress:
> + return LowerSymbolOperand(MO, MOTy, offset);
> + case MachineOperand::MO_RegisterMask:
> + break;
> + }
> +
> + return MCOperand();
> +}
> +
> +void XCoreMCInstLower::Lower(const MachineInstr *MI, MCInst &OutMI) const {
> + OutMI.setOpcode(MI->getOpcode());
> +
> + for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
> + const MachineOperand &MO = MI->getOperand(i);
> + MCOperand MCOp = LowerOperand(MO);
> +
> + if (MCOp.isValid())
> + OutMI.addOperand(MCOp);
> + }
> +}
>
> Added: llvm/trunk/lib/Target/XCore/XCoreMCInstLower.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/XCore/XCoreMCInstLower.h?rev=170288&view=auto
> ==============================================================================
> --- llvm/trunk/lib/Target/XCore/XCoreMCInstLower.h (added)
> +++ llvm/trunk/lib/Target/XCore/XCoreMCInstLower.h Sun Dec 16 10:20:48 2012
> @@ -0,0 +1,44 @@
> +//===-- XCoreMCInstLower.h - Lower MachineInstr to MCInst ------*- C++ -*--===//
> +//
> +// The LLVM Compiler Infrastructure
> +//
> +// This file is distributed under the University of Illinois Open Source
> +// License. See LICENSE.TXT for details.
> +//
> +//===----------------------------------------------------------------------===//
> +
> +#ifndef XCOREMCINSTLOWER_H
> +#define XCOREMCINSTLOWER_H
> +#include "llvm/ADT/SmallVector.h"
> +#include "llvm/CodeGen/MachineOperand.h"
> +#include "llvm/Support/Compiler.h"
> +
> +namespace llvm {
> + class MCContext;
> + class MCInst;
> + class MCOperand;
> + class MachineInstr;
> + class MachineFunction;
> + class Mangler;
> + class AsmPrinter;
> +
> +/// XCoreMCInstLower - This class is used to lower an MachineInstr into an
> +// MCInst.
> +class LLVM_LIBRARY_VISIBILITY XCoreMCInstLower {
> + typedef MachineOperand::MachineOperandType MachineOperandType;
> + MCContext *Ctx;
> + Mangler *Mang;
> + AsmPrinter &Printer;
> +public:
> + XCoreMCInstLower(class AsmPrinter &asmprinter);
> + void Initialize(Mangler *mang, MCContext *C);
> + void Lower(const MachineInstr *MI, MCInst &OutMI) const;
> + MCOperand LowerOperand(const MachineOperand& MO, unsigned offset = 0) const;
> +
> +private:
> + MCOperand LowerSymbolOperand(const MachineOperand &MO,
> + MachineOperandType MOTy, unsigned Offset) const;
> +};
> +}
> +
> +#endif
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list