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 | f0f40681964c5720f2b2efd981ac8c33ea430ec1 (patch) | |
| tree | 604d83986420f093447c5a04f499df86c4be844c /llvm/lib | |
| parent | 1171d95d884e6048a3e7fefb14c0366fad25af58 (diff) | |
| download | bcm5719-llvm-f0f40681964c5720f2b2efd981ac8c33ea430ec1.tar.gz bcm5719-llvm-f0f40681964c5720f2b2efd981ac8c33ea430ec1.zip | |
implement constant folding for the element-wise binary operations
llvm-svn: 25073
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/VMCore/ConstantFolding.cpp | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/llvm/lib/VMCore/ConstantFolding.cpp b/llvm/lib/VMCore/ConstantFolding.cpp index 4cbe919b839..e6a27155b44 100644 --- a/llvm/lib/VMCore/ConstantFolding.cpp +++ b/llvm/lib/VMCore/ConstantFolding.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; + } }; |

