gallivm,draw,llvmpipe: Support wider native registers.
[mesa.git] / src / gallium / auxiliary / gallivm / lp_bld_debug.cpp
index bb2c82fe0eddb5cb3c67525d223c3b560db1498c..93505f3da455cb6f422f003e896ac03f1703752b 100644 (file)
  *
  **************************************************************************/
 
+#include <stddef.h>
+
 #include <llvm-c/Core.h>
 #include <llvm/Target/TargetMachine.h>
-#include <llvm/Target/TargetRegistry.h>
-#include <llvm/Target/TargetSelect.h>
 #include <llvm/Target/TargetInstrInfo.h>
 #include <llvm/Support/raw_ostream.h>
 #include <llvm/Support/MemoryObject.h>
+
+#if HAVE_LLVM >= 0x0300
+#include <llvm/Support/TargetRegistry.h>
+#else /* HAVE_LLVM < 0x0300 */
+#include <llvm/Target/TargetRegistry.h>
+#endif /* HAVE_LLVM < 0x0300 */
+
+#if HAVE_LLVM >= 0x0209
+#include <llvm/Support/Host.h>
+#else /* HAVE_LLVM < 0x0209 */
 #include <llvm/System/Host.h>
+#endif /* HAVE_LLVM < 0x0209 */
 
 #if HAVE_LLVM >= 0x0207
 #include <llvm/MC/MCDisassembler.h>
@@ -40,6 +51,9 @@
 #include <llvm/MC/MCInst.h>
 #include <llvm/MC/MCInstPrinter.h>
 #endif /* HAVE_LLVM >= 0x0207 */
+#if HAVE_LLVM >= 0x0301
+#include <llvm/MC/MCRegisterInfo.h>
+#endif /* HAVE_LLVM >= 0x0301 */
 
 #include "util/u_math.h"
 #include "util/u_debug.h"
@@ -70,12 +84,12 @@ class raw_debug_ostream :
    uint64_t pos;
 
    void write_impl(const char *Ptr, size_t Size);
-   uint64_t current_pos() { return pos; }
-   uint64_t current_pos() const { return pos; }
 
 #if HAVE_LLVM >= 0x207
-   uint64_t preferred_buffer_size() { return 512; }
+   uint64_t current_pos() const { return pos; }
+   size_t preferred_buffer_size() const { return 512; }
 #else
+   uint64_t current_pos() { return pos; }
    size_t preferred_buffer_size() { return 512; }
 #endif
 };
@@ -167,7 +181,7 @@ lp_disassemble(const void* func)
    /*
     * Limit disassembly to this extent
     */
-   const uint64_t extent = 0x10000;
+   const uint64_t extent = 96 * 1024;
 
    uint64_t max_pc = 0;
 
@@ -175,27 +189,32 @@ lp_disassemble(const void* func)
     * Initialize all used objects.
     */
 
+#if HAVE_LLVM >= 0x0301
+   std::string Triple = sys::getDefaultTargetTriple();
+#else
    std::string Triple = sys::getHostTriple();
+#endif
 
    std::string Error;
    const Target *T = TargetRegistry::lookupTarget(Triple, Error);
 
-#if HAVE_LLVM >= 0x0208
-   InitializeNativeTargetAsmPrinter();
+#if HAVE_LLVM >= 0x0300
+   OwningPtr<const MCAsmInfo> AsmInfo(T->createMCAsmInfo(Triple));
 #else
-   InitializeAllAsmPrinters();
-#endif
-
-   InitializeAllDisassemblers();
-
    OwningPtr<const MCAsmInfo> AsmInfo(T->createAsmInfo(Triple));
+#endif
 
    if (!AsmInfo) {
       debug_printf("error: no assembly info for target %s\n", Triple.c_str());
       return;
    }
 
+#if HAVE_LLVM >= 0x0300
+   const MCSubtargetInfo *STI = T->createMCSubtargetInfo(Triple, sys::getHostCPUName(), "");
+   OwningPtr<const MCDisassembler> DisAsm(T->createMCDisassembler(*STI));
+#else 
    OwningPtr<const MCDisassembler> DisAsm(T->createMCDisassembler());
