[clang] 046b064 - [clang][bytecode][NFC] Use FixedPoint opaque int API (#123522)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Jan 19 23:45:03 PST 2025
Author: Timm Baeder
Date: 2025-01-20T08:44:59+01:00
New Revision: 046b064df0ac9d4530e79f11077a768383b1ca16
URL: https://github.com/llvm/llvm-project/commit/046b064df0ac9d4530e79f11077a768383b1ca16
DIFF: https://github.com/llvm/llvm-project/commit/046b064df0ac9d4530e79f11077a768383b1ca16.diff
LOG: [clang][bytecode][NFC] Use FixedPoint opaque int API (#123522)
Now that we have it, use it.
Added:
Modified:
clang/lib/AST/ByteCode/Compiler.cpp
clang/lib/AST/ByteCode/Interp.h
Removed:
################################################################################
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp
index 414323eaa12654..1a0e5ff45587f3 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -689,20 +689,18 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {
if (!this->visit(SubExpr))
return false;
- auto Sem = Ctx.getASTContext().getFixedPointSemantics(CE->getType());
- uint32_t I;
- std::memcpy(&I, &Sem, sizeof(Sem));
- return this->emitCastIntegralFixedPoint(classifyPrim(SubExpr->getType()), I,
- CE);
+ auto Sem =
+ Ctx.getASTContext().getFixedPointSemantics(CE->getType()).toOpaqueInt();
+ return this->emitCastIntegralFixedPoint(classifyPrim(SubExpr->getType()),
+ Sem, CE);
}
case CK_FloatingToFixedPoint: {
if (!this->visit(SubExpr))
return false;
- auto Sem = Ctx.getASTContext().getFixedPointSemantics(CE->getType());
- uint32_t I;
- std::memcpy(&I, &Sem, sizeof(Sem));
- return this->emitCastFloatingFixedPoint(I, CE);
+ auto Sem =
+ Ctx.getASTContext().getFixedPointSemantics(CE->getType()).toOpaqueInt();
+ return this->emitCastFloatingFixedPoint(Sem, CE);
}
case CK_FixedPointToFloating: {
if (!this->visit(SubExpr))
@@ -718,10 +716,9 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {
case CK_FixedPointCast: {
if (!this->visit(SubExpr))
return false;
- auto Sem = Ctx.getASTContext().getFixedPointSemantics(CE->getType());
- uint32_t I;
- std::memcpy(&I, &Sem, sizeof(Sem));
- return this->emitCastFixedPoint(I, CE);
+ auto Sem =
+ Ctx.getASTContext().getFixedPointSemantics(CE->getType()).toOpaqueInt();
+ return this->emitCastFixedPoint(Sem, CE);
}
case CK_ToVoid:
@@ -1522,28 +1519,29 @@ template <class Emitter>
bool Compiler<Emitter>::VisitFixedPointBinOp(const BinaryOperator *E) {
const Expr *LHS = E->getLHS();
const Expr *RHS = E->getRHS();
+ const ASTContext &ASTCtx = Ctx.getASTContext();
assert(LHS->getType()->isFixedPointType() ||
RHS->getType()->isFixedPointType());
- auto LHSSema = Ctx.getASTContext().getFixedPointSemantics(LHS->getType());
- auto RHSSema = Ctx.getASTContext().getFixedPointSemantics(RHS->getType());
+ auto LHSSema = ASTCtx.getFixedPointSemantics(LHS->getType());
+ auto LHSSemaInt = LHSSema.toOpaqueInt();
+ auto RHSSema = ASTCtx.getFixedPointSemantics(RHS->getType());
+ auto RHSSemaInt = RHSSema.toOpaqueInt();
if (!this->visit(LHS))
return false;
if (!LHS->getType()->isFixedPointType()) {
- uint32_t I;
- std::memcpy(&I, &LHSSema, sizeof(llvm::FixedPointSemantics));
- if (!this->emitCastIntegralFixedPoint(classifyPrim(LHS->getType()), I, E))
+ if (!this->emitCastIntegralFixedPoint(classifyPrim(LHS->getType()),
+ LHSSemaInt, E))
return false;
}
if (!this->visit(RHS))
return false;
if (!RHS->getType()->isFixedPointType()) {
- uint32_t I;
- std::memcpy(&I, &RHSSema, sizeof(llvm::FixedPointSemantics));
- if (!this->emitCastIntegralFixedPoint(classifyPrim(RHS->getType()), I, E))
+ if (!this->emitCastIntegralFixedPoint(classifyPrim(RHS->getType()),
+ RHSSemaInt, E))
return false;
}
@@ -1551,13 +1549,10 @@ bool Compiler<Emitter>::VisitFixedPointBinOp(const BinaryOperator *E) {
auto ConvertResult = [&](bool R) -> bool {
if (!R)
return false;
- auto ResultSema = Ctx.getASTContext().getFixedPointSemantics(E->getType());
- auto CommonSema = LHSSema.getCommonSemantics(RHSSema);
- if (ResultSema != CommonSema) {
- uint32_t I;
- std::memcpy(&I, &ResultSema, sizeof(ResultSema));
- return this->emitCastFixedPoint(I, E);
- }
+ auto ResultSema = ASTCtx.getFixedPointSemantics(E->getType()).toOpaqueInt();
+ auto CommonSema = LHSSema.getCommonSemantics(RHSSema).toOpaqueInt();
+ if (ResultSema != CommonSema)
+ return this->emitCastFixedPoint(ResultSema, E);
return true;
};
diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h
index 93a91976a31bf1..58c0256c7d7df8 100644
--- a/clang/lib/AST/ByteCode/Interp.h
+++ b/clang/lib/AST/ByteCode/Interp.h
@@ -2141,9 +2141,8 @@ inline bool CastFP(InterpState &S, CodePtr OpPC, const llvm::fltSemantics *Sem,
}
inline bool CastFixedPoint(InterpState &S, CodePtr OpPC, uint32_t FPS) {
- FixedPointSemantics TargetSemantics(0, 0, false, false, false);
- std::memcpy(&TargetSemantics, &FPS, sizeof(TargetSemantics));
-
+ FixedPointSemantics TargetSemantics =
+ FixedPointSemantics::getFromOpaqueInt(FPS);
const auto &Source = S.Stk.pop<FixedPoint>();
bool Overflow;
@@ -2271,8 +2270,7 @@ static inline bool CastIntegralFixedPoint(InterpState &S, CodePtr OpPC,
uint32_t FPS) {
const T &Int = S.Stk.pop<T>();
- FixedPointSemantics Sem(0, 0, false, false, false);
- std::memcpy(&Sem, &FPS, sizeof(Sem));
+ FixedPointSemantics Sem = FixedPointSemantics::getFromOpaqueInt(FPS);
bool Overflow;
FixedPoint Result = FixedPoint::from(Int.toAPSInt(), Sem, &Overflow);
@@ -2288,8 +2286,7 @@ static inline bool CastFloatingFixedPoint(InterpState &S, CodePtr OpPC,
uint32_t FPS) {
const auto &Float = S.Stk.pop<Floating>();
- FixedPointSemantics Sem(0, 0, false, false, false);
- std::memcpy(&Sem, &FPS, sizeof(Sem));
+ FixedPointSemantics Sem = FixedPointSemantics::getFromOpaqueInt(FPS);
bool Overflow;
FixedPoint Result = FixedPoint::from(Float.getAPFloat(), Sem, &Overflow);
More information about the cfe-commits
mailing list