[LLVMbugs] [Bug 5746] New: JIT should use available_externally globals to find more things it doesn' t need to codegen

bugzilla-daemon at cs.uiuc.edu bugzilla-daemon at cs.uiuc.edu
Wed Dec 9 16:41:12 PST 2009


http://llvm.org/bugs/show_bug.cgi?id=5746

           Summary: JIT should use available_externally globals to find more
                    things it doesn't need to codegen
           Product: libraries
           Version: trunk
          Platform: PC
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: Target-Independent JIT
        AssignedTo: unassignedbugs at nondot.org
        ReportedBy: jyasskin at google.com
                CC: llvmbugs at cs.uiuc.edu, nlewycky at google.com


Say we have C code like:

static int func(void) { ... }
typedef int (*FuncPtr)(void);
extern const FuncPtr NS_UniquelyNamedFunc = &func;

If this code is compiled into the JIT's runtime, we can also compile it to
bitcode and mark NS_UniquelyNamedFunc as available_externally, since the JIT
can use dlsym() to look it up in the runtime. However, we can't mark 'func' as
available_externally since its symbol will be renamed and hidden to avoid name
collisions with other translation units. Even once PR5735 is fixed, this will
cause the JIT to unnecessarily codegen func. It's unnecessary because there's
guaranteed to be a pointer with the same semantics, since it escaped the
translation unit.

Proposed algorithm for improving this:
1. dlsym the available_externally GlobalVariable to get its address in the real
program.
2. Traverse its initializer and that address in parallel.
(http://code.google.com/p/unladen-swallow/source/browse/trunk/Util/ConstantMirror.cc#266
traverses memory according to an llvm::Type, so we can copy from there.)
3. Each time we find a pointer @p in the initializer, call addGlobalMapping(@p,
value_from_memory) to match it up and prevent the JIT from trying to compile it
again.

For this to be useful, we'd have to do the traversal before trying to JIT any
function that used a value from one of these globals. Since the optimizers try
to remove references to the global and replace it with its field, we can't rely
on the global still being used by the IR when the JIT gets to it. That means
this utility needs to available for explicit calls from the user in addition to
operating automatically from the JIT.


-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list