- CallInst *resolve = new CallInst(resolverFunc, ResolverArgs,
- "resolver");
- Header->getInstList().push_back(resolve);
- // cast the result from the resolver to correctly-typed function
- CastInst *castResolver =
- new CastInst(resolve, PointerType::get(F->getFunctionType()),
- "resolverCast");
- Header->getInstList().push_back(castResolver);
-
- // Save the argument list
+ CallInst *Resolver =
+ CallInst::Create(resolverFunc, ResolverArgs.begin(),
+ ResolverArgs.end(), "resolver", LookupBB);
+
+ // Cast the result from the resolver to correctly-typed function.
+ CastInst *CastedResolver =
+ new BitCastInst(Resolver,
+ PointerType::getUnqual(F->getFunctionType()),
+ "resolverCast", LookupBB);
+
+ // Save the value in our cache.
+ new StoreInst(CastedResolver, Cache, LookupBB);
+ BranchInst::Create(DoCallBB, LookupBB);
+
+ PHINode *FuncPtr = PHINode::Create(NullPtr->getType(),
+ "fp", DoCallBB);
+ FuncPtr->addIncoming(CastedResolver, LookupBB);
+ FuncPtr->addIncoming(CachedVal, EntryBB);
+
+ // Save the argument list.