Allow the JIT ExecutionEngine to report details about the generated machine code.
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Mon, 18 May 2009 21:06:40 +0000 (21:06 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Mon, 18 May 2009 21:06:40 +0000 (21:06 +0000)
Introduce a new class (MachineCodeInfo) that the JIT can fill in with details. Right now, just the address and the size of the machine code are reported.

Patch by Evan Phoenix!

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@72040 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ExecutionEngine/ExecutionEngine.h
lib/ExecutionEngine/JIT/JIT.cpp
lib/ExecutionEngine/JIT/JIT.h
lib/ExecutionEngine/JIT/JITEmitter.cpp

index 5df11f33ba009453a72f1d017e28315930672ca3..0d171f6764d0b6064d5c71c341a12d1617ce0cdb 100644 (file)
@@ -35,6 +35,7 @@ class TargetData;
 class Type;
 class MutexGuard;
 class JITMemoryManager;
+class MachineCodeInfo;
 
 class ExecutionEngineState {
 private:
@@ -241,6 +242,9 @@ public:
     return getPointerToFunction(F);
   }
 
+  // The JIT overrides a version that actually does this.
+  virtual void runJITOnFunction(Function *F, MachineCodeInfo *MCI = 0) { }
+
   /// getGlobalValueAtAddress - Return the LLVM global value object that starts
   /// at the specified address.
   ///
index 21e670aadc9cb0a25ae5164e0938c3255678dd0c..522a08dd78340c991e216805417846e0954afb1e 100644 (file)
@@ -21,6 +21,7 @@
 #include "llvm/ModuleProvider.h"
 #include "llvm/CodeGen/MachineCodeEmitter.h"
 #include "llvm/ExecutionEngine/GenericValue.h"
+#include "llvm/CodeGen/MachineCodeInfo.h"
 #include "llvm/Target/TargetData.h"
 #include "llvm/Target/TargetMachine.h"
 #include "llvm/Target/TargetJITInfo.h"
@@ -512,9 +513,14 @@ GenericValue JIT::runFunction(Function *F,
 /// just-in-time compilation passes on F, hopefully filling in
 /// GlobalAddress[F] with the address of F's machine code.
 ///
-void JIT::runJITOnFunction(Function *F) {
+void JIT::runJITOnFunction(Function *F, MachineCodeInfo *MCI) {
   MutexGuard locked(lock);
+
+  registerMachineCodeInfo(MCI);
+
   runJITOnFunctionUnlocked(F, locked);
+
+  registerMachineCodeInfo(0);
 }
 
 void JIT::runJITOnFunctionUnlocked(Function *F, const MutexGuard &locked) {
index d5646063e987fcd33b22acef6ed1800dbc27a7a0..02955ab3ad8dd02f1fdb5bf4b87bbbb4099c2c06 100644 (file)
@@ -23,6 +23,7 @@ class Function;
 class TargetMachine;
 class TargetJITInfo;
 class MachineCodeEmitter;
+class MachineCodeInfo;
 
 class JITState {
 private:
@@ -151,14 +152,18 @@ public:
   static ExecutionEngine *createJIT(ModuleProvider *MP, std::string *Err,
                                     JITMemoryManager *JMM,
                                     CodeGenOpt::Level OptLevel);
-  
+
+
+  // Run the JIT on F and return information about the generated code
+  void runJITOnFunction(Function *F, MachineCodeInfo *MCI = 0);
+
 private:
   static MachineCodeEmitter *createEmitter(JIT &J, JITMemoryManager *JMM);
-  void runJITOnFunction(Function *F);
+  void registerMachineCodeInfo(MachineCodeInfo *MCI);
   void runJITOnFunctionUnlocked(Function *F, const MutexGuard &locked);
   void updateFunctionStub(Function *F);
   void updateDlsymStubTable();
-  
+
 protected:
 
   /// getMemoryforGV - Allocate memory for a global variable.
index 58563563887c3b6233d705364f190a06ae8592e5..fe1d96ad19a8b60a713524fd6c7908bf6b659e89 100644 (file)
@@ -26,6 +26,7 @@
 #include "llvm/CodeGen/MachineRelocation.h"
 #include "llvm/ExecutionEngine/JITMemoryManager.h"
 #include "llvm/ExecutionEngine/GenericValue.h"
+#include "llvm/CodeGen/MachineCodeInfo.h"
 #include "llvm/Target/TargetData.h"
 #include "llvm/Target/TargetJITInfo.h"
 #include "llvm/Target/TargetMachine.h"
@@ -614,9 +615,12 @@ namespace {
     // ExtFnStubs - A map of external function names to stubs which have entries
     // in the JITResolver's ExternalFnToStubMap.
     StringMap<void *> ExtFnStubs;
-    
+
+    // MCI - A pointer to a MachineCodeInfo object to update with information.
+    MachineCodeInfo *MCI;
+
   public:
-    JITEmitter(JIT &jit, JITMemoryManager *JMM) : Resolver(jit), CurFn(0) {
+    JITEmitter(JIT &jit, JITMemoryManager *JMM) : Resolver(jit), CurFn(0), MCI(0) {
       MemMgr = JMM ? JMM : JITMemoryManager::CreateDefaultMemManager();
       if (jit.getJITInfo().needsGOT()) {
         MemMgr->AllocateGOT();
@@ -712,6 +716,10 @@ namespace {
     
     JITMemoryManager *getMemMgr(void) const { return MemMgr; }
 
+    void setMachineCodeInfo(MachineCodeInfo *mci) {
+      MCI = mci;
+    }
+
   private:
     void *getPointerToGlobal(GlobalValue *GV, void *Reference, bool NoNeedStub);
     void *getPointerToGVIndirectSym(GlobalValue *V, void *Reference,
@@ -1155,6 +1163,12 @@ bool JITEmitter::finishFunction(MachineFunction &F) {
        << "] Function: " << F.getFunction()->getName()
        << ": " << (FnEnd-FnStart) << " bytes of text, "
        << Relocations.size() << " relocations\n";
+
+  if (MCI) {
+    MCI->setAddress(FnStart);
+    MCI->setSize(FnEnd-FnStart);
+  }
+
   Relocations.clear();
   ConstPoolAddresses.clear();
 
@@ -1478,6 +1492,13 @@ void *JIT::getPointerToFunctionOrStub(Function *F) {
   return JE->getJITResolver().getFunctionStub(F);
 }
 
+void JIT::registerMachineCodeInfo(MachineCodeInfo *mc) {
+  assert(isa<JITEmitter>(MCE) && "Unexpected MCE?");
+  JITEmitter *JE = cast<JITEmitter>(getCodeEmitter());
+
+  JE->setMachineCodeInfo(mc);
+}
+
 void JIT::updateFunctionStub(Function *F) {
   // Get the empty stub we generated earlier.
   assert(isa<JITEmitter>(MCE) && "Unexpected MCE?");