llvm.org GIT mirror llvm / 08aea7d
SymbolRewriter: allow rewriting with comdats COMDATs must be identically named to the symbol. When support for COMDATs was introduced, the symbol rewriter was not updated, resulting in rewriting failing for symbols which were placed into COMDATs. This corrects the behaviour and adds test cases for this. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@227261 91177308-0d34-0410-b5e6-96231b3b80d8 Saleem Abdulrasool 4 years ago
3 changed file(s) with 73 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
7878
7979 namespace llvm {
8080 namespace SymbolRewriter {
81 void rewriteComdat(Module &M, GlobalObject *GO, const std::string &Source,
82 const std::string &Target) {
83 if (Comdat *CD = GO->getComdat()) {
84 auto &Comdats = M.getComdatSymbolTable();
85
86 Comdat *C = M.getOrInsertComdat(Target);
87 C->setSelectionKind(CD->getSelectionKind());
88 GO->setComdat(C);
89
90 Comdats.erase(Comdats.find(Source));
91 }
92 }
93
8194 template
8295 ValueType *(llvm::Module::*Get)(StringRef) const>
8396 class ExplicitRewriteDescriptor : public RewriteDescriptor {
101114 bool ExplicitRewriteDescriptor::performOnModule(Module &M) {
102115 bool Changed = false;
103116 if (ValueType *S = (M.*Get)(Source)) {
117 if (GlobalObject *GO = dyn_cast(S))
118 rewriteComdat(M, GO, Source, Target);
119
104120 if (Value *T = (M.*Get)(Target))
105121 S->setValueName(T->getValueName());
106122 else
107123 S->setName(Target);
124
108125 Changed = true;
109126 }
110127 return Changed;
146163
147164 if (C.getName() == Name)
148165 continue;
166
167 if (GlobalObject *GO = dyn_cast(&C))
168 rewriteComdat(M, GO, C.getName(), Name);
149169
150170 if (Value *V = (M.*Get)(Name))
151171 C.setValueName(V->getValueName());
2727 ret void
2828 }
2929
30 $source_comdat_function = comdat any
31 define dllexport void @source_comdat_function() comdat($source_comdat_function) {
32 entry:
33 ret void
34 }
35
36 $source_comdat_function_1 = comdat exactmatch
37 define dllexport void @source_comdat_function_1() comdat($source_comdat_function_1) {
38 entry:
39 ret void
40 }
41
42 $source_comdat_variable = comdat largest
43 @source_comdat_variable = global i32 32, comdat($source_comdat_variable)
44
45 $source_comdat_variable_1 = comdat noduplicates
46 @source_comdat_variable_1 = global i32 64, comdat($source_comdat_variable_1)
47
48 ; CHECK: $target_comdat_function = comdat any
49 ; CHECK: $target_comdat_function_1 = comdat exactmatch
50 ; CHECK: $target_comdat_variable = comdat largest
51 ; CHECK: $target_comdat_variable_1 = comdat noduplicates
52
3053 ; CHECK: @target_variable = external global i32
3154 ; CHECK-NOT: @source_variable = external global i32
3255 ; CHECK: @target_pattern_variable = external global i32
3356 ; CHECK-NOT: @source_pattern_variable = external global i32
3457 ; CHECK: @target_pattern_multiple_variable_matches = external global i32
3558 ; CHECK-NOT: @source_pattern_multiple_variable_matches = external global i32
59 ; CHECK: @target_comdat_variable = global i32 32, comdat
60 ; CHECK-NOT: @source_comdat_variable = global i32 32, comdat
61 ; CHECK: @target_comdat_variable_1 = global i32 64, comdat
62 ; CHECK-NOT: @source_comdat_variable_1 = global i32 64, comdat
63
3664 ; CHECK: declare void @target_function()
3765 ; CHECK-NOT: declare void @source_function()
3866 ; CHECK: declare void @target_pattern_function()
5684 ; CHECK: ret i32 %res
5785 ; CHECK: }
5886
87 ; CHECK: define dllexport void @target_comdat_function() comdat
88 ; CHECK-NOT: define dllexport void @source_comdat_function() comdat
89 ; CHECK: define dllexport void @target_comdat_function_1() comdat
90 ; CHECK-NOT: define dllexport void @source_comdat_function_1() comdat
91
4343 target: _ZN1SD1Ev,
4444 }
4545
46 function: {
47 source: source_comdat_function,
48 target: target_comdat_function,
49 }
50
51 function: {
52 source: source_comdat_function_(.*),
53 transform: target_comdat_function_\1,
54 }
55
56 global variable: {
57 source: source_comdat_variable,
58 target: target_comdat_variable,
59 }
60
61 global variable: {
62 source: source_comdat_variable_(.*),
63 transform: target_comdat_variable_\1,
64 }
65