llvm.org GIT mirror llvm / ad2afc2
Reapply r77654 with a fix: MachineFunctionPass's getAnalysisUsage shouldn't do AU.setPreservesCFG(), because even though CodeGen passes don't modify the LLVM IR CFG, they may modify the MachineFunction CFG, and passes like MachineLoop are registered with isCFGOnly set to true. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@77691 91177308-0d34-0410-b5e6-96231b3b80d8 Dan Gohman 10 years ago
18 changed file(s) with 192 addition(s) and 139 deletion(s). Raw diff Collapse all Expand all
3333 void getAnalysisUsage(AnalysisUsage &AU) const {
3434 AU.setPreservesAll();
3535 AU.addRequired();
36 MachineFunctionPass::getAnalysisUsage(AU);
3637 }
3738
3839 bool runOnMachineFunction(MachineFunction &mf);
6666 };
6767
6868 class MachineFunction : private Annotation {
69 const Function *Fn;
69 Function *Fn;
7070 const TargetMachine &Target;
7171
7272 // RegInfo - Information about each register in use in the function.
114114 unsigned Alignment;
115115
116116 public:
117 MachineFunction(const Function *Fn, const TargetMachine &TM);
117 MachineFunction(Function *Fn, const TargetMachine &TM);
118118 ~MachineFunction();
119119
120120 /// getFunction - Return the LLVM function that this machine code represents
121121 ///
122 const Function *getFunction() const { return Fn; }
122 Function *getFunction() const { return Fn; }
123123
124124 /// getTarget - Return the target machine this machine code is compiled with
125125 ///
228228 ///
229229 void dump() const;
230230
231 /// construct - Allocate and initialize a MachineFunction for a given Function
232 /// and Target
233 ///
234 static MachineFunction& construct(const Function *F, const TargetMachine &TM);
235
236 /// destruct - Destroy the MachineFunction corresponding to a given Function
237 ///
238 static void destruct(const Function *F);
239
240 /// get - Return a handle to a MachineFunction corresponding to the given
241 /// Function. This should not be called before "construct()" for a given
242 /// Function.
243 ///
244 static MachineFunction& get(const Function *F);
245
246231 // Provide accessors for the MachineBasicBlock list...
247232 typedef BasicBlockListType::iterator iterator;
248233 typedef BasicBlockListType::const_iterator const_iterator;
0 //===-- MachineFunctionAnalysis.h - Owner of MachineFunctions ----*-C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file declares the MachineFunctionAnalysis class.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #ifndef LLVM_CODEGEN_MACHINE_FUNCTION_ANALYSIS_H
14 #define LLVM_CODEGEN_MACHINE_FUNCTION_ANALYSIS_H
15
16 #include "llvm/Pass.h"
17 #include "llvm/Target/TargetMachine.h"
18
19 namespace llvm {
20
21 class MachineFunction;
22
23 /// MachineFunctionAnalysis - This class is a Pass that manages a
24 /// MachineFunction object.
25 struct MachineFunctionAnalysis : public FunctionPass {
26 private:
27 const TargetMachine &TM;
28 CodeGenOpt::Level OptLevel;
29 MachineFunction *MF;
30
31 public:
32 static char ID;
33 explicit MachineFunctionAnalysis(TargetMachine &tm,
34 CodeGenOpt::Level OL = CodeGenOpt::Default);
35
36
37 MachineFunction &getMF() const { return *MF; }
38 CodeGenOpt::Level getOptLevel() const { return OptLevel; }
39
40 private:
41 virtual bool runOnFunction(Function &F);
42 virtual void releaseMemory();
43 virtual void getAnalysisUsage(AnalysisUsage &AU) const;
44 };
45
46 } // End llvm namespace
47
48 #endif
2323
2424 namespace llvm {
2525
26 // FIXME: This pass should declare that the pass does not invalidate any LLVM
27 // passes.
28 struct MachineFunctionPass : public FunctionPass {
26 /// MachineFunctionPass - This class adapts the FunctionPass interface to
27 /// allow convenient creation of passes that operate on the MachineFunction
28 /// representation. Instead of overriding runOnFunction, subclasses
29 /// override runOnMachineFunction.
30 class MachineFunctionPass : public FunctionPass {
31 protected:
2932 explicit MachineFunctionPass(intptr_t ID) : FunctionPass(ID) {}
3033 explicit MachineFunctionPass(void *ID) : FunctionPass(ID) {}
3134
32 protected:
3335 /// runOnMachineFunction - This method must be overloaded to perform the
3436 /// desired machine code transformation or analysis.
3537 ///
3638 virtual bool runOnMachineFunction(MachineFunction &MF) = 0;
3739
38 public:
40 /// getAnalysisUsage - Subclasses that override getAnalysisUsage
41 /// must call this.
42 virtual void getAnalysisUsage(AnalysisUsage &AU) const;
43
44 private:
3945 bool runOnFunction(Function &F);
4046 };
4147
145145 /// by seeing if the labels map to the same reduced label.
146146 FunctionPass *createDebugLabelFoldingPass();
147147
148 /// MachineCodeDeletion Pass - This pass deletes all of the machine code for
149 /// the current function, which should happen after the function has been
150 /// emitted to a .s file or to memory.
151 FunctionPass *createMachineCodeDeleter();
152
153148 /// getRegisterAllocator - This creates an instance of the register allocator
154149 /// for the Sparc.
155150 FunctionPass *getRegisterAllocator(TargetMachine &T);
1818 #include "llvm/Pass.h"
1919 #include "llvm/Constant.h"
2020 #include "llvm/CodeGen/SelectionDAG.h"
21 #include "llvm/CodeGen/MachineFunctionPass.h"
2122
2223 namespace llvm {
2324 class FastISel;
3839
3940 /// SelectionDAGISel - This is the common base class used for SelectionDAG-based
4041 /// pattern-matching instruction selectors.
41 class SelectionDAGISel : public FunctionPass {
42 class SelectionDAGISel : public MachineFunctionPass {
4243 public:
4344 const TargetMachine &TM;
4445 TargetLowering &TLI;
6162
6263 virtual void getAnalysisUsage(AnalysisUsage &AU) const;
6364
64 virtual bool runOnFunction(Function &Fn);
65 virtual bool runOnMachineFunction(MachineFunction &MF);
6566
6667 unsigned MakeReg(MVT VT);
6768
2020 #include "llvm/GlobalValue.h"
2121 #include "llvm/BasicBlock.h"
2222 #include "llvm/Argument.h"
23 #include "llvm/Support/Annotation.h"
2423 #include "llvm/Attributes.h"
2524
2625 namespace llvm {
6564 mutable ilist_node Sentinel;
6665 };
6766
68 class Function : public GlobalValue, public Annotable,
67 class Function : public GlobalValue,
6968 public ilist_node {
7069 public:
7170 typedef iplist ArgumentListType;
1717 #include "llvm/Analysis/LoopPass.h"
1818 #include "llvm/CodeGen/Passes.h"
1919 #include "llvm/CodeGen/GCStrategy.h"
20 #include "llvm/CodeGen/MachineFunctionAnalysis.h"
2021 #include "llvm/Target/TargetOptions.h"
2122 #include "llvm/Target/TargetAsmInfo.h"
2223 #include "llvm/Target/TargetRegistry.h"
117118
118119 PM.add(createGCInfoDeleter());
119120
120 // Delete machine code for this function
121 PM.add(createMachineCodeDeleter());
122
123121 return false; // success!
124122 }
125123
136134
137135 PM.add(createGCInfoDeleter());
138136
139 // Delete machine code for this function
140 PM.add(createMachineCodeDeleter());
141
142137 return false; // success!
143138 }
144139
154149 addAssemblyEmitter(PM, OptLevel, true, ferrs());
155150
156151 PM.add(createGCInfoDeleter());
157
158 // Delete machine code for this function
159 PM.add(createMachineCodeDeleter());
160152
161153 return false; // success!
162154 }
183175
184176 PM.add(createGCInfoDeleter());
185177
186 // Delete machine code for this function
187 PM.add(createMachineCodeDeleter());
188
189178 return false; // success!
190179 }
191180
211200
212201 PM.add(createGCInfoDeleter());
213202
214 // Delete machine code for this function
215 PM.add(createMachineCodeDeleter());
216
217203 return false; // success!
218204 }
219205
264250
265251 // Standard Lower-Level Passes.
266252
253 // Set up a MachineFunction for the rest of CodeGen to work on.
254 PM.add(new MachineFunctionAnalysis(*this, OptLevel));
255
267256 // Enable FastISel with -fast, but allow that to be overridden.
268257 if (EnableFastISelOption == cl::BOU_TRUE ||
269258 (OptLevel == CodeGenOpt::None && EnableFastISelOption != cl::BOU_FALSE))
4747 void LiveVariables::getAnalysisUsage(AnalysisUsage &AU) const {
4848 AU.addRequiredID(UnreachableMachineBlockElimID);
4949 AU.setPreservesAll();
50 MachineFunctionPass::getAnalysisUsage(AU);
5051 }
5152
5253 void LiveVariables::VarInfo::dump() const {
3535 #include
3636 using namespace llvm;
3737
38 bool MachineFunctionPass::runOnFunction(Function &F) {
39 // Do not codegen any 'available_externally' functions at all, they have
40 // definitions outside the translation unit.
41 if (F.hasAvailableExternallyLinkage())
42 return false;
43
44 return runOnMachineFunction(MachineFunction::get(&F));
45 }
46
4738 namespace {
4839 struct VISIBILITY_HIDDEN Printer : public MachineFunctionPass {
4940 static char ID;
5849
5950 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
6051 AU.setPreservesAll();
52 MachineFunctionPass::getAnalysisUsage(AU);
6153 }
6254
6355 bool runOnMachineFunction(MachineFunction &MF) {
7769 return new Printer(OS, Banner);
7870 }
7971
80 namespace {
81 struct VISIBILITY_HIDDEN Deleter : public MachineFunctionPass {
82 static char ID;
83 Deleter() : MachineFunctionPass(&ID) {}
84
85 const char *getPassName() const { return "Machine Code Deleter"; }
86
87 bool runOnMachineFunction(MachineFunction &MF) {
88 // Delete the annotation from the function now.
89 MachineFunction::destruct(MF.getFunction());
90 return true;
91 }
92 };
93 char Deleter::ID = 0;
94 }
95
96 /// MachineCodeDeletion Pass - This pass deletes all of the machine code for
97 /// the current function, which should happen after the function has been
98 /// emitted to a .s file or to memory.
99 FunctionPass *llvm::createMachineCodeDeleter() {
100 return new Deleter();
101 }
102
103
104
10572 //===---------------------------------------------------------------------===//
10673 // MachineFunction implementation
10774 //===---------------------------------------------------------------------===//
11077 MBB->getParent()->DeleteMachineBasicBlock(MBB);
11178 }
11279
113 MachineFunction::MachineFunction(const Function *F,
80 MachineFunction::MachineFunction(Function *F,
11481 const TargetMachine &TM)
11582 : Annotation(AnnotationManager::getID("CodeGen::MachineCodeForFunction")),
11683 Fn(F), Target(TM) {
353320 cerr << "SelectionDAG::viewGraph is only available in debug builds on "
354321 << "systems with Graphviz or gv!\n";
355322 #endif // NDEBUG
356 }
357
358 // The next two methods are used to construct and to retrieve
359 // the MachineCodeForFunction object for the given function.
360 // construct() -- Allocates and initializes for a given function and target
361 // get() -- Returns a handle to the object.
362 // This should not be called before "construct()"
363 // for a given Function.
364 //
365 MachineFunction&
366 MachineFunction::construct(const Function *Fn, const TargetMachine &Tar)
367 {
368 AnnotationID MF_AID =
369 AnnotationManager::getID("CodeGen::MachineCodeForFunction");
370 assert(Fn->getAnnotation(MF_AID) == 0 &&
371 "Object already exists for this function!");
372 MachineFunction* mcInfo = new MachineFunction(Fn, Tar);
373 Fn->addAnnotation(mcInfo);
374 return *mcInfo;
375 }
376
377 void MachineFunction::destruct(const Function *Fn) {
378 AnnotationID MF_AID =
379 AnnotationManager::getID("CodeGen::MachineCodeForFunction");
380 bool Deleted = Fn->deleteAnnotation(MF_AID);
381 assert(Deleted && "Machine code did not exist for function!");
382 Deleted = Deleted; // silence warning when no assertions.
383 }
384
385 MachineFunction& MachineFunction::get(const Function *F)
386 {
387 AnnotationID MF_AID =
388 AnnotationManager::getID("CodeGen::MachineCodeForFunction");
389 MachineFunction *mc = (MachineFunction*)F->getAnnotation(MF_AID);
390 assert(mc && "Call construct() method first to allocate the object");
391 return *mc;
392323 }
393324
394325 /// addLiveIn - Add the specified physical register as a live-in value and
0 //===-- MachineFunctionAnalysis.cpp ---------------------------------------===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file contains the definitions of the MachineFunctionAnalysis members.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #include "llvm/CodeGen/MachineFunctionAnalysis.h"
14 #include "llvm/CodeGen/MachineFunction.h"
15 using namespace llvm;
16
17 // Register this pass with PassInfo directly to avoid having to define
18 // a default constructor.
19 static PassInfo
20 X("Machine Function Analysis", "machine-function-analysis",
21 intptr_t(&MachineFunctionAnalysis::ID), 0,
22 /*CFGOnly=*/false, /*is_analysis=*/true);
23
24 char MachineFunctionAnalysis::ID = 0;
25
26 MachineFunctionAnalysis::MachineFunctionAnalysis(TargetMachine &tm,
27 CodeGenOpt::Level OL) :
28 FunctionPass(&ID), TM(tm), OptLevel(OL), MF(0) {
29 }
30
31 bool MachineFunctionAnalysis::runOnFunction(Function &F) {
32 assert(!MF && "MachineFunctionAnalysis already initialized!");
33 MF = new MachineFunction(&F, TM);
34 return false;
35 }
36
37 void MachineFunctionAnalysis::releaseMemory() {
38 delete MF;
39 MF = 0;
40 }
41
42 void MachineFunctionAnalysis::getAnalysisUsage(AnalysisUsage &AU) const {
43 AU.setPreservesAll();
44 }
0 //===-- MachineFunctionPass.cpp -------------------------------------------===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file contains the definitions of the MachineFunctionPass members.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #include "llvm/Analysis/AliasAnalysis.h"
14 #include "llvm/Analysis/ScalarEvolution.h"
15 #include "llvm/Analysis/IVUsers.h"
16 #include "llvm/Analysis/LiveValues.h"
17 #include "llvm/Analysis/LoopDependenceAnalysis.h"
18 #include "llvm/Analysis/MemoryDependenceAnalysis.h"
19 #include "llvm/CodeGen/MachineFunctionAnalysis.h"
20 #include "llvm/CodeGen/MachineFunctionPass.h"
21 using namespace llvm;
22
23 bool MachineFunctionPass::runOnFunction(Function &F) {
24 // Do not codegen any 'available_externally' functions at all, they have
25 // definitions outside the translation unit.
26 if (F.hasAvailableExternallyLinkage())
27 return false;
28
29 MachineFunction &MF = getAnalysis().getMF();
30 return runOnMachineFunction(MF);
31 }
32
33 void MachineFunctionPass::getAnalysisUsage(AnalysisUsage &AU) const {
34 AU.addRequired();
35 AU.addPreserved();
36
37 // MachineFunctionPass preserves all LLVM IR passes, but there's no
38 // high-level way to express this. Instead, just list a bunch of
39 // passes explicitly.
40 AU.addPreserved();
41 AU.addPreserved();
42 AU.addPreserved();
43 AU.addPreserved();
44 AU.addPreserved();
45 AU.addPreserved();
46 AU.addPreserved();
47 AU.addPreserved();
48 AU.addPreserved();
49
50 FunctionPass::getAnalysisUsage(AU);
51 }
4040 void MachineLoopInfo::getAnalysisUsage(AnalysisUsage &AU) const {
4141 AU.setPreservesAll();
4242 AU.addRequired();
43 MachineFunctionPass::getAnalysisUsage(AU);
4344 }
5454
5555 void getAnalysisUsage(AnalysisUsage &AU) const {
5656 AU.setPreservesAll();
57 MachineFunctionPass::getAnalysisUsage(AU);
5758 }
5859
5960 bool runOnMachineFunction(MachineFunction &MF);
110110
111111 #if 0
112112 void PEI::getAnalysisUsage(AnalysisUsage &AU) const {
113 AU.setPreservesCFG();
114113 if (ShrinkWrapping || ShrinkWrapFunc != "") {
115114 AU.addRequired();
116115 AU.addRequired();
2828 #include "llvm/CodeGen/GCStrategy.h"
2929 #include "llvm/CodeGen/GCMetadata.h"
3030 #include "llvm/CodeGen/MachineFunction.h"
31 #include "llvm/CodeGen/MachineFunctionAnalysis.h"
3132 #include "llvm/CodeGen/MachineFrameInfo.h"
3233 #include "llvm/CodeGen/MachineInstrBuilder.h"
3334 #include "llvm/CodeGen/MachineJumpTableInfo.h"
266267 //===----------------------------------------------------------------------===//
267268
268269 SelectionDAGISel::SelectionDAGISel(TargetMachine &tm, CodeGenOpt::Level OL) :
269 FunctionPass(&ID), TM(tm), TLI(*tm.getTargetLowering()),
270 MachineFunctionPass(&ID), TM(tm), TLI(*tm.getTargetLowering()),
270271 FuncInfo(new FunctionLoweringInfo(TLI)),
271272 CurDAG(new SelectionDAG(TLI, *FuncInfo)),
272273 SDL(new SelectionDAGLowering(*CurDAG, TLI, *FuncInfo, OL)),
290291 AU.addRequired();
291292 AU.addRequired();
292293 AU.setPreservesAll();
293 }
294
295 bool SelectionDAGISel::runOnFunction(Function &Fn) {
294 MachineFunctionPass::getAnalysisUsage(AU);
295 }
296
297 bool SelectionDAGISel::runOnMachineFunction(MachineFunction &mf) {
298 Function &Fn = *mf.getFunction();
299
296300 // Do some sanity-checking on the command-line options.
297301 assert((!EnableFastISelVerbose || EnableFastISel) &&
298302 "-fast-isel-verbose requires -fast-isel");
304308 if (Fn.hasAvailableExternallyLinkage())
305309 return false;
306310
307
308311 // Get alias analysis for load/store combining.
309312 AA = &getAnalysis();
310313
311314 TargetMachine &TM = TLI.getTargetMachine();
312 MF = &MachineFunction::construct(&Fn, TM);
315 MF = &mf;
313316 const TargetInstrInfo &TII = *TM.getInstrInfo();
314317 const TargetRegisterInfo &TRI = *TM.getRegisterInfo();
315318
252252 SPUtli(*tm.getTargetLowering())
253253 { }
254254
255 virtual bool runOnFunction(Function &Fn) {
255 virtual bool runOnMachineFunction(MachineFunction &MF) {
256256 // Make sure we re-emit a set of the global base reg if necessary
257257 GlobalBaseReg = 0;
258 SelectionDAGISel::runOnFunction(Fn);
258 SelectionDAGISel::runOnMachineFunction(MF);
259259 return true;
260260 }
261261
1919 #include "PPCHazardRecognizers.h"
2020 #include "llvm/CodeGen/MachineInstrBuilder.h"
2121 #include "llvm/CodeGen/MachineFunction.h"
22 #include "llvm/CodeGen/MachineFunctionAnalysis.h"
2223 #include "llvm/CodeGen/MachineRegisterInfo.h"
2324 #include "llvm/CodeGen/SelectionDAG.h"
2425 #include "llvm/CodeGen/SelectionDAGISel.h"
5051 PPCLowering(*TM.getTargetLowering()),
5152 PPCSubTarget(*TM.getSubtargetImpl()) {}
5253
53 virtual bool runOnFunction(Function &Fn) {
54 // Do not codegen any 'available_externally' functions at all, they have
55 // definitions outside the translation unit.
56 if (Fn.hasAvailableExternallyLinkage())
57 return false;
58
54 virtual bool runOnMachineFunction(MachineFunction &MF) {
5955 // Make sure we re-emit a set of the global base reg if necessary
6056 GlobalBaseReg = 0;
61 SelectionDAGISel::runOnFunction(Fn);
62
63 InsertVRSaveCode(Fn);
57 SelectionDAGISel::runOnMachineFunction(MF);
58
59 InsertVRSaveCode(MF);
6460 return true;
6561 }
6662
180176 /// SelectionDAGISel when it has created a SelectionDAG for us to codegen.
181177 virtual void InstructionSelect();
182178
183 void InsertVRSaveCode(Function &Fn);
179 void InsertVRSaveCode(MachineFunction &MF);
184180
185181 virtual const char *getPassName() const {
186182 return "PowerPC DAG->DAG Pattern Instruction Selection";
217213 /// InsertVRSaveCode - Once the entire function has been instruction selected,
218214 /// all virtual registers are created and all machine instructions are built,
219215 /// check to see if we need to save/restore VRSAVE. If so, do it.
220 void PPCDAGToDAGISel::InsertVRSaveCode(Function &F) {
216 void PPCDAGToDAGISel::InsertVRSaveCode(MachineFunction &Fn) {
221217 // Check to see if this function uses vector registers, which means we have to
222218 // save and restore the VRSAVE register and update it with the regs we use.
223219 //
224220 // In this case, there will be virtual registers of vector type type created
225221 // by the scheduler. Detect them now.
226 MachineFunction &Fn = MachineFunction::get(&F);
227222 bool HasVectorVReg = false;
228223 for (unsigned i = TargetRegisterInfo::FirstVirtualRegister,
229224 e = RegInfo->getLastVirtReg()+1; i != e; ++i)