llvm.org GIT mirror llvm / 046ca04
[Analysis] Fix some Clang-tidy modernize-use-using and Include What You Use warnings; other minor fixes. Also affected in files (NFC). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@312289 91177308-0d34-0410-b5e6-96231b3b80d8 Eugene Zelenko 2 years ago
11 changed file(s) with 356 addition(s) and 183 deletion(s). Raw diff Collapse all Expand all
8888 #ifndef LLVM_ANALYSIS_CGSCCPASSMANAGER_H
8989 #define LLVM_ANALYSIS_CGSCCPASSMANAGER_H
9090
91 #include "llvm/ADT/DenseSet.h"
9192 #include "llvm/ADT/PriorityWorklist.h"
93 #include "llvm/ADT/STLExtras.h"
94 #include "llvm/ADT/SmallPtrSet.h"
95 #include "llvm/ADT/SmallVector.h"
9296 #include "llvm/Analysis/LazyCallGraph.h"
9397 #include "llvm/IR/CallSite.h"
98 #include "llvm/IR/Function.h"
9499 #include "llvm/IR/InstIterator.h"
95100 #include "llvm/IR/PassManager.h"
96101 #include "llvm/IR/ValueHandle.h"
102 #include "llvm/Support/Debug.h"
103 #include "llvm/Support/raw_ostream.h"
104 #include
105 #include
106 #include
97107
98108 namespace llvm {
109
110 struct CGSCCUpdateResult;
111 class Module;
99112
100113 // Allow debug logging in this inline function.
101114 #define DEBUG_TYPE "cgscc"
102115
103 struct CGSCCUpdateResult;
104
105116 /// Extern template declaration for the analysis set for this IR unit.
106117 extern template class AllAnalysesOn;
107118
108119 extern template class AnalysisManager;
120
109121 /// \brief The CGSCC analysis manager.
110122 ///
111123 /// See the documentation for the AnalysisManager template for detail
112 /// documentation. This typedef serves as a convenient way to refer to this
124 /// documentation. This type serves as a convenient way to refer to this
113125 /// construct in the adaptors and proxies used to integrate this into the larger
114126 /// pass manager infrastructure.
115 typedef AnalysisManager
116 CGSCCAnalysisManager;
127 using CGSCCAnalysisManager =
128 AnalysisManager;
117129
118130 // Explicit specialization and instantiation declarations for the pass manager.
119131 // See the comments on the definition of the specialization for details on how
131143 ///
132144 /// See the documentation for the PassManager template for details. It runs
133145 /// a sequence of SCC passes over each SCC that the manager is run over. This
134 /// typedef serves as a convenient way to refer to this construct.
135 typedef PassManager
136 CGSCCUpdateResult &>
137 CGSCCPassManager;
146 /// type serves as a convenient way to refer to this construct.
147 using CGSCCPassManager =
148 PassManager
149 CGSCCUpdateResult &>;
138150
139151 /// An explicit specialization of the require analysis template pass.
140152 template
151163 };
152164
153165 /// A proxy from a \c CGSCCAnalysisManager to a \c Module.
154 typedef InnerAnalysisManagerProxy
155 CGSCCAnalysisManagerModuleProxy;
166 using CGSCCAnalysisManagerModuleProxy =
167 InnerAnalysisManagerProxy;
156168
157169 /// We need a specialized result for the \c CGSCCAnalysisManagerModuleProxy so
158170 /// it can have access to the call graph in order to walk all the SCCs when
195207
196208 extern template class OuterAnalysisManagerProxy<
197209 ModuleAnalysisManager, LazyCallGraph::SCC, LazyCallGraph &>;
210
198211 /// A proxy from a \c ModuleAnalysisManager to an \c SCC.
199 typedef OuterAnalysisManagerProxy
200 LazyCallGraph &>
201 ModuleAnalysisManagerCGSCCProxy;
212 using ModuleAnalysisManagerCGSCCProxy =
213 OuterAnalysisManagerProxy
214 LazyCallGraph &>;
202215
203216 /// Support structure for SCC passes to communicate updates the call graph back
204217 /// to the CGSCC pass manager infrsatructure.
303316 public:
304317 explicit ModuleToPostOrderCGSCCPassAdaptor(CGSCCPassT Pass)
305318 : Pass(std::move(Pass)) {}
319
306320 // We have to explicitly define all the special member functions because MSVC
307321 // refuses to generate them.
308322 ModuleToPostOrderCGSCCPassAdaptor(
309323 const ModuleToPostOrderCGSCCPassAdaptor &Arg)
310324 : Pass(Arg.Pass) {}
325
311326 ModuleToPostOrderCGSCCPassAdaptor(ModuleToPostOrderCGSCCPassAdaptor &&Arg)
312327 : Pass(std::move(Arg.Pass)) {}
328
313329 friend void swap(ModuleToPostOrderCGSCCPassAdaptor &LHS,
314330 ModuleToPostOrderCGSCCPassAdaptor &RHS) {
315 using std::swap;
316 swap(LHS.Pass, RHS.Pass);
331 std::swap(LHS.Pass, RHS.Pass);
317332 }
333
318334 ModuleToPostOrderCGSCCPassAdaptor &
319335 operator=(ModuleToPostOrderCGSCCPassAdaptor RHS) {
320336 swap(*this, RHS);
382398
383399 // Push the initial SCCs in reverse post-order as we'll pop off the the
384400 // back and so see this in post-order.
385 for (LazyCallGraph::SCC &C : reverse(*RC))
401 for (LazyCallGraph::SCC &C : llvm::reverse(*RC))
386402 CWorklist.insert(&C);
387403
388404 do {
504520
505521 private:
506522 friend AnalysisInfoMixin;
523
507524 static AnalysisKey Key;
508525 };
509526
510527 extern template class OuterAnalysisManagerProxy;
528
511529 /// A proxy from a \c CGSCCAnalysisManager to a \c Function.
512 typedef OuterAnalysisManagerProxy
513 CGSCCAnalysisManagerFunctionProxy;
530 using CGSCCAnalysisManagerFunctionProxy =
531 OuterAnalysisManagerProxy;
514532
515533 /// Helper to update the call graph after running a function pass.
516534 ///
536554 public:
537555 explicit CGSCCToFunctionPassAdaptor(FunctionPassT Pass)
538556 : Pass(std::move(Pass)) {}
557
539558 // We have to explicitly define all the special member functions because MSVC
540559 // refuses to generate them.
541560 CGSCCToFunctionPassAdaptor(const CGSCCToFunctionPassAdaptor &Arg)
542561 : Pass(Arg.Pass) {}
562
543563 CGSCCToFunctionPassAdaptor(CGSCCToFunctionPassAdaptor &&Arg)
544564 : Pass(std::move(Arg.Pass)) {}
565
545566 friend void swap(CGSCCToFunctionPassAdaptor &LHS,
546567 CGSCCToFunctionPassAdaptor &RHS) {
547 using std::swap;
548 swap(LHS.Pass, RHS.Pass);
568 std::swap(LHS.Pass, RHS.Pass);
549569 }
570
550571 CGSCCToFunctionPassAdaptor &operator=(CGSCCToFunctionPassAdaptor RHS) {
551572 swap(*this, RHS);
552573 return *this;
732753 // so iterate to process this devirtualization site.
733754 return true;
734755 };
735 bool Devirt = any_of(CallHandles, IsDevirtualizedHandle);
756 bool Devirt = llvm::any_of(CallHandles, IsDevirtualizedHandle);
736757
737758 // Rescan to build up a new set of handles and count how many direct
738759 // calls remain. If we decide to iterate, this also sets up the input to
801822
802823 // Clear out the debug logging macro.
803824 #undef DEBUG_TYPE
804 }
805
806 #endif
825
826 } // end namespace llvm
827
828 #endif // LLVM_ANALYSIS_CGSCCPASSMANAGER_H
2020 #ifndef LLVM_ANALYSIS_CALLGRAPHSCCPASS_H
2121 #define LLVM_ANALYSIS_CALLGRAPHSCCPASS_H
2222
23 #include "llvm/Analysis/CallGraph.h"
23 #include "llvm/ADT/ArrayRef.h"
2424 #include "llvm/Pass.h"
25 #include "llvm/PassSupport.h"
25 #include
2626
2727 namespace llvm {
2828
29 class CallGraph;
2930 class CallGraphNode;
30 class CallGraph;
31 class CallGraphSCC;
3132 class PMStack;
32 class CallGraphSCC;
3333
3434 class CallGraphSCCPass : public Pass {
3535 public:
3737
3838 /// createPrinterPass - Get a pass that prints the Module
3939 /// corresponding to a CallGraph.
40 Pass *createPrinterPass(raw_ostream &O,
40 Pass *createPrinterPass(raw_ostream &OS,
4141 const std::string &Banner) const override;
4242
4343 using llvm::Pass::doInitialization;
5656 ///
5757 /// SCC passes that add or delete functions to the SCC are required to update
5858 /// the SCC list, otherwise stale pointers may be dereferenced.
59 ///
6059 virtual bool runOnSCC(CallGraphSCC &SCC) = 0;
6160
6261 /// doFinalization - This method is called after the SCC's of the program has
8887 class CallGraphSCC {
8988 const CallGraph &CG; // The call graph for this SCC.
9089 void *Context; // The CGPassManager object that is vending this.
91 std::vector*> Nodes;
90 std::vector *> Nodes;
9291
9392 public:
9493 CallGraphSCC(CallGraph &cg, void *context) : CG(cg), Context(context) {}
104103 /// Old node has been deleted, and New is to be used in its place.
105104 void ReplaceNode(CallGraphNode *Old, CallGraphNode *New);
106105
107 typedef std::vector::const_iterator iterator;
106 using iterator = std::vector::const_iterator;
107
108108 iterator begin() const { return Nodes.begin(); }
109109 iterator end() const { return Nodes.end(); }
110110
118118 class DummyCGSCCPass : public CallGraphSCCPass {
119119 public:
120120 static char ID;
121
121122 DummyCGSCCPass() : CallGraphSCCPass(ID) {
122123 PassRegistry &Registry = *PassRegistry::getPassRegistry();
123124 initializeDummyCGSCCPassPass(Registry);
124 };
125 }
126
125127 bool runOnSCC(CallGraphSCC &SCC) override { return false; }
128
126129 void getAnalysisUsage(AnalysisUsage &AU) const override {
127130 AU.setPreservesAll();
128131 }
129132 };
130133
131 } // End llvm namespace
134 } // end namespace llvm
132135
133 #endif
136 #endif // LLVM_ANALYSIS_CALLGRAPHSCCPASS_H
77 //===----------------------------------------------------------------------===//
88
99 #include "llvm/Analysis/CGSCCPassManager.h"
10 #include "llvm/ADT/ArrayRef.h"
11 #include "llvm/ADT/Optional.h"
12 #include "llvm/ADT/STLExtras.h"
13 #include "llvm/ADT/SetVector.h"
14 #include "llvm/ADT/SmallPtrSet.h"
15 #include "llvm/ADT/SmallVector.h"
16 #include "llvm/ADT/iterator_range.h"
17 #include "llvm/Analysis/LazyCallGraph.h"
1018 #include "llvm/IR/CallSite.h"
19 #include "llvm/IR/Constant.h"
1120 #include "llvm/IR/InstIterator.h"
21 #include "llvm/IR/Instruction.h"
22 #include "llvm/IR/PassManager.h"
23 #include "llvm/Support/Casting.h"
24 #include "llvm/Support/Debug.h"
25 #include "llvm/Support/raw_ostream.h"
26 #include
27 #include
28 #include
1229
1330 #define DEBUG_TYPE "cgscc"
1431
261278 return false;
262279 }
263280
264 } // End llvm namespace
281 } // end namespace llvm
265282
266283 /// When a new SCC is created for the graph and there might be function
267284 /// analysis results cached for the functions now in that SCC two forms of
308325 }
309326 }
310327
311 namespace {
312328 /// Helper function to update both the \c CGSCCAnalysisManager \p AM and the \c
313329 /// CGSCCPassManager's \c CGSCCUpdateResult \p UR based on a range of newly
314330 /// added SCCs.
320336 /// This function returns the SCC containing \p N. This will be either \p C if
321337 /// no new SCCs have been split out, or it will be the new SCC containing \p N.
322338 template
323 LazyCallGraph::SCC *
339 static LazyCallGraph::SCC *
324340 incorporateNewSCCRange(const SCCRangeT &NewSCCRange, LazyCallGraph &G,
325341 LazyCallGraph::Node &N, LazyCallGraph::SCC *C,
326342 CGSCCAnalysisManager &AM, CGSCCUpdateResult &UR) {
327 typedef LazyCallGraph::SCC SCC;
343 using SCC = LazyCallGraph::SCC;
328344
329345 if (NewSCCRange.begin() == NewSCCRange.end())
330346 return C;
362378 if (NeedFAMProxy)
363379 updateNewSCCFunctionAnalyses(*C, G, AM);
364380
365 for (SCC &NewC :
366 reverse(make_range(std::next(NewSCCRange.begin()), NewSCCRange.end()))) {
381 for (SCC &NewC : llvm::reverse(make_range(std::next(NewSCCRange.begin()),
382 NewSCCRange.end()))) {
367383 assert(C != &NewC && "No need to re-visit the current SCC!");
368384 assert(OldC != &NewC && "Already handled the original SCC!");
369385 UR.CWorklist.insert(&NewC);
379395 }
380396 return C;
381397 }
382 }
383398
384399 LazyCallGraph::SCC &llvm::updateCGAndAnalysisManagerForFunctionPass(
385400 LazyCallGraph &G, LazyCallGraph::SCC &InitialC, LazyCallGraph::Node &N,
386401 CGSCCAnalysisManager &AM, CGSCCUpdateResult &UR) {
387 typedef LazyCallGraph::Node Node;
388 typedef LazyCallGraph::Edge Edge;
389 typedef LazyCallGraph::SCC SCC;
390 typedef LazyCallGraph::RefSCC RefSCC;
402 using Node = LazyCallGraph::Node;
403 using Edge = LazyCallGraph::Edge;
404 using SCC = LazyCallGraph::SCC;
405 using RefSCC = LazyCallGraph::RefSCC;
391406
392407 RefSCC &InitialRC = InitialC.getOuterRefSCC();
393408 SCC *C = &InitialC;
429444 // Now walk all references.
430445 for (Instruction &I : instructions(F))
431446 for (Value *Op : I.operand_values())
432 if (Constant *C = dyn_cast(Op))
447 if (auto *C = dyn_cast(Op))
433448 if (Visited.insert(C).second)
434449 Worklist.push_back(C);
435450
520535 // "bottom" we will continue processing in the bottom-up walk.
521536 assert(NewRefSCCs.front() == RC &&
522537 "New current RefSCC not first in the returned list!");
523 for (RefSCC *NewRC :
524 reverse(make_range(std::next(NewRefSCCs.begin()), NewRefSCCs.end()))) {
538 for (RefSCC *NewRC : llvm::reverse(make_range(std::next(NewRefSCCs.begin()),
539 NewRefSCCs.end()))) {
525540 assert(NewRC != RC && "Should not encounter the current RefSCC further "
526541 "in the postorder list of new RefSCCs.");
527542 UR.RCWorklist.insert(NewRC);
643658 DEBUG(dbgs() << "Enqueuing the existing SCC in the worklist: " << *C
644659 << "\n");
645660 // Enqueue in reverse order as we pop off the back of the worklist.
646 for (SCC &MovedC : reverse(make_range(RC->begin() + InitialSCCIndex,
647 RC->begin() + NewSCCIndex))) {
661 for (SCC &MovedC : llvm::reverse(make_range(RC->begin() + InitialSCCIndex,
662 RC->begin() + NewSCCIndex))) {
648663 UR.CWorklist.insert(&MovedC);
649664 DEBUG(dbgs() << "Enqueuing a newly earlier in post-order SCC: "
650665 << MovedC << "\n");
1515 //===----------------------------------------------------------------------===//
1616
1717 #include "llvm/Analysis/CallGraphSCCPass.h"
18 #include "llvm/ADT/DenseMap.h"
1819 #include "llvm/ADT/SCCIterator.h"
1920 #include "llvm/ADT/Statistic.h"
2021 #include "llvm/Analysis/CallGraph.h"
22 #include "llvm/IR/CallSite.h"
2123 #include "llvm/IR/Function.h"
22 #include "llvm/IR/IntrinsicInst.h"
24 #include "llvm/IR/Intrinsics.h"
2325 #include "llvm/IR/LLVMContext.h"
2426 #include "llvm/IR/LegacyPassManagers.h"
27 #include "llvm/IR/Module.h"
2528 #include "llvm/IR/OptBisect.h"
29 #include "llvm/Pass.h"
2630 #include "llvm/Support/CommandLine.h"
2731 #include "llvm/Support/Debug.h"
2832 #include "llvm/Support/Timer.h"
2933 #include "llvm/Support/raw_ostream.h"
34 #include
35 #include
36 #include
37 #include
38
3039 using namespace llvm;
3140
3241 #define DEBUG_TYPE "cgscc-passmgr"
4655 class CGPassManager : public ModulePass, public PMDataManager {
4756 public:
4857 static char ID;
49 explicit CGPassManager()
50 : ModulePass(ID), PMDataManager() { }
58
59 explicit CGPassManager() : ModulePass(ID), PMDataManager() {}
5160
5261 /// Execute all of the passes scheduled for execution. Keep track of
5362 /// whether any of the passes modifies the module, and if so, return true.
105114
106115 char CGPassManager::ID = 0;
107116
108
109117 bool CGPassManager::RunPassOnSCC(Pass *P, CallGraphSCC &CurSCC,
110118 CallGraph &CG, bool &CallGraphUpToDate,
111119 bool &DevirtualizedCall) {
133141
134142 return Changed;
135143 }
136
137144
138145 assert(PM->getPassManagerType() == PMT_FunctionPassManager &&
139146 "Invalid CGPassManager member");
161168 return Changed;
162169 }
163170
164
165171 /// Scan the functions in the specified CFG and resync the
166172 /// callgraph with the call sites found in it. This is used after
167173 /// FunctionPasses have potentially munged the callgraph, and can be used after
171177 /// meaning it turned an indirect call into a direct call. This happens when
172178 /// a function pass like GVN optimizes away stuff feeding the indirect call.
173179 /// This never happens in checking mode.
174 ///
175180 bool CGPassManager::RefreshCallGraph(const CallGraphSCC &CurSCC, CallGraph &CG,
176181 bool CheckingMode) {
177182 DenseMap CallSites;
483488 return Changed;
484489 }
485490
486
487491 /// Initialize CG
488492 bool CGPassManager::doInitialization(CallGraph &CG) {
489493 bool Changed = false;
535539 CGI->ReplaceNode(Old, New);
536540 }
537541
538
539542 //===----------------------------------------------------------------------===//
540543 // CallGraphSCCPass Implementation
541544 //===----------------------------------------------------------------------===//
585588 AU.addPreserved();
586589 }
587590
588
589591 //===----------------------------------------------------------------------===//
590592 // PrintCallGraphPass Implementation
591593 //===----------------------------------------------------------------------===//
592594
593595 namespace {
596
594597 /// PrintCallGraphPass - Print a Module corresponding to a call graph.
595598 ///
596599 class PrintCallGraphPass : public CallGraphSCCPass {
597600 std::string Banner;
598 raw_ostream &Out; // raw_ostream to print on.
601 raw_ostream &OS; // raw_ostream to print on.
599602
600603 public:
601604 static char ID;
602 PrintCallGraphPass(const std::string &B, raw_ostream &o)
603 : CallGraphSCCPass(ID), Banner(B), Out(o) {}
605
606 PrintCallGraphPass(const std::string &B, raw_ostream &OS)
607 : CallGraphSCCPass(ID), Banner(B), OS(OS) {}
604608
605609 void getAnalysisUsage(AnalysisUsage &AU) const override {
606610 AU.setPreservesAll();
611615 auto PrintBannerOnce = [&] () {
612616 if (BannerPrinted)
613617 return;
614 Out << Banner;
618 OS << Banner;
615619 BannerPrinted = true;
616620 };
617621 for (CallGraphNode *CGN : SCC) {
618622 if (Function *F = CGN->getFunction()) {
619623 if (!F->isDeclaration() && isFunctionInPrintList(F->getName())) {
620624 PrintBannerOnce();
621 F->print(Out);
625 F->print(OS);
622626 }
623 } else if (llvm::isFunctionInPrintList("*")) {
627 } else if (isFunctionInPrintList("*")) {
624628 PrintBannerOnce();
625 Out << "\nPrinting Function\n";
629 OS << "\nPrinting Function\n";
626630 }
627631 }
628632 return false;
635639
636640 char PrintCallGraphPass::ID = 0;
637641
638 Pass *CallGraphSCCPass::createPrinterPass(raw_ostream &O,
642 Pass *CallGraphSCCPass::createPrinterPass(raw_ostream &OS,
639643 const std::string &Banner) const {
640 return new PrintCallGraphPass(Banner, O);
644 return new PrintCallGraphPass(Banner, OS);
641645 }
642646
643647 bool CallGraphSCCPass::skipSCC(CallGraphSCC &SCC) const {
648652 }
649653
650654 char DummyCGSCCPass::ID = 0;
655
651656 INITIALIZE_PASS(DummyCGSCCPass, "DummyCGSCCPass", "DummyCGSCCPass", false,
652657 false)
None //===-- AMDGPUAnnotateKernelFeaturesPass.cpp ------------------------------===//
0 //===- AMDGPUAnnotateKernelFeaturesPass.cpp -------------------------------===//
11 //
22 // The LLVM Compiler Infrastructure
33 //
1313
1414 #include "AMDGPU.h"
1515 #include "AMDGPUSubtarget.h"
16 #include "Utils/AMDGPUBaseInfo.h"
17 #include "llvm/ADT/SmallPtrSet.h"
18 #include "llvm/ADT/SmallVector.h"
19 #include "llvm/ADT/StringRef.h"
1620 #include "llvm/ADT/Triple.h"
21 #include "llvm/Analysis/CallGraph.h"
1722 #include "llvm/Analysis/CallGraphSCCPass.h"
1823 #include "llvm/CodeGen/TargetPassConfig.h"
24 #include "llvm/IR/CallSite.h"
25 #include "llvm/IR/Constant.h"
1926 #include "llvm/IR/Constants.h"
20 #include "llvm/IR/InstIterator.h"
27 #include "llvm/IR/Function.h"
28 #include "llvm/IR/Instruction.h"
2129 #include "llvm/IR/Instructions.h"
30 #include "llvm/IR/Intrinsics.h"
2231 #include "llvm/IR/Module.h"
32 #include "llvm/IR/Type.h"
33 #include "llvm/IR/Use.h"
34 #include "llvm/Pass.h"
35 #include "llvm/Support/Casting.h"
36 #include "llvm/Support/ErrorHandling.h"
37 #include "llvm/Target/TargetMachine.h"
2338
2439 #define DEBUG_TYPE "amdgpu-annotate-kernel-features"
2540
4156
4257 bool doInitialization(CallGraph &CG) override;
4358 bool runOnSCC(CallGraphSCC &SCC) override;
59
4460 StringRef getPassName() const override {
4561 return "AMDGPU Annotate Kernel Features";
4662 }
5773 AMDGPUAS AS);
5874 };
5975
60 }
76 } // end anonymous namespace
6177
6278 char AMDGPUAnnotateKernelFeatures::ID = 0;
6379
293309 Changed |= addFeatureAttributes(*F);
294310 }
295311
296
297312 return Changed;
298313 }
299314
1818 // coroutine.
1919 //===----------------------------------------------------------------------===//
2020
21 #include "CoroInstr.h"
2122 #include "CoroInternal.h"
23 #include "llvm/ADT/DenseMap.h"
24 #include "llvm/ADT/SmallPtrSet.h"
25 #include "llvm/ADT/SmallVector.h"
26 #include "llvm/ADT/StringRef.h"
27 #include "llvm/ADT/Twine.h"
28 #include "llvm/Analysis/CallGraph.h"
2229 #include "llvm/Analysis/CallGraphSCCPass.h"
23 #include "llvm/IR/DebugInfoMetadata.h"
30 #include "llvm/IR/Argument.h"
31 #include "llvm/IR/Attributes.h"
32 #include "llvm/IR/BasicBlock.h"
33 #include "llvm/IR/CFG.h"
34 #include "llvm/IR/CallSite.h"
35 #include "llvm/IR/CallingConv.h"
36 #include "llvm/IR/Constants.h"
37 #include "llvm/IR/DataLayout.h"
38 #include "llvm/IR/DerivedTypes.h"
39 #include "llvm/IR/Function.h"
40 #include "llvm/IR/GlobalValue.h"
41 #include "llvm/IR/GlobalVariable.h"
2442 #include "llvm/IR/IRBuilder.h"
2543 #include "llvm/IR/InstIterator.h"
44 #include "llvm/IR/InstrTypes.h"
45 #include "llvm/IR/Instruction.h"
46 #include "llvm/IR/Instructions.h"
47 #include "llvm/IR/IntrinsicInst.h"
48 #include "llvm/IR/LLVMContext.h"
2649 #include "llvm/IR/LegacyPassManager.h"
50 #include "llvm/IR/Module.h"
51 #include "llvm/IR/Type.h"
52 #include "llvm/IR/Value.h"
2753 #include "llvm/IR/Verifier.h"
54 #include "llvm/Pass.h"
55 #include "llvm/Support/Casting.h"
56 #include "llvm/Support/Debug.h"
57 #include "llvm/Support/raw_ostream.h"
2858 #include "llvm/Transforms/Scalar.h"
2959 #include "llvm/Transforms/Utils/BasicBlockUtils.h"
3060 #include "llvm/Transforms/Utils/Cloning.h"
3161 #include "llvm/Transforms/Utils/Local.h"
3262 #include "llvm/Transforms/Utils/ValueMapper.h"
63 #include
64 #include
65 #include
66 #include
67 #include
3368
3469 using namespace llvm;
3570
342377 // Assumes that all the functions have the same signature.
343378 static void setCoroInfo(Function &F, CoroBeginInst *CoroBegin,
344379 std::initializer_list Fns) {
345
346380 SmallVector Args(Fns.begin(), Fns.end());
347381 assert(!Args.empty());
348382 Function *Part = *Fns.begin();
363397 // Store addresses of Resume/Destroy/Cleanup functions in the coroutine frame.
364398 static void updateCoroFrame(coro::Shape &Shape, Function *ResumeFn,
365399 Function *DestroyFn, Function *CleanupFn) {
366
367400 IRBuilder<> Builder(Shape.FramePtr->getNextNode());
368401 auto *ResumeAddr = Builder.CreateConstInBoundsGEP2_32(
369402 Shape.FrameTy, Shape.FramePtr, 0, coro::Shape::ResumeField,
387420
388421 static void postSplitCleanup(Function &F) {
389422 removeUnreachableBlocks(F);
390 llvm::legacy::FunctionPassManager FPM(F.getParent());
423 legacy::FunctionPassManager FPM(F.getParent());
391424
392425 FPM.add(createVerifierPass());
393426 FPM.add(createSCCPPass());
477510 // Set musttail on those that are followed by a ret instruction.
478511 for (CallInst *Call : Resumes)
479512 if (simplifyTerminatorLeadingToRet(Call->getNextNode())) {
480 Call->setTailCallKind(llvm::CallInst::TCK_MustTail);
513 Call->setTailCallKind(CallInst::TCK_MustTail);
481514 changed = true;
482515 }
483516
573606 size_t I = 0, N = S.size();
574607 if (N == 0)
575608 return;
576 for (;;) {
609 while (true) {
577610 if (simplifySuspendPoint(S[I], Shape.CoroBegin)) {
578611 if (--N == I)
579612 break;
768801
769802 struct CoroSplit : public CallGraphSCCPass {
770803 static char ID; // Pass identification, replacement for typeid
804
771805 CoroSplit() : CallGraphSCCPass(ID) {
772806 initializeCoroSplitPass(*PassRegistry::getPassRegistry());
773807 }
816850 void getAnalysisUsage(AnalysisUsage &AU) const override {
817851 CallGraphSCCPass::getAnalysisUsage(AU);
818852 }
853
819854 StringRef getPassName() const override { return "Coroutine Splitting"; }
820855 };
821 }
856
857 } // end anonymous namespace
822858
823859 char CoroSplit::ID = 0;
860
824861 INITIALIZE_PASS(
825862 CoroSplit, "coro-split",
826863 "Split coroutine into a set of functions driving its state machine", false,
None //===-- Coroutines.cpp ----------------------------------------------------===//
0 //===- Coroutines.cpp -----------------------------------------------------===//
11 //
22 // The LLVM Compiler Infrastructure
33 //
55 // License. See LICENSE.TXT for details.
66 //
77 //===----------------------------------------------------------------------===//
8 //
89 // This file implements the common infrastructure for Coroutine Passes.
10 //
911 //===----------------------------------------------------------------------===//
1012
13 #include "CoroInstr.h"
1114 #include "CoroInternal.h"
15 #include "llvm/ADT/SmallVector.h"
16 #include "llvm/ADT/StringRef.h"
17 #include "llvm/Analysis/CallGraph.h"
1218 #include "llvm/Analysis/CallGraphSCCPass.h"
19 #include "llvm/IR/Attributes.h"
20 #include "llvm/IR/CallSite.h"
21 #include "llvm/IR/Constants.h"
22 #include "llvm/IR/DerivedTypes.h"
23 #include "llvm/IR/Function.h"
1324 #include "llvm/IR/InstIterator.h"
25 #include "llvm/IR/Instructions.h"
26 #include "llvm/IR/IntrinsicInst.h"
27 #include "llvm/IR/Intrinsics.h"
1428 #include "llvm/IR/LegacyPassManager.h"
15 #include "llvm/IR/Verifier.h"
16 #include "llvm/InitializePasses.h"
29 #include "llvm/IR/Module.h"
30 #include "llvm/IR/Type.h"
31 #include "llvm/Support/Casting.h"
32 #include "llvm/Support/ErrorHandling.h"
33 #include "llvm/Transforms/Coroutines.h"
1734 #include "llvm/Transforms/IPO.h"
1835 #include "llvm/Transforms/IPO/PassManagerBuilder.h"
1936 #include "llvm/Transforms/Utils/Local.h"
37 #include
38 #include
39 #include
2040
2141 using namespace llvm;
2242
116136 // that names are intrinsic names.
117137 bool coro::declaresIntrinsics(Module &M,
118138 std::initializer_list List) {
119
120139 for (StringRef Name : List) {
121140 assert(isCoroutineIntrinsicName(Name) && "not a coroutine intrinsic");
122141 if (M.getNamedValue(Name))
None //===-- LoopUnswitch.cpp - Hoist loop-invariant conditionals in loop ------===//
0 //===- LoopUnswitch.cpp - Hoist loop-invariant conditionals in loop -------===//
11 //
22 // The LLVM Compiler Infrastructure
33 //
2525 //
2626 //===----------------------------------------------------------------------===//
2727
28 #include "llvm/ADT/STLExtras.h"
28 #include "llvm/ADT/DenseMap.h"
2929 #include "llvm/ADT/SmallPtrSet.h"
30 #include "llvm/ADT/SmallSet.h"
31 #include "llvm/ADT/SmallVector.h"
3032 #include "llvm/ADT/Statistic.h"
3133 #include "llvm/Analysis/AssumptionCache.h"
32 #include "llvm/Analysis/BlockFrequencyInfo.h"
33 #include "llvm/Analysis/BlockFrequencyInfoImpl.h"
34 #include "llvm/Analysis/BranchProbabilityInfo.h"
3534 #include "llvm/Analysis/CodeMetrics.h"
3635 #include "llvm/Analysis/DivergenceAnalysis.h"
37 #include "llvm/Analysis/GlobalsModRef.h"
3836 #include "llvm/Analysis/InstructionSimplify.h"
3937 #include "llvm/Analysis/LoopInfo.h"
4038 #include "llvm/Analysis/LoopPass.h"
4139 #include "llvm/Analysis/ScalarEvolution.h"
4240 #include "llvm/Analysis/TargetTransformInfo.h"
41 #include "llvm/IR/Attributes.h"
42 #include "llvm/IR/BasicBlock.h"
43 #include "llvm/IR/CallSite.h"
44 #include "llvm/IR/Constant.h"
4345 #include "llvm/IR/Constants.h"
4446 #include "llvm/IR/DerivedTypes.h"
4547 #include "llvm/IR/Dominators.h"
4648 #include "llvm/IR/Function.h"
49 #include "llvm/IR/IRBuilder.h"
4750 #include "llvm/IR/InstrTypes.h"
51 #include "llvm/IR/Instruction.h"
4852 #include "llvm/IR/Instructions.h"
49 #include "llvm/IR/MDBuilder.h"
53 #include "llvm/IR/IntrinsicInst.h"
54 #include "llvm/IR/Intrinsics.h"
5055 #include "llvm/IR/Module.h"
51 #include "llvm/Support/BranchProbability.h"
56 #include "llvm/IR/Type.h"
57 #include "llvm/IR/User.h"
58 #include "llvm/IR/Value.h"
59 #include "llvm/IR/ValueHandle.h"
60 #include "llvm/Pass.h"
61 #include "llvm/Support/Casting.h"
5262 #include "llvm/Support/CommandLine.h"
5363 #include "llvm/Support/Debug.h"
5464 #include "llvm/Support/raw_ostream.h"
5767 #include "llvm/Transforms/Utils/Cloning.h"
5868 #include "llvm/Transforms/Utils/Local.h"
5969 #include "llvm/Transforms/Utils/LoopUtils.h"
70 #include "llvm/Transforms/Utils/ValueMapper.h"
6071 #include
72 #include
6173 #include
6274 #include
75 #include
76 #include
77 #include
78
6379 using namespace llvm;
6480
6581 #define DEBUG_TYPE "loop-unswitch"
8197 namespace {
8298
8399 class LUAnalysisCache {
84
85 typedef DenseMap >
86 UnswitchedValsMap;
87
88 typedef UnswitchedValsMap::iterator UnswitchedValsIt;
100 using UnswitchedValsMap =
101 DenseMap>;
102 using UnswitchedValsIt = UnswitchedValsMap::iterator;
89103
90104 struct LoopProperties {
91105 unsigned CanBeUnswitchedCount;
96110
97111 // Here we use std::map instead of DenseMap, since we need to keep valid
98112 // LoopProperties pointer for current loop for better performance.
99 typedef std::map LoopPropsMap;
100 typedef LoopPropsMap::iterator LoopPropsMapIt;
113 using LoopPropsMap = std::map;
114 using LoopPropsMapIt = LoopPropsMap::iterator;
101115
102116 LoopPropsMap LoopsProperties;
103 UnswitchedValsMap *CurLoopInstructions;
104 LoopProperties *CurrentLoopProperties;
117 UnswitchedValsMap *CurLoopInstructions = nullptr;
118 LoopProperties *CurrentLoopProperties = nullptr;
105119
106120 // A loop unswitching with an estimated cost above this threshold
107121 // is not performed. MaxSize is turned into unswitching quota for
120134 unsigned MaxSize;
121135
122136 public:
123 LUAnalysisCache()
124 : CurLoopInstructions(nullptr), CurrentLoopProperties(nullptr),
125 MaxSize(Threshold) {}
137 LUAnalysisCache() : MaxSize(Threshold) {}
126138
127139 // Analyze loop. Check its size, calculate is it possible to unswitch
128140 // it. Returns true if we can unswitch this loop.
163175 LUAnalysisCache BranchesInfo;
164176
165177 bool OptimizeForSize;
166 bool redoLoop;
167
168 Loop *currentLoop;
169 DominatorTree *DT;
170 BasicBlock *loopHeader;
171 BasicBlock *loopPreheader;
178 bool redoLoop = false;
179
180 Loop *currentLoop = nullptr;
181 DominatorTree *DT = nullptr;
182 BasicBlock *loopHeader = nullptr;
183 BasicBlock *loopPreheader = nullptr;
172184
173185 bool SanitizeMemory;
174186 LoopSafetyInfo SafetyInfo;
184196
185197 public:
186198 static char ID; // Pass ID, replacement for typeid
187 explicit LoopUnswitch(bool Os = false, bool hasBranchDivergence = false) :
188 LoopPass(ID), OptimizeForSize(Os), redoLoop(false),
189 currentLoop(nullptr), DT(nullptr), loopHeader(nullptr),
190 loopPreheader(nullptr), hasBranchDivergence(hasBranchDivergence) {
199
200 explicit LoopUnswitch(bool Os = false, bool hasBranchDivergence = false)
201 : LoopPass(ID), OptimizeForSize(Os),
202 hasBranchDivergence(hasBranchDivergence) {
191203 initializeLoopUnswitchPass(*PassRegistry::getPassRegistry());
192 }
204 }
193205
194206 bool runOnLoop(Loop *L, LPPassManager &LPM) override;
195207 bool processCurrentLoop();
196208 bool isUnreachableDueToPreviousUnswitching(BasicBlock *);
209
197210 /// This transformation requires natural loop information & requires that
198211 /// loop preheaders be inserted into the CFG.
199212 ///
206219 }
207220
208221 private:
209
210222 void releaseMemory() override {
211223 BranchesInfo.forgetLoop(currentLoop);
212224 }
246258 Value *SimplifyInstructionWithNotEqual(Instruction *Inst, Value *Invariant,
247259 Constant *Val);
248260 };
249 }
261
262 } // end anonymous namespace
250263
251264 // Analyze loop. Check its size, calculate is it possible to unswitch
252265 // it. Returns true if we can unswitch this loop.
253266 bool LUAnalysisCache::countLoop(const Loop *L, const TargetTransformInfo &TTI,
254267 AssumptionCache *AC) {
255
256268 LoopPropsMapIt PropsIt;
257269 bool Inserted;
258270 std::tie(PropsIt, Inserted) =
301313
302314 // Clean all data related to given loop.
303315 void LUAnalysisCache::forgetLoop(const Loop *L) {
304
305316 LoopPropsMapIt LIt = LoopsProperties.find(L);
306317
307318 if (LIt != LoopsProperties.end()) {
336347 // Note, that new loop data is stored inside the VMap.
337348 void LUAnalysisCache::cloneData(const Loop *NewLoop, const Loop *OldLoop,
338349 const ValueToValueMapTy &VMap) {
339
340350 LoopProperties &NewLoopProps = LoopsProperties[NewLoop];
341351 LoopProperties &OldLoopProps = *CurrentLoopProperties;
342352 UnswitchedValsMap &Insts = OldLoopProps.UnswitchedVals;
366376 }
367377
368378 char LoopUnswitch::ID = 0;
379
369380 INITIALIZE_PASS_BEGIN(LoopUnswitch, "loop-unswitch", "Unswitch loops",
370381 false, false)
371382 INITIALIZE_PASS_DEPENDENCY(AssumptionCacheTracker)
None //===-- llvm-stress.cpp - Generate random LL files to stress-test LLVM ----===//
0 //===- llvm-stress.cpp - Generate random LL files to stress-test LLVM -----===//
11 //
22 // The LLVM Compiler Infrastructure
33 //
1111 //
1212 //===----------------------------------------------------------------------===//
1313
14 #include "llvm/Analysis/CallGraphSCCPass.h"
14 #include "llvm/ADT/APFloat.h"
15 #include "llvm/ADT/APInt.h"
16 #include "llvm/ADT/ArrayRef.h"
17 #include "llvm/ADT/STLExtras.h"
18 #include "llvm/ADT/StringRef.h"
19 #include "llvm/ADT/Twine.h"
20 #include "llvm/IR/BasicBlock.h"
21 #include "llvm/IR/CallingConv.h"
1522 #include "llvm/IR/Constants.h"
23 #include "llvm/IR/DataLayout.h"
24 #include "llvm/IR/DerivedTypes.h"
25 #include "llvm/IR/Function.h"
26 #include "llvm/IR/GlobalValue.h"
1627 #include "llvm/IR/IRPrintingPasses.h"
28 #include "llvm/IR/InstrTypes.h"
1729 #include "llvm/IR/Instruction.h"
30 #include "llvm/IR/Instructions.h"
1831 #include "llvm/IR/LLVMContext.h"
1932 #include "llvm/IR/LegacyPassManager.h"
20 #include "llvm/IR/LegacyPassNameParser.h"
2133 #include "llvm/IR/Module.h"
34 #include "llvm/IR/Type.h"
35 #include "llvm/IR/Value.h"
2236 #include "llvm/IR/Verifier.h"
23 #include "llvm/Support/Debug.h"
37 #include "llvm/Support/Casting.h"
38 #include "llvm/Support/CommandLine.h"
39 #include "llvm/Support/ErrorHandling.h"
2440 #include "llvm/Support/FileSystem.h"
2541 #include "llvm/Support/ManagedStatic.h"
26 #include "llvm/Support/PluginLoader.h"
2742 #include "llvm/Support/PrettyStackTrace.h"
2843 #include "llvm/Support/ToolOutputFile.h"
44 #include "llvm/Support/raw_ostream.h"
2945 #include
30 #include <random>
46 #include <cassert>
47 #include
48 #include
49 #include
50 #include
51 #include
3152 #include
3253
3354 namespace llvm {
3455
3556 static cl::opt SeedCL("seed",
3657 cl::desc("Seed used for randomness"), cl::init(0));
58
3759 static cl::opt SizeCL("size",
3860 cl::desc("The estimated size of the generated function (# of instrs)"),
3961 cl::init(100));
62
4063 static cl::opt
4164 OutputFilename("o", cl::desc("Override output filename"),
4265 cl::value_desc("filename"));
4467 static LLVMContext Context;
4568
4669 namespace cl {
70
4771 template <> class parser final : public basic_parser {
4872 public:
4973 parser(Option &O) : basic_parser(O) {}
6993
7094 StringRef getValueName() const override { return "IR scalar type"; }
7195 };
72 }
73
96
97 } // end namespace cl
7498
7599 static cl::list AdditionalScalarTypes("types", cl::CommaSeparated,
76100 cl::desc("Additional IR scalar types "
77101 "(always includes i1, i8, i16, i32, i64, float and double)"));
78102
79103 namespace {
104
80105 /// A utility class to provide a pseudo-random number generator which is
81106 /// the same across all platforms. This is somewhat close to the libc
82107 /// implementation. Note: This is not a cryptographically secure pseudorandom
110135 }
111136
112137 /// Make this like a C++11 random device
113 typedef uint32_t result_type;
138 using result_type = uint32_t ;
139
114140 static constexpr result_type min() { return 0; }
115141 static constexpr result_type max() { return 0x7ffff; }
142
116143 uint32_t operator()() {
117144 uint32_t Val = Rand();
118145 assert(Val <= max() && "Random value out of range");
148175 /// modifying and adding new random instructions.
149176 struct Modifier {
150177 /// Used to store the randomly generated values.
151 typedef std::vector PieceTable;
178 using PieceTable = std::vector;
152179
153180 public:
154181 /// C'tor
155 Modifier(BasicBlock *Block, PieceTable *PT, Random *R):
156 BB(Block),PT(PT),Ran(R),Context(BB->getContext()) {}
182 Modifier(BasicBlock *Block, PieceTable *PT, Random *R)
183 : BB(Block), PT(PT), Ran(R), Context(BB->getContext()) {}
157184
158185 /// virtual D'tor to silence warnings.
159 virtual ~Modifier() {}
186 virtual ~Modifier() = default;
160187
161188 /// Add a new instruction.
162189 virtual void Act() = 0;
190
163191 /// Add N new instructions,
164192 virtual void ActN(unsigned n) {
165193 for (unsigned i=0; i
297325
298326 /// Basic block to populate
299327 BasicBlock *BB;
328
300329 /// Value table
301330 PieceTable *PT;
331
302332 /// Random number generator
303333 Random *Ran;
334
304335 /// Context
305336 LLVMContext &Context;
306337 };
307338
308339 struct LoadModifier: public Modifier {
309 LoadModifier(BasicBlock *BB, PieceTable *PT, Random *R):Modifier(BB, PT, R) {}
340 LoadModifier(BasicBlock *BB, PieceTable *PT, Random *R)
341 : Modifier(BB, PT, R) {}
342
310343 void Act() override {
311344 // Try to use predefined pointers. If non-exist, use undef pointer value;
312345 Value *Ptr = getRandomPointerValue();
316349 };
317350
318351 struct StoreModifier: public Modifier {
319 StoreModifier(BasicBlock *BB, PieceTable *PT, Random *R):Modifier(BB, PT, R) {}
352 StoreModifier(BasicBlock *BB, PieceTable *PT, Random *R)
353 : Modifier(BB, PT, R) {}
354
320355 void Act() override {
321356 // Try to use predefined pointers. If non-exist, use undef pointer value;
322357 Value *Ptr = getRandomPointerValue();
334369 };
335370
336371 struct BinModifier: public Modifier {
337 BinModifier(BasicBlock *BB, PieceTable *PT, Random *R):Modifier(BB, PT, R) {}
372 BinModifier(BasicBlock *BB, PieceTable *PT, Random *R)
373 : Modifier(BB, PT, R) {}
338374
339375 void Act() override {
340376 Value *Val0 = getRandomVal();
348384 // Don't handle i1 types.
349385 if (Val0->getType()->getScalarSizeInBits() == 1)
350386 return;
351
352387
353388 bool isFloat = Val0->getType()->getScalarType()->isFloatingPointTy();
354389 Instruction* Term = BB->getTerminator();
378413
379414 /// Generate constant values.
380415 struct ConstModifier: public Modifier {
381 ConstModifier(BasicBlock *BB, PieceTable *PT, Random *R):Modifier(BB, PT, R) {}
416 ConstModifier(BasicBlock *BB, PieceTable *PT, Random *R)
417 : Modifier(BB, PT, R) {}
418
382419 void Act() override {
383420 Type *Ty = pickType();
384421
427464 };
428465
429466 struct AllocaModifier: public Modifier {
430 AllocaModifier(BasicBlock *BB, PieceTable *PT, Random *R):Modifier(BB, PT, R){}
467 AllocaModifier(BasicBlock *BB, PieceTable *PT, Random *R)
468 : Modifier(BB, PT, R) {}
431469
432470 void Act() override {
433471 Type *Tp = pickType();
438476 };
439477
440478 struct ExtractElementModifier: public Modifier {
441 ExtractElementModifier(BasicBlock *BB, PieceTable *PT, Random *R):
442 Modifier(BB, PT, R) {}
479 ExtractElementModifier(BasicBlock *BB, PieceTable *PT, Random *R)
480 : Modifier(BB, PT, R) {}
443481
444482 void Act() override {
445483 Value *Val0 = getRandomVectorValue();
452490 };
453491
454492 struct ShuffModifier: public Modifier {
455 ShuffModifier(BasicBlock *BB, PieceTable *PT, Random *R):Modifier(BB, PT, R) {}
456 void Act() override {
457
493 ShuffModifier(BasicBlock *BB, PieceTable *PT, Random *R)
494 : Modifier(BB, PT, R) {}
495
496 void Act() override {
458497 Value *Val0 = getRandomVectorValue();
459498 Value *Val1 = getRandomValue(Val0->getType());
460499
479518 };
480519
481520 struct InsertElementModifier: public Modifier {
482 InsertElementModifier(BasicBlock *BB, PieceTable *PT, Random *R):
483 Modifier(BB, PT, R) {}
521 InsertElementModifier(BasicBlock *BB, PieceTable *PT, Random *R)
522 : Modifier(BB, PT, R) {}
484523
485524 void Act() override {
486525 Value *Val0 = getRandomVectorValue();
492531 "I", BB->getTerminator());
493532 return PT->push_back(V);
494533 }
495
496534 };
497535
498536 struct CastModifier: public Modifier {
499 CastModifier(BasicBlock *BB, PieceTable *PT, Random *R):Modifier(BB, PT, R) {}
500 void Act() override {
501
537 CastModifier(BasicBlock *BB, PieceTable *PT, Random *R)
538 : Modifier(BB, PT, R) {}
539
540 void Act() override {
502541 Value *V = getRandomVal();
503542 Type *VTy = V->getType();
504543 Type *DestTy = pickScalarType();
557596 return PT->push_back(
558597 new SIToFPInst(V, DestTy, "FC", BB->getTerminator()));
559598 return PT->push_back(new UIToFPInst(V, DestTy, "FC", BB->getTerminator()));
560
561599 }
562600
563601 // Both floats.
573611 // for which there is no defined conversion. So do nothing.
574612 }
575613 }
576
577614 };
578615
579616 struct SelectModifier: public Modifier {
580 SelectModifier(BasicBlock *BB, PieceTable *PT, Random *R):
581 Modifier(BB, PT, R) {}
617 SelectModifier(BasicBlock *BB, PieceTable *PT, Random *R)
618 : Modifier(BB, PT, R) {}
582619
583620 void Act() override {
584621 // Try a bunch of different select configuration until a valid one is found.
585 Value *Val0 = getRandomVal();
586 Value *Val1 = getRandomValue(Val0->getType());
587
588 Type *CondTy = Type::getInt1Ty(Context);
589
590 // If the value type is a vector, and we allow vector select, then in 50%
591 // of the cases generate a vector select.
592 if (Val0->getType()->isVectorTy() && (getRandom() % 1)) {
593 unsigned NumElem = cast(Val0->getType())->getNumElements();
594 CondTy = VectorType::get(CondTy, NumElem);
595 }
596
597 Value *Cond = getRandomValue(CondTy);
598 Value *V = SelectInst::Create(Cond, Val0, Val1, "Sl", BB->getTerminator());
599 return PT->push_back(V);
600 }
601 };
602
622 Value *Val0 = getRandomVal();
623 Value *Val1 = getRandomValue(Val0->getType());
624
625 Type *CondTy = Type::getInt1Ty(Context);
626
627 // If the value type is a vector, and we allow vector select, then in 50%
628 // of the cases generate a vector select.
629 if (Val0->getType()->isVectorTy() && (getRandom() % 1)) {
630 unsigned NumElem = cast(Val0->getType())->getNumElements();
631 CondTy = VectorType::get(CondTy, NumElem);
632 }
633
634 Value *Cond = getRandomValue(CondTy);
635 Value *V = SelectInst::Create(Cond, Val0, Val1, "Sl", BB->getTerminator());
636 return PT->push_back(V);
637 }
638 };
603639
604640 struct CmpModifier: public Modifier {
605 CmpModifier(BasicBlock *BB, PieceTable *PT, Random *R):Modifier(BB, PT, R) {}
606 void Act() override {
607
641 CmpModifier(BasicBlock *BB, PieceTable *PT, Random *R)
642 : Modifier(BB, PT, R) {}
643
644 void Act() override {
608645 Value *Val0 = getRandomVal();
609646 Value *Val1 = getRandomValue(Val0->getType());
610647
688725 }
689726 }
690727
691 }
728 } // end namespace llvm
692729
693730 int main(int argc, char **argv) {
694731 using namespace llvm;
698735 cl::ParseCommandLineOptions(argc, argv, "llvm codegen stress-tester\n");
699736 llvm_shutdown_obj Y;
700737
701 auto M = make_unique("/tmp/autogen.bc", Context);
738 auto M = llvm::make_unique("/tmp/autogen.bc", Context);
702739 Function *F = GenEmptyFunction(M.get());
703740
704741 // Pick an initial seed value
1010 /// \brief Utilities to print analysis info for various kinds of passes.
1111 ///
1212 //===----------------------------------------------------------------------===//
13
1314 #include "PassPrinters.h"
15 #include "llvm/Analysis/CallGraph.h"
1416 #include "llvm/Analysis/CallGraphSCCPass.h"
17 #include "llvm/Analysis/LoopInfo.h"
1518 #include "llvm/Analysis/LoopPass.h"
19 #include "llvm/Analysis/RegionInfo.h"
1620 #include "llvm/Analysis/RegionPass.h"
21 #include "llvm/IR/BasicBlock.h"
1722 #include "llvm/IR/Function.h"
1823 #include "llvm/Pass.h"
24 #include "llvm/Support/raw_ostream.h"
1925 #include
2026
2127 using namespace llvm;
225231 };
226232
227233 char BasicBlockPassPrinter::ID = 0;
228 }
234
235 } // end anonymous namespace
229236
230237 FunctionPass *llvm::createFunctionPassPrinter(const PassInfo *PI,
231238 raw_ostream &OS, bool Quiet) {
None //===- PassPrinters.h - Utilities to print analysis info for passes -------===//
0 //=- PassPrinters.h - Utilities to print analysis info for passes -*- C++ -*-=//
11 //
22 // The LLVM Compiler Infrastructure
33 //
1010 /// \brief Utilities to print analysis info for various kinds of passes.
1111 ///
1212 //===----------------------------------------------------------------------===//
13
1314 #ifndef LLVM_TOOLS_OPT_PASSPRINTERS_H
1415 #define LLVM_TOOLS_OPT_PASSPRINTERS_H
1516
2122 class ModulePass;
2223 class LoopPass;
2324 class PassInfo;
25 class raw_ostream;
2426 class RegionPass;
25 class raw_ostream;
2627
2728 FunctionPass *createFunctionPassPrinter(const PassInfo *PI, raw_ostream &out,
2829 bool Quiet);
4142
4243 BasicBlockPass *createBasicBlockPassPrinter(const PassInfo *PI,
4344 raw_ostream &out, bool Quiet);
44 }
45
46 } // end namespace llvm
4547
4648 #endif // LLVM_TOOLS_OPT_PASSPRINTERS_H