blob: e12f27a7cb1ead40b9e0805e7b638937f52dd2c2 [file] [log] [blame]
Chris Lattnercbfd4062004-01-12 21:13:12 +00001//===-- ConstantFolding.h - Internal Constant Folding Interface -*- C++ -*-===//
Misha Brukmanfd939082005-04-21 23:48:37 +00002//
John Criswell6fbcc262003-10-20 20:19:47 +00003// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Misha Brukmanfd939082005-04-21 23:48:37 +00007//
John Criswell6fbcc262003-10-20 20:19:47 +00008//===----------------------------------------------------------------------===//
Chris Lattner00950542001-06-06 20:29:01 +00009//
Chris Lattnercbfd4062004-01-12 21:13:12 +000010// This file defines the (internal) constant folding interfaces for LLVM. These
11// interfaces are used by the ConstantExpr::get* methods to automatically fold
12// constants when possible.
13//
Duncan Sands58921fe2008-08-01 12:23:49 +000014// These operators may return a null object if they don't know how to perform
15// the specified operation on the specified constant types.
Chris Lattner00950542001-06-06 20:29:01 +000016//
17//===----------------------------------------------------------------------===//
Chris Lattner00950542001-06-06 20:29:01 +000018
Chris Lattnercbfd4062004-01-12 21:13:12 +000019#ifndef CONSTANTFOLDING_H
20#define CONSTANTFOLDING_H
Chris Lattner00950542001-06-06 20:29:01 +000021
Jay Foadfc6d3a42011-07-13 10:26:04 +000022#include "llvm/ADT/ArrayRef.h"
23
Brian Gaeked0fde302003-11-11 22:41:34 +000024namespace llvm {
Chris Lattner7fa6e662004-10-11 22:52:25 +000025 class Value;
Chris Lattner8b0f0cb2004-01-12 21:02:29 +000026 class Constant;
Chris Lattner1fca5ff2004-10-27 16:14:51 +000027 class Type;
Misha Brukmanfd939082005-04-21 23:48:37 +000028
Chris Lattnercbfd4062004-01-12 21:13:12 +000029 // Constant fold various types of instruction...
Reid Spencer3da59db2006-11-27 01:05:10 +000030 Constant *ConstantFoldCastInstruction(
31 unsigned opcode, ///< The opcode of the cast
Nick Lewycky33c06ad2009-09-20 01:35:59 +000032 Constant *V, ///< The source constant
Chris Lattnerdb125cf2011-07-18 04:54:35 +000033 Type *DestTy ///< The destination type
Reid Spencer3da59db2006-11-27 01:05:10 +000034 );
Chris Lattnerb29d5962010-02-01 20:48:08 +000035 Constant *ConstantFoldSelectInstruction(Constant *Cond,
Nick Lewycky33c06ad2009-09-20 01:35:59 +000036 Constant *V1, Constant *V2);
Chris Lattnerb29d5962010-02-01 20:48:08 +000037 Constant *ConstantFoldExtractElementInstruction(Constant *Val, Constant *Idx);
38 Constant *ConstantFoldInsertElementInstruction(Constant *Val, Constant *Elt,
Nick Lewycky33c06ad2009-09-20 01:35:59 +000039 Constant *Idx);
Chris Lattnerb29d5962010-02-01 20:48:08 +000040 Constant *ConstantFoldShuffleVectorInstruction(Constant *V1, Constant *V2,
Nick Lewycky33c06ad2009-09-20 01:35:59 +000041 Constant *Mask);
Chris Lattnerb29d5962010-02-01 20:48:08 +000042 Constant *ConstantFoldExtractValueInstruction(Constant *Agg,
Jay Foadfc6d3a42011-07-13 10:26:04 +000043 ArrayRef<unsigned> Idxs);
Chris Lattnerb29d5962010-02-01 20:48:08 +000044 Constant *ConstantFoldInsertValueInstruction(Constant *Agg, Constant *Val,
Jay Foadfc6d3a42011-07-13 10:26:04 +000045 ArrayRef<unsigned> Idxs);
Chris Lattnerb29d5962010-02-01 20:48:08 +000046 Constant *ConstantFoldBinaryInstruction(unsigned Opcode, Constant *V1,
Nick Lewycky33c06ad2009-09-20 01:35:59 +000047 Constant *V2);
Chris Lattnerb29d5962010-02-01 20:48:08 +000048 Constant *ConstantFoldCompareInstruction(unsigned short predicate,
Nick Lewycky33c06ad2009-09-20 01:35:59 +000049 Constant *C1, Constant *C2);
Chris Lattnerb29d5962010-02-01 20:48:08 +000050 Constant *ConstantFoldGetElementPtr(Constant *C, bool inBounds,
Jay Foad7fc52e22011-07-19 15:30:30 +000051 ArrayRef<Constant *> Idxs);
Jay Foad25052d82011-01-14 08:07:43 +000052 Constant *ConstantFoldGetElementPtr(Constant *C, bool inBounds,
Jay Foad7fc52e22011-07-19 15:30:30 +000053 ArrayRef<Value *> Idxs);
Brian Gaeked0fde302003-11-11 22:41:34 +000054} // End llvm namespace
55
Chris Lattner00950542001-06-06 20:29:01 +000056#endif