================
@@ -528,6 +564,256 @@ CallInst *IRTCallDescription::createLLVMCall(Value *&V,
   return CI;
 }
 
+template <typename Ty> constexpr static Value *getValue(Ty &ValueOrUse) {
+  if constexpr (std::is_same<Ty, Use>::value)
+    return ValueOrUse.get();
+  else
+    return static_cast<Value *>(&ValueOrUse);
+}
+
+template <typename Range>
+static Value *createValuePack(const Range &R, InstrumentationConfig &IConf,
+                              InstrumentorIRBuilderTy &IIRB) {
+  auto *Fn = IIRB.IRB.GetInsertBlock()->getParent();
+  auto *I32Ty = IIRB.IRB.getInt32Ty();
+  SmallVector<Constant *> ConstantValues;
+  SmallVector<std::pair<Value *, uint32_t>> Values;
+  SmallVector<Type *> Types;
+  for (auto &RE : R) {
+    Value *V = getValue(RE);
+    if (!V->getType()->isSized())
+      continue;
+    auto VSize = IIRB.DL.getTypeAllocSize(V->getType());
+    ConstantValues.push_back(getCI(I32Ty, VSize));
+    Types.push_back(I32Ty);
+    ConstantValues.push_back(getCI(I32Ty, V->getType()->getTypeID()));
+    Types.push_back(I32Ty);
+    if (uint32_t MisAlign = VSize % 8) {
+      Types.push_back(ArrayType::get(IIRB.Int8Ty, 8 - MisAlign));
+      ConstantValues.push_back(ConstantArray::getNullValue(Types.back()));
+    }
+    Types.push_back(V->getType());
+    if (auto *C = dyn_cast<Constant>(V)) {
+      ConstantValues.push_back(C);
+      continue;
+    }
+    Values.push_back({V, ConstantValues.size()});
+    ConstantValues.push_back(Constant::getNullValue(V->getType()));
+  }
+  if (Types.empty())
+    return ConstantPointerNull::get(PointerType::getUnqual(IIRB.Ctx));
+
+  StructType *STy = StructType::get(Fn->getContext(), Types, 
/*isPacked=*/true);
+  Constant *Initializer = ConstantStruct::get(STy, ConstantValues);
+
+  GlobalVariable *&GV = IConf.ConstantGlobalsCache[Initializer];
+  if (!GV)
+    GV = new GlobalVariable(*Fn->getParent(), STy, false,
+                            GlobalValue::InternalLinkage, Initializer,
+                            IConf.getRTName("", "value_pack"));
+
+  auto *AI = IIRB.getAlloca(Fn, STy);
+  IIRB.IRB.CreateMemCpy(AI, AI->getAlign(), GV, MaybeAlign(GV->getAlignment()),
----------------
arsenm wrote:

```suggestion
  IIRB.IRB.CreateMemCpy(AI, AI->getAlign(), GV, GV->getAlign(),
```

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

Reply via email to