X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=include%2Fllvm%2FSupport%2FTargetFolder.h;h=d2661ca9f3fc223cff8229cfec2674502f253bd0;hb=0eac0164c259fb4a9d824361029f175e3eeede5c;hp=14f2c9b244f873aa8e1b79aca063789f82bbef07;hpb=fe24bd3a89c44f9a16e3cbcf60c119dac88fad40;p=oota-llvm.git diff --git a/include/llvm/Support/TargetFolder.h b/include/llvm/Support/TargetFolder.h index 14f2c9b244f..d2661ca9f3f 100644 --- a/include/llvm/Support/TargetFolder.h +++ b/include/llvm/Support/TargetFolder.h @@ -9,8 +9,10 @@ // // This file defines the TargetFolder class, a helper for IRBuilder. // It provides IRBuilder with a set of methods for creating constants with -// target dependent folding. For general constant creation and folding, -// use ConstantExpr and the routines in llvm/Analysis/ConstantFolding.h. +// target dependent folding, in addition to the same target-independent +// folding that the ConstantFolder class provides. For general constant +// creation and folding, use ConstantExpr and the routines in +// llvm/Analysis/ConstantFolding.h. // //===----------------------------------------------------------------------===// @@ -23,75 +25,87 @@ namespace llvm { class TargetData; +class LLVMContext; /// TargetFolder - Create constants with target dependent folding. class TargetFolder { - const TargetData &TD; + const TargetData *TD; + LLVMContext &Context; /// Fold - Fold the constant using target specific information. Constant *Fold(Constant *C) const { if (ConstantExpr *CE = dyn_cast(C)) - if (Constant *CF = ConstantFoldConstantExpression(CE, &TD)) + if (Constant *CF = ConstantFoldConstantExpression(CE, &Context, TD)) return CF; return C; } public: - TargetFolder(const TargetData &TheTD) : TD(TheTD) {} + explicit TargetFolder(const TargetData *TheTD, LLVMContext &C) : + TD(TheTD), Context(C) {} //===--------------------------------------------------------------------===// // Binary Operators //===--------------------------------------------------------------------===// Constant *CreateAdd(Constant *LHS, Constant *RHS) const { - return Fold(ConstantExpr::getAdd(LHS, RHS)); + return Fold(Context.getConstantExprAdd(LHS, RHS)); + } + Constant *CreateFAdd(Constant *LHS, Constant *RHS) const { + return Fold(Context.getConstantExprFAdd(LHS, RHS)); } Constant *CreateSub(Constant *LHS, Constant *RHS) const { - return Fold(ConstantExpr::getSub(LHS, RHS)); + return Fold(Context.getConstantExprSub(LHS, RHS)); + } + Constant *CreateFSub(Constant *LHS, Constant *RHS) const { + return Fold(Context.getConstantExprFSub(LHS, RHS)); } Constant *CreateMul(Constant *LHS, Constant *RHS) const { - return Fold(ConstantExpr::getMul(LHS, RHS)); + return Fold(Context.getConstantExprMul(LHS, RHS)); + } + Constant *CreateFMul(Constant *LHS, Constant *RHS) const { + return Fold(Context.getConstantExprFMul(LHS, RHS)); } Constant *CreateUDiv(Constant *LHS, Constant *RHS) const { - return Fold(ConstantExpr::getUDiv(LHS, RHS)); + return Fold(Context.getConstantExprUDiv(LHS, RHS)); } Constant *CreateSDiv(Constant *LHS, Constant *RHS) const { - return Fold(ConstantExpr::getSDiv(LHS, RHS)); + return Fold(Context.getConstantExprSDiv(LHS, RHS)); } Constant *CreateFDiv(Constant *LHS, Constant *RHS) const { - return Fold(ConstantExpr::getFDiv(LHS, RHS)); + return Fold(Context.getConstantExprFDiv(LHS, RHS)); } Constant *CreateURem(Constant *LHS, Constant *RHS) const { - return Fold(ConstantExpr::getURem(LHS, RHS)); + return Fold(Context.getConstantExprURem(LHS, RHS)); } Constant *CreateSRem(Constant *LHS, Constant *RHS) const { - return Fold(ConstantExpr::getSRem(LHS, RHS)); + return Fold(Context.getConstantExprSRem(LHS, RHS)); } Constant *CreateFRem(Constant *LHS, Constant *RHS) const { - return Fold(ConstantExpr::getFRem(LHS, RHS)); + return Fold(Context.getConstantExprFRem(LHS, RHS)); } Constant *CreateShl(Constant *LHS, Constant *RHS) const { - return Fold(ConstantExpr::getShl(LHS, RHS)); + return Fold(Context.getConstantExprShl(LHS, RHS)); } Constant *CreateLShr(Constant *LHS, Constant *RHS) const { - return Fold(ConstantExpr::getLShr(LHS, RHS)); + return Fold(Context.getConstantExprLShr(LHS, RHS)); } Constant *CreateAShr(Constant *LHS, Constant *RHS) const { - return Fold(ConstantExpr::getAShr(LHS, RHS)); + return Fold(Context.getConstantExprAShr(LHS, RHS)); } Constant *CreateAnd(Constant *LHS, Constant *RHS) const { - return Fold(ConstantExpr::getAnd(LHS, RHS)); + return Fold(Context.getConstantExprAnd(LHS, RHS)); } Constant *CreateOr(Constant *LHS, Constant *RHS) const { - return Fold(ConstantExpr::getOr(LHS, RHS)); + return Fold(Context.getConstantExprOr(LHS, RHS)); } Constant *CreateXor(Constant *LHS, Constant *RHS) const { - return Fold(ConstantExpr::getXor(LHS, RHS)); + return Fold(Context.getConstantExprXor(LHS, RHS)); } Constant *CreateBinOp(Instruction::BinaryOps Opc, Constant *LHS, Constant *RHS) const { - return Fold(ConstantExpr::get(Opc, LHS, RHS)); + return Fold(Context.getConstantExpr(Opc, LHS, RHS)); } //===--------------------------------------------------------------------===// @@ -99,10 +113,13 @@ public: //===--------------------------------------------------------------------===// Constant *CreateNeg(Constant *C) const { - return Fold(ConstantExpr::getNeg(C)); + return Fold(Context.getConstantExprNeg(C)); + } + Constant *CreateFNeg(Constant *C) const { + return Fold(Context.getConstantExprFNeg(C)); } Constant *CreateNot(Constant *C) const { - return Fold(ConstantExpr::getNot(C)); + return Fold(Context.getConstantExprNot(C)); } //===--------------------------------------------------------------------===// @@ -111,11 +128,11 @@ public: Constant *CreateGetElementPtr(Constant *C, Constant* const *IdxList, unsigned NumIdx) const { - return Fold(ConstantExpr::getGetElementPtr(C, IdxList, NumIdx)); + return Fold(Context.getConstantExprGetElementPtr(C, IdxList, NumIdx)); } Constant *CreateGetElementPtr(Constant *C, Value* const *IdxList, unsigned NumIdx) const { - return Fold(ConstantExpr::getGetElementPtr(C, IdxList, NumIdx)); + return Fold(Context.getConstantExprGetElementPtr(C, IdxList, NumIdx)); } //===--------------------------------------------------------------------===// @@ -126,13 +143,13 @@ public: const Type *DestTy) const { if (C->getType() == DestTy) return C; // avoid calling Fold - return Fold(ConstantExpr::getCast(Op, C, DestTy)); + return Fold(Context.getConstantExprCast(Op, C, DestTy)); } Constant *CreateIntCast(Constant *C, const Type *DestTy, bool isSigned) const { if (C->getType() == DestTy) return C; // avoid calling Fold - return Fold(ConstantExpr::getIntegerCast(C, DestTy, isSigned)); + return Fold(Context.getConstantExprIntegerCast(C, DestTy, isSigned)); } Constant *CreateBitCast(Constant *C, const Type *DestTy) const { @@ -147,7 +164,7 @@ public: Constant *CreateTruncOrBitCast(Constant *C, const Type *DestTy) const { if (C->getType() == DestTy) return C; // avoid calling Fold - return Fold(ConstantExpr::getTruncOrBitCast(C, DestTy)); + return Fold(Context.getConstantExprTruncOrBitCast(C, DestTy)); } //===--------------------------------------------------------------------===// @@ -156,19 +173,11 @@ public: Constant *CreateICmp(CmpInst::Predicate P, Constant *LHS, Constant *RHS) const { - return Fold(ConstantExpr::getCompare(P, LHS, RHS)); + return Fold(Context.getConstantExprCompare(P, LHS, RHS)); } Constant *CreateFCmp(CmpInst::Predicate P, Constant *LHS, Constant *RHS) const { - return Fold(ConstantExpr::getCompare(P, LHS, RHS)); - } - Constant *CreateVICmp(CmpInst::Predicate P, Constant *LHS, - Constant *RHS) const { - return Fold(ConstantExpr::getCompare(P, LHS, RHS)); - } - Constant *CreateVFCmp(CmpInst::Predicate P, Constant *LHS, - Constant *RHS) const { - return Fold(ConstantExpr::getCompare(P, LHS, RHS)); + return Fold(Context.getConstantExprCompare(P, LHS, RHS)); } //===--------------------------------------------------------------------===// @@ -176,31 +185,31 @@ public: //===--------------------------------------------------------------------===// Constant *CreateSelect(Constant *C, Constant *True, Constant *False) const { - return Fold(ConstantExpr::getSelect(C, True, False)); + return Fold(Context.getConstantExprSelect(C, True, False)); } Constant *CreateExtractElement(Constant *Vec, Constant *Idx) const { - return Fold(ConstantExpr::getExtractElement(Vec, Idx)); + return Fold(Context.getConstantExprExtractElement(Vec, Idx)); } Constant *CreateInsertElement(Constant *Vec, Constant *NewElt, Constant *Idx) const { - return Fold(ConstantExpr::getInsertElement(Vec, NewElt, Idx)); + return Fold(Context.getConstantExprInsertElement(Vec, NewElt, Idx)); } Constant *CreateShuffleVector(Constant *V1, Constant *V2, Constant *Mask) const { - return Fold(ConstantExpr::getShuffleVector(V1, V2, Mask)); + return Fold(Context.getConstantExprShuffleVector(V1, V2, Mask)); } Constant *CreateExtractValue(Constant *Agg, const unsigned *IdxList, unsigned NumIdx) const { - return Fold(ConstantExpr::getExtractValue(Agg, IdxList, NumIdx)); + return Fold(Context.getConstantExprExtractValue(Agg, IdxList, NumIdx)); } Constant *CreateInsertValue(Constant *Agg, Constant *Val, const unsigned *IdxList, unsigned NumIdx) const { - return Fold(ConstantExpr::getInsertValue(Agg, Val, IdxList, NumIdx)); + return Fold(Context.getConstantExprInsertValue(Agg, Val, IdxList, NumIdx)); } };