mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-26 04:32:44 +01:00
Final fix for PR 23499 and IR test case.
This fixes a bit I forgot in r238335. In addition to the data record and the counter, we can also move the name of the counter to the comdat for the associated function. I'm also adding an IR test case to check that these three elements are placed in the proper comdat. llvm-svn: 238351
This commit is contained in:
parent
ce281b5177
commit
913ede308e
@ -196,14 +196,17 @@ InstrProfiling::getOrCreateRegionCounters(InstrProfIncrementInst *Inc) {
|
|||||||
if (It != RegionCounters.end())
|
if (It != RegionCounters.end())
|
||||||
return It->second;
|
return It->second;
|
||||||
|
|
||||||
// Move the name variable to the right section.
|
// Move the name variable to the right section. Make sure it is placed in the
|
||||||
|
// same comdat as its associated function. Otherwise, we may get multiple
|
||||||
|
// counters for the same function in certain cases.
|
||||||
|
Function *Fn = Inc->getParent()->getParent();
|
||||||
Name->setSection(getNameSection());
|
Name->setSection(getNameSection());
|
||||||
Name->setAlignment(1);
|
Name->setAlignment(1);
|
||||||
|
Name->setComdat(Fn->getComdat());
|
||||||
|
|
||||||
uint64_t NumCounters = Inc->getNumCounters()->getZExtValue();
|
uint64_t NumCounters = Inc->getNumCounters()->getZExtValue();
|
||||||
LLVMContext &Ctx = M->getContext();
|
LLVMContext &Ctx = M->getContext();
|
||||||
ArrayType *CounterTy = ArrayType::get(Type::getInt64Ty(Ctx), NumCounters);
|
ArrayType *CounterTy = ArrayType::get(Type::getInt64Ty(Ctx), NumCounters);
|
||||||
Function *Fn = Inc->getParent()->getParent();
|
|
||||||
|
|
||||||
// Create the counters variable.
|
// Create the counters variable.
|
||||||
auto *Counters = new GlobalVariable(*M, CounterTy, false, Name->getLinkage(),
|
auto *Counters = new GlobalVariable(*M, CounterTy, false, Name->getLinkage(),
|
||||||
@ -212,9 +215,6 @@ InstrProfiling::getOrCreateRegionCounters(InstrProfIncrementInst *Inc) {
|
|||||||
Counters->setVisibility(Name->getVisibility());
|
Counters->setVisibility(Name->getVisibility());
|
||||||
Counters->setSection(getCountersSection());
|
Counters->setSection(getCountersSection());
|
||||||
Counters->setAlignment(8);
|
Counters->setAlignment(8);
|
||||||
// Place the counters in the same comdat section as its parent function.
|
|
||||||
// Otherwise, we may get multiple counters for the same function in certain
|
|
||||||
// cases.
|
|
||||||
Counters->setComdat(Fn->getComdat());
|
Counters->setComdat(Fn->getComdat());
|
||||||
|
|
||||||
RegionCounters[Inc->getName()] = Counters;
|
RegionCounters[Inc->getName()] = Counters;
|
||||||
|
21
test/Instrumentation/InstrProfiling/PR23499.ll
Normal file
21
test/Instrumentation/InstrProfiling/PR23499.ll
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
;; Check that data associated with linkonce odr functions are placed in
|
||||||
|
;; the same comdat section as their associated function.
|
||||||
|
|
||||||
|
; RUN: opt < %s -mtriple=x86_64-apple-macosx10.10.0 -instrprof -S | FileCheck %s
|
||||||
|
; RUN: opt < %s -mtriple=x86_64-unknown-linux -instrprof -S | FileCheck %s
|
||||||
|
|
||||||
|
$_Z3barIvEvv = comdat any
|
||||||
|
|
||||||
|
@__llvm_profile_name__Z3barIvEvv = linkonce_odr hidden constant [11 x i8] c"_Z3barIvEvv", align 1
|
||||||
|
|
||||||
|
; CHECK: @__llvm_profile_name__Z3barIvEvv = linkonce_odr hidden constant [11 x i8] c"_Z3barIvEvv", section "{{.*}}__llvm_prf_names", comdat($_Z3barIvEvv), align 1
|
||||||
|
; CHECK: @__llvm_profile_counters__Z3barIvEvv = linkonce_odr hidden global [1 x i64] zeroinitializer, section "{{.*}}__llvm_prf_cnts", comdat($_Z3barIvEvv), align 8
|
||||||
|
; CHECK: @__llvm_profile_data__Z3barIvEvv = linkonce_odr hidden constant { i32, i32, i64, i8*, i64* } { i32 11, i32 1, i64 0, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @__llvm_profile_name__Z3barIvEvv, i32 0, i32 0), i64* getelementptr inbounds ([1 x i64], [1 x i64]* @__llvm_profile_counters__Z3barIvEvv, i32 0, i32 0) }, section "{{.*}}__llvm_prf_data", comdat($_Z3barIvEvv), align 8
|
||||||
|
|
||||||
|
declare void @llvm.instrprof.increment(i8*, i64, i32, i32) #1
|
||||||
|
|
||||||
|
define linkonce_odr void @_Z3barIvEvv() comdat {
|
||||||
|
entry:
|
||||||
|
call void @llvm.instrprof.increment(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @__llvm_profile_name__Z3barIvEvv, i32 0, i32 0), i64 0, i32 1, i32 0)
|
||||||
|
ret void
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user