From 65511ff69d06452b4c8ec14ac851e369ba49aaa2 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Thu, 5 Oct 2006 06:24:58 +0000 Subject: [PATCH] Add insertelement/extractelement helper ctors. llvm-svn: 30750 --- llvm/include/llvm/Instructions.h | 8 +++++ llvm/lib/VMCore/Instructions.cpp | 53 ++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/llvm/include/llvm/Instructions.h b/llvm/include/llvm/Instructions.h index 4983dfaa75e0..38a3dde62858 100644 --- a/llvm/include/llvm/Instructions.h +++ b/llvm/include/llvm/Instructions.h @@ -775,8 +775,12 @@ class ExtractElementInst : public Instruction { public: ExtractElementInst(Value *Vec, Value *Idx, const std::string &Name = "", Instruction *InsertBefore = 0); + ExtractElementInst(Value *Vec, unsigned Idx, const std::string &Name = "", + Instruction *InsertBefore = 0); ExtractElementInst(Value *Vec, Value *Idx, const std::string &Name, BasicBlock *InsertAtEnd); + ExtractElementInst(Value *Vec, unsigned Idx, const std::string &Name, + BasicBlock *InsertAtEnd); /// isValidOperands - Return true if an extractelement instruction can be /// formed with the specified operands. @@ -820,8 +824,12 @@ class InsertElementInst : public Instruction { public: InsertElementInst(Value *Vec, Value *NewElt, Value *Idx, const std::string &Name = "",Instruction *InsertBefore = 0); + InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx, + const std::string &Name = "",Instruction *InsertBefore = 0); InsertElementInst(Value *Vec, Value *NewElt, Value *Idx, const std::string &Name, BasicBlock *InsertAtEnd); + InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx, + const std::string &Name, BasicBlock *InsertAtEnd); /// isValidOperands - Return true if an insertelement instruction can be /// formed with the specified operands. diff --git a/llvm/lib/VMCore/Instructions.cpp b/llvm/lib/VMCore/Instructions.cpp index 8f3633a66b54..60fce0e49257 100644 --- a/llvm/lib/VMCore/Instructions.cpp +++ b/llvm/lib/VMCore/Instructions.cpp @@ -844,6 +844,19 @@ ExtractElementInst::ExtractElementInst(Value *Val, Value *Index, Ops[1].init(Index, this); } +ExtractElementInst::ExtractElementInst(Value *Val, unsigned IndexV, + const std::string &Name, + Instruction *InsertBef) + : Instruction(cast(Val->getType())->getElementType(), + ExtractElement, Ops, 2, Name, InsertBef) { + Constant *Index = ConstantUInt::get(Type::UIntTy, IndexV); + assert(isValidOperands(Val, Index) && + "Invalid extractelement instruction operands!"); + Ops[0].init(Val, this); + Ops[1].init(Index, this); +} + + ExtractElementInst::ExtractElementInst(Value *Val, Value *Index, const std::string &Name, BasicBlock *InsertAE) @@ -856,6 +869,20 @@ ExtractElementInst::ExtractElementInst(Value *Val, Value *Index, Ops[1].init(Index, this); } +ExtractElementInst::ExtractElementInst(Value *Val, unsigned IndexV, + const std::string &Name, + BasicBlock *InsertAE) + : Instruction(cast(Val->getType())->getElementType(), + ExtractElement, Ops, 2, Name, InsertAE) { + Constant *Index = ConstantUInt::get(Type::UIntTy, IndexV); + assert(isValidOperands(Val, Index) && + "Invalid extractelement instruction operands!"); + + Ops[0].init(Val, this); + Ops[1].init(Index, this); +} + + bool ExtractElementInst::isValidOperands(const Value *Val, const Value *Index) { if (!isa(Val->getType()) || Index->getType() != Type::UIntTy) return false; @@ -884,6 +911,19 @@ InsertElementInst::InsertElementInst(Value *Vec, Value *Elt, Value *Index, Ops[2].init(Index, this); } +InsertElementInst::InsertElementInst(Value *Vec, Value *Elt, unsigned IndexV, + const std::string &Name, + Instruction *InsertBef) + : Instruction(Vec->getType(), InsertElement, Ops, 3, Name, InsertBef) { + Constant *Index = ConstantUInt::get(Type::UIntTy, IndexV); + assert(isValidOperands(Vec, Elt, Index) && + "Invalid insertelement instruction operands!"); + Ops[0].init(Vec, this); + Ops[1].init(Elt, this); + Ops[2].init(Index, this); +} + + InsertElementInst::InsertElementInst(Value *Vec, Value *Elt, Value *Index, const std::string &Name, BasicBlock *InsertAE) @@ -896,6 +936,19 @@ InsertElementInst::InsertElementInst(Value *Vec, Value *Elt, Value *Index, Ops[2].init(Index, this); } +InsertElementInst::InsertElementInst(Value *Vec, Value *Elt, unsigned IndexV, + const std::string &Name, + BasicBlock *InsertAE) +: Instruction(Vec->getType(), InsertElement, Ops, 3, Name, InsertAE) { + Constant *Index = ConstantUInt::get(Type::UIntTy, IndexV); + assert(isValidOperands(Vec, Elt, Index) && + "Invalid insertelement instruction operands!"); + + Ops[0].init(Vec, this); + Ops[1].init(Elt, this); + Ops[2].init(Index, this); +} + bool InsertElementInst::isValidOperands(const Value *Vec, const Value *Elt, const Value *Index) { if (!isa(Vec->getType()))