diff options
author | Chris Lattner <sabre@nondot.org> | 2006-01-04 02:15:02 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2006-01-04 02:15:02 +0000 |
commit | d2a7ea45b0603aeeb4921ab3b7e39aa07ca3bd77 (patch) | |
tree | 19f8cc3746cdb83b5faa6d2487799f341d541327 /lib/VMCore | |
parent | d15ed597349e611553f0eb72b7187844c7630acc (diff) | |
download | external_llvm-d2a7ea45b0603aeeb4921ab3b7e39aa07ca3bd77.zip external_llvm-d2a7ea45b0603aeeb4921ab3b7e39aa07ca3bd77.tar.gz external_llvm-d2a7ea45b0603aeeb4921ab3b7e39aa07ca3bd77.tar.bz2 |
implement constant folding for the element-wise binary operations
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25073 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore')
-rw-r--r-- | lib/VMCore/ConstantFold.cpp | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/lib/VMCore/ConstantFold.cpp b/lib/VMCore/ConstantFold.cpp index 4cbe919..e6a2715 100644 --- a/lib/VMCore/ConstantFold.cpp +++ b/lib/VMCore/ConstantFold.cpp @@ -332,11 +332,61 @@ struct NullPointerRules : public TemplateRules<ConstantPointerNull, // ConstantPackedRules Class //===----------------------------------------------------------------------===// +/// DoVectorOp - Given two packed constants and a function pointer, apply the +/// function pointer to each element pair, producing a new ConstantPacked +/// constant. +static Constant *EvalVectorOp(const ConstantPacked *V1, + const ConstantPacked *V2, + Constant *(*FP)(Constant*, Constant*)) { + std::vector<Constant*> Res; + for (unsigned i = 0, e = V1->getNumOperands(); i != e; ++i) + Res.push_back(FP(const_cast<Constant*>(V1->getOperand(i)), + const_cast<Constant*>(V2->getOperand(i)))); + return ConstantPacked::get(Res); +} + /// PackedTypeRules provides a concrete base class of ConstRules for /// ConstantPacked operands. /// struct ConstantPackedRules : public TemplateRules<ConstantPacked, ConstantPackedRules> { + + static Constant *Add(const ConstantPacked *V1, const ConstantPacked *V2) { + return EvalVectorOp(V1, V2, ConstantExpr::getAdd); + } + static Constant *Sub(const ConstantPacked *V1, const ConstantPacked *V2) { + return EvalVectorOp(V1, V2, ConstantExpr::getSub); + } + static Constant *Mul(const ConstantPacked *V1, const ConstantPacked *V2) { + return EvalVectorOp(V1, V2, ConstantExpr::getMul); + } + static Constant *Div(const ConstantPacked *V1, const ConstantPacked *V2) { + return EvalVectorOp(V1, V2, ConstantExpr::getDiv); + } + static Constant *Rem(const ConstantPacked *V1, const ConstantPacked *V2) { + return EvalVectorOp(V1, V2, ConstantExpr::getRem); + } + static Constant *And(const ConstantPacked *V1, const ConstantPacked *V2) { + return EvalVectorOp(V1, V2, ConstantExpr::getAnd); + } + static Constant *Or (const ConstantPacked *V1, const ConstantPacked *V2) { + return EvalVectorOp(V1, V2, ConstantExpr::getOr); + } + static Constant *Xor(const ConstantPacked *V1, const ConstantPacked *V2) { + return EvalVectorOp(V1, V2, ConstantExpr::getXor); + } + static Constant *Shl(const ConstantPacked *V1, const ConstantPacked *V2) { + return EvalVectorOp(V1, V2, ConstantExpr::getShl); + } + static Constant *Shr(const ConstantPacked *V1, const ConstantPacked *V2) { + return EvalVectorOp(V1, V2, ConstantExpr::getShr); + } + static Constant *LessThan(const ConstantPacked *V1, const ConstantPacked *V2){ + return 0; + } + static Constant *EqualTo(const ConstantPacked *V1, const ConstantPacked *V2) { + return 0; + } }; |