|
1 | | -//===-- CopyrightMetadataPass.cpp - Lower copyright metadata -------------===// |
| 1 | +//===-- LowerCommentStringPass.cpp - Lower Comment string metadata -------===// |
2 | 2 | // |
3 | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | 4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | 6 | // |
7 | 7 | //===---------------------------------------------------------------------===// |
8 | 8 | // |
9 | | -// CopyrightMetadataPass pass lowers module-level copyright metadata emitted by |
10 | | -// Clang: |
| 9 | +// LowerCommentStringPass pass lowers module-level comment string metadata |
| 10 | +// emitted by Clang: |
11 | 11 | // |
12 | 12 | // !comment_string.loadtime = !{!"Copyright ..."} |
13 | 13 | // |
|
16 | 16 | // For each module (translation unit), the pass performs the following: |
17 | 17 | // |
18 | 18 | // 1. Creates a null-terminated, internal constant string global |
19 | | -// (`__loadtime_copyright_str`) containing the copyright text in |
20 | | -// `__copyright_comment` section. |
| 19 | +// (`__loadtime_comment_str`) containing the copyright text in |
| 20 | +// `__loadtime_comment` section. |
21 | 21 | // |
22 | 22 | // 2. Marks the string in `llvm.used` so it cannot be dropped by |
23 | 23 | // optimization or LTO. |
|
31 | 31 | // Input IR: |
32 | 32 | // !comment_string.loadtime = !{!"Copyright"} |
33 | 33 | // Output IR: |
34 | | -// @__loadtime_copyright_str = internal constant [N x i8] c"Copyright\00", |
35 | | -// section "__copyright_comment" |
36 | | -// @llvm.used = appending global [1 x ptr] [ptr @__loadtime_copyright_str] |
| 34 | +// @__loadtime_comment_str = internal constant [N x i8] c"Copyright\00", |
| 35 | +// section "__loadtime_comment" |
| 36 | +// @llvm.used = appending global [1 x ptr] [ptr @__loadtime_comment_str] |
37 | 37 | // |
38 | 38 | // define i32 @func() !implicit.ref !5 { ... } |
39 | | -// !5 = !{ptr @__loadtime_copyright_str} |
| 39 | +// !5 = !{ptr @__loadtime_comment_str} |
40 | 40 | // |
41 | 41 | //===----------------------------------------------------------------------===// |
42 | 42 |
|
43 | | -#include "llvm/Transforms/Utils/CopyrightMetadataPass.h" |
| 43 | +#include "llvm/Transforms/Utils/LowerCommentStringPass.h" |
44 | 44 |
|
45 | 45 | #include "llvm/ADT/SmallVector.h" |
46 | 46 | #include "llvm/ADT/StringRef.h" |
|
61 | 61 | #include "llvm/TargetParser/Triple.h" |
62 | 62 | #include "llvm/Transforms/Utils/ModuleUtils.h" |
63 | 63 |
|
64 | | -#define DEBUG_TYPE "copyright-metadata" |
| 64 | +#define DEBUG_TYPE "lower-comment-string" |
65 | 65 |
|
66 | 66 | using namespace llvm; |
67 | 67 |
|
68 | 68 | static cl::opt<bool> |
69 | | - DisableCopyrightMetadata("disable-copyright-metadata", cl::ReallyHidden, |
70 | | - cl::desc("Disable copyright metadata pass."), |
| 69 | + DisableCopyrightMetadata("disable-lower-comment-string", cl::ReallyHidden, |
| 70 | + cl::desc("Disable LowerCommentString pass."), |
71 | 71 | cl::init(false)); |
72 | 72 |
|
73 | 73 | static bool isAIXTriple(const Module &M) { |
74 | 74 | return Triple(M.getTargetTriple()).isOSAIX(); |
75 | 75 | } |
76 | 76 |
|
77 | | -PreservedAnalyses CopyrightMetadataPass::run(Module &M, |
| 77 | +PreservedAnalyses LowerCommentStringPass::run(Module &M, |
78 | 78 | ModuleAnalysisManager &AM) { |
79 | 79 | if (DisableCopyrightMetadata || !isAIXTriple(M)) |
80 | 80 | return PreservedAnalyses::all(); |
@@ -108,21 +108,21 @@ PreservedAnalyses CopyrightMetadataPass::run(Module &M, |
108 | 108 | auto *StrGV = new GlobalVariable(M, StrInit->getType(), |
109 | 109 | /*isConstant=*/true, |
110 | 110 | GlobalValue::InternalLinkage, StrInit, |
111 | | - /*Name=*/"__loadtime_copyright_str"); |
| 111 | + /*Name=*/"__loadtime_comment_str"); |
112 | 112 | // Set unnamed_addr to allow the linker to merge identical strings |
113 | 113 | StrGV->setUnnamedAddr(GlobalValue::UnnamedAddr::Global); |
114 | 114 | StrGV->setAlignment(Align(1)); |
115 | | - // Place in the "__copyright_comment" section. |
| 115 | + // Place in the "__loadtime_comment" section. |
116 | 116 | // The GV is constant, so we expect a read-only section. |
117 | | - StrGV->setSection("__copyright_comment"); |
| 117 | + StrGV->setSection("__loadtime_comment"); |
118 | 118 |
|
119 | 119 | // 2. Add the string to llvm.used to prevent LLVM optimization/LTO passes from |
120 | 120 | // removing it. |
121 | 121 | appendToUsed(M, {StrGV}); |
122 | 122 |
|
123 | 123 | // 3. Attach !implicit ref to every defined function |
124 | 124 | // Create a metadata node pointing to the copyright string: |
125 | | - // !N = !{ptr @__loadtime_copyright_str} |
| 125 | + // !N = !{ptr @__loadtime_comment_str} |
126 | 126 | Metadata *Ops[] = {ConstantAsMetadata::get(StrGV)}; |
127 | 127 | MDNode *ImplicitRefMD = MDNode::get(Ctx, Ops); |
128 | 128 |
|
|
0 commit comments