DbgIntrinsicInst: Downcast to specialized MDNodes in accessors

Change accessors to downcast to `MDLocalVariable` and `MDExpression`,
now that we have -verify checks in place to confirm that it's safe.

llvm-svn: 232299
diff --git a/llvm/include/llvm/IR/IntrinsicInst.h b/llvm/include/llvm/IR/IntrinsicInst.h
index 72ab46d..bf0adc3 100644
--- a/llvm/include/llvm/IR/IntrinsicInst.h
+++ b/llvm/include/llvm/IR/IntrinsicInst.h
@@ -82,8 +82,12 @@
   class DbgDeclareInst : public DbgInfoIntrinsic {
   public:
     Value *getAddress() const;
-    MDNode *getVariable() const { return cast<MDNode>(getRawVariable()); }
-    MDNode *getExpression() const { return cast<MDNode>(getRawExpression()); }
+    MDLocalVariable *getVariable() const {
+      return cast<MDLocalVariable>(getRawVariable());
+    }
+    MDExpression *getExpression() const {
+      return cast<MDExpression>(getRawExpression());
+    }
 
     Metadata *getRawVariable() const {
       return cast<MetadataAsValue>(getArgOperand(1))->getMetadata();
@@ -111,8 +115,12 @@
       return cast<ConstantInt>(
                           const_cast<Value*>(getArgOperand(1)))->getZExtValue();
     }
-    MDNode *getVariable() const { return cast<MDNode>(getRawVariable()); }
-    MDNode *getExpression() const { return cast<MDNode>(getRawExpression()); }
+    MDLocalVariable *getVariable() const {
+      return cast<MDLocalVariable>(getRawVariable());
+    }
+    MDExpression *getExpression() const {
+      return cast<MDExpression>(getRawExpression());
+    }
 
     Metadata *getRawVariable() const {
       return cast<MetadataAsValue>(getArgOperand(2))->getMetadata();
diff --git a/llvm/include/llvm/IR/Metadata.h b/llvm/include/llvm/IR/Metadata.h
index c01cc7c..6ba0fd4 100644
--- a/llvm/include/llvm/IR/Metadata.h
+++ b/llvm/include/llvm/IR/Metadata.h
@@ -128,6 +128,16 @@
 #define HANDLE_METADATA(CLASS) class CLASS;
 #include "llvm/IR/Metadata.def"
 
+// Provide specializations of isa so that we don't need definitions of
+// subclasses to see if the metadata is a subclass.
+#define HANDLE_METADATA_LEAF(CLASS)                                            \
+  template <> struct isa_impl<CLASS, Metadata> {                               \
+    static inline bool doit(const Metadata &MD) {                              \
+      return MD.getMetadataID() == Metadata::CLASS##Kind;                      \
+    }                                                                          \
+  };
+#include "llvm/IR/Metadata.def"
+
 inline raw_ostream &operator<<(raw_ostream &OS, const Metadata &MD) {
   MD.print(OS);
   return OS;
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index f007106..084bfb8 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -3032,8 +3032,8 @@
          DII.getRawExpression());
 
   // Don't call visitMDNode(), since that will recurse through operands.
-  visitMDLocalVariable(*cast<MDLocalVariable>(DII.getVariable()));
-  visitMDExpression(*cast<MDExpression>(DII.getExpression()));
+  visitMDLocalVariable(*DII.getVariable());
+  visitMDExpression(*DII.getExpression());
 }
 
 void DebugInfoVerifier::verifyDebugInfo() {