[PATCH] D156154: [clang][ConstExprEmitter] handle IntegerLiterals and IntegralCasts

2023-07-24 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers updated this revision to Diff 543662.
nickdesaulniers marked an inline comment as done.
nickdesaulniers added a comment.

- put back the IntegralCast, for now


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156154/new/

https://reviews.llvm.org/D156154

Files:
  clang/lib/CodeGen/CGExprConstant.cpp


Index: clang/lib/CodeGen/CGExprConstant.cpp
===
--- clang/lib/CodeGen/CGExprConstant.cpp
+++ clang/lib/CodeGen/CGExprConstant.cpp
@@ -1215,6 +1215,10 @@
 return Visit(E->getSubExpr(), T);
   }
 
+  llvm::Constant *VisitIntegerLiteral(IntegerLiteral *I, QualType T) {
+return llvm::ConstantInt::get(CGM.getLLVMContext(), I->getValue());
+  }
+
   llvm::Constant *EmitArrayInitialization(InitListExpr *ILE, QualType T) {
 auto *CAT = CGM.getContext().getAsConstantArrayType(ILE->getType());
 assert(CAT && "can't emit array init for non-constant-bound array");


Index: clang/lib/CodeGen/CGExprConstant.cpp
===
--- clang/lib/CodeGen/CGExprConstant.cpp
+++ clang/lib/CodeGen/CGExprConstant.cpp
@@ -1215,6 +1215,10 @@
 return Visit(E->getSubExpr(), T);
   }
 
+  llvm::Constant *VisitIntegerLiteral(IntegerLiteral *I, QualType T) {
+return llvm::ConstantInt::get(CGM.getLLVMContext(), I->getValue());
+  }
+
   llvm::Constant *EmitArrayInitialization(InitListExpr *ILE, QualType T) {
 auto *CAT = CGM.getContext().getAsConstantArrayType(ILE->getType());
 assert(CAT && "can't emit array init for non-constant-bound array");
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D156154: [clang][ConstExprEmitter] handle IntegerLiterals and IntegralCasts

2023-07-24 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added a comment.

In D156154#4529265 , @efriedma wrote:

> As a practical matter, I'm not sure this helps much; ExprConstant should be 
> reasonably fast for simple integers.  The performance issues only really show 
> for structs/arrays.  But maybe it helps a little to handle a few of the most 
> common integer expressions.

Perhaps, but after D151587 , 
`ConstExprEmitter` will be tried first before `ExprConstant::Evaluate` (or 
rather `Evaluate` in ExprConstant.cpp; god, why is that a static function and 
not a method???). So it seems bad if we can't just evaluate the constant then 
and there.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156154/new/

https://reviews.llvm.org/D156154

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


[PATCH] D156154: [clang][ConstExprEmitter] handle IntegerLiterals and IntegralCasts

2023-07-24 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

As a practical matter, I'm not sure this helps much; ExprConstant should be 
reasonably fast for simple integers.  The performance issues only really show 
for structs/arrays.  But maybe it helps a little to handle a few of the most 
common integer expressions.




Comment at: clang/lib/CodeGen/CGExprConstant.cpp:1128
 case CK_ConstructorConversion:
+case CK_IntegralCast:
   return Visit(subExpr, destType);

This doesn't look right; I suspect this will return an integer with the wrong 
width.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156154/new/

https://reviews.llvm.org/D156154

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


[PATCH] D156154: [clang][ConstExprEmitter] handle IntegerLiterals and IntegralCasts

2023-07-24 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers created this revision.
Herald added a project: All.
nickdesaulniers requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Improves the ability of ConstExprEmitter to evaluate constants.

Found by adding asserts to ConstantEmitter::tryEmitPrivate to find cases
where ConstExprEmitter::Visit() fails to resolve (obvious) constants.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D156154

Files:
  clang/lib/CodeGen/CGExprConstant.cpp


Index: clang/lib/CodeGen/CGExprConstant.cpp
===
--- clang/lib/CodeGen/CGExprConstant.cpp
+++ clang/lib/CodeGen/CGExprConstant.cpp
@@ -1125,6 +1125,7 @@
 case CK_NonAtomicToAtomic:
 case CK_NoOp:
 case CK_ConstructorConversion:
+case CK_IntegralCast:
   return Visit(subExpr, destType);
 
 case CK_IntToOCLSampler:
@@ -1184,7 +1185,6 @@
 case CK_PointerToIntegral:
 case CK_PointerToBoolean:
 case CK_NullToPointer:
-case CK_IntegralCast:
 case CK_BooleanToSignedIntegral:
 case CK_IntegralToPointer:
 case CK_IntegralToBoolean:
@@ -1215,6 +1215,10 @@
 return Visit(E->getSubExpr(), T);
   }
 
+  llvm::Constant *VisitIntegerLiteral(IntegerLiteral *I, QualType T) {
+return llvm::ConstantInt::get(CGM.getLLVMContext(), I->getValue());
+  }
+
   llvm::Constant *EmitArrayInitialization(InitListExpr *ILE, QualType T) {
 auto *CAT = CGM.getContext().getAsConstantArrayType(ILE->getType());
 assert(CAT && "can't emit array init for non-constant-bound array");


Index: clang/lib/CodeGen/CGExprConstant.cpp
===
--- clang/lib/CodeGen/CGExprConstant.cpp
+++ clang/lib/CodeGen/CGExprConstant.cpp
@@ -1125,6 +1125,7 @@
 case CK_NonAtomicToAtomic:
 case CK_NoOp:
 case CK_ConstructorConversion:
+case CK_IntegralCast:
   return Visit(subExpr, destType);
 
 case CK_IntToOCLSampler:
@@ -1184,7 +1185,6 @@
 case CK_PointerToIntegral:
 case CK_PointerToBoolean:
 case CK_NullToPointer:
-case CK_IntegralCast:
 case CK_BooleanToSignedIntegral:
 case CK_IntegralToPointer:
 case CK_IntegralToBoolean:
@@ -1215,6 +1215,10 @@
 return Visit(E->getSubExpr(), T);
   }
 
+  llvm::Constant *VisitIntegerLiteral(IntegerLiteral *I, QualType T) {
+return llvm::ConstantInt::get(CGM.getLLVMContext(), I->getValue());
+  }
+
   llvm::Constant *EmitArrayInitialization(InitListExpr *ILE, QualType T) {
 auto *CAT = CGM.getContext().getAsConstantArrayType(ILE->getType());
 assert(CAT && "can't emit array init for non-constant-bound array");
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits