[RewriteStatepointsForGC] Minor code cleanup [NFC]
authorPhilip Reames <listmail@philipreames.com>
Tue, 21 Jul 2015 00:49:55 +0000 (00:49 +0000)
committerPhilip Reames <listmail@philipreames.com>
Tue, 21 Jul 2015 00:49:55 +0000 (00:49 +0000)
We can use builders to simplify part of the code and we only check for the existance of the metadata value; this enables us to delete some redundant code.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@242751 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/RewriteStatepointsForGC.cpp

index ae2ae3af0c7a046c6f6c5d72e0f20f820a8df72e..c48321586baf652603e5c61eb4de1a7038649606 100644 (file)
@@ -848,14 +848,7 @@ static Value *findBasePointer(Value *I, DefiningValueMapTy &cache) {
       assert(num_preds > 0 && "how did we reach here");
       PHINode *phi = PHINode::Create(v->getType(), num_preds, "base_phi", v);
       // Add metadata marking this as a base value
       assert(num_preds > 0 && "how did we reach here");
       PHINode *phi = PHINode::Create(v->getType(), num_preds, "base_phi", v);
       // Add metadata marking this as a base value
-      auto *const_1 = ConstantInt::get(
-          Type::getInt32Ty(
-              v->getParent()->getParent()->getParent()->getContext()),
-          1);
-      auto MDConst = ConstantAsMetadata::get(const_1);
-      MDNode *md = MDNode::get(
-          v->getParent()->getParent()->getParent()->getContext(), MDConst);
-      phi->setMetadata("is_base_value", md);
+      phi->setMetadata("is_base_value", MDNode::get(v->getContext(), {}));
       states[v] = PhiState(PhiState::Conflict, phi);
     } else {
       SelectInst *sel = cast<SelectInst>(v);
       states[v] = PhiState(PhiState::Conflict, phi);
     } else {
       SelectInst *sel = cast<SelectInst>(v);
@@ -864,14 +857,7 @@ static Value *findBasePointer(Value *I, DefiningValueMapTy &cache) {
       SelectInst *basesel = SelectInst::Create(sel->getCondition(), undef,
                                                undef, "base_select", sel);
       // Add metadata marking this as a base value
       SelectInst *basesel = SelectInst::Create(sel->getCondition(), undef,
                                                undef, "base_select", sel);
       // Add metadata marking this as a base value
-      auto *const_1 = ConstantInt::get(
-          Type::getInt32Ty(
-              v->getParent()->getParent()->getParent()->getContext()),
-          1);
-      auto MDConst = ConstantAsMetadata::get(const_1);
-      MDNode *md = MDNode::get(
-          v->getParent()->getParent()->getParent()->getContext(), MDConst);
-      basesel->setMetadata("is_base_value", md);
+      basesel->setMetadata("is_base_value", MDNode::get(v->getContext(), {}));
       states[v] = PhiState(PhiState::Conflict, basesel);
     }
   }
       states[v] = PhiState(PhiState::Conflict, basesel);
     }
   }
@@ -1198,11 +1184,9 @@ static void CreateGCRelocates(ArrayRef<llvm::Value *> LiveVariables,
 
     // Generate the gc.relocate call and save the result
     Value *BaseIdx =
 
     // Generate the gc.relocate call and save the result
     Value *BaseIdx =
-        ConstantInt::get(Type::getInt32Ty(M->getContext()),
-                         LiveStart + find_index(LiveVariables, BasePtrs[i]));
-    Value *LiveIdx = ConstantInt::get(
-        Type::getInt32Ty(M->getContext()),
-        LiveStart + find_index(LiveVariables, LiveVariables[i]));
+      Builder.getInt32(LiveStart + find_index(LiveVariables, BasePtrs[i]));
+    Value *LiveIdx =
+      Builder.getInt32(LiveStart + find_index(LiveVariables, LiveVariables[i]));
 
     // only specify a debug name if we can give a useful one
     Value *Reloc = Builder.CreateCall(
 
     // only specify a debug name if we can give a useful one
     Value *Reloc = Builder.CreateCall(