[compiler-rt] [llvm] [nsan] Emit calls to optimized functions (PR #98900)

Dmitriy Chestnykh via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 17 21:38:28 PDT 2024


================
@@ -493,6 +493,59 @@ class ValueToShadowMap {
   DenseMap<Value *, Value *> Map;
 };
 
+// Template parameter is the number of functions
+template <size_t N> class NsanMemOpFn {
+public:
+  NsanMemOpFn(Module &M, ArrayRef<StringRef> Sized, StringRef Fallback,
+              size_t NumArgs);
+  // Number of parameters can be extracted from FunctionCallee
+  FunctionCallee getFunctionFor(uint64_t MemOpSize) const;
+  FunctionCallee getFallback() const;
+
+private:
+  std::array<FunctionCallee, N> Funcs;
+};
+
+template <size_t N>
+NsanMemOpFn<N>::NsanMemOpFn(Module &M, ArrayRef<StringRef> Sized,
+                            StringRef Fallback, size_t NumArgs) {
+  LLVMContext &Ctx = M.getContext();
+  AttributeList Attr;
+  Attr = Attr.addFnAttribute(Ctx, Attribute::NoUnwind);
+  Type *PtrTy = PointerType::getUnqual(Ctx);
+  Type *VoidTy = Type::getVoidTy(Ctx);
+  IntegerType *IntptrTy = M.getDataLayout().getIntPtrType(Ctx);
+  FunctionType *SizedFnTy;
+
+  if (NumArgs == 3)
+    SizedFnTy = FunctionType::get(VoidTy, {PtrTy, PtrTy}, false);
+  else
+    SizedFnTy = FunctionType::get(VoidTy, {PtrTy}, false);
+
+  for (size_t i = 0; i < N - 1; ++i)
+    Funcs[i] = M.getOrInsertFunction(Sized[i], SizedFnTy, Attr);
+
+  if (NumArgs == 3)
----------------
chestnykh wrote:

Dont, thx

https://github.com/llvm/llvm-project/pull/98900


More information about the llvm-commits mailing list