blob: cc97001e3cf38b2037015531681235f1721ba2b5 [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;
Benjamin Kramer78c3bcb2009-08-11 17:45:13 +000026 class LLVMContext;
Misha Brukmanb1c93172005-04-21 23:48:37 +000027
Chris Lattner5a945e32004-01-12 21:13:12 +000028 // Constant fold various types of instruction...
Reid Spencer6c38f0b2006-11-27 01:05:10 +000029 Constant *ConstantFoldCastInstruction(
Owen Anderson53a52212009-07-13 04:09:18 +000030 LLVMContext &Context,
Reid Spencer6c38f0b2006-11-27 01:05:10 +000031 unsigned opcode, ///< The opcode of the cast
Nick Lewyckye0332982009-09-20 01:35:59 +000032 Constant *V, ///< The source constant
Owen Anderson2cda7d72009-06-20 00:26:26 +000033 const Type *DestTy ///< The destination type
Reid Spencer6c38f0b2006-11-27 01:05:10 +000034 );
Owen Anderson53a52212009-07-13 04:09:18 +000035 Constant *ConstantFoldSelectInstruction(LLVMContext &Context,
Nick Lewyckye0332982009-09-20 01:35:59 +000036 Constant *Cond,
37 Constant *V1, Constant *V2);
Owen Anderson53a52212009-07-13 04:09:18 +000038 Constant *ConstantFoldExtractElementInstruction(LLVMContext &Context,
Nick Lewyckye0332982009-09-20 01:35:59 +000039 Constant *Val,
40 Constant *Idx);
Owen Anderson53a52212009-07-13 04:09:18 +000041 Constant *ConstantFoldInsertElementInstruction(LLVMContext &Context,
Nick Lewyckye0332982009-09-20 01:35:59 +000042 Constant *Val,
43 Constant *Elt,
44 Constant *Idx);
Owen Anderson53a52212009-07-13 04:09:18 +000045 Constant *ConstantFoldShuffleVectorInstruction(LLVMContext &Context,
Nick Lewyckye0332982009-09-20 01:35:59 +000046 Constant *V1,
47 Constant *V2,
48 Constant *Mask);
Owen Anderson53a52212009-07-13 04:09:18 +000049 Constant *ConstantFoldExtractValueInstruction(LLVMContext &Context,
Nick Lewyckye0332982009-09-20 01:35:59 +000050 Constant *Agg,
Dan Gohman3db11c22008-06-03 00:15:20 +000051 const unsigned *Idxs,
52 unsigned NumIdx);
Owen Anderson53a52212009-07-13 04:09:18 +000053 Constant *ConstantFoldInsertValueInstruction(LLVMContext &Context,
Nick Lewyckye0332982009-09-20 01:35:59 +000054 Constant *Agg,
55 Constant *Val,
56 const unsigned *Idxs,
Dan Gohman3db11c22008-06-03 00:15:20 +000057 unsigned NumIdx);
Owen Anderson53a52212009-07-13 04:09:18 +000058 Constant *ConstantFoldBinaryInstruction(LLVMContext &Context,
Nick Lewyckye0332982009-09-20 01:35:59 +000059 unsigned Opcode, Constant *V1,
60 Constant *V2);
Owen Anderson53a52212009-07-13 04:09:18 +000061 Constant *ConstantFoldCompareInstruction(LLVMContext &Context,
62 unsigned short predicate,
Nick Lewyckye0332982009-09-20 01:35:59 +000063 Constant *C1, Constant *C2);
64 Constant *ConstantFoldGetElementPtr(LLVMContext &Context, Constant *C,
Dan Gohman21c62162009-09-11 00:04:14 +000065 bool inBounds,
Owen Anderson2cda7d72009-06-20 00:26:26 +000066 Constant* const *Idxs, unsigned NumIdx);
Brian Gaeke960707c2003-11-11 22:41:34 +000067} // End llvm namespace
68
Chris Lattner2f7c9632001-06-06 20:29:01 +000069#endif