[llvm] r264767 - IR: Add DbgInfoIntrinsic::getVariableLocation

Duncan P. N. Exon Smith via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 29 11:56:03 PDT 2016


Author: dexonsmith
Date: Tue Mar 29 13:56:03 2016
New Revision: 264767

URL: http://llvm.org/viewvc/llvm-project?rev=264767&view=rev
Log:
IR: Add DbgInfoIntrinsic::getVariableLocation

Create a common accessor, DbgInfoIntrinsic::getVariableLocation, which
doesn't care about the type of debug info intrinsic.  Use this to
further unify the implementations of DbgDeclareInst::getAddress and
DbgValueInst::getValue.

Besides being a cleanup, I'm planning to use this to prepare DEBUG
output without having to branch on the concrete type.

Modified:
    llvm/trunk/include/llvm/IR/IntrinsicInst.h
    llvm/trunk/lib/IR/IntrinsicInst.cpp

Modified: llvm/trunk/include/llvm/IR/IntrinsicInst.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/IntrinsicInst.h?rev=264767&r1=264766&r2=264767&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/IntrinsicInst.h (original)
+++ llvm/trunk/include/llvm/IR/IntrinsicInst.h Tue Mar 29 13:56:03 2016
@@ -58,6 +58,10 @@ namespace llvm {
   /// This is the common base class for debug info intrinsics.
   class DbgInfoIntrinsic : public IntrinsicInst {
   public:
+    /// Get the location corresponding to the variable referenced by the debug
+    /// info intrinsic.  Depending on the intrinsic, this could be the
+    /// variable's value or its address.
+    Value *getVariableLocation(bool AllowNullOp = true) const;
 
     // Methods for support type inquiry through isa, cast, and dyn_cast:
     static inline bool classof(const IntrinsicInst *I) {
@@ -78,7 +82,7 @@ namespace llvm {
   /// This represents the llvm.dbg.declare instruction.
   class DbgDeclareInst : public DbgInfoIntrinsic {
   public:
-    Value *getAddress() const;
+    Value *getAddress() const { return getVariableLocation(); }
     DILocalVariable *getVariable() const {
       return cast<DILocalVariable>(getRawVariable());
     }
@@ -105,8 +109,9 @@ namespace llvm {
   /// This represents the llvm.dbg.value instruction.
   class DbgValueInst : public DbgInfoIntrinsic {
   public:
-    const Value *getValue() const;
-    Value *getValue();
+    Value *getValue() const {
+      return getVariableLocation(/* AllowNullOp = */ false);
+    }
     uint64_t getOffset() const {
       return cast<ConstantInt>(
                           const_cast<Value*>(getArgOperand(1)))->getZExtValue();

Modified: llvm/trunk/lib/IR/IntrinsicInst.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/IntrinsicInst.cpp?rev=264767&r1=264766&r2=264767&view=diff
==============================================================================
--- llvm/trunk/lib/IR/IntrinsicInst.cpp (original)
+++ llvm/trunk/lib/IR/IntrinsicInst.cpp Tue Mar 29 13:56:03 2016
@@ -50,7 +50,11 @@ Value *DbgInfoIntrinsic::StripCast(Value
   return dyn_cast<GlobalVariable>(C);
 }
 
-static Value *getValueImpl(Value *Op) {
+Value *DbgInfoIntrinsic::getVariableLocation(bool AllowNullOp) const {
+  Value *Op = getArgOperand(0);
+  if (AllowNullOp && !Op)
+    return nullptr;
+
   auto *MD = cast<MetadataAsValue>(Op)->getMetadata();
   if (auto *V = dyn_cast<ValueAsMetadata>(MD))
     return V->getValue();
@@ -60,27 +64,6 @@ static Value *getValueImpl(Value *Op) {
   return nullptr;
 }
 
-//===----------------------------------------------------------------------===//
-/// DbgDeclareInst - This represents the llvm.dbg.declare instruction.
-///
-
-Value *DbgDeclareInst::getAddress() const {
-  if (!getArgOperand(0))
-    return nullptr;
-
-  return getValueImpl(getArgOperand(0));
-}
-
-//===----------------------------------------------------------------------===//
-/// DbgValueInst - This represents the llvm.dbg.value instruction.
-///
-
-const Value *DbgValueInst::getValue() const {
-  return const_cast<DbgValueInst *>(this)->getValue();
-}
-
-Value *DbgValueInst::getValue() { return getValueImpl(getArgOperand(0)); }
-
 int llvm::Intrinsic::lookupLLVMIntrinsicByName(ArrayRef<const char *> NameTable,
                                                StringRef Name) {
   assert(Name.startswith("llvm."));




More information about the llvm-commits mailing list