llvm.org GIT mirror llvm / 6e1b812
Add an insertPass API to TargetPassConfig. <rdar://problem/11498613> Besides adding the new insertPass function, this patch uses it to enhance the existing -print-machineinstrs so that the MachineInstrs after a specific pass can be printed. Patch by Bin Zeng! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@157655 91177308-0d34-0410-b5e6-96231b3b80d8 Bob Wilson 8 years ago
7 changed file(s) with 70 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
100100 /// point where StadardID is expected, add TargetID in its place.
101101 void substitutePass(char &StandardID, char &TargetID);
102102
103 /// Insert InsertedPassID pass after TargetPassID pass.
104 void insertPass(const char &TargetPassID, const char &InsertedPassID);
105
103106 /// Allow the target to enable a specific standard pass by default.
104107 void enablePass(char &ID) { substitutePass(ID, ID); }
105108
341344 /// branches.
342345 extern char &BranchFolderPassID;
343346
347 /// MachineFunctionPrinterPass - This pass prints out MachineInstr's.
348 extern char &MachineFunctionPrinterPassID;
349
344350 /// TailDuplicate - Duplicate blocks with unconditional branches
345351 /// into tails of their predecessors.
346352 extern char &TailDuplicateID;
251251 void initializeUnpackMachineBundlesPass(PassRegistry&);
252252 void initializeFinalizeMachineBundlesPass(PassRegistry&);
253253 void initializeBBVectorizePass(PassRegistry&);
254 void initializeMachineFunctionPrinterPassPass(PassRegistry&);
254255 }
255256
256257 #endif
6565 initializeUnreachableMachineBlockElimPass(Registry);
6666 initializeVirtRegMapPass(Registry);
6767 initializeLowerIntrinsicsPass(Registry);
68 initializeMachineFunctionPrinterPassPass(Registry);
6869 }
6970
7071 void LLVMInitializeCodeGen(LLVMPassRegistryRef R) {
1414 #include "llvm/CodeGen/MachineFunctionPass.h"
1515 #include "llvm/CodeGen/MachineFunction.h"
1616 #include "llvm/Support/raw_ostream.h"
17 #include "llvm/Support/Debug.h"
1718
1819 using namespace llvm;
1920
2728 raw_ostream &OS;
2829 const std::string Banner;
2930
31 MachineFunctionPrinterPass() : MachineFunctionPass(ID), OS(dbgs()) { }
3032 MachineFunctionPrinterPass(raw_ostream &os, const std::string &banner)
3133 : MachineFunctionPass(ID), OS(os), Banner(banner) {}
3234
4749 char MachineFunctionPrinterPass::ID = 0;
4850 }
4951
52 char &MachineFunctionPrinterPassID = MachineFunctionPrinterPass::ID;
53 INITIALIZE_PASS(MachineFunctionPrinterPass, "print-machineinstrs",
54 "Machine Function Printer", false, false)
55
5056 namespace llvm {
5157 /// Returns a newly-created MachineFunction Printer pass. The
5258 /// default banner is empty.
7979 static cl::opt VerifyMachineCode("verify-machineinstrs", cl::Hidden,
8080 cl::desc("Verify generated machine code"),
8181 cl::init(getenv("LLVM_VERIFY_MACHINEINSTRS")!=NULL));
82 static cl::opt
83 PrintMachineInstrs("print-machineinstrs", cl::ValueOptional,
84 cl::desc("Print machine instrs"),
85 cl::value_desc("pass-name"), cl::init("option-unspecified"));
8286
8387 /// Allow standard passes to be disabled by command line options. This supports
8488 /// simple binary flags that either suppress the pass or do nothing.
195199 // default by substituting NoPass, and the user may still enable that standard
196200 // pass with an explicit command line option.
197201 DenseMap TargetPasses;
202
203 /// Store the pairs of of which the second pass
204 /// is inserted after each instance of the first one.
205 SmallVector, 4> InsertedPasses;
198206 };
199207 } // namespace llvm
200208
224232 substitutePass(MachineSchedulerID, NoPassID);
225233 }
226234
235 /// Insert InsertedPassID pass after TargetPassID.
236 void TargetPassConfig::insertPass(const char &TargetPassID,
237 const char &InsertedPassID) {
238 assert(&TargetPassID != &InsertedPassID && "Insert a pass after itself!");
239 std::pair P(&TargetPassID, &InsertedPassID);
240 Impl->InsertedPasses.push_back(P);
241 }
242
227243 /// createPassConfig - Create a pass configuration object to be used by
228244 /// addPassToEmitX methods for generating a pipeline of CodeGen passes.
229245 ///
269285 if (!P)
270286 llvm_unreachable("Pass ID not registered");
271287 PM->add(P);
288 // Add the passes after the pass P if there is any.
289 for (SmallVector, 4>::iterator
290 I = Impl->InsertedPasses.begin(), E = Impl->InsertedPasses.end();
291 I != E; ++I) {
292 if ((*I).first == &ID) {
293 assert((*I).second && "Illegal Pass ID!");
294 Pass *NP = Pass::createPass((*I).second);
295 assert(NP && "Pass ID not registered");
296 PM->add(NP);
297 }
298 }
272299 return FinalID;
273300 }
274301
350377 void TargetPassConfig::addMachinePasses() {
351378 // Print the instruction selected machine code...
352379 printAndVerify("After Instruction Selection");
380
381 // Insert a machine instr printer pass after the specified pass.
382 // If -print-machineinstrs specified, print machineinstrs after all passes.
383 if (StringRef(PrintMachineInstrs.getValue()).equals(""))
384 TM->Options.PrintMachineCode = true;
385 else if (!StringRef(PrintMachineInstrs.getValue())
386 .equals("option-unspecified")) {
387 const PassRegistry *PR = PassRegistry::getPassRegistry();
388 const PassInfo *TPI = PR->getPassInfo(PrintMachineInstrs.getValue());
389 const PassInfo *IPI = PR->getPassInfo(StringRef("print-machineinstrs"));
390 assert (TPI && IPI && "Pass ID not registered!");
391 const char *TID = (char *)(TPI->getTypeInfo());
392 const char *IID = (char *)(IPI->getTypeInfo());
393 insertPass(*TID, *IID);
394 }
353395
354396 // Expand pseudo-instructions emitted by ISel.
355397 addPass(ExpandISelPseudosID);
0 ; RUN: llc < %s -O3 -debug-pass=Structure -print-machineinstrs=branch-folder -o /dev/null |& FileCheck %s
1 ; RUN: llc < %s -O3 -debug-pass=Structure -print-machineinstrs -o /dev/null |& FileCheck %s
2 ; RUN: llc < %s -O3 -debug-pass=Structure -print-machineinstrs= -o /dev/null |& FileCheck %s
3
4 define i64 @foo(i64 %a, i64 %b) nounwind {
5 ; CHECK: -branch-folder -print-machineinstrs
6 ; CHECK: Control Flow Optimizer
7 ; CHECK-NEXT: MachineFunction Printer
8 ; CHECK: Machine code for function foo:
9 %c = add i64 %a, %b
10 %d = trunc i64 %c to i32
11 %e = zext i32 %d to i64
12 ret i64 %e
13 }
145145 cl::init(false));
146146
147147 static cl::opt
148 PrintCode("print-machineinstrs",
149 cl::desc("Print generated machine code"),
150 cl::init(false));
151
152 static cl::opt
153148 DisableFPElim("disable-fp-elim",
154149 cl::desc("Disable frame pointer elimination optimization"),
155150 cl::init(false));
402397
403398 TargetOptions Options;
404399 Options.LessPreciseFPMADOption = EnableFPMAD;
405 Options.PrintMachineCode = PrintCode;
406400 Options.NoFramePointerElim = DisableFPElim;
407401 Options.NoFramePointerElimNonLeaf = DisableFPElimNonLeaf;
408402 Options.NoExcessFPPrecision = DisableExcessPrecision;