add a SelectionDAG method to check if no common bits are set in two nodes; NFCI
[oota-llvm.git] / lib / Target / X86 / X86WinEHState.cpp
index ed909c58e9b2d1d0e5c1a50c93672f7b2fea56e1..db717385da62ced19e3ba09e2cef806391db76ba 100644 (file)
@@ -71,7 +71,6 @@ private:
   void addStateStoresToFunclet(Value *ParentRegNode, WinEHFuncInfo &FuncInfo,
                                Function &F, int BaseState);
   void insertStateNumberStore(Value *ParentRegNode, Instruction *IP, int State);
-  void insertRestoreFrame(BasicBlock *BB);
 
   Value *emitEHLSDA(IRBuilder<> &Builder, Function *F);
 
@@ -149,13 +148,6 @@ void WinEHStatePass::getAnalysisUsage(AnalysisUsage &AU) const {
 }
 
 bool WinEHStatePass::runOnFunction(Function &F) {
-  // If this is an outlined handler, don't do anything. We'll do state insertion
-  // for it in the parent.
-  StringRef WinEHParentName =
-      F.getFnAttribute("wineh-parent").getValueAsString();
-  if (WinEHParentName != F.getName() && !WinEHParentName.empty())
-    return false;
-
   // Check the personality. Do nothing if this personality doesn't use funclets.
   if (!F.hasPersonalityFn())
     return false;
@@ -169,17 +161,15 @@ bool WinEHStatePass::runOnFunction(Function &F) {
 
   // Skip this function if there are no EH pads and we aren't using IR-level
   // outlining.
-  if (WinEHParentName.empty()) {
-    bool HasPads = false;
-    for (BasicBlock &BB : F) {
-      if (BB.isEHPad()) {
-        HasPads = true;
-        break;
-      }
+  bool HasPads = false;
+  for (BasicBlock &BB : F) {
+    if (BB.isEHPad()) {
+      HasPads = true;
+      break;
     }
-    if (!HasPads)
-      return false;
   }
+  if (!HasPads)
+    return false;
 
   // Disable frame pointer elimination in this function.
   // FIXME: Do the nested handlers need to keep the parent ebp in ebp, or can we
@@ -298,7 +288,7 @@ void WinEHStatePass::emitExceptionRegistrationRecord(Function *F) {
     Builder.CreateStore(SP, Builder.CreateStructGEP(RegNodeTy, RegNode, 0));
     // TryLevel = -1
     StateFieldIndex = 2;
-    insertStateNumberStore(RegNode, Builder.GetInsertPoint(), -1);
+    insertStateNumberStore(RegNode, &*Builder.GetInsertPoint(), -1);
     // Handler = __ehhandler$F
     Function *Trampoline = generateLSDAInEAXThunk(F);
     Link = Builder.CreateStructGEP(RegNodeTy, RegNode, 1);
@@ -315,7 +305,7 @@ void WinEHStatePass::emitExceptionRegistrationRecord(Function *F) {
     Builder.CreateStore(SP, Builder.CreateStructGEP(RegNodeTy, RegNode, 0));
     // TryLevel = -2 / -1
     StateFieldIndex = 4;
-    insertStateNumberStore(RegNode, Builder.GetInsertPoint(),
+    insertStateNumberStore(RegNode, &*Builder.GetInsertPoint(),
                            UseStackGuard ? -2 : -1);
     // ScopeTable = llvm.x86.seh.lsda(F)
     Value *FI8 = Builder.CreateBitCast(F, Int8PtrType);
@@ -384,7 +374,7 @@ Function *WinEHStatePass::generateLSDAInEAXThunk(Function *ParentFunc) {
   Value *CastPersonality =
       Builder.CreateBitCast(PersonalityFn, TargetFuncTy->getPointerTo());
   auto AI = Trampoline->arg_begin();
-  Value *Args[5] = {LSDA, AI++, AI++, AI++, AI++};
+  Value *Args[5] = {LSDA, &*AI++, &*AI++, &*AI++, &*AI++};
   CallInst *Call = Builder.CreateCall(CastPersonality, Args);
   // Can't use musttail due to prototype mismatch, but we can use tail.
   Call->setTailCall(true);
@@ -477,21 +467,13 @@ int WinEHStatePass::escapeRegNode(Function &F) {
   Instruction *InsertPt = EscapeCall;
   if (!EscapeCall)
     InsertPt = F.getEntryBlock().getTerminator();
-  IRBuilder<> Builder(&F.getEntryBlock(), InsertPt);
+  IRBuilder<> Builder(InsertPt);
   Builder.CreateCall(FrameEscape, Args);
   if (EscapeCall)
     EscapeCall->eraseFromParent();
   return Args.size() - 1;
 }
 
-void WinEHStatePass::insertRestoreFrame(BasicBlock *BB) {
-  Instruction *Start = BB->getFirstInsertionPt();
-  if (match(Start, m_Intrinsic<Intrinsic::x86_seh_restoreframe>()))
-    return;
-  IRBuilder<> Builder(Start);
-  Builder.CreateCall(RestoreFrame, {});
-}
-
 void WinEHStatePass::addStateStoresToFunclet(Value *ParentRegNode,
                                              WinEHFuncInfo &FuncInfo,
                                              Function &F, int BaseState) {