llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Vitaly Buka (vitalybuka)

<details>
<summary>Changes</summary>

#<!-- -->244116 included `clang/CIR/Dialect/Passes.h` from
`TargetLowering/CIRABIRewriteContext.h` for `cir::CallConvTarget`, pulling
in the generated `Passes.h.inc` (`MLIRCIRPassIncGen`) from a higher-level
library and breaking builds when `CIRABIRewriteContext.cpp` compiles first.

Keep `CallConvTarget` out of `TargetLowering` by dispatching non-ignored
`cir.va_arg` lowering through a virtual `expandVAArg` hook on
`CIRABIRewriteContext`, implemented by X86_64 and AMDGPU subclasses
selected in `CallConvLoweringPass` (matching the structure of #<!-- -->244729).

Fixes build failure on 
https://lab.llvm.org/buildbot/#/builders/sanitizer-windows.

Assisted-by: Gemini

---
Full diff: https://github.com/llvm/llvm-project/pull/244977.diff


3 Files Affected:

- (modified) clang/lib/CIR/Dialect/Transforms/CallConvLoweringPass.cpp (+21-1) 
- (modified) 
clang/lib/CIR/Dialect/Transforms/TargetLowering/CIRABIRewriteContext.cpp 
(+42-13) 
- (modified) 
clang/lib/CIR/Dialect/Transforms/TargetLowering/CIRABIRewriteContext.h (+29-26) 


``````````diff
diff --git a/clang/lib/CIR/Dialect/Transforms/CallConvLoweringPass.cpp 
b/clang/lib/CIR/Dialect/Transforms/CallConvLoweringPass.cpp
index 2ccf798e5fa3f..ecb53b2cab299 100644
--- a/clang/lib/CIR/Dialect/Transforms/CallConvLoweringPass.cpp
+++ b/clang/lib/CIR/Dialect/Transforms/CallConvLoweringPass.cpp
@@ -159,6 +159,24 @@ createABIClassifier(cir::CallConvTarget target,
   llvm_unreachable("an unset driver mode is rejected before this point");
 }
 
+static std::unique_ptr<CIRABIRewriteContext>
+createABIRewriteContext(cir::CallConvTarget target, ModuleOp modOp,
+                        const DataLayout &dl, bool enableNoundefAttrs) {
+  switch (target) {
+  case cir::CallConvTarget::X86_64:
+    return createX86_64ABIRewriteContext(modOp, dl, enableNoundefAttrs);
+  case cir::CallConvTarget::AMDGPU:
+    return createAMDGPUABIRewriteContext(modOp, dl, enableNoundefAttrs);
+  case cir::CallConvTarget::None:
+  case cir::CallConvTarget::Test:
+  case cir::CallConvTarget::SPIRV:
+  case cir::CallConvTarget::AArch64:
+    return std::make_unique<CIRABIRewriteContext>(modOp, dl,
+                                                  enableNoundefAttrs);
+  }
+  llvm_unreachable("unhandled CallConvTarget");
+}
+
 namespace {
 
 /// Find the cir.func declaration matching a direct cir.call / cir.try_call
@@ -220,7 +238,9 @@ void CallConvLoweringPass::runOnOperation() {
   }
 
   DataLayout dl(moduleOp);
-  CIRABIRewriteContext rewriteCtx(moduleOp, dl, target, enableNoundefAttrs);
+  std::unique_ptr<CIRABIRewriteContext> rewriteCtxOwner =
+      createABIRewriteContext(target, moduleOp, dl, enableNoundefAttrs);
+  CIRABIRewriteContext &rewriteCtx = *rewriteCtxOwner;
   // A non-byval indirect parameter's slot outlives the rewrite that retypes
   // the parameter, so that a call forwarding the parameter can still recognize
   // it.  Draining on scope exit collapses those slots whichever way this
diff --git 
a/clang/lib/CIR/Dialect/Transforms/TargetLowering/CIRABIRewriteContext.cpp 
b/clang/lib/CIR/Dialect/Transforms/TargetLowering/CIRABIRewriteContext.cpp
index 4b826f4ddb754..fb667458e4c53 100644
--- a/clang/lib/CIR/Dialect/Transforms/TargetLowering/CIRABIRewriteContext.cpp
+++ b/clang/lib/CIR/Dialect/Transforms/TargetLowering/CIRABIRewriteContext.cpp
@@ -2841,6 +2841,24 @@ mlir::LogicalResult replaceVAArgResult(CIRBaseBuilderTy 
&b, cir::VAArgOp op,
   return mlir::success();
 }
 
+class AMDGPUABIRewriteContext final : public CIRABIRewriteContext {
+public:
+  using CIRABIRewriteContext::CIRABIRewriteContext;
+
+protected:
+  mlir::LogicalResult expandVAArg(cir::VAArgOp op, const ArgClassification &ac,
+                                  CIRBaseBuilderTy &builder) override;
+};
+
+class X86_64ABIRewriteContext final : public CIRABIRewriteContext {
+public:
+  using CIRABIRewriteContext::CIRABIRewriteContext;
+
+protected:
+  mlir::LogicalResult expandVAArg(cir::VAArgOp op, const ArgClassification &ac,
+                                  CIRBaseBuilderTy &builder) override;
+};
+
 } // namespace
 
 mlir::LogicalResult
@@ -2861,21 +2879,16 @@ CIRABIRewriteContext::rewriteVAArg(mlir::Operation 
*vaArgOp,
     return mlir::success();
   }
 
-  switch (target) {
-  case cir::CallConvTarget::X86_64:
-    return rewriteVAArgX86_64(op, ac, builder);
-  case cir::CallConvTarget::AMDGPU:
-    return rewriteVAArgAMDGPU(op, ac, builder);
-  case cir::CallConvTarget::None:
-  case cir::CallConvTarget::Test:
-  case cir::CallConvTarget::SPIRV:
-  case cir::CallConvTarget::AArch64:
-    break;
-  }
+  return expandVAArg(op, ac, builder);
+}
+
+mlir::LogicalResult CIRABIRewriteContext::expandVAArg(cir::VAArgOp op,
+                                                      const ArgClassification 
&,
+                                                      CIRBaseBuilderTy &) {
   return reportVAArgNYI(op, "a type on this target");
 }
 
