1 //===---- llvm/Support/IRBuilder.h - Builder for LLVM Instrs ----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the IRBuilder class, which is used as a convenient way
11 // to create LLVM instructions with a consistent and simplified interface.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_SUPPORT_IRBUILDER_H
16 #define LLVM_SUPPORT_IRBUILDER_H
18 #include "llvm/BasicBlock.h"
19 #include "llvm/Instructions.h"
20 #include "llvm/Constants.h"
24 /// IRBuilder - This provides a uniform API for creating instructions and
25 /// inserting them into a basic block: either at the end of a BasicBlock, or
26 /// at a specific iterator location in a block.
28 /// Note that the builder does not expose the full generality of LLVM
29 /// instructions. For example, it cannot be used to create instructions with
30 /// arbitrary names (specifically, names with nul characters in them) - It only
31 /// supports nul-terminated C strings. For fully generic names, use
32 /// I->setName(). For access to extra instruction properties, use the mutators
33 /// (e.g. setVolatile) on the instructions after they have been created.
36 BasicBlock::iterator InsertPt;
38 IRBuilder() { ClearInsertionPoint(); }
39 explicit IRBuilder(BasicBlock *TheBB) { SetInsertPoint(TheBB); }
40 IRBuilder(BasicBlock *TheBB, BasicBlock::iterator IP) {
41 SetInsertPoint(TheBB, IP);
44 //===--------------------------------------------------------------------===//
45 // Builder configuration methods
46 //===--------------------------------------------------------------------===//
48 /// ClearInsertionPoint - Clear the insertion point: created instructions will
49 /// not be inserted into a block.
50 void ClearInsertionPoint() {
54 BasicBlock *GetInsertBlock() const { return BB; }
56 /// SetInsertPoint - This specifies that created instructions should be
57 /// appended to the end of the specified block.
58 void SetInsertPoint(BasicBlock *TheBB) {
63 /// SetInsertPoint - This specifies that created instructions should be
64 /// inserted at the specified point.
65 void SetInsertPoint(BasicBlock *TheBB, BasicBlock::iterator IP) {
70 /// Insert - Insert and return the specified instruction.
71 template<typename InstTy>
72 InstTy *Insert(InstTy *I) const {
77 /// InsertHelper - Insert the specified instruction at the specified insertion
78 /// point. This is split out of Insert so that it isn't duplicated for every
79 /// template instantiation.
80 void InsertHelper(Instruction *I) const {
81 if (BB) BB->getInstList().insert(InsertPt, I);
84 //===--------------------------------------------------------------------===//
85 // Instruction creation methods: Terminators
86 //===--------------------------------------------------------------------===//
88 /// CreateRetVoid - Create a 'ret void' instruction.
89 ReturnInst *CreateRetVoid() {
90 return Insert(ReturnInst::Create());
94 /// CreateRet - Create a 'ret <val>' instruction.
96 ReturnInst *CreateRet(Value *V) {
97 return Insert(ReturnInst::Create(V));
100 ReturnInst *CreateRet(Value * const* retVals, unsigned N) {
101 return Insert(ReturnInst::Create(retVals, N));
104 GetResultInst *CreateGetResult(Value *V, unsigned Index,
105 const char *Name = "") {
106 return Insert(new GetResultInst(V, Index, Name));
109 /// CreateBr - Create an unconditional 'br label X' instruction.
110 BranchInst *CreateBr(BasicBlock *Dest) {
111 return Insert(BranchInst::Create(Dest));
114 /// CreateCondBr - Create a conditional 'br Cond, TrueDest, FalseDest'
116 BranchInst *CreateCondBr(Value *Cond, BasicBlock *True, BasicBlock *False) {
117 return Insert(BranchInst::Create(True, False, Cond));
120 /// CreateSwitch - Create a switch instruction with the specified value,
121 /// default dest, and with a hint for the number of cases that will be added
122 /// (for efficient allocation).
123 SwitchInst *CreateSwitch(Value *V, BasicBlock *Dest, unsigned NumCases = 10) {
124 return Insert(SwitchInst::Create(V, Dest, NumCases));
127 /// CreateInvoke - Create an invoke instruction.
128 template<typename InputIterator>
129 InvokeInst *CreateInvoke(Value *Callee, BasicBlock *NormalDest,
130 BasicBlock *UnwindDest, InputIterator ArgBegin,
131 InputIterator ArgEnd, const char *Name = "") {
132 return Insert(InvokeInst::Create(Callee, NormalDest, UnwindDest,
133 ArgBegin, ArgEnd, Name));
136 UnwindInst *CreateUnwind() {
137 return Insert(new UnwindInst());
140 UnreachableInst *CreateUnreachable() {
141 return Insert(new UnreachableInst());
144 //===--------------------------------------------------------------------===//
145 // Instruction creation methods: Binary Operators
146 //===--------------------------------------------------------------------===//
148 Value *CreateAdd(Value *LHS, Value *RHS, const char *Name = "") {
149 if (Constant *LC = dyn_cast<Constant>(LHS))
150 if (Constant *RC = dyn_cast<Constant>(RHS))
151 return ConstantExpr::getAdd(LC, RC);
152 return Insert(BinaryOperator::createAdd(LHS, RHS, Name));
154 Value *CreateSub(Value *LHS, Value *RHS, const char *Name = "") {
155 if (Constant *LC = dyn_cast<Constant>(LHS))
156 if (Constant *RC = dyn_cast<Constant>(RHS))
157 return ConstantExpr::getSub(LC, RC);
158 return Insert(BinaryOperator::createSub(LHS, RHS, Name));
160 Value *CreateMul(Value *LHS, Value *RHS, const char *Name = "") {
161 if (Constant *LC = dyn_cast<Constant>(LHS))
162 if (Constant *RC = dyn_cast<Constant>(RHS))
163 return ConstantExpr::getMul(LC, RC);
164 return Insert(BinaryOperator::createMul(LHS, RHS, Name));
166 Value *CreateUDiv(Value *LHS, Value *RHS, const char *Name = "") {
167 if (Constant *LC = dyn_cast<Constant>(LHS))
168 if (Constant *RC = dyn_cast<Constant>(RHS))
169 return ConstantExpr::getUDiv(LC, RC);
170 return Insert(BinaryOperator::createUDiv(LHS, RHS, Name));
172 Value *CreateSDiv(Value *LHS, Value *RHS, const char *Name = "") {
173 if (Constant *LC = dyn_cast<Constant>(LHS))
174 if (Constant *RC = dyn_cast<Constant>(RHS))
175 return ConstantExpr::getSDiv(LC, RC);
176 return Insert(BinaryOperator::createSDiv(LHS, RHS, Name));
178 Value *CreateFDiv(Value *LHS, Value *RHS, const char *Name = "") {
179 if (Constant *LC = dyn_cast<Constant>(LHS))
180 if (Constant *RC = dyn_cast<Constant>(RHS))
181 return ConstantExpr::getFDiv(LC, RC);
182 return Insert(BinaryOperator::createFDiv(LHS, RHS, Name));
184 Value *CreateURem(Value *LHS, Value *RHS, const char *Name = "") {
185 if (Constant *LC = dyn_cast<Constant>(LHS))
186 if (Constant *RC = dyn_cast<Constant>(RHS))
187 return ConstantExpr::getURem(LC, RC);
188 return Insert(BinaryOperator::createURem(LHS, RHS, Name));
190 Value *CreateSRem(Value *LHS, Value *RHS, const char *Name = "") {
191 if (Constant *LC = dyn_cast<Constant>(LHS))
192 if (Constant *RC = dyn_cast<Constant>(RHS))
193 return ConstantExpr::getSRem(LC, RC);
194 return Insert(BinaryOperator::createSRem(LHS, RHS, Name));
196 Value *CreateFRem(Value *LHS, Value *RHS, const char *Name = "") {
197 if (Constant *LC = dyn_cast<Constant>(LHS))
198 if (Constant *RC = dyn_cast<Constant>(RHS))
199 return ConstantExpr::getFRem(LC, RC);
200 return Insert(BinaryOperator::createFRem(LHS, RHS, Name));
202 Value *CreateShl(Value *LHS, Value *RHS, const char *Name = "") {
203 if (Constant *LC = dyn_cast<Constant>(LHS))
204 if (Constant *RC = dyn_cast<Constant>(RHS))
205 return ConstantExpr::getShl(LC, RC);
206 return Insert(BinaryOperator::createShl(LHS, RHS, Name));
208 Value *CreateLShr(Value *LHS, Value *RHS, const char *Name = "") {
209 if (Constant *LC = dyn_cast<Constant>(LHS))
210 if (Constant *RC = dyn_cast<Constant>(RHS))
211 return ConstantExpr::getLShr(LC, RC);
212 return Insert(BinaryOperator::createLShr(LHS, RHS, Name));
214 Value *CreateAShr(Value *LHS, Value *RHS, const char *Name = "") {
215 if (Constant *LC = dyn_cast<Constant>(LHS))
216 if (Constant *RC = dyn_cast<Constant>(RHS))
217 return ConstantExpr::getAShr(LC, RC);
218 return Insert(BinaryOperator::createAShr(LHS, RHS, Name));
220 Value *CreateAnd(Value *LHS, Value *RHS, const char *Name = "") {
221 if (Constant *LC = dyn_cast<Constant>(LHS))
222 if (Constant *RC = dyn_cast<Constant>(RHS))
223 return ConstantExpr::getAnd(LC, RC);
224 return Insert(BinaryOperator::createAnd(LHS, RHS, Name));
226 Value *CreateOr(Value *LHS, Value *RHS, const char *Name = "") {
227 if (Constant *LC = dyn_cast<Constant>(LHS))
228 if (Constant *RC = dyn_cast<Constant>(RHS))
229 return ConstantExpr::getOr(LC, RC);
230 return Insert(BinaryOperator::createOr(LHS, RHS, Name));
232 Value *CreateXor(Value *LHS, Value *RHS, const char *Name = "") {
233 if (Constant *LC = dyn_cast<Constant>(LHS))
234 if (Constant *RC = dyn_cast<Constant>(RHS))
235 return ConstantExpr::getXor(LC, RC);
236 return Insert(BinaryOperator::createXor(LHS, RHS, Name));
239 BinaryOperator *CreateBinOp(Instruction::BinaryOps Opc,
240 Value *LHS, Value *RHS, const char *Name = "") {
241 return Insert(BinaryOperator::create(Opc, LHS, RHS, Name));
244 BinaryOperator *CreateNeg(Value *V, const char *Name = "") {
245 return Insert(BinaryOperator::createNeg(V, Name));
247 BinaryOperator *CreateNot(Value *V, const char *Name = "") {
248 return Insert(BinaryOperator::createNot(V, Name));
251 //===--------------------------------------------------------------------===//
252 // Instruction creation methods: Memory Instructions
253 //===--------------------------------------------------------------------===//
255 MallocInst *CreateMalloc(const Type *Ty, Value *ArraySize = 0,
256 const char *Name = "") {
257 return Insert(new MallocInst(Ty, ArraySize, Name));
259 AllocaInst *CreateAlloca(const Type *Ty, Value *ArraySize = 0,
260 const char *Name = "") {
261 return Insert(new AllocaInst(Ty, ArraySize, Name));
263 FreeInst *CreateFree(Value *Ptr) {
264 return Insert(new FreeInst(Ptr));
266 LoadInst *CreateLoad(Value *Ptr, const char *Name = 0) {
267 return Insert(new LoadInst(Ptr, Name));
269 LoadInst *CreateLoad(Value *Ptr, bool isVolatile, const char *Name = 0) {
270 return Insert(new LoadInst(Ptr, Name, isVolatile));
272 StoreInst *CreateStore(Value *Val, Value *Ptr, bool isVolatile = false) {
273 return Insert(new StoreInst(Val, Ptr, isVolatile));
275 template<typename InputIterator>
276 Value *CreateGEP(Value *Ptr, InputIterator IdxBegin,
277 InputIterator IdxEnd, const char *Name = "") {
279 if (Constant *PC = dyn_cast<Constant>(Ptr)) {
280 // Every index must be constant.
282 for (i = IdxBegin; i < IdxEnd; ++i) {
283 if (!dyn_cast<Constant>(*i))
287 return ConstantExpr::getGetElementPtr(PC, &IdxBegin[0], IdxEnd - IdxBegin);
289 return(Insert(GetElementPtrInst::Create(Ptr, IdxBegin, IdxEnd, Name)));
291 Value *CreateGEP(Value *Ptr, Value *Idx, const char *Name = "") {
292 if (Constant *PC = dyn_cast<Constant>(Ptr))
293 if (Constant *IC = dyn_cast<Constant>(Idx))
294 return ConstantExpr::getGetElementPtr(PC, &IC, 1);
295 return Insert(GetElementPtrInst::Create(Ptr, Idx, Name));
297 Value *CreateStructGEP(Value *Ptr, unsigned Idx, const char *Name = "") {
298 llvm::Value *Idxs[] = {
299 ConstantInt::get(llvm::Type::Int32Ty, 0),
300 ConstantInt::get(llvm::Type::Int32Ty, Idx)
303 if (Constant *PC = dyn_cast<Constant>(Ptr))
304 return ConstantExpr::getGetElementPtr(PC, Idxs, 2);
306 return Insert(GetElementPtrInst::Create(Ptr, Idxs, Idxs+2, Name));
309 //===--------------------------------------------------------------------===//
310 // Instruction creation methods: Cast/Conversion Operators
311 //===--------------------------------------------------------------------===//
313 Value *CreateTrunc(Value *V, const Type *DestTy, const char *Name = "") {
314 return CreateCast(Instruction::Trunc, V, DestTy, Name);
316 Value *CreateZExt(Value *V, const Type *DestTy, const char *Name = "") {
317 return CreateCast(Instruction::ZExt, V, DestTy, Name);
319 Value *CreateSExt(Value *V, const Type *DestTy, const char *Name = "") {
320 return CreateCast(Instruction::SExt, V, DestTy, Name);
322 Value *CreateFPToUI(Value *V, const Type *DestTy, const char *Name = ""){
323 return CreateCast(Instruction::FPToUI, V, DestTy, Name);
325 Value *CreateFPToSI(Value *V, const Type *DestTy, const char *Name = ""){
326 return CreateCast(Instruction::FPToSI, V, DestTy, Name);
328 Value *CreateUIToFP(Value *V, const Type *DestTy, const char *Name = ""){
329 return CreateCast(Instruction::UIToFP, V, DestTy, Name);
331 Value *CreateSIToFP(Value *V, const Type *DestTy, const char *Name = ""){
332 return CreateCast(Instruction::SIToFP, V, DestTy, Name);
334 Value *CreateFPTrunc(Value *V, const Type *DestTy,
335 const char *Name = "") {
336 return CreateCast(Instruction::FPTrunc, V, DestTy, Name);
338 Value *CreateFPExt(Value *V, const Type *DestTy, const char *Name = "") {
339 return CreateCast(Instruction::FPExt, V, DestTy, Name);
341 Value *CreatePtrToInt(Value *V, const Type *DestTy,
342 const char *Name = "") {
343 return CreateCast(Instruction::PtrToInt, V, DestTy, Name);
345 Value *CreateIntToPtr(Value *V, const Type *DestTy,
346 const char *Name = "") {
347 return CreateCast(Instruction::IntToPtr, V, DestTy, Name);
349 Value *CreateBitCast(Value *V, const Type *DestTy,
350 const char *Name = "") {
351 return CreateCast(Instruction::BitCast, V, DestTy, Name);
354 Value *CreateCast(Instruction::CastOps Op, Value *V, const Type *DestTy,
355 const char *Name = "") {
356 if (V->getType() == DestTy)
358 if (Constant *VC = dyn_cast<Constant>(V))
359 return ConstantExpr::getCast(Op, VC, DestTy);
360 return Insert(CastInst::create(Op, V, DestTy, Name));
362 Value *CreateIntCast(Value *V, const Type *DestTy, bool isSigned,
363 const char *Name = "") {
364 if (V->getType() == DestTy)
366 if (Constant *VC = dyn_cast<Constant>(V))
367 return ConstantExpr::getIntegerCast(VC, DestTy, isSigned);
368 return Insert(CastInst::createIntegerCast(V, DestTy, isSigned, Name));
371 //===--------------------------------------------------------------------===//
372 // Instruction creation methods: Compare Instructions
373 //===--------------------------------------------------------------------===//
375 Value *CreateICmpEQ(Value *LHS, Value *RHS, const char *Name = "") {
376 return CreateICmp(ICmpInst::ICMP_EQ, LHS, RHS, Name);
378 Value *CreateICmpNE(Value *LHS, Value *RHS, const char *Name = "") {
379 return CreateICmp(ICmpInst::ICMP_NE, LHS, RHS, Name);
381 Value *CreateICmpUGT(Value *LHS, Value *RHS, const char *Name = "") {
382 return CreateICmp(ICmpInst::ICMP_UGT, LHS, RHS, Name);
384 Value *CreateICmpUGE(Value *LHS, Value *RHS, const char *Name = "") {
385 return CreateICmp(ICmpInst::ICMP_UGE, LHS, RHS, Name);
387 Value *CreateICmpULT(Value *LHS, Value *RHS, const char *Name = "") {
388 return CreateICmp(ICmpInst::ICMP_ULT, LHS, RHS, Name);
390 Value *CreateICmpULE(Value *LHS, Value *RHS, const char *Name = "") {
391 return CreateICmp(ICmpInst::ICMP_ULE, LHS, RHS, Name);
393 Value *CreateICmpSGT(Value *LHS, Value *RHS, const char *Name = "") {
394 return CreateICmp(ICmpInst::ICMP_SGT, LHS, RHS, Name);
396 Value *CreateICmpSGE(Value *LHS, Value *RHS, const char *Name = "") {
397 return CreateICmp(ICmpInst::ICMP_SGE, LHS, RHS, Name);
399 Value *CreateICmpSLT(Value *LHS, Value *RHS, const char *Name = "") {
400 return CreateICmp(ICmpInst::ICMP_SLT, LHS, RHS, Name);
402 Value *CreateICmpSLE(Value *LHS, Value *RHS, const char *Name = "") {
403 return CreateICmp(ICmpInst::ICMP_SLE, LHS, RHS, Name);
406 Value *CreateFCmpOEQ(Value *LHS, Value *RHS, const char *Name = "") {
407 return CreateFCmp(FCmpInst::FCMP_OEQ, LHS, RHS, Name);
409 Value *CreateFCmpOGT(Value *LHS, Value *RHS, const char *Name = "") {
410 return CreateFCmp(FCmpInst::FCMP_OGT, LHS, RHS, Name);
412 Value *CreateFCmpOGE(Value *LHS, Value *RHS, const char *Name = "") {
413 return CreateFCmp(FCmpInst::FCMP_OGE, LHS, RHS, Name);
415 Value *CreateFCmpOLT(Value *LHS, Value *RHS, const char *Name = "") {
416 return CreateFCmp(FCmpInst::FCMP_OLT, LHS, RHS, Name);
418 Value *CreateFCmpOLE(Value *LHS, Value *RHS, const char *Name = "") {
419 return CreateFCmp(FCmpInst::FCMP_OLE, LHS, RHS, Name);
421 Value *CreateFCmpONE(Value *LHS, Value *RHS, const char *Name = "") {
422 return CreateFCmp(FCmpInst::FCMP_ONE, LHS, RHS, Name);
424 Value *CreateFCmpORD(Value *LHS, Value *RHS, const char *Name = "") {
425 return CreateFCmp(FCmpInst::FCMP_ORD, LHS, RHS, Name);
427 Value *CreateFCmpUNO(Value *LHS, Value *RHS, const char *Name = "") {
428 return CreateFCmp(FCmpInst::FCMP_UNO, LHS, RHS, Name);
430 Value *CreateFCmpUEQ(Value *LHS, Value *RHS, const char *Name = "") {
431 return CreateFCmp(FCmpInst::FCMP_UEQ, LHS, RHS, Name);
433 Value *CreateFCmpUGT(Value *LHS, Value *RHS, const char *Name = "") {
434 return CreateFCmp(FCmpInst::FCMP_UGT, LHS, RHS, Name);
436 Value *CreateFCmpUGE(Value *LHS, Value *RHS, const char *Name = "") {
437 return CreateFCmp(FCmpInst::FCMP_UGE, LHS, RHS, Name);
439 Value *CreateFCmpULT(Value *LHS, Value *RHS, const char *Name = "") {
440 return CreateFCmp(FCmpInst::FCMP_ULT, LHS, RHS, Name);
442 Value *CreateFCmpULE(Value *LHS, Value *RHS, const char *Name = "") {
443 return CreateFCmp(FCmpInst::FCMP_ULE, LHS, RHS, Name);
445 Value *CreateFCmpUNE(Value *LHS, Value *RHS, const char *Name = "") {
446 return CreateFCmp(FCmpInst::FCMP_UNE, LHS, RHS, Name);
449 Value *CreateICmp(CmpInst::Predicate P, Value *LHS, Value *RHS,
450 const char *Name = "") {
451 if (Constant *LC = dyn_cast<Constant>(LHS))
452 if (Constant *RC = dyn_cast<Constant>(RHS))
453 return ConstantExpr::getCompare(P, LC, RC);
454 return Insert(new ICmpInst(P, LHS, RHS, Name));
456 Value *CreateFCmp(CmpInst::Predicate P, Value *LHS, Value *RHS,
457 const char *Name = "") {
458 if (Constant *LC = dyn_cast<Constant>(LHS))
459 if (Constant *RC = dyn_cast<Constant>(RHS))
460 return ConstantExpr::getCompare(P, LC, RC);
461 return Insert(new FCmpInst(P, LHS, RHS, Name));
464 Value *CreateVICmp(CmpInst::Predicate P, Value *LHS, Value *RHS,
465 const char *Name = "") {
466 if (Constant *LC = dyn_cast<Constant>(LHS))
467 if (Constant *RC = dyn_cast<Constant>(RHS))
468 return ConstantExpr::getCompare(P, LC, RC);
469 return Insert(new VICmpInst(P, LHS, RHS, Name));
471 Value *CreateVFCmp(CmpInst::Predicate P, Value *LHS, Value *RHS,
472 const char *Name = "") {
473 if (Constant *LC = dyn_cast<Constant>(LHS))
474 if (Constant *RC = dyn_cast<Constant>(RHS))
475 return ConstantExpr::getCompare(P, LC, RC);
476 return Insert(new VFCmpInst(P, LHS, RHS, Name));
479 //===--------------------------------------------------------------------===//
480 // Instruction creation methods: Other Instructions
481 //===--------------------------------------------------------------------===//
483 PHINode *CreatePHI(const Type *Ty, const char *Name = "") {
484 return Insert(PHINode::Create(Ty, Name));
487 CallInst *CreateCall(Value *Callee, const char *Name = "") {
488 return Insert(CallInst::Create(Callee, Name));
490 CallInst *CreateCall(Value *Callee, Value *Arg, const char *Name = "") {
491 return Insert(CallInst::Create(Callee, Arg, Name));
493 CallInst *CreateCall2(Value *Callee, Value *Arg1, Value *Arg2,
494 const char *Name = "") {
495 Value *Args[] = { Arg1, Arg2 };
496 return Insert(CallInst::Create(Callee, Args, Args+2, Name));
498 CallInst *CreateCall3(Value *Callee, Value *Arg1, Value *Arg2, Value *Arg3,
499 const char *Name = "") {
500 Value *Args[] = { Arg1, Arg2, Arg3 };
501 return Insert(CallInst::Create(Callee, Args, Args+3, Name));
503 CallInst *CreateCall4(Value *Callee, Value *Arg1, Value *Arg2, Value *Arg3,
504 Value *Arg4, const char *Name = "") {
505 Value *Args[] = { Arg1, Arg2, Arg3, Arg4 };
506 return Insert(CallInst::Create(Callee, Args, Args+4, Name));
509 template<typename InputIterator>
510 CallInst *CreateCall(Value *Callee, InputIterator ArgBegin,
511 InputIterator ArgEnd, const char *Name = "") {
512 return Insert(CallInst::Create(Callee, ArgBegin, ArgEnd, Name));
515 Value *CreateSelect(Value *C, Value *True, Value *False,
516 const char *Name = "") {
517 if (Constant *CC = dyn_cast<Constant>(C))
518 if (Constant *TC = dyn_cast<Constant>(True))
519 if (Constant *FC = dyn_cast<Constant>(False))
520 return ConstantExpr::getSelect(CC, TC, FC);
521 return Insert(SelectInst::Create(C, True, False, Name));
524 VAArgInst *CreateVAArg(Value *List, const Type *Ty, const char *Name = "") {
525 return Insert(new VAArgInst(List, Ty, Name));
528 Value *CreateExtractElement(Value *Vec, Value *Idx,
529 const char *Name = "") {
530 if (Constant *VC = dyn_cast<Constant>(Vec))
531 if (Constant *IC = dyn_cast<Constant>(Idx))
532 return ConstantExpr::getExtractElement(VC, IC);
533 return Insert(new ExtractElementInst(Vec, Idx, Name));
536 Value *CreateInsertElement(Value *Vec, Value *NewElt, Value *Idx,
537 const char *Name = "") {
538 if (Constant *VC = dyn_cast<Constant>(Vec))
539 if (Constant *NC = dyn_cast<Constant>(NewElt))
540 if (Constant *IC = dyn_cast<Constant>(Idx))
541 return ConstantExpr::getInsertElement(VC, NC, IC);
542 return Insert(InsertElementInst::Create(Vec, NewElt, Idx, Name));
545 Value *CreateShuffleVector(Value *V1, Value *V2, Value *Mask,
546 const char *Name = "") {
547 if (Constant *V1C = dyn_cast<Constant>(V1))
548 if (Constant *V2C = dyn_cast<Constant>(V2))
549 if (Constant *MC = dyn_cast<Constant>(Mask))
550 return ConstantExpr::getShuffleVector(V1C, V2C, MC);
551 return Insert(new ShuffleVectorInst(V1, V2, Mask, Name));