llvm.org GIT mirror llvm / 1e64b30
LTO: rename the various makeLTOModule overloads. This rename makes it easier to identify the specific overload being called in each particular case and makes future refactorings easier. Differential Revision: http://reviews.llvm.org/D4370 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@212302 91177308-0d34-0410-b5e6-96231b3b80d8 Peter Collingbourne 5 years ago
5 changed file(s) with 35 addition(s) and 36 deletion(s). Raw diff Collapse all Expand all
8585 /// InitializeAllTargetMCs();
8686 /// InitializeAllAsmPrinters();
8787 /// InitializeAllAsmParsers();
88 static LTOModule *makeLTOModule(const char *path, TargetOptions options,
89 std::string &errMsg);
90 static LTOModule *makeLTOModule(int fd, const char *path, size_t size,
91 TargetOptions options, std::string &errMsg);
92 static LTOModule *makeLTOModule(int fd, const char *path, size_t map_size,
93 off_t offset, TargetOptions options,
94 std::string &errMsg);
95 static LTOModule *makeLTOModule(const void *mem, size_t length,
96 TargetOptions options, std::string &errMsg,
97 StringRef path = "");
88 static LTOModule *createFromFile(const char *path, TargetOptions options,
89 std::string &errMsg);
90 static LTOModule *createFromOpenFile(int fd, const char *path, size_t size,
91 TargetOptions options,
92 std::string &errMsg);
93 static LTOModule *createFromOpenFileSlice(int fd, const char *path,
94 size_t map_size, off_t offset,
95 TargetOptions options,
96 std::string &errMsg);
97 static LTOModule *createFromBuffer(const void *mem, size_t length,
98 TargetOptions options, std::string &errMsg,
99 StringRef path = "");
98100
99101 /// Return the Module's target triple.
100102 const char *getTargetTriple() {
9393 return strncmp(Triple.c_str(), triplePrefix, strlen(triplePrefix)) == 0;
9494 }
9595
96 /// makeLTOModule - Create an LTOModule. N.B. These methods take ownership of
97 /// the buffer.
98 LTOModule *LTOModule::makeLTOModule(const char *path, TargetOptions options,
99 std::string &errMsg) {
96 LTOModule *LTOModule::createFromFile(const char *path, TargetOptions options,
97 std::string &errMsg) {
10098 std::unique_ptr buffer;
10199 if (std::error_code ec = MemoryBuffer::getFile(path, buffer)) {
102100 errMsg = ec.message();
105103 return makeLTOModule(std::move(buffer), options, errMsg);
106104 }
107105
108 LTOModule *LTOModule::makeLTOModule(int fd, const char *path,
109 size_t size, TargetOptions options,
110 std::string &errMsg) {
111 return makeLTOModule(fd, path, size, 0, options, errMsg);
112 }
113
114 LTOModule *LTOModule::makeLTOModule(int fd, const char *path,
115 size_t map_size,
116 off_t offset,
117 TargetOptions options,
118 std::string &errMsg) {
106 LTOModule *LTOModule::createFromOpenFile(int fd, const char *path, size_t size,
107 TargetOptions options,
108 std::string &errMsg) {
109 return createFromOpenFileSlice(fd, path, size, 0, options, errMsg);
110 }
111
112 LTOModule *LTOModule::createFromOpenFileSlice(int fd, const char *path,
113 size_t map_size, off_t offset,
114 TargetOptions options,
115 std::string &errMsg) {
119116 std::unique_ptr buffer;
120117 if (std::error_code ec =
121118 MemoryBuffer::getOpenFileSlice(fd, path, buffer, map_size, offset)) {
125122 return makeLTOModule(std::move(buffer), options, errMsg);
126123 }
127124
128 LTOModule *LTOModule::makeLTOModule(const void *mem, size_t length,
129 TargetOptions options,
130 std::string &errMsg, StringRef path) {
125 LTOModule *LTOModule::createFromBuffer(const void *mem, size_t length,
126 TargetOptions options,
127 std::string &errMsg, StringRef path) {
131128 std::unique_ptr buffer(makeBuffer(mem, length, path));
132129 if (!buffer)
133130 return nullptr;
291291 return LDPS_OK;
292292
293293 std::string Error;
294 M = LTOModule::makeLTOModule(view, file->filesize, TargetOpts, Error);
294 M = LTOModule::createFromBuffer(view, file->filesize, TargetOpts, Error);
295295 if (!M) {
296296 (*message)(LDPL_ERROR,
297297 "LLVM gold plugin has failed to create LTO module: %s",
109109 for (unsigned i = BaseArg; i < InputFilenames.size(); ++i) {
110110 std::string error;
111111 std::unique_ptr Module(
112 LTOModule::makeLTOModule(InputFilenames[i].c_str(), Options, error));
112 LTOModule::createFromFile(InputFilenames[i].c_str(), Options, error));
113113 if (!error.empty()) {
114114 errs() << argv[0] << ": error loading file '" << InputFilenames[i]
115115 << "': " << error << "\n";
103103 lto_module_t lto_module_create(const char* path) {
104104 lto_initialize();
105105 llvm::TargetOptions Options = InitTargetOptionsFromCodeGenFlags();
106 return wrap(LTOModule::makeLTOModule(path, Options, sLastErrorString));
106 return wrap(LTOModule::createFromFile(path, Options, sLastErrorString));
107107 }
108108
109109 lto_module_t lto_module_create_from_fd(int fd, const char *path, size_t size) {
110110 lto_initialize();
111111 llvm::TargetOptions Options = InitTargetOptionsFromCodeGenFlags();
112112 return wrap(
113 LTOModule::makeLTOModule(fd, path, size, Options, sLastErrorString));
113 LTOModule::createFromOpenFile(fd, path, size, Options, sLastErrorString));
114114 }
115115
116116 lto_module_t lto_module_create_from_fd_at_offset(int fd, const char *path,
119119 off_t offset) {
120120 lto_initialize();
121121 llvm::TargetOptions Options = InitTargetOptionsFromCodeGenFlags();
122 return wrap(LTOModule::makeLTOModule(fd, path, map_size, offset, Options,
123 sLastErrorString));
122 return wrap(LTOModule::createFromOpenFileSlice(fd, path, map_size, offset,
123 Options, sLastErrorString));
124124 }
125125
126126 lto_module_t lto_module_create_from_memory(const void* mem, size_t length) {
127127 lto_initialize();
128128 llvm::TargetOptions Options = InitTargetOptionsFromCodeGenFlags();
129 return wrap(LTOModule::makeLTOModule(mem, length, Options, sLastErrorString));
129 return wrap(LTOModule::createFromBuffer(mem, length, Options, sLastErrorString));
130130 }
131131
132132 lto_module_t lto_module_create_from_memory_with_path(const void* mem,
135135 lto_initialize();
136136 llvm::TargetOptions Options = InitTargetOptionsFromCodeGenFlags();
137137 return wrap(
138 LTOModule::makeLTOModule(mem, length, Options, sLastErrorString, path));
138 LTOModule::createFromBuffer(mem, length, Options, sLastErrorString, path));
139139 }
140140
141141 void lto_module_dispose(lto_module_t mod) { delete unwrap(mod); }