[clang] [CIR] Update RValue class to reflect changes in classic CodeGen (PR #142779)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 4 07:05:46 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clangir
Author: Morris Hafner (mmha)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/142779.diff
1 Files Affected:
- (modified) clang/lib/CIR/CodeGen/CIRGenValue.h (+70-15)
``````````diff
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;
}
};
``````````
</details>
https://github.com/llvm/llvm-project/pull/142779
More information about the cfe-commits
mailing list