[llvm] r331307 - Create a MachineBasicBlock for created IR-level BasicBlock

Jessica Paquette via llvm-commits llvm-commits at lists.llvm.org
Tue May 1 13:49:42 PDT 2018


Author: paquette
Date: Tue May  1 13:49:42 2018
New Revision: 331307

URL: http://llvm.org/viewvc/llvm-project?rev=331307&view=rev
Log:
Create a MachineBasicBlock for created IR-level BasicBlock

While running the lit tests for the most recent version of D45916
(https://reviews.llvm.org/D45916), I found that a couple tests for this pass
suddenly started segfaulting. Since the outliner wasn't actually doing anything
to the code in either of these tests I got curious.

I found that the pass doesn’t completely create the machine-level constructs
necessary to actually add a MachineFunction and MachineBasicBlock to the
module. This patch adds in those missing bits. After this, adding the
outliner before this pass won’t cause it to segfault.

You can recreate this behaviour by adding the MachineOutliner directly before
the pass and having it return false immediately.

https://reviews.llvm.org/D46330


Modified:
    llvm/trunk/lib/Target/X86/X86RetpolineThunks.cpp

Modified: llvm/trunk/lib/Target/X86/X86RetpolineThunks.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86RetpolineThunks.cpp?rev=331307&r1=331306&r2=331307&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86RetpolineThunks.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86RetpolineThunks.cpp Tue May  1 13:49:42 2018
@@ -214,6 +214,15 @@ void X86RetpolineThunks::createThunkFunc
   IRBuilder<> Builder(Entry);
 
   Builder.CreateRetVoid();
+
+  // MachineFunctions/MachineBasicBlocks aren't created automatically for the
+  // IR-level constructs we already made. Create them and insert them into the
+  // module.
+  MachineFunction &MF = MMI->getOrCreateMachineFunction(*F);
+  MachineBasicBlock *EntryMBB = MF.CreateMachineBasicBlock(Entry);
+
+  // Insert EntryMBB into MF. It's not in the module until we do this.
+  MF.insert(MF.end(), EntryMBB);
 }
 
 void X86RetpolineThunks::insertRegReturnAddrClobber(MachineBasicBlock &MBB,




More information about the llvm-commits mailing list