X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=include%2Fllvm%2FSupport%2FTargetFolder.h;h=f2d83a4565d864ca753f11b2d3f50ba4a0b03e1d;hb=b09c146b116359616f6cbd4c8b3328607e00ff42;hp=1e49850f68791b33a5c842e657d608dba5e78487;hpb=e922c0201916e0b980ab3cfe91e1413e68d55647;p=oota-llvm.git diff --git a/include/llvm/Support/TargetFolder.h b/include/llvm/Support/TargetFolder.h index 1e49850f687..f2d83a4565d 100644 --- a/include/llvm/Support/TargetFolder.h +++ b/include/llvm/Support/TargetFolder.h @@ -19,120 +19,145 @@ #ifndef LLVM_SUPPORT_TARGETFOLDER_H #define LLVM_SUPPORT_TARGETFOLDER_H -#include "llvm/Constants.h" +#include "llvm/ADT/ArrayRef.h" #include "llvm/Analysis/ConstantFolding.h" +#include "llvm/Constants.h" +#include "llvm/InstrTypes.h" namespace llvm { -class TargetData; -class LLVMContext; +class DataLayout; /// TargetFolder - Create constants with target dependent folding. class TargetFolder { - const TargetData *TD; - LLVMContext &Context; + const DataLayout *TD; /// Fold - Fold the constant using target specific information. Constant *Fold(Constant *C) const { if (ConstantExpr *CE = dyn_cast(C)) - if (Constant *CF = ConstantFoldConstantExpression(CE, Context, TD)) + if (Constant *CF = ConstantFoldConstantExpression(CE, TD)) return CF; return C; } public: - explicit TargetFolder(const TargetData *TheTD, LLVMContext &C) : - TD(TheTD), Context(C) {} + explicit TargetFolder(const DataLayout *TheTD) : TD(TheTD) {} //===--------------------------------------------------------------------===// // Binary Operators //===--------------------------------------------------------------------===// - Constant *CreateAdd(Constant *LHS, Constant *RHS) const { - return Fold(Context.getConstantExprAdd(LHS, RHS)); + Constant *CreateAdd(Constant *LHS, Constant *RHS, + bool HasNUW = false, bool HasNSW = false) const { + return Fold(ConstantExpr::getAdd(LHS, RHS, HasNUW, HasNSW)); } Constant *CreateFAdd(Constant *LHS, Constant *RHS) const { - return Fold(Context.getConstantExprFAdd(LHS, RHS)); + return Fold(ConstantExpr::getFAdd(LHS, RHS)); } - Constant *CreateSub(Constant *LHS, Constant *RHS) const { - return Fold(Context.getConstantExprSub(LHS, RHS)); + Constant *CreateSub(Constant *LHS, Constant *RHS, + bool HasNUW = false, bool HasNSW = false) const { + return Fold(ConstantExpr::getSub(LHS, RHS, HasNUW, HasNSW)); } Constant *CreateFSub(Constant *LHS, Constant *RHS) const { - return Fold(Context.getConstantExprFSub(LHS, RHS)); + return Fold(ConstantExpr::getFSub(LHS, RHS)); } - Constant *CreateMul(Constant *LHS, Constant *RHS) const { - return Fold(Context.getConstantExprMul(LHS, RHS)); + Constant *CreateMul(Constant *LHS, Constant *RHS, + bool HasNUW = false, bool HasNSW = false) const { + return Fold(ConstantExpr::getMul(LHS, RHS, HasNUW, HasNSW)); } Constant *CreateFMul(Constant *LHS, Constant *RHS) const { - return Fold(Context.getConstantExprFMul(LHS, RHS)); + return Fold(ConstantExpr::getFMul(LHS, RHS)); } - Constant *CreateUDiv(Constant *LHS, Constant *RHS) const { - return Fold(Context.getConstantExprUDiv(LHS, RHS)); + Constant *CreateUDiv(Constant *LHS, Constant *RHS, bool isExact = false)const{ + return Fold(ConstantExpr::getUDiv(LHS, RHS, isExact)); } - Constant *CreateSDiv(Constant *LHS, Constant *RHS) const { - return Fold(Context.getConstantExprSDiv(LHS, RHS)); + Constant *CreateSDiv(Constant *LHS, Constant *RHS, bool isExact = false)const{ + return Fold(ConstantExpr::getSDiv(LHS, RHS, isExact)); } Constant *CreateFDiv(Constant *LHS, Constant *RHS) const { - return Fold(Context.getConstantExprFDiv(LHS, RHS)); + return Fold(ConstantExpr::getFDiv(LHS, RHS)); } Constant *CreateURem(Constant *LHS, Constant *RHS) const { - return Fold(Context.getConstantExprURem(LHS, RHS)); + return Fold(ConstantExpr::getURem(LHS, RHS)); } Constant *CreateSRem(Constant *LHS, Constant *RHS) const { - return Fold(Context.getConstantExprSRem(LHS, RHS)); + return Fold(ConstantExpr::getSRem(LHS, RHS)); } Constant *CreateFRem(Constant *LHS, Constant *RHS) const { - return Fold(Context.getConstantExprFRem(LHS, RHS)); + return Fold(ConstantExpr::getFRem(LHS, RHS)); } - Constant *CreateShl(Constant *LHS, Constant *RHS) const { - return Fold(Context.getConstantExprShl(LHS, RHS)); + Constant *CreateShl(Constant *LHS, Constant *RHS, + bool HasNUW = false, bool HasNSW = false) const { + return Fold(ConstantExpr::getShl(LHS, RHS, HasNUW, HasNSW)); } - Constant *CreateLShr(Constant *LHS, Constant *RHS) const { - return Fold(Context.getConstantExprLShr(LHS, RHS)); + Constant *CreateLShr(Constant *LHS, Constant *RHS, bool isExact = false)const{ + return Fold(ConstantExpr::getLShr(LHS, RHS, isExact)); } - Constant *CreateAShr(Constant *LHS, Constant *RHS) const { - return Fold(Context.getConstantExprAShr(LHS, RHS)); + Constant *CreateAShr(Constant *LHS, Constant *RHS, bool isExact = false)const{ + return Fold(ConstantExpr::getAShr(LHS, RHS, isExact)); } Constant *CreateAnd(Constant *LHS, Constant *RHS) const { - return Fold(Context.getConstantExprAnd(LHS, RHS)); + return Fold(ConstantExpr::getAnd(LHS, RHS)); } Constant *CreateOr(Constant *LHS, Constant *RHS) const { - return Fold(Context.getConstantExprOr(LHS, RHS)); + return Fold(ConstantExpr::getOr(LHS, RHS)); } Constant *CreateXor(Constant *LHS, Constant *RHS) const { - return Fold(Context.getConstantExprXor(LHS, RHS)); + return Fold(ConstantExpr::getXor(LHS, RHS)); } Constant *CreateBinOp(Instruction::BinaryOps Opc, Constant *LHS, Constant *RHS) const { - return Fold(Context.getConstantExpr(Opc, LHS, RHS)); + return Fold(ConstantExpr::get(Opc, LHS, RHS)); } //===--------------------------------------------------------------------===// // Unary Operators //===--------------------------------------------------------------------===// - Constant *CreateNeg(Constant *C) const { - return Fold(Context.getConstantExprNeg(C)); + Constant *CreateNeg(Constant *C, + bool HasNUW = false, bool HasNSW = false) const { + return Fold(ConstantExpr::getNeg(C, HasNUW, HasNSW)); } Constant *CreateFNeg(Constant *C) const { - return Fold(Context.getConstantExprFNeg(C)); + return Fold(ConstantExpr::getFNeg(C)); } Constant *CreateNot(Constant *C) const { - return Fold(Context.getConstantExprNot(C)); + return Fold(ConstantExpr::getNot(C)); } //===--------------------------------------------------------------------===// // Memory Instructions //===--------------------------------------------------------------------===// - Constant *CreateGetElementPtr(Constant *C, Constant* const *IdxList, - unsigned NumIdx) const { - return Fold(Context.getConstantExprGetElementPtr(C, IdxList, NumIdx)); + Constant *CreateGetElementPtr(Constant *C, + ArrayRef IdxList) const { + return Fold(ConstantExpr::getGetElementPtr(C, IdxList)); + } + Constant *CreateGetElementPtr(Constant *C, Constant *Idx) const { + // This form of the function only exists to avoid ambiguous overload + // warnings about whether to convert Idx to ArrayRef or + // ArrayRef. + return Fold(ConstantExpr::getGetElementPtr(C, Idx)); + } + Constant *CreateGetElementPtr(Constant *C, + ArrayRef IdxList) const { + return Fold(ConstantExpr::getGetElementPtr(C, IdxList)); + } + + Constant *CreateInBoundsGetElementPtr(Constant *C, + ArrayRef IdxList) const { + return Fold(ConstantExpr::getInBoundsGetElementPtr(C, IdxList)); + } + Constant *CreateInBoundsGetElementPtr(Constant *C, Constant *Idx) const { + // This form of the function only exists to avoid ambiguous overload + // warnings about whether to convert Idx to ArrayRef or + // ArrayRef. + return Fold(ConstantExpr::getInBoundsGetElementPtr(C, Idx)); } - Constant *CreateGetElementPtr(Constant *C, Value* const *IdxList, - unsigned NumIdx) const { - return Fold(Context.getConstantExprGetElementPtr(C, IdxList, NumIdx)); + Constant *CreateInBoundsGetElementPtr(Constant *C, + ArrayRef IdxList) const { + return Fold(ConstantExpr::getInBoundsGetElementPtr(C, IdxList)); } //===--------------------------------------------------------------------===// @@ -140,31 +165,50 @@ public: //===--------------------------------------------------------------------===// Constant *CreateCast(Instruction::CastOps Op, Constant *C, - const Type *DestTy) const { + Type *DestTy) const { if (C->getType() == DestTy) return C; // avoid calling Fold - return Fold(Context.getConstantExprCast(Op, C, DestTy)); + return Fold(ConstantExpr::getCast(Op, C, DestTy)); } - Constant *CreateIntCast(Constant *C, const Type *DestTy, + Constant *CreateIntCast(Constant *C, Type *DestTy, bool isSigned) const { if (C->getType() == DestTy) return C; // avoid calling Fold - return Fold(Context.getConstantExprIntegerCast(C, DestTy, isSigned)); + return Fold(ConstantExpr::getIntegerCast(C, DestTy, isSigned)); } - - Constant *CreateBitCast(Constant *C, const Type *DestTy) const { + Constant *CreatePointerCast(Constant *C, Type *DestTy) const { + if (C->getType() == DestTy) + return C; // avoid calling Fold + return Fold(ConstantExpr::getPointerCast(C, DestTy)); + } + Constant *CreateFPCast(Constant *C, Type *DestTy) const { + if (C->getType() == DestTy) + return C; // avoid calling Fold + return Fold(ConstantExpr::getFPCast(C, DestTy)); + } + Constant *CreateBitCast(Constant *C, Type *DestTy) const { return CreateCast(Instruction::BitCast, C, DestTy); } - Constant *CreateIntToPtr(Constant *C, const Type *DestTy) const { + Constant *CreateIntToPtr(Constant *C, Type *DestTy) const { return CreateCast(Instruction::IntToPtr, C, DestTy); } - Constant *CreatePtrToInt(Constant *C, const Type *DestTy) const { + Constant *CreatePtrToInt(Constant *C, Type *DestTy) const { return CreateCast(Instruction::PtrToInt, C, DestTy); } - Constant *CreateTruncOrBitCast(Constant *C, const Type *DestTy) const { + Constant *CreateZExtOrBitCast(Constant *C, Type *DestTy) const { + if (C->getType() == DestTy) + return C; // avoid calling Fold + return Fold(ConstantExpr::getZExtOrBitCast(C, DestTy)); + } + Constant *CreateSExtOrBitCast(Constant *C, Type *DestTy) const { + if (C->getType() == DestTy) + return C; // avoid calling Fold + return Fold(ConstantExpr::getSExtOrBitCast(C, DestTy)); + } + Constant *CreateTruncOrBitCast(Constant *C, Type *DestTy) const { if (C->getType() == DestTy) return C; // avoid calling Fold - return Fold(Context.getConstantExprTruncOrBitCast(C, DestTy)); + return Fold(ConstantExpr::getTruncOrBitCast(C, DestTy)); } //===--------------------------------------------------------------------===// @@ -173,11 +217,11 @@ public: Constant *CreateICmp(CmpInst::Predicate P, Constant *LHS, Constant *RHS) const { - return Fold(Context.getConstantExprCompare(P, LHS, RHS)); + return Fold(ConstantExpr::getCompare(P, LHS, RHS)); } Constant *CreateFCmp(CmpInst::Predicate P, Constant *LHS, Constant *RHS) const { - return Fold(Context.getConstantExprCompare(P, LHS, RHS)); + return Fold(ConstantExpr::getCompare(P, LHS, RHS)); } //===--------------------------------------------------------------------===// @@ -185,31 +229,31 @@ public: //===--------------------------------------------------------------------===// Constant *CreateSelect(Constant *C, Constant *True, Constant *False) const { - return Fold(Context.getConstantExprSelect(C, True, False)); + return Fold(ConstantExpr::getSelect(C, True, False)); } Constant *CreateExtractElement(Constant *Vec, Constant *Idx) const { - return Fold(Context.getConstantExprExtractElement(Vec, Idx)); + return Fold(ConstantExpr::getExtractElement(Vec, Idx)); } Constant *CreateInsertElement(Constant *Vec, Constant *NewElt, Constant *Idx) const { - return Fold(Context.getConstantExprInsertElement(Vec, NewElt, Idx)); + return Fold(ConstantExpr::getInsertElement(Vec, NewElt, Idx)); } Constant *CreateShuffleVector(Constant *V1, Constant *V2, Constant *Mask) const { - return Fold(Context.getConstantExprShuffleVector(V1, V2, Mask)); + return Fold(ConstantExpr::getShuffleVector(V1, V2, Mask)); } - Constant *CreateExtractValue(Constant *Agg, const unsigned *IdxList, - unsigned NumIdx) const { - return Fold(Context.getConstantExprExtractValue(Agg, IdxList, NumIdx)); + Constant *CreateExtractValue(Constant *Agg, + ArrayRef IdxList) const { + return Fold(ConstantExpr::getExtractValue(Agg, IdxList)); } Constant *CreateInsertValue(Constant *Agg, Constant *Val, - const unsigned *IdxList, unsigned NumIdx) const { - return Fold(Context.getConstantExprInsertValue(Agg, Val, IdxList, NumIdx)); + ArrayRef IdxList) const { + return Fold(ConstantExpr::getInsertValue(Agg, Val, IdxList)); } };