blob: 0ecd7b49a48e2571bd750f0db03419a7acf5e29b [file] [log] [blame]
Chris Lattner5a945e32004-01-12 21:13:12 +00001//===-- ConstantFolding.h - Internal Constant Folding Interface -*- C++ -*-===//
Misha Brukmanb1c93172005-04-21 23:48:37 +00002//
John Criswellb6445982003-10-20 20:19:47 +00003// The LLVM Compiler Infrastructure
4//
Chris Lattnerf3ebc3f2007-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 Brukmanb1c93172005-04-21 23:48:37 +00007//
John Criswellb6445982003-10-20 20:19:47 +00008//===----------------------------------------------------------------------===//
Chris Lattner2f7c9632001-06-06 20:29:01 +00009//
Chris Lattner5a945e32004-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 Sandsc1e48b52008-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 Lattner2f7c9632001-06-06 20:29:01 +000016//
17//===----------------------------------------------------------------------===//
Chris Lattner2f7c9632001-06-06 20:29:01 +000018
Chris Lattner5a945e32004-01-12 21:13:12 +000019#ifndef CONSTANTFOLDING_H
20#define CONSTANTFOLDING_H
Chris Lattner2f7c9632001-06-06 20:29:01 +000021
Brian Gaeke960707c2003-11-11 22:41:34 +000022namespace llvm {
Chris Lattner13128ab2004-10-11 22:52:25 +000023 class Value;
Chris Lattner6ff6cea2004-01-12 21:02:29 +000024 class Constant;
Chris Lattner7dfc2d22004-10-27 16:14:51 +000025 class Type;
Misha Brukmanb1c93172005-04-21 23:48:37 +000026
Chris Lattner5a945e32004-01-12 21:13:12 +000027 // Constant fold various types of instruction...
Reid Spencer6c38f0b2006-11-27 01:05:10 +000028 Constant *ConstantFoldCastInstruction(
29 unsigned opcode, ///< The opcode of the cast
Nick Lewyckye0332982009-09-20 01:35:59 +000030 Constant *V, ///< The source constant
Owen Anderson2cda7d72009-06-20 00:26:26 +000031 const Type *DestTy ///< The destination type
Reid Spencer6c38f0b2006-11-27 01:05:10 +000032 );
Chris Lattnerf5edeeb2010-02-01 20:48:08 +000033 Constant *ConstantFoldSelectInstruction(Constant *Cond,
Nick Lewyckye0332982009-09-20 01:35:59 +000034 Constant *V1, Constant *V2);
Chris Lattnerf5edeeb2010-02-01 20:48:08 +000035 Constant *ConstantFoldExtractElementInstruction(Constant *Val, Constant *Idx);
36 Constant *ConstantFoldInsertElementInstruction(Constant *Val, Constant *Elt,
Nick Lewyckye0332982009-09-20 01:35:59 +000037 Constant *Idx);
Chris Lattnerf5edeeb2010-02-01 20:48:08 +000038 Constant *ConstantFoldShuffleVectorInstruction(Constant *V1, Constant *V2,
Nick Lewyckye0332982009-09-20 01:35:59 +000039 Constant *Mask);
Chris Lattnerf5edeeb2010-02-01 20:48:08 +000040 Constant *ConstantFoldExtractValueInstruction(Constant *Agg,
Dan Gohman3db11c22008-06-03 00:15:20 +000041 const unsigned *Idxs,
42 unsigned NumIdx);
Chris Lattnerf5edeeb2010-02-01 20:48:08 +000043 Constant *ConstantFoldInsertValueInstruction(Constant *Agg, Constant *Val,
Nick Lewyckye0332982009-09-20 01:35:59 +000044 const unsigned *Idxs,
Dan Gohman3db11c22008-06-03 00:15:20 +000045 unsigned NumIdx);
Chris Lattnerf5edeeb2010-02-01 20:48:08 +000046 Constant *ConstantFoldBinaryInstruction(unsigned Opcode, Constant *V1,
Nick Lewyckye0332982009-09-20 01:35:59 +000047 Constant *V2);
Chris Lattnerf5edeeb2010-02-01 20:48:08 +000048 Constant *ConstantFoldCompareInstruction(unsigned short predicate,
Nick Lewyckye0332982009-09-20 01:35:59 +000049 Constant *C1, Constant *C2);
Chris Lattnerf5edeeb2010-02-01 20:48:08 +000050 Constant *ConstantFoldGetElementPtr(Constant *C, bool inBounds,
Owen Anderson2cda7d72009-06-20 00:26:26 +000051 Constant* const *Idxs, unsigned NumIdx);
Jay Foad1d4a8fe2011-01-14 08:07:43 +000052 Constant *ConstantFoldGetElementPtr(Constant *C, bool inBounds,
53 Value* const *Idxs, unsigned NumIdx);
Brian Gaeke960707c2003-11-11 22:41:34 +000054} // End llvm namespace
55
Chris Lattner2f7c9632001-06-06 20:29:01 +000056#endif