- DenseMap<BasicBlock*,unsigned> PadSites;
- unsigned NextCallSiteValue = 1;
- for (SmallVector<InvokeInst*,16>::iterator I = Invokes.begin(),
- E = Invokes.end(); I < E; ++I) {
- unsigned CallSiteValue;
- BasicBlock *LandingPad = (*I)->getSuccessor(1);
- // landing pads can be shared. If we see a landing pad again, we
- // want to make sure to use the same call site index so the dispatch
- // will go to the right place.
- CallSiteValue = PadSites[LandingPad];
- if (!CallSiteValue) {
- CallSiteValue = NextCallSiteValue++;
- PadSites[LandingPad] = CallSiteValue;
- // Add a switch case to our unwind block. The runtime comes back
- // to the dispatcher with the call_site - 1 in the context. Odd,
- // but there it is.
- ConstantInt *SwitchValC =
- ConstantInt::get(Type::getInt32Ty((*I)->getContext()),
- CallSiteValue - 1);
- DispatchSwitch->addCase(SwitchValC, (*I)->getUnwindDest());
- }
- markInvokeCallSite(*I, CallSiteValue, CallSite);
- }
+ for (unsigned i = 0, e = Invokes.size(); i != e; ++i)
+ markInvokeCallSite(Invokes[i], i+1, CallSite, DispatchSwitch);