Commit 63eddb94 authored by Marius Wachtler's avatar Marius Wachtler

irgen: Embed parent module and None only once per module

this descreases the number of symbols / stackmap constants size slightly
parent f3fc35e3
...@@ -910,14 +910,13 @@ private: ...@@ -910,14 +910,13 @@ private:
} }
ConcreteCompilerVariable* getNone() { ConcreteCompilerVariable* getNone() {
ConcreteCompilerVariable* v = new ConcreteCompilerVariable( llvm::Constant* none = embedRelocatablePtr(None, g.llvm_value_type_ptr, "cNone");
typeFromClass(none_cls), embedRelocatablePtr(None, g.llvm_value_type_ptr), false); return new ConcreteCompilerVariable(typeFromClass(none_cls), none, false);
return v;
} }
llvm::Constant* embedParentModulePtr() { llvm::Constant* embedParentModulePtr() {
// TODO: We could reuse the name to reduce the number of relocatable pointers. BoxedModule* parent_module = irstate->getSourceInfo()->parent_module;
return embedRelocatablePtr(irstate->getSourceInfo()->parent_module, g.llvm_module_type_ptr); return embedRelocatablePtr(parent_module, g.llvm_module_type_ptr, "cParentModule");
} }
ConcreteCompilerVariable* _getGlobal(AST_Name* node, UnwindInfo unw_info) { ConcreteCompilerVariable* _getGlobal(AST_Name* node, UnwindInfo unw_info) {
...@@ -2150,7 +2149,7 @@ private: ...@@ -2150,7 +2149,7 @@ private:
v->decvref(emitter); v->decvref(emitter);
args.push_back(converted->getValue()); args.push_back(converted->getValue());
} else { } else {
args.push_back(embedRelocatablePtr(None, g.llvm_value_type_ptr)); args.push_back(embedRelocatablePtr(None, g.llvm_value_type_ptr, "cNone"));
} }
} }
......
...@@ -106,13 +106,23 @@ const void* getValueOfRelocatableSym(const std::string& str) { ...@@ -106,13 +106,23 @@ const void* getValueOfRelocatableSym(const std::string& str) {
return NULL; return NULL;
} }
llvm::Constant* embedRelocatablePtr(const void* addr, llvm::Type* type) { llvm::Constant* embedRelocatablePtr(const void* addr, llvm::Type* type, llvm::StringRef shared_name) {
assert(addr); assert(addr);
if (!ENABLE_JIT_OBJECT_CACHE) if (!ENABLE_JIT_OBJECT_CACHE)
return embedConstantPtr(addr, type); return embedConstantPtr(addr, type);
std::string name = (llvm::Twine("c") + llvm::Twine(relocatable_syms.size())).str(); std::string name;
if (!shared_name.empty()) {
llvm::GlobalVariable* gv = g.cur_module->getGlobalVariable(shared_name, true);
if (gv)
return gv;
assert(!relocatable_syms.count(name));
name = shared_name;
} else {
name = (llvm::Twine("c") + llvm::Twine(relocatable_syms.size())).str();
}
relocatable_syms[name] = addr; relocatable_syms[name] = addr;
llvm::Type* var_type = type->getPointerElementType(); llvm::Type* var_type = type->getPointerElementType();
......
...@@ -17,6 +17,8 @@ ...@@ -17,6 +17,8 @@
#include <string> #include <string>
#include "llvm/ADT/StringRef.h"
namespace llvm { namespace llvm {
class Constant; class Constant;
class Function; class Function;
...@@ -27,7 +29,7 @@ namespace pyston { ...@@ -27,7 +29,7 @@ namespace pyston {
llvm::Constant* getStringConstantPtr(const std::string& str); llvm::Constant* getStringConstantPtr(const std::string& str);
llvm::Constant* getStringConstantPtr(const char* str); llvm::Constant* getStringConstantPtr(const char* str);
llvm::Constant* embedRelocatablePtr(const void* addr, llvm::Type*); llvm::Constant* embedRelocatablePtr(const void* addr, llvm::Type*, llvm::StringRef shared_name = llvm::StringRef());
llvm::Constant* embedConstantPtr(const void* addr, llvm::Type*); llvm::Constant* embedConstantPtr(const void* addr, llvm::Type*);
llvm::Constant* getConstantInt(int64_t val); llvm::Constant* getConstantInt(int64_t val);
llvm::Constant* getConstantDouble(double val); llvm::Constant* getConstantDouble(double val);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment