Author: Morris Hafner
Date: 2025-06-05T11:06:09+02:00
New Revision: af82e50a77a2474d2ed5f209f3e29a2510fa9552

URL: 
https://github.com/llvm/llvm-project/commit/af82e50a77a2474d2ed5f209f3e29a2510fa9552
DIFF: 
https://github.com/llvm/llvm-project/commit/af82e50a77a2474d2ed5f209f3e29a2510fa9552.diff

LOG: [CIR][NFCI] Update RValue class to reflect changes in classic CodeGen 
(#142779)

This changes clang::CIRGen::RValue to look like current
clang::CodeGen::RValue which was changed in
84780a/[#86923](https://github.com/llvm/llvm-project/issues/86923). This
should be NFC and is preliminary work for upstreaming builtin function
call support.

Added: 
    

Modified: 
    clang/lib/CIR/CodeGen/CIRGenValue.h

Removed: 
    


################################################################################
diff  --git a/clang/lib/CIR/CodeGen/CIRGenValue.h 
b/clang/lib/CIR/CodeGen/CIRGenValue.h
index 56177c948df94..208247e16e531 100644
--- a/clang/lib/CIR/CodeGen/CIRGenValue.h
+++ b/clang/lib/CIR/CodeGen/CIRGenValue.h
@@ -19,8 +19,6 @@
 #include "clang/AST/CharUnits.h"
 #include "clang/AST/Type.h"
 
-#include "llvm/ADT/PointerIntPair.h"
-
 #include "mlir/IR/Value.h"
 
 #include "clang/CIR/MissingFeatures.h"
@@ -34,28 +32,85 @@ namespace clang::CIRGen {
 class RValue {
   enum Flavor { Scalar, Complex, Aggregate };
 
-  // Stores first value and flavor.
-  llvm::PointerIntPair<mlir::Value, 2, Flavor> v1;
-  // Stores second value and volatility.
-  llvm::PointerIntPair<llvm::PointerUnion<mlir::Value, int *>, 1, bool> v2;
-  // Stores element type for aggregate values.
-  mlir::Type elementType;
+  union {
+    // Stores first and second value.
+    struct {
+      mlir::Value first;
+      mlir::Value second;
+    } vals;
+
+    // Stores aggregate address.
+    Address aggregateAddr;
+  };
+
+  unsigned isVolatile : 1;
+  unsigned flavor : 2;
 
 public:
-  bool isScalar() const { return v1.getInt() == Scalar; }
-  bool isAggregate() const { return v1.getInt() == Aggregate; }
+  RValue() : vals{nullptr, nullptr}, flavor(Scalar) {}
+
+  bool isScalar() const { return flavor == Scalar; }
+  bool isComplex() const { return flavor == Complex; }
+  bool isAggregate() const { return flavor == Aggregate; }
+
+  bool isVolatileQualified() const { return isVolatile; }
 
-  /// Return the mlir::Value of this scalar value.
+  /// Return the value of this scalar value.
   mlir::Value getScalarVal() const {
     assert(isScalar() && "Not a scalar!");
-    return v1.getPointer();
+    return vals.first;
+  }
+
+  /// Return the real/imag components of this complex value.
+  std::pair<mlir::Value, mlir::Value> getComplexVal() const {
+    return std::make_pair(vals.first, vals.second);
+  }
+
+  /// Return the value of the address of the aggregate.
+  Address getAggregateAddress() const {
+    assert(isAggregate() && "Not an aggregate!");
+    return aggregateAddr;
+  }
+
+  mlir::Value getAggregatePointer(QualType pointeeType) const {
+    return getAggregateAddress().getPointer();
+  }
+
+  static RValue getIgnored() {
+    // FIXME: should we make this a more explicit state?
+    return get(nullptr);
   }
 
   static RValue get(mlir::Value v) {
     RValue er;
-    er.v1.setPointer(v);
-    er.v1.setInt(Scalar);
-    er.v2.setInt(false);
+    er.vals.first = v;
+    er.flavor = Scalar;
+    er.isVolatile = false;
+    return er;
+  }
+
+  static RValue getComplex(mlir::Value v1, mlir::Value v2) {
+    RValue er;
+    er.vals = {v1, v2};
+    er.flavor = Complex;
+    er.isVolatile = false;
+    return er;
+  }
+  static RValue getComplex(const std::pair<mlir::Value, mlir::Value> &c) {
+    return getComplex(c.first, c.second);
+  }
+  // FIXME: Aggregate rvalues need to retain information about whether they are
+  // volatile or not.  Remove default to find all places that probably get this
+  // wrong.
+
+  /// Convert an Address to an RValue. If the Address is not
+  /// signed, create an RValue using the unsigned address. Otherwise, resign 
the
+  /// address using the provided type.
+  static RValue getAggregate(Address addr, bool isVolatile = false) {
+    RValue er;
+    er.aggregateAddr = addr;
+    er.flavor = Aggregate;
+    er.isVolatile = isVolatile;
     return er;
   }
 };


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to