Commit 31bf1c5c authored by Yonghong Song's avatar Yonghong Song

setup some bpf_module data structures correctly when rw_engine is disabled

Commit db7b8eb0 ("add a BPFModule API to disable rw_engine
sscanf/snprintf functions") permits to disable rw_engine so that
memory can be saved for structures with large arrays. As a result,
the function BPFModule::annotate(), which is used to generate
"sscanf" module, is not called when rw_engine is disabled.

Besides generating "sscanf" module, however, BPFModule::annotate()
also sets up several other data structures which are used for
map/table manipulation. This patch implements BPFModule::annotate_light(),
which will be called when rw_engine is disabled, to
setup these data structures.
Signed-off-by: default avatarYonghong Song <yhs@fb.com>
parent cab4d7c6
...@@ -486,6 +486,20 @@ int BPFModule::load_includes(const string &text) { ...@@ -486,6 +486,20 @@ int BPFModule::load_includes(const string &text) {
return 0; return 0;
} }
void BPFModule::annotate_light() {
for (auto fn = mod_->getFunctionList().begin(); fn != mod_->getFunctionList().end(); ++fn)
if (!fn->hasFnAttribute(Attribute::NoInline))
fn->addFnAttr(Attribute::AlwaysInline);
size_t id = 0;
Path path({id_});
for (auto it = ts_->lower_bound(path), up = ts_->upper_bound(path); it != up; ++it) {
TableDesc &table = it->second;
tables_.push_back(&it->second);
table_names_[table.name] = id++;
}
}
int BPFModule::annotate() { int BPFModule::annotate() {
for (auto fn = mod_->getFunctionList().begin(); fn != mod_->getFunctionList().end(); ++fn) for (auto fn = mod_->getFunctionList().begin(); fn != mod_->getFunctionList().end(); ++fn)
if (!fn->hasFnAttribute(Attribute::NoInline)) if (!fn->hasFnAttribute(Attribute::NoInline))
...@@ -945,6 +959,8 @@ int BPFModule::load_b(const string &filename, const string &proto_filename) { ...@@ -945,6 +959,8 @@ int BPFModule::load_b(const string &filename, const string &proto_filename) {
if (rw_engine_enabled_) { if (rw_engine_enabled_) {
if (int rc = annotate()) if (int rc = annotate())
return rc; return rc;
} else {
annotate_light();
} }
if (int rc = finalize()) if (int rc = finalize())
return rc; return rc;
...@@ -966,6 +982,8 @@ int BPFModule::load_c(const string &filename, const char *cflags[], int ncflags) ...@@ -966,6 +982,8 @@ int BPFModule::load_c(const string &filename, const char *cflags[], int ncflags)
if (rw_engine_enabled_) { if (rw_engine_enabled_) {
if (int rc = annotate()) if (int rc = annotate())
return rc; return rc;
} else {
annotate_light();
} }
if (int rc = finalize()) if (int rc = finalize())
return rc; return rc;
...@@ -983,6 +1001,8 @@ int BPFModule::load_string(const string &text, const char *cflags[], int ncflags ...@@ -983,6 +1001,8 @@ int BPFModule::load_string(const string &text, const char *cflags[], int ncflags
if (rw_engine_enabled_) { if (rw_engine_enabled_) {
if (int rc = annotate()) if (int rc = annotate())
return rc; return rc;
} else {
annotate_light();
} }
if (int rc = finalize()) if (int rc = finalize())
......
...@@ -61,6 +61,7 @@ class BPFModule { ...@@ -61,6 +61,7 @@ class BPFModule {
int parse(llvm::Module *mod); int parse(llvm::Module *mod);
int finalize(); int finalize();
int annotate(); int annotate();
void annotate_light();
std::unique_ptr<llvm::ExecutionEngine> finalize_rw(std::unique_ptr<llvm::Module> mod); std::unique_ptr<llvm::ExecutionEngine> finalize_rw(std::unique_ptr<llvm::Module> mod);
std::string make_reader(llvm::Module *mod, llvm::Type *type); std::string make_reader(llvm::Module *mod, llvm::Type *type);
std::string make_writer(llvm::Module *mod, llvm::Type *type); std::string make_writer(llvm::Module *mod, llvm::Type *type);
......
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