Skip to content

Commit 298dafc

Browse files
Fix version extraction
1 parent 3fcaded commit 298dafc

File tree

4 files changed

+9
-8
lines changed

4 files changed

+9
-8
lines changed

clang/lib/CodeGen/CodeGenPGO.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,6 +1357,9 @@ void CodeGenPGO::setProfileVersion(llvm::Module &M) {
13571357

13581358
IRLevelVersionVariable->setVisibility(llvm::GlobalValue::HiddenVisibility);
13591359
llvm::Triple TT(M.getTargetTriple());
1360+
if (TT.isAMDGPU() || TT.isNVPTX())
1361+
IRLevelVersionVariable->setVisibility(
1362+
llvm::GlobalValue::ProtectedVisibility);
13601363
if (TT.supportsCOMDAT()) {
13611364
IRLevelVersionVariable->setLinkage(llvm::GlobalValue::ExternalLinkage);
13621365
IRLevelVersionVariable->setComdat(M.getOrInsertComdat(VarName));

llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -462,10 +462,11 @@ createIRLevelProfileFlagVar(Module &M,
462462
auto IRLevelVersionVariable = new GlobalVariable(
463463
M, IntTy64, true, GlobalValue::WeakAnyLinkage,
464464
Constant::getIntegerValue(IntTy64, APInt(64, ProfileVersion)), VarName);
465+
IRLevelVersionVariable->setVisibility(GlobalValue::HiddenVisibility);
465466
if (isGPUProfTarget(M))
466-
IRLevelVersionVariable->setVisibility(GlobalValue::ProtectedVisibility);
467-
else
468-
IRLevelVersionVariable->setVisibility(GlobalValue::HiddenVisibility);
467+
IRLevelVersionVariable->setVisibility(
468+
llvm::GlobalValue::ProtectedVisibility);
469+
469470
Triple TT(M.getTargetTriple());
470471
if (TT.supportsCOMDAT()) {
471472
IRLevelVersionVariable->setLinkage(GlobalValue::ExternalLinkage);

offload/plugins-nextgen/common/include/GlobalHandler.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#ifndef LLVM_OPENMP_LIBOMPTARGET_PLUGINS_NEXTGEN_COMMON_GLOBALHANDLER_H
1414
#define LLVM_OPENMP_LIBOMPTARGET_PLUGINS_NEXTGEN_COMMON_GLOBALHANDLER_H
1515

16-
#include <optional>
1716
#include <type_traits>
1817

1918
#include "llvm/ADT/DenseMap.h"
@@ -77,7 +76,7 @@ struct GPUProfGlobals {
7776
SmallVector<__llvm_profile_data> Data;
7877
SmallVector<uint8_t> NamesData;
7978
Triple TargetTriple;
80-
std::optional<uint64_t> Version;
79+
uint64_t Version = INSTR_PROF_RAW_VERSION;
8180

8281
void dump() const;
8382
Error write() const;

offload/plugins-nextgen/common/src/GlobalHandler.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,6 @@ Error GPUProfGlobals::write() const {
282282
CountsSize = Counts.size() * sizeof(int64_t);
283283
__llvm_profile_data *DataBegin, *DataEnd;
284284
char *CountersBegin, *CountersEnd, *NamesBegin, *NamesEnd;
285-
const uint64_t *VersionOverride =
286-
Version.has_value() ? &Version.value() : nullptr;
287285

288286
// Initialize array of contiguous data. We need to make sure each section is
289287
// contiguous so that the PGO library can compute deltas properly
@@ -307,7 +305,7 @@ Error GPUProfGlobals::write() const {
307305
// Invoke compiler-rt entrypoint
308306
int result = __llvm_write_custom_profile(
309307
TargetTriple.str().c_str(), DataBegin, DataEnd, CountersBegin,
310-
CountersEnd, NamesBegin, NamesEnd, VersionOverride);
308+
CountersEnd, NamesBegin, NamesEnd, &Version);
311309
if (result != 0)
312310
return Plugin::error("Error writing GPU PGO data to file");
313311

0 commit comments

Comments
 (0)