This is an archive of the discontinued LLVM Phabricator instance.

[OpenMP][OpenMPIRBuilder] Migrate setPropertyExecutionMode() from Clang to OpenMPIRBuilder.
AbandonedPublic

Authored by raghavendhra on Jul 20 2023, 12:54 AM.

Details

Summary

Move setPropertyExecutionMode() from Clang to OpenMPIRBuilder and change the references in Clang to use the function from OMPIRBuilder.

Diff Detail

Event Timeline

raghavendhra created this revision.Jul 20 2023, 12:54 AM
raghavendhra requested review of this revision.Jul 20 2023, 12:54 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald Transcript

Not an expert here, only some minor comments.

clang/lib/CodeGen/CodeGenModule.h
1015

Return a reference instead of pointer here?

llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
1506

Rename to sth like isSPMDMode or so? To me Mode reads overly general.

1507

Should this preferably be a reference instead of pointer?

raghavendhra marked 3 inline comments as done.Jul 21 2023, 12:46 AM

Addressed review comments.

Rebased patch.

jplehr added inline comments.Jul 21 2023, 1:24 AM
clang/lib/CodeGen/CodeGenModule.h
1016

I believe that this can be simplified to

std::vector<llvm::WeakTrackingVH> &getLLVMCompilerUsed() {
  return LLVMCompilerUsed;
}
llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
1509
...., bool IsSPMDMode, std::vector<llvm::WeakTrackingVH> &LLVMCompilerUsed);
llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
4938
...., std::vector<llvm::WeakTrackingVH> &LLVMCompilerUsed) {`
4947

Can this assertion ever be not be met? I'm just curious, given that you create that GVMode yourself.

raghavendhra marked 2 inline comments as done.Jul 21 2023, 11:08 AM
raghavendhra added inline comments.
llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
4947

Adopted this assert from Clang Codegen addCompilerUsedGlobal() which is called inside setPropertyExecutionMode() in CGOpenMPRuntimeGPU.cpp

Actual definition of addCompilerusedGlobal() in CodeGenModule.cpp

void CodeGenModule::addCompilerUsedGlobal(llvm::GlobalValue *GV) {

assert(!GV->isDeclaration() &&
       "Only globals with definition can force usage.");
LLVMCompilerUsed.emplace_back(GV);

}

Addressed JP's review comments and rebased.

Mostly nits. One problem I have is the vector. I do not believe Flang will use the same for their "llvm.used" tracking. I think it makes more sense to provide a callback or just return the global and let the caller handle it.

llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
1508
llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
4937
4950

No llvm:: here.

raghavendhra marked 2 inline comments as done.Jul 24 2023, 12:27 PM
raghavendhra added inline comments.
llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
4950

Sorry, Can you please elaborate which llvm:: you mentioned about here? Thanks!

Addressed review comments by making setPropertyExecutionMode() to return a Global Value instead of void. Rebased patch.

Remove llvm:: from function setPropertyExecutionMode(). Rebasing the patch.

jplehr added inline comments.Jul 26 2023, 4:42 AM
llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
4947

Sorry for the confusion I potentially created: I mainly wanted to understand if that case can ever happen.
I'm not really familiar with this part of the compiler.

jdoerfert accepted this revision.Jul 26 2023, 8:42 AM

LG, address the nits below please.

clang/lib/CodeGen/CodeGenModule.h
1017

Unused now.

llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
4941
4949–4956

unrelated. Avoid in this commit, feel free to push a NFC clang-format patch first.

This revision is now accepted and ready to land.Jul 26 2023, 8:42 AM
raghavendhra marked 3 inline comments as done.Jul 26 2023, 12:03 PM
raghavendhra abandoned this revision.Aug 11 2023, 11:55 AM

setPropertyExecutionMode function is no longer present / used in clang because of a change in https://reviews.llvm.org/D142569 So abandoning this patch to migrate that function into OMPIRBuilder.