136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines//===- NoFolder.h - Constant folding helper ---------------------*- C++ -*-===// 2fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands// 3fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands// The LLVM Compiler Infrastructure 4fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands// 5fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands// This file is distributed under the University of Illinois Open Source 6fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands// License. See LICENSE.TXT for details. 7fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands// 8fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands//===----------------------------------------------------------------------===// 9fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands// 109d8658a1292c1674f4968700b91e5a3b5ee3bf4eDuncan Sands// This file defines the NoFolder class, a helper for IRBuilder. It provides 11fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands// IRBuilder with a set of methods for creating unfolded constants. This is 12fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands// useful for learners trying to understand how LLVM IR works, and who don't 13fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands// want details to be hidden by the constant folder. For general constant 14fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands// creation and folding, use ConstantExpr and the routines in 15fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands// llvm/Analysis/ConstantFolding.h. 16fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands// 17fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands// Note: since it is not actually possible to create unfolded constants, this 1885a0a06b18be145feb0c10cbdf4d521c1a8835bfChris Lattner// class returns instructions rather than constants. 19fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands// 20fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands//===----------------------------------------------------------------------===// 21fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands 2236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines#ifndef LLVM_IR_NOFOLDER_H 2336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines#define LLVM_IR_NOFOLDER_H 24fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands 25fc6d3a49867cd38954dc40936a88f1907252c6d2Jay Foad#include "llvm/ADT/ArrayRef.h" 260b8c9a80f20772c3793201ab5b251d3520b9cea3Chandler Carruth#include "llvm/IR/Constants.h" 270b8c9a80f20772c3793201ab5b251d3520b9cea3Chandler Carruth#include "llvm/IR/Instructions.h" 28fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands 29fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sandsnamespace llvm { 30fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands 3185a0a06b18be145feb0c10cbdf4d521c1a8835bfChris Lattner/// NoFolder - Create "constants" (actually, instructions) with no folding. 329d8658a1292c1674f4968700b91e5a3b5ee3bf4eDuncan Sandsclass NoFolder { 33fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sandspublic: 34c12d4c93f94e271d32e60fae1d521c4fca39ae1eFrits van Bommel explicit NoFolder() {} 35fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands 36fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands //===--------------------------------------------------------------------===// 37fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands // Binary Operators 38fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands //===--------------------------------------------------------------------===// 39fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands 4049ff8a76d02f1c5f8da7cd2675be191c7be109c4Nick Lewycky Instruction *CreateAdd(Constant *LHS, Constant *RHS, 4149ff8a76d02f1c5f8da7cd2675be191c7be109c4Nick Lewycky bool HasNUW = false, bool HasNSW = false) const { 4249ff8a76d02f1c5f8da7cd2675be191c7be109c4Nick Lewycky BinaryOperator *BO = BinaryOperator::CreateAdd(LHS, RHS); 4349ff8a76d02f1c5f8da7cd2675be191c7be109c4Nick Lewycky if (HasNUW) BO->setHasNoUnsignedWrap(); 4449ff8a76d02f1c5f8da7cd2675be191c7be109c4Nick Lewycky if (HasNSW) BO->setHasNoSignedWrap(); 4549ff8a76d02f1c5f8da7cd2675be191c7be109c4Nick Lewycky return BO; 46fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands } 4785a0a06b18be145feb0c10cbdf4d521c1a8835bfChris Lattner Instruction *CreateNSWAdd(Constant *LHS, Constant *RHS) const { 48d6474fa1f19224e62e5095a6373bed0c69bdb215Dan Gohman return BinaryOperator::CreateNSWAdd(LHS, RHS); 49d6474fa1f19224e62e5095a6373bed0c69bdb215Dan Gohman } 5085a0a06b18be145feb0c10cbdf4d521c1a8835bfChris Lattner Instruction *CreateNUWAdd(Constant *LHS, Constant *RHS) const { 518991d51ddcea31e198aff1fd01c05af2679ee8f8Duncan Sands return BinaryOperator::CreateNUWAdd(LHS, RHS); 528991d51ddcea31e198aff1fd01c05af2679ee8f8Duncan Sands } 5385a0a06b18be145feb0c10cbdf4d521c1a8835bfChris Lattner Instruction *CreateFAdd(Constant *LHS, Constant *RHS) const { 54ae3a0be92e33bc716722aa600983fc1535acb122Dan Gohman return BinaryOperator::CreateFAdd(LHS, RHS); 55ae3a0be92e33bc716722aa600983fc1535acb122Dan Gohman } 5649ff8a76d02f1c5f8da7cd2675be191c7be109c4Nick Lewycky Instruction *CreateSub(Constant *LHS, Constant *RHS, 5749ff8a76d02f1c5f8da7cd2675be191c7be109c4Nick Lewycky bool HasNUW = false, bool HasNSW = false) const { 5849ff8a76d02f1c5f8da7cd2675be191c7be109c4Nick Lewycky BinaryOperator *BO = BinaryOperator::CreateSub(LHS, RHS); 5949ff8a76d02f1c5f8da7cd2675be191c7be109c4Nick Lewycky if (HasNUW) BO->setHasNoUnsignedWrap(); 6049ff8a76d02f1c5f8da7cd2675be191c7be109c4Nick Lewycky if (HasNSW) BO->setHasNoSignedWrap(); 6149ff8a76d02f1c5f8da7cd2675be191c7be109c4Nick Lewycky return BO; 62fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands } 6385a0a06b18be145feb0c10cbdf4d521c1a8835bfChris Lattner Instruction *CreateNSWSub(Constant *LHS, Constant *RHS) const { 643548ea8e905269e819fdd4c7fab42142b745c6c5Duncan Sands return BinaryOperator::CreateNSWSub(LHS, RHS); 653548ea8e905269e819fdd4c7fab42142b745c6c5Duncan Sands } 6685a0a06b18be145feb0c10cbdf4d521c1a8835bfChris Lattner Instruction *CreateNUWSub(Constant *LHS, Constant *RHS) const { 678991d51ddcea31e198aff1fd01c05af2679ee8f8Duncan Sands return BinaryOperator::CreateNUWSub(LHS, RHS); 688991d51ddcea31e198aff1fd01c05af2679ee8f8Duncan Sands } 6985a0a06b18be145feb0c10cbdf4d521c1a8835bfChris Lattner Instruction *CreateFSub(Constant *LHS, Constant *RHS) const { 70ae3a0be92e33bc716722aa600983fc1535acb122Dan Gohman return BinaryOperator::CreateFSub(LHS, RHS); 71ae3a0be92e33bc716722aa600983fc1535acb122Dan Gohman } 7249ff8a76d02f1c5f8da7cd2675be191c7be109c4Nick Lewycky Instruction *CreateMul(Constant *LHS, Constant *RHS, 7349ff8a76d02f1c5f8da7cd2675be191c7be109c4Nick Lewycky bool HasNUW = false, bool HasNSW = false) const { 7449ff8a76d02f1c5f8da7cd2675be191c7be109c4Nick Lewycky BinaryOperator *BO = BinaryOperator::CreateMul(LHS, RHS); 7549ff8a76d02f1c5f8da7cd2675be191c7be109c4Nick Lewycky if (HasNUW) BO->setHasNoUnsignedWrap(); 7649ff8a76d02f1c5f8da7cd2675be191c7be109c4Nick Lewycky if (HasNSW) BO->setHasNoSignedWrap(); 7749ff8a76d02f1c5f8da7cd2675be191c7be109c4Nick Lewycky return BO; 78fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands } 7985a0a06b18be145feb0c10cbdf4d521c1a8835bfChris Lattner Instruction *CreateNSWMul(Constant *LHS, Constant *RHS) const { 80411984810e4a66591123e1b16873e5f19ae18817Dan Gohman return BinaryOperator::CreateNSWMul(LHS, RHS); 81411984810e4a66591123e1b16873e5f19ae18817Dan Gohman } 8285a0a06b18be145feb0c10cbdf4d521c1a8835bfChris Lattner Instruction *CreateNUWMul(Constant *LHS, Constant *RHS) const { 838991d51ddcea31e198aff1fd01c05af2679ee8f8Duncan Sands return BinaryOperator::CreateNUWMul(LHS, RHS); 848991d51ddcea31e198aff1fd01c05af2679ee8f8Duncan Sands } 8585a0a06b18be145feb0c10cbdf4d521c1a8835bfChris Lattner Instruction *CreateFMul(Constant *LHS, Constant *RHS) const { 86ae3a0be92e33bc716722aa600983fc1535acb122Dan Gohman return BinaryOperator::CreateFMul(LHS, RHS); 87ae3a0be92e33bc716722aa600983fc1535acb122Dan Gohman } 8849ff8a76d02f1c5f8da7cd2675be191c7be109c4Nick Lewycky Instruction *CreateUDiv(Constant *LHS, Constant *RHS, 8949ff8a76d02f1c5f8da7cd2675be191c7be109c4Nick Lewycky bool isExact = false) const { 9049ff8a76d02f1c5f8da7cd2675be191c7be109c4Nick Lewycky if (!isExact) 9149ff8a76d02f1c5f8da7cd2675be191c7be109c4Nick Lewycky return BinaryOperator::CreateUDiv(LHS, RHS); 9249ff8a76d02f1c5f8da7cd2675be191c7be109c4Nick Lewycky return BinaryOperator::CreateExactUDiv(LHS, RHS); 93fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands } 941dbf0df996bba398a70abccc714b1a9652330014Duncan Sands Instruction *CreateExactUDiv(Constant *LHS, Constant *RHS) const { 951dbf0df996bba398a70abccc714b1a9652330014Duncan Sands return BinaryOperator::CreateExactUDiv(LHS, RHS); 961dbf0df996bba398a70abccc714b1a9652330014Duncan Sands } 9749ff8a76d02f1c5f8da7cd2675be191c7be109c4Nick Lewycky Instruction *CreateSDiv(Constant *LHS, Constant *RHS, 9849ff8a76d02f1c5f8da7cd2675be191c7be109c4Nick Lewycky bool isExact = false) const { 9949ff8a76d02f1c5f8da7cd2675be191c7be109c4Nick Lewycky if (!isExact) 10049ff8a76d02f1c5f8da7cd2675be191c7be109c4Nick Lewycky return BinaryOperator::CreateSDiv(LHS, RHS); 10149ff8a76d02f1c5f8da7cd2675be191c7be109c4Nick Lewycky return BinaryOperator::CreateExactSDiv(LHS, RHS); 102fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands } 10385a0a06b18be145feb0c10cbdf4d521c1a8835bfChris Lattner Instruction *CreateExactSDiv(Constant *LHS, Constant *RHS) const { 10459c4f5c2fc82af14b0f4f332709aac62921c6177Dan Gohman return BinaryOperator::CreateExactSDiv(LHS, RHS); 10559c4f5c2fc82af14b0f4f332709aac62921c6177Dan Gohman } 10685a0a06b18be145feb0c10cbdf4d521c1a8835bfChris Lattner Instruction *CreateFDiv(Constant *LHS, Constant *RHS) const { 107fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands return BinaryOperator::CreateFDiv(LHS, RHS); 108fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands } 10985a0a06b18be145feb0c10cbdf4d521c1a8835bfChris Lattner Instruction *CreateURem(Constant *LHS, Constant *RHS) const { 110fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands return BinaryOperator::CreateURem(LHS, RHS); 111fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands } 11285a0a06b18be145feb0c10cbdf4d521c1a8835bfChris Lattner Instruction *CreateSRem(Constant *LHS, Constant *RHS) const { 113fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands return BinaryOperator::CreateSRem(LHS, RHS); 114fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands } 11585a0a06b18be145feb0c10cbdf4d521c1a8835bfChris Lattner Instruction *CreateFRem(Constant *LHS, Constant *RHS) const { 116fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands return BinaryOperator::CreateFRem(LHS, RHS); 117fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands } 11849ff8a76d02f1c5f8da7cd2675be191c7be109c4Nick Lewycky Instruction *CreateShl(Constant *LHS, Constant *RHS, bool HasNUW = false, 11949ff8a76d02f1c5f8da7cd2675be191c7be109c4Nick Lewycky bool HasNSW = false) const { 12049ff8a76d02f1c5f8da7cd2675be191c7be109c4Nick Lewycky BinaryOperator *BO = BinaryOperator::CreateShl(LHS, RHS); 12149ff8a76d02f1c5f8da7cd2675be191c7be109c4Nick Lewycky if (HasNUW) BO->setHasNoUnsignedWrap(); 12249ff8a76d02f1c5f8da7cd2675be191c7be109c4Nick Lewycky if (HasNSW) BO->setHasNoSignedWrap(); 12349ff8a76d02f1c5f8da7cd2675be191c7be109c4Nick Lewycky return BO; 12449ff8a76d02f1c5f8da7cd2675be191c7be109c4Nick Lewycky } 12549ff8a76d02f1c5f8da7cd2675be191c7be109c4Nick Lewycky Instruction *CreateLShr(Constant *LHS, Constant *RHS, 12649ff8a76d02f1c5f8da7cd2675be191c7be109c4Nick Lewycky bool isExact = false) const { 12749ff8a76d02f1c5f8da7cd2675be191c7be109c4Nick Lewycky if (!isExact) 12849ff8a76d02f1c5f8da7cd2675be191c7be109c4Nick Lewycky return BinaryOperator::CreateLShr(LHS, RHS); 12949ff8a76d02f1c5f8da7cd2675be191c7be109c4Nick Lewycky return BinaryOperator::CreateExactLShr(LHS, RHS); 13049ff8a76d02f1c5f8da7cd2675be191c7be109c4Nick Lewycky } 13149ff8a76d02f1c5f8da7cd2675be191c7be109c4Nick Lewycky Instruction *CreateAShr(Constant *LHS, Constant *RHS, 13249ff8a76d02f1c5f8da7cd2675be191c7be109c4Nick Lewycky bool isExact = false) const { 13349ff8a76d02f1c5f8da7cd2675be191c7be109c4Nick Lewycky if (!isExact) 13449ff8a76d02f1c5f8da7cd2675be191c7be109c4Nick Lewycky return BinaryOperator::CreateAShr(LHS, RHS); 13549ff8a76d02f1c5f8da7cd2675be191c7be109c4Nick Lewycky return BinaryOperator::CreateExactAShr(LHS, RHS); 136fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands } 13785a0a06b18be145feb0c10cbdf4d521c1a8835bfChris Lattner Instruction *CreateAnd(Constant *LHS, Constant *RHS) const { 138fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands return BinaryOperator::CreateAnd(LHS, RHS); 139fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands } 14085a0a06b18be145feb0c10cbdf4d521c1a8835bfChris Lattner Instruction *CreateOr(Constant *LHS, Constant *RHS) const { 141fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands return BinaryOperator::CreateOr(LHS, RHS); 142fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands } 14385a0a06b18be145feb0c10cbdf4d521c1a8835bfChris Lattner Instruction *CreateXor(Constant *LHS, Constant *RHS) const { 144fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands return BinaryOperator::CreateXor(LHS, RHS); 145fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands } 146fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands 14785a0a06b18be145feb0c10cbdf4d521c1a8835bfChris Lattner Instruction *CreateBinOp(Instruction::BinaryOps Opc, 14885a0a06b18be145feb0c10cbdf4d521c1a8835bfChris Lattner Constant *LHS, Constant *RHS) const { 149fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands return BinaryOperator::Create(Opc, LHS, RHS); 150fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands } 151fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands 152fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands //===--------------------------------------------------------------------===// 153fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands // Unary Operators 154fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands //===--------------------------------------------------------------------===// 155fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands 15649ff8a76d02f1c5f8da7cd2675be191c7be109c4Nick Lewycky Instruction *CreateNeg(Constant *C, 15749ff8a76d02f1c5f8da7cd2675be191c7be109c4Nick Lewycky bool HasNUW = false, bool HasNSW = false) const { 15849ff8a76d02f1c5f8da7cd2675be191c7be109c4Nick Lewycky BinaryOperator *BO = BinaryOperator::CreateNeg(C); 15949ff8a76d02f1c5f8da7cd2675be191c7be109c4Nick Lewycky if (HasNUW) BO->setHasNoUnsignedWrap(); 16049ff8a76d02f1c5f8da7cd2675be191c7be109c4Nick Lewycky if (HasNSW) BO->setHasNoSignedWrap(); 16149ff8a76d02f1c5f8da7cd2675be191c7be109c4Nick Lewycky return BO; 162fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands } 16385a0a06b18be145feb0c10cbdf4d521c1a8835bfChris Lattner Instruction *CreateNSWNeg(Constant *C) const { 164bdc46c6af5ffcf3596a72df75880fe8703436060Dan Gohman return BinaryOperator::CreateNSWNeg(C); 165bdc46c6af5ffcf3596a72df75880fe8703436060Dan Gohman } 16685a0a06b18be145feb0c10cbdf4d521c1a8835bfChris Lattner Instruction *CreateNUWNeg(Constant *C) const { 1678991d51ddcea31e198aff1fd01c05af2679ee8f8Duncan Sands return BinaryOperator::CreateNUWNeg(C); 1688991d51ddcea31e198aff1fd01c05af2679ee8f8Duncan Sands } 16985a0a06b18be145feb0c10cbdf4d521c1a8835bfChris Lattner Instruction *CreateFNeg(Constant *C) const { 17085a0a06b18be145feb0c10cbdf4d521c1a8835bfChris Lattner return BinaryOperator::CreateFNeg(C); 17185a0a06b18be145feb0c10cbdf4d521c1a8835bfChris Lattner } 17285a0a06b18be145feb0c10cbdf4d521c1a8835bfChris Lattner Instruction *CreateNot(Constant *C) const { 173fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands return BinaryOperator::CreateNot(C); 174fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands } 175fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands 176fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands //===--------------------------------------------------------------------===// 177fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands // Memory Instructions 178fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands //===--------------------------------------------------------------------===// 179fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands 18012fc16f1950796486988dc91ba69797efa5bdb64Jay Foad Constant *CreateGetElementPtr(Constant *C, 18112fc16f1950796486988dc91ba69797efa5bdb64Jay Foad ArrayRef<Constant *> IdxList) const { 182dab3d29605a5c83db41b28176273ef55961120c1Jay Foad return ConstantExpr::getGetElementPtr(C, IdxList); 183fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands } 184734fd27647bbfcf66d26e32fced5e4021dfb67e4Jin-Gu Kang Constant *CreateGetElementPtr(Constant *C, Constant *Idx) const { 185734fd27647bbfcf66d26e32fced5e4021dfb67e4Jin-Gu Kang // This form of the function only exists to avoid ambiguous overload 186734fd27647bbfcf66d26e32fced5e4021dfb67e4Jin-Gu Kang // warnings about whether to convert Idx to ArrayRef<Constant *> or 187734fd27647bbfcf66d26e32fced5e4021dfb67e4Jin-Gu Kang // ArrayRef<Value *>. 188734fd27647bbfcf66d26e32fced5e4021dfb67e4Jin-Gu Kang return ConstantExpr::getGetElementPtr(C, Idx); 189734fd27647bbfcf66d26e32fced5e4021dfb67e4Jin-Gu Kang } 19012fc16f1950796486988dc91ba69797efa5bdb64Jay Foad Instruction *CreateGetElementPtr(Constant *C, 19112fc16f1950796486988dc91ba69797efa5bdb64Jay Foad ArrayRef<Value *> IdxList) const { 192a9203109f4ac95aa7e9624f2838e3d89623ec902Jay Foad return GetElementPtrInst::Create(C, IdxList); 193fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands } 194fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands 19512fc16f1950796486988dc91ba69797efa5bdb64Jay Foad Constant *CreateInBoundsGetElementPtr(Constant *C, 19612fc16f1950796486988dc91ba69797efa5bdb64Jay Foad ArrayRef<Constant *> IdxList) const { 197dab3d29605a5c83db41b28176273ef55961120c1Jay Foad return ConstantExpr::getInBoundsGetElementPtr(C, IdxList); 19812fc16f1950796486988dc91ba69797efa5bdb64Jay Foad } 199734fd27647bbfcf66d26e32fced5e4021dfb67e4Jin-Gu Kang Constant *CreateInBoundsGetElementPtr(Constant *C, Constant *Idx) const { 200734fd27647bbfcf66d26e32fced5e4021dfb67e4Jin-Gu Kang // This form of the function only exists to avoid ambiguous overload 201734fd27647bbfcf66d26e32fced5e4021dfb67e4Jin-Gu Kang // warnings about whether to convert Idx to ArrayRef<Constant *> or 202734fd27647bbfcf66d26e32fced5e4021dfb67e4Jin-Gu Kang // ArrayRef<Value *>. 203734fd27647bbfcf66d26e32fced5e4021dfb67e4Jin-Gu Kang return ConstantExpr::getInBoundsGetElementPtr(C, Idx); 204734fd27647bbfcf66d26e32fced5e4021dfb67e4Jin-Gu Kang } 20512fc16f1950796486988dc91ba69797efa5bdb64Jay Foad Instruction *CreateInBoundsGetElementPtr(Constant *C, 20612fc16f1950796486988dc91ba69797efa5bdb64Jay Foad ArrayRef<Value *> IdxList) const { 207a9203109f4ac95aa7e9624f2838e3d89623ec902Jay Foad return GetElementPtrInst::CreateInBounds(C, IdxList); 208e2574d3215c412a15763d26aee9aa5d856764c2cDan Gohman } 209e2574d3215c412a15763d26aee9aa5d856764c2cDan Gohman 210fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands //===--------------------------------------------------------------------===// 211fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands // Cast/Conversion Operators 212fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands //===--------------------------------------------------------------------===// 213fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands 21485a0a06b18be145feb0c10cbdf4d521c1a8835bfChris Lattner Instruction *CreateCast(Instruction::CastOps Op, Constant *C, 215db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner Type *DestTy) const { 216fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands return CastInst::Create(Op, C, DestTy); 217fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands } 218db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner Instruction *CreatePointerCast(Constant *C, Type *DestTy) const { 21985a0a06b18be145feb0c10cbdf4d521c1a8835bfChris Lattner return CastInst::CreatePointerCast(C, DestTy); 22085a0a06b18be145feb0c10cbdf4d521c1a8835bfChris Lattner } 221db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner Instruction *CreateIntCast(Constant *C, Type *DestTy, 222fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands bool isSigned) const { 223fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands return CastInst::CreateIntegerCast(C, DestTy, isSigned); 224fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands } 225db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner Instruction *CreateFPCast(Constant *C, Type *DestTy) const { 22685a0a06b18be145feb0c10cbdf4d521c1a8835bfChris Lattner return CastInst::CreateFPCast(C, DestTy); 22785a0a06b18be145feb0c10cbdf4d521c1a8835bfChris Lattner } 22885a0a06b18be145feb0c10cbdf4d521c1a8835bfChris Lattner 229db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner Instruction *CreateBitCast(Constant *C, Type *DestTy) const { 23085a0a06b18be145feb0c10cbdf4d521c1a8835bfChris Lattner return CreateCast(Instruction::BitCast, C, DestTy); 23185a0a06b18be145feb0c10cbdf4d521c1a8835bfChris Lattner } 232db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner Instruction *CreateIntToPtr(Constant *C, Type *DestTy) const { 23385a0a06b18be145feb0c10cbdf4d521c1a8835bfChris Lattner return CreateCast(Instruction::IntToPtr, C, DestTy); 23485a0a06b18be145feb0c10cbdf4d521c1a8835bfChris Lattner } 235db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner Instruction *CreatePtrToInt(Constant *C, Type *DestTy) const { 23685a0a06b18be145feb0c10cbdf4d521c1a8835bfChris Lattner return CreateCast(Instruction::PtrToInt, C, DestTy); 23785a0a06b18be145feb0c10cbdf4d521c1a8835bfChris Lattner } 238db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner Instruction *CreateZExtOrBitCast(Constant *C, Type *DestTy) const { 23985a0a06b18be145feb0c10cbdf4d521c1a8835bfChris Lattner return CastInst::CreateZExtOrBitCast(C, DestTy); 24085a0a06b18be145feb0c10cbdf4d521c1a8835bfChris Lattner } 241db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner Instruction *CreateSExtOrBitCast(Constant *C, Type *DestTy) const { 24285a0a06b18be145feb0c10cbdf4d521c1a8835bfChris Lattner return CastInst::CreateSExtOrBitCast(C, DestTy); 24385a0a06b18be145feb0c10cbdf4d521c1a8835bfChris Lattner } 24485a0a06b18be145feb0c10cbdf4d521c1a8835bfChris Lattner 245db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner Instruction *CreateTruncOrBitCast(Constant *C, Type *DestTy) const { 24685a0a06b18be145feb0c10cbdf4d521c1a8835bfChris Lattner return CastInst::CreateTruncOrBitCast(C, DestTy); 24785a0a06b18be145feb0c10cbdf4d521c1a8835bfChris Lattner } 248fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands 249fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands //===--------------------------------------------------------------------===// 250fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands // Compare Instructions 251fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands //===--------------------------------------------------------------------===// 252fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands 25385a0a06b18be145feb0c10cbdf4d521c1a8835bfChris Lattner Instruction *CreateICmp(CmpInst::Predicate P, 25485a0a06b18be145feb0c10cbdf4d521c1a8835bfChris Lattner Constant *LHS, Constant *RHS) const { 255fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands return new ICmpInst(P, LHS, RHS); 256fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands } 25785a0a06b18be145feb0c10cbdf4d521c1a8835bfChris Lattner Instruction *CreateFCmp(CmpInst::Predicate P, 25885a0a06b18be145feb0c10cbdf4d521c1a8835bfChris Lattner Constant *LHS, Constant *RHS) const { 259fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands return new FCmpInst(P, LHS, RHS); 260fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands } 261fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands 262fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands //===--------------------------------------------------------------------===// 263fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands // Other Instructions 264fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands //===--------------------------------------------------------------------===// 265fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands 26685a0a06b18be145feb0c10cbdf4d521c1a8835bfChris Lattner Instruction *CreateSelect(Constant *C, 26785a0a06b18be145feb0c10cbdf4d521c1a8835bfChris Lattner Constant *True, Constant *False) const { 268fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands return SelectInst::Create(C, True, False); 269fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands } 270fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands 27185a0a06b18be145feb0c10cbdf4d521c1a8835bfChris Lattner Instruction *CreateExtractElement(Constant *Vec, Constant *Idx) const { 2725a325e3663c0af8b0c7d644dfb56a5bed1f11bbcDaniel Dunbar return ExtractElementInst::Create(Vec, Idx); 273fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands } 274fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands 27585a0a06b18be145feb0c10cbdf4d521c1a8835bfChris Lattner Instruction *CreateInsertElement(Constant *Vec, Constant *NewElt, 27685a0a06b18be145feb0c10cbdf4d521c1a8835bfChris Lattner Constant *Idx) const { 277fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands return InsertElementInst::Create(Vec, NewElt, Idx); 278fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands } 279fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands 28085a0a06b18be145feb0c10cbdf4d521c1a8835bfChris Lattner Instruction *CreateShuffleVector(Constant *V1, Constant *V2, 28185a0a06b18be145feb0c10cbdf4d521c1a8835bfChris Lattner Constant *Mask) const { 282fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands return new ShuffleVectorInst(V1, V2, Mask); 283fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands } 284fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands 285fc6d3a49867cd38954dc40936a88f1907252c6d2Jay Foad Instruction *CreateExtractValue(Constant *Agg, 286fc6d3a49867cd38954dc40936a88f1907252c6d2Jay Foad ArrayRef<unsigned> IdxList) const { 287fc6d3a49867cd38954dc40936a88f1907252c6d2Jay Foad return ExtractValueInst::Create(Agg, IdxList); 288fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands } 289fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands 29085a0a06b18be145feb0c10cbdf4d521c1a8835bfChris Lattner Instruction *CreateInsertValue(Constant *Agg, Constant *Val, 291fc6d3a49867cd38954dc40936a88f1907252c6d2Jay Foad ArrayRef<unsigned> IdxList) const { 292fc6d3a49867cd38954dc40936a88f1907252c6d2Jay Foad return InsertValueInst::Create(Agg, Val, IdxList); 293fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands } 294fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands}; 295fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands 296fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands} 297fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands 298fe24bd3a89c44f9a16e3cbcf60c119dac88fad40Duncan Sands#endif 299