[llvm-branch-commits] [llvm-branch] r227324 - Merging r227261:
Hans Wennborg
hans at hanshq.net
Wed Jan 28 09:24:04 PST 2015
Author: hans
Date: Wed Jan 28 11:24:04 2015
New Revision: 227324
URL: http://llvm.org/viewvc/llvm-project?rev=227324&view=rev
Log:
Merging r227261:
------------------------------------------------------------------------
r227261 | compnerd | 2015-01-27 14:57:39 -0800 (Tue, 27 Jan 2015) | 6 lines
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.
------------------------------------------------------------------------
Modified:
llvm/branches/release_36/ (props changed)
llvm/branches/release_36/lib/Transforms/Utils/SymbolRewriter.cpp
llvm/branches/release_36/test/SymbolRewriter/rewrite.ll
llvm/branches/release_36/test/SymbolRewriter/rewrite.map
Propchange: llvm/branches/release_36/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Jan 28 11:24:04 2015
@@ -1,3 +1,3 @@
/llvm/branches/Apple/Pertwee:110850,110961
/llvm/branches/type-system-rewrite:133420-134817
-/llvm/trunk:155241,226023,226029,226044,226046,226048,226058,226075,226170-226171,226182,226473,226664,226708,226711,226755,227005,227260
+/llvm/trunk:155241,226023,226029,226044,226046,226048,226058,226075,226170-226171,226182,226473,226664,226708,226711,226755,227005,227260-227261
Modified: llvm/branches/release_36/lib/Transforms/Utils/SymbolRewriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_36/lib/Transforms/Utils/SymbolRewriter.cpp?rev=227324&r1=227323&r2=227324&view=diff
==============================================================================
--- llvm/branches/release_36/lib/Transforms/Utils/SymbolRewriter.cpp (original)
+++ llvm/branches/release_36/lib/Transforms/Utils/SymbolRewriter.cpp Wed Jan 28 11:24:04 2015
@@ -79,6 +79,19 @@ static cl::list<std::string> RewriteMapF
namespace llvm {
namespace SymbolRewriter {
+void rewriteComdat(Module &M, GlobalObject *GO, const std::string &Source,
+ const std::string &Target) {
+ if (Comdat *CD = GO->getComdat()) {
+ auto &Comdats = M.getComdatSymbolTable();
+
+ Comdat *C = M.getOrInsertComdat(Target);
+ C->setSelectionKind(CD->getSelectionKind());
+ GO->setComdat(C);
+
+ Comdats.erase(Comdats.find(Source));
+ }
+}
+
template <RewriteDescriptor::Type DT, typename ValueType,
ValueType *(llvm::Module::*Get)(StringRef) const>
class ExplicitRewriteDescriptor : public RewriteDescriptor {
@@ -102,10 +115,14 @@ template <RewriteDescriptor::Type DT, ty
bool ExplicitRewriteDescriptor<DT, ValueType, Get>::performOnModule(Module &M) {
bool Changed = false;
if (ValueType *S = (M.*Get)(Source)) {
+ if (GlobalObject *GO = dyn_cast<GlobalObject>(S))
+ rewriteComdat(M, GO, Source, Target);
+
if (Value *T = (M.*Get)(Target))
S->setValueName(T->getValueName());
else
S->setName(Target);
+
Changed = true;
}
return Changed;
@@ -148,6 +165,9 @@ performOnModule(Module &M) {
if (C.getName() == Name)
continue;
+ if (GlobalObject *GO = dyn_cast<GlobalObject>(&C))
+ rewriteComdat(M, GO, C.getName(), Name);
+
if (Value *V = (M.*Get)(Name))
C.setValueName(V->getValueName());
else
Modified: llvm/branches/release_36/test/SymbolRewriter/rewrite.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_36/test/SymbolRewriter/rewrite.ll?rev=227324&r1=227323&r2=227324&view=diff
==============================================================================
--- llvm/branches/release_36/test/SymbolRewriter/rewrite.ll (original)
+++ llvm/branches/release_36/test/SymbolRewriter/rewrite.ll Wed Jan 28 11:24:04 2015
@@ -28,12 +28,40 @@ entry:
ret void
}
+$source_comdat_function = comdat any
+define dllexport void @source_comdat_function() comdat($source_comdat_function) {
+entry:
+ ret void
+}
+
+$source_comdat_function_1 = comdat exactmatch
+define dllexport void @source_comdat_function_1() comdat($source_comdat_function_1) {
+entry:
+ ret void
+}
+
+$source_comdat_variable = comdat largest
+ at source_comdat_variable = global i32 32, comdat($source_comdat_variable)
+
+$source_comdat_variable_1 = comdat noduplicates
+ at source_comdat_variable_1 = global i32 64, comdat($source_comdat_variable_1)
+
+; CHECK: $target_comdat_function = comdat any
+; CHECK: $target_comdat_function_1 = comdat exactmatch
+; CHECK: $target_comdat_variable = comdat largest
+; CHECK: $target_comdat_variable_1 = comdat noduplicates
+
; CHECK: @target_variable = external global i32
; CHECK-NOT: @source_variable = external global i32
; CHECK: @target_pattern_variable = external global i32
; CHECK-NOT: @source_pattern_variable = external global i32
; CHECK: @target_pattern_multiple_variable_matches = external global i32
; CHECK-NOT: @source_pattern_multiple_variable_matches = external global i32
+; CHECK: @target_comdat_variable = global i32 32, comdat
+; CHECK-NOT: @source_comdat_variable = global i32 32, comdat
+; CHECK: @target_comdat_variable_1 = global i32 64, comdat
+; CHECK-NOT: @source_comdat_variable_1 = global i32 64, comdat
+
; CHECK: declare void @target_function()
; CHECK-NOT: declare void @source_function()
; CHECK: declare void @target_pattern_function()
@@ -57,3 +85,8 @@ entry:
; CHECK: ret i32 %res
; CHECK: }
+; CHECK: define dllexport void @target_comdat_function() comdat
+; CHECK-NOT: define dllexport void @source_comdat_function() comdat
+; CHECK: define dllexport void @target_comdat_function_1() comdat
+; CHECK-NOT: define dllexport void @source_comdat_function_1() comdat
+
Modified: llvm/branches/release_36/test/SymbolRewriter/rewrite.map
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_36/test/SymbolRewriter/rewrite.map?rev=227324&r1=227323&r2=227324&view=diff
==============================================================================
--- llvm/branches/release_36/test/SymbolRewriter/rewrite.map (original)
+++ llvm/branches/release_36/test/SymbolRewriter/rewrite.map Wed Jan 28 11:24:04 2015
@@ -44,3 +44,23 @@ global alias: {
target: _ZN1SD1Ev,
}
+function: {
+ source: source_comdat_function,
+ target: target_comdat_function,
+}
+
+function: {
+ source: source_comdat_function_(.*),
+ transform: target_comdat_function_\1,
+}
+
+global variable: {
+ source: source_comdat_variable,
+ target: target_comdat_variable,
+}
+
+global variable: {
+ source: source_comdat_variable_(.*),
+ transform: target_comdat_variable_\1,
+}
+
More information about the llvm-branch-commits
mailing list