-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[CIR][NFCI] Update RValue class to reflect changes in classic CodeGen #142779
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This changes clang::CIRGen::RValue to look like current clang::CodeGen::RValue which was changed in 84780a. This should be NFC and is preliminary work for upstreaming builtin function call support.
@llvm/pr-subscribers-clangir Author: Morris Hafner (mmha) ChangesThis changes clang::CIRGen::RValue to look like current clang::CodeGen::RValue which was changed in 84780a/#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:
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;
}
};
|
@llvm/pr-subscribers-clang Author: Morris Hafner (mmha) ChangesThis changes clang::CIRGen::RValue to look like current clang::CodeGen::RValue which was changed in 84780a/#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:
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;
}
};
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Tagging @AmrDeveloper for awareness of the complex value support added here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This changes clang::CIRGen::RValue to look like current clang::CodeGen::RValue which was changed in 84780a/#86923. This should be NFC and is preliminary work for upstreaming builtin function call support.