2003-09-30 18:37:50 +00:00
|
|
|
//===-- Local.h - Functions to perform local transformations ----*- C++ -*-===//
|
2003-10-20 20:19:47 +00:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file was developed by the LLVM research group and is distributed under
|
|
|
|
// the University of Illinois Open Source License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2002-05-07 18:52:48 +00:00
|
|
|
//
|
|
|
|
// This family of functions perform various local transformations to the
|
|
|
|
// program.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_TRANSFORMS_UTILS_LOCAL_H
|
|
|
|
#define LLVM_TRANSFORMS_UTILS_LOCAL_H
|
|
|
|
|
|
|
|
#include "llvm/Function.h"
|
2003-11-11 22:41:34 +00:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
2002-09-06 02:19:25 +00:00
|
|
|
class Pass;
|
2003-12-19 05:56:28 +00:00
|
|
|
class PHINode;
|
2004-03-14 02:13:07 +00:00
|
|
|
class AllocaInst;
|
2002-05-07 18:52:48 +00:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
2003-05-20 21:01:22 +00:00
|
|
|
// Local constant propagation...
|
2002-05-07 18:52:48 +00:00
|
|
|
//
|
|
|
|
|
2003-05-20 21:01:22 +00:00
|
|
|
/// doConstantPropagation - Constant prop a specific instruction. Returns true
|
|
|
|
/// and potentially moves the iterator if constant propagation was performed.
|
2002-09-06 02:19:25 +00:00
|
|
|
///
|
2003-05-20 21:01:22 +00:00
|
|
|
bool doConstantPropagation(BasicBlock::iterator &I);
|
2002-05-07 18:52:48 +00:00
|
|
|
|
2002-09-06 02:19:25 +00:00
|
|
|
/// ConstantFoldTerminator - If a terminator instruction is predicated on a
|
|
|
|
/// constant value, convert it into an unconditional branch to the constant
|
|
|
|
/// destination. This is a nontrivial operation because the successors of this
|
|
|
|
/// basic block must have their PHI nodes updated.
|
|
|
|
///
|
2002-05-21 20:04:50 +00:00
|
|
|
bool ConstantFoldTerminator(BasicBlock *BB);
|
2002-05-07 18:52:48 +00:00
|
|
|
|
2004-01-12 18:25:56 +00:00
|
|
|
/// ConstantFoldInstruction - Attempt to constant fold the specified
|
|
|
|
/// instruction. If successful, the constant result is returned, if not, null
|
|
|
|
/// is returned. Note that this function can only fail when attempting to fold
|
|
|
|
/// instructions like loads and stores, which have no constant expression form.
|
|
|
|
///
|
|
|
|
Constant *ConstantFoldInstruction(Instruction *I);
|
|
|
|
|
2002-05-07 18:52:48 +00:00
|
|
|
|
2004-04-13 19:28:32 +00:00
|
|
|
/// canConstantFoldCallTo - Return true if its even possible to fold a call to
|
|
|
|
/// the specified function.
|
|
|
|
bool canConstantFoldCallTo(Function *F);
|
|
|
|
|
|
|
|
/// ConstantFoldCall - Attempt to constant fold a call to the specified function
|
|
|
|
/// with the specified arguments, returning null if unsuccessful.
|
|
|
|
Constant *ConstantFoldCall(Function *F, const std::vector<Constant*> &Operands);
|
|
|
|
|
|
|
|
|
2002-05-07 18:52:48 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Local dead code elimination...
|
|
|
|
//
|
|
|
|
|
2002-09-06 02:19:25 +00:00
|
|
|
/// isInstructionTriviallyDead - Return true if the result produced by the
|
|
|
|
/// instruction is not used, and the instruction has no side effects.
|
|
|
|
///
|
2002-05-07 18:52:48 +00:00
|
|
|
bool isInstructionTriviallyDead(Instruction *I);
|
|
|
|
|
|
|
|
|
2002-09-06 02:19:25 +00:00
|
|
|
/// dceInstruction - Inspect the instruction at *BBI and figure out if it
|
|
|
|
/// isTriviallyDead. If so, remove the instruction and update the iterator to
|
|
|
|
/// point to the instruction that immediately succeeded the original
|
|
|
|
/// instruction.
|
|
|
|
///
|
2002-05-26 20:18:35 +00:00
|
|
|
bool dceInstruction(BasicBlock::iterator &BBI);
|
2002-05-07 18:52:48 +00:00
|
|
|
|
2003-12-19 05:56:28 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// PHI Instruction Simplification
|
|
|
|
//
|
|
|
|
|
|
|
|
/// hasConstantValue - If the specified PHI node always merges together the same
|
|
|
|
/// value, return the value, otherwise return null.
|
|
|
|
///
|
|
|
|
Value *hasConstantValue(PHINode *PN);
|
|
|
|
|
2002-05-07 18:52:48 +00:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Control Flow Graph Restructuring...
|
|
|
|
//
|
|
|
|
|
2002-09-06 02:19:25 +00:00
|
|
|
/// SimplifyCFG - This function is used to do simplification of a CFG. For
|
|
|
|
/// example, it adjusts branches to branches to eliminate the extra hop, it
|
|
|
|
/// eliminates unreachable basic blocks, and does other "peephole" optimization
|
|
|
|
/// of the CFG. It returns true if a modification was made, possibly deleting
|
|
|
|
/// the basic block that was pointed to.
|
|
|
|
///
|
|
|
|
/// WARNING: The entry node of a method may not be simplified.
|
|
|
|
///
|
2002-06-25 16:12:52 +00:00
|
|
|
bool SimplifyCFG(BasicBlock *BB);
|
2002-05-07 18:52:48 +00:00
|
|
|
|
2004-03-14 02:13:07 +00:00
|
|
|
/// DemoteRegToStack - This function takes a virtual register computed by an
|
2004-03-17 01:29:36 +00:00
|
|
|
/// Instruction and replaces it with a slot in the stack frame, allocated via
|
2004-03-14 02:13:07 +00:00
|
|
|
/// alloca. This allows the CFG to be changed around without fear of
|
|
|
|
/// invalidating the SSA information for the value. It returns the pointer to
|
|
|
|
/// the alloca inserted to create a stack slot for X.
|
|
|
|
///
|
|
|
|
AllocaInst *DemoteRegToStack(Instruction &X);
|
|
|
|
|
2003-11-11 22:41:34 +00:00
|
|
|
} // End llvm namespace
|
|
|
|
|
2002-05-07 18:52:48 +00:00
|
|
|
#endif
|