+#endif 
    if (!DisAsm) {
       debug_printf("error: no disassembler for target %s\n", Triple.c_str());
       return;
@@ -203,8 +222,33 @@ lp_disassemble(const void* func)
 
    raw_debug_ostream Out;
 
+#if HAVE_LLVM >= 0x0300
+   unsigned int AsmPrinterVariant = AsmInfo->getAssemblerDialect();
+#else
    int AsmPrinterVariant = AsmInfo->getAssemblerDialect();
-#if HAVE_LLVM >= 0x0208
+#endif
+
+#if HAVE_LLVM >= 0x0301
+   OwningPtr<const MCRegisterInfo> MRI(T->createMCRegInfo(Triple));
+   if (!MRI) {
+      debug_printf("error: no register info for target %s\n", Triple.c_str());
+      return;
+   }
+
+   OwningPtr<const MCInstrInfo> MII(T->createMCInstrInfo());
+   if (!MII) {
+      debug_printf("error: no instruction info for target %s\n", Triple.c_str());
+      return;
+   }
+#endif
+
+#if HAVE_LLVM >= 0x0301
+   OwningPtr<MCInstPrinter> Printer(
+         T->createMCInstPrinter(AsmPrinterVariant, *AsmInfo, *MII, *MRI, *STI));
+#elif HAVE_LLVM == 0x0300
+   OwningPtr<MCInstPrinter> Printer(
+         T->createMCInstPrinter(AsmPrinterVariant, *AsmInfo, *STI));
+#elif HAVE_LLVM >= 0x0208
    OwningPtr<MCInstPrinter> Printer(
          T->createMCInstPrinter(AsmPrinterVariant, *AsmInfo));
 #else
@@ -216,7 +260,23 @@ lp_disassemble(const void* func)
       return;
    }
 
+#if HAVE_LLVM >= 0x0301
+   TargetOptions options;
+#if defined(DEBUG)
+   options.JITEmitDebugInfo = true;
+#endif
+#if defined(PIPE_ARCH_X86)
+   options.StackAlignmentOverride = 4;
+#endif
+#if defined(DEBUG) || defined(PROFILE)
+   options.NoFramePointerElim = true;
+#endif
+   TargetMachine *TM = T->createTargetMachine(Triple, sys::getHostCPUName(), "", options);
+#elif HAVE_LLVM == 0x0300
+   TargetMachine *TM = T->createTargetMachine(Triple, sys::getHostCPUName(), "");
+#else
    TargetMachine *TM = T->createTargetMachine(Triple, "");
+#endif
 
    const TargetInstrInfo *TII = TM->getInstrInfo();
 
@@ -240,7 +300,11 @@ lp_disassemble(const void* func)
 
       if (!DisAsm->getInstruction(Inst, Size, memoryObject,
                                  pc,
-                                 nulls())) {
+#if HAVE_LLVM >= 0x0300
+                                 nulls(), nulls())) {
+#else
+                                 nulls())) {
+#endif
          debug_printf("invalid\n");
          pc += 1;
       }
@@ -263,7 +327,9 @@ lp_disassemble(const void* func)
        * Print the instruction.
        */
 
-#if HAVE_LLVM >= 0x208
+#if HAVE_LLVM >= 0x0300
+      Printer->printInst(&Inst, Out, "");
+#elif HAVE_LLVM >= 0x208
       Printer->printInst(&Inst, Out);
 #else
       Printer->printInst(&Inst);
@@ -276,7 +342,11 @@ lp_disassemble(const void* func)
 
       pc += Size;
 
+#if HAVE_LLVM >= 0x0300
+      const MCInstrDesc &TID = TII->get(Inst.getOpcode());
+#else
       const TargetInstrDesc &TID = TII->get(Inst.getOpcode());
+#endif
 
       /*
        * Keep track of forward jumps to a nearby address.