Drive-by fixes for LandingPad -> EHPad
authorDavid Majnemer <david.majnemer@gmail.com>
Tue, 4 Aug 2015 08:21:40 +0000 (08:21 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Tue, 4 Aug 2015 08:21:40 +0000 (08:21 +0000)
This change was done as an audit and is by inspection.  The new EH
system is still very much a work in progress.  NFC for the landingpad
case.

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

lib/IR/Instructions.cpp
lib/Transforms/IPO/LoopExtractor.cpp
lib/Transforms/Scalar/GVN.cpp
lib/Transforms/Scalar/JumpThreading.cpp
lib/Transforms/Scalar/SCCP.cpp
lib/Transforms/Utils/BreakCriticalEdges.cpp
lib/Transforms/Utils/CodeExtractor.cpp
lib/Transforms/Utils/DemoteRegToStack.cpp
lib/Transforms/Utils/LoopSimplify.cpp

index 701f92eb6ea4d6eaf7b140e99e8f937fc328c8ec..6f267bde14998d4dfc940e1a6fd7e311d6e884fe 100644 (file)
@@ -680,6 +680,7 @@ CleanupReturnInst::CleanupReturnInst(const CleanupReturnInst &CRI)
                          CRI.getNumOperands(),
                      CRI.getNumOperands()) {
   SubclassOptionalData = CRI.SubclassOptionalData;
+  setInstructionSubclassData(CRI.getSubclassDataFromInstruction());
   if (Value *RetVal = CRI.getReturnValue())
     setReturnValue(RetVal);
   if (BasicBlock *UnwindDest = CRI.getUnwindDest())
@@ -749,6 +750,7 @@ CatchEndPadInst::CatchEndPadInst(const CatchEndPadInst &CRI)
                          CRI.getNumOperands(),
                      CRI.getNumOperands()) {
   SubclassOptionalData = CRI.SubclassOptionalData;
+  setInstructionSubclassData(CRI.getSubclassDataFromInstruction());
   if (BasicBlock *UnwindDest = CRI.getUnwindDest())
     setUnwindDest(UnwindDest);
 }
