[llvm] 3889ff8 - [DebugInfo] Refactor DIExpression [SZ]Ext creation into function [NFC]

David Stenberg via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 21 01:45:24 PST 2019


Author: David Stenberg
Date: 2019-11-21T10:44:04+01:00
New Revision: 3889ff82bf4057ead22dad91a89384ac20ebd557

URL: https://github.com/llvm/llvm-project/commit/3889ff82bf4057ead22dad91a89384ac20ebd557
DIFF: https://github.com/llvm/llvm-project/commit/3889ff82bf4057ead22dad91a89384ac20ebd557.diff

LOG: [DebugInfo] Refactor DIExpression [SZ]Ext creation into function [NFC]

Summary:
Also, replace the SmallVector with a normal C array.

Reviewers: vsk

Reviewed By: vsk

Subscribers: hiraditya, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D70498

Added: 
    

Modified: 
    llvm/include/llvm/IR/DebugInfoMetadata.h
    llvm/lib/IR/DebugInfoMetadata.cpp
    llvm/lib/Transforms/Utils/Local.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/IR/DebugInfoMetadata.h b/llvm/include/llvm/IR/DebugInfoMetadata.h
index e1a7b8629c42..0e43a05b318e 100644
--- a/llvm/include/llvm/IR/DebugInfoMetadata.h
+++ b/llvm/include/llvm/IR/DebugInfoMetadata.h
@@ -2551,6 +2551,11 @@ class DIExpression : public MDNode {
       return 0;
   }
 
+  /// Append a zero- or sign-extension to \p Expr. Converts the expression to a
+  /// stack value if it isn't one already.
+  static DIExpression *appendExt(const DIExpression *Expr, unsigned FromSize,
+                                 unsigned ToSize, bool Signed);
+
   /// Check if fragments overlap between a pair of FragmentInfos.
   static bool fragmentsOverlap(const FragmentInfo &A, const FragmentInfo &B) {
     return fragmentCmp(A, B) == 0;

diff  --git a/llvm/lib/IR/DebugInfoMetadata.cpp b/llvm/lib/IR/DebugInfoMetadata.cpp
index 8ccd85598237..e4036ee1eb0c 100644
--- a/llvm/lib/IR/DebugInfoMetadata.cpp
+++ b/llvm/lib/IR/DebugInfoMetadata.cpp
@@ -1189,6 +1189,15 @@ bool DIExpression::isConstant() const {
   return true;
 }
 
+DIExpression *DIExpression::appendExt(const DIExpression *Expr,
+                                      unsigned FromSize, unsigned ToSize,
+                                      bool Signed) {
+  dwarf::TypeKind TK = Signed ? dwarf::DW_ATE_signed : dwarf::DW_ATE_unsigned;
+  uint64_t Ops[] = {dwarf::DW_OP_LLVM_convert, FromSize, TK,
+                    dwarf::DW_OP_LLVM_convert, ToSize,   TK};
+  return appendToStack(Expr, Ops);
+}
+
 DIGlobalVariableExpression *
 DIGlobalVariableExpression::getImpl(LLVMContext &Context, Metadata *Variable,
                                     Metadata *Expression, StorageType Storage,

diff  --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp
index d5ae13ad2856..aa1341eea056 100644
--- a/llvm/lib/Transforms/Utils/Local.cpp
+++ b/llvm/lib/Transforms/Utils/Local.cpp
@@ -1867,10 +1867,8 @@ bool llvm::replaceAllDbgUsesWith(Instruction &From, Value &To,
         return None;
 
       bool Signed = *Signedness == DIBasicType::Signedness::Signed;
-      dwarf::TypeKind TK = Signed ? dwarf::DW_ATE_signed : dwarf::DW_ATE_unsigned;
-      SmallVector<uint64_t, 8> Ops({dwarf::DW_OP_LLVM_convert, ToBits, TK,
-                                   dwarf::DW_OP_LLVM_convert, FromBits, TK});
-      return DIExpression::appendToStack(DII.getExpression(), Ops);
+      return DIExpression::appendExt(DII.getExpression(), ToBits, FromBits,
+                                     Signed);
     };
     return rewriteDebugUsers(From, To, DomPoint, DT, SignOrZeroExt);
   }


        


More information about the llvm-commits mailing list