llvm.org GIT mirror llvm / 81da02b
Make tail merging the default, except on powerPC. There was no prior art for a target-dependent default with a command-line override; this way should be generally usable. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@37285 91177308-0d34-0410-b5e6-96231b3b80d8 Dale Johannesen 12 years ago
8 changed file(s) with 69 addition(s) and 7 deletion(s). Raw diff Collapse all Expand all
7878 /// optimizations to delete branches to branches, eliminate branches to
7979 /// successor blocks (creating fall throughs), and eliminating branches over
8080 /// branches.
81 FunctionPass *createBranchFoldingPass();
81 FunctionPass *createBranchFoldingPass(bool DefaultEnableTailMerge);
8282
8383 /// IfConverter Pass - This pass performs machine code if conversion.
8484 FunctionPass *createIfConverterPass();
543543
544544 EXTERN_TEMPLATE_INSTANTIATION(class basic_parser);
545545
546 //--------------------------------------------------
547 // parser
548 enum boolOrDefault { BOU_UNSET, BOU_TRUE, BOU_FALSE };
549 template<>
550 class parser : public basic_parser {
551 public:
552 // parse - Return true on error.
553 bool parse(Option &O, const char *ArgName, const std::string &Arg,
554 boolOrDefault &Val);
555
556 enum ValueExpected getValueExpectedFlagDefault() const {
557 return ValueOptional;
558 }
559
560 // getValueName - Do not print = at all.
561 virtual const char *getValueName() const { return 0; }
562
563 // An out-of-line virtual method to provide a 'home' for this class.
564 virtual void anchor();
565 };
566
567 EXTERN_TEMPLATE_INSTANTIATION(class basic_parser);
546568
547569 //--------------------------------------------------
548570 // parser
184184 AssemblyFile, ObjectFile, DynamicLibrary
185185 };
186186
187 /// DoTailMergeDefault - Whether it is generally a good idea to do this
188 /// on this target. User flag overrides.
189 virtual const bool DoTailMergeDefault() const { return true; }
190
187191 /// addPassesToEmitFile - Add passes to the specified pass manager to get the
188192 /// specified file emitted. Typically this will involve several steps of code
189193 /// generation. If Fast is set to true, the code generator should emit code
314318 MachineCodeEmitter &MCE) {
315319 return true;
316320 }
321
322 /// DoTailMergeDefault - Whether it is generally a good idea to do this
323 /// on this target. User flag overrides.
324 virtual const bool DoTailMergeDefault() const { return true; }
317325 };
318326
319327 } // End llvm namespace
3434 STATISTIC(NumDeadBlocks, "Number of dead blocks removed");
3535 STATISTIC(NumBranchOpts, "Number of branches optimized");
3636 STATISTIC(NumTailMerge , "Number of block tails merged");
37 static cl::opt EnableTailMerge("enable-tail-merge", cl::Hidden);
38
37 static cl::opt FlagEnableTailMerge("enable-tail-merge",
38 cl::init(cl::BOU_UNSET), cl::Hidden);
3939 namespace {
4040 struct BranchFolder : public MachineFunctionPass {
4141 static char ID;
42 BranchFolder() : MachineFunctionPass((intptr_t)&ID) {}
42 BranchFolder(bool defaultEnableTailMerge) :
43 MachineFunctionPass((intptr_t)&ID) {
44 switch (FlagEnableTailMerge) {
45 case cl::BOU_UNSET: EnableTailMerge = defaultEnableTailMerge; break;
46 case cl::BOU_TRUE: EnableTailMerge = true; break;
47 case cl::BOU_FALSE: EnableTailMerge = false; break;
48 }
49 }
4350
4451 virtual bool runOnMachineFunction(MachineFunction &MF);
4552 virtual const char *getPassName() const { return "Control Flow Optimizer"; }
4855 bool MadeChange;
4956 private:
5057 // Tail Merging.
58 bool EnableTailMerge;
5159 bool TailMergeBlocks(MachineFunction &MF);
5260 bool TryMergeBlocks(MachineBasicBlock* SuccBB,
5361 MachineBasicBlock* PredBB);
7886 bool isCond,
7987 MachineFunction::iterator FallThru);
8088
81 FunctionPass *llvm::createBranchFoldingPass() { return new BranchFolder(); }
89 FunctionPass *llvm::createBranchFoldingPass(bool DefaultEnableTailMerge) {
90 return new BranchFolder(DefaultEnableTailMerge); }
8291
8392 /// RemoveDeadBlock - Remove the specified dead machine basic block from the
8493 /// function, updating the CFG.
7777
7878 // Branch folding must be run after regalloc and prolog/epilog insertion.
7979 if (!Fast)
80 PM.add(createBranchFoldingPass());
80 PM.add(createBranchFoldingPass(DoTailMergeDefault()));
8181
8282 // Fold redundant debug labels.
8383 PM.add(createDebugLabelFoldingPass());
180180
181181 // Branch folding must be run after regalloc and prolog/epilog insertion.
182182 if (!Fast)
183 PM.add(createBranchFoldingPass());
183 PM.add(createBranchFoldingPass(DoTailMergeDefault()));
184184
185185 if (addPreEmitPass(PM, Fast) && PrintMachineCode)
186186 PM.add(createMachineFunctionPrinterPass(cerr));
3535 // Template instantiations and anchors.
3636 //
3737 TEMPLATE_INSTANTIATION(class basic_parser);
38 TEMPLATE_INSTANTIATION(class basic_parser);
3839 TEMPLATE_INSTANTIATION(class basic_parser);
3940 TEMPLATE_INSTANTIATION(class basic_parser);
4041 TEMPLATE_INSTANTIATION(class basic_parser);
4950 void Option::anchor() {}
5051 void basic_parser_impl::anchor() {}
5152 void parser::anchor() {}
53 void parser::anchor() {}
5254 void parser::anchor() {}
5355 void parser::anchor() {}
5456 void parser::anchor() {}
766768 return false;
767769 }
768770
771 // parser implementation
772 //
773 bool parser::parse(Option &O, const char *ArgName,
774 const std::string &Arg, boolOrDefault &Value) {
775 if (Arg == "" || Arg == "true" || Arg == "TRUE" || Arg == "True" ||
776 Arg == "1") {
777 Value = BOU_TRUE;
778 } else if (Arg == "false" || Arg == "FALSE" || Arg == "False" || Arg == "0") {
779 Value = BOU_FALSE;
780 } else {
781 return O.error(": '" + Arg +
782 "' is invalid value for boolean argument! Try 0 or 1");
783 }
784 return false;
785 }
786
769787 // parser implementation
770788 //
771789 bool parser::parse(Option &O, const char *ArgName,
9595 setRelocationModel(Reloc::Static);
9696 }
9797
98 /// Override this for PowerPC. Tail merging happily breaks up instruction issue
99 /// groups, which typically degrades performance.
100 const bool PPCTargetMachine::DoTailMergeDefault() const { return false; }
101
98102 PPC32TargetMachine::PPC32TargetMachine(const Module &M, const std::string &FS)
99103 : PPCTargetMachine(M, FS, false) {
100104 }
7272 MachineCodeEmitter &MCE);
7373 virtual bool addSimpleCodeEmitter(FunctionPassManager &PM, bool Fast,
7474 MachineCodeEmitter &MCE);
75 virtual const bool DoTailMergeDefault() const;
7576 };
7677
7778 /// PPC32TargetMachine - PowerPC 32-bit target machine.