svn commit: r222959 - in projects/llvm-ia64: contrib/llvm/lib/Target/IA64 contrib/llvm/lib/Target/IA64/InstPrinter lib/clang lib/clang/libllvmia64codegen lib/clang/libllvmia64instprinter usr.bin/cl...

Marcel Moolenaar marcel at FreeBSD.org
Fri Jun 10 23:05:51 UTC 2011


Author: marcel
Date: Fri Jun 10 23:05:51 2011
New Revision: 222959
URL: http://svn.freebsd.org/changeset/base/222959

Log:
  Add the AsmPrinter and InstPrinter classes. Unfortunately, this
  doesn't change the falure more (though it may have changed when
  or where it happens).
  
  Suggested by: rdivacky

Added:
  projects/llvm-ia64/contrib/llvm/lib/Target/IA64/IA64MCInstLower.cpp
  projects/llvm-ia64/contrib/llvm/lib/Target/IA64/IA64MCInstLower.h
  projects/llvm-ia64/contrib/llvm/lib/Target/IA64/InstPrinter/
  projects/llvm-ia64/contrib/llvm/lib/Target/IA64/InstPrinter/IA64InstPrinter.cpp
  projects/llvm-ia64/contrib/llvm/lib/Target/IA64/InstPrinter/IA64InstPrinter.h
  projects/llvm-ia64/lib/clang/libllvmia64instprinter/
  projects/llvm-ia64/lib/clang/libllvmia64instprinter/Makefile
Modified:
  projects/llvm-ia64/contrib/llvm/lib/Target/IA64/IA64.td
  projects/llvm-ia64/contrib/llvm/lib/Target/IA64/IA64AsmPrinter.cpp
  projects/llvm-ia64/lib/clang/Makefile
  projects/llvm-ia64/lib/clang/libllvmia64codegen/Makefile
  projects/llvm-ia64/usr.bin/clang/clang/Makefile

Modified: projects/llvm-ia64/contrib/llvm/lib/Target/IA64/IA64.td
==============================================================================
--- projects/llvm-ia64/contrib/llvm/lib/Target/IA64/IA64.td	Fri Jun 10 22:48:35 2011	(r222958)
+++ projects/llvm-ia64/contrib/llvm/lib/Target/IA64/IA64.td	Fri Jun 10 23:05:51 2011	(r222959)
@@ -48,8 +48,17 @@ def NOP : IA64Instruction<(outs), (ins)>
 def IA64InstrInfo : InstrInfo;
 
 //
+// Machine code and assembly writer
+//
+def IA64InstPrinter : AsmWriter {
+  string AsmWriterClassName  = "InstPrinter";
+  bit isMCAsmWriter = 1;
+}
+
+//
 // Target for the Itanium Processor Family (IPF)
 //
 def IA64 : Target {
   let InstructionSet = IA64InstrInfo;
+  let AssemblyWriters = [IA64InstPrinter];
 }

Modified: projects/llvm-ia64/contrib/llvm/lib/Target/IA64/IA64AsmPrinter.cpp
==============================================================================
--- projects/llvm-ia64/contrib/llvm/lib/Target/IA64/IA64AsmPrinter.cpp	Fri Jun 10 22:48:35 2011	(r222958)
+++ projects/llvm-ia64/contrib/llvm/lib/Target/IA64/IA64AsmPrinter.cpp	Fri Jun 10 23:05:51 2011	(r222959)
@@ -1,56 +1,131 @@
 #include "IA64.h"
+#include "IA64InstrInfo.h"
+#include "IA64MCAsmInfo.h"
+#include "IA64MCInstLower.h"
+#include "IA64TargetMachine.h"
+#include "InstPrinter/IA64InstPrinter.h"
 
+#include "llvm/Constants.h"
+#include "llvm/DerivedTypes.h"
 #include "llvm/Module.h"
-#include "llvm/Type.h"
+#include "llvm/Assembly/Writer.h"
 #include "llvm/CodeGen/AsmPrinter.h"
-#include "llvm/CodeGen/DwarfWriter.h"
+#include "llvm/CodeGen/MachineModuleInfo.h"
 #include "llvm/CodeGen/MachineFunctionPass.h"
