llvm.org GIT mirror llvm / b3a847d
Allow the JIT ExecutionEngine to report details about the generated machine code. 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 Argyrios Kyrtzidis 11 years ago
4 changed file(s) with 42 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
3434 class Type;
3535 class MutexGuard;
3636 class JITMemoryManager;
37 class MachineCodeInfo;
3738
3839 class ExecutionEngineState {
3940 private:
240241 return getPointerToFunction(F);
241242 }
242243
244 // The JIT overrides a version that actually does this.
245 virtual void runJITOnFunction(Function *F, MachineCodeInfo *MCI = 0) { }
246
243247 /// getGlobalValueAtAddress - Return the LLVM global value object that starts
244248 /// at the specified address.
245249 ///
2020 #include "llvm/ModuleProvider.h"
2121 #include "llvm/CodeGen/MachineCodeEmitter.h"
2222 #include "llvm/ExecutionEngine/GenericValue.h"
23 #include "llvm/CodeGen/MachineCodeInfo.h"
2324 #include "llvm/Target/TargetData.h"
2425 #include "llvm/Target/TargetMachine.h"
2526 #include "llvm/Target/TargetJITInfo.h"
511512 /// just-in-time compilation passes on F, hopefully filling in
512513 /// GlobalAddress[F] with the address of F's machine code.
513514 ///
514 void JIT::runJITOnFunction(Function *F) {
515 void JIT::runJITOnFunction(Function *F, MachineCodeInfo *MCI) {
515516 MutexGuard locked(lock);
517
518 registerMachineCodeInfo(MCI);
519
516520 runJITOnFunctionUnlocked(F, locked);
521
522 registerMachineCodeInfo(0);
517523 }
518524
519525 void JIT::runJITOnFunctionUnlocked(Function *F, const MutexGuard &locked) {
2222 class TargetMachine;
2323 class TargetJITInfo;
2424 class MachineCodeEmitter;
25 class MachineCodeInfo;
2526
2627 class JITState {
2728 private:
150151 static ExecutionEngine *createJIT(ModuleProvider *MP, std::string *Err,
151152 JITMemoryManager *JMM,
152153 CodeGenOpt::Level OptLevel);
153
154
155
156 // Run the JIT on F and return information about the generated code
157 void runJITOnFunction(Function *F, MachineCodeInfo *MCI = 0);
158
154159 private:
155160 static MachineCodeEmitter *createEmitter(JIT &J, JITMemoryManager *JMM);
156 void runJITOnFunction(Function *F);
161 void registerMachineCodeInfo(MachineCodeInfo *MCI);
157162 void runJITOnFunctionUnlocked(Function *F, const MutexGuard &locked);
158163 void updateFunctionStub(Function *F);
159164 void updateDlsymStubTable();
160
165
161166 protected:
162167
163168 /// getMemoryforGV - Allocate memory for a global variable.
2525 #include "llvm/CodeGen/MachineRelocation.h"
2626 #include "llvm/ExecutionEngine/JITMemoryManager.h"
2727 #include "llvm/ExecutionEngine/GenericValue.h"
28 #include "llvm/CodeGen/MachineCodeInfo.h"
2829 #include "llvm/Target/TargetData.h"
2930 #include "llvm/Target/TargetJITInfo.h"
3031 #include "llvm/Target/TargetMachine.h"
613614 // ExtFnStubs - A map of external function names to stubs which have entries
614615 // in the JITResolver's ExternalFnToStubMap.
615616 StringMap ExtFnStubs;
616
617
618 // MCI - A pointer to a MachineCodeInfo object to update with information.
619 MachineCodeInfo *MCI;
620
617621 public:
618 JITEmitter(JIT &jit, JITMemoryManager *JMM) : Resolver(jit), CurFn(0) {
622 JITEmitter(JIT &jit, JITMemoryManager *JMM) : Resolver(jit), CurFn(0), MCI(0) {
619623 MemMgr = JMM ? JMM : JITMemoryManager::CreateDefaultMemManager();
620624 if (jit.getJITInfo().needsGOT()) {
621625 MemMgr->AllocateGOT();
710714 }
711715
712716 JITMemoryManager *getMemMgr(void) const { return MemMgr; }
717
718 void setMachineCodeInfo(MachineCodeInfo *mci) {
719 MCI = mci;
720 }
713721
714722 private:
715723 void *getPointerToGlobal(GlobalValue *GV, void *Reference, bool NoNeedStub);
11541162 << "] Function: " << F.getFunction()->getName()
11551163 << ": " << (FnEnd-FnStart) << " bytes of text, "
11561164 << Relocations.size() << " relocations\n";
1165
1166 if (MCI) {
1167 MCI->setAddress(FnStart);
1168 MCI->setSize(FnEnd-FnStart);
1169 }
1170
11571171 Relocations.clear();
11581172 ConstPoolAddresses.clear();
11591173
14771491 return JE->getJITResolver().getFunctionStub(F);
14781492 }
14791493
1494 void JIT::registerMachineCodeInfo(MachineCodeInfo *mc) {
1495 assert(isa(MCE) && "Unexpected MCE?");
1496 JITEmitter *JE = cast(getCodeEmitter());
1497
1498 JE->setMachineCodeInfo(mc);
1499 }
1500
14801501 void JIT::updateFunctionStub(Function *F) {
14811502 // Get the empty stub we generated earlier.
14821503 assert(isa(MCE) && "Unexpected MCE?");