llvm.org GIT mirror llvm / 5e108ee
Added TargetPassConfig::disablePass/substitutePass as a general mechanism to override specific passes. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@150562 91177308-0d34-0410-b5e6-96231b3b80d8 Andrew Trick 8 years ago
5 changed file(s) with 70 addition(s) and 17 deletion(s). Raw diff Collapse all Expand all
3232
3333 extern char &NoPassID; // Allow targets to choose not to run a pass.
3434
35 class PassConfigImpl;
36
3537 /// Target-Independent Code Generator Pass Configuration Options.
3638 ///
3739 /// This is an ImmutablePass solely for the purpose of exposing CodeGen options
4042 protected:
4143 TargetMachine *TM;
4244 PassManagerBase ±
43 bool Initialized; // Flagged after all passes are configured.
45 PassConfigImpl *Impl; // Internal data structures
46 bool Initialized; // Flagged after all passes are configured.
4447
4548 // Target Pass Options
4649 // Targets provide a default setting, user flags override.
6871 return TM->getTargetLowering();
6972 }
7073
74 //
7175 void setInitialized() { Initialized = true; }
7276
7377 CodeGenOpt::Level getOptLevel() const { return TM->getOptLevel(); }
7680
7781 bool getEnableTailMerge() const { return EnableTailMerge; }
7882 void setEnableTailMerge(bool Enable) { setOpt(EnableTailMerge, Enable); }
83
84 /// Allow the target to override a specific pass without overriding the pass
85 /// pipeline. When passes are added to the standard pipeline at the
86 /// point where StadardID is expected, add TargetID in its place.
87 void substitutePass(char &StandardID, char &TargetID);
88
89 /// Allow the target to disable a specific standard pass.
90 void disablePass(char &ID) { substitutePass(ID, NoPassID); }
91
92 /// Return the pass ssubtituted for StandardID by the target.
93 /// If no substitution exists, return StandardID.
94 AnalysisID getPassSubstitution(AnalysisID StandardID) const;
7995
8096 /// Return true if the optimized regalloc pipeline is enabled.
8197 bool getOptimizeRegAlloc() const;
186202 /// Utilities for targets to add passes to the pass manager.
187203 ///
188204
189 /// Add a target-independent CodeGen pass at this point in the pipeline.
190 void addPass(char &ID);
205 /// Add a CodeGen pass at this point in the pipeline after checking overrides.
206 /// Return the pass that was added, or NoPassID.
207 AnalysisID addPass(char &ID);
191208
192209 /// addMachinePasses helper to create the target-selected or overriden
193210 /// regalloc pass.
176176
177177 // createPass - Create a object for the specified pass class,
178178 // or null if it is not known.
179 static Pass *createPass(char &TI);
179 static Pass *createPass(AnalysisID ID);
180180
181181 /// getAnalysisIfAvailable() - Subclasses use this function to
182182 /// get analysis information that might be around, for example to update it.
114114 static char NoPassIDAnchor = 0;
115115 char &llvm::NoPassID = NoPassIDAnchor;
116116
117 namespace llvm {
118 class PassConfigImpl {
119 public:
120 // List of passes explicitly substituted by this target. Normally this is
121 // empty, but it is a convenient way to suppress or replace specific passes
122 // that are part of a standard pass pipeline without overridding the entire
123 // pipeline. This mechanism allows target options to inherit a standard pass's
124 // user interface. For example, a target may disable a standard pass by
125 // default by substituting NoPass, and the user may still enable that standard
126 // pass with an explicit command line option.
127 DenseMap TargetPasses;
128 };
129 } // namespace llvm
130
117131 // Out of line virtual method.
118 TargetPassConfig::~TargetPassConfig() {}
132 TargetPassConfig::~TargetPassConfig() {
133 delete Impl;
134 }
119135
120136 // Out of line constructor provides default values for pass options and
121137 // registers all common codegen passes.
122138 TargetPassConfig::TargetPassConfig(TargetMachine *tm, PassManagerBase &pm)
123 : ImmutablePass(ID), TM(tm), PM(pm), Initialized(false),
139 : ImmutablePass(ID), TM(tm), PM(pm), Impl(0), Initialized(false),
124140 DisableVerify(false),
125141 EnableTailMerge(true) {
142
143 Impl = new PassConfigImpl();
126144
127145 // Register all target independent codegen passes to activate their PassIDs,
128146 // including this pass itself.
148166 Opt = Val;
149167 }
150168
151 void TargetPassConfig::addPass(char &ID) {
152 if (&ID == &NoPassID)
153 return;
154
169 void TargetPassConfig::substitutePass(char &StandardID, char &TargetID) {
170 Impl->TargetPasses[&StandardID] = &TargetID;
171 }
172
173 AnalysisID TargetPassConfig::getPassSubstitution(AnalysisID ID) const {
174 DenseMap::const_iterator
175 I = Impl->TargetPasses.find(ID);
176 if (I == Impl->TargetPasses.end())
177 return ID;
178 return I->second;
179 }
180
181 /// Add a CodeGen pass at this point in the pipeline after checking for target
182 /// and command line overrides.
183 AnalysisID TargetPassConfig::addPass(char &ID) {
184 assert(!Initialized && "PassConfig is immutable");
185
186 AnalysisID FinalID = getPassSubstitution(&ID);
155187 // FIXME: check user overrides
156 Pass *P = Pass::createPass(ID);
188 if (FinalID == &NoPassID)
189 return FinalID;
190
191 Pass *P = Pass::createPass(FinalID);
157192 if (!P)
158193 llvm_unreachable("Pass ID not registered");
159194 PM.add(P);
195 return FinalID;
160196 }
161197
162198 void TargetPassConfig::printNoVerify(const char *Banner) const {
150150
151151 /// Add passes that optimize machine instructions after register allocation.
152152 void PTXPassConfig::addMachineLateOptimization() {
153 addPass(BranchFolderPassID);
154 printNoVerify("After BranchFolding");
153 if (addPass(BranchFolderPassID) != &NoPassID)
154 printNoVerify("After BranchFolding");
155155
156 addPass(TailDuplicateID);
157 printNoVerify("After TailDuplicate");
156 if (addPass(TailDuplicateID) != &NoPassID)
157 printNoVerify("After TailDuplicate");
158158 }
159159
160160 bool PTXPassConfig::addPreEmitPass() {
188188 return PassRegistry::getPassRegistry()->getPassInfo(Arg);
189189 }
190190
191 Pass *Pass::createPass(char &TI) {
192 const PassInfo *PI = PassRegistry::getPassRegistry()->getPassInfo(&TI);
191 Pass *Pass::createPass(AnalysisID ID) {
192 const PassInfo *PI = PassRegistry::getPassRegistry()->getPassInfo(ID);
193193 if (!PI)
194194 return NULL;
195195 return PI->createPass();