-#include "llvm/MC/MCAsmInfo.h"
+#include "llvm/CodeGen/MachineConstantPool.h"
+#include "llvm/CodeGen/MachineInstr.h"
+#include "llvm/MC/MCInst.h"
+#include "llvm/MC/MCStreamer.h"
+#include "llvm/MC/MCSymbol.h"
+#include "llvm/Target/Mangler.h"
+#include "llvm/Target/TargetData.h"
+#include "llvm/Target/TargetLoweringObjectFile.h"
 #include "llvm/Target/TargetRegistry.h"
 #include "llvm/Support/ErrorHandling.h"
-#include "llvm/Support/FormattedStream.h"
-#include "llvm/ADT/Statistic.h"
+#include "llvm/Support/raw_ostream.h"
 
 using namespace llvm;
 
 namespace {
+
   class IA64AsmPrinter : public AsmPrinter {
-    std::set<std::string> ExternalFunctionNames, ExternalObjectNames;
   public:
-    explicit IA64AsmPrinter(formatted_raw_ostream &O, TargetMachine &TM,
-	    const MCAsmInfo *T, bool V) :
-        AsmPrinter(O, TM, T, V) {}
+    IA64AsmPrinter(TargetMachine &TM, MCStreamer &Streamer) :
+        AsmPrinter(TM, Streamer) {}
 
     virtual const char *getPassName() const {
-      return "IA64 Assembly Printer";
+      return "IA-64 Assembly Printer";
     }
 
-    static const char *getRegisterName(unsigned RegNo);
-
-    void PrintGlobalVariable(const GlobalVariable *GVar);
-
-    void printInstruction(const MachineInstr *MI);
-    bool runOnMachineFunction(MachineFunction &F);
+    void printOperand(const MachineInstr *MI, int OpNum, raw_ostream &O,
+          const char* Modifier = 0);
+    void printSrcMemOperand(const MachineInstr *MI, int OpNum, raw_ostream &O);
+    bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
+          unsigned AsmVariant, const char *ExtraCode, raw_ostream &O);
+    bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
+          unsigned AsmVariant, const char *ExtraCode, raw_ostream &O);
+    void EmitInstruction(const MachineInstr *MI);
   };
-} // end of anonymous namespace
 
-#include "IA64GenAsmWriter.inc"
+} // end of anonymous namespace
 
 void
-IA64AsmPrinter::PrintGlobalVariable(const GlobalVariable *GVar)
+IA64AsmPrinter::printOperand(const MachineInstr *MI, int OpNum,
+      raw_ostream &O, const char *Modifier)
 {
   llvm_unreachable(__func__);
 }
 
+void
+IA64AsmPrinter::printSrcMemOperand(const MachineInstr *MI, int OpNum,
+      raw_ostream &O)
+{
+  const MachineOperand &Base = MI->getOperand(OpNum);
+  const MachineOperand &Disp = MI->getOperand(OpNum+1);
+
+  // Print displacement first
+
+  // Imm here is in fact global address - print extra modifier.
+  if (Disp.isImm() && !Base.getReg())
+    O << '&';
+  printOperand(MI, OpNum+1, O, "nohash");
+
+  // Print register base field
+  if (Base.getReg()) {
+    O << '(';
+    printOperand(MI, OpNum, O);
+    O << ')';
+  }
+}
+
+/// PrintAsmOperand - Print out an operand for an inline asm expression.
 bool
-IA64AsmPrinter::runOnMachineFunction(MachineFunction &MF)
+IA64AsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
+      unsigned AsmVariant, const char *ExtraCode, raw_ostream &O)
 {
-  llvm_unreachable(__func__);
+  // Does this asm operand have a single letter operand modifier?
+  if (ExtraCode && ExtraCode[0])
+    return true; // Unknown modifier.
+
+  printOperand(MI, OpNo, O);
+  return false;
+}
+
+bool
+IA64AsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
+      unsigned AsmVariant, const char *ExtraCode, raw_ostream &O)
+{
+  if (ExtraCode && ExtraCode[0]) {
+    return true; // Unknown modifier.
+  }
+  printSrcMemOperand(MI, OpNo, O);
+  return false;
+}
+
+void
+IA64AsmPrinter::EmitInstruction(const MachineInstr *MI)
+{
+  IA64MCInstLower MCInstLowering(OutContext, *Mang, *this);
+
+  MCInst TmpInst;
+  MCInstLowering.Lower(MI, TmpInst);
+  OutStreamer.EmitInstruction(TmpInst);
 }
 
