blob: 2d8de1132b964d26348f86cbbe9afb62d6b413be [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
Benjamin Kramer00e08fc2014-08-13 16:26:38 +000019#ifndef LLVM_LIB_IR_CONSTANTFOLD_H
20#define LLVM_LIB_IR_CONSTANTFOLD_H
Chris Lattner00950542001-06-06 20:29:01 +000021
Peter Collingbourneca668e12016-11-10 22:34:55 +000022#include "llvm/ADT/Optional.h"
23
Brian Gaeked0fde302003-11-11 22:41:34 +000024namespace llvm {
Mehdi Aminif6071e12016-04-18 09:17:29 +000025template <typename T> class ArrayRef;
Chris Lattner7fa6e662004-10-11 22:52:25 +000026 class Value;
Chris Lattner8b0f0cb2004-01-12 21:02:29 +000027 class Constant;
Chris Lattner1fca5ff2004-10-27 16:14:51 +000028 class Type;
Misha Brukmanfd939082005-04-21 23:48:37 +000029
Chris Lattnercbfd4062004-01-12 21:13:12 +000030 // Constant fold various types of instruction...
Reid Spencer3da59db2006-11-27 01:05:10 +000031 Constant *ConstantFoldCastInstruction(
32 unsigned opcode, ///< The opcode of the cast
Nick Lewycky33c06ad2009-09-20 01:35:59 +000033 Constant *V, ///< The source constant
Chris Lattnerdb125cf2011-07-18 04:54:35 +000034 Type *DestTy ///< The destination type
Reid Spencer3da59db2006-11-27 01:05:10 +000035 );
Chris Lattnerb29d5962010-02-01 20:48:08 +000036 Constant *ConstantFoldSelectInstruction(Constant *Cond,
Nick Lewycky33c06ad2009-09-20 01:35:59 +000037 Constant *V1, Constant *V2);
Chris Lattnerb29d5962010-02-01 20:48:08 +000038 Constant *ConstantFoldExtractElementInstruction(Constant *Val, Constant *Idx);
39 Constant *ConstantFoldInsertElementInstruction(Constant *Val, Constant *Elt,
Nick Lewycky33c06ad2009-09-20 01:35:59 +000040 Constant *Idx);
Chris Lattnerb29d5962010-02-01 20:48:08 +000041 Constant *ConstantFoldShuffleVectorInstruction(Constant *V1, Constant *V2,
Nick Lewycky33c06ad2009-09-20 01:35:59 +000042 Constant *Mask);
Chris Lattnerb29d5962010-02-01 20:48:08 +000043 Constant *ConstantFoldExtractValueInstruction(Constant *Agg,
Jay Foadfc6d3a42011-07-13 10:26:04 +000044 ArrayRef<unsigned> Idxs);
Chris Lattnerb29d5962010-02-01 20:48:08 +000045 Constant *ConstantFoldInsertValueInstruction(Constant *Agg, Constant *Val,
Jay Foadfc6d3a42011-07-13 10:26:04 +000046 ArrayRef<unsigned> Idxs);
Chris Lattnerb29d5962010-02-01 20:48:08 +000047 Constant *ConstantFoldBinaryInstruction(unsigned Opcode, Constant *V1,
Nick Lewycky33c06ad2009-09-20 01:35:59 +000048 Constant *V2);
Junmo Parkf04d5892016-03-22 04:37:32 +000049 Constant *ConstantFoldCompareInstruction(unsigned short predicate,
Nick Lewycky33c06ad2009-09-20 01:35:59 +000050 Constant *C1, Constant *C2);
Peter Collingbourneca668e12016-11-10 22:34:55 +000051 Constant *ConstantFoldGetElementPtr(Type *Ty, Constant *C, bool InBounds,
52 Optional<unsigned> InRangeIndex,
David Blaikiead80c2d2015-05-07 17:28:58 +000053 ArrayRef<Value *> Idxs);
Alexander Kornienkocd52a7a2015-06-23 09:49:53 +000054} // End llvm namespace
Brian Gaeked0fde302003-11-11 22:41:34 +000055
Chris Lattner00950542001-06-06 20:29:01 +000056#endif