summaryrefslogtreecommitdiffstats
path: root/llvm/tools
diff options
context:
space:
mode:
authorReid Spencer <rspencer@reidspencer.com>2005-12-21 05:03:23 +0000
committerReid Spencer <rspencer@reidspencer.com>2005-12-21 05:03:23 +0000
commit41e1b6fed0e64f5014d6266836b8fcce11bf0c57 (patch)
treec20be4e3d1b94316371ecce3630814501c39a190 /llvm/tools
parent294adbb5cff0c61320d42e900ee9c603cf41d0e7 (diff)
downloadbcm5719-llvm-41e1b6fed0e64f5014d6266836b8fcce11bf0c57.tar.gz
bcm5719-llvm-41e1b6fed0e64f5014d6266836b8fcce11bf0c57.zip
Implement PR512:
This patch adds a -post-link-opts option to llvm-ld which allows an arbitrary program to optimize bytecode after linking. The program is passed two file names. The first is the input (linked bytecode) the second is where it must place its output (presumably after optimizing). If the output file is bytecode, it is used as a substitute for the input. This will allow things like poolalloc to be written as a separate program instead of a loadable module or built into LLVM. llvm-svn: 24893
Diffstat (limited to 'llvm/tools')
-rw-r--r--llvm/tools/llvm-ld/llvm-ld.cpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/llvm/tools/llvm-ld/llvm-ld.cpp b/llvm/tools/llvm-ld/llvm-ld.cpp
index 03f1c45cb4f..0c633d2462d 100644
--- a/llvm/tools/llvm-ld/llvm-ld.cpp
+++ b/llvm/tools/llvm-ld/llvm-ld.cpp
@@ -76,6 +76,10 @@ static cl::opt<bool>NativeCBE("native-cbe",
static cl::opt<bool>DisableCompression("disable-compression",cl::init(false),
cl::desc("Disable writing of compressed bytecode files"));
+static cl::list<std::string> PostLinkOpts("post-link-opts",
+ cl::value_desc("path to post-link optimization programs"),
+ cl::desc("Run one or more optimization programs after linking"));
+
// Compatibility options that are ignored but supported by LD
static cl::opt<std::string> CO3("soname", cl::Hidden,
cl::desc("Compatibility option: ignored"));
@@ -450,6 +454,41 @@ int main(int argc, char **argv, char **envp) {
// If we are not linking a library, generate either a native executable
// or a JIT shell script, depending upon what the user wants.
if (!LinkAsLibrary) {
+ // If the user wants to run a post-link optimization, run it now.
+ if (!PostLinkOpts.empty()) {
+ std::vector<std::string> opts = PostLinkOpts;
+ for (std::vector<std::string>::iterator I = opts.begin(),
+ E = opts.end(); I != E; ++I) {
+ sys::Path prog(*I);
+ if (!prog.canExecute()) {
+ prog = sys::Program::FindProgramByName(*I);
+ if (prog.isEmpty())
+ return PrintAndReturn(std::string("Optimization program '") + *I +
+ "' is not found or not executable.");
+ }
+ // Get the program arguments
+ sys::Path tmp_output("opt_result");
+ if (!tmp_output.createTemporaryFileOnDisk()) {
+ return PrintAndReturn(
+ "Can't create temporary file for post-link optimization");
+ }
+ const char* args[4];
+ args[0] = I->c_str();
+ args[1] = RealBytecodeOutput.c_str();
+ args[2] = tmp_output.c_str();
+ args[3] = 0;
+ if (0 == sys::Program::ExecuteAndWait(prog, args)) {
+ if (tmp_output.isBytecodeFile()) {
+ sys::Path target(RealBytecodeOutput);
+ target.eraseFromDisk();
+ tmp_output.renamePathOnDisk(target);
+ } else
+ return PrintAndReturn(
+ "Post-link optimization output is not bytecode");
+ }
+ }
+ }
+
// If the user wants to generate a native executable, compile it from the
// bytecode file.
//
OpenPOWER on IntegriCloud