@@ -1059,6 +1059,8 @@ void InstrLowerer::lowerValueProfileInst(InstrProfValueProfileInst *Ind) {
1059
1059
llvm::InstrProfValueKind::IPVK_MemOPSize);
1060
1060
CallInst *Call = nullptr ;
1061
1061
auto *TLI = &GetTLI (*Ind->getFunction ());
1062
+ auto *NormalizedDataVarPtr = ConstantExpr::getPointerBitCastOrAddrSpaceCast (
1063
+ DataVar, PointerType::get (M.getContext (), 0 ));
1062
1064
1063
1065
// To support value profiling calls within Windows exception handlers, funclet
1064
1066
// information contained within operand bundles needs to be copied over to
@@ -1067,11 +1069,13 @@ void InstrLowerer::lowerValueProfileInst(InstrProfValueProfileInst *Ind) {
1067
1069
SmallVector<OperandBundleDef, 1 > OpBundles;
1068
1070
Ind->getOperandBundlesAsDefs (OpBundles);
1069
1071
if (!IsMemOpSize) {
1070
- Value *Args[3 ] = {Ind->getTargetValue (), DataVar, Builder.getInt32 (Index)};
1072
+ Value *Args[3 ] = {Ind->getTargetValue (), NormalizedDataVarPtr,
1073
+ Builder.getInt32 (Index)};
1071
1074
Call = Builder.CreateCall (getOrInsertValueProfilingCall (M, *TLI), Args,
1072
1075
OpBundles);
1073
1076
} else {
1074
- Value *Args[3 ] = {Ind->getTargetValue (), DataVar, Builder.getInt32 (Index)};
1077
+ Value *Args[3 ] = {Ind->getTargetValue (), NormalizedDataVarPtr,
1078
+ Builder.getInt32 (Index)};
1075
1079
Call = Builder.CreateCall (
1076
1080
getOrInsertValueProfilingCall (M, *TLI, ValueProfilingCallType::MemOp),
1077
1081
Args, OpBundles);
@@ -1814,7 +1818,8 @@ void InstrLowerer::createDataVariable(InstrProfCntrInstBase *Inc) {
1814
1818
getInstrProfSectionName (IPSK_vals, TT.getObjectFormat ()));
1815
1819
ValuesVar->setAlignment (Align (8 ));
1816
1820
maybeSetComdat (ValuesVar, Fn, CntsVarName);
1817
- ValuesPtrExpr = ValuesVar;
1821
+ ValuesPtrExpr = ConstantExpr::getPointerBitCastOrAddrSpaceCast (
1822
+ ValuesVar, PointerType::get (Fn->getContext (), 0 ));
1818
1823
}
1819
1824
1820
1825
uint64_t NumCounters = Inc->getNumCounters ()->getZExtValue ();
@@ -1838,6 +1843,10 @@ void InstrLowerer::createDataVariable(InstrProfCntrInstBase *Inc) {
1838
1843
for (uint32_t Kind = IPVK_First; Kind <= IPVK_Last; ++Kind)
1839
1844
Int16ArrayVals[Kind] = ConstantInt::get (Int16Ty, PD.NumValueSites [Kind]);
1840
1845
1846
+ if (isGPUProfTarget (M)) {
1847
+ Linkage = GlobalValue::ExternalLinkage;
1848
+ Visibility = GlobalValue::ProtectedVisibility;
1849
+ }
1841
1850
// If the data variable is not referenced by code (if we don't emit
1842
1851
// @llvm.instrprof.value.profile, NS will be 0), and the counter keeps the
1843
1852
// data variable live under linker GC, the data variable can be private. This
@@ -1849,9 +1858,9 @@ void InstrLowerer::createDataVariable(InstrProfCntrInstBase *Inc) {
1849
1858
// If profd is in a deduplicate comdat, NS==0 with a hash suffix guarantees
1850
1859
// that other copies must have the same CFG and cannot have value profiling.
1851
1860
// If no hash suffix, other profd copies may be referenced by code.
1852
- if (NS == 0 && !(DataReferencedByCode && NeedComdat && !Renamed) &&
1853
- (TT.isOSBinFormatELF () ||
1854
- (!DataReferencedByCode && TT.isOSBinFormatCOFF ()))) {
1861
+ else if (NS == 0 && !(DataReferencedByCode && NeedComdat && !Renamed) &&
1862
+ (TT.isOSBinFormatELF () ||
1863
+ (!DataReferencedByCode && TT.isOSBinFormatCOFF ()))) {
1855
1864
Linkage = GlobalValue::PrivateLinkage;
1856
1865
Visibility = GlobalValue::DefaultVisibility;
1857
1866
}
@@ -1974,6 +1983,13 @@ void InstrLowerer::emitNameData() {
1974
1983
NamesVar = new GlobalVariable (M, NamesVal->getType (), true ,
1975
1984
GlobalValue::PrivateLinkage, NamesVal,
1976
1985
getInstrProfNamesVarName ());
1986
+
1987
+ // Make names variable public if current target is a GPU
1988
+ if (isGPUProfTarget (M)) {
1989
+ NamesVar->setLinkage (GlobalValue::ExternalLinkage);
1990
+ NamesVar->setVisibility (GlobalValue::VisibilityTypes::ProtectedVisibility);
1991
+ }
1992
+
1977
1993
NamesSize = CompressedNameStr.size ();
1978
1994
setGlobalVariableLargeSection (TT, *NamesVar);
1979
1995
NamesVar->setSection (
@@ -2040,10 +2056,13 @@ void InstrLowerer::emitRegistration() {
2040
2056
IRBuilder<> IRB (BasicBlock::Create (M.getContext (), " " , RegisterF));
2041
2057
for (Value *Data : CompilerUsedVars)
2042
2058
if (!isa<Function>(Data))
2043
- IRB.CreateCall (RuntimeRegisterF, Data);
2059
+ // Check for addrspace cast when profiling GPU
2060
+ IRB.CreateCall (RuntimeRegisterF,
2061
+ IRB.CreatePointerBitCastOrAddrSpaceCast (Data, VoidPtrTy));
2044
2062
for (Value *Data : UsedVars)
2045
2063
if (Data != NamesVar && !isa<Function>(Data))
2046
- IRB.CreateCall (RuntimeRegisterF, Data);
2064
+ IRB.CreateCall (RuntimeRegisterF,
2065
+ IRB.CreatePointerBitCastOrAddrSpaceCast (Data, VoidPtrTy));
2047
2066
2048
2067
if (NamesVar) {
2049
2068
Type *ParamTypes[] = {VoidPtrTy, Int64Ty};
@@ -2052,7 +2071,9 @@ void InstrLowerer::emitRegistration() {
2052
2071
auto *NamesRegisterF =
2053
2072
Function::Create (NamesRegisterTy, GlobalVariable::ExternalLinkage,
2054
2073
getInstrProfNamesRegFuncName (), M);
2055
- IRB.CreateCall (NamesRegisterF, {NamesVar, IRB.getInt64 (NamesSize)});
2074
+ IRB.CreateCall (NamesRegisterF, {IRB.CreatePointerBitCastOrAddrSpaceCast (
2075
+ NamesVar, VoidPtrTy),
2076
+ IRB.getInt64 (NamesSize)});
2056
2077
}
2057
2078
2058
2079
IRB.CreateRetVoid ();
@@ -2073,7 +2094,10 @@ bool InstrLowerer::emitRuntimeHook() {
2073
2094
auto *Var =
2074
2095
new GlobalVariable (M, Int32Ty, false , GlobalValue::ExternalLinkage,
2075
2096
nullptr , getInstrProfRuntimeHookVarName ());
2076
- Var->setVisibility (GlobalValue::HiddenVisibility);
2097
+ if (isGPUProfTarget (M))
2098
+ Var->setVisibility (GlobalValue::ProtectedVisibility);
2099
+ else
2100
+ Var->setVisibility (GlobalValue::HiddenVisibility);
2077
2101
2078
2102
if (TT.isOSBinFormatELF () && !TT.isPS ()) {
2079
2103
// Mark the user variable as used so that it isn't stripped out.
0 commit comments