[WinEH] Cache declarations of frame intrinsics
authorReid Kleckner <reid@kleckner.net>
Mon, 8 Jun 2015 22:43:32 +0000 (22:43 +0000)
committerReid Kleckner <reid@kleckner.net>
Mon, 8 Jun 2015 22:43:32 +0000 (22:43 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@239361 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/X86/X86WinEHState.cpp

index 0dbdab89682fad2562573fe4daea75d381d170a7..ce69ea721993ffd30a608d7263a7ab7fe31ea95c 100644 (file)
@@ -83,6 +83,9 @@ private:
   StructType *EHLinkRegistrationTy = nullptr;
   StructType *CXXEHRegistrationTy = nullptr;
   StructType *SEHRegistrationTy = nullptr;
+  Function *FrameRecover = nullptr;
+  Function *FrameAddress = nullptr;
+  Function *FrameEscape = nullptr;
 
   // Per-function state
   EHPersonality Personality = EHPersonality::Unknown;
@@ -109,6 +112,9 @@ char WinEHStatePass::ID = 0;
 
 bool WinEHStatePass::doInitialization(Module &M) {
   TheModule = &M;
+  FrameEscape = Intrinsic::getDeclaration(TheModule, Intrinsic::frameescape);
+  FrameRecover = Intrinsic::getDeclaration(TheModule, Intrinsic::framerecover);
+  FrameAddress = Intrinsic::getDeclaration(TheModule, Intrinsic::frameaddress);
   return false;
 }
 
@@ -118,6 +124,9 @@ bool WinEHStatePass::doFinalization(Module &M) {
   EHLinkRegistrationTy = nullptr;
   CXXEHRegistrationTy = nullptr;
   SEHRegistrationTy = nullptr;
+  FrameEscape = nullptr;
+  FrameRecover = nullptr;
+  FrameAddress = nullptr;
   return false;
 }
 
@@ -392,10 +401,6 @@ void WinEHStatePass::addCXXStateStores(Function &F, MachineModuleInfo &MMI) {
   int RegNodeEscapeIndex = escapeRegNode(F);
 
   // Only insert stores in catch handlers.
-  Function *FrameRecover =
-      Intrinsic::getDeclaration(TheModule, Intrinsic::framerecover);
-  Function *FrameAddress =
-      Intrinsic::getDeclaration(TheModule, Intrinsic::frameaddress);
   Constant *FI8 =
       ConstantExpr::getBitCast(&F, Type::getInt8PtrTy(TheModule->getContext()));
   for (auto P : FuncInfo.HandlerBaseState) {
@@ -437,8 +442,7 @@ int WinEHStatePass::escapeRegNode(Function &F) {
   // of the entry block.
   IRBuilder<> Builder(&F.getEntryBlock(),
                       EscapeCall ? EscapeCall : F.getEntryBlock().end());
-  Builder.CreateCall(
-      Intrinsic::getDeclaration(TheModule, Intrinsic::frameescape), Args);
+  Builder.CreateCall(FrameEscape, Args);
   if (EscapeCall)
     EscapeCall->eraseFromParent();
   return Args.size() - 1;