1 //===-- JITEmitter.cpp - Write machine code to executable memory ----------===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines a MachineCodeEmitter object that is used by the JIT to
11 // write machine code to memory and remember where relocatable values are.
13 //===----------------------------------------------------------------------===//
15 #define DEBUG_TYPE "jit"
17 #include "llvm/Constant.h"
18 #include "llvm/Module.h"
19 #include "llvm/Type.h"
20 #include "llvm/CodeGen/MachineCodeEmitter.h"
21 #include "llvm/CodeGen/MachineFunction.h"
22 #include "llvm/CodeGen/MachineConstantPool.h"
23 #include "llvm/CodeGen/MachineJumpTableInfo.h"
24 #include "llvm/CodeGen/MachineRelocation.h"
25 #include "llvm/ExecutionEngine/GenericValue.h"
26 #include "llvm/Target/TargetData.h"
27 #include "llvm/Target/TargetJITInfo.h"
28 #include "llvm/Support/Debug.h"
29 #include "llvm/ADT/Statistic.h"
30 #include "llvm/System/Memory.h"
36 Statistic<> NumBytes("jit", "Number of bytes of machine code compiled");
37 Statistic<> NumRelos("jit", "Number of relocations applied");
42 //===----------------------------------------------------------------------===//
43 // JITMemoryManager code.
46 /// JITMemoryManager - Manage memory for the JIT code generation in a logical,
47 /// sane way. This splits a large block of MAP_NORESERVE'd memory into two
48 /// sections, one for function stubs, one for the functions themselves. We
49 /// have to do this because we may need to emit a function stub while in the
50 /// middle of emitting a function, and we don't know how large the function we
51 /// are emitting is. This never bothers to release the memory, because when
52 /// we are ready to destroy the JIT, the program exits.
53 class JITMemoryManager {
54 std::vector<sys::MemoryBlock> Blocks; // Memory blocks allocated by the JIT
55 unsigned char *FunctionBase; // Start of the function body area
56 unsigned char *CurStubPtr, *CurFunctionPtr;
57 unsigned char *GOTBase; // Target Specific reserved memory
59 // centralize memory block allocation
60 sys::MemoryBlock getNewMemoryBlock(unsigned size);
62 JITMemoryManager(bool useGOT);
65 inline unsigned char *allocateStub(unsigned StubSize);
66 inline unsigned char *startFunctionBody();
67 inline void endFunctionBody(unsigned char *FunctionEnd);
69 unsigned char *getGOTBase() const {
72 bool isManagingGOT() const {
73 return GOTBase != NULL;
78 JITMemoryManager::JITMemoryManager(bool useGOT) {
79 // Allocate a 16M block of memory for functions
80 sys::MemoryBlock FunBlock = getNewMemoryBlock(16 << 20);
82 FunctionBase = reinterpret_cast<unsigned char*>(FunBlock.base());
84 // Allocate stubs backwards from the base, allocate functions forward
86 CurStubPtr = CurFunctionPtr = FunctionBase + 512*1024;// Use 512k for stubs
90 if (useGOT) GOTBase = (unsigned char*)malloc(sizeof(void*) * 8192);
93 JITMemoryManager::~JITMemoryManager() {
94 for (unsigned i = 0, e = Blocks.size(); i != e; ++i)
95 sys::Memory::ReleaseRWX(Blocks[i]);
99 unsigned char *JITMemoryManager::allocateStub(unsigned StubSize) {
100 CurStubPtr -= StubSize;
101 if (CurStubPtr < FunctionBase) {
102 // FIXME: allocate a new block
103 std::cerr << "JIT ran out of memory for function stubs!\n";
109 unsigned char *JITMemoryManager::startFunctionBody() {
110 return CurFunctionPtr;
113 void JITMemoryManager::endFunctionBody(unsigned char *FunctionEnd) {
114 assert(FunctionEnd > CurFunctionPtr);
115 CurFunctionPtr = FunctionEnd;
118 sys::MemoryBlock JITMemoryManager::getNewMemoryBlock(unsigned size) {
120 const sys::MemoryBlock *BOld = Blocks.empty() ? 0 : &Blocks.front();
121 sys::MemoryBlock B = sys::Memory::AllocateRWX(size, BOld);
124 } catch (std::string &err) {
125 std::cerr << "Allocation failed when allocating new memory in the JIT\n";
126 std::cerr << err << "\n";
131 //===----------------------------------------------------------------------===//
132 // JIT lazy compilation code.
135 class JITResolverState {
137 /// FunctionToStubMap - Keep track of the stub created for a particular
138 /// function so that we can reuse them if necessary.
139 std::map<Function*, void*> FunctionToStubMap;
141 /// StubToFunctionMap - Keep track of the function that each stub
143 std::map<void*, Function*> StubToFunctionMap;
146 std::map<Function*, void*>& getFunctionToStubMap(const MutexGuard& locked) {
147 assert(locked.holds(TheJIT->lock));
148 return FunctionToStubMap;
151 std::map<void*, Function*>& getStubToFunctionMap(const MutexGuard& locked) {
152 assert(locked.holds(TheJIT->lock));
153 return StubToFunctionMap;
157 /// JITResolver - Keep track of, and resolve, call sites for functions that
158 /// have not yet been compiled.
160 /// MCE - The MachineCodeEmitter to use to emit stubs with.
161 MachineCodeEmitter &MCE;
163 /// LazyResolverFn - The target lazy resolver function that we actually
164 /// rewrite instructions to use.
165 TargetJITInfo::LazyResolverFn LazyResolverFn;
167 JITResolverState state;
169 /// ExternalFnToStubMap - This is the equivalent of FunctionToStubMap for
170 /// external functions.
171 std::map<void*, void*> ExternalFnToStubMap;
173 //map addresses to indexes in the GOT
174 std::map<void*, unsigned> revGOTMap;
175 unsigned nextGOTIndex;
178 JITResolver(MachineCodeEmitter &mce) : MCE(mce), nextGOTIndex(0) {
180 TheJIT->getJITInfo().getLazyResolverFunction(JITCompilerFn);
183 /// getFunctionStub - This returns a pointer to a function stub, creating
184 /// one on demand as needed.
185 void *getFunctionStub(Function *F);
187 /// getExternalFunctionStub - Return a stub for the function at the
188 /// specified address, created lazily on demand.
189 void *getExternalFunctionStub(void *FnAddr);
191 /// AddCallbackAtLocation - If the target is capable of rewriting an
192 /// instruction without the use of a stub, record the location of the use so
193 /// we know which function is being used at the location.
194 void *AddCallbackAtLocation(Function *F, void *Location) {
195 MutexGuard locked(TheJIT->lock);
196 /// Get the target-specific JIT resolver function.
197 state.getStubToFunctionMap(locked)[Location] = F;
198 return (void*)LazyResolverFn;
201 /// getGOTIndexForAddress - Return a new or existing index in the GOT for
202 /// and address. This function only manages slots, it does not manage the
203 /// contents of the slots or the memory associated with the GOT.
204 unsigned getGOTIndexForAddr(void* addr);
206 /// JITCompilerFn - This function is called to resolve a stub to a compiled
207 /// address. If the LLVM Function corresponding to the stub has not yet
208 /// been compiled, this function compiles it first.
209 static void *JITCompilerFn(void *Stub);
213 /// getJITResolver - This function returns the one instance of the JIT resolver.
215 static JITResolver &getJITResolver(MachineCodeEmitter *MCE = 0) {
216 static JITResolver TheJITResolver(*MCE);
217 return TheJITResolver;
220 /// getFunctionStub - This returns a pointer to a function stub, creating
221 /// one on demand as needed.
222 void *JITResolver::getFunctionStub(Function *F) {
223 MutexGuard locked(TheJIT->lock);
225 // If we already have a stub for this function, recycle it.
226 void *&Stub = state.getFunctionToStubMap(locked)[F];
227 if (Stub) return Stub;
229 // Call the lazy resolver function unless we already KNOW it is an external
230 // function, in which case we just skip the lazy resolution step.
231 void *Actual = (void*)LazyResolverFn;
232 if (F->isExternal() && F->hasExternalLinkage())
233 Actual = TheJIT->getPointerToFunction(F);
235 // Otherwise, codegen a new stub. For now, the stub will call the lazy
236 // resolver function.
237 Stub = TheJIT->getJITInfo().emitFunctionStub(Actual, MCE);
239 if (Actual != (void*)LazyResolverFn) {
240 // If we are getting the stub for an external function, we really want the
241 // address of the stub in the GlobalAddressMap for the JIT, not the address
242 // of the external function.
243 TheJIT->updateGlobalMapping(F, Stub);
246 DEBUG(std::cerr << "JIT: Stub emitted at [" << Stub << "] for function '"
247 << F->getName() << "'\n");
249 // Finally, keep track of the stub-to-Function mapping so that the
250 // JITCompilerFn knows which function to compile!
251 state.getStubToFunctionMap(locked)[Stub] = F;
255 /// getExternalFunctionStub - Return a stub for the function at the
256 /// specified address, created lazily on demand.
257 void *JITResolver::getExternalFunctionStub(void *FnAddr) {
258 // If we already have a stub for this function, recycle it.
259 void *&Stub = ExternalFnToStubMap[FnAddr];
260 if (Stub) return Stub;
262 Stub = TheJIT->getJITInfo().emitFunctionStub(FnAddr, MCE);
263 DEBUG(std::cerr << "JIT: Stub emitted at [" << Stub
264 << "] for external function at '" << FnAddr << "'\n");
268 unsigned JITResolver::getGOTIndexForAddr(void* addr) {
269 unsigned idx = revGOTMap[addr];
271 idx = ++nextGOTIndex;
272 revGOTMap[addr] = idx;
273 DEBUG(std::cerr << "Adding GOT entry " << idx
274 << " for addr " << addr << "\n");
275 // ((void**)MemMgr.getGOTBase())[idx] = addr;
280 /// JITCompilerFn - This function is called when a lazy compilation stub has
281 /// been entered. It looks up which function this stub corresponds to, compiles
282 /// it if necessary, then returns the resultant function pointer.
283 void *JITResolver::JITCompilerFn(void *Stub) {
284 JITResolver &JR = getJITResolver();
286 MutexGuard locked(TheJIT->lock);
288 // The address given to us for the stub may not be exactly right, it might be
289 // a little bit after the stub. As such, use upper_bound to find it.
290 std::map<void*, Function*>::iterator I =
291 JR.state.getStubToFunctionMap(locked).upper_bound(Stub);
292 assert(I != JR.state.getStubToFunctionMap(locked).begin() &&
293 "This is not a known stub!");
294 Function *F = (--I)->second;
296 // We might like to remove the stub from the StubToFunction map.
297 // We can't do that! Multiple threads could be stuck, waiting to acquire the
298 // lock above. As soon as the 1st function finishes compiling the function,
299 // the next one will be released, and needs to be able to find the function it
301 //JR.state.getStubToFunctionMap(locked).erase(I);
303 DEBUG(std::cerr << "JIT: Lazily resolving function '" << F->getName()
304 << "' In stub ptr = " << Stub << " actual ptr = "
305 << I->first << "\n");
307 void *Result = TheJIT->getPointerToFunction(F);
309 // We don't need to reuse this stub in the future, as F is now compiled.
310 JR.state.getFunctionToStubMap(locked).erase(F);
312 // FIXME: We could rewrite all references to this stub if we knew them.
314 // What we will do is set the compiled function address to map to the
315 // same GOT entry as the stub so that later clients may update the GOT
316 // if they see it still using the stub address.
317 // Note: this is done so the Resolver doesn't have to manage GOT memory
318 // Do this without allocating map space if the target isn't using a GOT
319 if(JR.revGOTMap.find(Stub) != JR.revGOTMap.end())
320 JR.revGOTMap[Result] = JR.revGOTMap[Stub];
326 // getPointerToFunctionOrStub - If the specified function has been
327 // code-gen'd, return a pointer to the function. If not, compile it, or use
328 // a stub to implement lazy compilation if available.
330 void *JIT::getPointerToFunctionOrStub(Function *F) {
331 // If we have already code generated the function, just return the address.
332 if (void *Addr = getPointerToGlobalIfAvailable(F))
335 // Get a stub if the target supports it
336 return getJITResolver(MCE).getFunctionStub(F);
341 //===----------------------------------------------------------------------===//
345 /// JITEmitter - The JIT implementation of the MachineCodeEmitter, which is
346 /// used to output functions to memory for execution.
347 class JITEmitter : public MachineCodeEmitter {
348 JITMemoryManager MemMgr;
350 // When outputting a function stub in the context of some other function, we
351 // save BufferBegin/BufferEnd/CurBufferPtr here.
352 unsigned char *SavedBufferBegin, *SavedBufferEnd, *SavedCurBufferPtr;
354 /// Relocations - These are the relocations that the function needs, as
356 std::vector<MachineRelocation> Relocations;
358 /// MBBLocations - This vector is a mapping from MBB ID's to their address.
359 /// It is filled in by the StartMachineBasicBlock callback and queried by
360 /// the getMachineBasicBlockAddress callback.
361 std::vector<intptr_t> MBBLocations;
363 /// ConstantPool - The constant pool for the current function.
365 MachineConstantPool *ConstantPool;
367 /// ConstantPoolBase - A pointer to the first entry in the constant pool.
369 void *ConstantPoolBase;
371 /// ConstantPool - The constant pool for the current function.
373 MachineJumpTableInfo *JumpTable;
375 /// JumpTableBase - A pointer to the first entry in the jump table.
379 JITEmitter(JIT &jit) : MemMgr(jit.getJITInfo().needsGOT()) {
381 DEBUG(if (MemMgr.isManagingGOT()) std::cerr << "JIT is managing a GOT\n");
384 virtual void startFunction(MachineFunction &F);
385 virtual bool finishFunction(MachineFunction &F);
387 void emitConstantPool(MachineConstantPool *MCP);
388 void initJumpTableInfo(MachineJumpTableInfo *MJTI);
389 void emitJumpTableInfo(MachineJumpTableInfo *MJTI);
391 virtual void startFunctionStub(unsigned StubSize);
392 virtual void* finishFunctionStub(const Function *F);
394 virtual void addRelocation(const MachineRelocation &MR) {
395 Relocations.push_back(MR);
398 virtual void StartMachineBasicBlock(MachineBasicBlock *MBB) {
399 if (MBBLocations.size() <= (unsigned)MBB->getNumber())
400 MBBLocations.resize((MBB->getNumber()+1)*2);
401 MBBLocations[MBB->getNumber()] = getCurrentPCValue();
404 virtual intptr_t getConstantPoolEntryAddress(unsigned Entry) const;
405 virtual intptr_t getJumpTableEntryAddress(unsigned Entry) const;
407 virtual intptr_t getMachineBasicBlockAddress(MachineBasicBlock *MBB) const {
408 assert(MBBLocations.size() > (unsigned)MBB->getNumber() &&
409 MBBLocations[MBB->getNumber()] && "MBB not emitted!");
410 return MBBLocations[MBB->getNumber()];
415 void *getPointerToGlobal(GlobalValue *GV, void *Reference, bool NoNeedStub);
419 MachineCodeEmitter *JIT::createEmitter(JIT &jit) {
420 return new JITEmitter(jit);
423 void *JITEmitter::getPointerToGlobal(GlobalValue *V, void *Reference,
424 bool DoesntNeedStub) {
425 if (GlobalVariable *GV = dyn_cast<GlobalVariable>(V)) {
426 /// FIXME: If we straightened things out, this could actually emit the
427 /// global immediately instead of queuing it for codegen later!
428 return TheJIT->getOrEmitGlobalVariable(GV);
431 // If we have already compiled the function, return a pointer to its body.
432 Function *F = cast<Function>(V);
433 void *ResultPtr = TheJIT->getPointerToGlobalIfAvailable(F);
434 if (ResultPtr) return ResultPtr;
436 if (F->hasExternalLinkage() && F->isExternal()) {
437 // If this is an external function pointer, we can force the JIT to
438 // 'compile' it, which really just adds it to the map.
440 return TheJIT->getPointerToFunction(F);
442 return getJITResolver(this).getFunctionStub(F);
445 // Okay, the function has not been compiled yet, if the target callback
446 // mechanism is capable of rewriting the instruction directly, prefer to do
447 // that instead of emitting a stub.
449 return getJITResolver(this).AddCallbackAtLocation(F, Reference);
451 // Otherwise, we have to emit a lazy resolving stub.
452 return getJITResolver(this).getFunctionStub(F);
455 void JITEmitter::startFunction(MachineFunction &F) {
456 BufferBegin = CurBufferPtr = MemMgr.startFunctionBody();
458 /// FIXME: implement out of space handling correctly!
459 BufferEnd = (unsigned char*)(intptr_t)~0ULL;
461 emitConstantPool(F.getConstantPool());
462 initJumpTableInfo(F.getJumpTableInfo());
464 // About to start emitting the machine code for the function.
465 emitAlignment(std::max(F.getFunction()->getAlignment(), 8U));
466 TheJIT->updateGlobalMapping(F.getFunction(), CurBufferPtr);
468 MBBLocations.clear();
471 bool JITEmitter::finishFunction(MachineFunction &F) {
472 emitJumpTableInfo(F.getJumpTableInfo());
474 MemMgr.endFunctionBody(CurBufferPtr);
475 NumBytes += getCurrentPCOffset();
477 if (!Relocations.empty()) {
478 NumRelos += Relocations.size();
480 // Resolve the relocations to concrete pointers.
481 for (unsigned i = 0, e = Relocations.size(); i != e; ++i) {
482 MachineRelocation &MR = Relocations[i];
485 ResultPtr = TheJIT->getPointerToNamedFunction(MR.getString());
487 // If the target REALLY wants a stub for this function, emit it now.
488 if (!MR.doesntNeedFunctionStub())
489 ResultPtr = getJITResolver(this).getExternalFunctionStub(ResultPtr);
490 } else if (MR.isGlobalValue()) {
491 ResultPtr = getPointerToGlobal(MR.getGlobalValue(),
492 BufferBegin+MR.getMachineCodeOffset(),
493 MR.doesntNeedFunctionStub());
495 assert(MR.isConstantPoolIndex());
496 ResultPtr=(void*)getConstantPoolEntryAddress(MR.getConstantPoolIndex());
499 MR.setResultPointer(ResultPtr);
501 // if we are managing the GOT and the relocation wants an index,
503 if (MemMgr.isManagingGOT() && MR.isGOTRelative()) {
504 unsigned idx = getJITResolver(this).getGOTIndexForAddr(ResultPtr);
506 if (((void**)MemMgr.getGOTBase())[idx] != ResultPtr) {
507 DEBUG(std::cerr << "GOT was out of date for " << ResultPtr
508 << " pointing at " << ((void**)MemMgr.getGOTBase())[idx]
510 ((void**)MemMgr.getGOTBase())[idx] = ResultPtr;
515 TheJIT->getJITInfo().relocate(BufferBegin, &Relocations[0],
516 Relocations.size(), MemMgr.getGOTBase());
519 // Update the GOT entry for F to point to the new code.
520 if(MemMgr.isManagingGOT()) {
521 unsigned idx = getJITResolver(this).getGOTIndexForAddr((void*)BufferBegin);
522 if (((void**)MemMgr.getGOTBase())[idx] != (void*)BufferBegin) {
523 DEBUG(std::cerr << "GOT was out of date for " << (void*)BufferBegin
524 << " pointing at " << ((void**)MemMgr.getGOTBase())[idx] << "\n");
525 ((void**)MemMgr.getGOTBase())[idx] = (void*)BufferBegin;
529 DEBUG(std::cerr << "JIT: Finished CodeGen of [" << (void*)BufferBegin
530 << "] Function: " << F.getFunction()->getName()
531 << ": " << getCurrentPCOffset() << " bytes of text, "
532 << Relocations.size() << " relocations\n");
537 void JITEmitter::emitConstantPool(MachineConstantPool *MCP) {
538 const std::vector<MachineConstantPoolEntry> &Constants = MCP->getConstants();
539 if (Constants.empty()) return;
541 unsigned Size = Constants.back().Offset;
542 Size += TheJIT->getTargetData()->getTypeSize(Constants.back().Val->getType());
544 ConstantPoolBase = allocateSpace(Size, 1 << MCP->getConstantPoolAlignment());
547 if (ConstantPoolBase == 0) return; // Buffer overflow.
549 // Initialize the memory for all of the constant pool entries.
550 for (unsigned i = 0, e = Constants.size(); i != e; ++i) {
551 void *CAddr = (char*)ConstantPoolBase+Constants[i].Offset;
552 TheJIT->InitializeMemory(Constants[i].Val, CAddr);
556 void JITEmitter::initJumpTableInfo(MachineJumpTableInfo *MJTI) {
557 const std::vector<MachineJumpTableEntry> &JT = MJTI->getJumpTables();
558 if (JT.empty()) return;
560 unsigned NumEntries = 0;
561 for (unsigned i = 0, e = JT.size(); i != e; ++i)
562 NumEntries += JT[i].MBBs.size();
564 unsigned EntrySize = MJTI->getEntrySize();
566 // Just allocate space for all the jump tables now. We will fix up the actual
567 // MBB entries in the tables after we emit the code for each block, since then
568 // we will know the final locations of the MBBs in memory.
570 JumpTableBase = allocateSpace(NumEntries * EntrySize, MJTI->getAlignment());
573 void JITEmitter::emitJumpTableInfo(MachineJumpTableInfo *MJTI) {
574 const std::vector<MachineJumpTableEntry> &JT = MJTI->getJumpTables();
575 if (JT.empty() || JumpTableBase == 0) return;
578 assert(MJTI->getEntrySize() == sizeof(void*) && "Cross JIT'ing?");
580 // For each jump table, map each target in the jump table to the address of
581 // an emitted MachineBasicBlock.
582 intptr_t *SlotPtr = (intptr_t*)JumpTableBase;
584 for (unsigned i = 0, e = JT.size(); i != e; ++i) {
585 const std::vector<MachineBasicBlock*> &MBBs = JT[i].MBBs;
586 // Store the address of the basic block for this jump table slot in the
587 // memory we allocated for the jump table in 'initJumpTableInfo'
588 for (unsigned mi = 0, me = MBBs.size(); mi != me; ++mi)
589 *SlotPtr++ = getMachineBasicBlockAddress(MBBs[mi]);
593 void JITEmitter::startFunctionStub(unsigned StubSize) {
594 SavedBufferBegin = BufferBegin;
595 SavedBufferEnd = BufferEnd;
596 SavedCurBufferPtr = CurBufferPtr;
598 BufferBegin = CurBufferPtr = MemMgr.allocateStub(StubSize);
599 BufferEnd = BufferBegin+StubSize+1;
602 void *JITEmitter::finishFunctionStub(const Function *F) {
603 NumBytes += getCurrentPCOffset();
604 std::swap(SavedBufferBegin, BufferBegin);
605 BufferEnd = SavedBufferEnd;
606 CurBufferPtr = SavedCurBufferPtr;
607 return SavedBufferBegin;
610 // getConstantPoolEntryAddress - Return the address of the 'ConstantNum' entry
611 // in the constant pool that was last emitted with the 'emitConstantPool'
614 intptr_t JITEmitter::getConstantPoolEntryAddress(unsigned ConstantNum) const {
615 assert(ConstantNum < ConstantPool->getConstants().size() &&
616 "Invalid ConstantPoolIndex!");
617 return (intptr_t)ConstantPoolBase +
618 ConstantPool->getConstants()[ConstantNum].Offset;
621 // getJumpTableEntryAddress - Return the address of the JumpTable with index
622 // 'Index' in the jumpp table that was last initialized with 'initJumpTableInfo'
624 intptr_t JITEmitter::getJumpTableEntryAddress(unsigned Index) const {
625 const std::vector<MachineJumpTableEntry> &JT = JumpTable->getJumpTables();
626 assert(Index < JT.size() && "Invalid jump table index!");
629 unsigned EntrySize = JumpTable->getEntrySize();
631 for (unsigned i = 0; i < Index; ++i)
632 Offset += JT[i].MBBs.size() * EntrySize;
634 return (intptr_t)((char *)JumpTableBase + Offset);
637 // getPointerToNamedFunction - This function is used as a global wrapper to
638 // JIT::getPointerToNamedFunction for the purpose of resolving symbols when
639 // bugpoint is debugging the JIT. In that scenario, we are loading an .so and
640 // need to resolve function(s) that are being mis-codegenerated, so we need to
641 // resolve their addresses at runtime, and this is the way to do it.
643 void *getPointerToNamedFunction(const char *Name) {
644 Module &M = TheJIT->getModule();
645 if (Function *F = M.getNamedFunction(Name))
646 return TheJIT->getPointerToFunction(F);
647 return TheJIT->getPointerToNamedFunction(Name);