================
@@ -20,17 +21,117 @@ using namespace cir;
 // Helpers
 
//===----------------------------------------------------------------------===//
 
+static constexpr unsigned MaxLookupDepth = 6;
+
 mlir::Value CIRBasicAliasAnalysis::getUnderlyingObject(mlir::Value val) {
   LDBG() << "Getting underlying object for: " << val;
 
-  // TODO: Walk through cir.ptr_stride, cir.cast, cir.get_member, etc.
-  // to find the root allocation (cir.alloca, cir.global_addr, function args).
-  LDBG() << "Not yet implemented";
+  for (unsigned depth = 0; depth < MaxLookupDepth; ++depth) {
+    mlir::Operation *defOp = val.getDefiningOp();
+    if (!defOp) {
+      LDBG() << "No defining operation, stopping";
+      break; // Block argument (e.g. function parameter) — stop here.
+    }
+
+    // Bitcast and address-space casts don't change the underlying object.
+    // array_to_ptrdecay produces an element pointer to the same storage as
+    // the array pointer, so strip through it too.
+    if (auto castOp = mlir::dyn_cast<cir::CastOp>(defOp)) {
----------------
andykaylor wrote:

I ended up needing to generalize this quite a bit to get the partial alias 
handling to work, so a lot of what I have here will be replaced. My plan is to 
have a follow-up PR that does the reorganization and calculates the offset, but 
still only handles the `MustAlias` cases so the tests will remain the same. I 
had already posted this for review before I came to that conclusion though, and 
I think this version is easier to follow for review purposes. I can just tack 
that commit onto this PR if you'd prefer. It's going to look like a substantial 
replacement of this one either way. So, whatever is easier for review is fine 
with me.

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

Reply via email to