diff options
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Target/X86/X86RetpolineThunks.cpp | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/llvm/lib/Target/X86/X86RetpolineThunks.cpp b/llvm/lib/Target/X86/X86RetpolineThunks.cpp index f62e89eb1ba..08994cccb21 100644 --- a/llvm/lib/Target/X86/X86RetpolineThunks.cpp +++ b/llvm/lib/Target/X86/X86RetpolineThunks.cpp @@ -74,7 +74,7 @@ private: void createThunkFunction(Module &M, StringRef Name); void insertRegReturnAddrClobber(MachineBasicBlock &MBB, unsigned Reg); - void populateThunk(MachineFunction &MF, Optional<unsigned> Reg = None); + void populateThunk(MachineFunction &MF, unsigned Reg); }; } // end anonymous namespace @@ -236,25 +236,33 @@ void X86RetpolineThunks::insertRegReturnAddrClobber(MachineBasicBlock &MBB, } void X86RetpolineThunks::populateThunk(MachineFunction &MF, - Optional<unsigned> Reg) { + unsigned Reg) { // Set MF properties. We never use vregs... MF.getProperties().set(MachineFunctionProperties::Property::NoVRegs); + // Grab the entry MBB and erase any other blocks. O0 codegen appears to + // generate two bbs for the entry block. MachineBasicBlock *Entry = &MF.front(); Entry->clear(); + while (MF.size() > 1) + MF.erase(std::next(MF.begin())); MachineBasicBlock *CaptureSpec = MF.CreateMachineBasicBlock(Entry->getBasicBlock()); MachineBasicBlock *CallTarget = MF.CreateMachineBasicBlock(Entry->getBasicBlock()); + MCSymbol *TargetSym = MF.getContext().createTempSymbol(); MF.push_back(CaptureSpec); MF.push_back(CallTarget); const unsigned CallOpc = Is64Bit ? X86::CALL64pcrel32 : X86::CALLpcrel32; const unsigned RetOpc = Is64Bit ? X86::RETQ : X86::RETL; - BuildMI(Entry, DebugLoc(), TII->get(CallOpc)).addMBB(CallTarget); - Entry->addSuccessor(CallTarget); + Entry->addLiveIn(Reg); + BuildMI(Entry, DebugLoc(), TII->get(CallOpc)).addSym(TargetSym); + + // The MIR verifier thinks that the CALL in the entry block will fall through + // to CaptureSpec, so mark it as the successor. Technically, CaptureTarget is + // the successor, but the MIR verifier doesn't know how to cope with that. Entry->addSuccessor(CaptureSpec); - CallTarget->setHasAddressTaken(); // In the capture loop for speculation, we want to stop the processor from // speculating as fast as possible. On Intel processors, the PAUSE instruction @@ -270,7 +278,10 @@ void X86RetpolineThunks::populateThunk(MachineFunction &MF, CaptureSpec->setHasAddressTaken(); CaptureSpec->addSuccessor(CaptureSpec); + CallTarget->addLiveIn(Reg); + CallTarget->setHasAddressTaken(); CallTarget->setAlignment(4); - insertRegReturnAddrClobber(*CallTarget, *Reg); + insertRegReturnAddrClobber(*CallTarget, Reg); + CallTarget->back().setPreInstrSymbol(MF, TargetSym); BuildMI(CallTarget, DebugLoc(), TII->get(RetOpc)); } |