[clang] [llvm] [HIPSTDPAR] Add support for globals (PR #146813)
Alex Voicu via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 11 08:09:09 PDT 2025
================
@@ -114,24 +115,221 @@ static inline void clearModule(Module &M) { // TODO: simplify.
eraseFromModule(*M.ifuncs().begin());
}
+static inline SmallVector<std::reference_wrapper<Use>>
+collectIndirectableUses(GlobalVariable *G) {
+ // We are interested only in use chains that end in an Instruction.
+ SmallVector<std::reference_wrapper<Use>> Uses;
+
+ SmallVector<std::reference_wrapper<Use>> Tmp(G->use_begin(), G->use_end());
+ while (!Tmp.empty()) {
+ Use &U = Tmp.back();
+ Tmp.pop_back();
+ if (isa<Instruction>(U.getUser()))
+ Uses.emplace_back(U);
+ else
+ transform(U.getUser()->uses(), std::back_inserter(Tmp),
+ [](auto &&U) { return std::ref(U); });
+ }
+
+ return Uses;
+}
+
+static inline GlobalVariable *getGlobalForName(GlobalVariable *G) {
+ // Create an anonymous global which stores the variable's name, which will be
+ // used by the HIPSTDPAR runtime to look up the program-wide symbol.
+ LLVMContext &Ctx = G->getContext();
+ auto *CDS = ConstantDataArray::getString(Ctx, G->getName());
+
+ GlobalVariable *N = G->getParent()->getOrInsertGlobal("", CDS->getType());
+ N->setInitializer(CDS);
+ N->setLinkage(GlobalValue::LinkageTypes::PrivateLinkage);
+ N->setConstant(true);
+
+ return N;
+}
+
+static inline GlobalVariable *getIndirectionGlobal(Module *M) {
----------------
AlexVlx wrote:
Documentation (these start out as short blocks / sequences taken out from a larger function, or small helpers like `eraseFromModule`). Some are clearly vestigial now, and I should clean the header up.
https://github.com/llvm/llvm-project/pull/146813
More information about the llvm-commits
mailing list