+static
+MCInstPrinter *createIA64MCInstPrinter(const Target &T, TargetMachine &TM,
+      unsigned SyntaxVariant, const MCAsmInfo &MAI)
+{
+  if (SyntaxVariant == 0)
+    return new IA64InstPrinter(TM, MAI);
+  return 0;
+}
 
+// Force static initialization.
 extern "C" void
 LLVMInitializeIA64AsmPrinter()
 {
   RegisterAsmPrinter<IA64AsmPrinter> X(TheIA64Target);
+  TargetRegistry::RegisterMCInstPrinter(TheIA64Target,
+        createIA64MCInstPrinter);
 }

Added: projects/llvm-ia64/contrib/llvm/lib/Target/IA64/IA64MCInstLower.cpp
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ projects/llvm-ia64/contrib/llvm/lib/Target/IA64/IA64MCInstLower.cpp	Fri Jun 10 23:05:51 2011	(r222959)
@@ -0,0 +1,58 @@
+#include "IA64MCInstLower.h"
+
+#include "llvm/CodeGen/AsmPrinter.h"
+#include "llvm/CodeGen/MachineBasicBlock.h"
+#include "llvm/CodeGen/MachineInstr.h"
+#include "llvm/MC/MCAsmInfo.h"
+#include "llvm/MC/MCContext.h"
+#include "llvm/MC/MCExpr.h"
+#include "llvm/MC/MCInst.h"
+#include "llvm/Target/Mangler.h"
+#include "llvm/Support/raw_ostream.h"
+#include "llvm/Support/ErrorHandling.h"
+#include "llvm/ADT/SmallString.h"
+
+using namespace llvm;
+
+MCSymbol *
+IA64MCInstLower::GetGlobalAddressSymbol(const MachineOperand &MO) const
+{
+  llvm_unreachable(__func__);
+}
+
+MCSymbol *
+IA64MCInstLower::GetExternalSymbolSymbol(const MachineOperand &MO) const
+{
+  llvm_unreachable(__func__);
+}
+
+MCSymbol *
+IA64MCInstLower::GetJumpTableSymbol(const MachineOperand &MO) const
+{
+  llvm_unreachable(__func__);
+}
+
+MCSymbol *
+IA64MCInstLower::GetConstantPoolIndexSymbol(const MachineOperand &MO) const
+{
+  llvm_unreachable(__func__);
+}
+
+MCSymbol *
+IA64MCInstLower::GetBlockAddressSymbol(const MachineOperand &MO) const
+{
+  llvm_unreachable(__func__);
+}
+
+MCOperand
+IA64MCInstLower::LowerSymbolOperand(const MachineOperand &MO, MCSymbol *Sym)
+      const
+{
+  llvm_unreachable(__func__);
+}
+
+void
+IA64MCInstLower::Lower(const MachineInstr *MI, MCInst &OutMI) const
+{
+  llvm_unreachable(__func__);
+}

Added: projects/llvm-ia64/contrib/llvm/lib/Target/IA64/IA64MCInstLower.h
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ projects/llvm-ia64/contrib/llvm/lib/Target/IA64/IA64MCInstLower.h	Fri Jun 10 23:05:51 2011	(r222959)
@@ -0,0 +1,42 @@
+#ifndef LLVM_TARGET_IA64_MCINSTLOWER_H
+#define LLVM_TARGET_IA64_MCINSTLOWER_H
+
+#include "llvm/Support/Compiler.h"
+
+namespace llvm {
+
+  class AsmPrinter;
+  class MCAsmInfo;
+  class MCContext;
+  class MCInst;
+  class MCOperand;
+  class MCSymbol;
+  class MachineInstr;
+  class MachineModuleInfoMachO;
+  class MachineOperand;
+  class Mangler;
+
+  /// IA64MCInstLower - This class is used to lower an MachineInstr
+  /// into an MCInst.
+  class LLVM_LIBRARY_VISIBILITY IA64MCInstLower {
+    MCContext &Ctx;
+    Mangler &Mang;
+
+    AsmPrinter &Printer;
+  public:
+    IA64MCInstLower(MCContext &ctx, Mangler &mang, AsmPrinter &printer) :
+          Ctx(ctx), Mang(mang), Printer(printer) {}
+    void Lower(const MachineInstr *MI, MCInst &OutMI) const;
+
+    MCOperand LowerSymbolOperand(const MachineOperand &MO, MCSymbol *Sym) const;
+
+    MCSymbol *GetGlobalAddressSymbol(const MachineOperand &MO) const;
+    MCSymbol *GetExternalSymbolSymbol(const MachineOperand &MO) const;
+    MCSymbol *GetJumpTableSymbol(const MachineOperand &MO) const;
+    MCSymbol *GetConstantPoolIndexSymbol(const MachineOperand &MO) const;
+    MCSymbol *GetBlockAddressSymbol(const MachineOperand &MO) const;
+  };
+
+} // namespace llvm
+
+#endif // LLVM_TARGET_IA64_MCINSTLOWER_H

