Local.h revision 7ed47a13356daed2a34cd2209a31f92552e3bdd8
148486893f46d2e12e926682a3ecb908716bc66c4Chris Lattner//===-- Local.h - Functions to perform local transformations ----*- C++ -*-===// 234695381d626485a560594f162701088079589dfMisha Brukman// 36fbcc26f1460eaee4e0eb8b426fc1ff0c7af11beJohn Criswell// The LLVM Compiler Infrastructure 46fbcc26f1460eaee4e0eb8b426fc1ff0c7af11beJohn Criswell// 57ed47a13356daed2a34cd2209a31f92552e3bdd8Chris Lattner// This file is distributed under the University of Illinois Open Source 67ed47a13356daed2a34cd2209a31f92552e3bdd8Chris Lattner// License. See LICENSE.TXT for details. 734695381d626485a560594f162701088079589dfMisha Brukman// 86fbcc26f1460eaee4e0eb8b426fc1ff0c7af11beJohn Criswell//===----------------------------------------------------------------------===// 9148a0bfcea5d3267eac02613cfcc8b5fe8894f2cChris Lattner// 10148a0bfcea5d3267eac02613cfcc8b5fe8894f2cChris Lattner// This family of functions perform various local transformations to the 11148a0bfcea5d3267eac02613cfcc8b5fe8894f2cChris Lattner// program. 12148a0bfcea5d3267eac02613cfcc8b5fe8894f2cChris Lattner// 13148a0bfcea5d3267eac02613cfcc8b5fe8894f2cChris Lattner//===----------------------------------------------------------------------===// 14148a0bfcea5d3267eac02613cfcc8b5fe8894f2cChris Lattner 15148a0bfcea5d3267eac02613cfcc8b5fe8894f2cChris Lattner#ifndef LLVM_TRANSFORMS_UTILS_LOCAL_H 16148a0bfcea5d3267eac02613cfcc8b5fe8894f2cChris Lattner#define LLVM_TRANSFORMS_UTILS_LOCAL_H 17148a0bfcea5d3267eac02613cfcc8b5fe8894f2cChris Lattner 18148a0bfcea5d3267eac02613cfcc8b5fe8894f2cChris Lattner#include "llvm/Function.h" 19d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke 20d0fde30ce850b78371fd1386338350591f9ff494Brian Gaekenamespace llvm { 21d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke 223e57cb98bde04a65623493738d51f2a41e601748Chris Lattnerclass Pass; 23abbc2dd77908f146f73f4cd1abfdfe47faacf43dChris Lattnerclass PHINode; 24cbf99ee973b6c6e6cd9537dae12031382783bc61Chris Lattnerclass AllocaInst; 25c5406b55d58b7378822d5f6316bf253ad0eaa82dChris Lattnerclass ConstantExpr; 2673259caa44b03206d1e39e77a7aa375250b1a193Chris Lattnerclass TargetData; 27148a0bfcea5d3267eac02613cfcc8b5fe8894f2cChris Lattner 28148a0bfcea5d3267eac02613cfcc8b5fe8894f2cChris Lattner//===----------------------------------------------------------------------===// 2982c89b9f3a9b88bb63ce13b09b4f27fbb72f66fcMisha Brukman// Local constant propagation... 30148a0bfcea5d3267eac02613cfcc8b5fe8894f2cChris Lattner// 31148a0bfcea5d3267eac02613cfcc8b5fe8894f2cChris Lattner 3282c89b9f3a9b88bb63ce13b09b4f27fbb72f66fcMisha Brukman/// doConstantPropagation - Constant prop a specific instruction. Returns true 3382c89b9f3a9b88bb63ce13b09b4f27fbb72f66fcMisha Brukman/// and potentially moves the iterator if constant propagation was performed. 343e57cb98bde04a65623493738d51f2a41e601748Chris Lattner/// 3573259caa44b03206d1e39e77a7aa375250b1a193Chris Lattnerbool doConstantPropagation(BasicBlock::iterator &I, const TargetData *TD = 0); 36148a0bfcea5d3267eac02613cfcc8b5fe8894f2cChris Lattner 373e57cb98bde04a65623493738d51f2a41e601748Chris Lattner/// ConstantFoldTerminator - If a terminator instruction is predicated on a 383e57cb98bde04a65623493738d51f2a41e601748Chris Lattner/// constant value, convert it into an unconditional branch to the constant 393e57cb98bde04a65623493738d51f2a41e601748Chris Lattner/// destination. This is a nontrivial operation because the successors of this 403e57cb98bde04a65623493738d51f2a41e601748Chris Lattner/// basic block must have their PHI nodes updated. 413e57cb98bde04a65623493738d51f2a41e601748Chris Lattner/// 4276ae3445f81164aaff9f95123426109c119f27c0Chris Lattnerbool ConstantFoldTerminator(BasicBlock *BB); 43148a0bfcea5d3267eac02613cfcc8b5fe8894f2cChris Lattner 44148a0bfcea5d3267eac02613cfcc8b5fe8894f2cChris Lattner//===----------------------------------------------------------------------===// 45148a0bfcea5d3267eac02613cfcc8b5fe8894f2cChris Lattner// Local dead code elimination... 46148a0bfcea5d3267eac02613cfcc8b5fe8894f2cChris Lattner// 47148a0bfcea5d3267eac02613cfcc8b5fe8894f2cChris Lattner 483e57cb98bde04a65623493738d51f2a41e601748Chris Lattner/// isInstructionTriviallyDead - Return true if the result produced by the 493e57cb98bde04a65623493738d51f2a41e601748Chris Lattner/// instruction is not used, and the instruction has no side effects. 503e57cb98bde04a65623493738d51f2a41e601748Chris Lattner/// 51148a0bfcea5d3267eac02613cfcc8b5fe8894f2cChris Lattnerbool isInstructionTriviallyDead(Instruction *I); 52148a0bfcea5d3267eac02613cfcc8b5fe8894f2cChris Lattner 53148a0bfcea5d3267eac02613cfcc8b5fe8894f2cChris Lattner 543e57cb98bde04a65623493738d51f2a41e601748Chris Lattner/// dceInstruction - Inspect the instruction at *BBI and figure out if it 553e57cb98bde04a65623493738d51f2a41e601748Chris Lattner/// isTriviallyDead. If so, remove the instruction and update the iterator to 563e57cb98bde04a65623493738d51f2a41e601748Chris Lattner/// point to the instruction that immediately succeeded the original 573e57cb98bde04a65623493738d51f2a41e601748Chris Lattner/// instruction. 583e57cb98bde04a65623493738d51f2a41e601748Chris Lattner/// 59a338016c7cba2c9cd9d6ecb4c57cedae22ff37e4Chris Lattnerbool dceInstruction(BasicBlock::iterator &BBI); 60148a0bfcea5d3267eac02613cfcc8b5fe8894f2cChris Lattner 61abbc2dd77908f146f73f4cd1abfdfe47faacf43dChris Lattner//===----------------------------------------------------------------------===// 62148a0bfcea5d3267eac02613cfcc8b5fe8894f2cChris Lattner// Control Flow Graph Restructuring... 63148a0bfcea5d3267eac02613cfcc8b5fe8894f2cChris Lattner// 64148a0bfcea5d3267eac02613cfcc8b5fe8894f2cChris Lattner 653e57cb98bde04a65623493738d51f2a41e601748Chris Lattner/// SimplifyCFG - This function is used to do simplification of a CFG. For 663e57cb98bde04a65623493738d51f2a41e601748Chris Lattner/// example, it adjusts branches to branches to eliminate the extra hop, it 673e57cb98bde04a65623493738d51f2a41e601748Chris Lattner/// eliminates unreachable basic blocks, and does other "peephole" optimization 683e57cb98bde04a65623493738d51f2a41e601748Chris Lattner/// of the CFG. It returns true if a modification was made, possibly deleting 693e57cb98bde04a65623493738d51f2a41e601748Chris Lattner/// the basic block that was pointed to. 703e57cb98bde04a65623493738d51f2a41e601748Chris Lattner/// 713e57cb98bde04a65623493738d51f2a41e601748Chris Lattner/// WARNING: The entry node of a method may not be simplified. 723e57cb98bde04a65623493738d51f2a41e601748Chris Lattner/// 7318961504fc2b299578dba817900a0696cf3ccc4dChris Lattnerbool SimplifyCFG(BasicBlock *BB); 74148a0bfcea5d3267eac02613cfcc8b5fe8894f2cChris Lattner 75cbf99ee973b6c6e6cd9537dae12031382783bc61Chris Lattner/// DemoteRegToStack - This function takes a virtual register computed by an 768f71b63bead24de7acc6fe7f0487bf56da22d745Chris Lattner/// Instruction and replaces it with a slot in the stack frame, allocated via 77cbf99ee973b6c6e6cd9537dae12031382783bc61Chris Lattner/// alloca. This allows the CFG to be changed around without fear of 78cbf99ee973b6c6e6cd9537dae12031382783bc61Chris Lattner/// invalidating the SSA information for the value. It returns the pointer to 79cbf99ee973b6c6e6cd9537dae12031382783bc61Chris Lattner/// the alloca inserted to create a stack slot for X. 80cbf99ee973b6c6e6cd9537dae12031382783bc61Chris Lattner/// 81a024e8cedab928403818ac79e899cdae2a356c56Anton KorobeynikovAllocaInst *DemoteRegToStack(Instruction &X, bool VolatileLoads = false, 82a024e8cedab928403818ac79e899cdae2a356c56Anton Korobeynikov Instruction *AllocaPoint = NULL); 83cbf99ee973b6c6e6cd9537dae12031382783bc61Chris Lattner 8408d14d2469c4f0465f610a204353220ee2ccde9cTanya Lattner/// DemotePHIToStack - This function takes a virtual register computed by a phi 8508d14d2469c4f0465f610a204353220ee2ccde9cTanya Lattner/// node and replaces it with a slot in the stack frame, allocated via alloca. 8608d14d2469c4f0465f610a204353220ee2ccde9cTanya Lattner/// The phi node is deleted and it returns the pointer to the alloca inserted. 87a024e8cedab928403818ac79e899cdae2a356c56Anton KorobeynikovAllocaInst *DemotePHIToStack(PHINode *P, Instruction *AllocaPoint = NULL); 8808d14d2469c4f0465f610a204353220ee2ccde9cTanya Lattner 89d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke} // End llvm namespace 90d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke 91148a0bfcea5d3267eac02613cfcc8b5fe8894f2cChris Lattner#endif 92