================
@@ -124,6 +135,67 @@ Value createIgnoredValue(OpBuilder &builder, Location loc, 
Type ty) {
   return cir::ConstantOp::create(builder, loc, ty, cir::PoisonAttr::get(ty));
 }
 
+/// Build an updated arg_attrs ArrayAttr that drops Ignore'd args and adds
+/// llvm.signext / llvm.zeroext on Extend args.  Preserves any existing arg
+/// attributes on retained arg slots.
+ArrayAttr updateArgAttrs(MLIRContext *ctx, unsigned numNewArgs,
+                         ArrayAttr existingArgAttrs,
+                         const FunctionClassification &fc) {
+  SmallVector<Attribute> newArgAttrs(numNewArgs, DictionaryAttr::get(ctx));
+
+  // Step 1: copy existing arg attrs over to their new positions, skipping
+  // Ignore'd args.
+  if (existingArgAttrs) {
+    unsigned newIdx = 0;
+    for (unsigned oldIdx = 0; oldIdx < existingArgAttrs.size(); ++oldIdx) {
+      if (oldIdx < fc.argInfos.size() &&
+          fc.argInfos[oldIdx].kind == ArgKind::Ignore)
+        continue;
+      if (newIdx < numNewArgs)
+        newArgAttrs[newIdx] = existingArgAttrs[oldIdx];
+      ++newIdx;
+    }
+  }
+
+  // Step 2: layer llvm.signext / llvm.zeroext onto each Extend arg.  The new
+  // arg index for Extend at original index `oldIdx` is `oldIdx` minus the
+  // number of Ignore'd args that came before it.
+  unsigned newIdx = 0;
+  for (auto [oldIdx, ac] : llvm::enumerate(fc.argInfos)) {
----------------
andykaylor wrote:

Could this loop be combined with the loop above to make this a single pass?

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

Reply via email to