Added: projects/llvm-ia64/contrib/llvm/lib/Target/IA64/InstPrinter/IA64InstPrinter.cpp
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ projects/llvm-ia64/contrib/llvm/lib/Target/IA64/InstPrinter/IA64InstPrinter.cpp	Fri Jun 10 23:05:51 2011	(r222959)
@@ -0,0 +1,84 @@
+#include "IA64.h"
+#include "IA64InstPrinter.h"
+
+#include "llvm/MC/MCInst.h"
+#include "llvm/MC/MCAsmInfo.h"
+#include "llvm/MC/MCExpr.h"
+#include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/FormattedStream.h"
+
+using namespace llvm;
+
+// Include the auto-generated portion of the assembly writer.
+#include "IA64GenAsmWriter.inc"
+
+void
+IA64InstPrinter::printInst(const MCInst *MI, raw_ostream &O)
+{
+  printInstruction(MI, O);
+}
+
+void
+IA64InstPrinter::printPCRelImmOperand(const MCInst *MI, unsigned OpNo,
+      raw_ostream &O)
+{
+  const MCOperand &Op = MI->getOperand(OpNo);
+  if (Op.isImm())
+    O << Op.getImm();
+  else {
+    assert(Op.isExpr() && "unknown pcrel immediate operand");
+    O << *Op.getExpr();
+  }
+}
+
+void
+IA64InstPrinter::printOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O,
+      const char *Modifier)
+{
+  assert((Modifier == 0 || Modifier[0] == 0) && "No modifiers supported");
+  const MCOperand &Op = MI->getOperand(OpNo);
+  if (Op.isReg()) {
+    O << getRegisterName(Op.getReg());
+  } else if (Op.isImm()) {
+    O << '#' << Op.getImm();
+  } else {
+    assert(Op.isExpr() && "unknown operand kind in printOperand");
+    O << '#' << *Op.getExpr();
+  }
+}
+
+void IA64InstPrinter::printSrcMemOperand(const MCInst *MI, unsigned OpNo,
+      raw_ostream &O, const char *Modifier)
+{
+  const MCOperand &Base = MI->getOperand(OpNo);
+  const MCOperand &Disp = MI->getOperand(OpNo+1);
+
+  // Print displacement first
+
+  // If the global address expression is a part of displacement field with a
+  // register base, we should not emit any prefix symbol here, e.g.
+  //   mov.w &foo, r1
+  // vs
+  //   mov.w glb(r1), r2
+  // Otherwise (!) msp430-as will silently miscompile the output :(
+  if (!Base.getReg())
+    O << '&';
+
+  if (Disp.isExpr())
+    O << *Disp.getExpr();
+  else {
+    assert(Disp.isImm() && "Expected immediate in displacement field");
+    O << Disp.getImm();
+  }
+
+  // Print register base field
+  if (Base.getReg())
+    O << '(' << getRegisterName(Base.getReg()) << ')';
+}
+
+void
+IA64InstPrinter::printCCOperand(const MCInst *MI, unsigned OpNo,
+      raw_ostream &O)
+{
+  llvm_unreachable(__func__);
+}

