llvm.org GIT mirror llvm / db125cf
land David Blaikie's patch to de-constify Type, with a few tweaks. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@135375 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 9 years ago
206 changed file(s) with 2036 addition(s) and 2037 deletion(s). Raw diff Collapse all Expand all
8787 /// getTypeStoreSize - Return the TargetData store size for the given type,
8888 /// if known, or a conservative value otherwise.
8989 ///
90 uint64_t getTypeStoreSize(const Type *Ty);
90 uint64_t getTypeStoreSize(Type *Ty);
9191
9292 //===--------------------------------------------------------------------===//
9393 /// Alias Queries...
4646 /// fold instructions like loads and stores, which have no constant expression
4747 /// form.
4848 ///
49 Constant *ConstantFoldInstOperands(unsigned Opcode, const Type *DestTy,
49 Constant *ConstantFoldInstOperands(unsigned Opcode, Type *DestTy,
5050 Constant *const *Ops, unsigned NumOps,
5151 const TargetData *TD = 0);
5252
2222 class Value;
2323
2424 class FindUsedTypes : public ModulePass {
25 SetVector<const Type *> UsedTypes;
25 SetVector<Type *> UsedTypes;
2626 public:
2727 static char ID; // Pass identification, replacement for typeid
2828 FindUsedTypes() : ModulePass(ID) {
3232 /// getTypes - After the pass has been run, return the set containing all of
3333 /// the types used in the module.
3434 ///
35 const SetVector<const Type *> &getTypes() const { return UsedTypes; }
35 const SetVector<Type *> &getTypes() const { return UsedTypes; }
3636
3737 /// Print the types found in the module. If the optional Module parameter is
3838 /// passed in, then the types are printed symbolically if possible, using the
4444 /// IncorporateType - Incorporate one type and all of its subtypes into the
4545 /// collection of used types.
4646 ///
47 void IncorporateType(const Type *Ty);
47 void IncorporateType(Type *Ty);
4848
4949 /// IncorporateValue - Incorporate all of the types used by this value.
5050 ///
5050 /// 0: PointerType is the malloc calls' return type.
5151 /// 1: PointerType is the bitcast's result type.
5252 /// >1: Unique PointerType cannot be determined, return NULL.
53 const PointerType *getMallocType(const CallInst *CI);
53 PointerType *getMallocType(const CallInst *CI);
5454
5555 /// getMallocAllocatedType - Returns the Type allocated by malloc call.
5656 /// The Type depends on the number of bitcast uses of the malloc call:
5757 /// 0: PointerType is the malloc calls' return type.
5858 /// 1: PointerType is the bitcast's result type.
5959 /// >1: Unique PointerType cannot be determined, return NULL.
60 const Type *getMallocAllocatedType(const CallInst *CI);
60 Type *getMallocAllocatedType(const CallInst *CI);
6161
6262 /// getMallocArraySize - Returns the array size of a malloc call. If the
6363 /// argument passed to malloc is a multiple of the size of the malloced type,
102102
103103 /// getType - Return the LLVM type of this SCEV expression.
104104 ///
105 const Type *getType() const;
105 Type *getType() const;
106106
107107 /// isZero - Return true if the expression is a constant zero.
108108 ///
478478 /// the SCEV framework. This primarily includes integer types, and it
479479 /// can optionally include pointer types if the ScalarEvolution class
480480 /// has access to target-specific information.
481 bool isSCEVable(const Type *Ty) const;
481 bool isSCEVable(Type *Ty) const;
482482
483483 /// getTypeSizeInBits - Return the size in bits of the specified type,
484484 /// for which isSCEVable must return true.
485 uint64_t getTypeSizeInBits(const Type *Ty) const;
485 uint64_t getTypeSizeInBits(Type *Ty) const;
486486
487487 /// getEffectiveSCEVType - Return a type with the same bitwidth as
488488 /// the given type and which represents how SCEV will treat the given
489489 /// type, for which isSCEVable must return true. For pointer types,
490490 /// this is the pointer-sized integer type.
491 const Type *getEffectiveSCEVType(const Type *Ty) const;
491 Type *getEffectiveSCEVType(Type *Ty) const;
492492
493493 /// getSCEV - Return a SCEV expression for the full generality of the
494494 /// specified expression.
496496
497497 const SCEV *getConstant(ConstantInt *V);
498498 const SCEV *getConstant(const APInt& Val);
499 const SCEV *getConstant(const Type *Ty, uint64_t V, bool isSigned = false);
500 const SCEV *getTruncateExpr(const SCEV *Op, const Type *Ty);
501 const SCEV *getZeroExtendExpr(const SCEV *Op, const Type *Ty);
502 const SCEV *getSignExtendExpr(const SCEV *Op, const Type *Ty);
503 const SCEV *getAnyExtendExpr(const SCEV *Op, const Type *Ty);
499 const SCEV *getConstant(Type *Ty, uint64_t V, bool isSigned = false);
500 const SCEV *getTruncateExpr(const SCEV *Op, Type *Ty);
501 const SCEV *getZeroExtendExpr(const SCEV *Op, Type *Ty);
502 const SCEV *getSignExtendExpr(const SCEV *Op, Type *Ty);
503 const SCEV *getAnyExtendExpr(const SCEV *Op, Type *Ty);
504504 const SCEV *getAddExpr(SmallVectorImpl &Ops,
505505 SCEV::NoWrapFlags Flags = SCEV::FlagAnyWrap);
506506 const SCEV *getAddExpr(const SCEV *LHS, const SCEV *RHS,
549549
550550 /// getSizeOfExpr - Return an expression for sizeof on the given type.
551551 ///
552 const SCEV *getSizeOfExpr(const Type *AllocTy);
552 const SCEV *getSizeOfExpr(Type *AllocTy);
553553
554554 /// getAlignOfExpr - Return an expression for alignof on the given type.
555555 ///
556 const SCEV *getAlignOfExpr(const Type *AllocTy);
556 const SCEV *getAlignOfExpr(Type *AllocTy);
557557
558558 /// getOffsetOfExpr - Return an expression for offsetof on the given field.
559559 ///
560 const SCEV *getOffsetOfExpr(const StructType *STy, unsigned FieldNo);
560 const SCEV *getOffsetOfExpr(StructType *STy, unsigned FieldNo);
561561
562562 /// getOffsetOfExpr - Return an expression for offsetof on the given field.
563563 ///
564 const SCEV *getOffsetOfExpr(const Type *CTy, Constant *FieldNo);
564 const SCEV *getOffsetOfExpr(Type *CTy, Constant *FieldNo);
565565
566566 /// getNegativeSCEV - Return the SCEV object corresponding to -V.
567567 ///
578578 /// getTruncateOrZeroExtend - Return a SCEV corresponding to a conversion
579579 /// of the input value to the specified type. If the type must be
580580 /// extended, it is zero extended.
581 const SCEV *getTruncateOrZeroExtend(const SCEV *V, const Type *Ty);
581 const SCEV *getTruncateOrZeroExtend(const SCEV *V, Type *Ty);
582582
583583 /// getTruncateOrSignExtend - Return a SCEV corresponding to a conversion
584584 /// of the input value to the specified type. If the type must be
585585 /// extended, it is sign extended.
586 const SCEV *getTruncateOrSignExtend(const SCEV *V, const Type *Ty);
586 const SCEV *getTruncateOrSignExtend(const SCEV *V, Type *Ty);
587587
588588 /// getNoopOrZeroExtend - Return a SCEV corresponding to a conversion of
589589 /// the input value to the specified type. If the type must be extended,
590590 /// it is zero extended. The conversion must not be narrowing.
591 const SCEV *getNoopOrZeroExtend(const SCEV *V, const Type *Ty);
591 const SCEV *getNoopOrZeroExtend(const SCEV *V, Type *Ty);
592592
593593 /// getNoopOrSignExtend - Return a SCEV corresponding to a conversion of
594594 /// the input value to the specified type. If the type must be extended,
595595 /// it is sign extended. The conversion must not be narrowing.
596 const SCEV *getNoopOrSignExtend(const SCEV *V, const Type *Ty);
596 const SCEV *getNoopOrSignExtend(const SCEV *V, Type *Ty);
597597
598598 /// getNoopOrAnyExtend - Return a SCEV corresponding to a conversion of
599599 /// the input value to the specified type. If the type must be extended,
600600 /// it is extended with unspecified bits. The conversion must not be
601601 /// narrowing.
602 const SCEV *getNoopOrAnyExtend(const SCEV *V, const Type *Ty);
602 const SCEV *getNoopOrAnyExtend(const SCEV *V, Type *Ty);
603603
604604 /// getTruncateOrNoop - Return a SCEV corresponding to a conversion of the
605605 /// input value to the specified type. The conversion must not be
606606 /// widening.
607 const SCEV *getTruncateOrNoop(const SCEV *V, const Type *Ty);
607 const SCEV *getTruncateOrNoop(const SCEV *V, Type *Ty);
608608
609609 /// getUMaxFromMismatchedTypes - Promote the operands to the wider of
610610 /// the types using zero-extension, and then perform a umax operation
8888 /// loop (inserting one if there is none). A canonical induction variable
8989 /// starts at zero and steps by one on each iteration.
9090 PHINode *getOrInsertCanonicalInductionVariable(const Loop *L,
91 const Type *Ty);
91 Type *Ty);
9292
9393 /// expandCodeFor - Insert code to directly compute the specified SCEV
9494 /// expression into the program. The inserted code is inserted into the
9595 /// specified block.
96 Value *expandCodeFor(const SCEV *SH, const Type *Ty, Instruction *I);
96 Value *expandCodeFor(const SCEV *SH, Type *Ty, Instruction *I);
9797
9898 /// setIVIncInsertPos - Set the current IV increment loop and position.
9999 void setIVIncInsertPos(const Loop *L, Instruction *Pos) {
144144 /// reusing an existing cast if a suitable one exists, moving an existing
145145 /// cast if a suitable one exists but isn't in the right place, or
146146 /// or creating a new one.
147 Value *ReuseOrCreateCast(Value *V, const Type *Ty,
147 Value *ReuseOrCreateCast(Value *V, Type *Ty,
148148 Instruction::CastOps Op,
149149 BasicBlock::iterator IP);
150150
151151 /// InsertNoopCastOfTo - Insert a cast of V to the specified type,
152152 /// which must be possible with a noop cast, doing what we can to
153153 /// share the casts.
154 Value *InsertNoopCastOfTo(Value *V, const Type *Ty);
154 Value *InsertNoopCastOfTo(Value *V, Type *Ty);
155155
156156 /// expandAddToGEP - Expand a SCEVAddExpr with a pointer type into a GEP
157157 /// instead of using ptrtoint+arithmetic+inttoptr.
158158 Value *expandAddToGEP(const SCEV *const *op_begin,
159159 const SCEV *const *op_end,
160 const PointerType *PTy, const Type *Ty, Value *V);
160 PointerType *PTy, Type *Ty, Value *V);
161161
162162 Value *expand(const SCEV *S);
163163
165165 /// expression into the program. The inserted code is inserted into the
166166 /// SCEVExpander's current insertion point. If a type is specified, the
167167 /// result will be expanded to have that type, with a cast if necessary.
168 Value *expandCodeFor(const SCEV *SH, const Type *Ty = 0);
168 Value *expandCodeFor(const SCEV *SH, Type *Ty = 0);
169169
170170 /// isInsertedInstruction - Return true if the specified instruction was
171171 /// inserted by the code rewriter. If so, the client should not modify the
210210 Value *expandAddRecExprLiterally(const SCEVAddRecExpr *);
211211 PHINode *getAddRecExprPHILiterally(const SCEVAddRecExpr *Normalized,
212212 const Loop *L,
213 const Type *ExpandTy,
214 const Type *IntTy);
213 Type *ExpandTy,
214 Type *IntTy);
215215 };
216216 }
217217
4141 public:
4242 ConstantInt *getValue() const { return V; }
4343
44 const Type *getType() const { return V->getType(); }
44 Type *getType() const { return V->getType(); }
4545
4646 /// Methods for support type inquiry through isa, cast, and dyn_cast:
4747 static inline bool classof(const SCEVConstant *S) { return true; }
5656 class SCEVCastExpr : public SCEV {
5757 protected:
5858 const SCEV *Op;
59 const Type *Ty;
59 Type *Ty;
6060
6161 SCEVCastExpr(const FoldingSetNodeIDRef ID,
62 unsigned SCEVTy, const SCEV *op, const Type *ty);
62 unsigned SCEVTy, const SCEV *op, Type *ty);
6363
6464 public:
6565 const SCEV *getOperand() const { return Op; }
66 const Type *getType() const { return Ty; }
66 Type *getType() const { return Ty; }
6767
6868 /// Methods for support type inquiry through isa, cast, and dyn_cast:
6969 static inline bool classof(const SCEVCastExpr *S) { return true; }
8282 friend class ScalarEvolution;
8383
8484 SCEVTruncateExpr(const FoldingSetNodeIDRef ID,
85 const SCEV *op, const Type *ty);
85 const SCEV *op, Type *ty);
8686
8787 public:
8888 /// Methods for support type inquiry through isa, cast, and dyn_cast:
100100 friend class ScalarEvolution;
101101
102102 SCEVZeroExtendExpr(const FoldingSetNodeIDRef ID,
103 const SCEV *op, const Type *ty);
103 const SCEV *op, Type *ty);
104104
105105 public:
106106 /// Methods for support type inquiry through isa, cast, and dyn_cast:
118118 friend class ScalarEvolution;
119119
120120 SCEVSignExtendExpr(const FoldingSetNodeIDRef ID,
121 const SCEV *op, const Type *ty);
121 const SCEV *op, Type *ty);
122122
123123 public:
124124 /// Methods for support type inquiry through isa, cast, and dyn_cast:
157157 op_iterator op_begin() const { return Operands; }
158158 op_iterator op_end() const { return Operands + NumOperands; }
159159
160 const Type *getType() const { return getOperand(0)->getType(); }
160 Type *getType() const { return getOperand(0)->getType(); }
161161
162162 NoWrapFlags getNoWrapFlags(NoWrapFlags Mask = NoWrapMask) const {
163163 return (NoWrapFlags)(SubclassData & Mask);
213213 }
214214
215215 public:
216 const Type *getType() const {
216 Type *getType() const {
217217 // Use the type of the last operand, which is likely to be a pointer
218218 // type, if there is one. This doesn't usually matter, but it can help
219219 // reduce casts when the expressions are expanded.
262262 const SCEV *getLHS() const { return LHS; }
263263 const SCEV *getRHS() const { return RHS; }
264264
265 const Type *getType() const {
265 Type *getType() const {
266266 // In most cases the types of LHS and RHS will be the same, but in some
267267 // crazy cases one or the other may be a pointer. ScalarEvolution doesn't
268268 // depend on the type for correctness, but handling types carefully can
440440 /// folded with other operations into something unrecognizable. This
441441 /// is mainly only useful for pretty-printing and other situations
442442 /// where it isn't absolutely required for these to succeed.
443 bool isSizeOf(const Type *&AllocTy) const;
444 bool isAlignOf(const Type *&AllocTy) const;
445 bool isOffsetOf(const Type *&STy, Constant *&FieldNo) const;
446
447 const Type *getType() const { return getValPtr()->getType(); }
443 bool isSizeOf(Type *&AllocTy) const;
444 bool isAlignOf(Type *&AllocTy) const;
445 bool isOffsetOf(Type *&STy, Constant *&FieldNo) const;
446
447 Type *getType() const { return getValPtr()->getType(); }
448448
449449 /// Methods for support type inquiry through isa, cast, and dyn_cast:
450450 static inline bool classof(const SCEVUnknown *S) { return true; }
3838 /// Argument ctor - If Function argument is specified, this argument is
3939 /// inserted at the end of the argument list for the function.
4040 ///
41 explicit Argument(const Type *Ty, const Twine &Name = "", Function *F = 0);
41 explicit Argument(Type *Ty, const Twine &Name = "", Function *F = 0);
4242
4343 inline const Function *getParent() const { return Parent; }
4444 inline Function *getParent() { return Parent; }
106106 };
107107
108108 /// @brief Which attributes cannot be applied to a type.
109 Attributes typeIncompatible(const Type *Ty);
109 Attributes typeIncompatible(Type *Ty);
110110
111111 /// This turns an int alignment (a power of 2, normally) into the
112112 /// form used internally in Attributes.
3232 /// of insertvalue or extractvalue indices that identify a member, return
3333 /// the linearized index of the start of the member.
3434 ///
35 unsigned ComputeLinearIndex(const Type *Ty,
35 unsigned ComputeLinearIndex(Type *Ty,
3636 const unsigned *Indices,
3737 const unsigned *IndicesEnd,
3838 unsigned CurIndex = 0);
3939
40 inline unsigned ComputeLinearIndex(const Type *Ty,
40 inline unsigned ComputeLinearIndex(Type *Ty,
4141 ArrayRef Indices,
4242 unsigned CurIndex = 0) {
4343 return ComputeLinearIndex(Ty, Indices.begin(), Indices.end(), CurIndex);
5050 /// If Offsets is non-null, it points to a vector to be filled in
5151 /// with the in-memory offsets of each of the individual values.
5252 ///
53 void ComputeValueVTs(const TargetLowering &TLI, const Type *Ty,
53 void ComputeValueVTs(const TargetLowering &TLI, Type *Ty,
5454 SmallVectorImpl &ValueVTs,
5555 SmallVectorImpl *Offsets = 0,
5656 uint64_t StartingOffset = 0);
138138
139139 unsigned CreateReg(EVT VT);
140140
141 unsigned CreateRegs(const Type *Ty);
141 unsigned CreateRegs(Type *Ty);
142142
143143 unsigned InitializeRegForValue(const Value *V) {
144144 unsigned &R = ValueMap[V];
3333 /// Abstract base class for all machine specific constantpool value subclasses.
3434 ///
3535 class MachineConstantPoolValue {
36 const Type *Ty;
36 Type *Ty;
3737
3838 public:
39 explicit MachineConstantPoolValue(const Type *ty) : Ty(ty) {}
39 explicit MachineConstantPoolValue(Type *ty) : Ty(ty) {}
4040 virtual ~MachineConstantPoolValue() {}
4141
4242 /// getType - get type of this MachineConstantPoolValue.
4343 ///
44 const Type *getType() const { return Ty; }
44 Type *getType() const { return Ty; }
4545
4646
4747 /// getRelocationInfo - This method classifies the entry according to
103103 return Alignment & ~(1 << (sizeof(unsigned)*CHAR_BIT-1));
104104 }
105105
106 const Type *getType() const;
106 Type *getType() const;
107107
108108 /// getRelocationInfo - This method classifies the entry according to
109109 /// whether or not it may generate a relocation entry. This must be
12901290 unsigned getAlignment() const { return Alignment; }
12911291 unsigned char getTargetFlags() const { return TargetFlags; }
12921292
1293 const Type *getType() const;
1293 Type *getType() const;
12941294
12951295 static bool classof(const ConstantPoolSDNode *) { return true; }
12961296 static bool classof(const SDNode *N) {
379379 struct EVT {
380380 private:
381381 MVT V;
382 const Type *LLVMTy;
382 Type *LLVMTy;
383383
384384 public:
385385 EVT() : V((MVT::SimpleValueType)(MVT::INVALID_SIMPLE_VALUE_TYPE)),
644644 /// getTypeForEVT - This method returns an LLVM type corresponding to the
645645 /// specified EVT. For integer types, this returns an unsigned type. Note
646646 /// that this will abort for types that cannot be represented.
647 const Type *getTypeForEVT(LLVMContext &Context) const;
647 Type *getTypeForEVT(LLVMContext &Context) const;
648648
649649 /// getEVT - Return the value type corresponding to the specified type.
650650 /// This returns all pointers as iPTR. If HandleUnknown is true, unknown
651651 /// types are returned as Other, otherwise they are invalid.
652 static EVT getEVT(const Type *Ty, bool HandleUnknown = false);
652 static EVT getEVT(Type *Ty, bool HandleUnknown = false);
653653
654654 intptr_t getRawBits() {
655655 if (isSimple())
4242 Constant(const Constant &); // Do not implement
4343
4444 protected:
45 Constant(const Type *ty, ValueTy vty, Use *Ops, unsigned NumOps)
45 Constant(Type *ty, ValueTy vty, Use *Ops, unsigned NumOps)
4646 : User(ty, vty, Ops, NumOps) {}
4747
4848 void destroyConstantImpl();
127127 assert(0 && "Constants that do not have operands cannot be using 'From'!");
128128 }
129129
130 static Constant *getNullValue(const Type* Ty);
130 static Constant *getNullValue(Type* Ty);
131131
132132 /// @returns the value for an integer constant of the given type that has all
133133 /// its bits set to true.
134134 /// @brief Get the all ones value
135 static Constant *getAllOnesValue(const Type* Ty);
135 static Constant *getAllOnesValue(Type* Ty);
136136
137137 /// getIntegerValue - Return the value for an integer or pointer constant,
138138 /// or a vector thereof, with the given scalar value.
139 static Constant *getIntegerValue(const Type* Ty, const APInt &V);
139 static Constant *getIntegerValue(Type* Ty, const APInt &V);
140140
141141 /// removeDeadConstantUsers - If there are any dead constant users dangling
142142 /// off of this constant, remove them. This method is useful for clients
4646 class ConstantInt : public Constant {
4747 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
4848 ConstantInt(const ConstantInt &); // DO NOT IMPLEMENT
49 ConstantInt(const IntegerType *Ty, const APInt& V);
49 ConstantInt(IntegerType *Ty, const APInt& V);
5050 APInt Val;
5151 protected:
5252 // allocate space for exactly zero operands
5656 public:
5757 static ConstantInt *getTrue(LLVMContext &Context);
5858 static ConstantInt *getFalse(LLVMContext &Context);
59 static Constant *getTrue(const Type *Ty);
60 static Constant *getFalse(const Type *Ty);
59 static Constant *getTrue(Type *Ty);
60 static Constant *getFalse(Type *Ty);
6161
6262 /// If Ty is a vector type, return a Constant with a splat of the given
6363 /// value. Otherwise return a ConstantInt for the given value.
64 static Constant *get(const Type *Ty, uint64_t V, bool isSigned = false);
64 static Constant *get(Type *Ty, uint64_t V, bool isSigned = false);
6565
6666 /// Return a ConstantInt with the specified integer value for the specified
6767 /// type. If the type is wider than 64 bits, the value will be zero-extended
6969 /// be interpreted as a 64-bit signed integer and sign-extended to fit
7070 /// the type.
7171 /// @brief Get a ConstantInt for a specific value.
72 static ConstantInt *get(const IntegerType *Ty, uint64_t V,
72 static ConstantInt *get(IntegerType *Ty, uint64_t V,
7373 bool isSigned = false);
7474
7575 /// Return a ConstantInt with the specified value for the specified type. The
7777 /// either getSExtValue() or getZExtValue() will yield a correctly sized and
7878 /// signed value for the type Ty.
7979 /// @brief Get a ConstantInt for a specific signed value.
80 static ConstantInt *getSigned(const IntegerType *Ty, int64_t V);
81 static Constant *getSigned(const Type *Ty, int64_t V);
80 static ConstantInt *getSigned(IntegerType *Ty, int64_t V);
81 static Constant *getSigned(Type *Ty, int64_t V);
8282
8383 /// Return a ConstantInt with the specified value and an implied Type. The
8484 /// type is the integer type that corresponds to the bit width of the value.
8686
8787 /// Return a ConstantInt constructed from the string strStart with the given
8888 /// radix.
89 static ConstantInt *get(const IntegerType *Ty, StringRef Str,
89 static ConstantInt *get(IntegerType *Ty, StringRef Str,
9090 uint8_t radix);
9191
9292 /// If Ty is a vector type, return a Constant with a splat of the given
9393 /// value. Otherwise return a ConstantInt for the given value.
94 static Constant *get(const Type* Ty, const APInt& V);
94 static Constant *get(Type* Ty, const APInt& V);
9595
9696 /// Return the constant as an APInt value reference. This allows clients to
9797 /// obtain a copy of the value, with all its precision in tact.
132132 /// getType - Specialize the getType() method to always return an IntegerType,
133133 /// which reduces the amount of casting needed in parts of the compiler.
134134 ///
135 inline const IntegerType *getType() const {
136 return reinterpret_cast(Value::getType());
135 inline IntegerType *getType() const {
136 return reinterpret_cast(Value::getType());
137137 }
138138
139139 /// This static method returns true if the type Ty is big enough to
145145 /// to the appropriate unsigned type before calling the method.
146146 /// @returns true if V is a valid value for type Ty
147147 /// @brief Determine if the value is in range for the given type.
148 static bool isValueValidForType(const Type *Ty, uint64_t V);
149 static bool isValueValidForType(const Type *Ty, int64_t V);
148 static bool isValueValidForType(Type *Ty, uint64_t V);
149 static bool isValueValidForType(Type *Ty, int64_t V);
150150
151151 bool isNegative() const { return Val.isNegative(); }
152152
232232 ConstantFP(const ConstantFP &); // DO NOT IMPLEMENT
233233 friend class LLVMContextImpl;
234234 protected:
235 ConstantFP(const Type *Ty, const APFloat& V);
235 ConstantFP(Type *Ty, const APFloat& V);
236236 protected:
237237 // allocate space for exactly zero operands
238238 void *operator new(size_t s) {
242242 /// Floating point negation must be implemented with f(x) = -0.0 - x. This
243243 /// method returns the negative zero constant for floating point or vector
244244 /// floating point types; for all other types, it returns the null value.
245 static Constant *getZeroValueForNegation(const Type *Ty);
245 static Constant *getZeroValueForNegation(Type *Ty);
246246
247247 /// get() - This returns a ConstantFP, or a vector containing a splat of a
248248 /// ConstantFP, for the specified value in the specified type. This should
249249 /// only be used for simple constant values like 2.0/1.0 etc, that are
250250 /// known-valid both as host double and as the target format.
251 static Constant *get(const Type* Ty, double V);
252 static Constant *get(const Type* Ty, StringRef Str);
251 static Constant *get(Type* Ty, double V);
252 static Constant *get(Type* Ty, StringRef Str);
253253 static ConstantFP *get(LLVMContext &Context, const APFloat &V);
254 static ConstantFP *getNegativeZero(const Type* Ty);
255 static ConstantFP *getInfinity(const Type *Ty, bool Negative = false);
254 static ConstantFP *getNegativeZero(Type* Ty);
255 static ConstantFP *getInfinity(Type *Ty, bool Negative = false);
256256
257257 /// isValueValidForType - return true if Ty is big enough to represent V.
258 static bool isValueValidForType(const Type *Ty, const APFloat &V);
258 static bool isValueValidForType(Type *Ty, const APFloat &V);
259259 inline const APFloat &getValueAPF() const { return Val; }
260260
261261 /// isZero - Return true if the value is positive or negative zero.
299299 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
300300 ConstantAggregateZero(const ConstantAggregateZero &); // DO NOT IMPLEMENT
301301 protected:
302 explicit ConstantAggregateZero(const Type *ty)
302 explicit ConstantAggregateZero(Type *ty)
303303 : Constant(ty, ConstantAggregateZeroVal, 0, 0) {}
304304 protected:
305305 // allocate space for exactly zero operands
307307 return User::operator new(s, 0);
308308 }
309309 public:
310 static ConstantAggregateZero* get(const Type *Ty);
310 static ConstantAggregateZero* get(Type *Ty);
311311
312312 virtual void destroyConstant();
313313
328328 std::vector >;
329329 ConstantArray(const ConstantArray &); // DO NOT IMPLEMENT
330330 protected:
331 ConstantArray(const ArrayType *T, const std::vector &Val);
331 ConstantArray(ArrayType *T, const std::vector &Val);
332332 public:
333333 // ConstantArray accessors
334 static Constant *get(const ArrayType *T, ArrayRef V);
334 static Constant *get(ArrayType *T, ArrayRef V);
335335
336336 /// This method constructs a ConstantArray and initializes it with a text
337337 /// string. The default behavior (AddNull==true) causes a null terminator to
348348 /// getType - Specialize the getType() method to always return an ArrayType,
349349 /// which reduces the amount of casting needed in parts of the compiler.
350350 ///
351 inline const ArrayType *getType() const {
352 return reinterpret_cast(Value::getType());
351 inline ArrayType *getType() const {
352 return reinterpret_cast(Value::getType());
353353 }
354354
355355 /// isString - This method returns true if the array is an array of i8 and
399399 std::vector >;
400400 ConstantStruct(const ConstantStruct &); // DO NOT IMPLEMENT
401401 protected:
402 ConstantStruct(const StructType *T, const std::vector &Val);
402 ConstantStruct(StructType *T, const std::vector &Val);
403403 public:
404404 // ConstantStruct accessors
405 static Constant *get(const StructType *T, ArrayRef V);
406 static Constant *get(const StructType *T, ...) END_WITH_NULL;
405 static Constant *get(StructType *T, ArrayRef V);
406 static Constant *get(StructType *T, ...) END_WITH_NULL;
407407
408408 /// getAnon - Return an anonymous struct that has the specified
409409 /// elements. If the struct is possibly empty, then you must specify a
430430
431431 /// getType() specialization - Reduce amount of casting...
432432 ///
433 inline const StructType *getType() const {
434 return reinterpret_cast(Value::getType());
433 inline StructType *getType() const {
434 return reinterpret_cast(Value::getType());
435435 }
436436
437437 virtual void destroyConstant();
460460 std::vector >;
461461 ConstantVector(const ConstantVector &); // DO NOT IMPLEMENT
462462 protected:
463 ConstantVector(const VectorType *T, const std::vector &Val);
463 ConstantVector(VectorType *T, const std::vector &Val);
464464 public:
465465 // ConstantVector accessors
466466 static Constant *get(ArrayRef V);
471471 /// getType - Specialize the getType() method to always return a VectorType,
472472 /// which reduces the amount of casting needed in parts of the compiler.
473473 ///
474 inline const VectorType *getType() const {
475 return reinterpret_cast(Value::getType());
474 inline VectorType *getType() const {
475 return reinterpret_cast(Value::getType());
476476 }
477477
478478 /// This function will return true iff every element in this vector constant
510510 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
511511 ConstantPointerNull(const ConstantPointerNull &); // DO NOT IMPLEMENT
512512 protected:
513 explicit ConstantPointerNull(const PointerType *T)
514 : Constant(reinterpret_cast(T),
513 explicit ConstantPointerNull(PointerType *T)
514 : Constant(reinterpret_cast(T),
515515 Value::ConstantPointerNullVal, 0, 0) {}
516516
517517 protected:
521521 }
522522 public:
523523 /// get() - Static factory methods - Return objects of the specified value
524 static ConstantPointerNull *get(const PointerType *T);
524 static ConstantPointerNull *get(PointerType *T);
525525
526526 virtual void destroyConstant();
527527
528528 /// getType - Specialize the getType() method to always return an PointerType,
529529 /// which reduces the amount of casting needed in parts of the compiler.
530530 ///
531 inline const PointerType *getType() const {
532 return reinterpret_cast(Value::getType());
531 inline PointerType *getType() const {
532 return reinterpret_cast(Value::getType());
533533 }
534534
535535 /// Methods for support type inquiry through isa, cast, and dyn_cast:
590590 friend struct ConvertConstantType;
591591
592592 protected:
593 ConstantExpr(const Type *ty, unsigned Opcode, Use *Ops, unsigned NumOps)
593 ConstantExpr(Type *ty, unsigned Opcode, Use *Ops, unsigned NumOps)
594594 : Constant(ty, ConstantExprVal, Ops, NumOps) {
595595 // Operation type (an Instruction opcode) is stored as the SubclassData.
596596 setValueSubclassData(Opcode);
604604
605605 /// getAlignOf constant expr - computes the alignment of a type in a target
606606 /// independent way (Note: the return type is an i64).
607 static Constant *getAlignOf(const Type *Ty);
607 static Constant *getAlignOf(Type *Ty);
608608
609609 /// getSizeOf constant expr - computes the (alloc) size of a type (in
610610 /// address-units, not bits) in a target independent way (Note: the return
611611 /// type is an i64).
612612 ///
613 static Constant *getSizeOf(const Type *Ty);
613 static Constant *getSizeOf(Type *Ty);
614614
615615 /// getOffsetOf constant expr - computes the offset of a struct field in a
616616 /// target independent way (Note: the return type is an i64).
617617 ///
618 static Constant *getOffsetOf(const StructType *STy, unsigned FieldNo);
618 static Constant *getOffsetOf(StructType *STy, unsigned FieldNo);
619619
620620 /// getOffsetOf constant expr - This is a generalized form of getOffsetOf,
621621 /// which supports any aggregate type, and any Constant index.
622622 ///
623 static Constant *getOffsetOf(const Type *Ty, Constant *FieldNo);
623 static Constant *getOffsetOf(Type *Ty, Constant *FieldNo);
624624
625625 static Constant *getNeg(Constant *C, bool HasNUW = false, bool HasNSW =false);
626626 static Constant *getFNeg(Constant *C);
647647 bool HasNUW = false, bool HasNSW = false);
648648 static Constant *getLShr(Constant *C1, Constant *C2, bool isExact = false);
649649 static Constant *getAShr(Constant *C1, Constant *C2, bool isExact = false);
650 static Constant *getTrunc (Constant *C, const Type *Ty);
651 static Constant *getSExt (Constant *C, const Type *Ty);
652 static Constant *getZExt (Constant *C, const Type *Ty);
653 static Constant *getFPTrunc (Constant *C, const Type *Ty);
654 static Constant *getFPExtend(Constant *C, const Type *Ty);
655 static Constant *getUIToFP (Constant *C, const Type *Ty);
656 static Constant *getSIToFP (Constant *C, const Type *Ty);
657 static Constant *getFPToUI (Constant *C, const Type *Ty);
658 static Constant *getFPToSI (Constant *C, const Type *Ty);
659 static Constant *getPtrToInt(Constant *C, const Type *Ty);
660 static Constant *getIntToPtr(Constant *C, const Type *Ty);
661 static Constant *getBitCast (Constant *C, const Type *Ty);
650 static Constant *getTrunc (Constant *C, Type *Ty);
651 static Constant *getSExt (Constant *C, Type *Ty);
652 static Constant *getZExt (Constant *C, Type *Ty);
653 static Constant *getFPTrunc (Constant *C, Type *Ty);
654 static Constant *getFPExtend(Constant *C, Type *Ty);
655 static Constant *getUIToFP (Constant *C, Type *Ty);
656 static Constant *getSIToFP (Constant *C, Type *Ty);
657 static Constant *getFPToUI (Constant *C, Type *Ty);
658 static Constant *getFPToSI (Constant *C, Type *Ty);
659 static Constant *getPtrToInt(Constant *C, Type *Ty);
660 static Constant *getIntToPtr(Constant *C, Type *Ty);
661 static Constant *getBitCast (Constant *C, Type *Ty);
662662
663663 static Constant *getNSWNeg(Constant *C) { return getNeg(C, false, true); }
664664 static Constant *getNUWNeg(Constant *C) { return getNeg(C, true, false); }
707707 static Constant *getCast(
708708 unsigned ops, ///< The opcode for the conversion
709709 Constant *C, ///< The constant to be converted
710 const Type *Ty ///< The type to which the constant is converted
710 Type *Ty ///< The type to which the constant is converted
711711 );
712712
713713 // @brief Create a ZExt or BitCast cast constant expression
714714 static Constant *getZExtOrBitCast(
715715 Constant *C, ///< The constant to zext or bitcast
716 const Type *Ty ///< The type to zext or bitcast C to
716 Type *Ty ///< The type to zext or bitcast C to
717717 );
718718
719719 // @brief Create a SExt or BitCast cast constant expression
720720 static Constant *getSExtOrBitCast(
721721 Constant *C, ///< The constant to sext or bitcast
722 const Type *Ty ///< The type to sext or bitcast C to
722 Type *Ty ///< The type to sext or bitcast C to
723723 );
724724
725725 // @brief Create a Trunc or BitCast cast constant expression
726726 static Constant *getTruncOrBitCast(
727727 Constant *C, ///< The constant to trunc or bitcast
728 const Type *Ty ///< The type to trunc or bitcast C to
728 Type *Ty ///< The type to trunc or bitcast C to
729729 );
730730
731731 /// @brief Create a BitCast or a PtrToInt cast constant expression
732732 static Constant *getPointerCast(
733733 Constant *C, ///< The pointer value to be casted (operand 0)
734 const Type *Ty ///< The type to which cast should be made
734 Type *Ty ///< The type to which cast should be made
735735 );
736736
737737 /// @brief Create a ZExt, Bitcast or Trunc for integer -> integer casts
738738 static Constant *getIntegerCast(
739739 Constant *C, ///< The integer constant to be casted
740 const Type *Ty, ///< The integer type to cast to
740 Type *Ty, ///< The integer type to cast to
741741 bool isSigned ///< Whether C should be treated as signed or not
742742 );
743743
744744 /// @brief Create a FPExt, Bitcast or FPTrunc for fp -> fp casts
745745 static Constant *getFPCast(
746746 Constant *C, ///< The integer constant to be casted
747 const Type *Ty ///< The integer type to cast to
747 Type *Ty ///< The integer type to cast to
748748 );
749749
750750 /// @brief Return true if this is a convert constant expression
844844 /// operands replaced with the specified values and with the specified result
845845 /// type. The specified array must have the same number of operands as our
846846 /// current one.
847 Constant *getWithOperands(ArrayRef Ops, const Type *Ty) const;
847 Constant *getWithOperands(ArrayRef Ops, Type *Ty) const;
848848
849849 virtual void destroyConstant();
850850 virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
885885 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
886886 UndefValue(const UndefValue &); // DO NOT IMPLEMENT
887887 protected:
888 explicit UndefValue(const Type *T) : Constant(T, UndefValueVal, 0, 0) {}
888 explicit UndefValue(Type *T) : Constant(T, UndefValueVal, 0, 0) {}
889889 protected:
890890 // allocate space for exactly zero operands
891891 void *operator new(size_t s) {
895895 /// get() - Static factory methods - Return an 'undef' object of the specified
896896 /// type.
897897 ///
898 static UndefValue *get(const Type *T);
898 static UndefValue *get(Type *T);
899899
900900 virtual void destroyConstant();
901901
9595 class FunctionType : public Type {
9696 FunctionType(const FunctionType &); // Do not implement
9797 const FunctionType &operator=(const FunctionType &); // Do not implement
98 FunctionType(const Type *Result, ArrayRef Params, bool IsVarArgs);
98 FunctionType(Type *Result, ArrayRef Params, bool IsVarArgs);
9999
100100 public:
101101 /// FunctionType::get - This static method is the primary way of constructing
102102 /// a FunctionType.
103103 ///
104 static FunctionType *get(const Type *Result,
104 static FunctionType *get(Type *Result,
105105 ArrayRef Params, bool isVarArg);
106106
107107 /// FunctionType::get - Create a FunctionType taking no parameters.
108108 ///
109 static FunctionType *get(const Type *Result, bool isVarArg);
109 static FunctionType *get(Type *Result, bool isVarArg);
110110
111111 /// isValidReturnType - Return true if the specified type is valid as a return
112112 /// type.
113 static bool isValidReturnType(const Type *RetTy);
113 static bool isValidReturnType(Type *RetTy);
114114
115115 /// isValidArgumentType - Return true if the specified type is valid as an
116116 /// argument type.
117 static bool isValidArgumentType(const Type *ArgTy);
117 static bool isValidArgumentType(Type *ArgTy);
118118
119119 bool isVarArg() const { return getSubclassData(); }
120120 Type *getReturnType() const { return ContainedTys[0]; }
149149 /// getTypeAtIndex - Given an index value into the type, return the type of
150150 /// the element.
151151 ///
152 Type *getTypeAtIndex(const Value *V) const;
153 Type *getTypeAtIndex(unsigned Idx) const;
152 Type *getTypeAtIndex(const Value *V);
153 Type *getTypeAtIndex(unsigned Idx);
154154 bool indexValid(const Value *V) const;
155155 bool indexValid(unsigned Idx) const;
156156
249249
250250 /// isValidElementType - Return true if the specified type is valid as a
251251 /// element type.
252 static bool isValidElementType(const Type *ElemTy);
252 static bool isValidElementType(Type *ElemTy);
253253
254254
255255 // Iterator access to the elements.
259259
260260 /// isLayoutIdentical - Return true if this is layout identical to the
261261 /// specified struct.
262 bool isLayoutIdentical(const StructType *Other) const;
262 bool isLayoutIdentical(StructType *Other) const;
263263
264264 // Random access to the elements
265265 unsigned getNumElements() const { return NumContainedTys; }
320320 /// ArrayType::get - This static method is the primary way to construct an
321321 /// ArrayType
322322 ///
323 static ArrayType *get(const Type *ElementType, uint64_t NumElements);
323 static ArrayType *get(Type *ElementType, uint64_t NumElements);
324324
325325 /// isValidElementType - Return true if the specified type is valid as a
326326 /// element type.
327 static bool isValidElementType(const Type *ElemTy);
327 static bool isValidElementType(Type *ElemTy);
328328
329329 uint64_t getNumElements() const { return NumElements; }
330330
347347 /// VectorType::get - This static method is the primary way to construct an
348348 /// VectorType.
349349 ///
350 static VectorType *get(const Type *ElementType, unsigned NumElements);
350 static VectorType *get(Type *ElementType, unsigned NumElements);
351351
352352 /// VectorType::getInteger - This static method gets a VectorType with the
353353 /// same number of elements as the input type, and the element type is an
354354 /// integer type of the same width as the input element type.
355355 ///
356 static VectorType *getInteger(const VectorType *VTy) {
356 static VectorType *getInteger(VectorType *VTy) {
357357 unsigned EltBits = VTy->getElementType()->getPrimitiveSizeInBits();
358358 Type *EltTy = IntegerType::get(VTy->getContext(), EltBits);
359359 return VectorType::get(EltTy, VTy->getNumElements());
363363 /// getInteger except that the element types are twice as wide as the
364364 /// elements in the input type.
365365 ///
366 static VectorType *getExtendedElementVectorType(const VectorType *VTy) {
366 static VectorType *getExtendedElementVectorType(VectorType *VTy) {
367367 unsigned EltBits = VTy->getElementType()->getPrimitiveSizeInBits();
368368 Type *EltTy = IntegerType::get(VTy->getContext(), EltBits * 2);
369369 return VectorType::get(EltTy, VTy->getNumElements());
373373 /// getInteger except that the element types are half as wide as the
374374 /// elements in the input type.
375375 ///
376 static VectorType *getTruncatedElementVectorType(const VectorType *VTy) {
376 static VectorType *getTruncatedElementVectorType(VectorType *VTy) {
377377 unsigned EltBits = VTy->getElementType()->getPrimitiveSizeInBits();
378378 assert((EltBits & 1) == 0 &&
379379 "Cannot truncate vector element with odd bit-width");
383383
384384 /// isValidElementType - Return true if the specified type is valid as a
385385 /// element type.
386 static bool isValidElementType(const Type *ElemTy);
386 static bool isValidElementType(Type *ElemTy);
387387
388388 /// @brief Return the number of elements in the Vector type.
389389 unsigned getNumElements() const { return NumElements; }
410410 public:
411411 /// PointerType::get - This constructs a pointer to an object of the specified
412412 /// type in a numbered address space.
413 static PointerType *get(const Type *ElementType, unsigned AddressSpace);
413 static PointerType *get(Type *ElementType, unsigned AddressSpace);
414414
415415 /// PointerType::getUnqual - This constructs a pointer to an object of the
416416 /// specified type in the generic address space (address space zero).
417 static PointerType *getUnqual(const Type *ElementType) {
417 static PointerType *getUnqual(Type *ElementType) {
418418 return PointerType::get(ElementType, 0);
419419 }
420420
421421 /// isValidElementType - Return true if the specified type is valid as a
422422 /// element type.
423 static bool isValidElementType(const Type *ElemTy);
423 static bool isValidElementType(Type *ElemTy);
424424
425425 /// @brief Return the address space of the Pointer type.
426426 inline unsigned getAddressSpace() const { return getSubclassData(); }
313313 /// GenericValue *. It is not a pointer to a GenericValue containing the
314314 /// address at which to store Val.
315315 void StoreValueToMemory(const GenericValue &Val, GenericValue *Ptr,
316 const Type *Ty);
316 Type *Ty);
317317
318318 void InitializeMemory(const Constant *Init, void *Addr);
319319
439439
440440 GenericValue getConstantValue(const Constant *C);
441441 void LoadValueFromMemory(GenericValue &Result, GenericValue *Ptr,
442 const Type *Ty);
442 Type *Ty);
443443 };
444444
445445 namespace EngineKind {
116116 /// function is automatically inserted into the end of the function list for
117117 /// the module.
118118 ///
119 Function(const FunctionType *Ty, LinkageTypes Linkage,
119 Function(FunctionType *Ty, LinkageTypes Linkage,
120120 const Twine &N = "", Module *M = 0);
121121
122122 public:
123 static Function *Create(const FunctionType *Ty, LinkageTypes Linkage,
123 static Function *Create(FunctionType *Ty, LinkageTypes Linkage,
124124 const Twine &N = "", Module *M = 0) {
125125 return new(0) Function(Ty, Linkage, N, M);
126126 }
4040 }
4141 /// GlobalAlias ctor - If a parent module is specified, the alias is
4242 /// automatically inserted into the end of the specified module's alias list.
43 GlobalAlias(const Type *Ty, LinkageTypes Linkage, const Twine &Name = "",
43 GlobalAlias(Type *Ty, LinkageTypes Linkage, const Twine &Name = "",
4444 Constant* Aliasee = 0, Module *Parent = 0);
4545
4646 /// Provide fast operand accessors
5656 };
5757
5858 protected:
59 GlobalValue(const Type *ty, ValueTy vty, Use *Ops, unsigned NumOps,
59 GlobalValue(Type *ty, ValueTy vty, Use *Ops, unsigned NumOps,
6060 LinkageTypes linkage, const Twine &Name)
6161 : Constant(ty, vty, Ops, NumOps), Parent(0),
6262 Linkage(linkage), Visibility(DefaultVisibility), Alignment(0),
4949 }
5050 /// GlobalVariable ctor - If a parent module is specified, the global is
5151 /// automatically inserted into the end of the specified modules global list.
52 GlobalVariable(const Type *Ty, bool isConstant, LinkageTypes Linkage,
52 GlobalVariable(Type *Ty, bool isConstant, LinkageTypes Linkage,
5353 Constant *Initializer = 0, const Twine &Name = "",
5454 bool ThreadLocal = false, unsigned AddressSpace = 0);
5555 /// GlobalVariable ctor - This creates a global and inserts it before the
5656 /// specified other global.
57 GlobalVariable(Module &M, const Type *Ty, bool isConstant,
57 GlobalVariable(Module &M, Type *Ty, bool isConstant,
5858 LinkageTypes Linkage, Constant *Initializer,
5959 const Twine &Name,
6060 GlobalVariable *InsertBefore = 0, bool ThreadLocal = false,
4242 bool HasSideEffects;
4343 bool IsAlignStack;
4444
45 InlineAsm(const PointerType *Ty, const std::string &AsmString,
45 InlineAsm(PointerType *Ty, const std::string &AsmString,
4646 const std::string &Constraints, bool hasSideEffects,
4747 bool isAlignStack);
4848 virtual ~InlineAsm();
5454
5555 /// InlineAsm::get - Return the specified uniqued inline asm string.
5656 ///
57 static InlineAsm *get(const FunctionType *Ty, StringRef AsmString,
57 static InlineAsm *get(FunctionType *Ty, StringRef AsmString,
5858 StringRef Constraints, bool hasSideEffects,
5959 bool isAlignStack = false);
6060
7878 /// the specified constraint string is legal for the type. This returns true
7979 /// if legal, false if not.
8080 ///
81 static bool Verify(const FunctionType *Ty, StringRef Constraints);
81 static bool Verify(FunctionType *Ty, StringRef Constraints);
8282
8383 // Constraint String Parsing
8484 enum ConstraintPrefix {
3333 ///
3434 class TerminatorInst : public Instruction {
3535 protected:
36 TerminatorInst(const Type *Ty, Instruction::TermOps iType,
36 TerminatorInst(Type *Ty, Instruction::TermOps iType,
3737 Use *Ops, unsigned NumOps,
3838 Instruction *InsertBefore = 0)
3939 : Instruction(Ty, iType, Ops, NumOps, InsertBefore) {}
4040
41 TerminatorInst(const Type *Ty, Instruction::TermOps iType,
41 TerminatorInst(Type *Ty, Instruction::TermOps iType,
4242 Use *Ops, unsigned NumOps, BasicBlock *InsertAtEnd)
4343 : Instruction(Ty, iType, Ops, NumOps, InsertAtEnd) {}
4444
9090 void *operator new(size_t, unsigned); // Do not implement
9191
9292 protected:
93 UnaryInstruction(const Type *Ty, unsigned iType, Value *V,
93 UnaryInstruction(Type *Ty, unsigned iType, Value *V,
9494 Instruction *IB = 0)
9595 : Instruction(Ty, iType, &Op<0>(), 1, IB) {
9696 Op<0>() = V;
9797 }
98 UnaryInstruction(const Type *Ty, unsigned iType, Value *V, BasicBlock *IAE)
98 UnaryInstruction(Type *Ty, unsigned iType, Value *V, BasicBlock *IAE)
9999 : Instruction(Ty, iType, &Op<0>(), 1, IAE) {
100100 Op<0>() = V;
101101 }
140140 void *operator new(size_t, unsigned); // Do not implement
141141 protected:
142142 void init(BinaryOps iType);
143 BinaryOperator(BinaryOps iType, Value *S1, Value *S2, const Type *Ty,
143 BinaryOperator(BinaryOps iType, Value *S1, Value *S2, Type *Ty,
144144 const Twine &Name, Instruction *InsertBefore);
145 BinaryOperator(BinaryOps iType, Value *S1, Value *S2, const Type *Ty,
145 BinaryOperator(BinaryOps iType, Value *S1, Value *S2, Type *Ty,
146146 const Twine &Name, BasicBlock *InsertAtEnd);
147147 virtual BinaryOperator *clone_impl() const;
148148 public:
389389 class CastInst : public UnaryInstruction {
390390 protected:
391391 /// @brief Constructor with insert-before-instruction semantics for subclasses
392 CastInst(const Type *Ty, unsigned iType, Value *S,
392 CastInst(Type *Ty, unsigned iType, Value *S,
393393 const Twine &NameStr = "", Instruction *InsertBefore = 0)
394394 : UnaryInstruction(Ty, iType, S, InsertBefore) {
395395 setName(NameStr);
396396 }
397397 /// @brief Constructor with insert-at-end-of-block semantics for subclasses
398 CastInst(const Type *Ty, unsigned iType, Value *S,
398 CastInst(Type *Ty, unsigned iType, Value *S,
399399 const Twine &NameStr, BasicBlock *InsertAtEnd)
400400 : UnaryInstruction(Ty, iType, S, InsertAtEnd) {
401401 setName(NameStr);
410410 static CastInst *Create(
411411 Instruction::CastOps, ///< The opcode of the cast instruction
412412 Value *S, ///< The value to be casted (operand 0)
413 const Type *Ty, ///< The type to which cast should be made
413 Type *Ty, ///< The type to which cast should be made
414414 const Twine &Name = "", ///< Name for the instruction
415415 Instruction *InsertBefore = 0 ///< Place to insert the instruction
416416 );
423423 static CastInst *Create(
424424 Instruction::CastOps, ///< The opcode for the cast instruction
425425 Value *S, ///< The value to be casted (operand 0)
426 const Type *Ty, ///< The type to which operand is casted
426 Type *Ty, ///< The type to which operand is casted
427427 const Twine &Name, ///< The name for the instruction
428428 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
429429 );
431431 /// @brief Create a ZExt or BitCast cast instruction
432432 static CastInst *CreateZExtOrBitCast(
433433 Value *S, ///< The value to be casted (operand 0)
434 const Type *Ty, ///< The type to which cast should be made
434 Type *Ty, ///< The type to which cast should be made
435435 const Twine &Name = "", ///< Name for the instruction
436436 Instruction *InsertBefore = 0 ///< Place to insert the instruction
437437 );
439439 /// @brief Create a ZExt or BitCast cast instruction
440440 static CastInst *CreateZExtOrBitCast(
441441 Value *S, ///< The value to be casted (operand 0)
442 const Type *Ty, ///< The type to which operand is casted
442 Type *Ty, ///< The type to which operand is casted
443443 const Twine &Name, ///< The name for the instruction
444444 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
445445 );
447447 /// @brief Create a SExt or BitCast cast instruction
448448 static CastInst *CreateSExtOrBitCast(
449449 Value *S, ///< The value to be casted (operand 0)
450 const Type *Ty, ///< The type to which cast should be made
450 Type *Ty, ///< The type to which cast should be made
451451 const Twine &Name = "", ///< Name for the instruction
452452 Instruction *InsertBefore = 0 ///< Place to insert the instruction
453453 );
455455 /// @brief Create a SExt or BitCast cast instruction
456456 static CastInst *CreateSExtOrBitCast(
457457 Value *S, ///< The value to be casted (operand 0)
458 const Type *Ty, ///< The type to which operand is casted
458 Type *Ty, ///< The type to which operand is casted
459459 const Twine &Name, ///< The name for the instruction
460460 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
461461 );
463463 /// @brief Create a BitCast or a PtrToInt cast instruction
464464 static CastInst *CreatePointerCast(
465465 Value *S, ///< The pointer value to be casted (operand 0)
466 const Type *Ty, ///< The type to which operand is casted
466 Type *Ty, ///< The type to which operand is casted
467467 const Twine &Name, ///< The name for the instruction
468468 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
469469 );
471471 /// @brief Create a BitCast or a PtrToInt cast instruction
472472 static CastInst *CreatePointerCast(
473473 Value *S, ///< The pointer value to be casted (operand 0)
474 const Type *Ty, ///< The type to which cast should be made
474 Type *Ty, ///< The type to which cast should be made
475475 const Twine &Name = "", ///< Name for the instruction
476476 Instruction *InsertBefore = 0 ///< Place to insert the instruction
477477 );
479479 /// @brief Create a ZExt, BitCast, or Trunc for int -> int casts.
480480 static CastInst *CreateIntegerCast(
481481 Value *S, ///< The pointer value to be casted (operand 0)
482 const Type *Ty, ///< The type to which cast should be made
482 Type *Ty, ///< The type to which cast should be made
483483 bool isSigned, ///< Whether to regard S as signed or not
484484 const Twine &Name = "", ///< Name for the instruction
485485 Instruction *InsertBefore = 0 ///< Place to insert the instruction
488488 /// @brief Create a ZExt, BitCast, or Trunc for int -> int casts.
489489 static CastInst *CreateIntegerCast(
490490 Value *S, ///< The integer value to be casted (operand 0)
491 const Type *Ty, ///< The integer type to which operand is casted
491 Type *Ty, ///< The integer type to which operand is casted
492492 bool isSigned, ///< Whether to regard S as signed or not
493493 const Twine &Name, ///< The name for the instruction
494494 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
497497 /// @brief Create an FPExt, BitCast, or FPTrunc for fp -> fp casts
498498 static CastInst *CreateFPCast(
499499 Value *S, ///< The floating point value to be casted
500 const Type *Ty, ///< The floating point type to cast to
500 Type *Ty, ///< The floating point type to cast to
501501 const Twine &Name = "", ///< Name for the instruction
502502 Instruction *InsertBefore = 0 ///< Place to insert the instruction
503503 );
505505 /// @brief Create an FPExt, BitCast, or FPTrunc for fp -> fp casts
506506 static CastInst *CreateFPCast(
507507 Value *S, ///< The floating point value to be casted
508 const Type *Ty, ///< The floating point type to cast to
508 Type *Ty, ///< The floating point type to cast to
509509 const Twine &Name, ///< The name for the instruction
510510 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
511511 );
513513 /// @brief Create a Trunc or BitCast cast instruction
514514 static CastInst *CreateTruncOrBitCast(
515515 Value *S, ///< The value to be casted (operand 0)
516 const Type *Ty, ///< The type to which cast should be made
516 Type *Ty, ///< The type to which cast should be made
517517 const Twine &Name = "", ///< Name for the instruction
518518 Instruction *InsertBefore = 0 ///< Place to insert the instruction
519519 );
521521 /// @brief Create a Trunc or BitCast cast instruction
522522 static CastInst *CreateTruncOrBitCast(
523523 Value *S, ///< The value to be casted (operand 0)
524 const Type *Ty, ///< The type to which operand is casted
524 Type *Ty, ///< The type to which operand is casted
525525 const Twine &Name, ///< The name for the instruction
526526 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
527527 );
528528
529529 /// @brief Check whether it is valid to call getCastOpcode for these types.
530530 static bool isCastable(
531 const Type *SrcTy, ///< The Type from which the value should be cast.
532 const Type *DestTy ///< The Type to which the value should be cast.
531 Type *SrcTy, ///< The Type from which the value should be cast.
532 Type *DestTy ///< The Type to which the value should be cast.
533533 );
534534
535535 /// Returns the opcode necessary to cast Val into Ty using usual casting
538538 static Instruction::CastOps getCastOpcode(
539539 const Value *Val, ///< The value to cast
540540 bool SrcIsSigned, ///< Whether to treat the source as signed
541 const Type *Ty, ///< The Type to which the value should be casted
541 Type *Ty, ///< The Type to which the value should be casted
542542 bool DstIsSigned ///< Whether to treate the dest. as signed
543543 );
544544
567567 /// @brief Determine if the described cast is a no-op cast.
568568 static bool isNoopCast(
569569 Instruction::CastOps Opcode, ///< Opcode of cast
570 const Type *SrcTy, ///< SrcTy of cast
571 const Type *DstTy, ///< DstTy of cast
572 const Type *IntPtrTy ///< Integer type corresponding to Ptr types, or null
570 Type *SrcTy, ///< SrcTy of cast
571 Type *DstTy, ///< DstTy of cast
572 Type *IntPtrTy ///< Integer type corresponding to Ptr types, or null
573573 );
574574
575575 /// @brief Determine if this cast is a no-op cast.
576576 bool isNoopCast(
577 const Type *IntPtrTy ///< Integer type corresponding to pointer
577 Type *IntPtrTy ///< Integer type corresponding to pointer
578578 ) const;
579579
580580 /// Determine how a pair of casts can be eliminated, if they can be at all.
586586 static unsigned isEliminableCastPair(
587587 Instruction::CastOps firstOpcode, ///< Opcode of first cast
588588 Instruction::CastOps secondOpcode, ///< Opcode of second cast
589 const Type *SrcTy, ///< SrcTy of 1st cast
590 const Type *MidTy, ///< DstTy of 1st cast & SrcTy of 2nd cast
591 const Type *DstTy, ///< DstTy of 2nd cast
592 const Type *IntPtrTy ///< Integer type corresponding to Ptr types, or null
589 Type *SrcTy, ///< SrcTy of 1st cast
590 Type *MidTy, ///< DstTy of 1st cast & SrcTy of 2nd cast
591 Type *DstTy, ///< DstTy of 2nd cast
592 Type *IntPtrTy ///< Integer type corresponding to Ptr types, or null
593593 );
594594
595595 /// @brief Return the opcode of this CastInst
598598 }
599599
600600 /// @brief Return the source type, as a convenience
601 const Type* getSrcTy() const { return getOperand(0)->getType(); }
601 Type* getSrcTy() const { return getOperand(0)->getType(); }
602602 /// @brief Return the destination type, as a convenience
603 const Type* getDestTy() const { return getType(); }
603 Type* getDestTy() const { return getType(); }
604604
605605 /// This method can be used to determine if a cast from S to DstTy using
606606 /// Opcode op is valid or not.
607607 /// @returns true iff the proposed cast is valid.
608608 /// @brief Determine if a cast is valid without creating one.
609 static bool castIsValid(Instruction::CastOps op, Value *S, const Type *DstTy);
609 static bool castIsValid(Instruction::CastOps op, Value *S, Type *DstTy);
610610
611611 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
612612 static inline bool classof(const CastInst *) { return true; }
628628 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
629629 CmpInst(); // do not implement
630630 protected:
631 CmpInst(const Type *ty, Instruction::OtherOps op, unsigned short pred,
631 CmpInst(Type *ty, Instruction::OtherOps op, unsigned short pred,
632632 Value *LHS, Value *RHS, const Twine &Name = "",
633633 Instruction *InsertBefore = 0);
634634
635 CmpInst(const Type *ty, Instruction::OtherOps op, unsigned short pred,
635 CmpInst(Type *ty, Instruction::OtherOps op, unsigned short pred,
636636 Value *LHS, Value *RHS, const Twine &Name,
637637 BasicBlock *InsertAtEnd);
638638
824824 }
825825
826826 /// @brief Create a result type for fcmp/icmp
827 static const Type* makeCmpResultType(const Type* opnd_type) {
828 if (const VectorType* vt = dyn_cast(opnd_type)) {
827 static Type* makeCmpResultType(Type* opnd_type) {
828 if (VectorType* vt = dyn_cast(opnd_type)) {
829829 return VectorType::get(Type::getInt1Ty(opnd_type->getContext()),
830830 vt->getNumElements());
831831 }
364364 return getSubclassDataFromValue() & ~HasMetadataBit;
365365 }
366366
367 Instruction(const Type *Ty, unsigned iType, Use *Ops, unsigned NumOps,
367 Instruction(Type *Ty, unsigned iType, Use *Ops, unsigned NumOps,
368368 Instruction *InsertBefore = 0);
369 Instruction(const Type *Ty, unsigned iType, Use *Ops, unsigned NumOps,
369 Instruction(Type *Ty, unsigned iType, Use *Ops, unsigned NumOps,
370370 BasicBlock *InsertAtEnd);
371371 virtual Instruction *clone_impl() const = 0;
372372
4040 protected:
4141 virtual AllocaInst *clone_impl() const;
4242 public:
43 explicit AllocaInst(const Type *Ty, Value *ArraySize = 0,
43 explicit AllocaInst(Type *Ty, Value *ArraySize = 0,
4444 const Twine &Name = "", Instruction *InsertBefore = 0);
45 AllocaInst(const Type *Ty, Value *ArraySize,
45 AllocaInst(Type *Ty, Value *ArraySize,
4646 const Twine &Name, BasicBlock *InsertAtEnd);
4747
48 AllocaInst(const Type *Ty, const Twine &Name, Instruction *InsertBefore = 0);
49 AllocaInst(const Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd);
50
51 AllocaInst(const Type *Ty, Value *ArraySize, unsigned Align,
48 AllocaInst(Type *Ty, const Twine &Name, Instruction *InsertBefore = 0);
49 AllocaInst(Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd);
50
51 AllocaInst(Type *Ty, Value *ArraySize, unsigned Align,
5252 const Twine &Name = "", Instruction *InsertBefore = 0);
53 AllocaInst(const Type *Ty, Value *ArraySize, unsigned Align,
53 AllocaInst(Type *Ty, Value *ArraySize, unsigned Align,
5454 const Twine &Name, BasicBlock *InsertAtEnd);
5555
5656 // Out of line virtual method, so the vtable, etc. has a home.
6969
7070 /// getType - Overload to return most specific pointer type
7171 ///
72 const PointerType *getType() const {
73 return reinterpret_cast(Instruction::getType());
72 PointerType *getType() const {
73 return reinterpret_cast(Instruction::getType());
7474 }
7575
7676 /// getAllocatedType - Return the type that is being allocated by the
274274 // checkGEPType - Simple wrapper function to give a better assertion failure
275275 // message on bad indexes for a gep instruction.
276276 //
277 static inline const Type *checkGEPType(const Type *Ty) {
277 static inline Type *checkGEPType(Type *Ty) {
278278 assert(Ty && "Invalid GetElementPtrInst indices for type!");
279279 return Ty;
280280 }
315315 /// pointer type.
316316 ///
317317 template
318 static Type *getIndexedType(const Type *Ptr,
318 static Type *getIndexedType(Type *Ptr,
319319 RandomAccessIterator IdxBegin,
320320 RandomAccessIterator IdxEnd,
321321 // This argument ensures that we
435435 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
436436
437437 // getType - Overload to return most specific pointer type...
438 const PointerType *getType() const {
439 return reinterpret_cast(Instruction::getType());
438 PointerType *getType() const {
439 return reinterpret_cast(Instruction::getType());
440440 }
441441
442442 /// getIndexedType - Returns the type of the element that would be loaded with
446446 /// pointer type.
447447 ///
448448 template
449 static Type *getIndexedType(const Type *Ptr, RandomAccessIterator IdxBegin,
449 static Type *getIndexedType(Type *Ptr, RandomAccessIterator IdxBegin,
450450 RandomAccessIterator IdxEnd) {
451451 return getIndexedType(Ptr, IdxBegin, IdxEnd,
452452 typename std::iterator_traits::
454454 }
455455
456456 // FIXME: Use ArrayRef
457 static Type *getIndexedType(const Type *Ptr,
457 static Type *getIndexedType(Type *Ptr,
458458 Value* const *Idx, unsigned NumIdx);
459 static Type *getIndexedType(const Type *Ptr,
459 static Type *getIndexedType(Type *Ptr,
460460 Constant* const *Idx, unsigned NumIdx);
461461
462 static Type *getIndexedType(const Type *Ptr,
462 static Type *getIndexedType(Type *Ptr,
463463 uint64_t const *Idx, unsigned NumIdx);
464 static Type *getIndexedType(const Type *Ptr, Value *Idx);
464 static Type *getIndexedType(Type *Ptr, Value *Idx);
465465
466466 inline op_iterator idx_begin() { return op_begin()+1; }
467467 inline const_op_iterator idx_begin() const { return op_begin()+1; }
484484
485485 /// getPointerOperandType - Method to return the pointer operand as a
486486 /// PointerType.
487 const PointerType *getPointerOperandType() const {
488 return reinterpret_cast(getPointerOperand()->getType());
487 PointerType *getPointerOperandType() const {
488 return reinterpret_cast(getPointerOperand()->getType());
489489 }
490490
491491
892892 /// 2. Call malloc with that argument.
893893 /// 3. Bitcast the result of the malloc call to the specified type.
894894 static Instruction *CreateMalloc(Instruction *InsertBefore,
895 const Type *IntPtrTy, const Type *AllocTy,
895 Type *IntPtrTy, Type *AllocTy,
896896 Value *AllocSize, Value *ArraySize = 0,
897897 Function* MallocF = 0,
898898 const Twine &Name = "");
899899 static Instruction *CreateMalloc(BasicBlock *InsertAtEnd,
900 const Type *IntPtrTy, const Type *AllocTy,
900 Type *IntPtrTy, Type *AllocTy,
901901 Value *AllocSize, Value *ArraySize = 0,
902902 Function* MallocF = 0,
903903 const Twine &Name = "");
11641164 virtual VAArgInst *clone_impl() const;
11651165
11661166 public:
1167 VAArgInst(Value *List, const Type *Ty, const Twine &NameStr = "",
1167 VAArgInst(Value *List, Type *Ty, const Twine &NameStr = "",
11681168 Instruction *InsertBefore = 0)
11691169 : UnaryInstruction(Ty, VAArg, List, InsertBefore) {
11701170 setName(NameStr);
11711171 }
1172 VAArgInst(Value *List, const Type *Ty, const Twine &NameStr,
1172 VAArgInst(Value *List, Type *Ty, const Twine &NameStr,
11731173 BasicBlock *InsertAtEnd)
11741174 : UnaryInstruction(Ty, VAArg, List, InsertAtEnd) {
11751175 setName(NameStr);
12251225 const Value *getVectorOperand() const { return Op<0>(); }
12261226 const Value *getIndexOperand() const { return Op<1>(); }
12271227
1228 const VectorType *getVectorOperandType() const {
1229 return reinterpret_cast(getVectorOperand()->getType());
1228 VectorType *getVectorOperandType() const {
1229 return reinterpret_cast(getVectorOperand()->getType());
12301230 }
12311231
12321232
12851285
12861286 /// getType - Overload to return most specific vector type.
12871287 ///
1288 const VectorType *getType() const {
1289 return reinterpret_cast(Instruction::getType());
1288 VectorType *getType() const {
1289 return reinterpret_cast(Instruction::getType());
12901290 }
12911291
12921292 /// Transparently provide more efficient getOperand methods.
13381338
13391339 /// getType - Overload to return most specific vector type.
13401340 ///
1341 const VectorType *getType() const {
1342 return reinterpret_cast(Instruction::getType());
1341 VectorType *getType() const {
1342 return reinterpret_cast(Instruction::getType());
13431343 }
13441344
13451345 /// Transparently provide more efficient getOperand methods.
14181418 /// with an extractvalue instruction with the specified parameters.
14191419 ///
14201420 /// Null is returned if the indices are invalid for the specified type.
1421 static Type *getIndexedType(const Type *Agg, ArrayRef Idxs);
1421 static Type *getIndexedType(Type *Agg, ArrayRef Idxs);
14221422
14231423 typedef const unsigned* idx_iterator;
14241424 inline idx_iterator idx_begin() const { return Indices.begin(); }
16241624 void *operator new(size_t s) {
16251625 return User::operator new(s, 0);
16261626 }
1627 explicit PHINode(const Type *Ty, unsigned NumReservedValues,
1627 explicit PHINode(Type *Ty, unsigned NumReservedValues,
16281628 const Twine &NameStr = "", Instruction *InsertBefore = 0)
16291629 : Instruction(Ty, Instruction::PHI, 0, 0, InsertBefore),
16301630 ReservedSpace(NumReservedValues) {
16321632 OperandList = allocHungoffUses(ReservedSpace);
16331633 }
16341634
1635 PHINode(const Type *Ty, unsigned NumReservedValues, const Twine &NameStr,
1635 PHINode(Type *Ty, unsigned NumReservedValues, const Twine &NameStr,
16361636 BasicBlock *InsertAtEnd)
16371637 : Instruction(Ty, Instruction::PHI, 0, 0, InsertAtEnd),
16381638 ReservedSpace(NumReservedValues) {
16491649 public:
16501650 /// Constructors - NumReservedValues is a hint for the number of incoming
16511651 /// edges that this phi node will have (use 0 if you really have no idea).
1652 static PHINode *Create(const Type *Ty, unsigned NumReservedValues,
1652 static PHINode *Create(Type *Ty, unsigned NumReservedValues,
16531653 const Twine &NameStr = "",
16541654 Instruction *InsertBefore = 0) {
16551655 return new PHINode(Ty, NumReservedValues, NameStr, InsertBefore);
16561656 }
1657 static PHINode *Create(const Type *Ty, unsigned NumReservedValues,
1657 static PHINode *Create(Type *Ty, unsigned NumReservedValues,
16581658 const Twine &NameStr, BasicBlock *InsertAtEnd) {
16591659 return new PHINode(Ty, NumReservedValues, NameStr, InsertAtEnd);
16601660 }
25422542 /// @brief Constructor with insert-before-instruction semantics
25432543 TruncInst(
25442544 Value *S, ///< The value to be truncated
2545 const Type *Ty, ///< The (smaller) type to truncate to
2545 Type *Ty, ///< The (smaller) type to truncate to
25462546 const Twine &NameStr = "", ///< A name for the new instruction
25472547 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
25482548 );
25502550 /// @brief Constructor with insert-at-end-of-block semantics
25512551 TruncInst(
25522552 Value *S, ///< The value to be truncated
2553 const Type *Ty, ///< The (smaller) type to truncate to
2553 Type *Ty, ///< The (smaller) type to truncate to
25542554 const Twine &NameStr, ///< A name for the new instruction
25552555 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
25562556 );
25792579 /// @brief Constructor with insert-before-instruction semantics
25802580 ZExtInst(
25812581 Value *S, ///< The value to be zero extended
2582 const Type *Ty, ///< The type to zero extend to
2582 Type *Ty, ///< The type to zero extend to
25832583 const Twine &NameStr = "", ///< A name for the new instruction
25842584 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
25852585 );
25872587 /// @brief Constructor with insert-at-end semantics.
25882588 ZExtInst(
25892589 Value *S, ///< The value to be zero extended
2590 const Type *Ty, ///< The type to zero extend to
2590 Type *Ty, ///< The type to zero extend to
25912591 const Twine &NameStr, ///< A name for the new instruction
25922592 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
25932593 );
26162616 /// @brief Constructor with insert-before-instruction semantics
26172617 SExtInst(
26182618 Value *S, ///< The value to be sign extended
2619 const Type *Ty, ///< The type to sign extend to
2619 Type *Ty, ///< The type to sign extend to
26202620 const Twine &NameStr = "", ///< A name for the new instruction
26212621 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
26222622 );
26242624 /// @brief Constructor with insert-at-end-of-block semantics
26252625 SExtInst(
26262626 Value *S, ///< The value to be sign extended
2627 const Type *Ty, ///< The type to sign extend to
2627 Type *Ty, ///< The type to sign extend to
26282628 const Twine &NameStr, ///< A name for the new instruction
26292629 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
26302630 );
26532653 /// @brief Constructor with insert-before-instruction semantics
26542654 FPTruncInst(
26552655 Value *S, ///< The value to be truncated
2656 const Type *Ty, ///< The type to truncate to
2656 Type *Ty, ///< The type to truncate to
26572657 const Twine &NameStr = "", ///< A name for the new instruction
26582658 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
26592659 );
26612661 /// @brief Constructor with insert-before-instruction semantics
26622662 FPTruncInst(
26632663 Value *S, ///< The value to be truncated
2664 const Type *Ty, ///< The type to truncate to
2664 Type *Ty, ///< The type to truncate to
26652665 const Twine &NameStr, ///< A name for the new instruction
26662666 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
26672667 );
26902690 /// @brief Constructor with insert-before-instruction semantics
26912691 FPExtInst(
26922692 Value *S, ///< The value to be extended
2693 const Type *Ty, ///< The type to extend to
2693 Type *Ty, ///< The type to extend to
26942694 const Twine &NameStr = "", ///< A name for the new instruction
26952695 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
26962696 );
26982698 /// @brief Constructor with insert-at-end-of-block semantics
26992699 FPExtInst(
27002700 Value *S, ///< The value to be extended
2701 const Type *Ty, ///< The type to extend to
2701 Type *Ty, ///< The type to extend to
27022702 const Twine &NameStr, ///< A name for the new instruction
27032703 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
27042704 );
27272727 /// @brief Constructor with insert-before-instruction semantics
27282728 UIToFPInst(
27292729 Value *S, ///< The value to be converted
2730 const Type *Ty, ///< The type to convert to
2730 Type *Ty, ///< The type to convert to
27312731 const Twine &NameStr = "", ///< A name for the new instruction
27322732 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
27332733 );
27352735 /// @brief Constructor with insert-at-end-of-block semantics
27362736 UIToFPInst(
27372737 Value *S, ///< The value to be converted
2738 const Type *Ty, ///< The type to convert to
2738 Type *Ty, ///< The type to convert to
27392739 const Twine &NameStr, ///< A name for the new instruction
27402740 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
27412741 );
27642764 /// @brief Constructor with insert-before-instruction semantics
27652765 SIToFPInst(
27662766 Value *S, ///< The value to be converted
2767 const Type *Ty, ///< The type to convert to
2767 Type *Ty, ///< The type to convert to
27682768 const Twine &NameStr = "", ///< A name for the new instruction
27692769 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
27702770 );
27722772 /// @brief Constructor with insert-at-end-of-block semantics
27732773 SIToFPInst(
27742774 Value *S, ///< The value to be converted
2775 const Type *Ty, ///< The type to convert to
2775 Type *Ty, ///< The type to convert to
27762776 const Twine &NameStr, ///< A name for the new instruction
27772777 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
27782778 );
28012801 /// @brief Constructor with insert-before-instruction semantics
28022802 FPToUIInst(
28032803 Value *S, ///< The value to be converted
2804 const Type *Ty, ///< The type to convert to
2804 Type *Ty, ///< The type to convert to
28052805 const Twine &NameStr = "", ///< A name for the new instruction
28062806 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
28072807 );
28092809 /// @brief Constructor with insert-at-end-of-block semantics
28102810 FPToUIInst(
28112811 Value *S, ///< The value to be converted
2812 const Type *Ty, ///< The type to convert to
2812 Type *Ty, ///< The type to convert to
28132813 const Twine &NameStr, ///< A name for the new instruction
28142814 BasicBlock *InsertAtEnd ///< Where to insert the new instruction
28152815 );
28382838 /// @brief Constructor with insert-before-instruction semantics
28392839 FPToSIInst(
28402840 Value *S, ///< The value to be converted
2841 const Type *Ty, ///< The type to convert to
2841 Type *Ty, ///< The type to convert to
28422842 const Twine &NameStr = "", ///< A name for the new instruction
28432843 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
28442844 );
28462846 /// @brief Constructor with insert-at-end-of-block semantics
28472847 FPToSIInst(
28482848 Value *S, ///< The value to be converted
2849 const Type *Ty, ///< The type to convert to
2849 Type *Ty, ///< The type to convert to
28502850 const Twine &NameStr, ///< A name for the new instruction
28512851 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
28522852 );
28712871 /// @brief Constructor with insert-before-instruction semantics
28722872 IntToPtrInst(
28732873 Value *S, ///< The value to be converted
2874 const Type *Ty, ///< The type to convert to
2874 Type *Ty, ///< The type to convert to
28752875 const Twine &NameStr = "", ///< A name for the new instruction
28762876 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
28772877 );
28792879 /// @brief Constructor with insert-at-end-of-block semantics
28802880 IntToPtrInst(
28812881 Value *S, ///< The value to be converted
2882 const Type *Ty, ///< The type to convert to
2882 Type *Ty, ///< The type to convert to
28832883 const Twine &NameStr, ///< A name for the new instruction
28842884 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
28852885 );
29112911 /// @brief Constructor with insert-before-instruction semantics
29122912 PtrToIntInst(
29132913 Value *S, ///< The value to be converted
2914 const Type *Ty, ///< The type to convert to
2914 Type *Ty, ///< The type to convert to
29152915 const Twine &NameStr = "", ///< A name for the new instruction
29162916 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
29172917 );
29192919 /// @brief Constructor with insert-at-end-of-block semantics
29202920 PtrToIntInst(
29212921 Value *S, ///< The value to be converted
2922 const Type *Ty, ///< The type to convert to
2922 Type *Ty, ///< The type to convert to
29232923 const Twine &NameStr, ///< A name for the new instruction
29242924 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
29252925 );
29482948 /// @brief Constructor with insert-before-instruction semantics
29492949 BitCastInst(
29502950 Value *S, ///< The value to be casted
2951 const Type *Ty, ///< The type to casted to
2951 Type *Ty, ///< The type to casted to
29522952 const Twine &NameStr = "", ///< A name for the new instruction
29532953 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
29542954 );
29562956 /// @brief Constructor with insert-at-end-of-block semantics
29572957 BitCastInst(
29582958 Value *S, ///< The value to be casted
2959 const Type *Ty, ///< The type to casted to
2959 Type *Ty, ///< The type to casted to
29602960 const Twine &NameStr, ///< A name for the new instruction
29612961 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
29622962 );
169169 setArgOperand(4, V);
170170 }
171171
172 const Type *getAlignmentType() const {
172 Type *getAlignmentType() const {
173173 return getArgOperand(3)->getType();
174174 }
175175
4848
4949 /// Intrinsic::getType(ID) - Return the function type for an intrinsic.
5050 ///
51 const FunctionType *getType(LLVMContext &Context, ID id,
51 FunctionType *getType(LLVMContext &Context, ID id,
5252 ArrayRef Tys = ArrayRef());
5353
5454 /// Intrinsic::isOverloaded(ID) - Returns true if the intrinsic can be
271271 /// the existing function.
272272 /// 4. Finally, the function exists but has the wrong prototype: return the
273273 /// function with a constantexpr cast to the right prototype.
274 Constant *getOrInsertFunction(StringRef Name, const FunctionType *T,
274 Constant *getOrInsertFunction(StringRef Name, FunctionType *T,
275275 AttrListPtr AttributeList);
276276
277 Constant *getOrInsertFunction(StringRef Name, const FunctionType *T);
277 Constant *getOrInsertFunction(StringRef Name, FunctionType *T);
278278
279279 /// getOrInsertFunction - Look up the specified function in the module symbol
280280 /// table. If it does not exist, add a prototype for the function and return
285285 /// clients to use.
286286 Constant *getOrInsertFunction(StringRef Name,
287287 AttrListPtr AttributeList,
288 const Type *RetTy, ...) END_WITH_NULL;
288 Type *RetTy, ...) END_WITH_NULL;
289289
290290 /// getOrInsertFunction - Same as above, but without the attributes.
291 Constant *getOrInsertFunction(StringRef Name, const Type *RetTy, ...)
291 Constant *getOrInsertFunction(StringRef Name, Type *RetTy, ...)
292292 END_WITH_NULL;
293293
294294 Constant *getOrInsertTargetIntrinsic(StringRef Name,
295 const FunctionType *Ty,
295 FunctionType *Ty,
296296 AttrListPtr AttributeList);
297297
298298 /// getFunction - Look up the specified function in the module symbol table.
324324 /// with a constantexpr cast to the right type.
325325 /// 3. Finally, if the existing global is the correct declaration, return
326326 /// the existing global.
327 Constant *getOrInsertGlobal(StringRef Name, const Type *Ty);
327 Constant *getOrInsertGlobal(StringRef Name, Type *Ty);
328328
329329 /// @}
330330 /// @name Global Alias Accessors
260260
261261 /// getPointerOperandType - Method to return the pointer operand as a
262262 /// PointerType.
263 const PointerType *getPointerOperandType() const {
264 return reinterpret_cast(getPointerOperand()->getType());
263 PointerType *getPointerOperandType() const {
264 return reinterpret_cast(getPointerOperand()->getType());
265265 }
266266
267267 unsigned getNumIndices() const { // Note: always non-negative
146146
147147 /// getType - Return the type of the instruction that generated this call site
148148 ///
149 const Type *getType() const { return (*this)->getType(); }
149 Type *getType() const { return (*this)->getType(); }
150150
151151 /// getCaller - Return the caller function for this call site
152152 ///
140140 //===--------------------------------------------------------------------===//
141141
142142 Constant *CreateCast(Instruction::CastOps Op, Constant *C,
143 const Type *DestTy) const {
143 Type *DestTy) const {
144144 return ConstantExpr::getCast(Op, C, DestTy);
145145 }
146 Constant *CreatePointerCast(Constant *C, const Type *DestTy) const {
146 Constant *CreatePointerCast(Constant *C, Type *DestTy) const {
147147 return ConstantExpr::getPointerCast(C, DestTy);
148148 }
149 Constant *CreateIntCast(Constant *C, const Type *DestTy,
149 Constant *CreateIntCast(Constant *C, Type *DestTy,
150150 bool isSigned) const {
151151 return ConstantExpr::getIntegerCast(C, DestTy, isSigned);
152152 }
153 Constant *CreateFPCast(Constant *C, const Type *DestTy) const {
153 Constant *CreateFPCast(Constant *C, Type *DestTy) const {
154154 return ConstantExpr::getFPCast(C, DestTy);
155155 }
156156
157 Constant *CreateBitCast(Constant *C, const Type *DestTy) const {
157 Constant *CreateBitCast(Constant *C, Type *DestTy) const {
158158 return CreateCast(Instruction::BitCast, C, DestTy);
159159 }
160 Constant *CreateIntToPtr(Constant *C, const Type *DestTy) const {
160 Constant *CreateIntToPtr(Constant *C, Type *DestTy) const {
161161 return CreateCast(Instruction::IntToPtr, C, DestTy);
162162 }
163 Constant *CreatePtrToInt(Constant *C, const Type *DestTy) const {
163 Constant *CreatePtrToInt(Constant *C, Type *DestTy) const {
164164 return CreateCast(Instruction::PtrToInt, C, DestTy);
165165 }
166 Constant *CreateZExtOrBitCast(Constant *C, const Type *DestTy) const {
166 Constant *CreateZExtOrBitCast(Constant *C, Type *DestTy) const {
167167 return ConstantExpr::getZExtOrBitCast(C, DestTy);
168168 }
169 Constant *CreateSExtOrBitCast(Constant *C, const Type *DestTy) const {
169 Constant *CreateSExtOrBitCast(Constant *C, Type *DestTy) const {
170170 return ConstantExpr::getSExtOrBitCast(C, DestTy);
171171 }
172172
173 Constant *CreateTruncOrBitCast(Constant *C, const Type *DestTy) const {
173 Constant *CreateTruncOrBitCast(Constant *C, Type *DestTy) const {
174174 return ConstantExpr::getTruncOrBitCast(C, DestTy);
175175 }
176176
2020 namespace llvm {
2121 template
2222 class generic_gep_type_iterator
23 : public std::iteratorconst Type *, ptrdiff_t> {
23 : public std::iteratorType *, ptrdiff_t> {
2424 typedef std::iterator
25 const Type *, ptrdiff_t> super;
25 Type *, ptrdiff_t> super;
2626
2727 ItTy OpIt;
28 const Type *CurTy;
28 Type *CurTy;
2929 generic_gep_type_iterator() {}
3030 public:
3131
32 static generic_gep_type_iterator begin(const Type *Ty, ItTy It) {
32 static generic_gep_type_iterator begin(Type *Ty, ItTy It) {
3333 generic_gep_type_iterator I;
3434 I.CurTy = Ty;
3535 I.OpIt = It;
4949 return !operator==(x);
5050 }
5151
52 const Type *operator*() const {
52 Type *operator*() const {
5353 return CurTy;
5454 }
5555
56 const Type *getIndexedType() const {
57 const CompositeType *CT = cast(CurTy);
56 Type *getIndexedType() const {
57 CompositeType *CT = cast(CurTy);
5858 return CT->getTypeAtIndex(getOperand());
5959 }
6060
6161 // This is a non-standard operator->. It allows you to call methods on the
6262 // current type directly.
63 const Type *operator->() const { return operator*(); }
63 Type *operator->() const { return operator*(); }
6464
6565 Value *getOperand() const { return *OpIt; }
6666
6767 generic_gep_type_iterator& operator++() { // Preincrement
68 if (const CompositeType *CT = dyn_cast(CurTy)) {
68 if (CompositeType *CT = dyn_cast(CurTy)) {
6969 CurTy = CT->getTypeAtIndex(getOperand());
7070 } else {
7171 CurTy = 0;
9898
9999 template
100100 inline generic_gep_type_iterator
101 gep_type_begin(const Type *Op0, ItTy I, ItTy E) {
101 gep_type_begin(Type *Op0, ItTy I, ItTy E) {
102102 return generic_gep_type_iterator::begin(Op0, I);
103103 }
104104
105105 template
106106 inline generic_gep_type_iterator
107 gep_type_end(const Type *Op0, ItTy I, ItTy E) {
107 gep_type_end(Type *Op0, ItTy I, ItTy E) {
108108 return generic_gep_type_iterator::end(E);
109109 }
110110 } // end namespace llvm
743743 // Instruction creation methods: Memory Instructions
744744 //===--------------------------------------------------------------------===//
745745
746 AllocaInst *CreateAlloca(const Type *Ty, Value *ArraySize = 0,
746 AllocaInst *CreateAlloca(Type *Ty, Value *ArraySize = 0,
747747 const Twine &Name = "") {
748748 return Insert(new AllocaInst(Ty, ArraySize), Name);
749749 }
909909 // Instruction creation methods: Cast/Conversion Operators
910910 //===--------------------------------------------------------------------===//
911911
912 Value *CreateTrunc(Value *V, const Type *DestTy, const Twine &Name = "") {
912 Value *CreateTrunc(Value *V, Type *DestTy, const Twine &Name = "") {
913913 return CreateCast(Instruction::Trunc, V, DestTy, Name);
914914 }
915 Value *CreateZExt(Value *V, const Type *DestTy, const Twine &Name = "") {
915 Value *CreateZExt(Value *V, Type *DestTy, const Twine &Name = "") {
916916 return CreateCast(Instruction::ZExt, V, DestTy, Name);
917917 }
918 Value *CreateSExt(Value *V, const Type *DestTy, const Twine &Name = "") {
918 Value *CreateSExt(Value *V, Type *DestTy, const Twine &Name = "") {
919919 return CreateCast(Instruction::SExt, V, DestTy, Name);
920920 }
921 Value *CreateFPToUI(Value *V, const Type *DestTy, const Twine &Name = ""){
921 Value *CreateFPToUI(Value *V, Type *DestTy, const Twine &Name = ""){
922922 return CreateCast(Instruction::FPToUI, V, DestTy, Name);
923923 }
924 Value *CreateFPToSI(Value *V, const Type *DestTy, const Twine &Name = ""){
924 Value *CreateFPToSI(Value *V, Type *DestTy, const Twine &Name = ""){
925925 return CreateCast(Instruction::FPToSI, V, DestTy, Name);
926926 }
927 Value *CreateUIToFP(Value *V, const Type *DestTy, const Twine &Name = ""){
927 Value *CreateUIToFP(Value *V, Type *DestTy, const Twine &Name = ""){
928928 return CreateCast(Instruction::UIToFP, V, DestTy, Name);
929929 }
930 Value *CreateSIToFP(Value *V, const Type *DestTy, const Twine &Name = ""){
930 Value *CreateSIToFP(Value *V, Type *DestTy, const Twine &Name = ""){
931931 return CreateCast(Instruction::SIToFP, V, DestTy, Name);
932932 }
933 Value *CreateFPTrunc(Value *V, const Type *DestTy,
933 Value *CreateFPTrunc(Value *V, Type *DestTy,
934934 const Twine &Name = "") {
935935 return CreateCast(Instruction::FPTrunc, V, DestTy, Name);
936936 }
937 Value *CreateFPExt(Value *V, const Type *DestTy, const Twine &Name = "") {
937 Value *CreateFPExt(Value *V, Type *DestTy, const Twine &Name = "") {
938938 return CreateCast(Instruction::FPExt, V, DestTy, Name);
939939 }
940 Value *CreatePtrToInt(Value *V, const Type *DestTy,
940 Value *CreatePtrToInt(Value *V, Type *DestTy,
941941 const Twine &Name = "") {
942942 return CreateCast(Instruction::PtrToInt, V, DestTy, Name);
943943 }
944 Value *CreateIntToPtr(Value *V, const Type *DestTy,
944 Value *CreateIntToPtr(Value *V, Type *DestTy,
945945 const Twine &Name = "") {
946946 return CreateCast(Instruction::IntToPtr, V, DestTy, Name);
947947 }
948 Value *CreateBitCast(Value *V, const Type *DestTy,
948 Value *CreateBitCast(Value *V, Type *DestTy,
949949 const Twine &Name = "") {
950950 return CreateCast(Instruction::BitCast, V, DestTy, Name);
951951 }
952 Value *CreateZExtOrBitCast(Value *V, const Type *DestTy,
952 Value *CreateZExtOrBitCast(Value *V, Type *DestTy,
953953 const Twine &Name = "") {
954954 if (V->getType() == DestTy)
955955 return V;
957957 return Insert(Folder.CreateZExtOrBitCast(VC, DestTy), Name);
958958 return Insert(CastInst::CreateZExtOrBitCast(V, DestTy), Name);
959959 }
960 Value *CreateSExtOrBitCast(Value *V, const Type *DestTy,
960 Value *CreateSExtOrBitCast(Value *V, Type *DestTy,
961961 const Twine &Name = "") {
962962 if (V->getType() == DestTy)
963963 return V;
965965 return Insert(Folder.CreateSExtOrBitCast(VC, DestTy), Name);
966966 return Insert(CastInst::CreateSExtOrBitCast(V, DestTy), Name);
967967 }
968 Value *CreateTruncOrBitCast(Value *V, const Type *DestTy,
968 Value *CreateTruncOrBitCast(Value *V, Type *DestTy,
969969 const Twine &Name = "") {
970970 if (V->getType() == DestTy)
971971 return V;
973973 return Insert(Folder.CreateTruncOrBitCast(VC, DestTy), Name);
974974 return Insert(CastInst::CreateTruncOrBitCast(V, DestTy), Name);
975975 }
976 Value *CreateCast(Instruction::CastOps Op, Value *V, const Type *DestTy,
976 Value *CreateCast(Instruction::CastOps Op, Value *V, Type *DestTy,
977977 const Twine &Name = "") {
978978 if (V->getType() == DestTy)
979979 return V;
981981 return Insert(Folder.CreateCast(Op, VC, DestTy), Name);
982982 return Insert(CastInst::Create(Op, V, DestTy), Name);
983983 }
984 Value *CreatePointerCast(Value *V, const Type *DestTy,
984 Value *CreatePointerCast(Value *V, Type *DestTy,
985985 const Twine &Name = "") {
986986 if (V->getType() == DestTy)
987987 return V;
989989 return Insert(Folder.CreatePointerCast(VC, DestTy), Name);
990990 return Insert(CastInst::CreatePointerCast(V, DestTy), Name);
991991 }
992 Value *CreateIntCast(Value *V, const Type *DestTy, bool isSigned,
992 Value *CreateIntCast(Value *V, Type *DestTy, bool isSigned,
993993 const Twine &Name = "") {
994994 if (V->getType() == DestTy)
995995 return V;
10001000 private:
10011001 // Provided to resolve 'CreateIntCast(Ptr, Ptr, "...")', giving a compile time
10021002 // error, instead of converting the string to bool for the isSigned parameter.
1003 Value *CreateIntCast(Value *, const Type *, const char *); // DO NOT IMPLEMENT
1003 Value *CreateIntCast(Value *, Type *, const char *); // DO NOT IMPLEMENT
10041004 public:
1005 Value *CreateFPCast(Value *V, const Type *DestTy, const Twine &Name = "") {
1005 Value *CreateFPCast(Value *V, Type *DestTy, const Twine &Name = "") {
10061006 if (V->getType() == DestTy)
10071007 return V;
10081008 if (Constant *VC = dyn_cast(V))
11071107 // Instruction creation methods: Other Instructions
11081108 //===--------------------------------------------------------------------===//
11091109
1110 PHINode *CreatePHI(const Type *Ty, unsigned NumReservedValues,
1110 PHINode *CreatePHI(Type *Ty, unsigned NumReservedValues,
11111111 const Twine &Name = "") {
11121112 return Insert(PHINode::Create(Ty, NumReservedValues), Name);
11131113 }
11531153 return Insert(SelectInst::Create(C, True, False), Name);
11541154 }
11551155
1156 VAArgInst *CreateVAArg(Value *List, const Type *Ty, const Twine &Name = "") {
1156 VAArgInst *CreateVAArg(Value *List, Type *Ty, const Twine &Name = "") {
11571157 return Insert(new VAArgInst(List, Ty), Name);
11581158 }
11591159
199199 //===--------------------------------------------------------------------===//
200200
201201 Instruction *CreateCast(Instruction::CastOps Op, Constant *C,
202 const Type *DestTy) const {
202 Type *DestTy) const {
203203 return CastInst::Create(Op, C, DestTy);
204204 }
205 Instruction *CreatePointerCast(Constant *C, const Type *DestTy) const {
205 Instruction *CreatePointerCast(Constant *C, Type *DestTy) const {
206206 return CastInst::CreatePointerCast(C, DestTy);
207207 }
208 Instruction *CreateIntCast(Constant *C, const Type *DestTy,
208 Instruction *CreateIntCast(Constant *C, Type *DestTy,
209209 bool isSigned) const {
210210 return CastInst::CreateIntegerCast(C, DestTy, isSigned);
211211 }
212 Instruction *CreateFPCast(Constant *C, const Type *DestTy) const {
212 Instruction *CreateFPCast(Constant *C, Type *DestTy) const {
213213 return CastInst::CreateFPCast(C, DestTy);
214214 }
215215
216 Instruction *CreateBitCast(Constant *C, const Type *DestTy) const {
216 Instruction *CreateBitCast(Constant *C, Type *DestTy) const {
217217 return CreateCast(Instruction::BitCast, C, DestTy);
218218 }
219 Instruction *CreateIntToPtr(Constant *C, const Type *DestTy) const {
219 Instruction *CreateIntToPtr(Constant *C, Type *DestTy) const {
220220 return CreateCast(Instruction::IntToPtr, C, DestTy);
221221 }
222 Instruction *CreatePtrToInt(Constant *C, const Type *DestTy) const {
222 Instruction *CreatePtrToInt(Constant *C, Type *DestTy) const {
223223 return CreateCast(Instruction::PtrToInt, C, DestTy);
224224 }
225 Instruction *CreateZExtOrBitCast(Constant *C, const Type *DestTy) const {
225 Instruction *CreateZExtOrBitCast(Constant *C, Type *DestTy) const {
226226 return CastInst::CreateZExtOrBitCast(C, DestTy);
227227 }
228 Instruction *CreateSExtOrBitCast(Constant *C, const Type *DestTy) const {
228 Instruction *CreateSExtOrBitCast(Constant *C, Type *DestTy) const {
229229 return CastInst::CreateSExtOrBitCast(C, DestTy);
230230 }
231231
232 Instruction *CreateTruncOrBitCast(Constant *C, const Type *DestTy) const {
232 Instruction *CreateTruncOrBitCast(Constant *C, Type *DestTy) const {
233233 return CastInst::CreateTruncOrBitCast(C, DestTy);
234234 }
235235
152152 //===--------------------------------------------------------------------===//
153153
154154 Constant *CreateCast(Instruction::CastOps Op, Constant *C,
155 const Type *DestTy) const {
155 Type *DestTy) const {
156156 if (C->getType() == DestTy)
157157 return C; // avoid calling Fold
158158 return Fold(ConstantExpr::getCast(Op, C, DestTy));
159159 }
160 Constant *CreateIntCast(Constant *C, const Type *DestTy,
160 Constant *CreateIntCast(Constant *C, Type *DestTy,
161161 bool isSigned) const {
162162 if (C->getType() == DestTy)
163163 return C; // avoid calling Fold
164164 return Fold(ConstantExpr::getIntegerCast(C, DestTy, isSigned));
165165 }
166 Constant *CreatePointerCast(Constant *C, const Type *DestTy) const {
166 Constant *CreatePointerCast(Constant *C, Type *DestTy) const {
167167 return ConstantExpr::getPointerCast(C, DestTy);
168168 }
169 Constant *CreateBitCast(Constant *C, const Type *DestTy) const {
169 Constant *CreateBitCast(Constant *C, Type *DestTy) const {
170170 return CreateCast(Instruction::BitCast, C, DestTy);
171171 }
172 Constant *CreateIntToPtr(Constant *C, const Type *DestTy) const {
172 Constant *CreateIntToPtr(Constant *C, Type *DestTy) const {
173173 return CreateCast(Instruction::IntToPtr, C, DestTy);
174174 }
175 Constant *CreatePtrToInt(Constant *C, const Type *DestTy) const {
175 Constant *CreatePtrToInt(Constant *C, Type *DestTy) const {
176176 return CreateCast(Instruction::PtrToInt, C, DestTy);
177177 }
178 Constant *CreateZExtOrBitCast(Constant *C, const Type *DestTy) const {
178 Constant *CreateZExtOrBitCast(Constant *C, Type *DestTy) const {
179179 if (C->getType() == DestTy)
180180 return C; // avoid calling Fold
181181 return Fold(ConstantExpr::getZExtOrBitCast(C, DestTy));
182182 }
183 Constant *CreateSExtOrBitCast(Constant *C, const Type *DestTy) const {
183 Constant *CreateSExtOrBitCast(Constant *C, Type *DestTy) const {
184184 if (C->getType() == DestTy)
185185 return C; // avoid calling Fold
186186 return Fold(ConstantExpr::getSExtOrBitCast(C, DestTy));
187187 }
188 Constant *CreateTruncOrBitCast(Constant *C, const Type *DestTy) const {
188 Constant *CreateTruncOrBitCast(Constant *C, Type *DestTy) const {
189189 if (C->getType() == DestTy)
190190 return C; // avoid calling Fold
191191 return Fold(ConstantExpr::getTruncOrBitCast(C, DestTy));
8989 void setAlignment(AlignTypeEnum align_type, unsigned abi_align,
9090 unsigned pref_align, uint32_t bit_width);
9191 unsigned getAlignmentInfo(AlignTypeEnum align_type, uint32_t bit_width,
92 bool ABIAlign, const Type *Ty) const;
92 bool ABIAlign, Type *Ty) const;
9393 //! Internal helper method that returns requested alignment for type.
94 unsigned getAlignment(const Type *Ty, bool abi_or_pref) const;
94 unsigned getAlignment(Type *Ty, bool abi_or_pref) const;
9595
9696 /// Valid alignment predicate.
9797 ///
199199
200200 /// getTypeSizeInBits - Return the number of bits necessary to hold the
201201 /// specified type. For example, returns 36 for i36 and 80 for x86_fp80.
202 uint64_t getTypeSizeInBits(const Type* Ty) const;
202 uint64_t getTypeSizeInBits(Type* Ty) const;
203203
204204 /// getTypeStoreSize - Return the maximum number of bytes that may be
205205 /// overwritten by storing the specified type. For example, returns 5
206206 /// for i36 and 10 for x86_fp80.
207 uint64_t getTypeStoreSize(const Type *Ty) const {
207 uint64_t getTypeStoreSize(Type *Ty) const {
208208 return (getTypeSizeInBits(Ty)+7)/8;
209209 }
210210
211211 /// getTypeStoreSizeInBits - Return the maximum number of bits that may be
212212 /// overwritten by storing the specified type; always a multiple of 8. For
213213 /// example, returns 40 for i36 and 80 for x86_fp80.
214 uint64_t getTypeStoreSizeInBits(const Type *Ty) const {
214 uint64_t getTypeStoreSizeInBits(Type *Ty) const {
215215 return 8*getTypeStoreSize(Ty);
216216 }
217217
219219 /// of the specified type, including alignment padding. This is the amount
220220 /// that alloca reserves for this type. For example, returns 12 or 16 for
221221 /// x86_fp80, depending on alignment.
222 uint64_t getTypeAllocSize(const Type* Ty) const {
222 uint64_t getTypeAllocSize(Type* Ty) const {
223223 // Round up to the next alignment boundary.
224224 return RoundUpAlignment(getTypeStoreSize(Ty), getABITypeAlignment(Ty));
225225 }
228228 /// objects of the specified type, including alignment padding; always a
229229 /// multiple of 8. This is the amount that alloca reserves for this type.
230230 /// For example, returns 96 or 128 for x86_fp80, depending on alignment.
231 uint64_t getTypeAllocSizeInBits(const Type* Ty) const {
231 uint64_t getTypeAllocSizeInBits(Type* Ty) const {
232232 return 8*getTypeAllocSize(Ty);
233233 }
234234
235235 /// getABITypeAlignment - Return the minimum ABI-required alignment for the
236236 /// specified type.
237 unsigned getABITypeAlignment(const Type *Ty) const;
237 unsigned getABITypeAlignment(Type *Ty) const;
238238
239239 /// getABIIntegerTypeAlignment - Return the minimum ABI-required alignment for
240240 /// an integer type of the specified bitwidth.
243243
244244 /// getCallFrameTypeAlignment - Return the minimum ABI-required alignment
245245 /// for the specified type when it is part of a call frame.
246 unsigned getCallFrameTypeAlignment(const Type *Ty) const;
246 unsigned getCallFrameTypeAlignment(Type *Ty) const;
247247
248248
249249 /// getPrefTypeAlignment - Return the preferred stack/global alignment for
250250 /// the specified type. This is always at least as good as the ABI alignment.
251 unsigned getPrefTypeAlignment(const Type *Ty) const;
251 unsigned getPrefTypeAlignment(Type *Ty) const;
252252
253253 /// getPreferredTypeAlignmentShift - Return the preferred alignment for the
254254 /// specified type, returned as log2 of the value (a shift amount).
255255 ///
256 unsigned getPreferredTypeAlignmentShift(const Type *Ty) const;
256 unsigned getPreferredTypeAlignmentShift(Type *Ty) const;
257257
258258 /// getIntPtrType - Return an unsigned integer type that is the same size or
259259 /// greater to the host pointer size.
263263 /// getIndexedOffset - return the offset from the beginning of the type for
264264 /// the specified indices. This is used to implement getelementptr.
265265 ///
266 uint64_t getIndexedOffset(const Type *Ty,
266 uint64_t getIndexedOffset(Type *Ty,
267267 Value* const* Indices, unsigned NumIndices) const;
268268
269269 /// getStructLayout - Return a StructLayout object, indicating the alignment
270270 /// of the struct, its size, and the offsets of its fields. Note that this
271271 /// information is lazily cached.
272 const StructLayout *getStructLayout(const StructType *Ty) const;
272 const StructLayout *getStructLayout(StructType *Ty) const;
273273
274274 /// getPreferredAlignment - Return the preferred alignment of the specified
275275 /// global. This includes an explicitly requested alignment (if the global
332332
333333 private:
334334 friend class TargetData; // Only TargetData can create this class
335 StructLayout(const StructType *ST, const TargetData &TD);
335 StructLayout(StructType *ST, const TargetData &TD);
336336 };
337337
338338 } // End llvm namespace
3838 /// intrinsic, Tys should point to an array of numTys pointers to Type,
3939 /// and must provide exactly one type for each overloaded type in the
4040 /// intrinsic.
41 virtual std::string getName(unsigned IID, const Type **Tys = 0,
41 virtual std::string getName(unsigned IID, Type **Tys = 0,
4242 unsigned numTys = 0) const = 0;
4343
4444 /// Look up target intrinsic by name. Return intrinsic ID or 0 for unknown
5454 /// Create or insert an LLVM Function declaration for an intrinsic,
5555 /// and return it. The Tys and numTys are for intrinsics with overloaded
5656 /// types. See above for more information.
57 virtual Function *getDeclaration(Module *M, unsigned ID, const Type **Tys = 0,
57 virtual Function *getDeclaration(Module *M, unsigned ID, Type **Tys = 0,
5858 unsigned numTys = 0) const = 0;
5959 };
6060
500500 /// This is fixed by the LLVM operations except for the pointer size. If
501501 /// AllowUnknown is true, this will return MVT::Other for types with no EVT
502502 /// counterpart (e.g. structs), otherwise it will assert.
503 EVT getValueType(const Type *Ty, bool AllowUnknown = false) const {
503 EVT getValueType(Type *Ty, bool AllowUnknown = false) const {
504504 EVT VT = EVT::getEVT(Ty, AllowUnknown);
505505 return VT == MVT::iPTR ? PointerTy : VT;
506506 }
508508 /// getByValTypeAlignment - Return the desired alignment for ByVal aggregate
509509 /// function arguments in the caller parameter area. This is the actual
510510 /// alignment, not its logarithm.
511 virtual unsigned getByValTypeAlignment(const Type *Ty) const;
511 virtual unsigned getByValTypeAlignment(Type *Ty) const;
512512
513513 /// getRegisterType - Return the type of registers that this ValueType will
514514 /// eventually require.
11651165 /// lowering.
11661166 struct ArgListEntry {
11671167 SDValue Node;
1168 const Type* Ty;
1168 Type* Ty;
11691169 bool isSExt : 1;
11701170 bool isZExt : 1;
11711171 bool isInReg : 1;
11791179 };
11801180 typedef std::vector ArgListTy;
11811181 std::pair
1182 LowerCallTo(SDValue Chain, const Type *RetTy, bool RetSExt, bool RetZExt,
1182 LowerCallTo(SDValue Chain, Type *RetTy, bool RetSExt, bool RetZExt,
11831183 bool isVarArg, bool isInreg, unsigned NumFixedArgs,
11841184 CallingConv::ID CallConv, bool isTailCall,
11851185 bool isReturnValueUsed, SDValue Callee, ArgListTy &Args,
14841484 /// The type may be VoidTy, in which case only return true if the addressing
14851485 /// mode is legal for a load/store of any legal type.
14861486 /// TODO: Handle pre/postinc as well.
1487 virtual bool isLegalAddressingMode(const AddrMode &AM, const Type *Ty) const;
1487 virtual bool isLegalAddressingMode(const AddrMode &AM, Type *Ty) const;
14881488
14891489 /// isTruncateFree - Return true if it's free to truncate a value of
14901490 /// type Ty1 to type Ty2. e.g. On x86 it's free to truncate a i32 value in
14911491 /// register EAX to i16 by referencing its sub-register AX.
1492 virtual bool isTruncateFree(const Type *Ty1, const Type *Ty2) const {
1492 virtual bool isTruncateFree(Type *Ty1, Type *Ty2) const {
14931493 return false;
14941494 }
14951495
15051505 /// does not necessarily apply to truncate instructions. e.g. on x86-64,
15061506 /// all instructions that define 32-bit values implicit zero-extend the
15071507 /// result out to 64 bits.
1508 virtual bool isZExtFree(const Type *Ty1, const Type *Ty2) const {
1508 virtual bool isZExtFree(Type *Ty1, Type *Ty2) const {
15091509 return false;
15101510 }
15111511
19621962 /// GetReturnInfo - Given an LLVM IR type and return type attributes,
19631963 /// compute the return value EVTs and flags, and optionally also
19641964 /// the offsets, if the return value is being lowered to memory.
1965 void GetReturnInfo(const Type* ReturnType, Attributes attr,
1965 void GetReturnInfo(Type* ReturnType, Attributes attr,
19661966 SmallVectorImpl &Outs,
19671967 const TargetLowering &TLI,
19681968 SmallVectorImpl *Offsets = 0);
5757
5858 /// AccessTy/MemoryInst - This is the type for the access (e.g. double) and
5959 /// the memory instruction that we're computing this address for.
60 const Type *AccessTy;
60 Type *AccessTy;
6161 Instruction *MemoryInst;
6262
6363 /// AddrMode - This is the addressing mode that we're building up. This is
7070 bool IgnoreProfitability;
7171
7272 AddressingModeMatcher(SmallVectorImpl &AMI,
73 const TargetLowering &T, const Type *AT,
73 const TargetLowering &T, Type *AT,
7474 Instruction *MI, ExtAddrMode &AM)
7575 : AddrModeInsts(AMI), TLI(T), AccessTy(AT), MemoryInst(MI), AddrMode(AM) {
7676 IgnoreProfitability = false;
8080 /// Match - Find the maximal addressing mode that a load/store of V can fold,
8181 /// give an access type of AccessTy. This returns a list of involved
8282 /// instructions in AddrModeInsts.
83 static ExtAddrMode Match(Value *V, const Type *AccessTy,
83 static ExtAddrMode Match(Value *V, Type *AccessTy,
8484 Instruction *MemoryInst,
8585 SmallVectorImpl &AddrModeInsts,
8686 const TargetLowering &TLI) {
3838 void *AV;
3939
4040 /// ProtoType holds the type of the values being rewritten.
41 const Type *ProtoType;
41 Type *ProtoType;
4242
4343 // PHI nodes are given a name based on ProtoName.
4444 std::string ProtoName;
5555
5656 /// Initialize - Reset this object to get ready for a new set of SSA
5757 /// updates with type 'Ty'. PHI nodes get a name based on 'Name'.
58 void Initialize(const Type *Ty, StringRef Name);
58 void Initialize(Type *Ty, StringRef Name);
5959
6060 /// AddAvailableValue - Indicate that a rewritten value is available at the
6161 /// end of the specified block with the specified value.
192192 /// are valid for types of the same size only where no re-interpretation of
193193 /// the bits is done.
194194 /// @brief Determine if this type could be losslessly bitcast to Ty
195 bool canLosslesslyBitCastTo(const Type *Ty) const;
195 bool canLosslesslyBitCastTo(Type *Ty) const;
196196
197197 /// isEmptyTy - Return true if this type is empty, that is, it has no
198198 /// elements or all its elements are empty.
261261 /// getScalarSizeInBits - If this is a vector type, return the
262262 /// getPrimitiveSizeInBits value for the element type. Otherwise return the
263263 /// getPrimitiveSizeInBits value for this type.
264 unsigned getScalarSizeInBits() const;
264 unsigned getScalarSizeInBits();
265265
266266 /// getFPMantissaWidth - Return the width of the mantissa of this type. This
267267 /// is only valid on floating point types. If the FP type does not
270270
271271 /// getScalarType - If this is a vector type, return the element type,
272272 /// otherwise return 'this'.
273 const Type *getScalarType() const;
273 Type *getScalarType();
274274
275275 //===--------------------------------------------------------------------===//
276276 // Type Iteration support.
341341
342342 /// getPointerTo - Return a pointer to the current type. This is equivalent
343343 /// to PointerType::get(Foo, AddrSpace).
344 PointerType *getPointerTo(unsigned AddrSpace = 0) const;
344 PointerType *getPointerTo(unsigned AddrSpace = 0);
345345
346346 private:
347347 /// isSizedDerivedType - Derived types like structures and arrays are sized
351351 };
352352
353353 // Printing of types.
354 static inline raw_ostream &operator<<(raw_ostream &OS, const Type &T) {
354 static inline raw_ostream &operator<<(raw_ostream &OS, Type &T) {
355355 T.print(OS);
356356 return OS;
357357 }
386386 typedef const Type NodeType;
387387 typedef Type::subtype_iterator ChildIteratorType;
388388
389 static inline NodeType *getEntryNode(const Type *T) { return T; }
389 static inline NodeType *getEntryNode(NodeType *T) { return T; }
390390 static inline ChildIteratorType child_begin(NodeType *N) {
391391 return N->subtype_begin();
392392 }
4646 unsigned NumOperands;
4747
4848 void *operator new(size_t s, unsigned Us);
49 User(const Type *ty, unsigned vty, Use *OpList, unsigned NumOps)
49 User(Type *ty, unsigned vty, Use *OpList, unsigned NumOps)
5050 : Value(ty, vty), OperandList(OpList), NumOperands(NumOps) {}
5151 Use *allocHungoffUses(unsigned) const;
5252 void dropHungoffUses() {
9090 /// printing behavior.
9191 virtual void printCustom(raw_ostream &O) const;
9292
93 Value(const Type *Ty, unsigned scid);
93 Value(Type *Ty, unsigned scid);
9494 public:
9595 virtual ~Value();
9696
11351135 return reinterpret_cast(Tys);
11361136 }
11371137
1138 inline LLVMTypeRef *wrap(const Type **Tys) {
1138 inline LLVMTypeRef *wrap(Type **Tys) {
11391139 return reinterpret_cast(const_cast(Tys));
11401140 }
11411141
340340 /// getTypeStoreSize - Return the TargetData store size for the given type,
341341 /// if known, or a conservative value otherwise.
342342 ///
343 uint64_t AliasAnalysis::getTypeStoreSize(const Type *Ty) {
343 uint64_t AliasAnalysis::getTypeStoreSize(Type *Ty) {
344344 return TD ? TD->getTypeStoreSize(Ty) : UnknownSize;
345345 }
346346
170170 for (SetVector::iterator I1 = Pointers.begin(), E = Pointers.end();
171171 I1 != E; ++I1) {
172172 uint64_t I1Size = AliasAnalysis::UnknownSize;
173 const Type *I1ElTy = cast((*I1)->getType())->getElementType();
173 Type *I1ElTy = cast((*I1)->getType())->getElementType();
174174 if (I1ElTy->isSized()) I1Size = AA.getTypeStoreSize(I1ElTy);
175175
176176 for (SetVector::iterator I2 = Pointers.begin(); I2 != I1; ++I2) {
177177 uint64_t I2Size = AliasAnalysis::UnknownSize;
178 const Type *I2ElTy =cast((*I2)->getType())->getElementType();
178 Type *I2ElTy =cast((*I2)->getType())->getElementType();
179179 if (I2ElTy->isSized()) I2Size = AA.getTypeStoreSize(I2ElTy);
180180
181181 switch (AA.alias(*I1, I1Size, *I2, I2Size)) {
206206 for (SetVector::iterator V = Pointers.begin(), Ve = Pointers.end();
207207 V != Ve; ++V) {
208208 uint64_t Size = AliasAnalysis::UnknownSize;
209 const Type *ElTy = cast((*V)->getType())->getElementType();
209 Type *ElTy = cast((*V)->getType())->getElementType();
210210 if (ElTy->isSized()) Size = AA.getTypeStoreSize(ElTy);
211211
212212 switch (AA.getModRefInfo(*C, *V, Size)) {
9999 /// getObjectSize - Return the size of the object specified by V, or
100100 /// UnknownSize if unknown.
101101 static uint64_t getObjectSize(const Value *V, const TargetData &TD) {
102 const Type *AccessTy;
102 Type *AccessTy;
103103 if (const GlobalVariable *GV = dyn_cast(V)) {
104104 if (!GV->hasDefinitiveInitializer())
105105 return AliasAnalysis::UnknownSize;
316316 E = GEPOp->op_end(); I != E; ++I) {
317317 Value *Index = *I;
318318 // Compute the (potentially symbolic) offset in bytes for this index.
319 if (const StructType *STy = dyn_cast(*GTI++)) {
319 if (StructType *STy = dyn_cast(*GTI++)) {
320320 // For a struct, add the member offset.
321321 unsigned FieldNo = cast(Index)->getZExtValue();
322322 if (FieldNo == 0) continue;
4242 /// FoldBitCast - Constant fold bitcast, symbolically evaluating it with
4343 /// TargetData. This always returns a non-null constant, but it may be a
4444 /// ConstantExpr if unfoldable.
45 static Constant *FoldBitCast(Constant *C, const Type *DestTy,
45 static Constant *FoldBitCast(Constant *C, Type *DestTy,
4646 const TargetData &TD) {
4747
4848 // This only handles casts to vectors currently.
49 const VectorType *DestVTy = dyn_cast(DestTy);
49 VectorType *DestVTy = dyn_cast(DestTy);
5050 if (DestVTy == 0)
5151 return ConstantExpr::getBitCast(C, DestTy);
5252
6868 if (NumDstElt == NumSrcElt)
6969 return ConstantExpr::getBitCast(C, DestTy);
7070
71 const Type *SrcEltTy = CV->getType()->getElementType();
72 const Type *DstEltTy = DestVTy->getElementType();
71 Type *SrcEltTy = CV->getType()->getElementType();
72 Type *DstEltTy = DestVTy->getElementType();
7373
7474 // Otherwise, we're changing the number of elements in a vector, which
7575 // requires endianness information to do the right thing. For example,
8484 if (DstEltTy->isFloatingPointTy()) {
8585 // Fold to an vector of integers with same size as our FP type.
8686 unsigned FPWidth = DstEltTy->getPrimitiveSizeInBits();
87 const Type *DestIVTy =
87 Type *DestIVTy =
8888 VectorType::get(IntegerType::get(C->getContext(), FPWidth), NumDstElt);
8989 // Recursively handle this integer conversion, if possible.
9090 C = FoldBitCast(C, DestIVTy, TD);
9898 // it to integer first.
9999 if (SrcEltTy->isFloatingPointTy()) {
100100 unsigned FPWidth = SrcEltTy->getPrimitiveSizeInBits();
101 const Type *SrcIVTy =
101 Type *SrcIVTy =
102102 VectorType::get(IntegerType::get(C->getContext(), FPWidth), NumSrcElt);
103103 // Ask VMCore to do the conversion now that #elts line up.
104104 C = ConstantExpr::getBitCast(C, SrcIVTy);
211211 if (!CI) return false; // Index isn't a simple constant?
212212 if (CI->isZero()) continue; // Not adding anything.
213213
214 if (const StructType *ST = dyn_cast(*GTI)) {
214 if (StructType *ST = dyn_cast(*GTI)) {
215215 // N = N + Offset
216216 Offset += TD.getStructLayout(ST)->getElementOffset(CI->getZExtValue());
217217 } else {
218 const SequentialType *SQT = cast(*GTI);
218 SequentialType *SQT = cast(*GTI);
219219 Offset += TD.getTypeAllocSize(SQT->getElementType())*CI->getSExtValue();
220220 }
221221 }
353353
354354 static Constant *FoldReinterpretLoadFromConstPtr(Constant *C,
355355 const TargetData &TD) {
356 const Type *LoadTy = cast(C->getType())->getElementType();
357 const IntegerType *IntType = dyn_cast(LoadTy);
356 Type *LoadTy = cast(C->getType())->getElementType();
357 IntegerType *IntType = dyn_cast(LoadTy);
358358
359359 // If this isn't an integer load we can't fold it directly.
360360 if (!IntType) {
362362 // and then bitcast the result. This can be useful for union cases. Note
363363 // that address spaces don't matter here since we're not going to result in
364364 // an actual new load.
365 const Type *MapTy;
365 Type *MapTy;
366366 if (LoadTy->isFloatTy())
367367 MapTy = Type::getInt32PtrTy(C->getContext());
368368 else if (LoadTy->isDoubleTy())
442442 std::string Str;
443443 if (TD && GetConstantStringInfo(CE, Str) && !Str.empty()) {
444444 unsigned StrLen = Str.length();
445 const Type *Ty = cast(CE->getType())->getElementType();
445 Type *Ty = cast(CE->getType())->getElementType();
446446 unsigned NumBits = Ty->getPrimitiveSizeInBits();
447447 // Replace load with immediate integer if the result is an integer or fp
448448 // value.
477477 if (GlobalVariable *GV =
478478 dyn_cast(GetUnderlyingObject(CE, TD))) {
479479 if (GV->isConstant() && GV->hasDefinitiveInitializer()) {
480 const Type *ResTy = cast(C->getType())->getElementType();
480 Type *ResTy = cast(C->getType())->getElementType();
481481 if (GV->getInitializer()->isNullValue())
482482 return Constant::getNullValue(ResTy);
483483 if (isa(GV->getInitializer()))
536536 /// explicitly cast them so that they aren't implicitly casted by the
537537 /// getelementptr.
538538 static Constant *CastGEPIndices(Constant *const *Ops, unsigned NumOps,
539 const Type *ResultTy,
539 Type *ResultTy,
540540 const TargetData *TD) {
541541 if (!TD) return 0;
542 const Type *IntPtrTy = TD->getIntPtrType(ResultTy->getContext());
542 Type *IntPtrTy = TD->getIntPtrType(ResultTy->getContext());
543543
544544 bool Any = false;
545545 SmallVector NewIdxs;
571571 /// SymbolicallyEvaluateGEP - If we can symbolically evaluate the specified GEP
572572 /// constant expression, do so.
573573 static Constant *SymbolicallyEvaluateGEP(Constant *const *Ops, unsigned NumOps,
574 const Type *ResultTy,
574 Type *ResultTy,
575575 const TargetData *TD) {
576576 Constant *Ptr = Ops[0];
577577 if (!TD || !cast(Ptr->getType())->getElementType()->isSized())
578578 return 0;
579579
580 const Type *IntPtrTy = TD->getIntPtrType(Ptr->getContext());
580 Type *IntPtrTy = TD->getIntPtrType(Ptr->getContext());
581581
582582 // If this is a constant expr gep that is effectively computing an
583583 // "offsetof", fold it into 'cast int Size to T*' instead of 'gep 0, 0, 12'
648648 // we eliminate over-indexing of the notional static type array bounds.
649649 // This makes it easy to determine if the getelementptr is "inbounds".
650650 // Also, this helps GlobalOpt do SROA on GlobalVariables.
651 const Type *Ty = Ptr->getType();
651 Type *Ty = Ptr->getType();
652652 SmallVector NewIdxs;
653653 do {
654 if (const SequentialType *ATy = dyn_cast(Ty)) {
654 if (SequentialType *ATy = dyn_cast(Ty)) {
655655 if (ATy->isPointerTy()) {
656656 // The only pointer indexing we'll do is on the first index of the GEP.
657657 if (!NewIdxs.empty())
664664
665665 // Determine which element of the array the offset points into.
666666 APInt ElemSize(BitWidth, TD->getTypeAllocSize(ATy->getElementType()));
667 const IntegerType *IntPtrTy = TD->getIntPtrType(Ty->getContext());
667 IntegerType *IntPtrTy = TD->getIntPtrType(Ty->getContext());
668668 if (ElemSize == 0)
669669 // The element size is 0. This may be [0 x Ty]*, so just use a zero
670670 // index for this level and proceed to the next level to see if it can
678678 NewIdxs.push_back(ConstantInt::get(IntPtrTy, NewIdx));
679679 }
680680 Ty = ATy->getElementType();
681 } else if (const StructType *STy = dyn_cast(Ty)) {
681 } else if (StructType *STy = dyn_cast(Ty)) {
682682 // Determine which field of the struct the offset points into. The
683683 // getZExtValue is at least as safe as the StructLayout API because we
684684 // know the offset is within the struct at this point.
813813 /// information, due to only being passed an opcode and operands. Constant
814814 /// folding using this function strips this information.
815815 ///
816 Constant *llvm::ConstantFoldInstOperands(unsigned Opcode, const Type *DestTy,
816 Constant *llvm::ConstantFoldInstOperands(unsigned Opcode, Type *DestTy,
817817 Constant* const* Ops, unsigned NumOps,
818818 const TargetData *TD) {
819819 // Handle easy binops first.
911911 // around to know if bit truncation is happening.
912912 if (ConstantExpr *CE0 = dyn_cast(Ops0)) {
913913 if (TD && Ops1->isNullValue()) {
914 const Type *IntPtrTy = TD->getIntPtrType(CE0->getContext());
914 Type *IntPtrTy = TD->getIntPtrType(CE0->getContext());
915915 if (CE0->getOpcode() == Instruction::IntToPtr) {
916916 // Convert the integer value to the right size to ensure we get the
917917 // proper extension or truncation.
933933
934934 if (ConstantExpr *CE1 = dyn_cast(Ops1)) {
935935 if (TD && CE0->getOpcode() == CE1->getOpcode()) {
936 const Type *IntPtrTy = TD->getIntPtrType(CE0->getContext());
936 Type *IntPtrTy = TD->getIntPtrType(CE0->getContext());
937937
938938 if (CE0->getOpcode() == Instruction::IntToPtr) {
939939 // Convert the integer value to the right size to ensure we get the
986986 // addressing...
987987 gep_type_iterator I = gep_type_begin(CE), E = gep_type_end(CE);
988988 for (++I; I != E; ++I)
989 if (const StructType *STy = dyn_cast(*I)) {
989 if (StructType *STy = dyn_cast(*I)) {
990990 ConstantInt *CU = cast(I.getOperand());
991991 assert(CU->getZExtValue() < STy->getNumElements() &&
992992 "Struct index out of range!");
10011001 return 0;
10021002 }
10031003 } else if (ConstantInt *CI = dyn_cast(I.getOperand())) {
1004 if (const ArrayType *ATy = dyn_cast(*I)) {
1004 if (ArrayType *ATy = dyn_cast(*I)) {
10051005 if (CI->getZExtValue() >= ATy->getNumElements())
10061006 return 0;
10071007 if (ConstantArray *CA = dyn_cast(C))
10121012 C = UndefValue::get(ATy->getElementType());
10131013 else
10141014 return 0;
1015 } else if (const VectorType *VTy = dyn_cast(*I)) {
1015 } else if (VectorType *VTy = dyn_cast(*I)) {
10161016 if (CI->getZExtValue() >= VTy->getNumElements())
10171017 return 0;
10181018 if (ConstantVector *CP = dyn_cast(C))
11001100 }
11011101
11021102 static Constant *ConstantFoldFP(double (*NativeFP)(double), double V,
1103 const Type *Ty) {
1103 Type *Ty) {
11041104 sys::llvm_fenv_clearexcept();
11051105 V = NativeFP(V);
11061106 if (sys::llvm_fenv_testexcept()) {
11171117 }
11181118
11191119 static Constant *ConstantFoldBinaryFP(double (*NativeFP)(double, double),
1120 double V, double W, const Type *Ty) {
1120 double V, double W, Type *Ty) {
11211121 sys::llvm_fenv_clearexcept();
11221122 V = NativeFP(V, W);
11231123 if (sys::llvm_fenv_testexcept()) {
11421142 /// performed, otherwise returns the Constant value resulting from the
11431143 /// conversion.
11441144 static Constant *ConstantFoldConvertToInt(ConstantFP *Op, bool roundTowardZero,
1145 const Type *Ty) {
1145 Type *Ty) {
11461146 assert(Op && "Called with NULL operand");
11471147 APFloat Val(Op->getValueAPF());
11481148
11711171 if (!F->hasName()) return 0;
11721172 StringRef Name = F->getName();
11731173
1174 const Type *Ty = F->getReturnType();
1174 Type *Ty = F->getReturnType();
11751175 if (NumOperands == 1) {
11761176 if (ConstantFP *Op = dyn_cast(Operands[0])) {
11771177 if (F->getIntrinsicID() == Intrinsic::convert_to_fp16) {
2828 // IncorporateType - Incorporate one type and all of its subtypes into the
2929 // collection of used types.
3030 //
31 void FindUsedTypes::IncorporateType(const Type *Ty) {
31 void FindUsedTypes::IncorporateType(Type *Ty) {
3232 // If ty doesn't already exist in the used types map, add it now, otherwise
3333 // return.
3434 if (!UsedTypes.insert(Ty)) return; // Already contain Ty.
9393 //
9494 void FindUsedTypes::print(raw_ostream &OS, const Module *M) const {
9595 OS << "Types in use by this module:\n";
96 for (SetVector<const Type *>::const_iterator I = UsedTypes.begin(),
96 for (SetVector<Type *>::const_iterator I = UsedTypes.begin(),
9797 E = UsedTypes.end(); I != E; ++I) {
9898 OS << " " << **I << '\n';
9999 }
13711371 return ::SimplifyXorInst(Op0, Op1, TD, DT, RecursionLimit);
13721372 }
13731373
1374 static const Type *GetCompareTy(Value *Op) {
1374 static Type *GetCompareTy(Value *Op) {
13751375 return CmpInst::makeCmpResultType(Op->getType());
13761376 }
13771377
14121412 Pred = CmpInst::getSwappedPredicate(Pred);
14131413 }
14141414
1415 const Type *ITy = GetCompareTy(LHS); // The return type.
1416 const Type *OpTy = LHS->getType(); // The operand type.
1415 Type *ITy = GetCompareTy(LHS); // The return type.
1416 Type *OpTy = LHS->getType(); // The operand type.
14171417
14181418 // icmp X, X -> true/false
14191419 // X icmp undef -> true/false. For example, icmp ugt %X, undef -> false
15921592 if (isa(LHS) && (isa(RHS) || isa(RHS))) {
15931593 Instruction *LI = cast(LHS);
15941594 Value *SrcOp = LI->getOperand(0);
1595 const Type *SrcTy = SrcOp->getType();
1596 const Type *DstTy = LI->getType();
1595 Type *SrcTy = SrcOp->getType();
1596 Type *DstTy = LI->getType();
15971597
15981598 // Turn icmp (ptrtoint x), (ptrtoint/constant) into a compare of the input
15991599 // if the integer type is the same size as the pointer type.
22212221 Value *llvm::SimplifyGEPInst(Value *const *Ops, unsigned NumOps,
22222222 const TargetData *TD, const DominatorTree *) {
22232223 // The type of the GEP pointer operand.
2224 const PointerType *PtrTy = cast(Ops[0]->getType());
2224 PointerType *PtrTy = cast(Ops[0]->getType());
22252225
22262226 // getelementptr P -> P.
22272227 if (NumOps == 1)
22292229
22302230 if (isa(Ops[0])) {
22312231 // Compute the (pointer) type returned by the GEP instruction.
2232 const Type *LastType = GetElementPtrInst::getIndexedType(PtrTy, &Ops[1],
2232 Type *LastType = GetElementPtrInst::getIndexedType(PtrTy, &Ops[1],
22332233 NumOps-1);
2234 const Type *GEPTy = PointerType::get(LastType, PtrTy->getAddressSpace());
2234 Type *GEPTy = PointerType::get(LastType, PtrTy->getAddressSpace());
22352235 return UndefValue::get(GEPTy);
22362236 }
22372237
22422242 return Ops[0];
22432243 // getelementptr P, N -> P if P points to a type of zero size.
22442244 if (TD) {
2245 const Type *Ty = PtrTy->getElementType();
2245 Type *Ty = PtrTy->getElementType();
22462246 if (Ty->isSized() && TD->getTypeAllocSize(Ty) == 0)
22472247 return Ops[0];
22482248 }
629629 if (BB == &BB->getParent()->getEntryBlock()) {
630630 assert(isa(Val) && "Unknown live-in to the entry block");
631631 if (NotNull) {
632 const PointerType *PTy = cast(Val->getType());
632 PointerType *PTy = cast(Val->getType());
633633 Result = LVILatticeVal::getNot(ConstantPointerNull::get(PTy));
634634 } else {
635635 Result.markOverdefined();
657657 // If we previously determined that this is a pointer that can't be null
658658 // then return that rather than giving up entirely.
659659 if (NotNull) {
660 const PointerType *PTy = cast(Val->getType());
660 PointerType *PTy = cast(Val->getType());
661661 Result = LVILatticeVal::getNot(ConstantPointerNull::get(PTy));
662662 }
663663
727727
728728 ConstantRange LHSRange = LHSVal.getConstantRange();
729729 ConstantRange RHSRange(1);
730 const IntegerType *ResultTy = cast(BBI->getType());
730 IntegerType *ResultTy = cast(BBI->getType());
731731 if (isa(BBI)) {
732732 if (ConstantInt *RHS = dyn_cast(BBI->getOperand(1))) {
733733 RHSRange = ConstantRange(RHS->getValue());
7070 void visitCallSite(CallSite CS);
7171 void visitMemoryReference(Instruction &I, Value *Ptr,
7272 uint64_t Size, unsigned Align,
73 const Type *Ty, unsigned Flags);
73 Type *Ty, unsigned Flags);
7474
7575 void visitCallInst(CallInst &I);
7676 void visitInvokeInst(InvokeInst &I);
200200 "Undefined behavior: Caller and callee calling convention differ",
201201 &I);
202202
203 const FunctionType *FT = F->getFunctionType();
203 FunctionType *FT = F->getFunctionType();
204204 unsigned NumActualArgs = unsigned(CS.arg_end()-CS.arg_begin());
205205
206206 Assert1(FT->isVarArg() ?
239239
240240 // Check that an sret argument points to valid memory.
241241 if (Formal->hasStructRetAttr() && Actual->getType()->isPointerTy()) {
242 const Type *Ty =
242 Type *Ty =
243243 cast(Formal->getType())->getElementType();
244244 visitMemoryReference(I, Actual, AA->getTypeStoreSize(Ty),
245245 TD ? TD->getABITypeAlignment(Ty) : 0,
363363 // TODO: Check readnone/readonly function attributes.
364364 void Lint::visitMemoryReference(Instruction &I,
365365 Value *Ptr, uint64_t Size, unsigned Align,
366 const Type *Ty, unsigned Flags) {
366 Type *Ty, unsigned Flags) {
367367 // If no memory is being referenced, it doesn't matter if the pointer
368368 // is valid.
369369 if (Size == 0)
8989 if (TD)
9090 Base = getUnderlyingObjectWithOffset(V, TD, ByteOffset);
9191
92 const Type *BaseType = 0;
92 Type *BaseType = 0;
9393 unsigned BaseAlign = 0;
9494 if (const AllocaInst *AI = dyn_cast(Base)) {
9595 // An alloca is safe to load from as load as it is suitably aligned.
113113 return true; // Loading directly from an alloca or global is OK.
114114
115115 // Check if the load is within the bounds of the underlying object.
116 const PointerType *AddrTy = cast(V->getType());
116 PointerType *AddrTy = cast(V->getType());
117117 uint64_t LoadSize = TD->getTypeStoreSize(AddrTy->getElementType());
118118 if (ByteOffset + LoadSize <= TD->getTypeAllocSize(BaseType) &&
119119 (Align == 0 || (ByteOffset % Align) == 0))
168168 // If we're using alias analysis to disambiguate get the size of *Ptr.
169169 uint64_t AccessSize = 0;
170170 if (AA) {
171 const Type *AccessTy = cast(Ptr->getType())->getElementType();
171 Type *AccessTy = cast(Ptr->getType())->getElementType();
172172 AccessSize = AA->getTypeStoreSize(AccessTy);
173173 }
174174
4646 // Check malloc prototype.
4747 // FIXME: workaround for PR5130, this will be obsolete when a nobuiltin
4848 // attribute will exist.
49 const FunctionType *FTy = Callee->getFunctionType();
49 FunctionType *FTy = Callee->getFunctionType();
5050 if (FTy->getNumParams() != 1)
5151 return false;
5252 return FTy->getParamType(0)->isIntegerTy(32) ||
9393 return NULL;
9494
9595 // The size of the malloc's result type must be known to determine array size.
96 const Type *T = getMallocAllocatedType(CI);
96 Type *T = getMallocAllocatedType(CI);
9797 if (!T || !T->isSized() || !TD)
9898 return NULL;
9999
100100 unsigned ElementSize = TD->getTypeAllocSize(T);
101 if (const StructType *ST = dyn_cast(T))
101 if (StructType *ST = dyn_cast(T))
102102 ElementSize = TD->getStructLayout(ST)->getSizeInBytes();
103103
104104 // If malloc call's arg can be determined to be a multiple of ElementSize,
132132 /// 0: PointerType is the calls' return type.
133133 /// 1: PointerType is the bitcast's result type.
134134 /// >1: Unique PointerType cannot be determined, return NULL.
135 const PointerType *llvm::getMallocType(const CallInst *CI) {
135 PointerType *llvm::getMallocType(const CallInst *CI) {
136136 assert(isMalloc(CI) && "getMallocType and not malloc call");
137137
138 const PointerType *MallocType = NULL;
138 PointerType *MallocType = NULL;
139139 unsigned NumOfBitCastUses = 0;
140140
141141 // Determine if CallInst has a bitcast use.
163163 /// 0: PointerType is the malloc calls' return type.
164164 /// 1: PointerType is the bitcast's result type.
165165 /// >1: Unique PointerType cannot be determined, return NULL.
166 const Type *llvm::getMallocAllocatedType(const CallInst *CI) {
167 const PointerType *PT = getMallocType(CI);
166 Type *llvm::getMallocAllocatedType(const CallInst *CI) {
167 PointerType *PT = getMallocType(CI);
168168 return PT ? PT->getElementType() : NULL;
169169 }
170170
200200 // Check free prototype.
201201 // FIXME: workaround for PR5130, this will be obsolete when a nobuiltin
202202 // attribute will exist.
203 const FunctionType *FTy = Callee->getFunctionType();
203 FunctionType *FTy = Callee->getFunctionType();
204204 if (!FTy->getReturnType()->isVoidTy())
205205 return 0;
206206 if (FTy->getNumParams() != 1)
381381 // location is 1 byte at P+1). If so, return it as a load/load
382382 // clobber result, allowing the client to decide to widen the load if
383383 // it wants to.
384 if (const IntegerType *ITy = dyn_cast(LI->getType()))
384 if (IntegerType *ITy = dyn_cast(LI->getType()))
385385 if (LI->getAlignment()*8 > ITy->getPrimitiveSizeInBits() &&
386386 isLoadLoadClobberIfExtendedToFullWidth(MemLoc, MemLocBase,
387387 MemLocOffset, LI, TD))
196196 }
197197 case scUnknown: {
198198 const SCEVUnknown *U = cast(this);
199