-mlir::LogicalResult CIRABIRewriteContext::rewriteVAArgAMDGPU(
+mlir::LogicalResult AMDGPUABIRewriteContext::expandVAArg(
     cir::VAArgOp op, const ArgClassification &ac, CIRBaseBuilderTy &builder) {
   assert(ac.kind == ArgKind::Direct && !ac.coercedType && ac.directAlign &&
          "AMDGPU reads every variadic argument in place from its slots");
@@ -2886,7 +2899,7 @@ mlir::LogicalResult 
CIRABIRewriteContext::rewriteVAArgAMDGPU(
   return replaceVAArgResult(builder, op, addr, slotSize, dl);
 }
 
-mlir::LogicalResult CIRABIRewriteContext::rewriteVAArgX86_64(
+mlir::LogicalResult X86_64ABIRewriteContext::expandVAArg(
     cir::VAArgOp op, const ArgClassification &ac, CIRBaseBuilderTy &builder) {
   mlir::Location loc = op.getLoc();
   mlir::Type resultTy = op.getType();
@@ -3006,3 +3019,19 @@ mlir::LogicalResult 
CIRABIRewriteContext::rewriteVAArgX86_64(
   return replaceVAArgResult(builder, op, addr,
                             argumentAreaAlign(resultTy, module), dl);
 }
+
+std::unique_ptr<CIRABIRewriteContext>
+cir::createX86_64ABIRewriteContext(mlir::ModuleOp module,
+                                   const mlir::DataLayout &dl,
+                                   bool enableNoundefAttrs) {
+  return std::make_unique<X86_64ABIRewriteContext>(module, dl,
+                                                   enableNoundefAttrs);
+}
+
+std::unique_ptr<CIRABIRewriteContext>
+cir::createAMDGPUABIRewriteContext(mlir::ModuleOp module,
+                                   const mlir::DataLayout &dl,
+                                   bool enableNoundefAttrs) {
+  return std::make_unique<AMDGPUABIRewriteContext>(module, dl,
+                                                   enableNoundefAttrs);
+}
diff --git 
a/clang/lib/CIR/Dialect/Transforms/TargetLowering/CIRABIRewriteContext.h 
b/clang/lib/CIR/Dialect/Transforms/TargetLowering/CIRABIRewriteContext.h
index 3d85c5d66ed31..e492e74153ca5 100644
--- a/clang/lib/CIR/Dialect/Transforms/TargetLowering/CIRABIRewriteContext.h
+++ b/clang/lib/CIR/Dialect/Transforms/TargetLowering/CIRABIRewriteContext.h
@@ -27,9 +27,9 @@
 #include "clang/CIR/Dialect/Analysis/CIRAliasAnalysis.h"
 #include "clang/CIR/Dialect/IR/CIRDataLayout.h"
 #include "clang/CIR/Dialect/IR/CIRDialect.h"
-#include "clang/CIR/Dialect/Passes.h"
 #include "llvm/ADT/SmallVector.h"
 #include <cassert>
+#include <memory>
 #include <utility>
 
 namespace cir {
@@ -47,10 +47,9 @@ class CIRBaseBuilderTy;
 class CIRABIRewriteContext : public mlir::abi::ABIRewriteContext {
 public:
   CIRABIRewriteContext(mlir::ModuleOp module, const mlir::DataLayout &dl,
-                       cir::CallConvTarget target, bool enableNoundefAttrs)
-      : module(module), dl(dl), target(target),
-        enableNoundefAttrs(enableNoundefAttrs), cirDataLayout(module),
-        aliasAnalysis(module) {
+                       bool enableNoundefAttrs)
+      : module(module), dl(dl), cirDataLayout(module),
+        enableNoundefAttrs(enableNoundefAttrs), aliasAnalysis(module) {
     cir::registerCIRAliasAnalyses(aliasAnalysis, module);
   }
 
@@ -69,11 +68,11 @@ class CIRABIRewriteContext : public 
mlir::abi::ABIRewriteContext {
                   const mlir::abi::FunctionClassification &fc,
                   mlir::OpBuilder &builder) override;
 
-  /// Expand a `cir.va_arg` with the va_arg rules of the target this context
-  /// lowers for.
+  /// Replace a `cir.va_arg` of an ignored type with poison, leaving the
+  /// va_list unchanged.  Every other `cir.va_arg` is passed to expandVAArg.
   mlir::LogicalResult rewriteVAArg(mlir::Operation *vaArgOp,
                                    const mlir::abi::ArgClassification &ac,
-                                   mlir::OpBuilder &builder) override;
+                                   mlir::OpBuilder &builder) final;
 
   /// Retype \p addrOp, which holds the address of \p funcOp, to the signature
   /// funcOp was rewritten to, and cast it back so existing uses keep the type
@@ -119,34 +118,26 @@ class CIRABIRewriteContext : public 
mlir::abi::ABIRewriteContext {
 
   mlir::StringRef getDialectNamespace() const override { return "cir"; }
 
-private:
-  /// Expand \p op into the x86-64 SysV register-save-area / overflow-area
-  /// sequence.
-  mlir::LogicalResult rewriteVAArgX86_64(cir::VAArgOp op,
-                                         const mlir::abi::ArgClassification 
&ac,
-                                         CIRBaseBuilderTy &builder);
-
-  /// Expand \p op into a read from the 4-byte slots its pointer va_list walks.
-  mlir::LogicalResult rewriteVAArgAMDGPU(cir::VAArgOp op,
-                                         const mlir::abi::ArgClassification 
&ac,
-                                         CIRBaseBuilderTy &builder);
+protected:
+  /// Expand \p op, whose type is not ignored, into a read through the
+  /// target's va_list that also advances the va_list past the value.
+  virtual mlir::LogicalResult
+  expandVAArg(cir::VAArgOp op, const mlir::abi::ArgClassification &ac,
+              CIRBaseBuilderTy &builder);
 
   mlir::ModuleOp module;
   const mlir::DataLayout &dl;
 
-  /// The target whose rules drive the target-specific rewrites, such as
-  /// va_arg expansion.
-  cir::CallConvTarget target;
+  /// The CIR view of the module's data layout, which provides the store and
+  /// alloc sizes that \c dl does not.
+  cir::CIRDataLayout cirDataLayout;
 
+private:
   /// Whether extended and indirect arguments are marked llvm.noundef.  Set
   /// from the enable_noundef_attrs field of the module's
   /// #cir.lowering_options.
   bool enableNoundefAttrs;
 
-  /// The CIR view of the module's data layout, which provides the store and
-  /// alloc sizes that \c dl does not.
-  cir::CIRDataLayout cirDataLayout;
-
   /// Alias analysis over the module with the CIR implementations registered.
   /// rewriteCallSite asks it whether a byval operand's storage is written
   /// between its load and the call.
@@ -165,6 +156,18 @@ class CIRABIRewriteContext : public 
mlir::abi::ABIRewriteContext {
 /// The signature the indirect call \p call reaches its callee through.
 cir::FuncType getIndirectCalleeType(cir::CIRCallOpInterface call);
 
+/// A rewrite context that expands `cir.va_arg` through the x86-64 SysV
+/// va_list.
+std::unique_ptr<CIRABIRewriteContext>
+createX86_64ABIRewriteContext(mlir::ModuleOp module, const mlir::DataLayout 
&dl,
+                              bool enableNoundefAttrs);
+
+/// A rewrite context that expands `cir.va_arg` through the AMDGPU pointer
+/// va_list.
+std::unique_ptr<CIRABIRewriteContext>
+createAMDGPUABIRewriteContext(mlir::ModuleOp module, const mlir::DataLayout 
&dl,
+                              bool enableNoundefAttrs);
+
 } // namespace cir
 
 #endif // 
CLANG_LIB_CIR_DIALECT_TRANSFORMS_TARGETLOWERING_CIRABIREWRITECONTEXT_H

``````````

</details>


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

Reply via email to