Added: projects/llvm-ia64/contrib/llvm/lib/Target/IA64/InstPrinter/IA64InstPrinter.h
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ projects/llvm-ia64/contrib/llvm/lib/Target/IA64/InstPrinter/IA64InstPrinter.h	Fri Jun 10 23:05:51 2011	(r222959)
@@ -0,0 +1,32 @@
+#ifndef LLVM_TARGET_IA64_INSTPRINTER_H
+#define LLVM_TARGET_IA64_INSTPRINTER_H
+
+#include "llvm/MC/MCInstPrinter.h"
+
+namespace llvm {
+
+  class MCOperand;
+  class TargetMachine;
+
+  class IA64InstPrinter : public MCInstPrinter {
+  public:
+    IA64InstPrinter(TargetMachine &TM, const MCAsmInfo &MAI) :
+        MCInstPrinter(MAI) {}
+
+    virtual void printInst(const MCInst *MI, raw_ostream &O);
+
+    // Autogenerated by tblgen.
+    void printInstruction(const MCInst *MI, raw_ostream &O);
+    static const char *getRegisterName(unsigned RegNo);
+
+    void printOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O,
+          const char *Modifier = 0);
+    void printPCRelImmOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O);
+    void printSrcMemOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O,
+          const char *Modifier = 0);
+    void printCCOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O);
+  };
+
+} // namespace llvm
+
+#endif // LLVM_TARGET_IA64_INSTPRINTER_H

Modified: projects/llvm-ia64/lib/clang/Makefile
==============================================================================
--- projects/llvm-ia64/lib/clang/Makefile	Fri Jun 10 22:48:35 2011	(r222958)
+++ projects/llvm-ia64/lib/clang/Makefile	Fri Jun 10 23:05:51 2011	(r222959)
@@ -44,6 +44,7 @@ SUBDIR=	libclanganalysis \
 	libllvmarminstprinter \
 	libllvmia64codegen \
 	libllvmia64info \
+	libllvmia64instprinter \
 	libllvmmipscodegen \
 	libllvmmipsinfo \
 	libllvmpowerpccodegen \

Modified: projects/llvm-ia64/lib/clang/libllvmia64codegen/Makefile
==============================================================================
--- projects/llvm-ia64/lib/clang/libllvmia64codegen/Makefile	Fri Jun 10 22:48:35 2011	(r222958)
+++ projects/llvm-ia64/lib/clang/libllvmia64codegen/Makefile	Fri Jun 10 23:05:51 2011	(r222959)
@@ -4,10 +4,12 @@ LIB=	llvmia64codegen
 
 SRCDIR=	lib/Target/IA64
 SRCS=	\
+	IA64AsmPrinter.cpp \
 	IA64FrameLowering.cpp \
 	IA64InstrInfo.cpp \
 	IA64TargetLowering.cpp \
 	IA64MCAsmInfo.cpp \
+	IA64MCInstLower.cpp \
 	IA64RegisterInfo.cpp \
 	IA64SelectionDAGInfo.cpp \
 	IA64Subtarget.cpp \

Added: projects/llvm-ia64/lib/clang/libllvmia64instprinter/Makefile
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ projects/llvm-ia64/lib/clang/libllvmia64instprinter/Makefile	Fri Jun 10 23:05:51 2011	(r222959)
@@ -0,0 +1,14 @@
+# $FreeBSD$
+
+LIB=	llvmia64instprinter
+
+SRCDIR=	lib/Target/IA64/InstPrinter
+INCDIR=	lib/Target/IA64
+SRCS=	IA64InstPrinter.cpp
+
+TGHDRS=	\
+	IA64GenAsmWriter \
+	IA64GenInstrNames \
+	IA64GenRegisterNames
+
+.include "../clang.lib.mk"

Modified: projects/llvm-ia64/usr.bin/clang/clang/Makefile
==============================================================================
--- projects/llvm-ia64/usr.bin/clang/clang/Makefile	Fri Jun 10 22:48:35 2011	(r222958)
+++ projects/llvm-ia64/usr.bin/clang/clang/Makefile	Fri Jun 10 23:05:51 2011	(r222959)
@@ -47,6 +47,7 @@ LIBDEPS=clangfrontendtool \
 	llvmarminfo \
 	llvmia64codegen \
 	llvmia64info \
+	llvmia64instprinter \
 	llvmmipscodegen \
 	llvmmipsinfo \
 	llvmpowerpccodegen \


More information about the svn-src-projects mailing list