llvm.org GIT mirror llvm / c94da20
Make DataLayout Non-Optional in the Module Summary: DataLayout keeps the string used for its creation. As a side effect it is no longer needed in the Module. This is "almost" NFC, the string is no longer canonicalized, you can't rely on two "equals" DataLayout having the same string returned by getStringRepresentation(). Get rid of DataLayoutPass: the DataLayout is in the Module The DataLayout is "per-module", let's enforce this by not duplicating it more than necessary. One more step toward non-optionality of the DataLayout in the module. Make DataLayout Non-Optional in the Module Module->getDataLayout() will never returns nullptr anymore. Reviewers: echristo Subscribers: resistor, llvm-commits, jholewinski Differential Revision: http://reviews.llvm.org/D7992 From: Mehdi Amini <mehdi.amini@apple.com> git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@231270 91177308-0d34-0410-b5e6-96231b3b80d8 Mehdi Amini 4 years ago
163 changed file(s) with 622 addition(s) and 978 deletion(s). Raw diff Collapse all Expand all
19721972 // Start with registering info about how the
19731973 // target lays out data structures.
19741974 module->setDataLayout(executionEngine->getDataLayout());
1975 fpm.add(new llvm::DataLayoutPass());
19761975
19771976 // Optimizations turned on
19781977 #ifdef ADD_OPT_PASSES
560560 // Set up the optimizer pipeline. Start with registering info about how the
561561 // target lays out data structures.
562562 OpenModule->setDataLayout(NewEngine->getDataLayout());
563 FPM->add(new DataLayoutPass());
564563 // Provide basic AliasAnalysis support for GVN.
565564 FPM->add(createBasicAliasAnalysisPass());
566565 // Promote allocas to registers.
913913 // Set up the optimizer pipeline. Start with registering info about how the
914914 // target lays out data structures.
915915 TheModule->setDataLayout(TheExecutionEngine->getDataLayout());
916 OurFPM.add(new DataLayoutPass());
917916 // Provide basic AliasAnalysis support for GVN.
918917 OurFPM.add(createBasicAliasAnalysisPass());
919918 // Do simple "peephole" optimizations and bit-twiddling optzns.
10341034 // Set up the optimizer pipeline. Start with registering info about how the
10351035 // target lays out data structures.
10361036 TheModule->setDataLayout(TheExecutionEngine->getDataLayout());
1037 OurFPM.add(new DataLayoutPass());
10381037 // Provide basic AliasAnalysis support for GVN.
10391038 OurFPM.add(createBasicAliasAnalysisPass());
10401039 // Do simple "peephole" optimizations and bit-twiddling optzns.
12081208 // Set up the optimizer pipeline. Start with registering info about how the
12091209 // target lays out data structures.
12101210 TheModule->setDataLayout(TheExecutionEngine->getDataLayout());
1211 OurFPM.add(new DataLayoutPass());
12121211 // Provide basic AliasAnalysis support for GVN.
12131212 OurFPM.add(createBasicAliasAnalysisPass());
12141213 // Promote allocas to registers.
14591459 // Set up the optimizer pipeline. Start with registering info about how the
14601460 // target lays out data structures.
14611461 TheModule->setDataLayout(TheExecutionEngine->getDataLayout());
1462 OurFPM.add(new DataLayoutPass());
14631462 #if 0
14641463 // Provide basic AliasAnalysis support for GVN.
14651464 OurFPM.add(createBasicAliasAnalysisPass());
715715 M(new Module(GenerateUniqueName("jit_module_"),
716716 Session.getLLVMContext())),
717717 Builder(Session.getLLVMContext()) {
718 M->setDataLayout(Session.getTarget().getDataLayout());
718 M->setDataLayout(*Session.getTarget().getDataLayout());
719719 }
720720
721721 SessionContext& getSession() { return Session; }
714714 M(new Module(GenerateUniqueName("jit_module_"),
715715 Session.getLLVMContext())),
716716 Builder(Session.getLLVMContext()) {
717 M->setDataLayout(Session.getTarget().getDataLayout());
717 M->setDataLayout(*Session.getTarget().getDataLayout());
718718 }
719719
720720 SessionContext& getSession() { return Session; }
714714 M(new Module(GenerateUniqueName("jit_module_"),
715715 Session.getLLVMContext())),
716716 Builder(Session.getLLVMContext()) {
717 M->setDataLayout(Session.getTarget().getDataLayout());
717 M->setDataLayout(*Session.getTarget().getDataLayout());
718718 }
719719
720720 SessionContext& getSession() { return Session; }
714714 M(new Module(GenerateUniqueName("jit_module_"),
715715 Session.getLLVMContext())),
716716 Builder(Session.getLLVMContext()) {
717 M->setDataLayout(Session.getTarget().getDataLayout());
717 M->setDataLayout(*Session.getTarget().getDataLayout());
718718 }
719719
720720 SessionContext& getSession() { return Session; }
6767 /// typically called by the run* methods of these subclasses. This may be
6868 /// called multiple times.
6969 ///
70 void InitializeAliasAnalysis(Pass *P);
70 void InitializeAliasAnalysis(Pass *P, const DataLayout *DL);
7171
7272 /// getAnalysisUsage - All alias analysis implementations should invoke this
7373 /// directly (using AliasAnalysis::getAnalysisUsage(AU)).
1414 #define LLVM_ANALYSIS_LIBCALLALIASANALYSIS_H
1515
1616 #include "llvm/Analysis/AliasAnalysis.h"
17 #include "llvm/IR/Module.h"
1718 #include "llvm/Pass.h"
1819
1920 namespace llvm {
4748
4849 void getAnalysisUsage(AnalysisUsage &AU) const override;
4950
50 bool runOnFunction(Function &F) override {
51 InitializeAliasAnalysis(this); // set up super class
52 return false;
53 }
54
51 bool runOnFunction(Function &F) override;
52
5553 /// getAdjustedAnalysisPointer - This method is used when a pass implements
5654 /// an analysis interface through multiple inheritance. If needed, it
5755 /// should override this to adjust the this pointer as needed for the
182182 auto Names = llvm::make_unique>();
183183
184184 for (const auto &M : Ms) {
185 Mangler Mang(M->getDataLayout());
185 Mangler Mang(&M->getDataLayout());
186186
187187 for (const auto &GV : M->globals())
188188 if (addGlobalValue(*Names, GV, Mang, SearchName, ExportedSymbolsOnly))
115115 /// \brief Primitive type alignment data.
116116 SmallVector Alignments;
117117
118 /// \brief The string representation used to create this DataLayout
119 std::string StringRepresentation;
120
118121 typedef SmallVector PointersTy;
119122 PointersTy Pointers;
120123
184187
185188 DataLayout &operator=(const DataLayout &DL) {
186189 clear();
190 StringRepresentation = DL.StringRepresentation;
187191 BigEndian = DL.isBigEndian();
188192 StackNaturalAlign = DL.StackNaturalAlign;
189193 ManglingMode = DL.ManglingMode;
208212 /// \brief Returns the string representation of the DataLayout.
209213 ///
210214 /// This representation is in the same format accepted by the string
211 /// constructor above.
212 std::string getStringRepresentation() const;
215 /// constructor above. This should not be used to compare two DataLayout as
216 /// different string can represent the same layout.
217 std::string getStringRepresentation() const { return StringRepresentation; }
218
219 /// \brief Test if the DataLayout was constructed from an empty string.
220 bool isDefault() const { return StringRepresentation.empty(); }
213221
214222 /// \brief Returns true if the specified type is known to be a native integer
215223 /// type supported by the CPU.
449457 inline LLVMTargetDataRef wrap(const DataLayout *P) {
450458 return reinterpret_cast(const_cast(P));
451459 }
452
453 class DataLayoutPass : public ImmutablePass {
454 DataLayout DL;
455
456 public:
457 /// This has to exist, because this is a pass, but it should never be used.
458 DataLayoutPass();
459 ~DataLayoutPass();
460
461 const DataLayout &getDataLayout() const { return DL; }
462
463 static char ID; // Pass identification, replacement for typeid
464
465 bool doFinalization(Module &M) override;
466 bool doInitialization(Module &M) override;
467 };
468460
469461 /// Used to lazily calculate structure layout information for a target machine,
470462 /// based on the DataLayout structure.
218218 std::string TargetTriple; ///< Platform target triple Module compiled on
219219 ///< Format: (arch)(sub)-(vendor)-(sys0-(abi)
220220 void *NamedMDSymTab; ///< NamedMDNode names.
221
222 // We need to keep the string because the C API expects us to own the string
223 // representation.
224 // Since we have it, we also use an empty string to represent a module without
225 // a DataLayout. If it has a DataLayout, these variables are in sync and the
226 // string is just a cache of getDataLayout()->getStringRepresentation().
227 std::string DataLayoutStr;
228 DataLayout DL;
221 DataLayout DL; ///< DataLayout associated with the module
229222
230223 friend class Constant;
231224
255248
256249 /// Get the data layout string for the module's target platform. This is
257250 /// equivalent to getDataLayout()->getStringRepresentation().
258 const std::string &getDataLayoutStr() const { return DataLayoutStr; }
251 const std::string getDataLayoutStr() const {
252 return DL.getStringRepresentation();
253 }
259254
260255 /// Get the data layout for the module's target platform.
261 const DataLayout *getDataLayout() const;
256 const DataLayout &getDataLayout() const;
262257
263258 /// Get the target triple which is a string describing the target host.
264259 /// @returns a string containing the target triple.
292287
293288 /// Set the data layout
294289 void setDataLayout(StringRef Desc);
295 void setDataLayout(const DataLayout *Other);
290 void setDataLayout(const DataLayout &Other);
296291
297292 /// Set the target triple.
298293 void setTargetTriple(StringRef T) { TargetTriple = T; }
191191 class InlineFunctionInfo {
192192 public:
193193 explicit InlineFunctionInfo(CallGraph *cg = nullptr,
194 const DataLayout *DL = nullptr,
195194 AliasAnalysis *AA = nullptr,
196195 AssumptionCacheTracker *ACT = nullptr)
197 : CG(cg), DL(DL), AA(AA), ACT(ACT) {}
196 : CG(cg), AA(AA), ACT(ACT) {}
198197
199198 /// CG - If non-null, InlineFunction will update the callgraph to reflect the
200199 /// changes it makes.
201200 CallGraph *CG;
202 const DataLayout *DL;
203201 AliasAnalysis *AA;
204202 AssumptionCacheTracker *ACT;
205203
461461 /// InitializeAliasAnalysis - Subclasses must call this method to initialize the
462462 /// AliasAnalysis interface before any other methods are called.
463463 ///
464 void AliasAnalysis::InitializeAliasAnalysis(Pass *P) {
465 DataLayoutPass *DLP = P->getAnalysisIfAvailable();
466 DL = DLP ? &DLP->getDataLayout() : nullptr;
464 void AliasAnalysis::InitializeAliasAnalysis(Pass *P, const DataLayout *NewDL) {
465 DL = NewDL;
467466 auto *TLIP = P->getAnalysisIfAvailable();
468467 TLI = TLIP ? &TLIP->getTLI() : nullptr;
469468 AA = &P->getAnalysis();
1313
1414 #include "llvm/Analysis/Passes.h"
1515 #include "llvm/Analysis/AliasAnalysis.h"
16 #include "llvm/IR/Module.h"
1617 #include "llvm/Pass.h"
1718 #include "llvm/Support/CommandLine.h"
1819 #include "llvm/Support/Debug.h"
7576
7677 bool runOnModule(Module &M) override {
7778 this->M = &M;
78 InitializeAliasAnalysis(this);
79 InitializeAliasAnalysis(this, &M.getDataLayout());
7980 return false;
8081 }
8182
4343 }
4444
4545 bool runOnModule(Module &M) override {
46 InitializeAliasAnalysis(this); // set up super class
46 InitializeAliasAnalysis(this, &M.getDataLayout()); // set up super class
4747
4848 for(Module::global_iterator I = M.global_begin(),
4949 E = M.global_end(); I != E; ++I) {
460460 initializeBasicAliasAnalysisPass(*PassRegistry::getPassRegistry());
461461 }
462462
463 void initializePass() override {
464 InitializeAliasAnalysis(this);
465 }
463 bool doInitialization(Module &M) override;
466464
467465 void getAnalysisUsage(AnalysisUsage &AU) const override {
468466 AU.addRequired();
812810 return true;
813811
814812 return false;
813 }
814
815 bool BasicAliasAnalysis::doInitialization(Module &M) {
816 InitializeAliasAnalysis(this, &M.getDataLayout());
817 return true;
815818 }
816819
817820 /// getModRefInfo - Check to see if the specified callsite can clobber the
239239 return QueryResult;
240240 }
241241
242 void initializePass() override { InitializeAliasAnalysis(this); }
242 bool doInitialization(Module &M) override;
243243 };
244244
245245 void FunctionHandle::removeSelfFromCache() {
10331033
10341034 return AliasAnalysis::NoAlias;
10351035 }
1036
1037 bool CFLAliasAnalysis::doInitialization(Module &M) {
1038 InitializeAliasAnalysis(this, &M.getDataLayout());
1039 return true;
1040 }
9595 }
9696
9797 bool runOnModule(Module &M) override {
98 InitializeAliasAnalysis(this);
98 InitializeAliasAnalysis(this, &M.getDataLayout());
9999
100100 // Find non-addr taken globals.
101101 AnalyzeGlobals(M);
395395 }
396396
397397 bool CallAnalyzer::visitPtrToInt(PtrToIntInst &I) {
398 const DataLayout *DL = I.getModule()->getDataLayout();
399398 // Propagate constants through ptrtoint.
400399 Constant *COp = dyn_cast(I.getOperand(0));
401400 if (!COp)
409408 // Track base/offset pairs when converted to a plain integer provided the
410409 // integer is large enough to represent the pointer.
411410 unsigned IntegerSize = I.getType()->getScalarSizeInBits();
412 if (DL && IntegerSize >= DL->getPointerSizeInBits()) {
411 const DataLayout &DL = I.getModule()->getDataLayout();
412 if (IntegerSize >= DL.getPointerSizeInBits()) {
413413 std::pair BaseAndOffset
414414 = ConstantOffsetPtrs.lookup(I.getOperand(0));
415415 if (BaseAndOffset.first)
432432 }
433433
434434 bool CallAnalyzer::visitIntToPtr(IntToPtrInst &I) {
435 const DataLayout *DL = I.getModule()->getDataLayout();
436435 // Propagate constants through ptrtoint.
437436 Constant *COp = dyn_cast(I.getOperand(0));
438437 if (!COp)
447446 // modifications provided the integer is not too large.
448447 Value *Op = I.getOperand(0);
449448 unsigned IntegerSize = Op->getType()->getScalarSizeInBits();
450 if (DL && IntegerSize <= DL->getPointerSizeInBits()) {
449 const DataLayout &DL = I.getModule()->getDataLayout();
450 if (IntegerSize <= DL.getPointerSizeInBits()) {
451451 std::pair BaseAndOffset = ConstantOffsetPtrs.lookup(Op);
452452 if (BaseAndOffset.first)
453453 ConstantOffsetPtrs[&I] = BaseAndOffset;
13321332 DEBUG(llvm::dbgs() << " Analyzing call of " << Callee->getName()
13331333 << "...\n");
13341334
1335 CallAnalyzer CA(Callee->getParent()->getDataLayout(), TTIWP->getTTI(*Callee),
1335 CallAnalyzer CA(&Callee->getParent()->getDataLayout(), TTIWP->getTTI(*Callee),
13361336 ACT, *Callee, Threshold);
13371337 bool ShouldInline = CA.analyzeCall(CS);
13381338
2121 #include "llvm/IR/DerivedTypes.h"
2222 #include "llvm/IR/Dominators.h"
2323 #include "llvm/IR/Instructions.h"
24 #include "llvm/IR/Module.h"
2425 #include "llvm/IR/Type.h"
2526 #include "llvm/Support/Debug.h"
2627 #include "llvm/Support/raw_ostream.h"
252253 LI = &getAnalysis().getLoopInfo();
253254 DT = &getAnalysis().getDomTree();
254255 SE = &getAnalysis();
255 DataLayoutPass *DLP = getAnalysisIfAvailable();
256 DL = DLP ? &DLP->getDataLayout() : nullptr;
256 DL = &L->getHeader()->getModule()->getDataLayout();
257257
258258 // Find all uses of induction variables in this loop, and categorize
259259 // them by stride. Start by finding all of the PHI nodes in the header for
11161116 getAnalysisIfAvailable();
11171117 DT = DTWP ? &DTWP->getDomTree() : nullptr;
11181118
1119 DataLayoutPass *DLP = getAnalysisIfAvailable();
1120 DL = DLP ? &DLP->getDataLayout() : nullptr;
1119 DL = &F.getParent()->getDataLayout();
11211120
11221121 TLI = &getAnalysis().getTLI();
11231122
3535 AU.setPreservesAll(); // Does not transform code
3636 }
3737
38
38 bool LibCallAliasAnalysis::runOnFunction(Function &F) {
39 // set up super class
40 InitializeAliasAnalysis(this, &F.getParent()->getDataLayout());
41 return false;
42 }
3943
4044 /// AnalyzeLibCallDetails - Given a call to a function with the specified
4145 /// LibCallFunctionInfo, see if we can improve the mod/ref footprint of the call
183183 AA = &getAnalysis();
184184 AC = &getAnalysis().getAssumptionCache(F);
185185 DT = &getAnalysis().getDomTree();
186 DataLayoutPass *DLP = getAnalysisIfAvailable();
187 DL = DLP ? &DLP->getDataLayout() : nullptr;
186 DL = &F.getParent()->getDataLayout();
188187 TLI = &getAnalysis().getTLI();
189188 visit(F);
190189 dbgs() << MessagesStr.str();
178178
179179 // Try to get the DataLayout for this module. This may be null, in which case
180180 // the optimizations will be limited.
181 const DataLayout *DL = ScanBB->getModule()->getDataLayout();
181 const DataLayout &DL = ScanBB->getModule()->getDataLayout();
182182
183183 // Try to get the store size for the type.
184 uint64_t AccessSize = DL ? DL->getTypeStoreSize(AccessTy)
185 : AA ? AA->getTypeStoreSize(AccessTy) : 0;
184 uint64_t AccessSize = DL.getTypeStoreSize(AccessTy);
186185
187186 Value *StrippedPtr = Ptr->stripPointerCasts();
188187
207206 if (LoadInst *LI = dyn_cast(Inst))
208207 if (AreEquivalentAddressValues(
209208 LI->getPointerOperand()->stripPointerCasts(), StrippedPtr) &&
210 CastInst::isBitOrNoopPointerCastable(LI->getType(), AccessTy, DL)) {
209 CastInst::isBitOrNoopPointerCastable(LI->getType(), AccessTy, &DL)) {
211210 if (AATags)
212211 LI->getAAMetadata(*AATags);
213212 return LI;
220219 // those cases are unlikely.)
221220 if (AreEquivalentAddressValues(StorePtr, StrippedPtr) &&
222221 CastInst::isBitOrNoopPointerCastable(SI->getValueOperand()->getType(),
223 AccessTy, DL)) {
222 AccessTy, &DL)) {
224223 if (AATags)
225224 SI->getAAMetadata(*AATags);
226225 return SI->getOperand(0);
13591359
13601360 bool LoopAccessAnalysis::runOnFunction(Function &F) {
13611361 SE = &getAnalysis();
1362 DL = F.getParent()->getDataLayout();
1362 DL = &F.getParent()->getDataLayout();
13631363 auto *TLIP = getAnalysisIfAvailable();
13641364 TLI = TLIP ? &TLIP->getTLI() : nullptr;
13651365 AA = &getAnalysis();
1313 #include "llvm/IR/DataLayout.h"
1414 #include "llvm/IR/InstIterator.h"
1515 #include "llvm/IR/LLVMContext.h"
16 #include "llvm/IR/Module.h"
1617 #include "llvm/Support/ErrorHandling.h"
1718 #include "llvm/Support/raw_ostream.h"
1819 using namespace llvm;
2627 initializeMemDerefPrinterPass(*PassRegistry::getPassRegistry());
2728 }
2829 void getAnalysisUsage(AnalysisUsage &AU) const override {
29 AU.addRequired();
3030 AU.setPreservesAll();
3131 }
3232 bool runOnFunction(Function &F) override;
4040 char MemDerefPrinter::ID = 0;
4141 INITIALIZE_PASS_BEGIN(MemDerefPrinter, "print-memderefs",
4242 "Memory Dereferenciblity of pointers in function", false, true)
43 INITIALIZE_PASS_DEPENDENCY(DataLayoutPass)
4443 INITIALIZE_PASS_END(MemDerefPrinter, "print-memderefs",
4544 "Memory Dereferenciblity of pointers in function", false, true)
4645
4948 }
5049
5150 bool MemDerefPrinter::runOnFunction(Function &F) {
52 const DataLayout *DL = &getAnalysis().getDataLayout();
51 const DataLayout &DL = F.getParent()->getDataLayout();
5352 for (auto &I: inst_range(F)) {
5453 if (LoadInst *LI = dyn_cast(&I)) {
5554 Value *PO = LI->getPointerOperand();
56 if (PO->isDereferenceablePointer(DL))
55 if (PO->isDereferenceablePointer(&DL))
5756 Vec.push_back(PO);
5857 }
5958 }
9292 bool MemoryDependenceAnalysis::runOnFunction(Function &F) {
9393 AA = &getAnalysis();
9494 AC = &getAnalysis().getAssumptionCache(F);
95 DataLayoutPass *DLP = getAnalysisIfAvailable();
96 DL = DLP ? &DLP->getDataLayout() : nullptr;
95 DL = &F.getParent()->getDataLayout();
9796 DominatorTreeWrapperPass *DTWP =
9897 getAnalysisIfAvailable();
9998 DT = DTWP ? &DTWP->getDomTree() : nullptr;
1515 #include "llvm/Analysis/AliasAnalysis.h"
1616 #include "llvm/IR/DataLayout.h"
1717 #include "llvm/IR/LLVMContext.h"
18 #include "llvm/IR/Module.h"
1819 #include "llvm/Pass.h"
1920 using namespace llvm;
2021
3233
3334 void getAnalysisUsage(AnalysisUsage &AU) const override {}
3435
35 void initializePass() override {
36 bool doInitialization(Module &M) override {
3637 // Note: NoAA does not call InitializeAliasAnalysis because it's
3738 // special and does not support chaining.
38 DataLayoutPass *DLP = getAnalysisIfAvailable();
39 DL = DLP ? &DLP->getDataLayout() : nullptr;
39 DL = &M.getDataLayout();
40 return true;
4041 }
4142
4243 AliasResult alias(const Location &LocA, const Location &LocB) override {
79557955 this->F = &F;
79567956 AC = &getAnalysis().getAssumptionCache(F);
79577957 LI = &getAnalysis().getLoopInfo();
7958 DataLayoutPass *DLP = getAnalysisIfAvailable();
7959 DL = DLP ? &DLP->getDataLayout() : nullptr;
7958 DL = &F.getParent()->getDataLayout();
79607959 TLI = &getAnalysis().getTLI();
79617960 DT = &getAnalysis().getDomTree();
79627961 return false;
2121 #include "llvm/Analysis/Passes.h"
2222 #include "llvm/Analysis/AliasAnalysis.h"
2323 #include "llvm/Analysis/ScalarEvolutionExpressions.h"
24 #include "llvm/IR/Module.h"
2425 #include "llvm/Pass.h"
2526 using namespace llvm;
2627
7879
7980 bool
8081 ScalarEvolutionAliasAnalysis::runOnFunction(Function &F) {
81 InitializeAliasAnalysis(this);
82 InitializeAliasAnalysis(this, &F.getParent()->getDataLayout());
8283 SE = &getAnalysis();
8384 return false;
8485 }
7979 initializeScopedNoAliasAAPass(*PassRegistry::getPassRegistry());
8080 }
8181
82 void initializePass() override { InitializeAliasAnalysis(this); }
82 bool doInitialization(Module &M) override;
8383
8484 /// getAdjustedAnalysisPointer - This method is used when a pass implements
8585 /// an analysis interface through multiple inheritance. If needed, it
118118 return new ScopedNoAliasAA();
119119 }
120120
121 bool ScopedNoAliasAA::doInitialization(Module &M) {
122 InitializeAliasAnalysis(this, &M.getDataLayout());
123 return true;
124 }
125
121126 void
122127 ScopedNoAliasAA::getAnalysisUsage(AnalysisUsage &AU) const {
123128 AU.setPreservesAll();
276276 char TargetIRAnalysis::PassID;
277277
278278 TargetIRAnalysis::Result TargetIRAnalysis::getDefaultTTI(Function &F) {
279 return Result(F.getParent()->getDataLayout());
279 return Result(&F.getParent()->getDataLayout());
280280 }
281281
282282 // Register the basic pass.
281281 initializeTypeBasedAliasAnalysisPass(*PassRegistry::getPassRegistry());
282282 }
283283
284 void initializePass() override {
285 InitializeAliasAnalysis(this);
286 }
284 bool doInitialization(Module &M) override;
287285
288286 /// getAdjustedAnalysisPointer - This method is used when a pass implements
289287 /// an analysis interface through multiple inheritance. If needed, it
320318 return new TypeBasedAliasAnalysis();
321319 }
322320
321 bool TypeBasedAliasAnalysis::doInitialization(Module &M) {
322 InitializeAliasAnalysis(this, &M.getDataLayout());
323 return true;
324 }
325
323326 void
324327 TypeBasedAliasAnalysis::getAnalysisUsage(AnalysisUsage &AU) const {
325328 AU.setPreservesAll();
368368 Builder.SetInsertPoint(Entry->getFirstInsertionPt());
369369 Function *FrameAllocFn =
370370 Intrinsic::getDeclaration(M, Intrinsic::frameallocate);
371 uint64_t EHAllocSize = M->getDataLayout()->getTypeAllocSize(EHDataStructTy);
371 uint64_t EHAllocSize = M->getDataLayout().getTypeAllocSize(EHDataStructTy);
372372 Value *FrameAllocArgs[] = {
373373 ConstantInt::get(Type::getInt32Ty(Context), EHAllocSize)};
374374 CallInst *FrameAlloc =
537537 CloneAndPruneIntoFromInst(
538538 Handler, SrcFn, ++II, VMap,
539539 /*ModuleLevelChanges=*/false, Returns, "", &InlinedFunctionInfo,
540 SrcFn->getParent()->getDataLayout(), Director.get());
540 &SrcFn->getParent()->getDataLayout(), Director.get());
541541
542542 // Move all the instructions in the first cloned block into our entry block.
543543 BasicBlock *FirstClonedBB = std::next(Function::iterator(Entry));
136136
137137 legacy::PassManager PM;
138138
139 M->setDataLayout(TM->getDataLayout());
140 PM.add(new DataLayoutPass());
139 M->setDataLayout(*TM->getDataLayout());
141140
142141 // The RuntimeDyld will take ownership of this shortly
143142 SmallVector ObjBufferSV;
132132
133133 // If this module doesn't have a DataLayout attached then attach the
134134 // default.
135 if (!M->getDataLayout())
136 M->setDataLayout(getDataLayout());
135 if (M->getDataLayout().isDefault())
136 M->setDataLayout(*getDataLayout());
137137
138138 Modules.push_back(std::move(M));
139139 std::vector Ms;
3232 #include
3333 using namespace llvm;
3434
35 // Handle the Pass registration stuff necessary to use DataLayout's.
36
37 INITIALIZE_PASS(DataLayoutPass, "datalayout", "Data Layout", false, true)
38 char DataLayoutPass::ID = 0;
39
4035 //===----------------------------------------------------------------------===//
4136 // Support for StructLayout
4237 //===----------------------------------------------------------------------===//
220215 }
221216
222217 void DataLayout::parseSpecifier(StringRef Desc) {
218 StringRepresentation = Desc;
223219 while (!Desc.empty()) {
224220 // Split at '-'.
225221 std::pair Split = split(Desc, '-');
377373 init(M);
378374 }
379375
380 void DataLayout::init(const Module *M) {
381 const DataLayout *Other = M->getDataLayout();
382 if (Other)
383 *this = *Other;
384 else
385 reset("");
386 }
376 void DataLayout::init(const Module *M) { *this = M->getDataLayout(); }
387377
388378 bool DataLayout::operator==(const DataLayout &Other) const {
389379 bool Ret = BigEndian == Other.BigEndian &&
391381 ManglingMode == Other.ManglingMode &&
392382 LegalIntWidths == Other.LegalIntWidths &&
393383 Alignments == Other.Alignments && Pointers == Other.Pointers;
394 assert(Ret == (getStringRepresentation() == Other.getStringRepresentation()));
384 // Note: getStringRepresentation() might differs, it is not canonicalized
395385 return Ret;
396386 }
397387
566556 return L;
567557 }
568558
569 std::string DataLayout::getStringRepresentation() const {
570 std::string Result;
571 raw_string_ostream OS(Result);
572
573 OS << (BigEndian ? "E" : "e");
574
575 switch (ManglingMode) {
576 case MM_None:
577 break;
578 case MM_ELF:
579 OS << "-m:e";
580 break;
581 case MM_MachO:
582 OS << "-m:o";
583 break;
584 case MM_WINCOFF:
585 OS << "-m:w";
586 break;
587 case MM_Mips:
588 OS << "-m:m";
589 break;
590 }
591
592 for (const PointerAlignElem &PI : Pointers) {
593 // Skip default.
594 if (PI.AddressSpace == 0 && PI.ABIAlign == 8 && PI.PrefAlign == 8 &&
595 PI.TypeByteWidth == 8)
596 continue;
597
598 OS << "-p";
599 if (PI.AddressSpace) {
600 OS << PI.AddressSpace;
601 }
602 OS << ":" << PI.TypeByteWidth*8 << ':' << PI.ABIAlign*8;
603 if (PI.PrefAlign != PI.ABIAlign)
604 OS << ':' << PI.PrefAlign*8;
605 }
606
607 for (const LayoutAlignElem &AI : Alignments) {
608 if (std::find(std::begin(DefaultAlignments), std::end(DefaultAlignments),
609 AI) != std::end(DefaultAlignments))
610 continue;
611 OS << '-' << (char)AI.AlignType;
612 if (AI.TypeBitWidth)
613 OS << AI.TypeBitWidth;
614 OS << ':' << AI.ABIAlign*8;
615 if (AI.ABIAlign != AI.PrefAlign)
616 OS << ':' << AI.PrefAlign*8;
617 }
618
619 if (!LegalIntWidths.empty()) {
620 OS << "-n" << (unsigned)LegalIntWidths[0];
621
622 for (unsigned i = 1, e = LegalIntWidths.size(); i != e; ++i)
623 OS << ':' << (unsigned)LegalIntWidths[i];
624 }
625
626 if (StackNaturalAlign)
627 OS << "-S" << StackNaturalAlign*8;
628
629 return OS.str();
630 }
631559
632560 unsigned DataLayout::getPointerABIAlignment(unsigned AS) const {
633561 PointersTy::const_iterator I = findPointerLowerBound(AS);
843771 return Log2_32(getPreferredAlignment(GV));
844772 }
845773
846 DataLayoutPass::DataLayoutPass() : ImmutablePass(ID), DL("") {
847 initializeDataLayoutPassPass(*PassRegistry::getPassRegistry());
848 }
849
850 DataLayoutPass::~DataLayoutPass() {}
851
852 bool DataLayoutPass::doInitialization(Module &M) {
853 DL.init(&M);
854 return false;
855 }
856
857 bool DataLayoutPass::doFinalization(Module &M) {
858 DL.reset("");
859 return false;
860 }
364364
365365 void Module::setDataLayout(StringRef Desc) {
366366 DL.reset(Desc);
367
368 if (Desc.empty()) {
369 DataLayoutStr = "";
370 } else {
371 DataLayoutStr = DL.getStringRepresentation();
372 // DataLayoutStr is now equivalent to Desc, but since the representation
373 // is not unique, they may not be identical.
374 }
375 }
376
377 void Module::setDataLayout(const DataLayout *Other) {
378 if (!Other) {
379 DataLayoutStr = "";
380 DL.reset("");
381 } else {
382 DL = *Other;
383 DataLayoutStr = DL.getStringRepresentation();
384 }
385 }
386
387 const DataLayout *Module::getDataLayout() const {
388 if (DataLayoutStr.empty())
389 return nullptr;
390 return &DL;
391 }
367 }
368
369 void Module::setDataLayout(const DataLayout &Other) { DL = Other; }
370
371 const DataLayout &Module::getDataLayout() const { return DL; }
392372
393373 //===----------------------------------------------------------------------===//
394374 // Methods to control the materialization of GlobalValues in the Module.
528528 legacy::PassManager passes;
529529
530530 // Add an appropriate DataLayout instance for this module...
531 mergedModule->setDataLayout(TargetMach->getDataLayout());
532
533 passes.add(new DataLayoutPass());
531 mergedModule->setDataLayout(*TargetMach->getDataLayout());
532
534533 passes.add(
535534 createTargetTransformInfoWrapperPass(TargetMach->getTargetIRAnalysis()));
536535
566565
567566 legacy::PassManager codeGenPasses;
568567
569 codeGenPasses.add(new DataLayoutPass());
570
571568 formatted_raw_ostream Out(out);
572569
573570 // If the bitcode files contain ARC code and were compiled with optimization,
228228
229229 TargetMachine *target = march->createTargetMachine(TripleStr, CPU, FeatureStr,
230230 options);
231 M->setDataLayout(target->getDataLayout());
231 M->setDataLayout(*target->getDataLayout());
232232
233233 std::unique_ptr IRObj(
234234 new object::IRObjectFile(Buffer, std::move(M)));
671671 getComdatLeader(SrcM, ComdatName, SrcGV))
672672 return true;
673673
674 const DataLayout *DstDL = DstM->getDataLayout();
675 const DataLayout *SrcDL = SrcM->getDataLayout();
676 if (!DstDL || !SrcDL) {
677 return emitError(
678 "Linking COMDATs named '" + ComdatName +
679 "': can't do size dependent selection without DataLayout!");
680 }
674 const DataLayout &DstDL = DstM->getDataLayout();
675 const DataLayout &SrcDL = SrcM->getDataLayout();
681676 uint64_t DstSize =
682 DstDL->getTypeAllocSize(DstGV->getType()->getPointerElementType());
677 DstDL.getTypeAllocSize(DstGV->getType()->getPointerElementType());
683678 uint64_t SrcSize =
684 SrcDL->getTypeAllocSize(SrcGV->getType()->getPointerElementType());
679 SrcDL.getTypeAllocSize(SrcGV->getType()->getPointerElementType());
685680 if (Result == Comdat::SelectionKind::ExactMatch) {
686681 if (SrcGV->getInitializer() != DstGV->getInitializer())
687682 return emitError("Linking COMDATs named '" + ComdatName +
14811476
14821477 // Inherit the target data from the source module if the destination module
14831478 // doesn't have one already.
1484 if (!DstM->getDataLayout() && SrcM->getDataLayout())
1479 if (DstM->getDataLayout().isDefault())
14851480 DstM->setDataLayout(SrcM->getDataLayout());
14861481
1487 if (SrcM->getDataLayout() && DstM->getDataLayout() &&
1488 *SrcM->getDataLayout() != *DstM->getDataLayout()) {
1482 if (SrcM->getDataLayout() != DstM->getDataLayout()) {
14891483 emitWarning("Linking two modules of different data layouts: '" +
14901484 SrcM->getModuleIdentifier() + "' is '" +
14911485 SrcM->getDataLayoutStr() + "' whereas '" +
3535
3636 IRObjectFile::IRObjectFile(MemoryBufferRef Object, std::unique_ptr Mod)
3737 : SymbolicFile(Binary::ID_IR, Object), M(std::move(Mod)) {
38 // If we have a DataLayout, setup a mangler.
39 const DataLayout *DL = M->getDataLayout();
40 if (!DL)
41 return;
42
43 Mang.reset(new Mangler(DL));
38 // Setup a mangler with the DataLayout.
39 const DataLayout &DL = M->getDataLayout();
40 Mang.reset(new Mangler(&DL));
4441
4542 const std::string &InlineAsm = M->getModuleInlineAsm();
4643 if (InlineAsm.empty())
19801980 printEscapedString(mName);
19811981 Out << "\", getGlobalContext());";
19821982 if (!TheModule->getTargetTriple().empty()) {
1983 nl(Out) << "mod->setDataLayout(\"" << TheModule->getDataLayout() << "\");";
1983 nl(Out) << "mod->setDataLayout(\"" << TheModule->getDataLayoutStr()
1984 << "\");";
19841985 }
19851986 if (!TheModule->getTargetTriple().empty()) {
19861987 nl(Out) << "mod->setTargetTriple(\"" << TheModule->getTargetTriple()
3131 NVPTXAllocaHoisting() : FunctionPass(ID) {}
3232
3333 void getAnalysisUsage(AnalysisUsage &AU) const override {
34 AU.addRequired();
3534 AU.addPreserved();
3635 AU.addPreserved();
3736 }
2121 #include "llvm/IR/Intrinsics.h"
2222 #include "llvm/IR/LLVMContext.h"
2323 #include "llvm/IR/Module.h"
24 #include "llvm/Support/Debug.h"
25
26 #define DEBUG_TYPE "nvptx"
2427
2528 using namespace llvm;
2629
103106 SmallVector aggrMemcpys;
104107 SmallVector aggrMemsets;
105108
106 const DataLayout *DL = &getAnalysis().getDataLayout();
109 const DataLayout &DL = F.getParent()->getDataLayout();
107110 LLVMContext &Context = F.getParent()->getContext();
108111
109112 //
119122 if (load->hasOneUse() == false)
120123 continue;
121124
122 if (DL->getTypeStoreSize(load->getType()) < MaxAggrCopySize)
125 if (DL.getTypeStoreSize(load->getType()) < MaxAggrCopySize)
123126 continue;
124127
125128 User *use = load->user_back();
165168 StoreInst *store = dyn_cast(*load->user_begin());
166169 Value *srcAddr = load->getOperand(0);
167170 Value *dstAddr = store->getOperand(1);
168 unsigned numLoads = DL->getTypeStoreSize(load->getType());
171 unsigned numLoads = DL.getTypeStoreSize(load->getType());
169172 Value *len = ConstantInt::get(Type::getInt32Ty(Context), numLoads);
170173
171174 convertTransferToLoop(store, srcAddr, dstAddr, len, load->isVolatile(),
2828 NVPTXLowerAggrCopies() : FunctionPass(ID) {}
2929
3030 void getAnalysisUsage(AnalysisUsage &AU) const override {
31 AU.addRequired();
3231 AU.addPreserved();
3332 AU.addPreserved();
3433 }
170170 LI = &getAnalysis().getLoopInfo();
171171 SE = &getAnalysis();
172172 DT = &getAnalysis().getDomTree();
173 DataLayoutPass *DLP = getAnalysisIfAvailable();
174 DL = DLP ? &DLP->getDataLayout() : nullptr;
173 DL = &F.getParent()->getDataLayout();
175174 auto *TLIP = getAnalysisIfAvailable();
176175 LibInfo = TLIP ? &TLIP->getTLI() : nullptr;
177176
103103 bool PPCLoopDataPrefetch::runOnFunction(Function &F) {
104104 LI = &getAnalysis().getLoopInfo();
105105 SE = &getAnalysis();
106 DL = F.getParent()->getDataLayout();
106 DL = &F.getParent()->getDataLayout();
107107 AC = &getAnalysis().getAssumptionCache(F);
108108 TTI = &getAnalysis().getTTI(F);
109109
3535 #include "llvm/IR/Dominators.h"
3636 #include "llvm/IR/Function.h"
3737 #include "llvm/IR/IntrinsicInst.h"
38 #include "llvm/IR/Module.h"
3839 #include "llvm/Support/CommandLine.h"
3940 #include "llvm/Support/Debug.h"
4041 #include "llvm/Transforms/Scalar.h"
8384 PPCTargetMachine *TM;
8485 LoopInfo *LI;
8586 ScalarEvolution *SE;
86 const DataLayout *DL;
8787 };
8888 }
8989
140140 LI = &getAnalysis().getLoopInfo();
141141 SE = &getAnalysis();
142142
143 DataLayoutPass *DLP = getAnalysisIfAvailable();
144 DL = DLP ? &DLP->getDataLayout() : 0;
145
146143 bool MadeChange = false;
147144
148145 for (LoopInfo::iterator I = LI->begin(), E = LI->end();
156153
157154 bool PPCLoopPreIncPrep::runOnLoop(Loop *L) {
158155 bool MadeChange = false;
159
160 if (!DL)
161 return MadeChange;
162156
163157 // Only prep. the inner-most loop
164158 if (!L->empty())
8686 continue;
8787 if (Use->getParent()->getParent() == &F)
8888 LocalMemAvailable -=
89 Mod->getDataLayout()->getTypeAllocSize(GVTy->getElementType());
89 Mod->getDataLayout().getTypeAllocSize(GVTy->getElementType());
9090 }
9191 }
9292 }
275275 // value from the reqd_work_group_size function attribute if it is
276276 // available.
277277 unsigned WorkGroupSize = 256;
278 int AllocaSize = WorkGroupSize *
279 Mod->getDataLayout()->getTypeAllocSize(AllocaTy);
278 int AllocaSize =
279 WorkGroupSize * Mod->getDataLayout().getTypeAllocSize(AllocaTy);
280280
281281 if (AllocaSize > LocalMemAvailable) {
282282 DEBUG(dbgs() << " Not enough local memory to promote alloca.\n");
3333 }
3434
3535 void llvm::initializeTarget(PassRegistry &Registry) {
36 initializeDataLayoutPassPass(Registry);
3736 initializeTargetLibraryInfoWrapperPassPass(Registry);
3837 initializeTargetTransformInfoWrapperPassPass(Registry);
3938 }
4746 }
4847
4948 void LLVMAddTargetData(LLVMTargetDataRef TD, LLVMPassManagerRef PM) {
50 // The DataLayoutPass must now be in sync with the module. Unfortunatelly we
51 // cannot enforce that from the C api.
52 unwrap(PM)->add(new DataLayoutPass());
5349 }
5450
5551 void LLVMAddTargetLibraryInfo(LLVMTargetLibraryInfoRef TLI,
197197 *ErrorMessage = strdup(error.c_str());
198198 return true;
199199 }
200 Mod->setDataLayout(td);
201 pass.add(new DataLayoutPass());
200 Mod->setDataLayout(*td);
202201
203202 TargetMachine::CodeGenFileType ft;
204203 switch (codegen) {
108108 bool ArgPromotion::runOnSCC(CallGraphSCC &SCC) {
109109 bool Changed = false, LocalChange;
110110
111 DataLayoutPass *DLP = getAnalysisIfAvailable();
112 DL = DLP ? &DLP->getDataLayout() : nullptr;
113
114111 do { // Iterate until we stop promoting from this SCC.
115112 LocalChange = false;
116113 // Attempt to promote arguments from all functions in this SCC.
208205
209206 // Make sure that it is local to this module.
210207 if (!F || !F->hasLocalLinkage()) return nullptr;
208
209 DL = &F->getParent()->getDataLayout();
211210
212211 // First check: see if there are any pointer arguments! If not, quick exit.
213212 SmallVector PointerArgs;
102102 }
103103
104104 bool ConstantMerge::runOnModule(Module &M) {
105 DataLayoutPass *DLP = getAnalysisIfAvailable();
106 DL = DLP ? &DLP->getDataLayout() : nullptr;
105 DL = &M.getDataLayout();
107106
108107 // Find all the globals that are marked "used". These cannot be merged.
109108 SmallPtrSet UsedGlobals;
8585 const GlobalStatus &GS);
8686 bool OptimizeEmptyGlobalCXXDtors(Function *CXAAtExitFn);
8787
88 const DataLayout *DL;
88 // const DataLayout *DL;
8989 TargetLibraryInfo *TLI;
9090 SmallSet NotDiscardableComdats;
9191 };
268268 /// quick scan over the use list to clean up the easy and obvious cruft. This
269269 /// returns true if it made a change.
270270 static bool CleanupConstantGlobalUsers(Value *V, Constant *Init,
271 const DataLayout *DL,
271 const DataLayout &DL,
272272 TargetLibraryInfo *TLI) {
273273 bool Changed = false;
274274 // Note that we need to use a weak value handle for the worklist items. When
317317 // and will invalidate our notion of what Init is.
318318 Constant *SubInit = nullptr;
319319 if (!isa(GEP->getOperand(0))) {
320 ConstantExpr *CE =
321 dyn_cast_or_null(ConstantFoldInstruction(GEP, DL, TLI));
320 ConstantExpr *CE = dyn_cast_or_null(
321 ConstantFoldInstruction(GEP, &DL, TLI));
322322 if (Init && CE && CE->getOpcode() == Instruction::GetElementPtr)
323323 SubInit = ConstantFoldLoadThroughGEPConstantExpr(Init, CE);
324324
738738 /// if the loaded value is dynamically null, then we know that they cannot be
739739 /// reachable with a null optimize away the load.
740740 static bool OptimizeAwayTrappingUsesOfLoads(GlobalVariable *GV, Constant *LV,
741 const DataLayout *DL,
741 const DataLayout &DL,
742742 TargetLibraryInfo *TLI) {
743743 bool Changed = false;
744744
801801
802802 /// ConstantPropUsersOf - Walk the use list of V, constant folding all of the
803803 /// instructions that are foldable.
804 static void ConstantPropUsersOf(Value *V, const DataLayout *DL,
804 static void ConstantPropUsersOf(Value *V, const DataLayout &DL,
805805 TargetLibraryInfo *TLI) {
806806 for (Value::user_iterator UI = V->user_begin(), E = V->user_end(); UI != E; )
807807 if (Instruction *I = dyn_cast(*UI++))
808 if (Constant *NewC = ConstantFoldInstruction(I, DL, TLI)) {
808 if (Constant *NewC = ConstantFoldInstruction(I, &DL, TLI)) {
809809 I->replaceAllUsesWith(NewC);
810810
811811 // Advance UI to the next non-I use to avoid invalidating it!
821821 /// the specified malloc. Because it is always the result of the specified
822822 /// malloc, there is no reason to actually DO the malloc. Instead, turn the
823823 /// malloc into a global, and any loads of GV as uses of the new global.
824 static GlobalVariable *OptimizeGlobalAddressOfMalloc(GlobalVariable *GV,
825 CallInst *CI,
826 Type *AllocTy,
827 ConstantInt *NElements,
828 const DataLayout *DL,
829 TargetLibraryInfo *TLI) {
824 static GlobalVariable *
825 OptimizeGlobalAddressOfMalloc(GlobalVariable *GV, CallInst *CI, Type *AllocTy,
826 ConstantInt *NElements, const DataLayout &DL,
827 TargetLibraryInfo *TLI) {
830828 DEBUG(errs() << "PROMOTING GLOBAL: " << *GV << " CALL = " << *CI << '\n');
831829
832830 Type *GlobalType;
12701268 /// PerformHeapAllocSRoA - CI is an allocation of an array of structures. Break
12711269 /// it up into multiple allocations of arrays of the fields.
12721270 static GlobalVariable *PerformHeapAllocSRoA(GlobalVariable *GV, CallInst *CI,
1273 Value *NElems, const DataLayout *DL,
1271 Value *NElems, const DataLayout &DL,
12741272 const TargetLibraryInfo *TLI) {
12751273 DEBUG(dbgs() << "SROA HEAP ALLOC: " << *GV << " MALLOC = " << *CI << '\n');
12761274 Type *MAT = getMallocAllocatedType(CI, TLI);
13001298 GV->getThreadLocalMode());
13011299 FieldGlobals.push_back(NGV);
13021300
1303 unsigned TypeSize = DL->getTypeAllocSize(FieldTy);
1301 unsigned TypeSize = DL.getTypeAllocSize(FieldTy);
13041302 if (StructType *ST = dyn_cast(FieldTy))
1305 TypeSize = DL->getStructLayout(ST)->getSizeInBytes();
1306 Type *IntPtrTy = DL->getIntPtrType(CI->getType());
1303 TypeSize = DL.getStructLayout(ST)->getSizeInBytes();
1304 Type *IntPtrTy = DL.getIntPtrType(CI->getType());
13071305 Value *NMI = CallInst::CreateMalloc(CI, IntPtrTy, FieldTy,
13081306 ConstantInt::get(IntPtrTy, TypeSize),
13091307 NElems, nullptr,
14581456 /// TryToOptimizeStoreOfMallocToGlobal - This function is called when we see a
14591457 /// pointer global variable with a single value stored it that is a malloc or
14601458 /// cast of malloc.
1461 static bool TryToOptimizeStoreOfMallocToGlobal(GlobalVariable *GV,
1462 CallInst *CI,
1459 static bool TryToOptimizeStoreOfMallocToGlobal(GlobalVariable *GV, CallInst *CI,
14631460 Type *AllocTy,
14641461 AtomicOrdering Ordering,
14651462 Module::global_iterator &GVI,
1466 const DataLayout *DL,
1463 const DataLayout &DL,
14671464 TargetLibraryInfo *TLI) {
1468 if (!DL)
1469 return false;
1470
14711465 // If this is a malloc of an abstract type, don't touch it.
14721466 if (!AllocTy->isSized())
14731467 return false;
14951489 // This eliminates dynamic allocation, avoids an indirection accessing the
14961490 // data, and exposes the resultant global to further GlobalOpt.
14971491 // We cannot optimize the malloc if we cannot determine malloc array size.
1498 Value *NElems = getMallocArraySize(CI, DL, TLI, true);
1492 Value *NElems = getMallocArraySize(CI, &DL, TLI, true);
14991493 if (!NElems)
15001494 return false;
15011495
15031497 // Restrict this transformation to only working on small allocations
15041498 // (2048 bytes currently), as we don't want to introduce a 16M global or
15051499 // something.
1506 if (NElements->getZExtValue() * DL->getTypeAllocSize(AllocTy) < 2048) {
1500 if (NElements->getZExtValue() * DL.getTypeAllocSize(AllocTy) < 2048) {
15071501 GVI = OptimizeGlobalAddressOfMalloc(GV, CI, AllocTy, NElements, DL, TLI);
15081502 return true;
15091503 }
15331527 // If this is a fixed size array, transform the Malloc to be an alloc of
15341528 // structs. malloc [100 x struct],1 -> malloc struct, 100
15351529 if (ArrayType *AT = dyn_cast(getMallocAllocatedType(CI, TLI))) {
1536 Type *IntPtrTy = DL->getIntPtrType(CI->getType());
1537 unsigned TypeSize = DL->getStructLayout(AllocSTy)->getSizeInBytes();
1530 Type *IntPtrTy = DL.getIntPtrType(CI->getType());
1531 unsigned TypeSize = DL.getStructLayout(AllocSTy)->getSizeInBytes();
15381532 Value *AllocSize = ConstantInt::get(IntPtrTy, TypeSize);
15391533 Value *NumElements = ConstantInt::get(IntPtrTy, AT->getNumElements());
15401534 Instruction *Malloc = CallInst::CreateMalloc(CI, IntPtrTy, AllocSTy,
15491543 CI = cast(Malloc);
15501544 }
15511545
1552 GVI = PerformHeapAllocSRoA(GV, CI, getMallocArraySize(CI, DL, TLI, true),
1546 GVI = PerformHeapAllocSRoA(GV, CI, getMallocArraySize(CI, &DL, TLI, true),
15531547 DL, TLI);
15541548 return true;
15551549 }
15621556 static bool OptimizeOnceStoredGlobal(GlobalVariable *GV, Value *StoredOnceVal,
15631557 AtomicOrdering Ordering,
15641558 Module::global_iterator &GVI,
1565 const DataLayout *DL,
1559 const DataLayout &DL,
15661560 TargetLibraryInfo *TLI) {
15671561 // Ignore no-op GEPs and bitcasts.
15681562 StoredOnceVal = StoredOnceVal->stripPointerCasts();
17321726 bool GlobalOpt::ProcessInternalGlobal(GlobalVariable *GV,
17331727 Module::global_iterator &GVI,
17341728 const GlobalStatus &GS) {
1729 auto &DL = GV->getParent()->getDataLayout();
17351730 // If this is a first class global and has only one accessing function
17361731 // and this function is main (which we know is not recursive), we replace
17371732 // the global with a local alloca in this function.
18031798 ++NumMarked;
18041799 return true;
18051800 } else if (!GV->getInitializer()->getType()->isSingleValueType()) {
1806 if (DataLayoutPass *DLP = getAnalysisIfAvailable()) {
1807 const DataLayout &DL = DLP->getDataLayout();
1808 if (GlobalVariable *FirstNewGV = SRAGlobal(GV, DL)) {
1809 GVI = FirstNewGV; // Don't skip the newly produced globals!
1810 return true;
1811 }
1801 const DataLayout &DL = GV->getParent()->getDataLayout();
1802 if (GlobalVariable *FirstNewGV = SRAGlobal(GV, DL)) {
1803 GVI = FirstNewGV; // Don't skip the newly produced globals!
1804 return true;
18121805 }
18131806 } else if (GS.StoredType == GlobalStatus::StoredOnce) {
18141807 // If the initial value for the global was an undef value, and if only
19531946 // Simplify the initializer.
19541947 if (GV->hasInitializer())
19551948 if (ConstantExpr *CE = dyn_cast(GV->getInitializer())) {
1956 Constant *New = ConstantFoldConstantExpression(CE, DL, TLI);
1949 auto &DL = M.getDataLayout();
1950 Constant *New = ConstantFoldConstantExpression(CE, &DL, TLI);
19571951 if (New && New != CE)
19581952 GV->setInitializer(New);
19591953 }
19701964
19711965 static inline bool
19721966 isSimpleEnoughValueToCommit(Constant *C,
1973 SmallPtrSetImpl &SimpleConstants,
1974 const DataLayout *DL);
1975
1967 SmallPtrSetImpl &SimpleConstants,
1968 const DataLayout &DL);
19761969
19771970 /// isSimpleEnoughValueToCommit - Return true if the specified constant can be
19781971 /// handled by the code generator. We don't want to generate something like:
19821975 /// This function should be called if C was not found (but just got inserted)
19831976 /// in SimpleConstants to avoid having to rescan the same constants all the
19841977 /// time.
1985 static bool isSimpleEnoughValueToCommitHelper(Constant *C,
1986 SmallPtrSetImpl &SimpleConstants,
1987 const DataLayout *DL) {
1978 static bool
1979 isSimpleEnoughValueToCommitHelper(Constant *C,
1980 SmallPtrSetImpl &SimpleConstants,
1981 const DataLayout &DL) {
19881982 // Simple global addresses are supported, do not allow dllimport or
19891983 // thread-local globals.
19901984 if (auto *GV = dyn_cast(C))
20182012 case Instruction::PtrToInt:
20192013 // int <=> ptr is fine if the int type is the same size as the
20202014 // pointer type.
2021 if (!DL || DL->getTypeSizeInBits(CE->getType()) !=
2022 DL->getTypeSizeInBits(CE->getOperand(0)->getType()))
2015 if (DL.getTypeSizeInBits(CE->getType()) !=
2016 DL.getTypeSizeInBits(CE->getOperand(0)->getType()))
20232017 return false;
20242018 return isSimpleEnoughValueToCommit(CE->getOperand(0), SimpleConstants, DL);
20252019
20412035
20422036 static inline bool
20432037 isSimpleEnoughValueToCommit(Constant *C,
2044 SmallPtrSetImpl &SimpleConstants,
2045 const DataLayout *DL) {
2038 SmallPtrSetImpl &SimpleConstants,
2039 const DataLayout &DL) {
20462040 // If we already checked this constant, we win.
20472041 if (!SimpleConstants.insert(C).second)
20482042 return true;
21732167 /// Once an evaluation call fails, the evaluation object should not be reused.
21742168 class Evaluator {
21752169 public:
2176 Evaluator(const DataLayout *DL, const TargetLibraryInfo *TLI)
2177 : DL(DL), TLI(TLI) {
2170 Evaluator(const DataLayout &DL, const TargetLibraryInfo *TLI)
2171 : DL(DL), TLI(TLI) {
21782172 ValueStack.emplace_back();
21792173 }
21802174
22482242 /// simple enough to live in a static initializer of a global.
22492243 SmallPtrSet SimpleConstants;
22502244
2251 const DataLayout *DL;
2245 const DataLayout &DL;
22522246 const TargetLibraryInfo *TLI;
22532247 };
22542248
23012295 Constant *Ptr = getVal(SI->getOperand(1));
23022296 if (ConstantExpr *CE = dyn_cast(Ptr)) {
23032297 DEBUG(dbgs() << "Folding constant ptr expression: " << *Ptr);
2304 Ptr = ConstantFoldConstantExpression(CE, DL, TLI);
2298 Ptr = ConstantFoldConstantExpression(CE, &DL, TLI);
23052299 DEBUG(dbgs() << "; To: " << *Ptr << "\n");
23062300 }
23072301 if (!isSimpleEnoughPointerToCommit(Ptr)) {
23462340
23472341 Ptr = ConstantExpr::getGetElementPtr(Ptr, IdxList);
23482342 if (ConstantExpr *CE = dyn_cast(Ptr))
2349 Ptr = ConstantFoldConstantExpression(CE, DL, TLI);
2343 Ptr = ConstantFoldConstantExpression(CE, &DL, TLI);
23502344
23512345 // If we can't improve the situation by introspecting NewTy,
23522346 // we have to give up.
24212415
24222416 Constant *Ptr = getVal(LI->getOperand(0));
24232417 if (ConstantExpr *CE = dyn_cast(Ptr)) {
2424 Ptr = ConstantFoldConstantExpression(CE, DL, TLI);
2418 Ptr = ConstantFoldConstantExpression(CE, &DL, TLI);
24252419 DEBUG(dbgs() << "Found a constant pointer expression, constant "
24262420 "folding: " << *Ptr << "\n");
24272421 }
24972491 Value *Ptr = PtrArg->stripPointerCasts();
24982492 if (GlobalVariable *GV = dyn_cast(Ptr)) {
24992493 Type *ElemTy = cast(GV->getType())->getElementType();
2500 if (DL && !Size->isAllOnesValue() &&
2494 if (!Size->isAllOnesValue() &&
25012495 Size->getValue().getLimitedValue() >=
2502 DL->getTypeStoreSize(ElemTy)) {
2496 DL.getTypeStoreSize(ElemTy)) {
25032497 Invariants.insert(GV);
25042498 DEBUG(dbgs() << "Found a global var that is an invariant: " << *GV
25052499 << "\n");
26052599
26062600 if (!CurInst->use_empty()) {
26072601 if (ConstantExpr *CE = dyn_cast(InstResult))
2608 InstResult = ConstantFoldConstantExpression(CE, DL, TLI);
2602 InstResult = ConstantFoldConstantExpression(CE, &DL, TLI);
26092603
26102604 setVal(CurInst, InstResult);
26112605 }
26882682
26892683 /// EvaluateStaticConstructor - Evaluate static constructors in the function, if
26902684 /// we can. Return true if we can, false otherwise.
2691 static bool EvaluateStaticConstructor(Function *F, const DataLayout *DL,
2685 static bool EvaluateStaticConstructor(Function *F, const DataLayout &DL,
26922686 const TargetLibraryInfo *TLI) {
26932687 // Call the function.
26942688 Evaluator Eval(DL, TLI);
30393033 bool GlobalOpt::runOnModule(Module &M) {
30403034 bool Changed = false;
30413035
3042 DataLayoutPass *DLP = getAnalysisIfAvailable();
3043 DL = DLP ? &DLP->getDataLayout() : nullptr;
3036 auto &DL = M.getDataLayout();
30443037 TLI = &getAnalysis().getTLI();
30453038
30463039 bool LocalChange = true;
120120 /// any new allocas to the set if not possible.
121121 static bool InlineCallIfPossible(CallSite CS, InlineFunctionInfo &IFI,
122122 InlinedArrayAllocasTy &InlinedArrayAllocas,
123 int InlineHistory, bool InsertLifetime,
124 const DataLayout *DL) {
123 int InlineHistory, bool InsertLifetime) {
125124 Function *Callee = CS.getCalledFunction();
126125 Function *Caller = CS.getCaller();
127126
197196
198197 unsigned Align1 = AI->getAlignment(),
199198 Align2 = AvailableAlloca->getAlignment();
200 // If we don't have data layout information, and only one alloca is using
201 // the target default, then we can't safely merge them because we can't
202 // pick the greater alignment.
203 if (!DL && (!Align1 || !Align2) && Align1 != Align2)
204 continue;
205199
206200 // The available alloca has to be in the right function, not in some other
207201 // function in this SCC.
222216
223217 if (Align1 != Align2) {
224218 if (!Align1 || !Align2) {
225 assert(DL && "DataLayout required to compare default alignments");
226 unsigned TypeAlign = DL->getABITypeAlignment(AI->getAllocatedType());
219 const DataLayout &DL = Caller->getParent()->getDataLayout();
220 unsigned TypeAlign = DL.getABITypeAlignment(AI->getAllocatedType());
227221
228222 Align1 = Align1 ? Align1 : TypeAlign;
229223 Align2 = Align2 ? Align2 : TypeAlign;
431425 bool Inliner::runOnSCC(CallGraphSCC &SCC) {
432426 CallGraph &CG = getAnalysis().getCallGraph();
433427 AssumptionCacheTracker *ACT = &getAnalysis();
434 DataLayoutPass *DLP = getAnalysisIfAvailable();
435 const DataLayout *DL = DLP ? &DLP->getDataLayout() : nullptr;
436428 auto *TLIP = getAnalysisIfAvailable();
437429 const TargetLibraryInfo *TLI = TLIP ? &TLIP->getTLI() : nullptr;
438430 AliasAnalysis *AA = &getAnalysis();
494486
495487
496488 InlinedArrayAllocasTy InlinedArrayAllocas;
497 InlineFunctionInfo InlineInfo(&CG, DL, AA, ACT);
489 InlineFunctionInfo InlineInfo(&CG, AA, ACT);
498490
499491 // Now that we have all of the call sites, loop over them and inline them if
500492 // it looks profitable to do so.
552544
553545 // Attempt to inline the function.
554546 if (!InlineCallIfPossible(CS, InlineInfo, InlinedArrayAllocas,
555 InlineHistoryID, InsertLifetime, DL)) {
547 InlineHistoryID, InsertLifetime)) {
556548 emitOptimizationRemarkMissed(CallerCtx, DEBUG_TYPE, *Caller, DLoc,
557549 Twine(Callee->getName() +
558550 " will not be inlined into " +
233233
234234 bool LowerBitSets::doInitialization(Module &Mod) {
235235 M = &Mod;
236
237 DL = M->getDataLayout();
238 if (!DL)
239 report_fatal_error("Data layout required");
236 DL = &Mod.getDataLayout();
240237
241238 Int1Ty = Type::getInt1Ty(M->getContext());
242239 Int8Ty = Type::getInt8Ty(M->getContext());
12111211
12121212 bool MergeFunctions::runOnModule(Module &M) {
12131213 bool Changed = false;
1214 DataLayoutPass *DLP = getAnalysisIfAvailable();
1215 DL = DLP ? &DLP->getDataLayout() : nullptr;
1214 DL = &M.getDataLayout();
12161215
12171216 for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) {
12181217 if (!I->isDeclaration() && !I->hasAvailableExternallyLinkage())
29092909 return MadeIRChange;
29102910 }
29112911
2912 static bool combineInstructionsOverFunction(
2913 Function &F, InstCombineWorklist &Worklist, AssumptionCache &AC,
2914 TargetLibraryInfo &TLI, DominatorTree &DT, const DataLayout *DL = nullptr,
2915 LoopInfo *LI = nullptr) {
2912 static bool
2913 combineInstructionsOverFunction(Function &F, InstCombineWorklist &Worklist,
2914 AssumptionCache &AC, TargetLibraryInfo &TLI,
2915 DominatorTree &DT, LoopInfo *LI = nullptr) {
29162916 // Minimizing size?
29172917 bool MinimizeSize = F.hasFnAttribute(Attribute::MinSize);
2918 const DataLayout &DL = F.getParent()->getDataLayout();
29182919
29192920 /// Builder - This is an IRBuilder that automatically inserts new
29202921 /// instructions into the worklist when they are created.
29212922 IRBuilder Builder(
2922 F.getContext(), TargetFolder(DL), InstCombineIRInserter(Worklist, &AC));
2923 F.getContext(), TargetFolder(&DL), InstCombineIRInserter(Worklist, &AC));
29232924
29242925 // Lower dbg.declare intrinsics otherwise their value may be clobbered
29252926 // by instcombiner.
29332934 << F.getName() << "\n");
29342935
29352936 bool Changed = false;
2936 if (prepareICWorklistFromFunction(F, DL, &TLI, Worklist))
2937 if (prepareICWorklistFromFunction(F, &DL, &TLI, Worklist))
29372938 Changed = true;
29382939
2939 InstCombiner IC(Worklist, &Builder, MinimizeSize, &AC, &TLI, &DT, DL, LI);
2940 InstCombiner IC(Worklist, &Builder, MinimizeSize, &AC, &TLI, &DT, &DL, LI);
29402941 if (IC.run())
29412942 Changed = true;
29422943
29492950
29502951 PreservedAnalyses InstCombinePass::run(Function &F,
29512952 AnalysisManager *AM) {
2952 auto *DL = F.getParent()->getDataLayout();
2953
29542953 auto &AC = AM->getResult(F);
29552954 auto &DT = AM->getResult(F);
29562955 auto &TLI = AM->getResult(F);
29572956
29582957 auto *LI = AM->getCachedResult(F);
29592958
2960 if (!combineInstructionsOverFunction(F, Worklist, AC, TLI, DT, DL, LI))
2959 if (!combineInstructionsOverFunction(F, Worklist, AC, TLI, DT, LI))
29612960 // No changes, all analyses are preserved.
29622961 return PreservedAnalyses::all();
29632962
30063005 auto &DT = getAnalysis().getDomTree();
30073006
30083007 // Optional analyses.
3009 auto *DLP = getAnalysisIfAvailable();
3010 auto *DL = DLP ? &DLP->getDataLayout() : nullptr;
30113008 auto *LIWP = getAnalysisIfAvailable();
30123009 auto *LI = LIWP ? &LIWP->getLoopInfo() : nullptr;
30133010
3014 return combineInstructionsOverFunction(F, Worklist, AC, TLI, DT, DL, LI);
3011 return combineInstructionsOverFunction(F, Worklist, AC, TLI, DT, LI);
30153012 }
30163013
30173014 char InstructionCombiningPass::ID = 0;
391391 }
392392 void getAnalysisUsage(AnalysisUsage &AU) const override {
393393 AU.addRequired();
394 AU.addRequired();
395394 AU.addRequired();
396395 }
397396 uint64_t getAllocaSizeInBytes(AllocaInst *AI) const {
13201319 }
13211320
13221321 bool AddressSanitizerModule::runOnModule(Module &M) {
1323 DataLayoutPass *DLP = getAnalysisIfAvailable();
1324 if (!DLP) return false;
1325 DL = &DLP->getDataLayout();
1322 DL = &M.getDataLayout();
13261323 C = &(M.getContext());
13271324 int LongSize = DL->getPointerSizeInBits();
13281325 IntptrTy = Type::getIntNTy(*C, LongSize);
13981395 // virtual
13991396 bool AddressSanitizer::doInitialization(Module &M) {
14001397 // Initialize the private fields. No one has accessed them before.
1401 DataLayoutPass *DLP = getAnalysisIfAvailable();
1402 if (!DLP) report_fatal_error("data layout missing");
1403 DL = &DLP->getDataLayout();
1398 DL = &M.getDataLayout();
14041399
14051400 GlobalsMD.init(M);
14061401
4848 bool runOnFunction(Function &F) override;
4949
5050 void getAnalysisUsage(AnalysisUsage &AU) const override {
51 AU.addRequired();
5251 AU.addRequired();
5352 }
5453
164163 }
165164
166165 bool BoundsChecking::runOnFunction(Function &F) {
167 DL = &getAnalysis().getDataLayout();
166 DL = &F.getParent()->getDataLayout();
168167 TLI = &getAnalysis().getTLI();
169168
170169 TrapBB = nullptr;
421421 bool IsMIPS64 = TargetTriple.getArch() == llvm::Triple::mips64 ||
422422 TargetTriple.getArch() == llvm::Triple::mips64el;
423423
424 DataLayoutPass *DLP = getAnalysisIfAvailable();
425 if (!DLP)
426 report_fatal_error("data layout missing");
427 DL = &DLP->getDataLayout();
424 DL = &M.getDataLayout();
428425
429426 Mod = &M;
430427 Ctx = &M.getContext();
592589 }
593590
594591 bool DataFlowSanitizer::runOnModule(Module &M) {
595 if (!DL)
596 return false;
597592
598593 if (ABIList.isIn(M, "skip"))
599594 return false;
448448 ///
449449 /// inserts a call to __msan_init to the module's constructor list.
450450 bool MemorySanitizer::doInitialization(Module &M) {
451 DataLayoutPass *DLP = getAnalysisIfAvailable();
452 if (!DLP)
453 report_fatal_error("data layout missing");
454 DL = &DLP->getDataLayout();
451 DL = &M.getDataLayout();
455452
456453 Triple TargetTriple(M.getTargetTriple());
457454 switch (TargetTriple.getOS()) {
103103 return "SanitizerCoverageModule";
104104 }
105105
106 void getAnalysisUsage(AnalysisUsage &AU) const override {
107 AU.addRequired();
108 }
109
110106 private:
111107 void InjectCoverageForIndirectCalls(Function &F,
112108 ArrayRef IndirCalls);
143139 bool SanitizerCoverageModule::runOnModule(Module &M) {
144140 if (!CoverageLevel) return false;
145141 C = &(M.getContext());
146 DataLayoutPass *DLP = &getAnalysis();
147 IntptrTy = Type::getIntNTy(*C, DLP->getDataLayout().getPointerSizeInBits());
142 auto &DL = M.getDataLayout();
143 IntptrTy = Type::getIntNTy(*C, DL.getPointerSizeInBits());
148144 Type *VoidTy = Type::getVoidTy(*C);
149145 IRBuilder<> IRB(*C);
150146 Type *Int8PtrTy = PointerType::getUnqual(IRB.getInt8Ty());
229229 }
230230
231231 bool ThreadSanitizer::doInitialization(Module &M) {
232 DataLayoutPass *DLP = getAnalysisIfAvailable();
233 if (!DLP)
234 report_fatal_error("data layout missing");
235 DL = &DLP->getDataLayout();
232 DL = &M.getDataLayout();
236233
237234 // Always insert a call to __tsan_init into the module's CTORs.
238235 IRBuilder<> IRB(M.getContext());
4343
4444 ImmutablePass *llvm::createObjCARCAliasAnalysisPass() {
4545 return new ObjCARCAliasAnalysis();
46 }
47
48 bool ObjCARCAliasAnalysis::doInitialization(Module &M) {
49 InitializeAliasAnalysis(this, &M.getDataLayout());
50 return true;
4651 }
4752
4853 void
4343 }
4444
4545 private:
46 void initializePass() override {
47 InitializeAliasAnalysis(this);
48 }
46 bool doInitialization(Module &M) override;
4947
5048 /// This method is used when a pass implements an analysis interface through
5149 /// multiple inheritance. If needed, it should override this to adjust the
3131 #include "llvm/IR/IntrinsicInst.h"
3232 #include "llvm/IR/Intrinsics.h"
3333 #include "llvm/IR/DataLayout.h"
34 #include "llvm/IR/Module.h"
3435 #include "llvm/Support/Debug.h"
3536 #include "llvm/Support/raw_ostream.h"
3637 using namespace llvm;
412413 auto &AC = getAnalysis().getAssumptionCache(F);
413414 SE = &getAnalysis();
414415 DT = &getAnalysis().getDomTree();
415 DataLayoutPass *DLP = getAnalysisIfAvailable();
416 DL = DLP ? &DLP->getDataLayout() : nullptr;
416 DL = &F.getParent()->getDataLayout();
417417
418418 NewDestAlignments.clear();
419419 NewSrcAlignments.clear();
262262 return false;
263263
264264 AC = &getAnalysis().getAssumptionCache(F);
265 DL = F.getParent()->getDataLayout();
265 DL = &F.getParent()->getDataLayout();
266266 DT = &getAnalysis().getDomTree();
267267
268268 DenseMap AliveBits;
6767 WorkList.insert(&*i);
6868 }
6969 bool Changed = false;
70 DataLayoutPass *DLP = getAnalysisIfAvailable();
71 const DataLayout *DL = DLP ? &DLP->getDataLayout() : nullptr;
70 const DataLayout &DL = F.getParent()->getDataLayout();
7271 TargetLibraryInfo *TLI =
7372 &getAnalysis().getTLI();
7473
7776 WorkList.erase(WorkList.begin()); // Get an element from the worklist...
7877
7978 if (!I->use_empty()) // Don't muck with dead instructions...
80 if (Constant *C = ConstantFoldInstruction(I, DL, TLI)) {
79 if (Constant *C = ConstantFoldInstruction(I, &DL, TLI)) {
8180 // Add all of the users of this instruction to the worklist, they might
8281 // be constant propagatable now...
8382 for (User *U : I->users())
684684
685685 PreservedAnalyses EarlyCSEPass::run(Function &F,
686686 AnalysisManager *AM) {
687 const DataLayout *DL = F.getParent()->getDataLayout();
687 const DataLayout &DL = F.getParent()->getDataLayout();
688688
689689 auto &TLI = AM->getResult(F);
690690 auto &TTI = AM->getResult(F);
691691 auto &DT = AM->getResult(F);
692692 auto &AC = AM->getResult(F);
693693
694 EarlyCSE CSE(F, DL, TLI, TTI, DT, AC);
694 EarlyCSE CSE(F, &DL, TLI, TTI, DT, AC);
695695
696696 if (!CSE.run())
697697 return PreservedAnalyses::all();
723723 if (skipOptnoneFunction(F))
724724 return false;
725725
726 DataLayoutPass *DLP = getAnalysisIfAvailable();
727 auto *DL = DLP ? &DLP->getDataLayout() : nullptr;
726 auto &DL = F.getParent()->getDataLayout();
728727 auto &TLI = getAnalysis().getTLI();
729728 auto &TTI = getAnalysis().getTTI(F);
730729 auto &DT = getAnalysis().getDomTree();
731730 auto &AC = getAnalysis().getAssumptionCache(F);
732731
733 EarlyCSE CSE(F, DL, TLI, TTI, DT, AC);
732 EarlyCSE CSE(F, &DL, TLI, TTI, DT, AC);
734733
735734 return CSE.run();
736735 }
23562356 if (!NoLoads)
23572357 MD = &getAnalysis();
23582358 DT = &getAnalysis().getDomTree();
2359 DataLayoutPass *DLP = getAnalysisIfAvailable();
2360 DL = DLP ? &DLP->getDataLayout() : nullptr;
2359 DL = &F.getParent()->getDataLayout();
23612360 AC = &getAnalysis().getAssumptionCache(F);
23622361 TLI = &getAnalysis().getTLI();
23632362 VN.setAliasAnalysis(&getAnalysis());
18951895 LI = &getAnalysis().getLoopInfo();
18961896 SE = &getAnalysis();
18971897 DT = &getAnalysis().getDomTree();
1898 DataLayoutPass *DLP = getAnalysisIfAvailable();
1899 DL = DLP ? &DLP->getDataLayout() : nullptr;
1898 DL = &L->getHeader()->getModule()->getDataLayout();
19001899 auto *TLIP = getAnalysisIfAvailable();
19011900 TLI = TLIP ? &TLIP->getTLI() : nullptr;
19021901 auto *TTIP = getAnalysisIfAvailable();
158158 return false;
159159
160160 DEBUG(dbgs() << "Jump threading on function '" << F.getName() << "'\n");
161 DataLayoutPass *DLP = getAnalysisIfAvailable();
162 DL = DLP ? &DLP->getDataLayout() : nullptr;
161 DL = &F.getParent()->getDataLayout();
163162 TLI = &getAnalysis().getTLI();
164163 LVI = &getAnalysis();
165164
4747 #include "llvm/IR/IntrinsicInst.h"
4848 #include "llvm/IR/LLVMContext.h"
4949 #include "llvm/IR/Metadata.h"
50 #include "llvm/IR/Module.h"
5051 #include "llvm/IR/PredIteratorCache.h"
5152 #include "llvm/Support/CommandLine.h"
5253 #include "llvm/Support/Debug.h"
180181 AA = &getAnalysis();
181182 DT = &getAnalysis().getDomTree();
182183
183 DataLayoutPass *DLP = getAnalysisIfAvailable();
184 DL = DLP ? &DLP->getDataLayout() : nullptr;
184 DL = &L->getHeader()->getModule()->getDataLayout();
185185 TLI = &getAnalysis().getTLI();
186186
187187 assert(L->isLCSSAForm(*DT) && "Loop is not in LCSSA form.");
2222 #include "llvm/IR/Function.h"
2323 #include "llvm/IR/Instructions.h"
2424 #include "llvm/IR/IRBuilder.h"
25 #include "llvm/IR/Module.h"
2526 #include "llvm/Support/Debug.h"
2627 #include "llvm/Support/MathExtras.h"
2728 #include "llvm/Support/raw_ostream.h"
8485 bool LoadCombine::doInitialization(Function &F) {
8586 DEBUG(dbgs() << "LoadCombine function: " << F.getName() << "\n");
8687 C = &F.getContext();
87 DataLayoutPass *DLP = getAnalysisIfAvailable();
88 if (!DLP) {
88 DL = &F.getParent()->getDataLayout();
89 if (!DL) {
8990 DEBUG(dbgs() << " Skipping LoadCombine -- no target data!\n");
9091 return false;
9192 }
92 DL = &DLP->getDataLayout();
9393 return true;
9494 }
9595
129129
130130 class LoopIdiomRecognize : public LoopPass {
131131 Loop *CurLoop;
132 const DataLayout *DL;
133132 DominatorTree *DT;
134133 ScalarEvolution *SE;
135134 TargetLibraryInfo *TLI;
138137 static char ID;
139138 explicit LoopIdiomRecognize() : LoopPass(ID) {
140139 initializeLoopIdiomRecognizePass(*PassRegistry::getPassRegistry());
141 DL = nullptr; DT = nullptr; SE = nullptr; TLI = nullptr; TTI = nullptr;
140 DT = nullptr;
141 SE = nullptr;
142 TLI = nullptr;
143 TTI = nullptr;
142144 }
143145
144146 bool runOnLoop(Loop *L, LPPassManager &LPM) override;
176178 AU.addRequired();
177179 AU.addRequired();
178180 AU.addRequired();
179 }
180
181 const DataLayout *getDataLayout() {
182 if (DL)
183 return DL;
184 DataLayoutPass *DLP = getAnalysisIfAvailable();
185 DL = DLP ? &DLP->getDataLayout() : nullptr;
186 return DL;
187181 }
188182
189183 DominatorTree *getDominatorTree() {
624618 if (BECst->getValue()->getValue() == 0)
625619 return false;
626620
627 // We require target data for now.
628 if (!getDataLayout())
629 return false;
630
631621 // set DT
632622 (void)getDominatorTree();
633623
741731 Value *StorePtr = SI->getPointerOperand();
742732
743733 // Reject stores that are so large that they overflow an unsigned.
744 uint64_t SizeInBits = DL->getTypeSizeInBits(StoredVal->getType());
734 auto &DL = CurLoop->getHeader()->getModule()->getDataLayout();
735 uint64_t SizeInBits = DL.getTypeSizeInBits(StoredVal->getType());
745736 if ((SizeInBits & 7) || (SizeInBits >> 32) != 0)
746737 return false;
747738
916907 // but it can be turned into memset_pattern if the target supports it.
917908 Value *SplatValue = isBytewiseValue(StoredVal);
918909 Constant *PatternValue = nullptr;
919
910 auto &DL = CurLoop->getHeader()->getModule()->getDataLayout();
920911 unsigned DestAS = DestPtr->getType()->getPointerAddressSpace();
921912
922913 // If we're allowed to form a memset, and the stored value would be acceptable
927918 CurLoop->isLoopInvariant(SplatValue)) {
928919 // Keep and use SplatValue.
929920 PatternValue = nullptr;
930 } else if (DestAS == 0 &&
931 TLI->has(LibFunc::memset_pattern16) &&
932 (PatternValue = getMemSetPatternValue(StoredVal, *DL))) {
921 } else if (DestAS == 0 && TLI->has(LibFunc::memset_pattern16) &&
922 (PatternValue = getMemSetPatternValue(StoredVal, DL))) {
933923 // Don't create memset_pattern16s with address spaces.
934924 // It looks like we can use PatternValue!
935925 SplatValue = nullptr;
970960
971961 // The # stored bytes is (BECount+1)*Size. Expand the trip count out to
972962 // pointer size if it isn't already.
973 Type *IntPtr = Builder.getIntPtrTy(DL, DestAS);
963 Type *IntPtr = Builder.getIntPtrTy(&DL, DestAS);
974964 BECount = SE->getTruncateOrZeroExtend(BECount, IntPtr);
975965
976966 const SCEV *NumBytesS = SE->getAddExpr(BECount, SE->getConstant(IntPtr, 1),
10841074
10851075 // The # stored bytes is (BECount+1)*Size. Expand the trip count out to
10861076 // pointer size if it isn't already.
1087 Type *IntPtrTy = Builder.getIntPtrTy(DL, SI->getPointerAddressSpace());
1077 auto &DL = CurLoop->getHeader()->getModule()->getDataLayout();
1078 Type *IntPtrTy = Builder.getIntPtrTy(&DL, SI->getPointerAddressSpace());
10881079 BECount = SE->getTruncateOrZeroExtend(BECount, IntPtrTy);
10891080
10901081 const SCEV *NumBytesS = SE->getAddExpr(BECount, SE->getConstant(IntPtrTy, 1),
7676 getAnalysisIfAvailable();
7777 DominatorTree *DT = DTWP ? &DTWP->getDomTree() : nullptr;
7878 LoopInfo *LI = &getAnalysis().getLoopInfo();
79 DataLayoutPass *DLP = getAnalysisIfAvailable();
80 const DataLayout *DL = DLP ? &DLP->getDataLayout() : nullptr;
79 const DataLayout *DL = &L->getHeader()->getModule()->getDataLayout();
8180 const TargetLibraryInfo *TLI =
8281 &getAnalysis().getTLI();
8382 auto &AC = getAnalysis().getAssumptionCache(
14761476 LI = &getAnalysis().getLoopInfo();
14771477 SE = &getAnalysis();
14781478 TLI = &getAnalysis().getTLI();
1479 DataLayoutPass *DLP = getAnalysisIfAvailable();
1480 DL = DLP ? &DLP->getDataLayout() : nullptr;
1479 DL = &L->getHeader()->getModule()->getDataLayout();
14811480 DT = &getAnalysis().getDomTree();
14821481
14831482 BasicBlock *Header = L->getHeader();
10761076
10771077 bool MadeChange = false;
10781078 MD = &getAnalysis();
1079 DataLayoutPass *DLP = getAnalysisIfAvailable();
1080 DL = DLP ? &DLP->getDataLayout() : nullptr;
1079 DL = &F.getParent()->getDataLayout();
10811080 TLI = &getAnalysis().getTLI();
10821081
10831082 // If we don't have at least memset and memcpy, there is little point of doing
153153 /// Constant Propagation.
154154 ///
155155 class SCCPSolver : public InstVisitor {
156 const DataLayout *DL;
156 const DataLayout &DL;
157157 const TargetLibraryInfo *TLI;
158158 SmallPtrSet BBExecutable; // The BBs that are executable.
159159 DenseMap ValueState; // The state each value is in.
205205 typedef std::pair Edge;
206206 DenseSet KnownFeasibleEdges;
207207 public:
208 SCCPSolver(const DataLayout *DL, const TargetLibraryInfo *tli)
209 : DL(DL), TLI(tli) {}
208 SCCPSolver(const DataLayout &DL, const TargetLibraryInfo *tli)
209 : DL(DL), TLI(tli) {}
210210
211211 /// MarkBlockExecutable - This method can be used by clients to mark all of
212212 /// the blocks that are known to be intrinsically live in the processed unit.
10691069 }
10701070
10711071 // Transform load from a constant into a constant if possible.
1072 if (Constant *C = ConstantFoldLoadFromConstPtr(Ptr, DL))
1072 if (Constant *C = ConstantFoldLoadFromConstPtr(Ptr, &DL))
10731073 return markConstant(IV, &I, C);
10741074
10751075 // Otherwise we cannot say for certain what value this load will produce.
15601560 return false;
15611561
15621562 DEBUG(dbgs() << "SCCP on function '" << F.getName() << "'\n");
1563 const DataLayoutPass *DLP = getAnalysisIfAvailable();
1564 const DataLayout *DL = DLP ? &DLP->getDataLayout() : nullptr;
1563 const DataLayout &DL = F.getParent()->getDataLayout();
15651564 const TargetLibraryInfo *TLI =
15661565 &getAnalysis().getTLI();
15671566 SCCPSolver Solver(DL, TLI);
16901689 }
16911690
16921691 bool IPSCCP::runOnModule(Module &M) {
1693 DataLayoutPass *DLP = getAnalysisIfAvailable();
1694 const DataLayout *DL = DLP ? &DLP->getDataLayout() : nullptr;
1692 const DataLayout &DL = M.getDataLayout();
16951693 const TargetLibraryInfo *TLI =
16961694 &getAnalysis().getTLI();
16971695 SCCPSolver Solver(DL, TLI);
44224422
44234423 DEBUG(dbgs() << "SROA function: " << F.getName() << "\n");
44244424 C = &F.getContext();
4425 DataLayoutPass *DLP = getAnalysisIfAvailable();
4426 if (!DLP) {
4427 DEBUG(dbgs() << " Skipping SROA -- no target data!\n");
4428 return false;
4429 }
4430 DL = &DLP->getDataLayout();
4425 DL = &F.getParent()->getDataLayout();
44314426 DominatorTreeWrapperPass *DTWP =
44324427 getAnalysisIfAvailable();
44334428 DT = DTWP ? &DTWP->getDomTree() : nullptr;
10311031 if (skipOptnoneFunction(F))
10321032 return false;
10331033
1034 DataLayoutPass *DLP = getAnalysisIfAvailable();
1035 DL = DLP ? &DLP->getDataLayout() : nullptr;
1034 DL = &F.getParent()->getDataLayout();
10361035
10371036 bool Changed = performPromotion(F);
10381037
247247 }
248248
249249 bool Scalarizer::runOnFunction(Function &F) {
250 DataLayoutPass *DLP = getAnalysisIfAvailable();
251 DL = DLP ? &DLP->getDataLayout() : nullptr;
250 DL = &F.getParent()->getDataLayout();
252251 for (Function::iterator BBI = F.begin(), BBE = F.end(); BBI != BBE; ++BBI) {
253252 BasicBlock *BB = BBI;
254253 for (BasicBlock::iterator II = BB->begin(), IE = BB->end(); II != IE;) {
311311 }
312312
313313 void getAnalysisUsage(AnalysisUsage &AU) const override {
314 AU.addRequired();
315314 AU.addRequired();
316315 AU.setPreservesCFG();
317316 }
318317
319318 bool doInitialization(Module &M) override {
320 DataLayoutPass *DLP = getAnalysisIfAvailable();
321 if (DLP == nullptr)
322 report_fatal_error("data layout missing");
323 DL = &DLP->getDataLayout();
319 DL = &M.getDataLayout();
324320 return false;
325321 }
326322
385381 "Split GEPs to a variadic base and a constant offset for better CSE", false,
386382 false)
387383 INITIALIZE_PASS_DEPENDENCY(TargetTransformInfoWrapperPass)
388 INITIALIZE_PASS_DEPENDENCY(DataLayoutPass)
389384 INITIALIZE_PASS_END(
390385 SeparateConstOffsetFromGEP, "separate-const-offset-from-gep",
391386 "Split GEPs to a variadic base and a constant offset for better CSE", false,
180180
181181 PreservedAnalyses SimplifyCFGPass::run(Function &F,
182182 AnalysisManager *AM) {
183 auto *DL = F.getParent()->getDataLayout();
183 auto &DL = F.getParent()->getDataLayout();
184184 auto &TTI = AM->getResult(F);
185185 auto &AC = AM->getResult(F);
186186
187 if (!simplifyFunctionCFG(F, TTI, DL, &AC, BonusInstThreshold))
187 if (!simplifyFunctionCFG(F, TTI, &DL, &AC, BonusInstThreshold))
188188 return PreservedAnalyses::none();
189189
190190 return PreservedAnalyses::all();
206206 &getAnalysis().getAssumptionCache(F);
207207 const TargetTransformInfo &TTI =
208208 getAnalysis().getTTI(F);
209 DataLayoutPass *DLP = getAnalysisIfAvailable();
210 const DataLayout *DL = DLP ? &DLP->getDataLayout() : nullptr;
211 return simplifyFunctionCFG(F, TTI, DL, AC, BonusInstThreshold);
209 const DataLayout &DL = F.getParent()->getDataLayout();
210 return simplifyFunctionCFG(F, TTI, &DL, AC, BonusInstThreshold);
212211 }
213212
214213 void getAnalysisUsage(AnalysisUsage &AU) const override {
2020 #include "llvm/IR/DataLayout.h"
2121 #include "llvm/IR/Dominators.h"
2222 #include "llvm/IR/IntrinsicInst.h"
23 #include "llvm/IR/Module.h"
2324 #include "llvm/Support/Debug.h"
2425 #include "llvm/Support/raw_ostream.h"
2526 using namespace llvm;
99100 DT = &getAnalysis().getDomTree();
100101 LI = &getAnalysis().getLoopInfo();
101102 AA = &getAnalysis();
102 DataLayoutPass *DLP = getAnalysisIfAvailable();
103 DL = DLP ? &DLP->getDataLayout() : nullptr;
103 DL = &F.getParent()->getDataLayout();
104104
105105 bool MadeChange, EverMadeChange = false;
106106
158158 if (skipOptnoneFunction(F))
159159 return false;
160160
161 DL = F.getParent()->getDataLayout();
161 DL = &F.getParent()->getDataLayout();
162162
163163 bool AllCallsAreTailCalls = false;
164164 bool Modified = markTails(F, AllCallsAreTailCalls);
621621 /// If the inlined function has non-byval align arguments, then
622622 /// add @llvm.assume-based alignment assumptions to preserve this information.
623623 static void AddAlignmentAssumptions(CallSite CS, InlineFunctionInfo &IFI) {
624 if (!PreserveAlignmentAssumptions || !IFI.DL)
624 if (!PreserveAlignmentAssumptions)
625625 return;
626 auto &DL = CS.getCaller()->getParent()->getDataLayout();
626627
627628 // To avoid inserting redundant assumptions, we should check for assumptions
628629 // already in the caller. To do this, we might need a DT of the caller.
644645 // If we can already prove the asserted alignment in the context of the
645646 // caller, then don't bother inserting the assumption.
646647 Value *Arg = CS.getArgument(I->getArgNo());
647 if (getKnownAlignment(Arg, IFI.DL,
648 &IFI.ACT->getAssumptionCache(*CalledFunc),
648 if (getKnownAlignment(Arg, &DL, &IFI.ACT->getAssumptionCache(*CalledFunc),
649649 CS.getInstruction(), &DT) >= Align)
650650 continue;
651651
652 IRBuilder<>(CS.getInstruction()).CreateAlignmentAssumption(*IFI.DL, Arg,
653 Align);
652 IRBuilder<>(CS.getInstruction())
653 .CreateAlignmentAssumption(DL, Arg, Align);
654654 }
655655 }
656656 }
725725 Type *AggTy = cast(Src->getType())->getElementType();
726726 IRBuilder<> Builder(InsertBlock->begin());
727727
728 Value *Size;
729 if (IFI.DL == nullptr)
730 Size = ConstantExpr::getSizeOf(AggTy);
731 else
732 Size = Builder.getInt64(IFI.DL->getTypeStoreSize(AggTy));
728 Value *Size = Builder.getInt64(M->getDataLayout().getTypeStoreSize(AggTy));
733729
734730 // Always generate a memcpy of alignment 1 here because we don't know
735731 // the alignment of the src pointer. Other optimizations can infer
760756
761757 // If the pointer is already known to be sufficiently aligned, or if we can
762758 // round it up to a larger alignment, then we don't need a temporary.
763 if (getOrEnforceKnownAlignment(Arg, ByValAlignment, IFI.DL,
759 auto &DL = Caller->getParent()->getDataLayout();
760 if (getOrEnforceKnownAlignment(Arg, ByValAlignment, &DL,
764761 &IFI.ACT->getAssumptionCache(*Caller),
765762 TheCall) >= ByValAlignment)
766763 return Arg;
770767 }
771768
772769 // Create the alloca. If we have DataLayout, use nice alignment.
773 unsigned Align = 1;
774 if (IFI.DL)
775 Align = IFI.DL->getPrefTypeAlignment(AggTy);
776
770 unsigned Align =
771 Caller->getParent()->getDataLayout().getPrefTypeAlignment(AggTy);
772
777773 // If the byval had an alignment specified, we *must* use at least that
778774 // alignment, as it is required by the byval argument (and uses of the
779775 // pointer inside the callee).
10071003 // Keep a list of pair (dst, src) to emit byval initializations.
10081004 SmallVector, 4> ByValInit;
10091005
1006 auto &DL = Caller->getParent()->getDataLayout();
1007
10101008 assert(CalledFunc->arg_size() == CS.arg_size() &&
10111009 "No varargs calls can be inlined!");
10121010
10411039 // have no dead or constant instructions leftover after inlining occurs
10421040 // (which can happen, e.g., because an argument was constant), but we'll be
10431041 // happy with whatever the cloner can do.
1044 CloneAndPruneFunctionInto(Caller, CalledFunc, VMap,
1042 CloneAndPruneFunctionInto(Caller, CalledFunc, VMap,
10451043 /*ModuleLevelChanges=*/false, Returns, ".i",
1046 &InlinedFunctionInfo, IFI.DL, TheCall);
1044 &InlinedFunctionInfo, &DL, TheCall);
10471045
10481046 // Remember the first block that is newly cloned over.
10491047 FirstNewBlock = LastBlock; ++FirstNewBlock;
10641062 CloneAliasScopeMetadata(CS, VMap);
10651063
10661064 // Add noalias metadata if necessary.
1067 AddAliasScopeMetadata(CS, VMap, IFI.DL, IFI.AA);
1065 AddAliasScopeMetadata(CS, VMap, &DL, IFI.AA);
10681066
10691067 // FIXME: We could register any cloned assumptions instead of clearing the
10701068 // whole function's cache.
11721170 ConstantInt *AllocaSize = nullptr;
11731171 if (ConstantInt *AIArraySize =
11741172 dyn_cast(AI->getArraySize())) {
1175 if (IFI.DL) {
1176 Type *AllocaType = AI->getAllocatedType();
1177 uint64_t AllocaTypeSize = IFI.DL->getTypeAllocSize(AllocaType);
1178 uint64_t AllocaArraySize = AIArraySize->getLimitedValue();
1179 assert(AllocaArraySize > 0 && "array size of AllocaInst is zero");
1180 // Check that array size doesn't saturate uint64_t and doesn't
1181 // overflow when it's multiplied by type size.
1182 if (AllocaArraySize != ~0ULL &&
1183 UINT64_MAX / AllocaArraySize >= AllocaTypeSize) {
1184 AllocaSize = ConstantInt::get(Type::getInt64Ty(AI->getContext()),
1185 AllocaArraySize * AllocaTypeSize);
1186 }
1173 auto &DL = Caller->getParent()->getDataLayout();
1174 Type *AllocaType = AI->getAllocatedType();
1175 uint64_t AllocaTypeSize = DL.getTypeAllocSize(AllocaType);
1176 uint64_t AllocaArraySize = AIArraySize->getLimitedValue();
1177 assert(AllocaArraySize > 0 && "array size of AllocaInst is zero");
1178 // Check that array size doesn't saturate uint64_t and doesn't
1179 // overflow when it's multiplied by type size.
1180 if (AllocaArraySize != ~0ULL &&
1181 UINT64_MAX / AllocaArraySize >= AllocaTypeSize) {
1182 AllocaSize = ConstantInt::get(Type::getInt64Ty(AI->getContext()),
1183 AllocaArraySize * AllocaTypeSize);
11871184 }
11881185 }
11891186
14441441 // the entries are the same or undef). If so, remove the PHI so it doesn't
14451442 // block other optimizations.
14461443 if (PHI) {
1447 if (Value *V = SimplifyInstruction(PHI, IFI.DL, nullptr, nullptr,
1444 auto &DL = Caller->getParent()->getDataLayout();
1445 if (Value *V = SimplifyInstruction(PHI, &DL, nullptr, nullptr,
14481446 &IFI.ACT->getAssumptionCache(*Caller))) {
14491447 PHI->replaceAllUsesWith(V);
14501448 PHI->eraseFromParent();
5656 #include "llvm/IR/Instructions.h"
5757 #include "llvm/IR/IntrinsicInst.h"
5858 #include "llvm/IR/LLVMContext.h"
59 #include "llvm/IR/Module.h"
5960 #include "llvm/IR/Type.h"
6061 #include "llvm/Support/Debug.h"
6162 #include "llvm/Transforms/Utils/BasicBlockUtils.h"
796797 LI = &getAnalysis().getLoopInfo();
797798 DT = &getAnalysis().getDomTree();
798799 SE = getAnalysisIfAvailable();
799 DataLayoutPass *DLP = getAnalysisIfAvailable();
800 DL = DLP ? &DLP->getDataLayout() : nullptr;
800 DL = &F.getParent()->getDataLayout();
801801 AC = &getAnalysis().getAssumptionCache(F);
802802
803803 // Simplify each loop nest in the function.
530530 if (!OuterL && !CompletelyUnroll)
531531 OuterL = L;
532532 if (OuterL) {
533 DataLayoutPass *DLP = PP->getAnalysisIfAvailable();
534 const DataLayout *DL = DLP ? &DLP->getDataLayout() : nullptr;
535 simplifyLoop(OuterL, DT, LI, PP, /*AliasAnalysis*/ nullptr, SE, DL, AC);
533 const DataLayout &DL = F->getParent()->getDataLayout();
534 simplifyLoop(OuterL, DT, LI, PP, /*AliasAnalysis*/ nullptr, SE, &DL, AC);
536535
537536 // LCSSA must be performed on the outermost affected loop. The unrolled
538537 // loop's last loop latch is guaranteed to be in the outermost loop after
5050 const DominatorTreeWrapperPass *DTWP =
5151 getAnalysisIfAvailable();
5252 const DominatorTree *DT = DTWP ? &DTWP->getDomTree() : nullptr;
53 DataLayoutPass *DLP = getAnalysisIfAvailable();
54 const DataLayout *DL = DLP ? &DLP->getDataLayout() : nullptr;
53 const DataLayout &DL = F.getParent()->getDataLayout();
5554 const TargetLibraryInfo *TLI =
5655 &getAnalysis().getTLI();
5756 AssumptionCache *AC =
7271 continue;
7372 // Don't waste time simplifying unused instructions.
7473 if (!I->use_empty())
75 if (Value *V = SimplifyInstruction(I, DL, TLI, DT, AC)) {
74 if (Value *V = SimplifyInstruction(I, &DL, TLI, DT, AC)) {
7675 // Mark all uses for resimplification next time round the loop.
7776 for (User *U : I->users())
7877 Next->insert(cast(U));
3838 #include "llvm/IR/Intrinsics.h"
3939 #include "llvm/IR/LLVMContext.h"
4040 #include "llvm/IR/Metadata.h"
41 #include "llvm/IR/Module.h"
4142 #include "llvm/IR/Type.h"
4243 #include "llvm/IR/ValueHandle.h"
4344 #include "llvm/Pass.h"
205206 AA = &P->getAnalysis();
206207 DT = &P->getAnalysis().getDomTree();
207208 SE = &P->getAnalysis();
208 DataLayoutPass *DLP = P->getAnalysisIfAvailable();
209 DL = DLP ? &DLP->getDataLayout() : nullptr;
209 DL = &F.getParent()->getDataLayout();
210210 TTI = IgnoreTargetInfo
211211 ? nullptr
212212 : &P->getAnalysis().getTTI(F);
441441 AA = &getAnalysis();
442442 DT = &getAnalysis().getDomTree();
443443 SE = &getAnalysis();
444 DataLayoutPass *DLP = getAnalysisIfAvailable();
445 DL = DLP ? &DLP->getDataLayout() : nullptr;
444 DL = &BB.getModule()->getDataLayout();
446445 TTI = IgnoreTargetInfo
447446 ? nullptr
448447 : &getAnalysis().getTTI(
12731273
12741274 bool runOnFunction(Function &F) override {
12751275 SE = &getAnalysis();
1276 DataLayoutPass *DLP = getAnalysisIfAvailable();
1277 DL = DLP ? &DLP->getDataLayout() : nullptr;
1276 DL = &F.getParent()->getDataLayout();
12781277 LI = &getAnalysis().getLoopInfo();
12791278 TTI = &getAnalysis().getTTI(F);
12801279 DT = &getAnalysis().getDomTree();
30633063 return false;
30643064
30653065 SE = &getAnalysis();
3066 DataLayoutPass *DLP = getAnalysisIfAvailable();
3067 DL = DLP ? &DLP->getDataLayout() : nullptr;
3066 DL = &F.getParent()->getDataLayout();
30683067 TTI = &getAnalysis().getTTI(F);
30693068 auto *TLIP = getAnalysisIfAvailable();
30703069 TLI = TLIP ? &TLIP->getTLI() : nullptr;
88
99 ; AddRec: {{{(28 + (4 * (-4 + (3 * %m)) * %o) + %A),+,(8 * %m * %o)}<%for.i>,+,(12 * %o)}<%for.j>,+,20}<%for.k>
1010 ; CHECK: Base offset: %A
11 ; CHECK: ArrayDecl[UnknownSize][%m][%o] with elements of sizeof(i32) bytes.
11 ; CHECK: ArrayDecl[UnknownSize][%m][%o] with elements of 4 bytes.
1212 ; CHECK: ArrayRef[{3,+,2}<%for.i>][{-4,+,3}<%for.j>][{7,+,5}<%for.k>]
1313
1414 define void @foo(i64 %n, i64 %m, i64 %o, i32* nocapture %A) #0 {
2727
2828 ; AddRec: {{{(4 + (4 * (sext i32 %a.deps to i64) * (1 + (sext i32 %a.cols to i64))) + %a.base),+,(4 * (sext i32 %a.deps to i64) * (sext i32 %a.cols to i64))}<%for.i>,+,(4 * (sext i32 %a.deps to i64))}<%for.j>,+,4}<%for.k>
2929 ; CHECK: Base offset: %a.base
30 ; CHECK: ArrayDecl[UnknownSize][(sext i32 %a.cols to i64)][(sext i32 %a.deps to i64)] with elements of sizeof(float) bytes.
30 ; CHECK: ArrayDecl[UnknownSize][(sext i32 %a.cols to i64)][(sext i32 %a.deps to i64)] with elements of 4 bytes.
3131 ; CHECK: ArrayRef[{1,+,1}<%for.i>][{1,+,1}<%for.j>][{1,+,1}<%for.k>]
3232
3333 %struct.Mat = type { float*, i32, i32, i32, i32 }
2727
2828 ; AddRec: {{{(4 + (4 * (sext i32 %a.deps to i64) * (1 + (sext i32 %a.cols to i64))) + %a.base),+,(4 * (sext i32 %a.deps to i64) * (sext i32 %a.cols to i64))}<%for.i>,+,(4 * (sext i32 %a.deps to i64))}<%for.j>,+,4}<%for.k>
2929 ; CHECK: Base offset: %a.base
30 ; CHECK: ArrayDecl[UnknownSize][(sext i32 %a.cols to i64)][(sext i32 %a.deps to i64)] with elements of sizeof(float) bytes.
30 ; CHECK: ArrayDecl[UnknownSize][(sext i32 %a.cols to i64)][(sext i32 %a.deps to i64)] with elements of 4 bytes.
3131 ; CHECK: ArrayRef[{1,+,1}<%for.i>][{1,+,1}<%for.j>][{1,+,1}<%for.k>]
3232
3333 %struct.Mat = type { float*, i32, i32, i32, i32 }
77 ; A[2i+b][2j] = 1.0;
88 ; }
99
10 ; AddRec: {{((%m * %b * sizeof(double)) + %A),+,(2 * %m * sizeof(double))}<%for.i>,+,(2 * sizeof(double))}<%for.j>
10 ; AddRec: {{((%m * %b * 8) + %A),+,(2 * %m * 8)}<%for.i>,+,(2 * 8)}<%for.j>
1111 ; CHECK: Base offset: %A
12 ; CHECK: ArrayDecl[UnknownSize][%m] with elements of sizeof(double) bytes.
12 ; CHECK: ArrayDecl[UnknownSize][%m] with elements of 8 bytes.
1313 ; CHECK: ArrayRef[{%b,+,2}<%for.i>][{0,+,2}<%for.j>]
1414
1515
99
1010 ; AddRec: {{{(56 + (8 * (-4 + (3 * %m)) * %o) + %A),+,(8 * %m * %o)}<%for.i>,+,(8 * %o)}<%for.j>,+,8}<%for.k>
1111 ; CHECK: Base offset: %A
12 ; CHECK: ArrayDecl[UnknownSize][%m][%o] with elements of sizeof(double) bytes.
12 ; CHECK: ArrayDecl[UnknownSize][%m][%o] with elements of 8 bytes.
1313 ; CHECK: ArrayRef[{3,+,1}<%for.i>][{-4,+,1}<%for.j>][{7,+,1}<%for.k>]
1414
1515 define void @foo(i64 %n, i64 %m, i64 %o, double* %A) {
99
1010 ; AddRec: {{{(56 + (8 * (-4 + (3 * %m)) * (%o + %p)) + %A),+,(8 * (%o + %p) * %m)}<%for.cond4.preheader.lr.ph.us>,+,(8 * (%o + %p))}<%for.body6.lr.ph.us.us>,+,8}<%for.body6.us.us>
1111 ; CHECK: Base offset: %A
12 ; CHECK: ArrayDecl[UnknownSize][%m][(%o + %p)] with elements of sizeof(double) bytes.
12 ; CHECK: ArrayDecl[UnknownSize][%m][(%o + %p)] with elements of 8 bytes.
1313 ; CHECK: ArrayRef[{3,+,1}<%for.cond4.preheader.lr.ph.us>][{-4,+,1}<%for.body6.lr.ph.us.us>][{7,+,1}<%for.body6.us.us>]
1414
1515 define void @foo(i64 %n, i64 %m, i64 %o, i64 %p, double* nocapture %A) nounwind uwtable {
99
1010 ; AddRec: {{{((8 * ((((%m * %p) + %q) * %o) + %r)) + %A),+,(8 * %m * %o)}<%for.i>,+,(8 * %o)}<%for.j>,+,8}<%for.k>
1111 ; CHECK: Base offset: %A
12 ; CHECK: ArrayDecl[UnknownSize][%m][%o] with elements of sizeof(double) bytes.
12 ; CHECK: ArrayDecl[UnknownSize][%m][%o] with elements of 8 bytes.
1313 ; CHECK: ArrayRef[{%p,+,1}<%for.i>][{%q,+,1}<%for.j>][{%r,+,1}<%for.k>]
1414
1515 define void @foo(i64 %n, i64 %m, i64 %o, double* %A, i64 %p, i64 %q, i64 %r) {
99
1010 ; Inst: %val = load double, double* %arrayidx
1111 ; In Loop with Header: for.j
12 ; AddRec: {{0,+,(%m * sizeof(double))}<%for.i>,+,sizeof(double)}<%for.j>
12 ; AddRec: {{0,+,(%m * 8)}<%for.i>,+,8}<%for.j>
1313 ; Base offset: %A
14 ; ArrayDecl[UnknownSize][%m] with elements of sizeof(double) bytes.
14 ; ArrayDecl[UnknownSize][%m] with elements of 8 bytes.
1515 ; ArrayRef[{0,+,1}<%for.i>][{0,+,1}<%for.j>]
1616
1717 ; Inst: store double %val, double* %arrayidx
1818 ; In Loop with Header: for.j
1919 ; AddRec: {{%A,+,(8 * %m)}<%for.i>,+,8}<%for.j>
2020 ; CHECK: Base offset: %A
21 ; CHECK: ArrayDecl[UnknownSize][%m] with elements of sizeof(double) bytes.
21 ; CHECK: ArrayDecl[UnknownSize][%m] with elements of 8 bytes.
2222 ; CHECK: ArrayRef[{0,+,1}<%for.i>][{0,+,1}<%for.j>]
2323
2424 define void @foo(i64 %n, i64 %m, double* %A) {
99
1010 ; AddRec: {{{%A,+,(8 * %m * %o)}<%for.i>,+,(8 * %o)}<%for.j>,+,8}<%for.k>
1111 ; CHECK: Base offset: %A
12 ; CHECK: ArrayDecl[UnknownSize][%m][%o] with elements of sizeof(double) bytes.
12 ; CHECK: ArrayDecl[UnknownSize][%m][%o] with elements of 8 bytes.
1313 ; CHECK: ArrayRef[{0,+,1}<%for.i>][{0,+,1}<%for.j>][{0,+,1}<%for.k>]
1414
1515 define void @foo(i64 %n, i64 %m, i64 %o, double* %A) {
11
22 ; ScalarEvolution should be able to understand the loop and eliminate the casts.
33
4 ; CHECK: {%d,+,sizeof(i32)}
4 ; CHECK: {%d,+,4}
55
66 define void @foo(i32* nocapture %d, i32 %n) nounwind {
77 entry:
3838 ; count, it should say so.
3939
4040 ; PR7845
41 ; CHECK: Loop %for.cond: Unpredictable backedge-taken count.
41 ; CHECK: Loop %for.cond: Unpredictable backedge-taken count.
4242 ; CHECK: Loop %for.cond: max backedge-taken count is 5
4343
4444 @.str = private constant [4 x i8] c"%d\0A\00" ; <[4 x i8]*> [#uses=2]
100100
101101 ; PR19799: Indvars miscompile due to an incorrect max backedge taken count from SCEV.
102102 ; CHECK-LABEL: @pr19799
103 ; CHECK: Loop %for.body.i: Unpredictable backedge-taken count.
103 ; CHECK: Loop %for.body.i: Unpredictable backedge-taken count.
104104 ; CHECK: Loop %for.body.i: max backedge-taken count is 1
105105 @a = common global i32 0, align 4
106106
126126
127127 ; PR18886: Indvars miscompile due to an incorrect max backedge taken count from SCEV.
128128 ; CHECK-LABEL: @pr18886
129 ; CHECK: Loop %for.body: Unpredictable backedge-taken count.
129 ; CHECK: Loop %for.body: Unpredictable backedge-taken count.
130130 ; CHECK: Loop %for.body: max backedge-taken count is 3
131131 @aa = global i64 0, align 8
132132
156156 ; before the check is forever skipped.
157157 ;
158158 ; CHECK-LABEL: @cannot_compute_mustexit
159 ; CHECK: Loop %for.body.i: Unpredictable backedge-taken count.
160 ; CHECK: Loop %for.body.i: Unpredictable max backedge-taken count.
159 ; CHECK: Loop %for.body.i: Unpredictable backedge-taken count.
160 ; CHECK: Loop %for.body.i: Unpredictable max backedge-taken count.
161161 @b = common global i32 0, align 4
162162
163163 define i32 @cannot_compute_mustexit() {
185185 ; MaxBECount should be the minimum of them.
186186 ;
187187 ; CHECK-LABEL: @two_mustexit
188 ; CHECK: Loop %for.body.i: Unpredictable backedge-taken count.
188 ; CHECK: Loop %for.body.i: Unpredictable backedge-taken count.
189189 ; CHECK: Loop %for.body.i: max backedge-taken count is 1
190190 define i32 @two_mustexit() {
191191 entry:
44 ; older bitcode files.
55
66 ; Data Layout Test
7 ; CHECK: target datalayout = "e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-f80:32-n8:16:32-S32"
7 ; CHECK: target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v16:16:16-v24:32:32-v32:32:32-v48:64:64-v64:64:64-v96:128:128-v128:128:128-v192:256:256-v256:256:256-v512:512:512-v1024:1024:1024-a0:0:64-f80:32:32-n8:16:32-S32"
88 target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v16:16:16-v24:32:32-v32:32:32-v48:64:64-v64:64:64-v96:128:128-v128:128:128-v192:256:256-v256:256:256-v512:512:512-v1024:1024:1024-a0:0:64-f80:32:32-n8:16:32-S32"
99
1010 ; Module-Level Inline Assembly Test
0 ; RUN: opt < %s -O3 | \
11 ; RUN: llc -mtriple=thumbv7-apple-darwin10 -mattr=+neon | FileCheck %s
2
3 target datalayout = "e-p:32:32:32-i1:8:32-i8:8:32-i16:16:32-i32:32:32-i64:32:32-f32:32:32-f64:32:32-v64:64:64-v128:128:128-a0:0:32"
24
35 define void @fred(i32 %three_by_three, i8* %in, double %dt1, i32 %x_size, i32 %y_size, i8* %bp) nounwind {
46 entry:
+0
-5
test/Linker/comdat3.ll less more
None ; RUN: not llvm-link %s %p/Inputs/comdat2.ll -S -o - 2>&1 | FileCheck %s
1
2 $foo = comdat largest
3 @foo = global i32 43, comdat($foo)
4 ; CHECK: Linking COMDATs named 'foo': can't do size dependent selection without DataLayout!
0 ; REQUIRES: shell
1 ; RUN: llvm-link %s %S/Inputs/datalayout-a.ll -S -o - 2>%t.a.err | FileCheck %s
1 ; RUN: llvm-link %s %S/Inputs/datalayout-a.ll -S -o - 2>%t.a.err
22 ; RUN: (echo foo ;cat %t.a.err) | FileCheck --check-prefix=WARN-A %s
33
4 ; RUN: llvm-link %s %S/Inputs/datalayout-b.ll -S -o - 2>%t.b.err | FileCheck %s
4 ; RUN: llvm-link %s %S/Inputs/datalayout-b.ll -S -o - 2>%t.b.err
55 ; RUN: cat %t.b.err | FileCheck --check-prefix=WARN-B %s
66
77 target datalayout = "e"
88
9 ; CHECK: target datalayout = "e"
109
1110 ; WARN-A-NOT: WARNING
1211
None ; "PLAIN" - No optimizations. This tests the target-independent
0 ; "PLAIN" - No optimizations. This tests the default target layout
11 ; constant folder.
22 ; RUN: opt -S -o - < %s | FileCheck --check-prefix=PLAIN %s
33
4 ; "OPT" - Optimizations but no targetdata. This tests target-independent
4 ; "OPT" - Optimizations but no targetdata. This tests default target layout
55 ; folding in the optimizers.
66 ; RUN: opt -S -o - -instcombine -globalopt < %s | FileCheck --check-prefix=OPT %s
77
99 ; folding in the optimizers.
1010 ; RUN: opt -S -o - -instcombine -globalopt -default-data-layout="e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64" < %s | FileCheck --check-prefix=TO %s
1111
12 ; "SCEV" - ScalarEvolution but no targetdata.
12 ; "SCEV" - ScalarEvolution with default target layout
1313 ; RUN: opt -analyze -scalar-evolution < %s | FileCheck --check-prefix=SCEV %s
1414
1515
2323 ; PLAIN: @F1 = global i1* getelementptr (i1* inttoptr (i32 1 to i1*), i32 -2)
2424 ; PLAIN: @H8 = global i8* getelementptr (i8* null, i32 -1)
2525 ; PLAIN: @H1 = global i1* getelementptr (i1* null, i32 -1)
26 ; OPT: @G8 = global i8* getelementptr (i8* inttoptr (i32 1 to i8*), i32 -1)
27 ; OPT: @G1 = global i1* getelementptr (i1* inttoptr (i32 1 to i1*), i32 -1)
28 ; OPT: @F8 = global i8* getelementptr (i8* inttoptr (i32 1 to i8*), i32 -2)
29 ; OPT: @F1 = global i1* getelementptr (i1* inttoptr (i32 1 to i1*), i32 -2)
30 ; OPT: @H8 = global i8* getelementptr (i8* null, i32 -1)
31 ; OPT: @H1 = global i1* getelementptr (i1* null, i32 -1)
26 ; OPT: @G8 = global i8* null
27 ; OPT: @G1 = global i1* null
28 ; OPT: @F8 = global i8* inttoptr (i64 -1 to i8*)
29 ; OPT: @F1 = global i1* inttoptr (i64 -1 to i1*)
30 ; OPT: @H8 = global i8* inttoptr (i64 -1 to i8*)
31 ; OPT: @H1 = global i1* inttoptr (i64 -1 to i1*)
3232 ; TO: @G8 = global i8* null
3333 ; TO: @G1 = global i1* null
3434 ; TO: @F8 = global i8* inttoptr (i64 -1 to i8*)
5656 ; PLAIN: @g = constant i64 ptrtoint (double* getelementptr ({ i1, double }* null, i64 0, i32 1) to i64)
5757 ; PLAIN: @h = constant i64 ptrtoint (i1** getelementptr (i1** null, i32 1) to i64)
5858 ; PLAIN: @i = constant i64 ptrtoint (i1** getelementptr ({ i1, i1* }* null, i64 0, i32 1) to i64)
59 ; OPT: @a = constant i64 mul (i64 ptrtoint (double* getelementptr (double* null, i32 1) to i64), i64 2310)
60 ; OPT: @b = constant i64 ptrtoint (double* getelementptr ({ i1, double }* null, i64 0, i32 1) to i64)
61 ; OPT: @c = constant i64 mul (i64 ptrtoint (double* getelementptr (double* null, i32 1) to i64), i64 2)
62 ; OPT: @d = constant i64 mul (i64 ptrtoint (double* getelementptr (double* null, i32 1) to i64), i64 11)
63 ; OPT: @e = constant i64 ptrtoint (double* getelementptr ({ double, float, double, double }* null, i64 0, i32 2) to i64)
59 ; OPT: @a = constant i64 18480
60 ; OPT: @b = constant i64 8
61 ; OPT: @c = constant i64 16
62 ; OPT: @d = constant i64 88
63 ; OPT: @e = constant i64 16
6464 ; OPT: @f = constant i64 1
65 ; OPT: @g = constant i64 ptrtoint (double* getelementptr ({ i1, double }* null, i64 0, i32 1) to i64)
66 ; OPT: @h = constant i64 ptrtoint (i1** getelementptr (i1** null, i32 1) to i64)
67 ; OPT: @i = constant i64 ptrtoint (i1** getelementptr ({ i1, i1* }* null, i64 0, i32 1) to i64)
65 ; OPT: @g = constant i64 8
66 ; OPT: @h = constant i64 8
67 ; OPT: @i = constant i64 8
6868 ; TO: @a = constant i64 18480
6969 ; TO: @b = constant i64 8
7070 ; TO: @c = constant i64 16
9090 ; PLAIN: @M = constant i64* getelementptr (i64* null, i32 1)
9191 ; PLAIN: @N = constant i64* getelementptr ({ i64, i64 }* null, i32 0, i32 1)
9292 ; PLAIN: @O = constant i64* getelementptr ([2 x i64]* null, i32 0, i32 1)
93 ; OPT: @M = constant i64* getelementptr (i64* null, i32 1)
94 ; OPT: @N = constant i64* getelementptr ({ i64, i64 }* null, i32 0, i32 1)
95 ; OPT: @O = constant i64* getelementptr ([2 x i64]* null, i32 0, i32 1)
93 ; OPT: @M = constant i64* inttoptr (i64 8 to i64*)
94 ; OPT: @N = constant i64* inttoptr (i64 8 to i64*)
95 ; OPT: @O = constant i64* inttoptr (i64 8 to i64*)
9696 ; TO: @M = constant i64* inttoptr (i64 8 to i64*)
9797 ; TO: @N = constant i64* inttoptr (i64 8 to i64*)
9898 ; TO: @O = constant i64* inttoptr (i64 8 to i64*)
106106 ; PLAIN: @Y = global [3 x { i32, i32 }]* getelementptr inbounds ([3 x { i32, i32 }]* @ext, i64 2)
107107 ; PLAIN: @Z = global i32* getelementptr inbounds (i32* getelementptr inbounds ([3 x { i32, i32 }]* @ext, i64 0, i64 1, i32 0), i64 1)
108108 ; OPT: @Y = global [3 x { i32, i32 }]* getelementptr ([3 x { i32, i32 }]* @ext, i64 2)
109 ; OPT: @Z = global i32* getelementptr (i32* getelementptr inbounds ([3 x { i32, i32 }]* @ext, i64 0, i64 1, i32 0), i64 1)
109 ; OPT: @Z = global i32* getelementptr inbounds ([3 x { i32, i32 }]* @ext, i64 0, i64 1, i32 1)
110110 ; TO: @Y = global [3 x { i32, i32 }]* getelementptr ([3 x { i32, i32 }]* @ext, i64 2)
111111 ; TO: @Z = global i32* getelementptr inbounds ([3 x { i32, i32 }]* @ext, i64 0, i64 1, i32 1)
112112
142142 ; PLAIN: ret i1* %t
143143 ; PLAIN: }
144144 ; OPT: define i8* @goo8() #0 {
145 ; OPT: ret i8* getelementptr (i8* inttoptr (i32 1 to i8*), i32 -1)
145 ; OPT: ret i8* null
146146 ; OPT: }
147147 ; OPT: define i1* @goo1() #0 {
148 ; OPT: ret i1* getelementptr (i1* inttoptr (i32 1 to i1*), i32 -1)
148 ; OPT: ret i1* null
149149 ; OPT: }
150150 ; OPT: define i8* @foo8() #0 {
151 ; OPT: ret i8* getelementptr (i8* inttoptr (i32 1 to i8*), i32 -2)
151 ; OPT: ret i8* inttoptr (i64 -1 to i8*)
152152 ; OPT: }
153153 ; OPT: define i1* @foo1() #0 {
154 ; OPT: ret i1* getelementptr (i1* inttoptr (i32 1 to i1*), i32 -2)
154 ; OPT: ret i1* inttoptr (i64 -1 to i1*)
155155 ; OPT: }
156156 ; OPT: define i8* @hoo8() #0 {
157 ; OPT: ret i8* getelementptr (i8* null, i32 -1)
157 ; OPT: ret i8* inttoptr (i64 -1 to i8*)
158158 ; OPT: }
159159 ; OPT: define i1* @hoo1() #0 {
160 ; OPT: ret i1* getelementptr (i1* null, i32 -1)
160 ; OPT: ret i1* inttoptr (i64 -1 to i1*)
161161 ; OPT: }
162162 ; TO: define i8* @goo8() #0 {
163163 ; TO: ret i8* null
179179 ; TO: }
180180 ; SCEV: Classifying expressions for: @goo8
181181 ; SCEV: %t = bitcast i8* getelementptr (i8* inttoptr (i32 1 to i8*), i32 -1) to i8*
182 ; SCEV: --> ((-1 * sizeof(i8)) + inttoptr (i32 1 to i8*))
182 ; SCEV: --> (-1 + inttoptr (i32 1 to i8*))
183183 ; SCEV: Classifying expressions for: @goo1
184184 ; SCEV: %t = bitcast i1* getelementptr (i1* inttoptr (i32 1 to i1*), i32 -1) to i1*
185 ; SCEV: --> ((-1 * sizeof(i1)) + inttoptr (i32 1 to i1*))
185 ; SCEV: --> (-1 + inttoptr (i32 1 to i1*))
186186 ; SCEV: Classifying expressions for: @foo8
187187 ; SCEV: %t = bitcast i8* getelementptr (i8* inttoptr (i32 1 to i8*), i32 -2) to i8*
188 ; SCEV: --> ((-2 * sizeof(i8)) + inttoptr (i32 1 to i8*))
188 ; SCEV: --> (-2 + inttoptr (i32 1 to i8*))
189189 ; SCEV: Classifying expressions for: @foo1
190190 ; SCEV: %t = bitcast i1* getelementptr (i1* inttoptr (i32 1 to i1*), i32 -2) to i1*
191 ; SCEV: --> ((-2 * sizeof(i1)) + inttoptr (i32 1 to i1*))
191 ; SCEV: --> (-2 + inttoptr (i32 1 to i1*))
192192 ; SCEV: Classifying expressions for: @hoo8
193 ; SCEV: --> (-1 * sizeof(i8))
193 ; SCEV: --> -1
194194 ; SCEV: Classifying expressions for: @hoo1
195 ; SCEV: --> (-1 * sizeof(i1))
195 ; SCEV: --> -1
196196
197197 define i8* @goo8() nounwind {
198198 %t = bitcast i8* getelementptr (i8* inttoptr (i32 1 to i8*), i32 -1) to i8*
256256 ; PLAIN: ret i64 %t
257257 ; PLAIN: }
258258 ; OPT: define i64 @fa() #0 {
259 ; OPT: ret i64 mul (i64 ptrtoint (double* getelementptr (double* null, i32 1) to i64), i64 2310)
259 ; OPT: ret i64 18480
260260 ; OPT: }
261261 ; OPT: define i64 @fb() #0 {
262 ; OPT: ret i64 ptrtoint (double* getelementptr ({ i1, double }* null, i64 0, i32 1) to i64)
262 ; OPT: ret i64 8
263263 ; OPT: }
264264 ; OPT: define i64 @fc() #0 {
265 ; OPT: ret i64 mul (i64 ptrtoint (double* getelementptr (double* null, i32 1) to i64), i64 2)
265 ; OPT: ret i64 16
266266 ; OPT: }
267267 ; OPT: define i64 @fd() #0 {
268 ; OPT: ret i64 mul (i64 ptrtoint (double* getelementptr (double* null, i32 1) to i64), i64 11)
268 ; OPT: ret i64 88
269269 ; OPT: }
270270 ; OPT: define i64 @fe() #0 {
271 ; OPT: ret i64 ptrtoint (double* getelementptr ({ double, float, double, double }* null, i64 0, i32 2) to i64)
271 ; OPT: ret i64 16
272272 ; OPT: }
273273 ; OPT: define i64 @ff() #0 {
274274 ; OPT: ret i64 1
275275 ; OPT: }
276276 ; OPT: define i64 @fg() #0 {
277 ; OPT: ret i64 ptrtoint (double* getelementptr ({ i1, double }* null, i64 0, i32 1) to i64)
277 ; OPT: ret i64 8
278278 ; OPT: }
279279 ; OPT: define i64 @fh() #0 {
280 ; OPT: ret i64 ptrtoint (i1** getelementptr (i1** null, i32 1) to i64)
280 ; OPT: ret i64 8
281281 ; OPT: }
282282 ; OPT: define i64 @fi() #0 {
283 ; OPT: ret i64 ptrtoint (i1** getelementptr ({ i1, i1* }* null, i64 0, i32 1) to i64)
283 ; OPT: ret i64 8
284284 ; OPT: }
285285 ; TO: define i64 @fa() #0 {
286286 ; TO: ret i64 18480
310310 ; TO: ret i64 8
311311 ; TO: }
312312 ; SCEV: Classifying expressions for: @fa
313 ; SCEV: %t = bitcast i64 mul (i64 ptrtoint (double* getelementptr (double* null, i32 1) to i64), i64 2310) to i64
313 ; SCEV: %t = bitcast i64 mul (i64 ptrtoint (double* getelementptr (double* null, i32 1) to i64), i64 2310) to i64
314314 ; SCEV: --> (2310 * sizeof(double))
315315 ; SCEV: Classifying expressions for: @fb
316 ; SCEV: %t = bitcast i64 ptrtoint (double* getelementptr ({ i1, double }* null, i64 0, i32 1) to i64) to i64
316 ; SCEV: %t = bitcast i64 ptrtoint (double* getelementptr ({ i1, double }* null, i64 0, i32 1) to i64) to i64
317317 ; SCEV: --> alignof(double)
318318 ; SCEV: Classifying expressions for: @fc
319 ; SCEV: %t = bitcast i64 mul nuw (i64 ptrtoint (double* getelementptr (double* null, i32 1) to i64), i64 2) to i64
319 ; SCEV: %t = bitcast i64 mul nuw (i64 ptrtoint (double* getelementptr (double* null, i32 1) to i64), i64 2) to i64
320320 ; SCEV: --> (2 * sizeof(double))
321321 ; SCEV: Classifying expressions for: @fd
322 ; SCEV: %t = bitcast i64 mul nuw (i64 ptrtoint (double* getelementptr (double* null, i32 1) to i64), i64 11) to i64
322 ; SCEV: %t = bitcast i64 mul nuw (i64 ptrtoint (double* getelementptr (double* null, i32 1) to i64), i64 11) to i64
323323 ; SCEV: --> (11 * sizeof(double))
324324 ; SCEV: Classifying expressions for: @fe
325 ; SCEV: %t = bitcast i64 ptrtoint (double* getelementptr ({ double, float, double, double }* null, i64 0, i32 2) to i64) to i64
325 ; SCEV: %t = bitcast i64 ptrtoint (double* getelementptr ({ double, float, double, double }* null, i64 0, i32 2) to i64) to i64
326326 ; SCEV: --> offsetof({ double, float, double, double }, 2)
327327 ; SCEV: Classifying expressions for: @ff
328 ; SCEV: %t = bitcast i64 1 to i64
328 ; SCEV: %t = bitcast i64 1 to i64
329329 ; SCEV: --> 1
330330 ; SCEV: Classifying expressions for: @fg
331331 ; SCEV: %t = bitcast i64 ptrtoint (double* getelementptr ({ i1, double }* null, i64 0, i32 1) to i64) to i64
387387 ; PLAIN: ret i64* %t
388388 ; PLAIN: }
389389 ; OPT: define i64* @fM() #0 {
390 ; OPT: ret i64* getelementptr (i64* null, i32 1)
390 ; OPT: ret i64* inttoptr (i64 8 to i64*)
391391 ; OPT: }
392392 ; OPT: define i64* @fN() #0 {
393 ; OPT: ret i64* getelementptr ({ i64, i64 }* null, i32 0, i32 1)
393 ; OPT: ret i64* inttoptr (i64 8 to i64*)
394394 ; OPT: }
395395 ; OPT: define i64* @fO() #0 {
396 ; OPT: ret i64* getelementptr ([2 x i64]* null, i32 0, i32 1)
396 ; OPT: ret i64* inttoptr (i64 8 to i64*)
397397 ; OPT: }
398398 ; TO: define i64* @fM() #0 {
399399 ; TO: ret i64* inttoptr (i64 8 to i64*)
405405 ; TO: ret i64* inttoptr (i64 8 to i64*)
406406 ; TO: }
407407 ; SCEV: Classifying expressions for: @fM
408 ; SCEV: %t = bitcast i64* getelementptr (i64* null, i32 1) to i64*
409 ; SCEV: --> sizeof(i64)
408 ; SCEV: %t = bitcast i64* getelementptr (i64* null, i32 1) to i64*
409 ; SCEV: --> 8
410410 ; SCEV: Classifying expressions for: @fN
411 ; SCEV: %t = bitcast i64* getelementptr ({ i64, i64 }* null, i32 0, i32 1) to i64*
412 ; SCEV: --> sizeof(i64)
411 ; SCEV: %t = bitcast i64* getelementptr ({ i64, i64 }* null, i32 0, i32 1) to i64*
412 ; SCEV: --> 8
413413 ; SCEV: Classifying expressions for: @fO
414 ; SCEV: %t = bitcast i64* getelementptr ([2 x i64]* null, i32 0, i32 1) to i64*
415 ; SCEV: --> sizeof(i64)
414 ; SCEV: %t = bitcast i64* getelementptr ([2 x i64]* null, i32 0, i32 1) to i64*
415 ; SCEV: --> 8
416416
417417 define i64* @fM() nounwind {
418418 %t = bitcast i64* getelementptr (i64* null, i32 1) to i64*
432432 ; PLAIN: ret i32* %t
433433 ; PLAIN: }
434434 ; OPT: define i32* @fZ() #0 {
435 ; OPT: ret i32* getelementptr (i32* getelementptr inbounds ([3 x { i32, i32 }]* @ext, i64 0, i64 1, i32 0), i64 1)
435 ; OPT: ret i32* getelementptr inbounds ([3 x { i32, i32 }]* @ext, i64 0, i64 1, i32 1)
436436 ; OPT: }
437437 ; TO: define i32* @fZ() #0 {
438438 ; TO: ret i32* getelementptr inbounds ([3 x { i32, i32 }]* @ext, i64 0, i64 1, i32 1)
439439 ; TO: }
440440 ; SCEV: Classifying expressions for: @fZ
441441 ; SCEV: %t = bitcast i32* getelementptr inbounds (i32* getelementptr inbounds ([3 x { i32, i32 }]* @ext, i64 0, i64 1, i32 0), i64 1) to i32*
442 ; SCEV: --> ((3 * sizeof(i32)) + @ext)
442 ; SCEV: --> (12 + @ext)
443443
444444 define i32* @fZ() nounwind {
445445 %t = bitcast i32* getelementptr inbounds (i32* getelementptr inbounds ([3 x { i32, i32 }]* @ext, i64 0, i64 1, i32 0), i64 1) to i32*
456456 %p = getelementptr inbounds i8, i8* addrspacecast ([4 x i8] addrspace(12)* @p12 to i8*),
457457 i32 2
458458 ret i8* %p
459 ; OPT: ret i8* getelementptr (i8* addrspacecast (i8 addrspace(12)* getelementptr inbounds ([4 x i8] addrspace(12)* @p12, i32 0, i32 0) to i8*), i32 2)
459 ; OPT: ret i8* getelementptr ([4 x i8]* addrspacecast ([4 x i8] addrspace(12)* @p12 to [4 x i8]*), i64 0, i64 2)
460460 }
461461
462462 define i8* @same_addrspace() nounwind noinline {
463463 ; OPT: same_addrspace
464464 %p = getelementptr inbounds i8, i8* bitcast ([4 x i8] * @p0 to i8*), i32 2
465465 ret i8* %p
466 ; OPT: ret i8* getelementptr inbounds ([4 x i8]* @p0, i32 0, i32 2)
466 ; OPT: ret i8* getelementptr inbounds ([4 x i8]* @p0, i64 0, i64 2)
467467 }
468468
469469 @gv1 = internal global i32 1
0 ; RUN: opt -constmerge -S < %s | FileCheck %s
11 ; Test that in one run var3 is merged into var2 and var1 into var4.
2 ; Test that we merge @var5 and @var6 into one with the higher alignment, and
3 ; don't merge var7/var8 into var5/var6.
2 ; Test that we merge @var5 and @var6 into one with the higher alignment
43
54 declare void @zed(%struct.foobar*, %struct.foobar*)
65
2221 @var7 = internal constant [16 x i8] c"foo1bar2foo3bar\00"
2322 @var8 = private unnamed_addr constant [16 x i8] c"foo1bar2foo3bar\00"
2423
25 ; CHECK-NEXT: @var6 = private constant [16 x i8] c"foo1bar2foo3bar\00", align 16
26 ; CHECK-NEXT: @var8 = private constant [16 x i8] c"foo1bar2foo3bar\00"
24 ; CHECK-NEXT: @var7 = internal constant [16 x i8] c"foo1bar2foo3bar\00"
25 ; CHECK-NEXT: @var8 = private constant [16 x i8] c"foo1bar2foo3bar\00", align 16
2726
2827 @var4a = alias %struct.foobar* @var4
2928 @llvm.used = appending global [1 x %struct.foobar*] [%struct.foobar* @var4a], section "llvm.metadata"
2525 declare void @test(i8*)
2626
2727 define void @print() {
28 ; CHECK: %1 = load i8*, i8** getelementptr inbounds ([1 x %struct.ButtonInitData]* @_ZL14buttonInitData, i32 0, i32 0, i32 0), align 4
28 ; CHECK: %1 = load i8*, i8** @_ZL14buttonInitData.0.0, align 4
2929 %1 = load i8*, i8** getelementptr inbounds ([1 x %struct.ButtonInitData]* @_ZL14buttonInitData, i32 0, i32 0, i32 0), align 4
3030 call void @test(i8* %1)
3131 ret void
0 ; RUN: opt < %s -indvars -S | grep sext | count 1
11 ; ModuleID = ''
2
3 ; Provide legal integer types.
4 target datalayout = "n8:16:32:64"
5
26
37 %struct.App1Marker = type <{ i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }>
48 %struct.ComponentInstanceRecord = type <{ [1 x i32] }>
0 ; RUN: opt < %s -indvars -S | FileCheck %s
11 ; PR4086
2
3 ; Provide legal integer types.
4 target datalayout = "n8:16:32:64"
5
26 declare void @foo()
37
48 define void @test() {
0 ; RUN: opt < %s -indvars -S | FileCheck %s
1
2 ; Provide legal integer types.
3 target datalayout = "n8:16:32:64"
4
15
26 target triple = "x86_64-apple-darwin"
37
0 ;RUN: opt -S %s -indvars | FileCheck %s
1
2 ; Provide legal integer types.
3 target datalayout = "n8:16:32:64"
4
15
26 ; CHECK-LABEL: @foo(
37 ; CHECK-NOT: %lftr.wideiv = trunc i32 %indvars.iv.next to i16
None ; LFTR should eliminate the need for the computation of i*i completely. It
0 ; LFTR should eliminate the need for the computation of i*i completely. It
11 ; is only used to compute the exit value.
22 ; RUN: opt < %s -indvars -dce -S | not grep mul
3
4 ; Provide legal integer types.
5 target datalayout = "n8:16:32:64"
6
37
48 @A = external global i32 ; [#uses=1]
59
0 ; RUN: opt < %s -indvars -S | FileCheck %s
1
2 ; Provide legal integer types.
3 target datalayout = "n8:16:32:64"
4
15
26 @a = common global i32 0, align 4
37 @c = common global i32 0, align 4
22 ; Indvars should insert a 64-bit induction variable to eliminate the
33 ; sext for the addressing, however it shouldn't eliminate the sext
44 ; on the other phi, since that value undergoes signed wrapping.
5
6 ; Provide legal integer types.
7 target datalayout = "n8:16:32:64"
8
59
610 define void @foo(i32* nocapture %d, i32 %n) nounwind {
711 entry:
None ; RUN: opt < %s -indvars -S > %t
1 ; RUN: not grep sext %t
0 ; RUN: opt < %s -indvars -S | not grep sext
1
2 ; Provide legal integer types.
3 target datalayout = "n8:16:32:64"
4
25
36 define i64 @test(i64* nocapture %first, i32 %count) nounwind readonly {
47 entry:
0 ; RUN: opt < %s -indvars -S > %t
11 ; RUN: not grep sext %t
22 ; RUN: grep phi %t | count 1
3
4 ; Provide legal integer types.
5 target datalayout = "n8:16:32:64"
6
37
48 define void @foo(i64* nocapture %x, i32 %n) nounwind {
59 entry:
0 ; RUN: opt -S -indvars < %s | FileCheck %s
1
2 ; Provide legal integer types.
3 target datalayout = "n8:16:32:64"
4
15
26 define void @test1(float* nocapture %autoc, float* nocapture %data, float %d, i32 %data_len, i32 %sample) nounwind {
37 entry:
0 ; RUN: opt < %s -indvars -S | FileCheck %s
11 target triple = "aarch64--linux-gnu"
2
3 ; Provide legal integer types.
4 target datalayout = "n8:16:32:64"
5
26
37 ; Check the loop exit i32 compare instruction and operand are widened to i64
48 ; instead of truncating IV before its use in the i32 compare instruction.
+0
-88
test/Transforms/Inline/alloca-merge-align-nodl.ll less more
None ; RUN: opt < %s -inline -S | FileCheck %s
1 ; This variant of the test has no data layout information.
2 target triple = "powerpc64-unknown-linux-gnu"
3
4 %struct.s = type { i32, i32 }
5
6 define void @foo(%struct.s* byval nocapture readonly %a) {
7 entry:
8 %x = alloca [2 x i32], align 4
9 %a1 = getelementptr inbounds %struct.s, %struct.s* %a, i64 0, i32 0
10 %0 = load i32, i32* %a1, align 4
11 %arrayidx = getelementptr inbounds [2 x i32], [2 x i32]* %x, i64 0, i64 0
12 store i32 %0, i32* %arrayidx, align 4
13 %b = getelementptr inbounds %struct.s, %struct.s* %a, i64 0, i32 1
14 %1 = load i32, i32* %b, align 4
15 %arrayidx2 = getelementptr inbounds [2 x i32], [2 x i32]* %x, i64 0, i64 1
16 store i32 %1, i32* %arrayidx2, align 4
17 call void @bar(i32* %arrayidx) #2
18 ret void
19 }
20
21 define void @foo0(%struct.s* byval nocapture readonly %a) {
22 entry:
23 %x = alloca [2 x i32]
24 %a1 = getelementptr inbounds %struct.s, %struct.s* %a, i64 0, i32 0
25 %0 = load i32, i32* %a1, align 4
26 %arrayidx = getelementptr inbounds [2 x i32], [2 x i32]* %x, i64 0, i64 0
27 store i32 %0, i32* %arrayidx, align 4
28 %b = getelementptr inbounds %struct.s, %struct.s* %a, i64 0, i32 1
29 %1 = load i32, i32* %b, align 4
30 %arrayidx2 = getelementptr inbounds [2 x i32], [2 x i32]* %x, i64 0, i64 1
31 store i32 %1, i32* %arrayidx2, align 4
32 call void @bar(i32* %arrayidx) #2
33 ret void
34 }
35
36 declare void @bar(i32*) #1
37
38 define void @goo(%struct.s* byval nocapture readonly %a) {
39 entry:
40 %x = alloca [2 x i32], align 32
41 %a1 = getelementptr inbounds %struct.s, %struct.s* %a, i64 0, i32 0
42 %0 = load i32, i32* %a1, align 4
43 %arrayidx = getelementptr inbounds [2 x i32], [2 x i32]* %x, i64 0, i64 0
44 store i32 %0, i32* %arrayidx, align 32
45 %b = getelementptr inbounds %struct.s, %struct.s* %a, i64 0, i32 1
46 %1 = load i32, i32* %b, align 4
47 %arrayidx2 = getelementptr inbounds [2 x i32], [2 x i32]* %x, i64 0, i64 1
48 store i32 %1, i32* %arrayidx2, align 4
49 call void @bar(i32* %arrayidx) #2
50 ret void
51 }
52
53 ; CHECK-LABEL: @main
54 ; CHECK: alloca [2 x i32], align 32
55 ; CHECK-NOT: alloca [2 x i32]
56 ; CHECK: ret i32 0
57
58 define signext i32 @main() {
59 entry:
60 %a = alloca i64, align 8
61 %tmpcast = bitcast i64* %a to %struct.s*
62