llvm.org GIT mirror llvm / 3574eca
Move TargetData to DataLayout. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@165402 91177308-0d34-0410-b5e6-96231b3b80d8 Micah Villmow 7 years ago
229 changed file(s) with 952 addition(s) and 1005 deletion(s). Raw diff Collapse all Expand all
4444 class LoadInst;
4545 class StoreInst;
4646 class VAArgInst;
47 class TargetData;
47 class DataLayout;
4848 class TargetLibraryInfo;
4949 class Pass;
5050 class AnalysisUsage;
5454
5555 class AliasAnalysis {
5656 protected:
57 const TargetData *TD;
57 const DataLayout *TD;
5858 const TargetLibraryInfo *TLI;
5959
6060 private:
8282 /// know the sizes of the potential memory references.
8383 static uint64_t const UnknownSize = ~UINT64_C(0);
8484
85 /// getTargetData - Return a pointer to the current TargetData object, or
86 /// null if no TargetData object is available.
87 ///
88 const TargetData *getTargetData() const { return TD; }
85 /// getDataLayout - Return a pointer to the current DataLayout object, or
86 /// null if no DataLayout object is available.
87 ///
88 const DataLayout *getDataLayout() const { return TD; }
8989
9090 /// getTargetLibraryInfo - Return a pointer to the current TargetLibraryInfo
9191 /// object, or null if no TargetLibraryInfo object is available.
9292 ///
9393 const TargetLibraryInfo *getTargetLibraryInfo() const { return TLI; }
9494
95 /// getTypeStoreSize - Return the TargetData store size for the given type,
95 /// getTypeStoreSize - Return the DataLayout store size for the given type,
9696 /// if known, or a conservative value otherwise.
9797 ///
9898 uint64_t getTypeStoreSize(Type *Ty);
2121 class BasicBlock;
2222 class Function;
2323 class Instruction;
24 class TargetData;
24 class DataLayout;
2525 class Value;
2626
2727 /// \brief Check whether an instruction is likely to be "free" when lowered.
28 bool isInstructionFree(const Instruction *I, const TargetData *TD = 0);
28 bool isInstructionFree(const Instruction *I, const DataLayout *TD = 0);
2929
3030 /// \brief Check whether a call will lower to something small.
3131 ///
8484 NumRets(0) {}
8585
8686 /// \brief Add information about a block to the current state.
87 void analyzeBasicBlock(const BasicBlock *BB, const TargetData *TD = 0);
87 void analyzeBasicBlock(const BasicBlock *BB, const DataLayout *TD = 0);
8888
8989 /// \brief Add information about a function to the current state.
90 void analyzeFunction(Function *F, const TargetData *TD = 0);
90 void analyzeFunction(Function *F, const DataLayout *TD = 0);
9191 };
9292 }
9393
1111 //
1212 // Also, to supplement the basic VMCore ConstantExpr simplifications,
1313 // this file declares some additional folding routines that can make use of
14 // TargetData information. These functions cannot go in VMCore due to library
14 // DataLayout information. These functions cannot go in VMCore due to library
1515 // dependency issues.
1616 //
1717 //===----------------------------------------------------------------------===//
2323 class Constant;
2424 class ConstantExpr;
2525 class Instruction;
26 class TargetData;
26 class DataLayout;
2727 class TargetLibraryInfo;
2828 class Function;
2929 class Type;
3535 /// Note that this fails if not all of the operands are constant. Otherwise,
3636 /// this function can only fail when attempting to fold instructions like loads
3737 /// and stores, which have no constant expression form.
38 Constant *ConstantFoldInstruction(Instruction *I, const TargetData *TD = 0,
38 Constant *ConstantFoldInstruction(Instruction *I, const DataLayout *TD = 0,
3939 const TargetLibraryInfo *TLI = 0);
4040
4141 /// ConstantFoldConstantExpression - Attempt to fold the constant expression
42 /// using the specified TargetData. If successful, the constant result is
42 /// using the specified DataLayout. If successful, the constant result is
4343 /// result is returned, if not, null is returned.
4444 Constant *ConstantFoldConstantExpression(const ConstantExpr *CE,
45 const TargetData *TD = 0,
45 const DataLayout *TD = 0,
4646 const TargetLibraryInfo *TLI = 0);
4747
4848 /// ConstantFoldInstOperands - Attempt to constant fold an instruction with the
5353 ///
5454 Constant *ConstantFoldInstOperands(unsigned Opcode, Type *DestTy,
5555 ArrayRef Ops,
56 const TargetData *TD = 0,
56 const DataLayout *TD = 0,
5757 const TargetLibraryInfo *TLI = 0);
5858
5959 /// ConstantFoldCompareInstOperands - Attempt to constant fold a compare
6262 ///
6363 Constant *ConstantFoldCompareInstOperands(unsigned Predicate,
6464 Constant *LHS, Constant *RHS,
65 const TargetData *TD = 0,
65 const DataLayout *TD = 0,
6666 const TargetLibraryInfo *TLI = 0);
6767
6868 /// ConstantFoldInsertValueInstruction - Attempt to constant fold an insertvalue
7474 /// ConstantFoldLoadFromConstPtr - Return the value that a load from C would
7575 /// produce if it is constant and determinable. If this is not determinable,
7676 /// return null.
77 Constant *ConstantFoldLoadFromConstPtr(Constant *C, const TargetData *TD = 0);
77 Constant *ConstantFoldLoadFromConstPtr(Constant *C, const DataLayout *TD = 0);
7878
7979 /// ConstantFoldLoadThroughGEPConstantExpr - Given a constant and a
8080 /// getelementptr constantexpr, return the constant value being addressed by the
2727 class ScalarEvolution;
2828 class SCEV;
2929 class IVUsers;
30 class TargetData;
30 class DataLayout;
3131
3232 /// IVStrideUse - Keep track of one use of a strided induction variable.
3333 /// The Expr member keeps track of the expression, User is the actual user
122122 LoopInfo *LI;
123123 DominatorTree *DT;
124124 ScalarEvolution *SE;
125 TargetData *TD;
125 DataLayout *TD;
126126 SmallPtrSet Processed;
127127
128128 /// IVUses - A list of all tracked IV uses of induction variable expressions
2525 namespace llvm {
2626
2727 class CallSite;
28 class TargetData;
28 class DataLayout;
2929
3030 namespace InlineConstants {
3131 // Various magic constants used to adjust heuristics.
103103
104104 /// InlineCostAnalyzer - Cost analyzer used by inliner.
105105 class InlineCostAnalyzer {
106 // TargetData if available, or null.
107 const TargetData *TD;
106 // DataLayout if available, or null.
107 const DataLayout *TD;
108108
109109 public:
110110 InlineCostAnalyzer(): TD(0) {}
111111
112 void setTargetData(const TargetData *TData) { TD = TData; }
112 void setDataLayout(const DataLayout *TData) { TD = TData; }
113113
114114 /// \brief Get an InlineCost object representing the cost of inlining this
115115 /// callsite.
2323 class ArrayRef;
2424 class DominatorTree;
2525 class Instruction;
26 class TargetData;
26 class DataLayout;
2727 class TargetLibraryInfo;
2828 class Type;
2929 class Value;
3131 /// SimplifyAddInst - Given operands for an Add, see if we can
3232 /// fold the result. If not, this returns null.
3333 Value *SimplifyAddInst(Value *LHS, Value *RHS, bool isNSW, bool isNUW,
34 const TargetData *TD = 0,
34 const DataLayout *TD = 0,
3535 const TargetLibraryInfo *TLI = 0,
3636 const DominatorTree *DT = 0);
3737
3838 /// SimplifySubInst - Given operands for a Sub, see if we can
3939 /// fold the result. If not, this returns null.
4040 Value *SimplifySubInst(Value *LHS, Value *RHS, bool isNSW, bool isNUW,
41 const TargetData *TD = 0,
41 const DataLayout *TD = 0,
4242 const TargetLibraryInfo *TLI = 0,
4343 const DominatorTree *DT = 0);
4444
4545 /// SimplifyMulInst - Given operands for a Mul, see if we can
4646 /// fold the result. If not, this returns null.
47 Value *SimplifyMulInst(Value *LHS, Value *RHS, const TargetData *TD = 0,
47 Value *SimplifyMulInst(Value *LHS, Value *RHS, const DataLayout *TD = 0,
4848 const TargetLibraryInfo *TLI = 0,
4949 const DominatorTree *DT = 0);
5050
5151 /// SimplifySDivInst - Given operands for an SDiv, see if we can
5252 /// fold the result. If not, this returns null.
53 Value *SimplifySDivInst(Value *LHS, Value *RHS, const TargetData *TD = 0,
53 Value *SimplifySDivInst(Value *LHS, Value *RHS, const DataLayout *TD = 0,
5454 const TargetLibraryInfo *TLI = 0,
5555 const DominatorTree *DT = 0);
5656
5757 /// SimplifyUDivInst - Given operands for a UDiv, see if we can
5858 /// fold the result. If not, this returns null.
59 Value *SimplifyUDivInst(Value *LHS, Value *RHS, const TargetData *TD = 0,
59 Value *SimplifyUDivInst(Value *LHS, Value *RHS, const DataLayout *TD = 0,
6060 const TargetLibraryInfo *TLI = 0,
6161 const DominatorTree *DT = 0);
6262
6363 /// SimplifyFDivInst - Given operands for an FDiv, see if we can
6464 /// fold the result. If not, this returns null.
65 Value *SimplifyFDivInst(Value *LHS, Value *RHS, const TargetData *TD = 0,
65 Value *SimplifyFDivInst(Value *LHS, Value *RHS, const DataLayout *TD = 0,
6666 const TargetLibraryInfo *TLI = 0,
6767 const DominatorTree *DT = 0);
6868
6969 /// SimplifySRemInst - Given operands for an SRem, see if we can
7070 /// fold the result. If not, this returns null.
71 Value *SimplifySRemInst(Value *LHS, Value *RHS, const TargetData *TD = 0,
71 Value *SimplifySRemInst(Value *LHS, Value *RHS, const DataLayout *TD = 0,
7272 const TargetLibraryInfo *TLI = 0,
7373 const DominatorTree *DT = 0);
7474
7575 /// SimplifyURemInst - Given operands for a URem, see if we can
7676 /// fold the result. If not, this returns null.
77 Value *SimplifyURemInst(Value *LHS, Value *RHS, const TargetData *TD = 0,
77 Value *SimplifyURemInst(Value *LHS, Value *RHS, const DataLayout *TD = 0,
7878 const TargetLibraryInfo *TLI = 0,
7979 const DominatorTree *DT = 0);
8080
8181 /// SimplifyFRemInst - Given operands for an FRem, see if we can
8282 /// fold the result. If not, this returns null.
83 Value *SimplifyFRemInst(Value *LHS, Value *RHS, const TargetData *TD = 0,
83 Value *SimplifyFRemInst(Value *LHS, Value *RHS, const DataLayout *TD = 0,
8484 const TargetLibraryInfo *TLI = 0,
8585 const DominatorTree *DT = 0);
8686
8787 /// SimplifyShlInst - Given operands for a Shl, see if we can
8888 /// fold the result. If not, this returns null.
8989 Value *SimplifyShlInst(Value *Op0, Value *Op1, bool isNSW, bool isNUW,
90 const TargetData *TD = 0,
90 const DataLayout *TD = 0,
9191 const TargetLibraryInfo *TLI = 0,
9292 const DominatorTree *DT = 0);
9393
9494 /// SimplifyLShrInst - Given operands for a LShr, see if we can
9595 /// fold the result. If not, this returns null.
9696 Value *SimplifyLShrInst(Value *Op0, Value *Op1, bool isExact,
97 const TargetData *TD = 0,
97 const DataLayout *TD = 0,
9898 const TargetLibraryInfo *TLI = 0,
9999 const DominatorTree *DT = 0);
100100
101101 /// SimplifyAShrInst - Given operands for a AShr, see if we can
102102 /// fold the result. If not, this returns null.
103103 Value *SimplifyAShrInst(Value *Op0, Value *Op1, bool isExact,
104 const TargetData *TD = 0,
104 const DataLayout *TD = 0,
105105 const TargetLibraryInfo *TLI = 0,
106106 const DominatorTree *DT = 0);
107107
108108 /// SimplifyAndInst - Given operands for an And, see if we can
109109 /// fold the result. If not, this returns null.
110 Value *SimplifyAndInst(Value *LHS, Value *RHS, const TargetData *TD = 0,
110 Value *SimplifyAndInst(Value *LHS, Value *RHS, const DataLayout *TD = 0,
111111 const TargetLibraryInfo *TLI = 0,
112112 const DominatorTree *DT = 0);
113113
114114 /// SimplifyOrInst - Given operands for an Or, see if we can
115115 /// fold the result. If not, this returns null.
116 Value *SimplifyOrInst(Value *LHS, Value *RHS, const TargetData *TD = 0,
116 Value *SimplifyOrInst(Value *LHS, Value *RHS, const DataLayout *TD = 0,
117117 const TargetLibraryInfo *TLI = 0,
118118 const DominatorTree *DT = 0);
119119
120120 /// SimplifyXorInst - Given operands for a Xor, see if we can
121121 /// fold the result. If not, this returns null.
122 Value *SimplifyXorInst(Value *LHS, Value *RHS, const TargetData *TD = 0,
122 Value *SimplifyXorInst(Value *LHS, Value *RHS, const DataLayout *TD = 0,
123123 const TargetLibraryInfo *TLI = 0,
124124 const DominatorTree *DT = 0);
125125
126126 /// SimplifyICmpInst - Given operands for an ICmpInst, see if we can
127127 /// fold the result. If not, this returns null.
128128 Value *SimplifyICmpInst(unsigned Predicate, Value *LHS, Value *RHS,
129 const TargetData *TD = 0,
129 const DataLayout *TD = 0,
130130 const TargetLibraryInfo *TLI = 0,
131131 const DominatorTree *DT = 0);
132132
133133 /// SimplifyFCmpInst - Given operands for an FCmpInst, see if we can
134134 /// fold the result. If not, this returns null.
135135 Value *SimplifyFCmpInst(unsigned Predicate, Value *LHS, Value *RHS,
136 const TargetData *TD = 0,
136 const DataLayout *TD = 0,
137137 const TargetLibraryInfo *TLI = 0,
138138 const DominatorTree *DT = 0);
139139
140140 /// SimplifySelectInst - Given operands for a SelectInst, see if we can fold
141141 /// the result. If not, this returns null.
142142 Value *SimplifySelectInst(Value *Cond, Value *TrueVal, Value *FalseVal,
143 const TargetData *TD = 0,
143 const DataLayout *TD = 0,
144144 const TargetLibraryInfo *TLI = 0,
145145 const DominatorTree *DT = 0);
146146
147147 /// SimplifyGEPInst - Given operands for an GetElementPtrInst, see if we can
148148 /// fold the result. If not, this returns null.
149 Value *SimplifyGEPInst(ArrayRef Ops, const TargetData *TD = 0,
149 Value *SimplifyGEPInst(ArrayRef Ops, const DataLayout *TD = 0,
150150 const TargetLibraryInfo *TLI = 0,
151151 const DominatorTree *DT = 0);
152152
154154 /// can fold the result. If not, this returns null.
155155 Value *SimplifyInsertValueInst(Value *Agg, Value *Val,
156156 ArrayRef Idxs,
157 const TargetData *TD = 0,
157 const DataLayout *TD = 0,
158158 const TargetLibraryInfo *TLI = 0,
159159 const DominatorTree *DT = 0);
160160
161161 /// SimplifyTruncInst - Given operands for an TruncInst, see if we can fold
162162 /// the result. If not, this returns null.
163 Value *SimplifyTruncInst(Value *Op, Type *Ty, const TargetData *TD = 0,
163 Value *SimplifyTruncInst(Value *Op, Type *Ty, const DataLayout *TD = 0,
164164 const TargetLibraryInfo *TLI = 0,
165165 const DominatorTree *DT = 0);
166166
170170 /// SimplifyCmpInst - Given operands for a CmpInst, see if we can
171171 /// fold the result. If not, this returns null.
172172 Value *SimplifyCmpInst(unsigned Predicate, Value *LHS, Value *RHS,
173 const TargetData *TD = 0,
173 const DataLayout *TD = 0,
174174 const TargetLibraryInfo *TLI = 0,
175175 const DominatorTree *DT = 0);
176176
177177 /// SimplifyBinOp - Given operands for a BinaryOperator, see if we can
178178 /// fold the result. If not, this returns null.
179179 Value *SimplifyBinOp(unsigned Opcode, Value *LHS, Value *RHS,
180 const TargetData *TD = 0,
180 const DataLayout *TD = 0,
181181 const TargetLibraryInfo *TLI = 0,
182182 const DominatorTree *DT = 0);
183183
184184 /// SimplifyInstruction - See if we can compute a simplified version of this
185185 /// instruction. If not, this returns null.
186 Value *SimplifyInstruction(Instruction *I, const TargetData *TD = 0,
186 Value *SimplifyInstruction(Instruction *I, const DataLayout *TD = 0,
187187 const TargetLibraryInfo *TLI = 0,
188188 const DominatorTree *DT = 0);
189189
197197 ///
198198 /// The function returns true if any simplifications were performed.
199199 bool replaceAndRecursivelySimplify(Instruction *I, Value *SimpleV,
200 const TargetData *TD = 0,
200 const DataLayout *TD = 0,
201201 const TargetLibraryInfo *TLI = 0,
202202 const DominatorTree *DT = 0);
203203
208208 /// of the users impacted. It returns true if any simplifications were
209209 /// performed.
210210 bool recursivelySimplifyInstruction(Instruction *I,
211 const TargetData *TD = 0,
211 const DataLayout *TD = 0,
212212 const TargetLibraryInfo *TLI = 0,
213213 const DominatorTree *DT = 0);
214214 } // end namespace llvm
1818
1919 namespace llvm {
2020 class Constant;
21 class TargetData;
21 class DataLayout;
2222 class TargetLibraryInfo;
2323 class Value;
2424
2525 /// LazyValueInfo - This pass computes, caches, and vends lazy value constraint
2626 /// information.
2727 class LazyValueInfo : public FunctionPass {
28 class TargetData *TD;
28 class DataLayout *TD;
2929 class TargetLibraryInfo *TLI;
3030 void *PImpl;
3131 LazyValueInfo(const LazyValueInfo&) LLVM_DELETED_FUNCTION;
1818 namespace llvm {
1919
2020 class AliasAnalysis;
21 class TargetData;
21 class DataLayout;
2222 class MDNode;
2323
2424 /// isSafeToLoadUnconditionally - Return true if we know that executing a load
2626 /// specified pointer, we do a quick local scan of the basic block containing
2727 /// ScanFrom, to determine if the address is already accessed.
2828 bool isSafeToLoadUnconditionally(Value *V, Instruction *ScanFrom,
29 unsigned Align, const TargetData *TD = 0);
29 unsigned Align, const DataLayout *TD = 0);
3030
3131 /// FindAvailableLoadedValue - Scan the ScanBB block backwards (starting at
3232 /// the instruction before ScanFrom) checking to see if we have the value at
2626 namespace llvm {
2727 class CallInst;
2828 class PointerType;
29 class TargetData;
29 class DataLayout;
3030 class TargetLibraryInfo;
3131 class Type;
3232 class Value;
8080 /// isArrayMalloc - Returns the corresponding CallInst if the instruction
8181 /// is a call to malloc whose array size can be determined and the array size
8282 /// is not constant 1. Otherwise, return NULL.
83 const CallInst *isArrayMalloc(const Value *I, const TargetData *TD,
83 const CallInst *isArrayMalloc(const Value *I, const DataLayout *TD,
8484 const TargetLibraryInfo *TLI);
8585
8686 /// getMallocType - Returns the PointerType resulting from the malloc call.
102102 /// then return that multiple. For non-array mallocs, the multiple is
103103 /// constant 1. Otherwise, return NULL for mallocs whose array size cannot be
104104 /// determined.
105 Value *getMallocArraySize(CallInst *CI, const TargetData *TD,
105 Value *getMallocArraySize(CallInst *CI, const DataLayout *TD,
106106 const TargetLibraryInfo *TLI,
107107 bool LookThroughSExt = false);
108108
140140 /// object size in Size if successful, and false otherwise.
141141 /// If RoundToAlign is true, then Size is rounded up to the aligment of allocas,
142142 /// byval arguments, and global variables.
143 bool getObjectSize(const Value *Ptr, uint64_t &Size, const TargetData *TD,
143 bool getObjectSize(const Value *Ptr, uint64_t &Size, const DataLayout *TD,
144144 const TargetLibraryInfo *TLI, bool RoundToAlign = false);
145145
146146
152152 class ObjectSizeOffsetVisitor
153153 : public InstVisitor {
154154
155 const TargetData *TD;
155 const DataLayout *TD;
156156 const TargetLibraryInfo *TLI;
157157 bool RoundToAlign;
158158 unsigned IntTyBits;
166166 }
167167
168168 public:
169 ObjectSizeOffsetVisitor(const TargetData *TD, const TargetLibraryInfo *TLI,
169 ObjectSizeOffsetVisitor(const DataLayout *TD, const TargetLibraryInfo *TLI,
170170 LLVMContext &Context, bool RoundToAlign = false);
171171
172172 SizeOffsetType compute(Value *V);
212212 typedef DenseMap CacheMapTy;
213213 typedef SmallPtrSet PtrSetTy;
214214
215 const TargetData *TD;
215 const DataLayout *TD;
216216 const TargetLibraryInfo *TLI;
217217 LLVMContext &Context;
218218 BuilderTy Builder;
227227 SizeOffsetEvalType compute_(Value *V);
228228
229229 public:
230 ObjectSizeOffsetEvaluator(const TargetData *TD, const TargetLibraryInfo *TLI,
230 ObjectSizeOffsetEvaluator(const DataLayout *TD, const TargetLibraryInfo *TLI,
231231 LLVMContext &Context);
232232 SizeOffsetEvalType compute(Value *V);
233233
2828 class Instruction;
2929 class CallSite;
3030 class AliasAnalysis;
31 class TargetData;
31 class DataLayout;
3232 class MemoryDependenceAnalysis;
3333 class PredIteratorCache;
3434 class DominatorTree;
322322
323323 /// Current AA implementation, just a cache.
324324 AliasAnalysis *AA;
325 TargetData *TD;
325 DataLayout *TD;
326326 DominatorTree *DT;
327327 OwningPtr PredCache;
328328 public:
411411 int64_t MemLocOffs,
412412 unsigned MemLocSize,
413413 const LoadInst *LI,
414 const TargetData &TD);
414 const DataLayout &TD);
415415
416416 private:
417417 MemDepResult getCallSiteDependencyFrom(CallSite C, bool isReadOnlyCall,
1818
1919 namespace llvm {
2020 class DominatorTree;
21 class TargetData;
21 class DataLayout;
2222 class TargetLibraryInfo;
2323
2424 /// PHITransAddr - An address value which tracks and handles phi translation.
3636 Value *Addr;
3737
3838 /// TD - The target data we are playing with if known, otherwise null.
39 const TargetData *TD;
39 const DataLayout *TD;
4040
4141 /// TLI - The target library info if known, otherwise null.
4242 const TargetLibraryInfo *TLI;
4444 /// InstInputs - The inputs for our symbolic address.
4545 SmallVector InstInputs;
4646 public:
47 PHITransAddr(Value *addr, const TargetData *td) : Addr(addr), TD(td), TLI(0) {
47 PHITransAddr(Value *addr, const DataLayout *td) : Addr(addr), TD(td), TLI(0) {
4848 // If the address is an instruction, the whole thing is considered an input.
4949 if (Instruction *I = dyn_cast(Addr))
5050 InstInputs.push_back(I);
3939 class DominatorTree;
4040 class Type;
4141 class ScalarEvolution;
42 class TargetData;
42 class DataLayout;
4343 class TargetLibraryInfo;
4444 class LLVMContext;
4545 class Loop;
226226
227227 /// TD - The target data information for the target we are targeting.
228228 ///
229 TargetData *TD;
229 DataLayout *TD;
230230
231231 /// TLI - The target library information for the target we are targeting.
232232 ///
2121 class Value;
2222 class Instruction;
2323 class APInt;
24 class TargetData;
24 class DataLayout;
2525 class StringRef;
2626 class MDNode;
2727
3636 /// same width as the vector element, and the bit is set only if it is true
3737 /// for all of the elements in the vector.
3838 void ComputeMaskedBits(Value *V, APInt &KnownZero, APInt &KnownOne,
39 const TargetData *TD = 0, unsigned Depth = 0);
39 const DataLayout *TD = 0, unsigned Depth = 0);
4040 void computeMaskedBitsLoad(const MDNode &Ranges, APInt &KnownZero);
4141
4242 /// ComputeSignBit - Determine whether the sign bit is known to be zero or
4343 /// one. Convenience wrapper around ComputeMaskedBits.
4444 void ComputeSignBit(Value *V, bool &KnownZero, bool &KnownOne,
45 const TargetData *TD = 0, unsigned Depth = 0);
45 const DataLayout *TD = 0, unsigned Depth = 0);
4646
4747 /// isPowerOfTwo - Return true if the given value is known to have exactly one
4848 /// bit set when defined. For vectors return true if every element is known to
4949 /// be a power of two when defined. Supports values with integer or pointer
5050 /// type and vectors of integers. If 'OrZero' is set then returns true if the
5151 /// given value is either a power of two or zero.
52 bool isPowerOfTwo(Value *V, const TargetData *TD = 0, bool OrZero = false,
52 bool isPowerOfTwo(Value *V, const DataLayout *TD = 0, bool OrZero = false,
5353 unsigned Depth = 0);
5454
5555 /// isKnownNonZero - Return true if the given value is known to be non-zero
5656 /// when defined. For vectors return true if every element is known to be
5757 /// non-zero when defined. Supports values with integer or pointer type and
5858 /// vectors of integers.
59 bool isKnownNonZero(Value *V, const TargetData *TD = 0, unsigned Depth = 0);
59 bool isKnownNonZero(Value *V, const DataLayout *TD = 0, unsigned Depth = 0);
6060
6161 /// MaskedValueIsZero - Return true if 'V & Mask' is known to be zero. We use
6262 /// this predicate to simplify operations downstream. Mask is known to be
6868 /// same width as the vector element, and the bit is set only if it is true
6969 /// for all of the elements in the vector.
7070 bool MaskedValueIsZero(Value *V, const APInt &Mask,
71 const TargetData *TD = 0, unsigned Depth = 0);
71 const DataLayout *TD = 0, unsigned Depth = 0);
7272
7373
7474 /// ComputeNumSignBits - Return the number of times the sign bit of the
7979 ///
8080 /// 'Op' must have a scalar integer type.
8181 ///
82 unsigned ComputeNumSignBits(Value *Op, const TargetData *TD = 0,
82 unsigned ComputeNumSignBits(Value *Op, const DataLayout *TD = 0,
8383 unsigned Depth = 0);
8484
8585 /// ComputeMultiple - This function computes the integer multiple of Base that
117117 /// it can be expressed as a base pointer plus a constant offset. Return the
118118 /// base and offset to the caller.
119119 Value *GetPointerBaseWithConstantOffset(Value *Ptr, int64_t &Offset,
120 const TargetData &TD);
120 const DataLayout &TD);
121121 static inline const Value *
122122 GetPointerBaseWithConstantOffset(const Value *Ptr, int64_t &Offset,
123 const TargetData &TD) {
123 const DataLayout &TD) {
124124 return GetPointerBaseWithConstantOffset(const_cast(Ptr), Offset,TD);
125125 }
126126
142142 /// being addressed. Note that the returned value has pointer type if the
143143 /// specified value does. If the MaxLookup value is non-zero, it limits the
144144 /// number of instructions to be stripped off.
145 Value *GetUnderlyingObject(Value *V, const TargetData *TD = 0,
145 Value *GetUnderlyingObject(Value *V, const DataLayout *TD = 0,
146146 unsigned MaxLookup = 6);
147147 static inline const Value *
148 GetUnderlyingObject(const Value *V, const TargetData *TD = 0,
148 GetUnderlyingObject(const Value *V, const DataLayout *TD = 0,
149149 unsigned MaxLookup = 6) {
150150 return GetUnderlyingObject(const_cast(V), TD, MaxLookup);
151151 }
155155 /// multiple objects.
156156 void GetUnderlyingObjects(Value *V,
157157 SmallVectorImpl &Objects,
158 const TargetData *TD = 0,
158 const DataLayout *TD = 0,
159159 unsigned MaxLookup = 6);
160160
161161 /// onlyUsedByLifetimeMarkers - Return true if the only users of this pointer
181181 /// However, this method can return true for instructions that read memory;
182182 /// for such instructions, moving them may change the resulting value.
183183 bool isSafeToSpeculativelyExecute(const Value *V,
184 const TargetData *TD = 0);
184 const DataLayout *TD = 0);
185185
186186 } // end namespace llvm
187187
4747 class DwarfException;
4848 class Mangler;
4949 class TargetLoweringObjectFile;
50 class TargetData;
50 class DataLayout;
5151 class TargetMachine;
5252
5353 /// AsmPrinter - This class is intended to be used as a driving class for all
130130 /// getObjFileLowering - Return information about object file lowering.
131131 const TargetLoweringObjectFile &getObjFileLowering() const;
132132
133 /// getTargetData - Return information about data layout.
134 const TargetData &getTargetData() const;
133 /// getDataLayout - Return information about data layout.
134 const DataLayout &getDataLayout() const;
135135
136136 /// getCurrentSection() - Return the current section we are emitting to.
137137 const MCSection *getCurrentSection() const;
3131 class MachineInstr;
3232 class MachineFrameInfo;
3333 class MachineRegisterInfo;
34 class TargetData;
34 class DataLayout;
3535 class TargetInstrInfo;
3636 class TargetLibraryInfo;
3737 class TargetLowering;
5353 MachineConstantPool &MCP;
5454 DebugLoc DL;
5555 const TargetMachine &TM;
56 const TargetData &TD;
56 const DataLayout &TD;
5757 const TargetInstrInfo &TII;
5858 const TargetLowering &TLI;
5959 const TargetRegisterInfo &TRI;
2020 namespace llvm {
2121 class CallInst;
2222 class Module;
23 class TargetData;
23 class DataLayout;
2424
2525 class IntrinsicLowering {
26 const TargetData& TD;
26 const DataLayout& TD;
2727
2828
2929 bool Warned;
3030 public:
31 explicit IntrinsicLowering(const TargetData &td) :
31 explicit IntrinsicLowering(const DataLayout &td) :
3232 TD(td), Warned(false) {}
3333
3434 /// AddPrototypes - This method, if called, causes all of the prototypes
2424
2525 class Constant;
2626 class FoldingSetNodeID;
27 class TargetData;
27 class DataLayout;
2828 class TargetMachine;
2929 class Type;
3030 class MachineConstantPool;
131131 /// address of the function constant pool values.
132132 /// @brief The machine constant pool.
133133 class MachineConstantPool {
134 const TargetData *TD; ///< The machine's TargetData.
134 const DataLayout *TD; ///< The machine's DataLayout.
135135 unsigned PoolAlignment; ///< The alignment for the pool.
136136 std::vector Constants; ///< The pool of constants.
137137 /// MachineConstantPoolValues that use an existing MachineConstantPoolEntry.
138138 DenseSet MachineCPVsSharingEntries;
139139 public:
140140 /// @brief The only constructor.
141 explicit MachineConstantPool(const TargetData *td)
141 explicit MachineConstantPool(const DataLayout *td)
142142 : TD(td), PoolAlignment(1) {}
143143 ~MachineConstantPool();
144144
2020
2121 namespace llvm {
2222 class raw_ostream;
23 class TargetData;
23 class DataLayout;
2424 class TargetRegisterClass;
2525 class Type;
2626 class MachineFunction;
2525 namespace llvm {
2626
2727 class MachineBasicBlock;
28 class TargetData;
28 class DataLayout;
2929 class raw_ostream;
3030
3131 /// MachineJumpTableEntry - One jump table in the jump table info.
8383 JTEntryKind getEntryKind() const { return EntryKind; }
8484
8585 /// getEntrySize - Return the size of each entry in the jump table.
86 unsigned getEntrySize(const TargetData &TD) const;
86 unsigned getEntrySize(const DataLayout &TD) const;
8787 /// getEntryAlignment - Return the alignment of each entry in the jump table.
88 unsigned getEntryAlignment(const TargetData &TD) const;
88 unsigned getEntryAlignment(const DataLayout &TD) const;
8989
9090 /// createJumpTableIndex - Create a new jump table.
9191 ///
1818 #define LLVM_DERIVED_TYPES_H
1919
2020 #include "llvm/Type.h"
21 #include "llvm/Support/DataTypes.h"
2122 #include "llvm/Support/Compiler.h"
22 #include "llvm/Support/DataTypes.h"
2323
2424 namespace llvm {
2525
183183 /// Independent of what kind of struct you have, the body of a struct type are
184184 /// laid out in memory consequtively with the elements directly one after the
185185 /// other (if the struct is packed) or (if not packed) with padding between the
186 /// elements as defined by TargetData (which is required to match what the code
186 /// elements as defined by DataLayout (which is required to match what the code
187187 /// generator for a target expects).
188188 ///
189189 class StructType : public CompositeType {
4141 class MachineCodeInfo;
4242 class Module;
4343 class MutexGuard;
44 class TargetData;
44 class DataLayout;
4545 class Triple;
4646 class Type;
4747
103103 ExecutionEngineState EEState;
104104
105105 /// The target data for the platform for which execution is being performed.
106 const TargetData *TD;
106 const DataLayout *TD;
107107
108108 /// Whether lazy JIT compilation is enabled.
109109 bool CompilingLazily;
122122 /// optimize for the case where there is only one module.
123123 SmallVector Modules;
124124
125 void setTargetData(const TargetData *td) { TD = td; }
125 void setDataLayout(const DataLayout *td) { TD = td; }
126126
127127 /// getMemoryforGV - Allocate memory for a global variable.
128128 virtual char *getMemoryForGV(const GlobalVariable *GV);
212212
213213 //===--------------------------------------------------------------------===//
214214
215 const TargetData *getTargetData() const { return TD; }
215 const DataLayout *getDataLayout() const { return TD; }
216216
217217 /// removeModule - Remove a Module from the list of modules. Returns true if
218218 /// M is found.
562562 /// IntPtrTy argument is used to make accurate determinations for casts
563563 /// involving Integer and Pointer types. They are no-op casts if the integer
564564 /// is the same size as the pointer. However, pointer size varies with
565 /// platform. Generally, the result of TargetData::getIntPtrType() should be
565 /// platform. Generally, the result of DataLayout::getIntPtrType() should be
566566 /// passed in. If that's not available, use Type::Int64Ty, which will make
567567 /// the isNoopCast call conservative.
568568 /// @brief Determine if the described cast is a no-op cast.
2525
2626 namespace llvm {
2727
28 class TargetData;
28 class DataLayout;
2929
3030 /// TargetFolder - Create constants with target dependent folding.
3131 class TargetFolder {
32 const TargetData *TD;
32 const DataLayout *TD;
3333
3434 /// Fold - Fold the constant using target specific information.
3535 Constant *Fold(Constant *C) const {
4040 }
4141
4242 public:
43 explicit TargetFolder(const TargetData *TheTD) : TD(TheTD) {}
43 explicit TargetFolder(const DataLayout *TheTD) : TD(TheTD) {}
4444
4545 //===--------------------------------------------------------------------===//
4646 // Binary Operators
2121 template class SmallVectorImpl;
2222 class MCContext;
2323 class MCSymbol;
24 class TargetData;
24 class DataLayout;
2525
2626 class Mangler {
2727 public:
3333
3434 private:
3535 MCContext &Context;
36 const TargetData &TD;
36 const DataLayout &TD;
3737
3838 /// AnonGlobalIDs - We need to give global values the same name every time
3939 /// they are mangled. This keeps track of the number we give to anonymous
4646 unsigned NextAnonGlobalID;
4747
4848 public:
49 Mangler(MCContext &context, const TargetData &td)
49 Mangler(MCContext &context, const DataLayout &td)
5050 : Context(context), TD(td), NextAnonGlobalID(1) {}
5151
5252 /// getSymbol - Return the MCSymbol for the specified global value. This
+0
-53
include/llvm/Target/TargetData.h less more
None //===-- llvm/Target/TargetData.h - Data size & alignment info ---*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines the wrapper for DataLayout to provide compatibility
10 // with the old TargetData class.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_TARGET_TARGETDATA_H
15 #define LLVM_TARGET_TARGETDATA_H
16
17 #include "llvm/DataLayout.h"
18 #include "llvm/Pass.h"
19 #include "llvm/ADT/SmallVector.h"
20 #include "llvm/Support/DataTypes.h"
21
22 namespace llvm {
23
24 /// TargetData - This class is just a wrapper to help with the transition to the
25 /// new DataLayout class.
26 class TargetData : public DataLayout {
27 public:
28 /// Default ctor.
29 ///
30 /// @note This has to exist, because this is a pass, but it should never be
31 /// used.
32 TargetData() : DataLayout() {}
33
34 /// Constructs a TargetData from a specification string.
35 /// See DataLayout::init().
36 explicit TargetData(StringRef TargetDescription)
37 : DataLayout(TargetDescription) {}
38
39 /// Initialize target data from properties stored in the module.
40 explicit TargetData(const Module *M) : DataLayout(M) {}
41
42 TargetData(const TargetData &TD) : DataLayout(TD) {}
43
44 template
45 static UIntTy RoundUpAlignment(UIntTy Val, unsigned Alignment) {
46 return DataLayout::RoundUpAlignment(Val, Alignment);
47 }
48 };
49
50 } // End llvm namespace
51
52 #endif
4949 class MCContext;
5050 class MCExpr;
5151 template class SmallVectorImpl;
52 class TargetData;
52 class DataLayout;
5353 class TargetRegisterClass;
5454 class TargetLibraryInfo;
5555 class TargetLoweringObjectFile;
136136 virtual ~TargetLowering();
137137
138138 const TargetMachine &getTargetMachine() const { return TM; }
139 const TargetData *getTargetData() const { return TD; }
139 const DataLayout *getDataLayout() const { return TD; }
140140 const TargetLoweringObjectFile &getObjFileLowering() const { return TLOF; }
141141
142142 bool isBigEndian() const { return !IsLittleEndian; }
17881788
17891789 private:
17901790 const TargetMachine &TM;
1791 const TargetData *TD;
1791 const DataLayout *TD;
17921792 const TargetLoweringObjectFile &TLOF;
17931793
17941794 /// PointerTy - The type to use for pointers, usually i32 or i64.
3030 class MCContext;
3131 class PassManagerBase;
3232 class Target;
33 class TargetData;
33 class DataLayout;
3434 class TargetELFWriterInfo;
3535 class TargetFrameLowering;
3636 class TargetInstrInfo;
105105 virtual const TargetFrameLowering *getFrameLowering() const { return 0; }
106106 virtual const TargetLowering *getTargetLowering() const { return 0; }
107107 virtual const TargetSelectionDAGInfo *getSelectionDAGInfo() const{ return 0; }
108 virtual const TargetData *getTargetData() const { return 0; }
108 virtual const DataLayout *getDataLayout() const { return 0; }
109109
110110 /// getMCAsmInfo - Return target specific asm information.
111111 ///
1919
2020 namespace llvm {
2121
22 class TargetData;
22 class DataLayout;
2323 class TargetMachine;
2424
2525 //===----------------------------------------------------------------------===//
3030 TargetSelectionDAGInfo(const TargetSelectionDAGInfo &) LLVM_DELETED_FUNCTION;
3131 void operator=(const TargetSelectionDAGInfo &) LLVM_DELETED_FUNCTION;
3232
33 const TargetData *TD;
33 const DataLayout *TD;
3434
3535 protected:
36 const TargetData *getTargetData() const { return TD; }
36 const DataLayout *getDataLayout() const { return TD; }
3737
3838 public:
3939 explicit TargetSelectionDAGInfo(const TargetMachine &TM);
2020
2121 namespace llvm {
2222 class CallSite;
23 class TargetData;
23 class DataLayout;
2424 class InlineCost;
2525 template
2626 class SmallPtrSet;
1818
1919 namespace llvm {
2020 class Value;
21 class TargetData;
21 class DataLayout;
2222 class TargetLibraryInfo;
2323
2424 /// CastToCStr - Return V if it is an i8*, otherwise cast it to i8*.
2727 /// EmitStrLen - Emit a call to the strlen function to the builder, for the
2828 /// specified pointer. Ptr is required to be some pointer type, and the
2929 /// return value has 'intptr_t' type.
30 Value *EmitStrLen(Value *Ptr, IRBuilder<> &B, const TargetData *TD,
30 Value *EmitStrLen(Value *Ptr, IRBuilder<> &B, const DataLayout *TD,
3131 const TargetLibraryInfo *TLI);
3232
3333 /// EmitStrNLen - Emit a call to the strnlen function to the builder, for the
3434 /// specified pointer. Ptr is required to be some pointer type, MaxLen must
3535 /// be of size_t type, and the return value has 'intptr_t' type.
3636 Value *EmitStrNLen(Value *Ptr, Value *MaxLen, IRBuilder<> &B,
37 const TargetData *TD, const TargetLibraryInfo *TLI);
37 const DataLayout *TD, const TargetLibraryInfo *TLI);
3838
3939 /// EmitStrChr - Emit a call to the strchr function to the builder, for the
4040 /// specified pointer and character. Ptr is required to be some pointer type,
4141 /// and the return value has 'i8*' type.
42 Value *EmitStrChr(Value *Ptr, char C, IRBuilder<> &B, const TargetData *TD,
42 Value *EmitStrChr(Value *Ptr, char C, IRBuilder<> &B, const DataLayout *TD,
4343 const TargetLibraryInfo *TLI);
4444
4545 /// EmitStrNCmp - Emit a call to the strncmp function to the builder.
4646 Value *EmitStrNCmp(Value *Ptr1, Value *Ptr2, Value *Len, IRBuilder<> &B,
47 const TargetData *TD, const TargetLibraryInfo *TLI);
47 const DataLayout *TD, const TargetLibraryInfo *TLI);
4848
4949 /// EmitStrCpy - Emit a call to the strcpy function to the builder, for the
5050 /// specified pointer arguments.
5151 Value *EmitStrCpy(Value *Dst, Value *Src, IRBuilder<> &B,
52 const TargetData *TD, const TargetLibraryInfo *TLI,
52 const DataLayout *TD, const TargetLibraryInfo *TLI,
5353 StringRef Name = "strcpy");
5454
5555 /// EmitStrNCpy - Emit a call to the strncpy function to the builder, for the
5656 /// specified pointer arguments and length.
5757 Value *EmitStrNCpy(Value *Dst, Value *Src, Value *Len, IRBuilder<> &B,
58 const TargetData *TD, const TargetLibraryInfo *TLI,
58 const DataLayout *TD, const TargetLibraryInfo *TLI,
5959 StringRef Name = "strncpy");
6060
6161 /// EmitMemCpyChk - Emit a call to the __memcpy_chk function to the builder.
6262 /// This expects that the Len and ObjSize have type 'intptr_t' and Dst/Src
6363 /// are pointers.
6464 Value *EmitMemCpyChk(Value *Dst, Value *Src, Value *Len, Value *ObjSize,
65 IRBuilder<> &B, const TargetData *TD,
65 IRBuilder<> &B, const DataLayout *TD,
6666 const TargetLibraryInfo *TLI);
6767
6868 /// EmitMemChr - Emit a call to the memchr function. This assumes that Ptr is
6969 /// a pointer, Val is an i32 value, and Len is an 'intptr_t' value.
7070 Value *EmitMemChr(Value *Ptr, Value *Val, Value *Len, IRBuilder<> &B,
71 const TargetData *TD, const TargetLibraryInfo *TLI);
71 const DataLayout *TD, const TargetLibraryInfo *TLI);
7272
7373 /// EmitMemCmp - Emit a call to the memcmp function.
7474 Value *EmitMemCmp(Value *Ptr1, Value *Ptr2, Value *Len, IRBuilder<> &B,
75 const TargetData *TD, const TargetLibraryInfo *TLI);
75 const DataLayout *TD, const TargetLibraryInfo *TLI);
7676
7777 /// EmitUnaryFloatFnCall - Emit a call to the unary function named 'Name'
7878 /// (e.g. 'floor'). This function is known to take a single of type matching
8484
8585 /// EmitPutChar - Emit a call to the putchar function. This assumes that Char
8686 /// is an integer.
87 Value *EmitPutChar(Value *Char, IRBuilder<> &B, const TargetData *TD,
87 Value *EmitPutChar(Value *Char, IRBuilder<> &B, const DataLayout *TD,
8888 const TargetLibraryInfo *TLI);
8989
9090 /// EmitPutS - Emit a call to the puts function. This assumes that Str is
9191 /// some pointer.
92 Value *EmitPutS(Value *Str, IRBuilder<> &B, const TargetData *TD,
92 Value *EmitPutS(Value *Str, IRBuilder<> &B, const DataLayout *TD,
9393 const TargetLibraryInfo *TLI);
9494
9595 /// EmitFPutC - Emit a call to the fputc function. This assumes that Char is
9696 /// an i32, and File is a pointer to FILE.
9797 Value *EmitFPutC(Value *Char, Value *File, IRBuilder<> &B,
98 const TargetData *TD, const TargetLibraryInfo *TLI);
98 const DataLayout *TD, const TargetLibraryInfo *TLI);
9999
100100 /// EmitFPutS - Emit a call to the puts function. Str is required to be a
101101 /// pointer and File is a pointer to FILE.
102 Value *EmitFPutS(Value *Str, Value *File, IRBuilder<> &B, const TargetData *TD,
102 Value *EmitFPutS(Value *Str, Value *File, IRBuilder<> &B, const DataLayout *TD,
103103 const TargetLibraryInfo *TLI);
104104
105105 /// EmitFWrite - Emit a call to the fwrite function. This assumes that Ptr is
106106 /// a pointer, Size is an 'intptr_t', and File is a pointer to FILE.
107107 Value *EmitFWrite(Value *Ptr, Value *Size, Value *File, IRBuilder<> &B,
108 const TargetData *TD, const TargetLibraryInfo *TLI);
108 const DataLayout *TD, const TargetLibraryInfo *TLI);
109109
110110 /// SimplifyFortifiedLibCalls - Helper class for folding checked library
111111 /// calls (e.g. __strcpy_chk) into their unchecked counterparts.
117117 bool isString) const = 0;
118118 public:
119119 virtual ~SimplifyFortifiedLibCalls();
120 bool fold(CallInst *CI, const TargetData *TD, const TargetLibraryInfo *TLI);
120 bool fold(CallInst *CI, const DataLayout *TD, const TargetLibraryInfo *TLI);
121121 };
122122 }
123123
3838 class CallSite;
3939 class Trace;
4040 class CallGraph;
41 class TargetData;
41 class DataLayout;
4242 class Loop;
4343 class LoopInfo;
4444 class AllocaInst;
149149 SmallVectorImpl &Returns,
150150 const char *NameSuffix = "",
151151 ClonedCodeInfo *CodeInfo = 0,
152 const TargetData *TD = 0,
152 const DataLayout *TD = 0,
153153 Instruction *TheCall = 0);
154154
155155
157157 /// InlineFunction call, and records the auxiliary results produced by it.
158158 class InlineFunctionInfo {
159159 public:
160 explicit InlineFunctionInfo(CallGraph *cg = 0, const TargetData *td = 0)
160 explicit InlineFunctionInfo(CallGraph *cg = 0, const DataLayout *td = 0)
161161 : CG(cg), TD(td) {}
162162
163163 /// CG - If non-null, InlineFunction will update the callgraph to reflect the
164164 /// changes it makes.
165165 CallGraph *CG;
166 const TargetData *TD;
166 const DataLayout *TD;
167167
168168 /// StaticAllocas - InlineFunction fills this in with all static allocas that
169169 /// get copied into the caller.
1717 #include "llvm/IRBuilder.h"
1818 #include "llvm/Operator.h"
1919 #include "llvm/Support/GetElementPtrTypeIterator.h"
20 #include "llvm/Target/TargetData.h"
20 #include "llvm/DataLayout.h"
2121
2222 namespace llvm {
2323
3434 class PHINode;
3535 class AllocaInst;
3636 class ConstantExpr;
37 class TargetData;
37 class DataLayout;
3838 class TargetLibraryInfo;
3939 class DIBuilder;
4040
8383 ///
8484 /// This returns true if it changed the code, note that it can delete
8585 /// instructions in other blocks as well in this block.
86 bool SimplifyInstructionsInBlock(BasicBlock *BB, const TargetData *TD = 0,
86 bool SimplifyInstructionsInBlock(BasicBlock *BB, const DataLayout *TD = 0,
8787 const TargetLibraryInfo *TLI = 0);
8888
8989 //===----------------------------------------------------------------------===//
102102 /// .. and delete the predecessor corresponding to the '1', this will attempt to
103103 /// recursively fold the 'and' to 0.
104104 void RemovePredecessorAndSimplify(BasicBlock *BB, BasicBlock *Pred,
105 TargetData *TD = 0);
105 DataLayout *TD = 0);
106106
107107
108108 /// MergeBasicBlockIntoOnlyPred - BB is a block with one predecessor and its
133133 /// of the CFG. It returns true if a modification was made, possibly deleting
134134 /// the basic block that was pointed to.
135135 ///
136 bool SimplifyCFG(BasicBlock *BB, const TargetData *TD = 0);
136 bool SimplifyCFG(BasicBlock *BB, const DataLayout *TD = 0);
137137
138138 /// FoldBranchToCommonDest - If this basic block is ONLY a setcc and a branch,
139139 /// and if a predecessor branches to us and one of our successors, fold the
161161 /// and it is more than the alignment of the ultimate object, see if we can
162162 /// increase the alignment of the ultimate object, making this check succeed.
163163 unsigned getOrEnforceKnownAlignment(Value *V, unsigned PrefAlign,
164 const TargetData *TD = 0);
164 const DataLayout *TD = 0);
165165
166166 /// getKnownAlignment - Try to infer an alignment for the specified pointer.
167 static inline unsigned getKnownAlignment(Value *V, const TargetData *TD = 0) {
167 static inline unsigned getKnownAlignment(Value *V, const DataLayout *TD = 0) {
168168 return getOrEnforceKnownAlignment(V, 0, TD);
169169 }
170170
174174 /// When NoAssumptions is true, no assumptions about index computation not
175175 /// overflowing is made.
176176 template
177 Value *EmitGEPOffset(IRBuilderTy *Builder, const TargetData &TD, User *GEP,
177 Value *EmitGEPOffset(IRBuilderTy *Builder, const DataLayout &TD, User *GEP,
178178 bool NoAssumptions = false) {
179179 gep_type_iterator GTI = gep_type_begin(GEP);
180180 Type *IntPtrTy = TD.getIntPtrType(GEP->getContext());
251251
252252 /// isSized - Return true if it makes sense to take the size of this type. To
253253 /// get the actual size for a particular target, it is reasonable to use the
254 /// TargetData subsystem to do this.
254 /// DataLayout subsystem to do this.
255255 ///
256256 bool isSized() const {
257257 // If it's a primitive, it is always sized.
275275 ///
276276 /// Note that this may not reflect the size of memory allocated for an
277277 /// instance of the type or the number of bytes that are written when an
278 /// instance of the type is stored to memory. The TargetData class provides
278 /// instance of the type is stored to memory. The DataLayout class provides
279279 /// additional query functions to provide this information.
280280 ///
281281 unsigned getPrimitiveSizeInBits() const;
144144 /*===-- Target Data -------------------------------------------------------===*/
145145
146146 /** Creates target data from a target layout string.
147 See the constructor llvm::TargetData::TargetData. */
147 See the constructor llvm::DataLayout::DataLayout. */
148148 LLVMTargetDataRef LLVMCreateTargetData(const char *StringRep);
149149
150150 /** Adds target data information to a pass manager. This does not take ownership
159159
160160 /** Converts target data to a target layout string. The string must be disposed
161161 with LLVMDisposeMessage.
162 See the constructor llvm::TargetData::TargetData. */
162 See the constructor llvm::DataLayout::DataLayout. */
163163 char *LLVMCopyStringRepOfTargetData(LLVMTargetDataRef);
164164
165165 /** Returns the byte order of a target, either LLVMBigEndian or
166166 LLVMLittleEndian.
167 See the method llvm::TargetData::isLittleEndian. */
167 See the method llvm::DataLayout::isLittleEndian. */
168168 enum LLVMByteOrdering LLVMByteOrder(LLVMTargetDataRef);
169169
170170 /** Returns the pointer size in bytes for a target.
171 See the method llvm::TargetData::getPointerSize. */
171 See the method llvm::DataLayout::getPointerSize. */
172172 unsigned LLVMPointerSize(LLVMTargetDataRef);
173173
174174 /** Returns the integer type that is the same size as a pointer on a target.
175 See the method llvm::TargetData::getIntPtrType. */
175 See the method llvm::DataLayout::getIntPtrType. */
176176 LLVMTypeRef LLVMIntPtrType(LLVMTargetDataRef);
177177
178178 /** Computes the size of a type in bytes for a target.
179 See the method llvm::TargetData::getTypeSizeInBits. */
179 See the method llvm::DataLayout::getTypeSizeInBits. */
180180 unsigned long long LLVMSizeOfTypeInBits(LLVMTargetDataRef, LLVMTypeRef);
181181
182182 /** Computes the storage size of a type in bytes for a target.
183 See the method llvm::TargetData::getTypeStoreSize. */
183 See the method llvm::DataLayout::getTypeStoreSize. */
184184 unsigned long long LLVMStoreSizeOfType(LLVMTargetDataRef, LLVMTypeRef);
185185
186186 /** Computes the ABI size of a type in bytes for a target.
187 See the method llvm::TargetData::getTypeAllocSize. */
187 See the method llvm::DataLayout::getTypeAllocSize. */
188188 unsigned long long LLVMABISizeOfType(LLVMTargetDataRef, LLVMTypeRef);
189189
190190 /** Computes the ABI alignment of a type in bytes for a target.
191 See the method llvm::TargetData::getTypeABISize. */
191 See the method llvm::DataLayout::getTypeABISize. */
192192 unsigned LLVMABIAlignmentOfType(LLVMTargetDataRef, LLVMTypeRef);
193193
194194 /** Computes the call frame alignment of a type in bytes for a target.
195 See the method llvm::TargetData::getTypeABISize. */
195 See the method llvm::DataLayout::getTypeABISize. */
196196 unsigned LLVMCallFrameAlignmentOfType(LLVMTargetDataRef, LLVMTypeRef);
197197
198198 /** Computes the preferred alignment of a type in bytes for a target.
199 See the method llvm::TargetData::getTypeABISize. */
199 See the method llvm::DataLayout::getTypeABISize. */
200200 unsigned LLVMPreferredAlignmentOfType(LLVMTargetDataRef, LLVMTypeRef);
201201
202202 /** Computes the preferred alignment of a global variable in bytes for a target.
203 See the method llvm::TargetData::getPreferredAlignment. */
203 See the method llvm::DataLayout::getPreferredAlignment. */
204204 unsigned LLVMPreferredAlignmentOfGlobal(LLVMTargetDataRef,
205205 LLVMValueRef GlobalVar);
206206
215215 unsigned Element);
216216
217217 /** Deallocates a TargetData.
218 See the destructor llvm::TargetData::~TargetData. */
218 See the destructor llvm::DataLayout::~DataLayout. */
219219 void LLVMDisposeTargetData(LLVMTargetDataRef);
220220
221221 /**
226226 }
227227
228228 namespace llvm {
229 class TargetData;
229 class DataLayout;
230230 class TargetLibraryInfo;
231231
232 inline TargetData *unwrap(LLVMTargetDataRef P) {
233 return reinterpret_cast(P);
234 }
235
236 inline LLVMTargetDataRef wrap(const TargetData *P) {
237 return reinterpret_cast(const_cast(P));
232 inline DataLayout *unwrap(LLVMTargetDataRef P) {
233 return reinterpret_cast(P);
234 }
235
236 inline LLVMTargetDataRef wrap(const DataLayout *P) {
237 return reinterpret_cast(const_cast(P));
238238 }
239239
240240 inline TargetLibraryInfo *unwrap(LLVMTargetLibraryInfoRef P) {
103103 LLVMDisposeMessage. */
104104 char *LLVMGetTargetMachineFeatureString(LLVMTargetMachineRef T);
105105
106 /** Returns the llvm::TargetData used for this llvm:TargetMachine. */
106 /** Returns the llvm::DataLayout used for this llvm:TargetMachine. */
107107 LLVMTargetDataRef LLVMGetTargetMachineData(LLVMTargetMachineRef T);
108108
109109 /** Emits an asm or object file for the given module to the filename. This
3434 #include "llvm/Instructions.h"
3535 #include "llvm/LLVMContext.h"
3636 #include "llvm/Type.h"
37 #include "llvm/Target/TargetData.h"
37 #include "llvm/DataLayout.h"
3838 #include "llvm/Target/TargetLibraryInfo.h"
3939 using namespace llvm;
4040
451451 /// AliasAnalysis interface before any other methods are called.
452452 ///
453453 void AliasAnalysis::InitializeAliasAnalysis(Pass *P) {
454 TD = P->getAnalysisIfAvailable<TargetData>();
454 TD = P->getAnalysisIfAvailable<DataLayout>();
455455 TLI = P->getAnalysisIfAvailable();
456456 AA = &P->getAnalysis();
457457 }
462462 AU.addRequired(); // All AA's chain
463463 }
464464
465 /// getTypeStoreSize - Return the TargetData store size for the given type,
465 /// getTypeStoreSize - Return the DataLayout store size for the given type,
466466 /// if known, or a conservative value otherwise.
467467 ///
468468 uint64_t AliasAnalysis::getTypeStoreSize(Type *Ty) {
1717 #include "llvm/LLVMContext.h"
1818 #include "llvm/Pass.h"
1919 #include "llvm/Type.h"
20 #include "llvm/Target/TargetData.h"
20 #include "llvm/DataLayout.h"
2121 #include "llvm/Assembly/Writer.h"
2222 #include "llvm/Support/Debug.h"
2323 #include "llvm/Support/ErrorHandling.h"
2828 #include "llvm/Analysis/MemoryBuiltins.h"
2929 #include "llvm/Analysis/InstructionSimplify.h"
3030 #include "llvm/Analysis/ValueTracking.h"
31 #include "llvm/Target/TargetData.h"
31 #include "llvm/DataLayout.h"
3232 #include "llvm/Target/TargetLibraryInfo.h"
3333 #include "llvm/ADT/SmallPtrSet.h"
3434 #include "llvm/ADT/SmallVector.h"
8383
8484 /// getObjectSize - Return the size of the object specified by V, or
8585 /// UnknownSize if unknown.
86 static uint64_t getObjectSize(const Value *V, const TargetData &TD,
86 static uint64_t getObjectSize(const Value *V, const DataLayout &TD,
8787 const TargetLibraryInfo &TLI,
8888 bool RoundToAlign = false) {
8989 uint64_t Size;
9595 /// isObjectSmallerThan - Return true if we can prove that the object specified
9696 /// by V is smaller than Size.
9797 static bool isObjectSmallerThan(const Value *V, uint64_t Size,
98 const TargetData &TD,
98 const DataLayout &TD,
9999 const TargetLibraryInfo &TLI) {
100100 // This function needs to use the aligned object size because we allow
101101 // reads a bit past the end given sufficient alignment.
107107 /// isObjectSize - Return true if we can prove that the object specified
108108 /// by V has size Size.
109109 static bool isObjectSize(const Value *V, uint64_t Size,
110 const TargetData &TD, const TargetLibraryInfo &TLI) {
110 const DataLayout &TD, const TargetLibraryInfo &TLI) {
111111 uint64_t ObjectSize = getObjectSize(V, TD, TLI);
112112 return ObjectSize != AliasAnalysis::UnknownSize && ObjectSize == Size;
113113 }
150150 /// represented in the result.
151151 static Value *GetLinearExpression(Value *V, APInt &Scale, APInt &Offset,
152152 ExtensionKind &Extension,
153 const TargetData &TD, unsigned Depth) {
153 const DataLayout &TD, unsigned Depth) {
154154 assert(V->getType()->isIntegerTy() && "Not an integer value");
155155
156156 // Limit our recursion depth.
225225 /// specified amount, but which may have other unrepresented high bits. As such,
226226 /// the gep cannot necessarily be reconstructed from its decomposed form.
227227 ///
228 /// When TargetData is around, this function is capable of analyzing everything
228 /// When DataLayout is around, this function is capable of analyzing everything
229229 /// that GetUnderlyingObject can look through. When not, it just looks
230230 /// through pointer casts.
231231 ///
232232 static const Value *
233233 DecomposeGEPExpression(const Value *V, int64_t &BaseOffs,
234234 SmallVectorImpl &VarIndices,
235 const TargetData *TD) {
235 const DataLayout *TD) {
236236 // Limit recursion depth to limit compile time in crazy cases.
237237 unsigned MaxLookup = 6;
238238
276276 ->getElementType()->isSized())
277277 return V;
278278
279 // If we are lacking TargetData information, we can't compute the offets of
279 // If we are lacking DataLayout information, we can't compute the offets of
280280 // elements computed by GEPs. However, we can handle bitcast equivalent
281281 // GEPs.
282282 if (TD == 0) {
867867 const Value *GEP1BasePtr =
868868 DecomposeGEPExpression(GEP1, GEP1BaseOffset, GEP1VariableIndices, TD);
869869 // DecomposeGEPExpression and GetUnderlyingObject should return the
870 // same result except when DecomposeGEPExpression has no TargetData.
870 // same result except when DecomposeGEPExpression has no DataLayout.
871871 if (GEP1BasePtr != UnderlyingV1 || GEP2BasePtr != UnderlyingV2) {
872872 assert(TD == 0 &&
873873 "DecomposeGEPExpression and GetUnderlyingObject disagree!");
901901 DecomposeGEPExpression(GEP2, GEP2BaseOffset, GEP2VariableIndices, TD);
902902
903903 // DecomposeGEPExpression and GetUnderlyingObject should return the
904 // same result except when DecomposeGEPExpression has no TargetData.
904 // same result except when DecomposeGEPExpression has no DataLayout.
905905 if (GEP1BasePtr != UnderlyingV1 || GEP2BasePtr != UnderlyingV2) {
906906 assert(TD == 0 &&
907907 "DecomposeGEPExpression and GetUnderlyingObject disagree!");
936936 DecomposeGEPExpression(GEP1, GEP1BaseOffset, GEP1VariableIndices, TD);
937937
938938 // DecomposeGEPExpression and GetUnderlyingObject should return the
939 // same result except when DecomposeGEPExpression has no TargetData.
939 // same result except when DecomposeGEPExpression has no DataLayout.
940940 if (GEP1BasePtr != UnderlyingV1) {
941941 assert(TD == 0 &&
942942 "DecomposeGEPExpression and GetUnderlyingObject disagree!");
1414 #include "llvm/Function.h"
1515 #include "llvm/Support/CallSite.h"
1616 #include "llvm/IntrinsicInst.h"
17 #include "llvm/Target/TargetData.h"
17 #include "llvm/DataLayout.h"
1818
1919 using namespace llvm;
2020
5353 return false;
5454 }
5555
56 bool llvm::isInstructionFree(const Instruction *I, const TargetData *TD) {
56 bool llvm::isInstructionFree(const Instruction *I, const DataLayout *TD) {
5757 if (isa(I))
5858 return true;
5959
118118 /// analyzeBasicBlock - Fill in the current structure with information gleaned
119119 /// from the specified block.
120120 void CodeMetrics::analyzeBasicBlock(const BasicBlock *BB,
121 const TargetData *TD) {
121 const DataLayout *TD) {
122122 ++NumBlocks;
123123 unsigned NumInstsBeforeThisBB = NumInsts;
124124 for (BasicBlock::const_iterator II = BB->begin(), E = BB->end();
188188 NumBBInsts[BB] = NumInsts - NumInstsBeforeThisBB;
189189 }
190190
191 void CodeMetrics::analyzeFunction(Function *F, const TargetData *TD) {
191 void CodeMetrics::analyzeFunction(Function *F, const DataLayout *TD) {
192192 // If this function contains a call that "returns twice" (e.g., setjmp or
193193 // _setjmp) and it isn't marked with "returns twice" itself, never inline it.
194194 // This is a hack because we depend on the user marking their local variables
1010 //
1111 // Also, to supplement the basic VMCore ConstantExpr simplifications,
1212 // this file defines some additional folding routines that can make use of
13 // TargetData information. These functions cannot go in VMCore due to library
13 // DataLayout information. These functions cannot go in VMCore due to library
1414 // dependency issues.
1515 //
1616 //===----------------------------------------------------------------------===//
2424 #include "llvm/Intrinsics.h"
2525 #include "llvm/Operator.h"
2626 #include "llvm/Analysis/ValueTracking.h"
27 #include "llvm/Target/TargetData.h"
27 #include "llvm/DataLayout.h"
2828 #include "llvm/Target/TargetLibraryInfo.h"
2929 #include "llvm/ADT/SmallVector.h"
3030 #include "llvm/ADT/StringMap.h"
4141 //===----------------------------------------------------------------------===//
4242
4343 /// FoldBitCast - Constant fold bitcast, symbolically evaluating it with
44 /// TargetData. This always returns a non-null constant, but it may be a
44 /// DataLayout. This always returns a non-null constant, but it may be a
4545 /// ConstantExpr if unfoldable.
4646 static Constant *FoldBitCast(Constant *C, Type *DestTy,
47 const TargetData &TD) {
47 const DataLayout &TD) {
4848 // Catch the obvious splat cases.
4949 if (C->isNullValue() && !DestTy->isX86_MMXTy())
5050 return Constant::getNullValue(DestTy);
217217 /// from a global, return the global and the constant. Because of
218218 /// constantexprs, this function is recursive.
219219 static bool IsConstantOffsetFromGlobal(Constant *C, GlobalValue *&GV,
220 int64_t &Offset, const TargetData &TD) {
220 int64_t &Offset, const DataLayout &TD) {
221221 // Trivial case, constant is the global.
222222 if ((GV = dyn_cast(C))) {
223223 Offset = 0;
273273 /// the CurPtr buffer. TD is the target data.
274274 static bool ReadDataFromGlobal(Constant *C, uint64_t ByteOffset,
275275 unsigned char *CurPtr, unsigned BytesLeft,
276 const TargetData &TD) {
276 const DataLayout &TD) {
277277 assert(ByteOffset <= TD.getTypeAllocSize(C->getType()) &&
278278 "Out of range access");
279279
387387 }
388388
389389 static Constant *FoldReinterpretLoadFromConstPtr(Constant *C,
390 const TargetData &TD) {
390 const DataLayout &TD) {
391391 Type *LoadTy = cast(C->getType())->getElementType();
392392 IntegerType *IntType = dyn_cast(LoadTy);
393393
454454 /// produce if it is constant and determinable. If this is not determinable,
455455 /// return null.
456456 Constant *llvm::ConstantFoldLoadFromConstPtr(Constant *C,
457 const TargetData *TD) {
457 const DataLayout *TD) {
458458 // First, try the easy cases:
459459 if (GlobalVariable *GV = dyn_cast(C))
460460 if (GV->isConstant() && GV->hasDefinitiveInitializer())
528528 return 0;
529529 }
530530
531 static Constant *ConstantFoldLoadInst(const LoadInst *LI, const TargetData *TD){
531 static Constant *ConstantFoldLoadInst(const LoadInst *LI, const DataLayout *TD){
532532 if (LI->isVolatile()) return 0;
533533
534534 if (Constant *C = dyn_cast(LI->getOperand(0)))
542542 /// these together. If target data info is available, it is provided as TD,
543543 /// otherwise TD is null.
544544 static Constant *SymbolicallyEvaluateBinop(unsigned Opc, Constant *Op0,
545 Constant *Op1, const TargetData *TD){
545 Constant *Op1, const DataLayout *TD){
546546 // SROA
547547
548548 // Fold (and 0xffffffff00000000, (shl x, 32)) -> shl.
571571 /// explicitly cast them so that they aren't implicitly casted by the
572572 /// getelementptr.
573573 static Constant *CastGEPIndices(ArrayRef Ops,
574 Type *ResultTy, const TargetData *TD,
574 Type *ResultTy, const DataLayout *TD,
575575 const TargetLibraryInfo *TLI) {
576576 if (!TD) return 0;
577577 Type *IntPtrTy = TD->getIntPtrType(ResultTy->getContext());
621621 /// SymbolicallyEvaluateGEP - If we can symbolically evaluate the specified GEP
622622 /// constant expression, do so.
623623 static Constant *SymbolicallyEvaluateGEP(ArrayRef Ops,
624 Type *ResultTy, const TargetData *TD,
624 Type *ResultTy, const DataLayout *TD,
625625 const TargetLibraryInfo *TLI) {
626626 Constant *Ptr = Ops[0];
627627 if (!TD || !cast(Ptr->getType())->getElementType()->isSized() ||
785785 /// this function can only fail when attempting to fold instructions like loads
786786 /// and stores, which have no constant expression form.
787787 Constant *llvm::ConstantFoldInstruction(Instruction *I,
788 const TargetData *TD,
788 const DataLayout *TD,
789789 const TargetLibraryInfo *TLI) {
790790 // Handle PHI nodes quickly here...
791791 if (PHINode *PN = dyn_cast(I)) {
855855 }
856856
857857 /// ConstantFoldConstantExpression - Attempt to fold the constant expression
858 /// using the specified TargetData. If successful, the constant result is
858 /// using the specified DataLayout. If successful, the constant result is
859859 /// result is returned, if not, null is returned.
860860 Constant *llvm::ConstantFoldConstantExpression(const ConstantExpr *CE,
861 const TargetData *TD,
861 const DataLayout *TD,
862862 const TargetLibraryInfo *TLI) {
863863 SmallVector Ops;
864864 for (User::const_op_iterator i = CE->op_begin(), e = CE->op_end();
888888 ///
889889 Constant *llvm::ConstantFoldInstOperands(unsigned Opcode, Type *DestTy,
890890 ArrayRef Ops,
891 const TargetData *TD,
891 const DataLayout *TD,
892892 const TargetLibraryInfo *TLI) {
893893 // Handle easy binops first.
894894 if (Instruction::isBinaryOp(Opcode)) {
975975 ///
976976 Constant *llvm::ConstantFoldCompareInstOperands(unsigned Predicate,
977977 Constant *Ops0, Constant *Ops1,
978 const TargetData *TD,
978 const DataLayout *TD,
979979 const TargetLibraryInfo *TLI) {
980980 // fold: icmp (inttoptr x), null -> icmp x, 0
981981 // fold: icmp (ptrtoint x), 0 -> icmp x, null
2121 #include "llvm/Analysis/LoopPass.h"
2222 #include "llvm/Analysis/ScalarEvolutionExpressions.h"
2323 #include "llvm/Analysis/ValueTracking.h"
24 #include "llvm/Target/TargetData.h"
24 #include "llvm/DataLayout.h"
2525 #include "llvm/Assembly/Writer.h"
2626 #include "llvm/ADT/STLExtras.h"
2727 #include "llvm/Support/Debug.h"
234234 LI = &getAnalysis();
235235 DT = &getAnalysis();
236236 SE = &getAnalysis();
237 TD = getAnalysisIfAvailable<TargetData>();
237 TD = getAnalysisIfAvailable<DataLayout>();
238238
239239 // Find all uses of induction variables in this loop, and categorize
240240 // them by stride. Start by finding all of the PHI nodes in the header for
2323 #include "llvm/IntrinsicInst.h"
2424 #include "llvm/Operator.h"
2525 #include "llvm/GlobalAlias.h"
26 #include "llvm/Target/TargetData.h"
26 #include "llvm/DataLayout.h"
2727 #include "llvm/ADT/STLExtras.h"
2828 #include "llvm/ADT/SetVector.h"
2929 #include "llvm/ADT/SmallVector.h"
4040 typedef InstVisitor Base;
4141 friend class InstVisitor;
4242
43 // TargetData if available, or null.
44 const TargetData *const TD;
43 // DataLayout if available, or null.
44 const DataLayout *const TD;
4545
4646 // The called function.
4747 Function &F;
125125 bool visitCallSite(CallSite CS);
126126
127127 public:
128 CallAnalyzer(const TargetData *TD, Function &Callee, int Threshold)
128 CallAnalyzer(const DataLayout *TD, Function &Callee, int Threshold)
129129 : TD(TD), F(Callee), Threshold(Threshold), Cost(0),
130130 AlwaysInline(F.getFnAttributes().hasAlwaysInlineAttr()),
131131 IsCallerRecursive(false), IsRecursiveCall(false),
832832 // one load and one store per word copied.
833833 // FIXME: The maxStoresPerMemcpy setting from the target should be used
834834 // here instead of a magic number of 8, but it's not available via
835 // TargetData.
835 // DataLayout.
836836 NumStores = std::min(NumStores, 8U);
837837
838838 Cost -= 2 * NumStores * InlineConstants::InstrCost;
3030 #include "llvm/Support/GetElementPtrTypeIterator.h"
3131 #include "llvm/Support/PatternMatch.h"
3232 #include "llvm/Support/ValueHandle.h"
33 #include "llvm/Target/TargetData.h"
33 #include "llvm/DataLayout.h"
3434 using namespace llvm;
3535 using namespace llvm::PatternMatch;
3636
4141 STATISTIC(NumReassoc, "Number of reassociations");
4242
4343 struct Query {
44 const TargetData *TD;
44 const DataLayout *TD;
4545 const TargetLibraryInfo *TLI;
4646 const DominatorTree *DT;
4747
48 Query(const TargetData *td, const TargetLibraryInfo *tli,
48 Query(const DataLayout *td, const TargetLibraryInfo *tli,
4949 const DominatorTree *dt) : TD(td), TLI(tli), DT(dt) {}
5050 };
5151
650650 }
651651
652652 Value *llvm::SimplifyAddInst(Value *Op0, Value *Op1, bool isNSW, bool isNUW,
653 const TargetData *TD, const TargetLibraryInfo *TLI,
653 const DataLayout *TD, const TargetLibraryInfo *TLI,
654654 const DominatorTree *DT) {
655655 return ::SimplifyAddInst(Op0, Op1, isNSW, isNUW, Query (TD, TLI, DT),
656656 RecursionLimit);
663663 /// if the GEP has all-constant indices. Returns false if any non-constant
664664 /// index is encountered leaving the 'Offset' in an undefined state. The
665665 /// 'Offset' APInt must be the bitwidth of the target's pointer size.
666 static bool accumulateGEPOffset(const TargetData &TD, GEPOperator *GEP,
666 static bool accumulateGEPOffset(const DataLayout &TD, GEPOperator *GEP,
667667 APInt &Offset) {
668668 unsigned IntPtrWidth = TD.getPointerSizeInBits();
669669 assert(IntPtrWidth == Offset.getBitWidth());
695695 /// accumulates the total constant offset applied in the returned constant. It
696696 /// returns 0 if V is not a pointer, and returns the constant '0' if there are
697697 /// no constant offsets applied.
698 static Constant *stripAndComputeConstantOffsets(const TargetData &TD,
698 static Constant *stripAndComputeConstantOffsets(const DataLayout &TD,
699699 Value *&V) {
700700 if (!V->getType()->isPointerTy())
701701 return 0;
730730
731731 /// \brief Compute the constant difference between two pointer values.
732732 /// If the difference is not a constant, returns zero.
733 static Constant *computePointerDifference(const TargetData &TD,
733 static Constant *computePointerDifference(const DataLayout &TD,
734734 Value *LHS, Value *RHS) {
735735 Constant *LHSOffset = stripAndComputeConstantOffsets(TD, LHS);
736736 if (!LHSOffset)
879879 }
880880
881881 Value *llvm::SimplifySubInst(Value *Op0, Value *Op1, bool isNSW, bool isNUW,
882 const TargetData *TD, const TargetLibraryInfo *TLI,
882 const DataLayout *TD, const TargetLibraryInfo *TLI,
883883 const DominatorTree *DT) {
884884 return ::SimplifySubInst(Op0, Op1, isNSW, isNUW, Query (TD, TLI, DT),
885885 RecursionLimit);
950950 return 0;
951951 }
952952
953 Value *llvm::SimplifyMulInst(Value *Op0, Value *Op1, const TargetData *TD,
953 Value *llvm::SimplifyMulInst(Value *Op0, Value *Op1, const DataLayout *TD,
954954 const TargetLibraryInfo *TLI,
955955 const DominatorTree *DT) {
956956 return ::SimplifyMulInst(Op0, Op1, Query (TD, TLI, DT), RecursionLimit);
10381038 return 0;
10391039 }
10401040
1041 Value *llvm::SimplifySDivInst(Value *Op0, Value *Op1, const TargetData *TD,
1041 Value *llvm::SimplifySDivInst(Value *Op0, Value *Op1, const DataLayout *TD,
10421042 const TargetLibraryInfo *TLI,
10431043 const DominatorTree *DT) {
10441044 return ::SimplifySDivInst(Op0, Op1, Query (TD, TLI, DT), RecursionLimit);
10541054 return 0;
10551055 }
10561056
1057 Value *llvm::SimplifyUDivInst(Value *Op0, Value *Op1, const TargetData *TD,
1057 Value *llvm::SimplifyUDivInst(Value *Op0, Value *Op1, const DataLayout *TD,
10581058 const TargetLibraryInfo *TLI,
10591059 const DominatorTree *DT) {
10601060 return ::SimplifyUDivInst(Op0, Op1, Query (TD, TLI, DT), RecursionLimit);
10731073 return 0;
10741074 }
10751075
1076 Value *llvm::SimplifyFDivInst(Value *Op0, Value *Op1, const TargetData *TD,
1076 Value *llvm::SimplifyFDivInst(Value *Op0, Value *Op1, const DataLayout *TD,
10771077 const TargetLibraryInfo *TLI,
10781078 const DominatorTree *DT) {
10791079 return ::SimplifyFDivInst(Op0, Op1, Query (TD, TLI, DT), RecursionLimit);
11431143 return 0;
11441144 }
11451145
1146 Value *llvm::SimplifySRemInst(Value *Op0, Value *Op1, const TargetData *TD,
1146 Value *llvm::SimplifySRemInst(Value *Op0, Value *Op1, const DataLayout *TD,
11471147 const TargetLibraryInfo *TLI,
11481148 const DominatorTree *DT) {
11491149 return ::SimplifySRemInst(Op0, Op1, Query (TD, TLI, DT), RecursionLimit);
11591159 return 0;
11601160 }
11611161
1162 Value *llvm::SimplifyURemInst(Value *Op0, Value *Op1, const TargetData *TD,
1162 Value *llvm::SimplifyURemInst(Value *Op0, Value *Op1, const DataLayout *TD,
11631163 const TargetLibraryInfo *TLI,
11641164 const DominatorTree *DT) {
11651165 return ::SimplifyURemInst(Op0, Op1, Query (TD, TLI, DT), RecursionLimit);
11781178 return 0;
11791179 }
11801180
1181 Value *llvm::SimplifyFRemInst(Value *Op0, Value *Op1, const TargetData *TD,
1181 Value *llvm::SimplifyFRemInst(Value *Op0, Value *Op1, const DataLayout *TD,
11821182 const TargetLibraryInfo *TLI,
11831183 const DominatorTree *DT) {
11841184 return ::SimplifyFRemInst(Op0, Op1, Query (TD, TLI, DT), RecursionLimit);
12471247 }
12481248
12491249 Value *llvm::SimplifyShlInst(Value *Op0, Value *Op1, bool isNSW, bool isNUW,
1250 const TargetData *TD, const TargetLibraryInfo *TLI,
1250 const DataLayout *TD, const TargetLibraryInfo *TLI,
12511251 const DominatorTree *DT) {
12521252 return ::SimplifyShlInst(Op0, Op1, isNSW, isNUW, Query (TD, TLI, DT),
12531253 RecursionLimit);
12741274 }
12751275
12761276 Value *llvm::SimplifyLShrInst(Value *Op0, Value *Op1, bool isExact,
1277 const TargetData *TD,
1277 const DataLayout *TD,
12781278 const TargetLibraryInfo *TLI,
12791279 const DominatorTree *DT) {
12801280 return ::SimplifyLShrInst(Op0, Op1, isExact, Query (TD, TLI, DT),
13061306 }
13071307
13081308 Value *llvm::SimplifyAShrInst(Value *Op0, Value *Op1, bool isExact,
1309 const TargetData *TD,
1309 const DataLayout *TD,
13101310 const TargetLibraryInfo *TLI,
13111311 const DominatorTree *DT) {
13121312 return ::SimplifyAShrInst(Op0, Op1, isExact, Query (TD, TLI, DT),
14061406 return 0;
14071407 }
14081408
1409 Value *llvm::SimplifyAndInst(Value *Op0, Value *Op1, const TargetData *TD,
1409 Value *llvm::SimplifyAndInst(Value *Op0, Value *Op1, const DataLayout *TD,
14101410 const TargetLibraryInfo *TLI,
14111411 const DominatorTree *DT) {
14121412 return ::SimplifyAndInst(Op0, Op1, Query (TD, TLI, DT), RecursionLimit);
15001500 return 0;
15011501 }
15021502
1503 Value *llvm::SimplifyOrInst(Value *Op0, Value *Op1, const TargetData *TD,
1503 Value *llvm::SimplifyOrInst(Value *Op0, Value *Op1, const DataLayout *TD,
15041504 const TargetLibraryInfo *TLI,
15051505 const DominatorTree *DT) {
15061506 return ::SimplifyOrInst(Op0, Op1, Query (TD, TLI, DT), RecursionLimit);
15601560 return 0;
15611561 }
15621562
1563 Value *llvm::SimplifyXorInst(Value *Op0, Value *Op1, const TargetData *TD,
1563 Value *llvm::SimplifyXorInst(Value *Op0, Value *Op1, const DataLayout *TD,
15641564 const TargetLibraryInfo *TLI,
15651565 const DominatorTree *DT) {
15661566 return ::SimplifyXorInst(Op0, Op1, Query (TD, TLI, DT), RecursionLimit);
15901590 return 0;
15911591 }
15921592
1593 static Constant *computePointerICmp(const TargetData &TD,
1593 static Constant *computePointerICmp(const DataLayout &TD,
15941594 CmpInst::Predicate Pred,
15951595 Value *LHS, Value *RHS) {
15961596 // We can only fold certain predicates on pointer comparisons.
23982398 }
23992399
24002400 Value *llvm::SimplifyICmpInst(unsigned Predicate, Value *LHS, Value *RHS,
2401 const TargetData *TD,
2401 const DataLayout *TD,
24022402 const TargetLibraryInfo *TLI,
24032403 const DominatorTree *DT) {
24042404 return ::SimplifyICmpInst(Predicate, LHS, RHS, Query (TD, TLI, DT),
24952495 }
24962496
24972497 Value *llvm::SimplifyFCmpInst(unsigned Predicate, Value *LHS, Value *RHS,
2498 const TargetData *TD,
2498 const DataLayout *TD,
24992499 const TargetLibraryInfo *TLI,
25002500 const DominatorTree *DT) {
25012501 return ::SimplifyFCmpInst(Predicate, LHS, RHS, Query (TD, TLI, DT),
25302530 }
25312531
25322532 Value *llvm::SimplifySelectInst(Value *Cond, Value *TrueVal, Value *FalseVal,
2533 const TargetData *TD,
2533 const DataLayout *TD,
25342534 const TargetLibraryInfo *TLI,
25352535 const DominatorTree *DT) {
25362536 return ::SimplifySelectInst(Cond, TrueVal, FalseVal, Query (TD, TLI, DT),
25782578 return ConstantExpr::getGetElementPtr(cast(Ops[0]), Ops.slice(1));
25792579 }
25802580
2581 Value *llvm::SimplifyGEPInst(ArrayRef Ops, const TargetData *TD,
2581 Value *llvm::SimplifyGEPInst(ArrayRef Ops, const DataLayout *TD,
25822582 const TargetLibraryInfo *TLI,
25832583 const DominatorTree *DT) {
25842584 return ::SimplifyGEPInst(Ops, Query (TD, TLI, DT), RecursionLimit);
26152615
26162616 Value *llvm::SimplifyInsertValueInst(Value *Agg, Value *Val,
26172617 ArrayRef Idxs,
2618 const TargetData *TD,
2618 const DataLayout *TD,
26192619 const TargetLibraryInfo *TLI,
26202620 const DominatorTree *DT) {
26212621 return ::SimplifyInsertValueInst(Agg, Val, Idxs, Query (TD, TLI, DT),
26632663 return 0;
26642664 }
26652665
2666 Value *llvm::SimplifyTruncInst(Value *Op, Type *Ty, const TargetData *TD,
2666 Value *llvm::SimplifyTruncInst(Value *Op, Type *Ty, const DataLayout *TD,
26672667 const TargetLibraryInfo *TLI,
26682668 const DominatorTree *DT) {
26692669 return ::SimplifyTruncInst(Op, Ty, Query (TD, TLI, DT), RecursionLimit);
27292729 }
27302730
27312731 Value *llvm::SimplifyBinOp(unsigned Opcode, Value *LHS, Value *RHS,
2732 const TargetData *TD, const TargetLibraryInfo *TLI,
2732 const DataLayout *TD, const TargetLibraryInfo *TLI,
27332733 const DominatorTree *DT) {
27342734 return ::SimplifyBinOp(Opcode, LHS, RHS, Query (TD, TLI, DT), RecursionLimit);
27352735 }
27442744 }
27452745
27462746 Value *llvm::SimplifyCmpInst(unsigned Predicate, Value *LHS, Value *RHS,
2747 const TargetData *TD, const TargetLibraryInfo *TLI,
2747 const DataLayout *TD, const TargetLibraryInfo *TLI,
27482748 const DominatorTree *DT) {
27492749 return ::SimplifyCmpInst(Predicate, LHS, RHS, Query (TD, TLI, DT),
27502750 RecursionLimit);
27602760
27612761 /// SimplifyInstruction - See if we can compute a simplified version of this
27622762 /// instruction. If not, this returns null.
2763 Value *llvm::SimplifyInstruction(Instruction *I, const TargetData *TD,
2763 Value *llvm::SimplifyInstruction(Instruction *I, const DataLayout *TD,
27642764 const TargetLibraryInfo *TLI,
27652765 const DominatorTree *DT) {
27662766 Value *Result;
28802880 /// This routine returns 'true' only when *it* simplifies something. The passed
28812881 /// in simplified value does not count toward this.
28822882 static bool replaceAndRecursivelySimplifyImpl(Instruction *I, Value *SimpleV,
2883 const TargetData *TD,
2883 const DataLayout *TD,
28842884 const TargetLibraryInfo *TLI,
28852885 const DominatorTree *DT) {
28862886 bool Simplified = false;
29352935 }
29362936
29372937 bool llvm::recursivelySimplifyInstruction(Instruction *I,
2938 const TargetData *TD,
2938 const DataLayout *TD,
29392939 const TargetLibraryInfo *TLI,
29402940 const DominatorTree *DT) {
29412941 return replaceAndRecursivelySimplifyImpl(I, 0, TD, TLI, DT);
29422942 }
29432943
29442944 bool llvm::replaceAndRecursivelySimplify(Instruction *I, Value *SimpleV,
2945 const TargetData *TD,
2945 const DataLayout *TD,
29462946 const TargetLibraryInfo *TLI,
29472947 const DominatorTree *DT) {
29482948 assert(I != SimpleV && "replaceAndRecursivelySimplify(X,X) is not valid!");
1818 #include "llvm/Instructions.h"
1919 #include "llvm/IntrinsicInst.h"
2020 #include "llvm/Analysis/ConstantFolding.h"
21 #include "llvm/Target/TargetData.h"
21 #include "llvm/DataLayout.h"
2222 #include "llvm/Target/TargetLibraryInfo.h"
2323 #include "llvm/Support/CFG.h"
2424 #include "llvm/Support/ConstantRange.h"
211211
212212 // Unless we can prove that the two Constants are different, we must
213213 // move to overdefined.
214 // FIXME: use TargetData/TargetLibraryInfo for smarter constant folding.
214 // FIXME: use DataLayout/TargetLibraryInfo for smarter constant folding.
215215 if (ConstantInt *Res = dyn_cast(
216216 ConstantFoldCompareInstOperands(CmpInst::ICMP_NE,
217217 getConstant(),
237237
238238 // Unless we can prove that the two Constants are different, we must
239239 // move to overdefined.
240 // FIXME: use TargetData/TargetLibraryInfo for smarter constant folding.
240 // FIXME: use DataLayout/TargetLibraryInfo for smarter constant folding.
241241 if (ConstantInt *Res = dyn_cast(
242242 ConstantFoldCompareInstOperands(CmpInst::ICMP_NE,
243243 getNotConstant(),
10081008 if (PImpl)
10091009 getCache(PImpl).clear();
10101010
1011 TD = getAnalysisIfAvailable<TargetData>();
1011 TD = getAnalysisIfAvailable<DataLayout>();
10121012 TLI = &getAnalysis();
10131013
10141014 // Fully lazy.
4242 #include "llvm/Analysis/Loads.h"
4343 #include "llvm/Analysis/ValueTracking.h"
4444 #include "llvm/Assembly/Writer.h"
45 #include "llvm/Target/TargetData.h"
45 #include "llvm/DataLayout.h"
4646 #include "llvm/Target/TargetLibraryInfo.h"
4747 #include "llvm/Pass.h"
4848 #include "llvm/PassManager.h"
102102 Module *Mod;
103103 AliasAnalysis *AA;
104104 DominatorTree *DT;
105 TargetData *TD;
105 DataLayout *TD;
106106 TargetLibraryInfo *TLI;
107107
108108 std::string Messages;
176176 Mod = F.getParent();
177177 AA = &getAnalysis();
178178 DT = &getAnalysis();
179 TD = getAnalysisIfAvailable<TargetData>();
179 TD = getAnalysisIfAvailable<DataLayout>();
180180 TLI = &getAnalysis();
181181 visit(F);
182182 dbgs() << MessagesStr.str();
505505 "Undefined result: Shift count out of range", &I);
506506 }
507507
508 static bool isZero(Value *V, TargetData *TD) {
508 static bool isZero(Value *V, DataLayout *TD) {
509509 // Assume undef could be zero.
510510 if (isa(V)) return true;
511511
1212
1313 #include "llvm/Analysis/Loads.h"
1414 #include "llvm/Analysis/AliasAnalysis.h"
15 #include "llvm/Target/TargetData.h"
15 #include "llvm/DataLayout.h"
1616 #include "llvm/GlobalAlias.h"
1717 #include "llvm/GlobalVariable.h"
1818 #include "llvm/IntrinsicInst.h"
5151 /// bitcasts to get back to the underlying object being addressed, keeping
5252 /// track of the offset in bytes from the GEPs relative to the result.
5353 /// This is closely related to GetUnderlyingObject but is located
54 /// here to avoid making VMCore depend on TargetData.
55 static Value *getUnderlyingObjectWithOffset(Value *V, const TargetData *TD,
54 /// here to avoid making VMCore depend on DataLayout.
55 static Value *getUnderlyingObjectWithOffset(Value *V, const DataLayout *TD,
5656 uint64_t &ByteOffset,
5757 unsigned MaxLookup = 6) {
5858 if (!V->getType()->isPointerTy())
8484 /// specified pointer, we do a quick local scan of the basic block containing
8585 /// ScanFrom, to determine if the address is already accessed.
8686 bool llvm::isSafeToLoadUnconditionally(Value *V, Instruction *ScanFrom,
87 unsigned Align, const TargetData *TD) {
87 unsigned Align, const DataLayout *TD) {
8888 uint64_t ByteOffset = 0;
8989 Value *Base = V;
9090 if (TD)
3434 #include "llvm/Support/Debug.h"
3535 #include "llvm/Support/ErrorHandling.h"
3636 #include "llvm/Support/raw_ostream.h"
37 #include "llvm/Target/TargetData.h"
37 #include "llvm/DataLayout.h"
3838 using namespace llvm;
3939
4040 STATISTIC(NumAnswered, "Number of dependence queries answered");
2424 #include "llvm/Support/Debug.h"
2525 #include "llvm/Support/MathExtras.h"
2626 #include "llvm/Support/raw_ostream.h"
27 #include "llvm/Target/TargetData.h"
27 #include "llvm/DataLayout.h"
2828 #include "llvm/Target/TargetLibraryInfo.h"
2929 #include "llvm/Transforms/Utils/Local.h"
3030 using namespace llvm;
189189 return isMallocLikeFn(I, TLI) ? dyn_cast(I) : 0;
190190 }
191191
192 static Value *computeArraySize(const CallInst *CI, const TargetData *TD,
192 static Value *computeArraySize(const CallInst *CI, const DataLayout *TD,
193193 const TargetLibraryInfo *TLI,
194194 bool LookThroughSExt = false) {
195195 if (!CI)
219219 /// is a call to malloc whose array size can be determined and the array size
220220 /// is not constant 1. Otherwise, return NULL.
221221 const CallInst *llvm::isArrayMalloc(const Value *I,
222 const TargetData *TD,
222 const DataLayout *TD,
223223 const TargetLibraryInfo *TLI) {
224224 const CallInst *CI = extractMallocCall(I, TLI);
225225 Value *ArraySize = computeArraySize(CI, TD, TLI);
280280 /// then return that multiple. For non-array mallocs, the multiple is
281281 /// constant 1. Otherwise, return NULL for mallocs whose array size cannot be
282282 /// determined.
283 Value *llvm::getMallocArraySize(CallInst *CI, const TargetData *TD,
283 Value *llvm::getMallocArraySize(CallInst *CI, const DataLayout *TD,
284284 const TargetLibraryInfo *TLI,
285285 bool LookThroughSExt) {
286286 assert(isMallocLikeFn(CI, TLI) && "getMallocArraySize and not malloc call");
340340 /// object size in Size if successful, and false otherwise.
341341 /// If RoundToAlign is true, then Size is rounded up to the aligment of allocas,
342342 /// byval arguments, and global variables.
343 bool llvm::getObjectSize(const Value *Ptr, uint64_t &Size, const TargetData *TD,
343 bool llvm::getObjectSize(const Value *Ptr, uint64_t &Size, const DataLayout *TD,
344344 const TargetLibraryInfo *TLI, bool RoundToAlign) {
345345 if (!TD)
346346 return false;
372372 return Size;
373373 }
374374
375 ObjectSizeOffsetVisitor::ObjectSizeOffsetVisitor(const TargetData *TD,
375 ObjectSizeOffsetVisitor::ObjectSizeOffsetVisitor(const DataLayout *TD,
376376 const TargetLibraryInfo *TLI,
377377 LLVMContext &Context,
378378 bool RoundToAlign)
558558 }
559559
560560
561 ObjectSizeOffsetEvaluator::ObjectSizeOffsetEvaluator(const TargetData *TD,
561 ObjectSizeOffsetEvaluator::ObjectSizeOffsetEvaluator(const DataLayout *TD,
562562 const TargetLibraryInfo *TLI,
563563 LLVMContext &Context)
564564 : TD(TD), TLI(TLI), Context(Context), Builder(Context, TargetFolder(TD)) {
2929 #include "llvm/ADT/STLExtras.h"
3030 #include "llvm/Support/PredIteratorCache.h"
3131 #include "llvm/Support/Debug.h"
32 #include "llvm/Target/TargetData.h"
32 #include "llvm/DataLayout.h"
3333 using namespace llvm;
3434
3535 STATISTIC(NumCacheNonLocal, "Number of fully cached non-local responses");
8888
8989 bool MemoryDependenceAnalysis::runOnFunction(Function &) {
9090 AA = &getAnalysis();
91 TD = getAnalysisIfAvailable<TargetData>();
91 TD = getAnalysisIfAvailable<DataLayout>();
9292 DT = getAnalysisIfAvailable();
9393 if (PredCache == 0)
9494 PredCache.reset(new PredIteratorCache());
255255 const Value *&MemLocBase,
256256 int64_t &MemLocOffs,
257257 const LoadInst *LI,
258 const TargetData *TD) {
258 const DataLayout *TD) {
259259 // If we have no target data, we can't do this.
260260 if (TD == 0) return false;
261261
279279 unsigned MemoryDependenceAnalysis::
280280 getLoadLoadClobberFullWidthSize(const Value *MemLocBase, int64_t MemLocOffs,
281281 unsigned MemLocSize, const LoadInst *LI,
282 const TargetData &TD) {
282 const DataLayout &TD) {
283283 // We can only extend simple integer loads.
284284 if (!isa(LI->getType()) || !LI->isSimple()) return 0;
285285
1414 #include "llvm/Analysis/AliasAnalysis.h"
1515 #include "llvm/Analysis/Passes.h"
1616 #include "llvm/Pass.h"
17 #include "llvm/Target/TargetData.h"
17 #include "llvm/DataLayout.h"
1818 using namespace llvm;
1919
2020 namespace {
3535 virtual void initializePass() {
3636 // Note: NoAA does not call InitializeAliasAnalysis because it's
3737 // special and does not support chaining.
38 TD = getAnalysisIfAvailable<TargetData>();
38 TD = getAnalysisIfAvailable<DataLayout>();
3939 }
4040
4141 virtual AliasResult alias(const Location &LocA, const Location &LocB) {
7272 #include "llvm/Analysis/LoopInfo.h"
7373 #include "llvm/Analysis/ValueTracking.h"
7474 #include "llvm/Assembly/Writer.h"
75 #include "llvm/Target/TargetData.h"
75 #include "llvm/DataLayout.h"
7676 #include "llvm/Target/TargetLibraryInfo.h"
7777 #include "llvm/Support/CommandLine.h"
7878 #include "llvm/Support/ConstantRange.h"
25812581 }
25822582
25832583 const SCEV *ScalarEvolution::getSizeOfExpr(Type *AllocTy) {
2584 // If we have TargetData, we can bypass creating a target-independent
2584 // If we have DataLayout, we can bypass creating a target-independent
25852585 // constant expression and then folding it back into a ConstantInt.
25862586 // This is just a compile-time optimization.
25872587 if (TD)
26072607
26082608 const SCEV *ScalarEvolution::getOffsetOfExpr(StructType *STy,
26092609 unsigned FieldNo) {
2610 // If we have TargetData, we can bypass creating a target-independent
2610 // If we have DataLayout, we can bypass creating a target-independent
26112611 // constant expression and then folding it back into a ConstantInt.
26122612 // This is just a compile-time optimization.
26132613 if (TD)
26722672 uint64_t ScalarEvolution::getTypeSizeInBits(Type *Ty) const {
26732673 assert(isSCEVable(Ty) && "Type is not SCEVable!");
26742674
2675 // If we have a TargetData, use it!
2675 // If we have a DataLayout, use it!
26762676 if (TD)
26772677 return TD->getTypeSizeInBits(Ty);
26782678
26802680 if (Ty->isIntegerTy())
26812681 return Ty->getPrimitiveSizeInBits();
26822682
2683 // The only other support type is pointer. Without TargetData, conservatively
2683 // The only other support type is pointer. Without DataLayout, conservatively
26842684 // assume pointers are 64-bit.
26852685 assert(Ty->isPointerTy() && "isSCEVable permitted a non-SCEVable type!");
26862686 return 64;
27002700 assert(Ty->isPointerTy() && "Unexpected non-pointer non-integer type!");
27012701 if (TD) return TD->getIntPtrType(getContext());
27022702
2703 // Without TargetData, conservatively assume pointers are 64-bit.
2703 // Without DataLayout, conservatively assume pointers are 64-bit.
27042704 return Type::getInt64Ty(getContext());
27052705 }
27062706
47504750 /// reason, return null.
47514751 static Constant *EvaluateExpression(Value *V, const Loop *L,
47524752 DenseMap &Vals,
4753 const TargetData *TD,
4753 const DataLayout *TD,
47544754 const TargetLibraryInfo *TLI) {
47554755 // Convenient constant check, but redundant for recursive calls.
47564756 if (Constant *C = dyn_cast(V)) return C;
65896589 bool ScalarEvolution::runOnFunction(Function &F) {
65906590 this->F = &F;
65916591 LI = &getAnalysis();
6592 TD = getAnalysisIfAvailable<TargetData>();
6592 TD = getAnalysisIfAvailable<DataLayout>();
65936593 TLI = &getAnalysis();
65946594 DT = &getAnalysis();
65956595 return false;
1717 #include "llvm/IntrinsicInst.h"
1818 #include "llvm/LLVMContext.h"
1919 #include "llvm/Support/Debug.h"
20 #include "llvm/Target/TargetData.h"
20 #include "llvm/DataLayout.h"
2121 #include "llvm/Target/TargetLowering.h"
2222 #include "llvm/ADT/STLExtras.h"
2323
211211 const SCEV *&Remainder,
212212 const SCEV *Factor,
213213 ScalarEvolution &SE,
214 const TargetData *TD) {
214 const DataLayout *TD) {
215215 // Everything is divisible by one.
216216 if (Factor->isOne())
217217 return true;
252252 // of the given factor.
253253 if (const SCEVMulExpr *M = dyn_cast(S)) {
254254 if (TD) {
255 // With TargetData, the size is known. Check if there is a constant
255 // With DataLayout, the size is known. Check if there is a constant
256256 // operand which is a multiple of the given factor. If so, we can
257257 // factor it.
258258 const SCEVConstant *FC = cast(Factor);
266266 return true;
267267 }
268268 } else {
269 // Without TargetData, check if Factor can be factored out of any of the
269 // Without DataLayout, check if Factor can be factored out of any of the
270270 // Mul's operands. If so, we can just remove it.
271271 for (unsigned i = 0, e = M->getNumOperands(); i != e; ++i) {
272272 const SCEV *SOp = M->getOperand(i);
457457 // An empty struct has no fields.
458458 if (STy->getNumElements() == 0) break;
459459 if (SE.TD) {
460 // With TargetData, field offsets are known. See if a constant offset
460 // With DataLayout, field offsets are known. See if a constant offset
461461 // falls within any of the struct fields.
462462 if (Ops.empty()) break;
463463 if (const SCEVConstant *C = dyn_cast(Ops[0]))
476476 }
477477 }
478478 } else {
479 // Without TargetData, just check for an offsetof expression of the
479 // Without DataLayout, just check for an offsetof expression of the
480480 // appropriate struct type.
481481 for (unsigned i = 0, e = Ops.size(); i != e; ++i)
482482 if (const SCEVUnknown *U = dyn_cast(Ops[i])) {
2121 #include "llvm/LLVMContext.h"
2222 #include "llvm/Metadata.h"
2323 #include "llvm/Operator.h"
24 #include "llvm/Target/TargetData.h"
24 #include "llvm/DataLayout.h"
2525 #include "llvm/Support/ConstantRange.h"
2626 #include "llvm/Support/GetElementPtrTypeIterator.h"
2727 #include "llvm/Support/MathExtras.h"
3535
3636 /// getBitWidth - Returns the bitwidth of the given scalar or pointer type (if
3737 /// unknown returns 0). For vector types, returns the element type's bitwidth.
38 static unsigned getBitWidth(Type *Ty, const TargetData *TD) {
38 static unsigned getBitWidth(Type *Ty, const DataLayout *TD) {
3939 if (unsigned BitWidth = Ty->getScalarSizeInBits())
4040 return BitWidth;
4141 assert(isa(Ty) && "Expected a pointer type!");
4545 static void ComputeMaskedBitsAddSub(bool Add, Value *Op0, Value *Op1, bool NSW,
4646 APInt &KnownZero, APInt &KnownOne,
4747 APInt &KnownZero2, APInt &KnownOne2,
48 const TargetData *TD, unsigned Depth) {
48 const DataLayout *TD, unsigned Depth) {
4949 if (!Add) {
5050 if (ConstantInt *CLHS = dyn_cast(Op0)) {
5151 // We know that the top bits of C-X are clear if X contains less bits
131131 static void ComputeMaskedBitsMul(Value *Op0, Value *Op1, bool NSW,
132132 APInt &KnownZero, APInt &KnownOne,
133133 APInt &KnownZero2, APInt &KnownOne2,
134 const TargetData *TD, unsigned Depth) {
134 const DataLayout *TD, unsigned Depth) {
135135 unsigned BitWidth = KnownZero.getBitWidth();
136136 ComputeMaskedBits(Op1, KnownZero, KnownOne, TD, Depth+1);
137137 ComputeMaskedBits(Op0, KnownZero2, KnownOne2, TD, Depth+1);
225225 /// same width as the vector element, and the bit is set only if it is true
226226 /// for all of the elements in the vector.
227227 void llvm::ComputeMaskedBits(Value *V, APInt &KnownZero, APInt &KnownOne,
228 const TargetData *TD, unsigned Depth) {
228 const DataLayout *TD, unsigned Depth) {
229229 assert(V && "No Value?");
230230 assert(Depth <= MaxDepth && "Limit Search Depth");
231231 unsigned BitWidth = KnownZero.getBitWidth();
786786 /// ComputeSignBit - Determine whether the sign bit is known to be zero or
787787 /// one. Convenience wrapper around ComputeMaskedBits.
788788 void llvm::ComputeSignBit(Value *V, bool &KnownZero, bool &KnownOne,
789 const TargetData *TD, unsigned Depth) {
789 const DataLayout *TD, unsigned Depth) {
790790 unsigned BitWidth = getBitWidth(V->getType(), TD);
791791 if (!BitWidth) {
792792 KnownZero = false;
804804 /// bit set when defined. For vectors return true if every element is known to
805805 /// be a power of two when defined. Supports values with integer or pointer
806806 /// types and vectors of integers.
807 bool llvm::isPowerOfTwo(Value *V, const TargetData *TD, bool OrZero,
807 bool llvm::isPowerOfTwo(Value *V, const DataLayout *TD, bool OrZero,
808808 unsigned Depth) {
809809 if (Constant *C = dyn_cast(V)) {
810810 if (C->isNullValue())
867867 /// when defined. For vectors return true if every element is known to be
868868 /// non-zero when defined. Supports values with integer or pointer type and
869869 /// vectors of integers.
870 bool llvm::isKnownNonZero(Value *V, const TargetData *TD, unsigned Depth) {
870 bool llvm::isKnownNonZero(Value *V, const DataLayout *TD, unsigned Depth) {
871871 if (Constant *C = dyn_cast(V)) {
872872 if (C->isNullValue())
873873 return false;
994994 /// same width as the vector element, and the bit is set only if it is true
995995 /// for all of the elements in the vector.
996996 bool llvm::MaskedValueIsZero(Value *V, const APInt &Mask,
997 const TargetData *TD, unsigned Depth) {
997 const DataLayout *TD, unsigned Depth) {
998998 APInt KnownZero(Mask.getBitWidth(), 0), KnownOne(Mask.getBitWidth(), 0);
999999 ComputeMaskedBits(V, KnownZero, KnownOne, TD, Depth);
10001000 assert((KnownZero & KnownOne) == 0 && "Bits known to be one AND zero?");
10111011 ///
10121012 /// 'Op' must have a scalar integer type.
10131013 ///
1014 unsigned llvm::ComputeNumSignBits(Value *V, const TargetData *TD,
1014 unsigned llvm::ComputeNumSignBits(Value *V, const DataLayout *TD,
10151015 unsigned Depth) {
10161016 assert((TD || V->getType()->isIntOrIntVectorTy()) &&
1017 "ComputeNumSignBits requires a TargetData object to operate "
1017 "ComputeNumSignBits requires a DataLayout object to operate "
10181018 "on non-integer values!");
10191019 Type *Ty = V->getType();
10201020 unsigned TyBits = TD ? TD->getTypeSizeInBits(V->getType()->getScalarType()) :
15901590 /// it can be expressed as a base pointer plus a constant offset. Return the
15911591 /// base and offset to the caller.
15921592 Value *llvm::GetPointerBaseWithConstantOffset(Value *Ptr, int64_t &Offset,
1593 const TargetData &TD) {
1593 const DataLayout &TD) {
15941594 Operator *PtrOp = dyn_cast(Ptr);
15951595 if (PtrOp == 0 || Ptr->getType()->isVectorTy())
15961596 return Ptr;
17761776 }
17771777
17781778 Value *
1779 llvm::GetUnderlyingObject(Value *V, const TargetData *TD, unsigned MaxLookup) {
1779 llvm::GetUnderlyingObject(Value *V, const DataLayout *TD, unsigned MaxLookup) {
17801780 if (!V->getType()->isPointerTy())
17811781 return V;
17821782 for (unsigned Count = 0; MaxLookup == 0 || Count < MaxLookup; ++Count) {
18071807 void
18081808 llvm::GetUnderlyingObjects(Value *V,
18091809 SmallVectorImpl &Objects,
1810 const TargetData *TD,
1810 const DataLayout *TD,
18111811 unsigned MaxLookup) {
18121812 SmallPtrSet Visited;
18131813 SmallVector Worklist;
18521852 }
18531853
18541854 bool llvm::isSafeToSpeculativelyExecute(const Value *V,
1855 const TargetData *TD) {
1855 const DataLayout *TD) {
18561856 const Operator *Inst = dyn_cast(V);
18571857 if (!Inst)
18581858 return false;
2020 #include "llvm/Module.h"
2121 #include "llvm/CodeGen/MachineFunction.h"
2222 #include "llvm/CodeGen/SelectionDAG.h"
23 #include "llvm/Target/TargetData.h"
23 #include "llvm/DataLayout.h"
2424 #include "llvm/Target/TargetLowering.h"
2525 #include "llvm/Target/TargetOptions.h"
2626 #include "llvm/Support/ErrorHandling.h"
7878 uint64_t StartingOffset) {
7979 // Given a struct type, recursively traverse the elements.
8080 if (StructType *STy = dyn_cast(Ty)) {
81 const StructLayout *SL = TLI.getTargetData()->getStructLayout(STy);
81 const StructLayout *SL = TLI.getDataLayout()->getStructLayout(STy);
8282 for (StructType::element_iterator EB = STy->element_begin(),
8383 EI = EB,
8484 EE = STy->element_end();
9090 // Given an array type, recursively traverse the elements.
9191 if (ArrayType *ATy = dyn_cast(Ty)) {
9292 Type *EltTy = ATy->getElementType();
93 uint64_t EltSize = TLI.getTargetData()->getTypeAllocSize(EltTy);
93 uint64_t EltSize = TLI.getDataLayout()->getTypeAllocSize(EltTy);
9494 for (unsigned i = 0, e = ATy->getNumElements(); i != e; ++i)
9595 ComputeValueVTs(TLI, EltTy, ValueVTs, Offsets,
9696 StartingOffset + i * EltSize);
2323 #include "llvm/MC/MCStreamer.h"
2424 #include "llvm/MC/MCSymbol.h"
2525 #include "llvm/Target/Mangler.h"
26 #include "llvm/Target/TargetData.h"
26 #include "llvm/DataLayout.h"
2727 #include "llvm/Target/TargetFrameLowering.h"
2828 #include "llvm/Target/TargetMachine.h"
2929 #include "llvm/Target/TargetOptions.h"
3232 #include "llvm/MC/MCStreamer.h"
3333 #include "llvm/MC/MCSymbol.h"
3434 #include "llvm/Target/Mangler.h"
35 #include "llvm/Target/TargetData.h"
35 #include "llvm/DataLayout.h"
3636 #include "llvm/Target/TargetInstrInfo.h"
3737 #include "llvm/Target/TargetLowering.h"
3838 #include "llvm/Target/TargetLoweringObjectFile.h"
6666 /// getGVAlignmentLog2 - Return the alignment to use for the specified global
6767 /// value in log2 form. This rounds up to the preferred alignment if possible
6868 /// and legal.
69 static unsigned getGVAlignmentLog2(const GlobalValue *GV, const TargetData &TD,
69 static unsigned getGVAlignmentLog2(const GlobalValue *GV, const DataLayout &TD,
7070 unsigned InBits = 0) {
7171 unsigned NumBits = 0;
7272 if (const GlobalVariable *GVar = dyn_cast(GV))
130130 }
131131
132132
133 /// getTargetData - Return information about data layout.
134 const TargetData &AsmPrinter::getTargetData() const {
135 return *TM.getTargetData();
133 /// getDataLayout - Return information about data layout.
134 const DataLayout &AsmPrinter::getDataLayout() const {
135 return *TM.getDataLayout();
136136 }
137137
138138 /// getCurrentSection() - Return the current section we are emitting to.
159159 const_cast(getObjFileLowering())
160160 .Initialize(OutContext, TM);
161161
162 Mang = new Mangler(OutContext, *TM.getTargetData());
162 Mang = new Mangler(OutContext, *TM.getDataLayout());
163163
164164 // Allow the target to emit any magic that it wants at the start of the file.
165165 EmitStartOfAsmFile(M);
279279
280280 SectionKind GVKind = TargetLoweringObjectFile::getKindForGlobal(GV, TM);
281281
282 const TargetData *TD = TM.getTargetData();
282 const DataLayout *TD = TM.getDataLayout();
283283 uint64_t Size = TD->getTypeAllocSize(GV->getType()->getElementType());
284284
285285 // If the alignment is specified, we *must* obey it. Overaligning a global
990990 Kind = SectionKind::getReadOnlyWithRelLocal();
991991 break;
992992 case 0:
993 switch (TM.getTargetData()->getTypeAllocSize(CPE.getType())) {
993 switch (TM.getDataLayout()->getTypeAllocSize(CPE.getType())) {
994994 case 4: Kind = SectionKind::getMergeableConst4(); break;
995995 case 8: Kind = SectionKind::getMergeableConst8(); break;
996996 case 16: Kind = SectionKind::getMergeableConst16();break;
10361036 OutStreamer.EmitFill(NewOffset - Offset, 0/*fillval*/, 0/*addrspace*/);
10371037
10381038 Type *Ty = CPE.getType();
1039 Offset = NewOffset + TM.getTargetData()->getTypeAllocSize(Ty);
1039 Offset = NewOffset + TM.getDataLayout()->getTypeAllocSize(Ty);
10401040 OutStreamer.EmitLabel(GetCPISymbol(CPI));
10411041
10421042 if (CPE.isMachineConstantPoolEntry())
10791079 JTInDiffSection = true;
10801080 }
10811081
1082 EmitAlignment(Log2_32(MJTI->getEntryAlignment(*TM.getTargetData())));
1082 EmitAlignment(Log2_32(MJTI->getEntryAlignment(*TM.getDataLayout())));
10831083
10841084 // Jump tables in code sections are marked with a data_region directive
10851085 // where that's supported.
11951195
11961196 assert(Value && "Unknown entry kind!");
11971197
1198 unsigned EntrySize = MJTI->getEntrySize(*TM.getTargetData());
1198 unsigned EntrySize = MJTI->getEntrySize(*TM.getDataLayout());
11991199 OutStreamer.EmitValue(Value, EntrySize, /*addrspace*/0);
12001200 }
12011201
12971297 }
12981298
12991299 // Emit the function pointers in the target-specific order
1300 const TargetData *TD = TM.getTargetData();
1300 const DataLayout *TD = TM.getDataLayout();
13011301 unsigned Align = Log2_32(TD->getPointerPrefAlignment());
13021302 std::stable_sort(Structors.begin(), Structors.end(), priority_order);
13031303 for (unsigned i = 0, e = Structors.size(); i != e; ++i) {
14131413 // if required for correctness.
14141414 //
14151415 void AsmPrinter::EmitAlignment(unsigned NumBits, const GlobalValue *GV) const {
1416 if (GV) NumBits = getGVAlignmentLog2(GV, *TM.getTargetData(), NumBits);
1416 if (GV) NumBits = getGVAlignmentLog2(GV, *TM.getDataLayout(), NumBits);
14171417
14181418 if (NumBits == 0) return; // 1-byte aligned: no need to emit alignment.
14191419
14521452 switch (CE->getOpcode()) {
14531453 default:
14541454 // If the code isn't optimized, there may be outstanding folding
1455 // opportunities. Attempt to fold the expression using TargetData as a
1455 // opportunities. Attempt to fold the expression using DataLayout as a
14561456 // last resort before giving up.
14571457 if (Constant *C =
1458 ConstantFoldConstantExpression(CE, AP.TM.getTargetData()))
1458 ConstantFoldConstantExpression(CE, AP.TM.getDataLayout()))
14591459 if (C != CE)
14601460 return lowerConstant(C, AP);
14611461
14691469 report_fatal_error(OS.str());
14701470 }
14711471 case Instruction::GetElementPtr: {
1472 const TargetData &TD = *AP.TM.getTargetData();
1472 const DataLayout &TD = *AP.TM.getDataLayout();
14731473 // Generate a symbolic expression for the byte address
14741474 const Constant *PtrVal = CE->getOperand(0);
14751475 SmallVector IdxVec(CE->op_begin()+1, CE->op_end());
14981498 return lowerConstant(CE->getOperand(0), AP);
14991499
15001500 case Instruction::IntToPtr: {
1501 const TargetData &TD = *AP.TM.getTargetData();
1501 const DataLayout &TD = *AP.TM.getDataLayout();
15021502 // Handle casts to pointers by changing them into casts to the appropriate
15031503 // integer type. This promotes constant folding and simplifies this code.
15041504 Constant *Op = CE->getOperand(0);
15081508 }
15091509
15101510 case Instruction::PtrToInt: {
1511 const TargetData &TD = *AP.TM.getTargetData();
1511 const DataLayout &TD = *AP.TM.getDataLayout();
15121512 // Support only foldable casts to/from pointers that can be eliminated by
15131513 // changing the pointer to the appropriately sized integer type.
15141514 Constant *Op = CE->getOperand(0);
15821582 if (const ConstantInt *CI = dyn_cast(V)) {
15831583 if (CI->getBitWidth() > 64) return -1;
15841584
1585 uint64_t Size = TM.getTargetData()->getTypeAllocSize(V->getType());
1585 uint64_t Size = TM.getDataLayout()->getTypeAllocSize(V->getType());
15861586 uint64_t Value = CI->getZExtValue();
15871587
15881588 // Make sure the constant is at least 8 bits long and has a power
16261626 // See if we can aggregate this into a .fill, if so, emit it as such.
16271627 int Value = isRepeatedByteSequence(CDS, AP.TM);
16281628 if (Value != -1) {
1629 uint64_t Bytes = AP.TM.getTargetData()->getTypeAllocSize(CDS->getType());
1629 uint64_t Bytes = AP.TM.getDataLayout()->getTypeAllocSize(CDS->getType());
16301630 // Don't emit a 1-byte object as a .fill.
16311631 if (Bytes > 1)
16321632 return AP.OutStreamer.EmitFill(Bytes, Value, AddrSpace);
16761676 }
16771677 }
16781678
1679 const TargetData &TD = *AP.TM.getTargetData();
1679 const DataLayout &TD = *AP.TM.getDataLayout();
16801680 unsigned Size = TD.getTypeAllocSize(CDS->getType());
16811681 unsigned EmittedSize = TD.getTypeAllocSize(CDS->getType()->getElementType()) *
16821682 CDS->getNumElements();
16921692 int Value = isRepeatedByteSequence(CA, AP.TM);
16931693
16941694 if (Value != -1) {
1695 uint64_t Bytes = AP.TM.getTargetData()->getTypeAllocSize(CA->getType());
1695 uint64_t Bytes = AP.TM.getDataLayout()->getTypeAllocSize(CA->getType());
16961696 AP.OutStreamer.EmitFill(Bytes, Value, AddrSpace);
16971697 }
16981698 else {
17061706 for (unsigned i = 0, e = CV->getType()->getNumElements(); i != e; ++i)
17071707 emitGlobalConstantImpl(CV->getOperand(i), AddrSpace, AP);
17081708
1709 const TargetData &TD = *AP.TM.getTargetData();
1709 const DataLayout &TD = *AP.TM.getDataLayout();
17101710 unsigned Size = TD.getTypeAllocSize(CV->getType());
17111711 unsigned EmittedSize = TD.getTypeAllocSize(CV->getType()->getElementType()) *
17121712 CV->getType()->getNumElements();
17171717 static void emitGlobalConstantStruct(const ConstantStruct *CS,
17181718 unsigned AddrSpace, AsmPrinter &AP) {
17191719 // Print the fields in successive locations. Pad to align if needed!
1720 const TargetData *TD = AP.TM.getTargetData();
1720 const DataLayout *TD = AP.TM.getDataLayout();
17211721 unsigned Size = TD->getTypeAllocSize(CS->getType());
17221722 const StructLayout *Layout = TD->getStructLayout(CS->getType());
17231723 uint64_t SizeSoFar = 0;
17971797 << DoubleVal.convertToDouble() << '\n';
17981798 }
17991799
1800 if (AP.TM.getTargetData()->isBigEndian()) {
1800 if (AP.TM.getDataLayout()->isBigEndian()) {
18011801 AP.OutStreamer.EmitIntValue(p[1], 2, AddrSpace);
18021802 AP.OutStreamer.EmitIntValue(p[0], 8, AddrSpace);
18031803 } else {
18061806 }
18071807
18081808 // Emit the tail padding for the long double.
1809 const TargetData &TD = *AP.TM.getTargetData();
1809 const DataLayout &TD = *AP.TM.getDataLayout();
18101810 AP.OutStreamer.EmitZeros(TD.getTypeAllocSize(CFP->getType()) -
18111811 TD.getTypeStoreSize(CFP->getType()), AddrSpace);
18121812 return;
18181818 // API needed to prevent premature destruction.
18191819 APInt API = CFP->getValueAPF().bitcastToAPInt();
18201820 const uint64_t *p = API.getRawData();
1821 if (AP.TM.getTargetData()->isBigEndian()) {
1821 if (AP.TM.getDataLayout()->isBigEndian()) {
18221822 AP.OutStreamer.EmitIntValue(p[0], 8, AddrSpace);
18231823 AP.OutStreamer.EmitIntValue(p[1], 8, AddrSpace);
18241824 } else {
18291829
18301830 static void emitGlobalConstantLargeInt(const ConstantInt *CI,
18311831 unsigned AddrSpace, AsmPrinter &AP) {
1832 const TargetData *TD = AP.TM.getTargetData();
1832 const DataLayout *TD = AP.TM.getDataLayout();
18331833 unsigned BitWidth = CI->getBitWidth();
18341834 assert((BitWidth & 63) == 0 && "only support multiples of 64-bits");
18351835
18451845
18461846 static void emitGlobalConstantImpl(const Constant *CV, unsigned AddrSpace,
18471847 AsmPrinter &AP) {
1848 const TargetData *TD = AP.TM.getTargetData();
1848 const DataLayout *TD = AP.TM.getDataLayout();
18491849 uint64_t Size = TD->getTypeAllocSize(CV->getType());
18501850 if (isa(CV) || isa(CV))
18511851 return AP.OutStreamer.EmitZeros(Size, AddrSpace);
19101910
19111911 /// EmitGlobalConstant - Print a general LLVM constant to the .s file.
19121912 void AsmPrinter::EmitGlobalConstant(const Constant *CV, unsigned AddrSpace) {
1913 uint64_t Size = TM.getTargetData()->getTypeAllocSize(CV->getType());
1913 uint64_t Size = TM.getDataLayout()->getTypeAllocSize(CV->getType());
19141914 if (Size)
19151915 emitGlobalConstantImpl(CV, AddrSpace, *this);
19161916 else if (MAI->hasSubsectionsViaSymbols()) {
1717 #include "llvm/MC/MCSection.h"
1818 #include "llvm/MC/MCStreamer.h"
1919 #include "llvm/MC/MCSymbol.h"
20 #include "llvm/Target/TargetData.h"
20 #include "llvm/DataLayout.h"
2121 #include "llvm/Target/TargetFrameLowering.h"
2222 #include "llvm/Target/TargetLoweringObjectFile.h"
2323 #include "llvm/Target/TargetMachine.h"
111111
112112 switch (Encoding & 0x07) {
113113 default: llvm_unreachable("Invalid encoded value.");
114 case dwarf::DW_EH_PE_absptr: return TM.getTargetData()->getPointerSize();
114 case dwarf::DW_EH_PE_absptr: return TM.getDataLayout()->getPointerSize();
115115 case dwarf::DW_EH_PE_udata2: return 2;
116116 case dwarf::DW_EH_PE_udata4: return 4;
117117 case dwarf::DW_EH_PE_udata8: return 8;
1616 #include "llvm/MC/MCAsmInfo.h"
1717 #include "llvm/MC/MCStreamer.h"
1818 #include "llvm/MC/MCSymbol.h"
19 #include "llvm/Target/TargetData.h"
19 #include "llvm/DataLayout.h"
2020 #include "llvm/Support/Allocator.h"
2121 #include "llvm/Support/Debug.h"
2222 #include "llvm/Support/ErrorHandling.h"
199199 case dwarf::DW_FORM_udata: Asm->EmitULEB128(Integer); return;
200200 case dwarf::DW_FORM_sdata: Asm->EmitSLEB128(Integer); return;
201201 case dwarf::DW_FORM_addr:
202 Size = Asm->getTargetData().getPointerSize(); break;
202 Size = Asm->getDataLayout().getPointerSize(); break;
203203 default: llvm_unreachable("DIE Value form not supported yet");
204204 }
205205 Asm->OutStreamer.EmitIntValue(Integer, Size, 0/*addrspace*/);
221221 case dwarf::DW_FORM_data8: return sizeof(int64_t);
222222 case dwarf::DW_FORM_udata: return MCAsmInfo::getULEB128Size(Integer);
223223 case dwarf::DW_FORM_sdata: return MCAsmInfo::getSLEB128Size(Integer);
224 case dwarf::DW_FORM_addr: return AP->getTargetData().getPointerSize();
224 case dwarf::DW_FORM_addr: return AP->getDataLayout().getPointerSize();
225225 default: llvm_unreachable("DIE Value form not supported yet");
226226 }
227227 }
248248 unsigned DIELabel::SizeOf(AsmPrinter *AP, unsigned Form) const {
249249 if (Form == dwarf::DW_FORM_data4) return 4;
250250 if (Form == dwarf::DW_FORM_strp) return 4;
251 return AP->getTargetData().getPointerSize();
251 return AP->getDataLayout().getPointerSize();
252252 }
253253
254254 #ifndef NDEBUG
272272 unsigned DIEDelta::SizeOf(AsmPrinter *AP, unsigned Form) const {
273273 if (Form == dwarf::DW_FORM_data4) return 4;
274274 if (Form == dwarf::DW_FORM_strp) return 4;
275 return AP->getTargetData().getPointerSize();
275 return AP->getDataLayout().getPointerSize();
276276 }
277277
278278 #ifndef NDEBUG
2424 #include "llvm/MC/MCStreamer.h"
2525 #include "llvm/MC/MCSymbol.h"
2626 #include "llvm/Target/Mangler.h"
27 #include "llvm/Target/TargetData.h"
27 #include "llvm/DataLayout.h"
2828 #include "llvm/Target/TargetFrameLowering.h"
2929 #include "llvm/Target/TargetLoweringObjectFile.h"
3030 #include "llvm/Target/TargetMachine.h"
2121 #include "llvm/Instructions.h"
2222 #include "llvm/Support/Debug.h"
2323 #include "llvm/Target/Mangler.h"
24 #include "llvm/Target/TargetData.h"
24 #include "llvm/DataLayout.h"
2525 #include "llvm/Target/TargetFrameLowering.h"
2626 #include "llvm/Target/TargetMachine.h"
2727 #include "llvm/Target/TargetRegisterInfo.h"
509509 const char *FltPtr = (const char*)FltVal.getRawData();
510510
511511 int NumBytes = FltVal.getBitWidth() / 8; // 8 bits per byte.
512 bool LittleEndian = Asm->getTargetData().isLittleEndian();
512 bool LittleEndian = Asm->getDataLayout().isLittleEndian();
513513 int Incr = (LittleEndian ? 1 : -1);
514514 int Start = (LittleEndian ? 0 : NumBytes - 1);
515515 int Stop = (LittleEndian ? NumBytes : -1);
551551 const uint64_t *Ptr64 = Val.getRawData();
552552
553553 int NumBytes = Val.getBitWidth() / 8; // 8 bits per byte.
554 bool LittleEndian = Asm->getTargetData().isLittleEndian();
554 bool LittleEndian = Asm->getDataLayout().isLittleEndian();
555555
556556 // Output the constant to DWARF one byte at a time.
557557 for (int i = 0; i < NumBytes; i++) {
12261226 addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_constu);
12271227 SmallVector Idx(CE->op_begin()+1, CE->op_end());
12281228 addUInt(Block, 0, dwarf::DW_FORM_udata,
1229 Asm->getTargetData().getIndexedOffset(Ptr->getType(), Idx));
1229 Asm->getDataLayout().getIndexedOffset(Ptr->getType(), Idx));
12301230 addUInt(Block, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_plus);
12311231 addBlock(VariableDIE, dwarf::DW_AT_location, 0, Block);
12321232 }
14581458 Offset -= FieldOffset;
14591459
14601460 // Maybe we need to work from the other end.
1461 if (Asm->getTargetData().isLittleEndian())
1461 if (Asm->getDataLayout().isLittleEndian())
14621462 Offset = FieldSize - (Offset + Size);
14631463 addUInt(MemberDie, dwarf::DW_AT_bit_offset, 0, Offset);
14641464
2626 #include "llvm/MC/MCSection.h"
2727 #include "llvm/MC/MCStreamer.h"
2828 #include "llvm/MC/MCSymbol.h"
29 #include "llvm/Target/TargetData.h"
29 #include "llvm/DataLayout.h"
3030 #include "llvm/Target/TargetFrameLowering.h"
3131 #include "llvm/Target/TargetLoweringObjectFile.h"
3232 #include "llvm/Target/TargetMachine.h"
383383 // DW_AT_ranges appropriately.
384384 TheCU->addUInt(ScopeDIE, dwarf::DW_AT_ranges, dwarf::DW_FORM_data4,
385385 DebugRangeSymbols.size()
386 * Asm->getTargetData().getPointerSize());
386 * Asm->getDataLayout().getPointerSize());
387387 for (SmallVector::const_iterator RI = Ranges.begin(),
388388 RE = Ranges.end(); RI != RE; ++RI) {
389389 DebugRangeSymbols.push_back(getLabelBeforeInsn(RI->first));
449449 // DW_AT_ranges appropriately.
450450 TheCU->addUInt(ScopeDIE, dwarf::DW_AT_ranges, dwarf::DW_FORM_data4,
451451 DebugRangeSymbols.size()
452 * Asm->getTargetData().getPointerSize());
452 * Asm->getDataLayout().getPointerSize());
453453 for (SmallVector::const_iterator RI = Ranges.begin(),
454454 RE = Ranges.end(); RI != RE; ++RI) {
455455 DebugRangeSymbols.push_back(getLabelBeforeInsn(RI->first));
17641764 Asm->EmitSectionOffset(Asm->GetTempSymbol("abbrev_begin"),
17651765 DwarfAbbrevSectionSym);
17661766 Asm->OutStreamer.AddComment("Address Size (in bytes)");
1767 Asm->EmitInt8(Asm->getTargetData().getPointerSize());
1767 Asm->EmitInt8(Asm->getDataLayout().getPointerSize());
17681768
17691769 emitDIE(Die);
17701770 Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("info_end", TheCU->getID()));
18101810 Asm->EmitInt8(0);
18111811
18121812 Asm->OutStreamer.AddComment("Op size");
1813 Asm->EmitInt8(Asm->getTargetData().getPointerSize() + 1);
1813 Asm->EmitInt8(Asm->getDataLayout().getPointerSize() + 1);
18141814 Asm->OutStreamer.AddComment("DW_LNE_set_address");
18151815 Asm->EmitInt8(dwarf::DW_LNE_set_address);
18161816
18171817 Asm->OutStreamer.AddComment("Section end label");
18181818
18191819 Asm->OutStreamer.EmitSymbolValue(Asm->GetTempSymbol("section_end",SectionEnd),
1820 Asm->getTargetData().getPointerSize(),
1820 Asm->getDataLayout().getPointerSize(),
18211821 0/*AddrSpace*/);
18221822
18231823 // Mark end of matrix.
20462046 // Start the dwarf loc section.
20472047 Asm->OutStreamer.SwitchSection(
20482048 Asm->getObjFileLowering().getDwarfLocSection());
2049 unsigned char Size = Asm->getTargetData().getPointerSize();
2049 unsigned char Size = Asm->getDataLayout().getPointerSize();
20502050 Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("debug_loc", 0));
20512051 unsigned index = 1;
20522052 for (SmallVector::iterator
21432143 // Start the dwarf ranges section.
21442144 Asm->OutStreamer.SwitchSection(
21452145 Asm->getObjFileLowering().getDwarfRangesSection());
2146 unsigned char Size = Asm->getTargetData().getPointerSize();
2146 unsigned char Size = Asm->getDataLayout().getPointerSize();
21472147 for (SmallVector::iterator
21482148 I = DebugRangeSymbols.begin(), E = DebugRangeSymbols.end();
21492149 I != E; ++I) {
22012201 Asm->OutStreamer.AddComment("Dwarf Version");
22022202 Asm->EmitInt16(dwarf::DWARF_VERSION);
22032203 Asm->OutStreamer.AddComment("Address Size (in bytes)");
2204 Asm->EmitInt8(Asm->getTargetData().getPointerSize());
2204 Asm->EmitInt8(Asm->getDataLayout().getPointerSize());
22052205
22062206 for (SmallVector::iterator I = InlinedSPNodes.begin(),
22072207 E = InlinedSPNodes.end(); I != E; ++I) {
22322232
22332233 if (Asm->isVerbose()) Asm->OutStreamer.AddComment("low_pc");
22342234 Asm->OutStreamer.EmitSymbolValue(LI->first,
2235 Asm->getTargetData().getPointerSize(),0);
2235 Asm->getDataLayout().getPointerSize(),0);
22362236 }
22372237 }
22382238
2323 #include "llvm/MC/MCStreamer.h"
2424 #include "llvm/MC/MCSymbol.h"
2525 #include "llvm/Target/Mangler.h"
26 #include "llvm/Target/TargetData.h"
26 #include "llvm/DataLayout.h"
2727 #include "llvm/Target/TargetFrameLowering.h"
2828 #include "llvm/Target/TargetLoweringObjectFile.h"
2929 #include "llvm/Target/TargetMachine.h"
416416 // that we're omitting that bit.
417417 TTypeEncoding = dwarf::DW_EH_PE_omit;
418418 // dwarf::DW_EH_PE_absptr
419 TypeFormatSize = Asm->getTargetData().getPointerSize();
419 TypeFormatSize = Asm->getDataLayout().getPointerSize();
420420 } else {
421421 // Okay, we have actual filters or typeinfos to emit. As such, we need to
422422 // pick a type encoding for them. We're about to emit a list of pointers to
1919 #include "llvm/MC/MCSymbol.h"
2020 #include "llvm/MC/MCStreamer.h"
2121 #include "llvm/Target/Mangler.h"
22 #include "llvm/Target/TargetData.h"
22 #include "llvm/DataLayout.h"
2323 #include "llvm/Target/TargetLoweringObjectFile.h"
2424 #include "llvm/Target/TargetMachine.h"
2525 #include "llvm/ADT/SmallString.h"
9090 /// either condition is detected in a function which uses the GC.
9191 ///
9292 void OcamlGCMetadataPrinter::finishAssembly(AsmPrinter &AP) {
93 unsigned IntPtrSize = AP.TM.getTargetData()->getPointerSize();
93 unsigned IntPtrSize = AP.TM.getDataLayout()->getPointerSize();
9494
9595 AP.OutStreamer.SwitchSection(AP.getObjFileLowering().getTextSection());
9696 EmitCamlGlobal(getModule(), AP, "code_end");
2323 #include "llvm/MC/MCStreamer.h"
2424 #include "llvm/MC/MCSymbol.h"
2525 #include "llvm/Target/Mangler.h"
26 #include "llvm/Target/TargetData.h"
26 #include "llvm/DataLayout.h"
2727 #include "llvm/Target/TargetFrameLowering.h"
2828 #include "llvm/Target/TargetLoweringObjectFile.h"
2929 #include "llvm/Target/TargetMachine.h"
1717 #include "llvm/Support/ErrorHandling.h"
1818 #include "llvm/Support/raw_ostream.h"
1919 #include "llvm/Target/TargetRegisterInfo.h"
20 #include "llvm/Target/TargetData.h"
20 #include "llvm/DataLayout.h"
2121 #include "llvm/Target/TargetMachine.h"
2222 #include "llvm/Target/TargetLowering.h"
2323 using namespace llvm;
2020 #include "llvm/Support/CallSite.h"
2121 #include "llvm/Support/ErrorHandling.h"
2222 #include "llvm/Support/raw_ostream.h"
23 #include "llvm/Target/TargetData.h"
23 #include "llvm/DataLayout.h"
2424 using namespace llvm;
2525
2626 template
2020 #include "llvm/MC/MCAsmInfo.h"
2121 #include "llvm/MC/MCContext.h"
2222 #include "llvm/Target/TargetRegisterInfo.h"
23 #include "llvm/Target/TargetData.h"
23 #include "llvm/DataLayout.h"
2424 #include "llvm/Target/TargetInstrInfo.h"
2525 #include "llvm/Target/TargetMachine.h"
2626 #include "llvm/Assembly/Writer.h"
2727 #include "llvm/MC/MCContext.h"
2828 #include "llvm/Analysis/ConstantFolding.h"
2929 #include "llvm/Support/Debug.h"
30 #include "llvm/Target/TargetData.h"
30 #include "llvm/DataLayout.h"
3131 #include "llvm/Target/TargetLowering.h"
3232 #include "llvm/Target/TargetMachine.h"
3333 #include "llvm/Target/TargetFrameLowering.h"
6161 if (Fn->getFnAttributes().hasStackAlignmentAttr())
6262 FrameInfo->ensureMaxAlignment(Fn->getAttributes().
6363 getFnAttributes().getStackAlignment());
64 ConstantPool = new (Allocator) MachineConstantPool(TM.getTargetData());
64 ConstantPool = new (Allocator) MachineConstantPool(TM.getDataLayout());
6565 Alignment = TM.getTargetLowering()->getMinFunctionAlignment();
6666 // FIXME: Shouldn't use pref alignment if explicit alignment is set on Fn.
6767 if (!Fn->getFnAttributes().hasOptimizeForSizeAttr())
544544 //===----------------------------------------------------------------------===//
545545
546546 /// getEntrySize - Return the size of each entry in the jump table.
547 unsigned MachineJumpTableInfo::getEntrySize(const TargetData &TD) const {
547 unsigned MachineJumpTableInfo::getEntrySize(const DataLayout &TD) const {
548548 // The size of a jump table entry is 4 bytes unless the entry is just the
549549 // address of a block, in which case it is the pointer size.
550550 switch (getEntryKind()) {
563563 }
564564
565565 /// getEntryAlignment - Return the alignment of each entry in the jump table.
566 unsigned MachineJumpTableInfo::getEntryAlignment(const TargetData &TD) const {
566 unsigned MachineJumpTableInfo::getEntryAlignment(const DataLayout &TD) const {
567567 // The alignment of a jump table entry is the alignment of int32 unless the
568568 // entry is just the address of a block, in which case it is the pointer
569569 // alignment.
669669 /// CanShareConstantPoolEntry - Test whether the given two constants
670670 /// can be allocated the same constant pool entry.
671671 static bool CanShareConstantPoolEntry(const Constant *A, const Constant *B,
672 const TargetData *TD) {
672 const DataLayout *TD) {
673673 // Handle the trivial case quickly.
674674