================
@@ -1071,6 +1091,62 @@ cir::GlobalViewAttr 
CIRGenModule::getAddrOfGlobalVarAttr(const VarDecl *d) {
   return builder.getGlobalViewAttr(ptrTy, globalOp);
 }
 
+void CIRGenModule::addUsedGlobal(cir::GlobalOp gv) {
+  assert(!gv.isDeclaration() &&
+         "Only globals with definition can force usage.");
+  LLVMUsed.emplace_back(gv);
+}
+
+void CIRGenModule::addCompilerUsedGlobal(cir::GlobalOp gv) {
+  assert(!gv.isDeclaration() &&
+         "Only globals with definition can force usage.");
+  LLVMCompilerUsed.emplace_back(gv);
+}
+
+void CIRGenModule::addUsedOrCompilerUsedGlobal(cir::GlobalOp gv) {
+  assert(!gv.isDeclaration() &&
+         "Only globals with definition can force usage.");
+  if (getTriple().isOSBinFormatELF())
+    LLVMCompilerUsed.emplace_back(gv);
+  else
+    LLVMUsed.emplace_back(gv);
+}
+
+static void emitUsed(CIRGenModule &cgm, StringRef name,
+                     std::vector<cir::GlobalOp> &list) {
+  // Don't create llvm.used if there is no need.
+  if (list.empty())
+    return;
+
+  // Convert List to what ConstantArray needs.
+  auto &builder = cgm.getBuilder();
+  auto loc = builder.getUnknownLoc();
+  llvm::SmallVector<mlir::Attribute, 8> usedArray;
+  usedArray.resize(list.size());
+  for (unsigned i = 0, e = list.size(); i != e; ++i) {
----------------
skc7 wrote:

Updated in latest patch.

https://github.com/llvm/llvm-project/pull/188189
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to