@@ -881,7 +883,7 @@ void CatchPadInst::setSuccessorV(unsigned Idx, BasicBlock *B) {
 //                        TerminatePadInst Implementation
 //===----------------------------------------------------------------------===//
 void TerminatePadInst::init(BasicBlock *BB, ArrayRef<Value *> Args,
-                              const Twine &NameStr) {
+                            const Twine &NameStr) {
   SubclassOptionalData = 0;
   if (BB)
     setInstructionSubclassData(getSubclassDataFromInstruction() | 1);
@@ -897,6 +899,7 @@ TerminatePadInst::TerminatePadInst(const TerminatePadInst &TPI)
                          TPI.getNumOperands(),
                      TPI.getNumOperands()) {
   SubclassOptionalData = TPI.SubclassOptionalData;
+  setInstructionSubclassData(TPI.getSubclassDataFromInstruction());
   std::copy(TPI.op_begin(), TPI.op_end(), op_begin());
 }
 
index 41334ca5b429864e3fa7a6d4695bac1460729a3e..f3d6d764c1365415b3a040be838f6210d23d8c69 100644 (file)
@@ -120,14 +120,14 @@ bool LoopExtractor::runOnLoop(Loop *L, LPPassManager &LPM) {
   }
 
   if (ShouldExtractLoop) {
-    // We must omit landing pads. Landing pads must accompany the invoke
+    // We must omit EH pads. EH pads must accompany the invoke
     // instruction. But this would result in a loop in the extracted
     // function. An infinite cycle occurs when it tries to extract that loop as
     // well.
     SmallVector<BasicBlock*, 8> ExitBlocks;
     L->getExitBlocks(ExitBlocks);
     for (unsigned i = 0, e = ExitBlocks.size(); i != e; ++i)
-      if (ExitBlocks[i]->isLandingPad()) {
+      if (ExitBlocks[i]->isEHPad()) {
         ShouldExtractLoop = false;
         break;
       }
index 351debb59dd525627ab7238db5ffab952271cbda..f0ac76d84b57314ca1ed69b9a3b3b4c217997fc0 100644 (file)
@@ -1553,9 +1553,9 @@ bool GVN::PerformLoadPRE(LoadInst *LI, AvailValInBlkVect &ValuesPerBlock,
         return false;
       }
 
-      if (LoadBB->isLandingPad()) {
+      if (LoadBB->isEHPad()) {
         DEBUG(dbgs()
-              << "COULD NOT PRE LOAD BECAUSE OF LANDING PAD CRITICAL EDGE '"
+              << "COULD NOT PRE LOAD BECAUSE OF AN EH PAD CRITICAL EDGE '"
               << Pred->getName() << "': " << *LI << '\n');
         return false;
       }
@@ -2588,8 +2588,8 @@ bool GVN::performPRE(Function &F) {
     if (CurrentBlock == &F.getEntryBlock())
       continue;
 
-    // Don't perform PRE on a landing pad.
-    if (CurrentBlock->isLandingPad())
+    // Don't perform PRE on an EH pad.
+    if (CurrentBlock->isEHPad())
       continue;
 
     for (BasicBlock::iterator BI = CurrentBlock->begin(),
index e845a7f586bc3160143efb663980efaf7527a0f6..6ad782f5089b4d31b10795285506ca65a7477aa5 100644 (file)
@@ -851,10 +851,10 @@ bool JumpThreading::SimplifyPartiallyRedundantLoad(LoadInst *LI) {
   if (LoadBB->getSinglePredecessor())
     return false;
 
-  // If the load is defined in a landing pad, it can't be partially redundant,
-  // because the edges between the invoke and the landing pad cannot have other
+  // If the load is defined in an EH pad, it can't be partially redundant,
+  // because the edges between the invoke and the EH pad cannot have other
   // instructions between them.
-  if (LoadBB->isLandingPad())
+  if (LoadBB->isEHPad())
     return false;
 
   Value *LoadedPtr = LI->getOperand(0);
index c625b0f3362a19baf552fe3abab8a39efc03e629..84af253d25e9f143aa201be44a5601a59b898367 100644 (file)
@@ -479,6 +479,11 @@ private:
   void visitExtractValueInst(ExtractValueInst &EVI);
   void visitInsertValueInst(InsertValueInst &IVI);
   void visitLandingPadInst(LandingPadInst &I) { markAnythingOverdefined(&I); }
+  void visitCleanupPadInst(CleanupPadInst &CPI) { markAnythingOverdefined(&CPI); }
+  void visitCatchPadInst(CatchPadInst &CPI) {
+    markAnythingOverdefined(&CPI);
+    visitTerminatorInst(CPI);
+  }
 
   // Instructions that cannot be folded away.
   void visitStoreInst     (StoreInst &I);
@@ -1545,7 +1550,7 @@ static void DeleteInstructionInBlock(BasicBlock *BB) {
     Instruction *Inst = --I;
     if (!Inst->use_empty())
       Inst->replaceAllUsesWith(UndefValue::get(Inst->getType()));
-    if (isa<LandingPadInst>(Inst)) {
+    if (Inst->isEHPad()) {
       EndInst = Inst;
       continue;
     }
index 565374c2e2ffa7fce5b8b406ab079508dc72313d..c185dc7260437376e97a720733c2780b8d51fbfe 100644 (file)
@@ -141,9 +141,9 @@ BasicBlock *llvm::SplitCriticalEdge(TerminatorInst *TI, unsigned SuccNum,
   BasicBlock *TIBB = TI->getParent();
   BasicBlock *DestBB = TI->getSuccessor(SuccNum);
 
-  // Splitting the critical edge to a landing pad block is non-trivial. Don't do
+  // Splitting the critical edge to a pad block is non-trivial. Don't do
   // it in this generic function.
-  if (DestBB->isLandingPad()) return nullptr;
+  if (DestBB->isEHPad()) return nullptr;
 
   // Create a new basic block, linking it into the CFG.
   BasicBlock *NewBB = BasicBlock::Create(TI->getContext(),
@@ -318,8 +318,7 @@ BasicBlock *llvm::SplitCriticalEdge(TerminatorInst *TI, unsigned SuccNum,
           LoopPreds.push_back(P);
         }
         if (!LoopPreds.empty()) {
-          assert(!DestBB->isLandingPad() &&
-                 "We don't split edges to landing pads!");
+          assert(!DestBB->isEHPad() && "We don't split edges to EH pads!");
           BasicBlock *NewExitBB = SplitBlockPredecessors(
               DestBB, LoopPreds, "split", DT, LI, Options.PreserveLCSSA);
           if (Options.PreserveLCSSA)
index ab89b41f6788e7271e97b47bce43b49c6a85ff83..896cff1bae9777e7b0337cf6d75c0227fe129da1 100644 (file)
@@ -51,7 +51,7 @@ AggregateArgsOpt("aggregate-extracted-args", cl::Hidden,
 /// \brief Test whether a block is valid for extraction.
 static bool isBlockValidForExtraction(const BasicBlock &BB) {
   // Landing pads must be in the function where they were inserted for cleanup.
-  if (BB.isLandingPad())
+  if (BB.isEHPad())
     return false;
 
   // Don't hoist code containing allocas, invokes, or vastarts.
index 003da58ee79831e6fdec3704f5f2a36876876294..f11b6099939cb8ac3492135ab35cf634d674ca7c 100644 (file)
@@ -91,7 +91,7 @@ AllocaInst *llvm::DemoteRegToStack(Instruction &I, bool VolatileLoads,
   if (!isa<TerminatorInst>(I)) {
     InsertPt = &I;
     ++InsertPt;
-    for (; isa<PHINode>(InsertPt) || isa<LandingPadInst>(InsertPt); ++InsertPt)
+    for (; isa<PHINode>(InsertPt) || InsertPt->isEHPad(); ++InsertPt)
       /* empty */;   // Don't insert before PHI nodes or landingpad instrs.
   } else {
     InvokeInst &II = cast<InvokeInst>(I);
index 1298011e78a9cf1e1fcc9afe304ba4f94e836e7c..ca188f470f5bb93ac18d0d282c4469dbf1a5a049 100644 (file)
@@ -261,9 +261,7 @@ static Loop *separateNestedLoop(Loop *L, BasicBlock *Preheader,
 
   // The header is not a landing pad; preheader insertion should ensure this.
   BasicBlock *Header = L->getHeader();
-  assert(!Header->isLandingPad() && "Can't insert backedge to landing pad");
-  if (!Header->canSplitPredecessors())
-    return nullptr;
+  assert(!Header->isEHPad() && "Can't insert backedge to EH pad");
 
   PHINode *PN = findPHIToPartitionLoops(L, DT, AC);
   if (!PN) return nullptr;  // No known way to partition.
@@ -370,8 +368,8 @@ static BasicBlock *insertUniqueBackedgeBlock(Loop *L, BasicBlock *Preheader,
   if (!Preheader)
     return nullptr;
 
-  // The header is not a landing pad; preheader insertion should ensure this.
-  assert(!Header->isLandingPad() && "Can't insert backedge to landing pad");
+  // The header is not an EH pad; preheader insertion should ensure this.
+  assert(!Header->isEHPad() && "Can't insert backedge to EH pad");
 
   // Figure out which basic blocks contain back-edges to the loop header.
   std::vector<BasicBlock*> BackedgeBlocks;