[llvm] [IPSCCP] Variable not visible at Og. (PR #66745)
Carlos Alberto Enciso via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 12 09:03:37 PDT 2023
================
@@ -3074,6 +3074,44 @@ void llvm::hoistAllInstructionsInto(BasicBlock *DomBlock, Instruction *InsertPt,
BB->getTerminator()->getIterator());
}
+DIExpression *llvm::getExpressionForConstant(DIBuilder &DIB, const Constant &C,
+ Type &Ty) {
+
+ // Create integer constant expression.
+ auto createIntegerExpression = [&DIB](const Constant &CV) -> DIExpression * {
+ const APInt &API = cast<ConstantInt>(&CV)->getValue();
+ std::optional<int64_t> InitIntOpt = API.trySExtValue();
+ return InitIntOpt ? DIB.createConstantValueExpression(
+ static_cast<uint64_t>(*InitIntOpt))
+ : nullptr;
+ };
+
+ if (Ty.isIntegerTy())
+ return createIntegerExpression(C);
+
+ if (Ty.isFloatTy() || Ty.isDoubleTy()) {
+ const APFloat &APF = cast<ConstantFP>(&C)->getValueAPF();
+ return DIB.createConstantValueExpression(
+ APF.bitcastToAPInt().getZExtValue());
+ }
+
+ if (!Ty.isPointerTy())
+ return nullptr;
+
+ if (isa<ConstantPointerNull>(C))
+ return DIB.createConstantValueExpression(0);
+
+ if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(&C)) {
+ if (CE->getNumOperands() == 1) {
----------------
CarlosAlbertoEnciso wrote:
Very good suggestion.
https://github.com/llvm/llvm-project/pull/66745
More information about the llvm-commits
mailing list