aboutsummaryrefslogtreecommitdiff
path: root/llvm/tools/llvm-extract/llvm-extract.cpp
diff options
context:
space:
mode:
authorJuneyoung Lee <aqjune@gmail.com>2020-02-02 02:34:10 +0900
committerJuneyoung Lee <aqjune@gmail.com>2020-02-03 14:30:28 +0900
commit578d2e2cb14106a93dc820cff25a7f2bc93629bc (patch)
treea9e4338b73bb35f2dec07df7d6c0cd62b8a73b0f /llvm/tools/llvm-extract/llvm-extract.cpp
parent47f309d9639181bf9930239299a5e08c992b2a2c (diff)
downloadllvm-578d2e2cb14106a93dc820cff25a7f2bc93629bc.zip
llvm-578d2e2cb14106a93dc820cff25a7f2bc93629bc.tar.gz
llvm-578d2e2cb14106a93dc820cff25a7f2bc93629bc.tar.bz2
[llvm-extract] Add -keep-const-init commandline option
Summary: This adds -keep-const-init option to llvm-extract which preserves initializers of used global constants. For example: ``` $ cat a.ll @g = constant i32 0 define i32 @f() { %v = load i32, i32* @g ret i32 %v } $ llvm-extract --func=f a.ll -S -o - @g = external constant i32 define i32 @f() { .. } $ llvm-extract --func=f a.ll -keep-const-init -S -o - @g = constant i32 0 define i32 @f() { .. } ``` This option is useful in checking whether a function that uses a constant global is optimized correctly. Reviewers: jsji, MaskRay, david2050 Reviewed By: MaskRay Subscribers: hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D73833
Diffstat (limited to 'llvm/tools/llvm-extract/llvm-extract.cpp')
-rw-r--r--llvm/tools/llvm-extract/llvm-extract.cpp6
1 files changed, 5 insertions, 1 deletions
diff --git a/llvm/tools/llvm-extract/llvm-extract.cpp b/llvm/tools/llvm-extract/llvm-extract.cpp
index dddc0d9..ac70b5f 100644
--- a/llvm/tools/llvm-extract/llvm-extract.cpp
+++ b/llvm/tools/llvm-extract/llvm-extract.cpp
@@ -53,6 +53,10 @@ static cl::opt<bool> DeleteFn("delete",
cl::desc("Delete specified Globals from Module"),
cl::cat(ExtractCat));
+static cl::opt<bool> KeepConstInit("keep-const-init",
+ cl::desc("Keep initializers of constants"),
+ cl::cat(ExtractCat));
+
static cl::opt<bool>
Recursive("recursive", cl::desc("Recursively extract all called functions"),
cl::cat(ExtractCat));
@@ -333,7 +337,7 @@ int main(int argc, char **argv) {
{
std::vector<GlobalValue *> Gvs(GVs.begin(), GVs.end());
legacy::PassManager Extract;
- Extract.add(createGVExtractionPass(Gvs, DeleteFn));
+ Extract.add(createGVExtractionPass(Gvs, DeleteFn, KeepConstInit));
Extract.run(*M);
// Now that we have all the GVs we want, mark the module as fully