aboutsummaryrefslogtreecommitdiff
path: root/tools/llvm-extract/llvm-extract.cpp
diff options
context:
space:
mode:
authorDerek Schuff <dschuff@chromium.org>2012-07-09 10:52:46 -0700
committerDerek Schuff <dschuff@chromium.org>2012-07-09 11:00:37 -0700
commit5dbcc7e0c9c12f4a4042fb4a226654aee927999c (patch)
treeb316a3370e9286cb4e6f81b2f9d8bd8b54ce5123 /tools/llvm-extract/llvm-extract.cpp
parent86dc97be9ac3b4804528e087b04b4f4192cdee54 (diff)
LOCALMODs from hg 0b098ca44de7 against r158408 (hg 90a87d6bfe45)
(only non-new files; new files in git 4f429c8b) Change-Id: Ia39f818088485bd90e4d048db404f8d6ba5f836b
Diffstat (limited to 'tools/llvm-extract/llvm-extract.cpp')
-rw-r--r--tools/llvm-extract/llvm-extract.cpp47
1 files changed, 47 insertions, 0 deletions
diff --git a/tools/llvm-extract/llvm-extract.cpp b/tools/llvm-extract/llvm-extract.cpp
index 2ed11c52b2..4ea1a9080d 100644
--- a/tools/llvm-extract/llvm-extract.cpp
+++ b/tools/llvm-extract/llvm-extract.cpp
@@ -20,6 +20,7 @@
#include "llvm/Transforms/IPO.h"
#include "llvm/Target/TargetData.h"
#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/Debug.h" // @LOCALMOD
#include "llvm/Support/IRReader.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/PrettyStackTrace.h"
@@ -47,6 +48,18 @@ Force("f", cl::desc("Enable binary output on terminals"));
static cl::opt<bool>
DeleteFn("delete", cl::desc("Delete specified Globals from Module"));
+// @LOCALMOD-BEGIN
+static cl::opt<unsigned>
+Divisor("divisor",
+ cl::init(0),
+ cl::desc("select GV by position (pos % divisor = remainder "));
+
+static cl::opt<unsigned>
+Remainder("remainder",
+ cl::init(0),
+ cl::desc("select GV by position (pos % divisor = remainder "));
+// @LOCALMOD-END
+
// ExtractFuncs - The functions to extract from the module.
static cl::list<std::string>
ExtractFuncs("func", cl::desc("Specify function to extract"),
@@ -131,6 +144,24 @@ int main(int argc, char **argv) {
}
}
+ // @LOCALMOD-BEGIN
+ // Extract globals via modulo operation.
+ size_t count_globals = 0;
+ if (Divisor != 0) {
+ size_t pos = 0;
+ for (Module::global_iterator GV = M->global_begin(), E = M->global_end();
+ GV != E;
+ GV++, pos++) {
+ if (pos % Divisor == Remainder) {
+ GVs.insert(&*GV);
+ }
+ }
+ dbgs() << "total globals: " << pos << "\n";
+ count_globals = GVs.size();
+ dbgs() << "selected globals: " << count_globals << "\n";
+ }
+ // @LOCALMOD-END
+
// Figure out which functions we should extract.
for (size_t i = 0, e = ExtractFuncs.size(); i != e; ++i) {
GlobalValue *GV = M->getFunction(ExtractFuncs[i]);
@@ -165,6 +196,22 @@ int main(int argc, char **argv) {
}
}
+ // @LOCALMOD-BEGIN
+ // Extract functions via modulo operation.
+ if (Divisor != 0) {
+ size_t pos = 0;
+ for (Module::iterator F = M->begin(), E = M->end();
+ F != E;
+ F++, pos++) {
+ if (pos % Divisor == Remainder) {
+ GVs.insert(&*F);
+ }
+ }
+ dbgs() << "total functions: " << pos << "\n";
+ dbgs() << "selected functions: " << GVs.size() - count_globals << "\n";
+ }
+ // @LOCALMOD-END
+
// Materialize requisite global values.
if (!DeleteFn)
for (size_t i = 0, e = GVs.size(); i != e; ++i) {