[llvm] r234257 - Transforms: Stop using DIDescriptor::is*() and auto-casting

Duncan P. N. Exon Smith dexonsmith at apple.com
Mon Apr 6 16:27:01 PDT 2015


Author: dexonsmith
Date: Mon Apr  6 18:27:00 2015
New Revision: 234257

URL: http://llvm.org/viewvc/llvm-project?rev=234257&view=rev
Log:
Transforms: Stop using DIDescriptor::is*() and auto-casting

Same as r234255, but for lib/Analysis and lib/Transforms.

Modified:
    llvm/trunk/lib/Analysis/ModuleDebugInfoPrinter.cpp
    llvm/trunk/lib/Transforms/IPO/StripSymbols.cpp
    llvm/trunk/lib/Transforms/Instrumentation/GCOVProfiling.cpp
    llvm/trunk/lib/Transforms/Scalar/SampleProfile.cpp
    llvm/trunk/lib/Transforms/Utils/CloneFunction.cpp
    llvm/trunk/lib/Transforms/Utils/Local.cpp

Modified: llvm/trunk/lib/Analysis/ModuleDebugInfoPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ModuleDebugInfoPrinter.cpp?rev=234257&r1=234256&r2=234257&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ModuleDebugInfoPrinter.cpp (original)
+++ llvm/trunk/lib/Analysis/ModuleDebugInfoPrinter.cpp Mon Apr  6 18:27:00 2015
@@ -103,8 +103,7 @@ void ModuleDebugInfoPrinter::print(raw_o
     if (!T.getName().empty())
       O << ' ' << T.getName();
     printFile(O, T.getFilename(), T.getDirectory(), T.getLineNumber());
-    if (T.isBasicType()) {
-      DIBasicType BT(T.get());
+    if (DIBasicType BT = dyn_cast<MDBasicType>(T)) {
       O << " ";
       if (const char *Encoding =
               dwarf::AttributeEncodingString(BT.getEncoding()))
@@ -118,8 +117,7 @@ void ModuleDebugInfoPrinter::print(raw_o
       else
         O << "unknown-tag(" << T.getTag() << ")";
     }
-    if (T.isCompositeType()) {
-      DICompositeType CT(T.get());
+    if (DICompositeType CT = dyn_cast<MDCompositeType>(T)) {
       if (auto *S = CT.getIdentifier())
         O << " (identifier: '" << S->getString() << "')";
     }

Modified: llvm/trunk/lib/Transforms/IPO/StripSymbols.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/StripSymbols.cpp?rev=234257&r1=234256&r2=234257&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/StripSymbols.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/StripSymbols.cpp Mon Apr  6 18:27:00 2015
@@ -307,10 +307,10 @@ bool StripDeadDebugInfo::runOnModule(Mod
 
   for (DICompileUnit DIC : F.compile_units()) {
     // Create our live subprogram list.
-    DIArray SPs = DIC.getSubprograms();
+    MDSubprogramArray SPs = DIC->getSubprograms();
     bool SubprogramChange = false;
-    for (unsigned i = 0, e = SPs.getNumElements(); i != e; ++i) {
-      DISubprogram DISP(SPs.getElement(i));
+    for (unsigned i = 0, e = SPs.size(); i != e; ++i) {
+      DISubprogram DISP = SPs[i];
 
       // Make sure we visit each subprogram only once.
       if (!VisitedSet.insert(DISP).second)
@@ -324,10 +324,10 @@ bool StripDeadDebugInfo::runOnModule(Mod
     }
 
     // Create our live global variable list.
-    DIArray GVs = DIC.getGlobalVariables();
+    MDGlobalVariableArray GVs = DIC->getGlobalVariables();
     bool GlobalVariableChange = false;
-    for (unsigned i = 0, e = GVs.getNumElements(); i != e; ++i) {
-      DIGlobalVariable DIG(GVs.getElement(i));
+    for (unsigned i = 0, e = GVs.size(); i != e; ++i) {
+      DIGlobalVariable DIG = GVs[i];
 
       // Make sure we only visit each global variable only once.
       if (!VisitedSet.insert(DIG).second)

Modified: llvm/trunk/lib/Transforms/Instrumentation/GCOVProfiling.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/GCOVProfiling.cpp?rev=234257&r1=234256&r2=234257&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Instrumentation/GCOVProfiling.cpp (original)
+++ llvm/trunk/lib/Transforms/Instrumentation/GCOVProfiling.cpp Mon Apr  6 18:27:00 2015
@@ -487,7 +487,7 @@ void GCOVProfiler::emitProfileNotes() {
     // this pass over the original .o's as they're produced, or run it after
     // LTO, we'll generate the same .gcno files.
 
-    DICompileUnit CU(CU_Nodes->getOperand(i));
+    DICompileUnit CU = cast<MDCompileUnit>(CU_Nodes->getOperand(i));
     std::error_code EC;
     raw_fd_ostream out(mangleName(CU, "gcno"), EC, sys::fs::F_None);
     std::string EdgeDestinations;
@@ -495,9 +495,7 @@ void GCOVProfiler::emitProfileNotes() {
     DIArray SPs = CU.getSubprograms();
     unsigned FunctionIdent = 0;
     for (unsigned i = 0, e = SPs.getNumElements(); i != e; ++i) {
-      DISubprogram SP(SPs.getElement(i));
-      assert((!SP || SP.isSubprogram()) &&
-        "A MDNode in subprograms of a CU should be null or a DISubprogram.");
+      DISubprogram SP = cast_or_null<MDSubprogram>(SPs.getElement(i));
       if (!SP)
         continue;
 
@@ -577,13 +575,11 @@ bool GCOVProfiler::emitProfileArcs() {
   bool Result = false;
   bool InsertIndCounterIncrCode = false;
   for (unsigned i = 0, e = CU_Nodes->getNumOperands(); i != e; ++i) {
-    DICompileUnit CU(CU_Nodes->getOperand(i));
+    DICompileUnit CU = cast<MDCompileUnit>(CU_Nodes->getOperand(i));
     DIArray SPs = CU.getSubprograms();
     SmallVector<std::pair<GlobalVariable *, MDNode *>, 8> CountersBySP;
     for (unsigned i = 0, e = SPs.getNumElements(); i != e; ++i) {
-      DISubprogram SP(SPs.getElement(i));
-      assert((!SP || SP.isSubprogram()) &&
-        "A MDNode in subprograms of a CU should be null or a DISubprogram.");
+      DISubprogram SP = cast_or_null<MDSubprogram>(SPs.getElement(i));
       if (!SP)
         continue;
       Function *F = SP.getFunction();
@@ -859,7 +855,7 @@ Function *GCOVProfiler::insertCounterWri
   NamedMDNode *CU_Nodes = M->getNamedMetadata("llvm.dbg.cu");
   if (CU_Nodes) {
     for (unsigned i = 0, e = CU_Nodes->getNumOperands(); i != e; ++i) {
-      DICompileUnit CU(CU_Nodes->getOperand(i));
+      DICompileUnit CU = cast<MDCompileUnit>(CU_Nodes->getOperand(i));
       std::string FilenameGcda = mangleName(CU, "gcda");
       uint32_t CfgChecksum = FileChecksums.empty() ? 0 : FileChecksums[i];
       Builder.CreateCall3(StartFile,
@@ -867,7 +863,7 @@ Function *GCOVProfiler::insertCounterWri
                           Builder.CreateGlobalStringPtr(ReversedVersion),
                           Builder.getInt32(CfgChecksum));
       for (unsigned j = 0, e = CountersBySP.size(); j != e; ++j) {
-        DISubprogram SP(CountersBySP[j].second);
+        DISubprogram SP = cast_or_null<MDSubprogram>(CountersBySP[j].second);
         uint32_t FuncChecksum = Funcs.empty() ? 0 : Funcs[j]->getFuncChecksum();
         Builder.CreateCall5(
             EmitFunction, Builder.getInt32(j),

Modified: llvm/trunk/lib/Transforms/Scalar/SampleProfile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/SampleProfile.cpp?rev=234257&r1=234256&r2=234257&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/SampleProfile.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/SampleProfile.cpp Mon Apr  6 18:27:00 2015
@@ -642,8 +642,7 @@ void SampleProfileLoader::propagateWeigh
 /// \returns the line number where \p F is defined. If it returns 0,
 ///          it means that there is no debug information available for \p F.
 unsigned SampleProfileLoader::getFunctionLoc(Function &F) {
-  DISubprogram S = getDISubprogram(&F);
-  if (S.isSubprogram())
+  if (DISubprogram S = getDISubprogram(&F))
     return S.getLineNumber();
 
   // If could not find the start of \p F, emit a diagnostic to inform the user

Modified: llvm/trunk/lib/Transforms/Utils/CloneFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/CloneFunction.cpp?rev=234257&r1=234256&r2=234257&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/CloneFunction.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/CloneFunction.cpp Mon Apr  6 18:27:00 2015
@@ -186,7 +186,8 @@ static void CloneDebugInfoMetadata(Funct
   // Ensure that OldFunc appears in the map.
   // (if it's already there it must point to NewFunc anyway)
   VMap[OldFunc] = NewFunc;
-  DISubprogram NewSubprogram(MapMetadata(OldSubprogramMDNode, VMap));
+  DISubprogram NewSubprogram =
+      cast<MDSubprogram>(MapMetadata(OldSubprogramMDNode, VMap));
 
   for (DICompileUnit CU : Finder.compile_units()) {
     DIArray Subprograms(CU.getSubprograms());

Modified: llvm/trunk/lib/Transforms/Utils/Local.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/Local.cpp?rev=234257&r1=234256&r2=234257&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/Local.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/Local.cpp Mon Apr  6 18:27:00 2015
@@ -998,10 +998,8 @@ static bool LdStHasDebugValue(DIVariable
 /// that has an associated llvm.dbg.decl intrinsic.
 bool llvm::ConvertDebugDeclareToDebugValue(DbgDeclareInst *DDI,
                                            StoreInst *SI, DIBuilder &Builder) {
-  DIVariable DIVar(DDI->getVariable());
-  DIExpression DIExpr(DDI->getExpression());
-  assert((!DIVar || DIVar.isVariable()) &&
-         "Variable in DbgDeclareInst should be either null or a DIVariable.");
+  DIVariable DIVar = DDI->getVariable();
+  DIExpression DIExpr = DDI->getExpression();
   if (!DIVar)
     return false;
 
@@ -1029,10 +1027,8 @@ bool llvm::ConvertDebugDeclareToDebugVal
 /// that has an associated llvm.dbg.decl intrinsic.
 bool llvm::ConvertDebugDeclareToDebugValue(DbgDeclareInst *DDI,
                                            LoadInst *LI, DIBuilder &Builder) {
-  DIVariable DIVar(DDI->getVariable());
-  DIExpression DIExpr(DDI->getExpression());
-  assert((!DIVar || DIVar.isVariable()) &&
-         "Variable in DbgDeclareInst should be either null or a DIVariable.");
+  DIVariable DIVar = DDI->getVariable();
+  DIExpression DIExpr = DDI->getExpression();
   if (!DIVar)
     return false;
 
@@ -1112,10 +1108,8 @@ bool llvm::replaceDbgDeclareForAlloca(Al
   if (!DDI)
     return false;
   DebugLoc Loc = DDI->getDebugLoc();
-  DIVariable DIVar(DDI->getVariable());
-  DIExpression DIExpr(DDI->getExpression());
-  assert((!DIVar || DIVar.isVariable()) &&
-         "Variable in DbgDeclareInst should be either null or a DIVariable.");
+  DIVariable DIVar = DDI->getVariable();
+  DIExpression DIExpr = DDI->getExpression();
   if (!DIVar)
     return false;
 





More information about the llvm-commits mailing list