| Brian Gaeke | 03cac37 | 2004-04-25 07:04:49 +0000 | [diff] [blame] | 1 | //===- SparcV9PreSelection.cpp - Specialize LLVM code for SparcV9 ---------===// |
| John Criswell | 482202a | 2003-10-20 19:43:21 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file was developed by the LLVM research group and is distributed under |
| 6 | // the University of Illinois Open Source License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| Vikram S. Adve | e9ac29b | 2002-09-20 00:29:28 +0000 | [diff] [blame] | 9 | // |
| Brian Gaeke | 03cac37 | 2004-04-25 07:04:49 +0000 | [diff] [blame] | 10 | // This file defines the PreSelection pass which specializes LLVM code for |
| 11 | // the SparcV9 instruction selector, while remaining in legal portable LLVM |
| 12 | // form and preserving type information and type safety. This is meant to enable |
| 13 | // dataflow optimizations on SparcV9-specific operations such as accesses to |
| Vikram S. Adve | e9ac29b | 2002-09-20 00:29:28 +0000 | [diff] [blame] | 14 | // constants, globals, and array indexing. |
| 15 | // |
| 16 | //===----------------------------------------------------------------------===// |
| 17 | |
| Brian Gaeke | 94e95d2 | 2004-02-25 18:44:15 +0000 | [diff] [blame] | 18 | #include "SparcV9Internals.h" |
| Brian Gaeke | 64f51df | 2004-07-27 17:43:23 +0000 | [diff] [blame] | 19 | #include "SparcV9InstrSelectionSupport.h" |
| Vikram S. Adve | e9ac29b | 2002-09-20 00:29:28 +0000 | [diff] [blame] | 20 | #include "llvm/Constants.h" |
| Misha Brukman | 980d74c | 2003-10-22 04:51:36 +0000 | [diff] [blame] | 21 | #include "llvm/DerivedTypes.h" |
| Chris Lattner | 66a64fb | 2004-07-29 17:11:37 +0000 | [diff] [blame^] | 22 | #include "llvm/Instructions.h" |
| Misha Brukman | 88be700 | 2003-10-22 03:27:45 +0000 | [diff] [blame] | 23 | #include "llvm/Module.h" |
| Vikram S. Adve | e9ac29b | 2002-09-20 00:29:28 +0000 | [diff] [blame] | 24 | #include "llvm/Pass.h" |
| Misha Brukman | 88be700 | 2003-10-22 03:27:45 +0000 | [diff] [blame] | 25 | #include "llvm/Support/InstVisitor.h" |
| Chris Lattner | dfcf8e3 | 2004-04-04 20:44:05 +0000 | [diff] [blame] | 26 | #include "llvm/Support/GetElementPtrTypeIterator.h" |
| Misha Brukman | 88be700 | 2003-10-22 03:27:45 +0000 | [diff] [blame] | 27 | #include "llvm/Target/TargetInstrInfo.h" |
| 28 | #include "llvm/Target/TargetMachine.h" |
| 29 | #include "llvm/Transforms/Scalar.h" |
| Vikram S. Adve | 4ef6cce | 2002-10-13 00:01:57 +0000 | [diff] [blame] | 30 | #include <algorithm> |
| Chris Lattner | dfcf8e3 | 2004-04-04 20:44:05 +0000 | [diff] [blame] | 31 | using namespace llvm; |
| Brian Gaeke | 960707c | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 32 | |
| Vikram S. Adve | e9ac29b | 2002-09-20 00:29:28 +0000 | [diff] [blame] | 33 | namespace { |
| Vikram S. Adve | e9ac29b | 2002-09-20 00:29:28 +0000 | [diff] [blame] | 34 | |
| 35 | //===--------------------------------------------------------------------===// |
| Brian Gaeke | 03cac37 | 2004-04-25 07:04:49 +0000 | [diff] [blame] | 36 | // PreSelection Pass - Specialize LLVM code for the SparcV9 instr. selector. |
| Vikram S. Adve | e9ac29b | 2002-09-20 00:29:28 +0000 | [diff] [blame] | 37 | // |
| Misha Brukman | 81c748c | 2003-11-07 17:31:22 +0000 | [diff] [blame] | 38 | class PreSelection : public FunctionPass, public InstVisitor<PreSelection> { |
| Vikram S. Adve | 82dca37 | 2003-06-05 21:12:56 +0000 | [diff] [blame] | 39 | const TargetInstrInfo &instrInfo; |
| Vikram S. Adve | e9ac29b | 2002-09-20 00:29:28 +0000 | [diff] [blame] | 40 | |
| 41 | public: |
| Chris Lattner | 2e2a0ed | 2003-10-21 14:49:19 +0000 | [diff] [blame] | 42 | PreSelection(const TargetMachine &T) |
| Chris Lattner | 82baa9c | 2004-06-02 05:55:25 +0000 | [diff] [blame] | 43 | : instrInfo(*T.getInstrInfo()) {} |
| Vikram S. Adve | e9ac29b | 2002-09-20 00:29:28 +0000 | [diff] [blame] | 44 | |
| Misha Brukman | 81c748c | 2003-11-07 17:31:22 +0000 | [diff] [blame] | 45 | // runOnFunction - apply this pass to each Function |
| 46 | bool runOnFunction(Function &F) { |
| 47 | visit(F); |
| Chris Lattner | 2e2a0ed | 2003-10-21 14:49:19 +0000 | [diff] [blame] | 48 | return true; |
| Vikram S. Adve | e9ac29b | 2002-09-20 00:29:28 +0000 | [diff] [blame] | 49 | } |
| Brian Gaeke | c028910 | 2004-03-11 19:23:15 +0000 | [diff] [blame] | 50 | const char *getPassName() const { return "SparcV9 Instr. Pre-selection"; } |
| Vikram S. Adve | e9ac29b | 2002-09-20 00:29:28 +0000 | [diff] [blame] | 51 | |
| 52 | // These methods do the actual work of specializing code |
| 53 | void visitInstruction(Instruction &I); // common work for every instr. |
| 54 | void visitGetElementPtrInst(GetElementPtrInst &I); |
| Vikram S. Adve | ba6f8e2 | 2003-05-31 07:34:57 +0000 | [diff] [blame] | 55 | void visitCallInst(CallInst &I); |
| Chris Lattner | 4439aee | 2003-10-21 16:09:23 +0000 | [diff] [blame] | 56 | void visitPHINode(PHINode &PN); |
| Vikram S. Adve | e9ac29b | 2002-09-20 00:29:28 +0000 | [diff] [blame] | 57 | |
| 58 | // Helper functions for visiting operands of every instruction |
| Vikram S. Adve | ba6f8e2 | 2003-05-31 07:34:57 +0000 | [diff] [blame] | 59 | // |
| 60 | // visitOperands() works on every operand in [firstOp, lastOp-1]. |
| 61 | // If lastOp==0, lastOp defaults to #operands or #incoming Phi values. |
| 62 | // |
| 63 | // visitOneOperand() does all the work for one operand. |
| 64 | // |
| Chris Lattner | 898a42a | 2003-10-21 16:06:07 +0000 | [diff] [blame] | 65 | void visitOperands(Instruction &I, int firstOp=0); |
| Vikram S. Adve | ba6f8e2 | 2003-05-31 07:34:57 +0000 | [diff] [blame] | 66 | void visitOneOperand(Instruction &I, Value* Op, unsigned opNum, |
| 67 | Instruction& insertBefore); |
| Vikram S. Adve | e9ac29b | 2002-09-20 00:29:28 +0000 | [diff] [blame] | 68 | }; |
| Chris Lattner | 13cafd0 | 2003-04-24 18:35:51 +0000 | [diff] [blame] | 69 | |
| Misha Brukman | 81c748c | 2003-11-07 17:31:22 +0000 | [diff] [blame] | 70 | #if 0 |
| Chris Lattner | 13cafd0 | 2003-04-24 18:35:51 +0000 | [diff] [blame] | 71 | // Register the pass... |
| Misha Brukman | 81c748c | 2003-11-07 17:31:22 +0000 | [diff] [blame] | 72 | RegisterPass<PreSelection> X("preselect", |
| 73 | "Specialize LLVM code for a target machine" |
| 74 | createPreselectionPass); |
| 75 | #endif |
| Brian Gaeke | 960707c | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 76 | |
| Vikram S. Adve | e9ac29b | 2002-09-20 00:29:28 +0000 | [diff] [blame] | 77 | } // end anonymous namespace |
| 78 | |
| 79 | |
| Vikram S. Adve | 4ef6cce | 2002-10-13 00:01:57 +0000 | [diff] [blame] | 80 | //------------------------------------------------------------------------------ |
| 81 | // Helper functions used by methods of class PreSelection |
| 82 | //------------------------------------------------------------------------------ |
| 83 | |
| 84 | |
| 85 | // getGlobalAddr(): Put address of a global into a v. register. |
| Misha Brukman | 88be700 | 2003-10-22 03:27:45 +0000 | [diff] [blame] | 86 | static GetElementPtrInst* getGlobalAddr(Value* ptr, Instruction& insertBefore) { |
| Vikram S. Adve | 4ef6cce | 2002-10-13 00:01:57 +0000 | [diff] [blame] | 87 | |
| Chris Lattner | 46666cf | 2003-06-04 01:24:40 +0000 | [diff] [blame] | 88 | return (isa<GlobalVariable>(ptr)) |
| Vikram S. Adve | e9ac29b | 2002-09-20 00:29:28 +0000 | [diff] [blame] | 89 | ? new GetElementPtrInst(ptr, |
| 90 | std::vector<Value*>(1, ConstantSInt::get(Type::LongTy, 0U)), |
| Brian Gaeke | ae6fb8a | 2004-06-23 21:41:32 +0000 | [diff] [blame] | 91 | "addrOfGlobal:" + ptr->getName(), &insertBefore) |
| Vikram S. Adve | e9ac29b | 2002-09-20 00:29:28 +0000 | [diff] [blame] | 92 | : NULL; |
| 93 | } |
| 94 | |
| Misha Brukman | 426275b | 2003-12-17 22:06:08 +0000 | [diff] [blame] | 95 | // Wrapper on Constant::classof to use in find_if |
| Misha Brukman | 88be700 | 2003-10-22 03:27:45 +0000 | [diff] [blame] | 96 | inline static bool nonConstant(const Use& U) { |
| Vikram S. Adve | 4ef6cce | 2002-10-13 00:01:57 +0000 | [diff] [blame] | 97 | return ! isa<Constant>(U); |
| 98 | } |
| 99 | |
| Vikram S. Adve | 4ef6cce | 2002-10-13 00:01:57 +0000 | [diff] [blame] | 100 | static Instruction* DecomposeConstantExpr(ConstantExpr* CE, |
| 101 | Instruction& insertBefore) |
| 102 | { |
| 103 | Value *getArg1, *getArg2; |
| Brian Gaeke | cc24411 | 2004-04-02 17:52:29 +0000 | [diff] [blame] | 104 | |
| Vikram S. Adve | 4ef6cce | 2002-10-13 00:01:57 +0000 | [diff] [blame] | 105 | switch(CE->getOpcode()) |
| 106 | { |
| 107 | case Instruction::Cast: |
| 108 | getArg1 = CE->getOperand(0); |
| 109 | if (ConstantExpr* CEarg = dyn_cast<ConstantExpr>(getArg1)) |
| 110 | getArg1 = DecomposeConstantExpr(CEarg, insertBefore); |
| 111 | return new CastInst(getArg1, CE->getType(), "constantCast",&insertBefore); |
| 112 | |
| 113 | case Instruction::GetElementPtr: |
| Chris Lattner | fb34004 | 2002-10-27 19:09:51 +0000 | [diff] [blame] | 114 | assert(find_if(CE->op_begin()+1, CE->op_end(),nonConstant) == CE->op_end() |
| Vikram S. Adve | 4ef6cce | 2002-10-13 00:01:57 +0000 | [diff] [blame] | 115 | && "All indices in ConstantExpr getelementptr must be constant!"); |
| Vikram S. Adve | 4ef6cce | 2002-10-13 00:01:57 +0000 | [diff] [blame] | 116 | getArg1 = CE->getOperand(0); |
| 117 | if (ConstantExpr* CEarg = dyn_cast<ConstantExpr>(getArg1)) |
| 118 | getArg1 = DecomposeConstantExpr(CEarg, insertBefore); |
| 119 | else if (GetElementPtrInst* gep = getGlobalAddr(getArg1, insertBefore)) |
| 120 | getArg1 = gep; |
| 121 | return new GetElementPtrInst(getArg1, |
| Chris Lattner | fb34004 | 2002-10-27 19:09:51 +0000 | [diff] [blame] | 122 | std::vector<Value*>(CE->op_begin()+1, CE->op_end()), |
| Brian Gaeke | ae6fb8a | 2004-06-23 21:41:32 +0000 | [diff] [blame] | 123 | "constantGEP:" + getArg1->getName(), &insertBefore); |
| Brian Gaeke | cc24411 | 2004-04-02 17:52:29 +0000 | [diff] [blame] | 124 | |
| 125 | case Instruction::Select: { |
| 126 | Value *C, *S1, *S2; |
| 127 | C = CE->getOperand (0); |
| 128 | if (ConstantExpr* CEarg = dyn_cast<ConstantExpr> (C)) |
| 129 | C = DecomposeConstantExpr (CEarg, insertBefore); |
| 130 | S1 = CE->getOperand (1); |
| 131 | if (ConstantExpr* CEarg = dyn_cast<ConstantExpr> (S1)) |
| 132 | S1 = DecomposeConstantExpr (CEarg, insertBefore); |
| 133 | S2 = CE->getOperand (2); |
| 134 | if (ConstantExpr* CEarg = dyn_cast<ConstantExpr> (S2)) |
| 135 | S2 = DecomposeConstantExpr (CEarg, insertBefore); |
| Brian Gaeke | 8931345 | 2004-04-07 18:31:47 +0000 | [diff] [blame] | 136 | return new SelectInst (C, S1, S2, "constantSelect", &insertBefore); |
| Brian Gaeke | cc24411 | 2004-04-02 17:52:29 +0000 | [diff] [blame] | 137 | } |
| 138 | |
| Vikram S. Adve | 4ef6cce | 2002-10-13 00:01:57 +0000 | [diff] [blame] | 139 | default: // must be a binary operator |
| Chris Lattner | 69ce867 | 2002-10-13 19:39:16 +0000 | [diff] [blame] | 140 | assert(CE->getOpcode() >= Instruction::BinaryOpsBegin && |
| 141 | CE->getOpcode() < Instruction::BinaryOpsEnd && |
| Brian Gaeke | cc24411 | 2004-04-02 17:52:29 +0000 | [diff] [blame] | 142 | "Unhandled opcode in ConstantExpr"); |
| Vikram S. Adve | 4ef6cce | 2002-10-13 00:01:57 +0000 | [diff] [blame] | 143 | getArg1 = CE->getOperand(0); |
| 144 | if (ConstantExpr* CEarg = dyn_cast<ConstantExpr>(getArg1)) |
| 145 | getArg1 = DecomposeConstantExpr(CEarg, insertBefore); |
| 146 | getArg2 = CE->getOperand(1); |
| 147 | if (ConstantExpr* CEarg = dyn_cast<ConstantExpr>(getArg2)) |
| 148 | getArg2 = DecomposeConstantExpr(CEarg, insertBefore); |
| 149 | return BinaryOperator::create((Instruction::BinaryOps) CE->getOpcode(), |
| 150 | getArg1, getArg2, |
| 151 | "constantBinaryOp", &insertBefore); |
| 152 | } |
| 153 | } |
| 154 | |
| Brian Gaeke | 28f75c2 | 2004-07-27 21:11:20 +0000 | [diff] [blame] | 155 | static inline bool ConstantTypeMustBeLoaded(const Type* CVT) { |
| 156 | assert(CVT->isPrimitiveType() || isa<PointerType>(CVT)); |
| 157 | return !(CVT->isIntegral() || isa<PointerType>(CVT)); |
| 158 | } |
| Vikram S. Adve | 4ef6cce | 2002-10-13 00:01:57 +0000 | [diff] [blame] | 159 | |
| Vikram S. Adve | e9ac29b | 2002-09-20 00:29:28 +0000 | [diff] [blame] | 160 | //------------------------------------------------------------------------------ |
| 161 | // Instruction visitor methods to perform instruction-specific operations |
| 162 | //------------------------------------------------------------------------------ |
| Vikram S. Adve | 82dca37 | 2003-06-05 21:12:56 +0000 | [diff] [blame] | 163 | inline void |
| 164 | PreSelection::visitOneOperand(Instruction &I, Value* Op, unsigned opNum, |
| 165 | Instruction& insertBefore) |
| 166 | { |
| Vikram S. Adve | cf952cb | 2003-07-02 01:23:15 +0000 | [diff] [blame] | 167 | assert(&insertBefore != NULL && "Must have instruction to insert before."); |
| 168 | |
| Vikram S. Adve | 82dca37 | 2003-06-05 21:12:56 +0000 | [diff] [blame] | 169 | if (GetElementPtrInst* gep = getGlobalAddr(Op, insertBefore)) { |
| 170 | I.setOperand(opNum, gep); // replace global operand |
| Vikram S. Adve | cf952cb | 2003-07-02 01:23:15 +0000 | [diff] [blame] | 171 | return; // nothing more to do for this op. |
| Vikram S. Adve | 82dca37 | 2003-06-05 21:12:56 +0000 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | Constant* CV = dyn_cast<Constant>(Op); |
| 175 | if (CV == NULL) |
| 176 | return; |
| 177 | |
| Misha Brukman | 88be700 | 2003-10-22 03:27:45 +0000 | [diff] [blame] | 178 | if (ConstantExpr* CE = dyn_cast<ConstantExpr>(CV)) { |
| 179 | // load-time constant: factor it out so we optimize as best we can |
| 180 | Instruction* computeConst = DecomposeConstantExpr(CE, insertBefore); |
| 181 | I.setOperand(opNum, computeConst); // replace expr operand with result |
| Brian Gaeke | 28f75c2 | 2004-07-27 21:11:20 +0000 | [diff] [blame] | 182 | } else if (ConstantTypeMustBeLoaded(CV->getType())) { |
| Misha Brukman | 88be700 | 2003-10-22 03:27:45 +0000 | [diff] [blame] | 183 | // load address of constant into a register, then load the constant |
| Misha Brukman | 81c748c | 2003-11-07 17:31:22 +0000 | [diff] [blame] | 184 | // this is now done during instruction selection |
| 185 | // the constant will live in the MachineConstantPool later on |
| Brian Gaeke | 64f51df | 2004-07-27 17:43:23 +0000 | [diff] [blame] | 186 | } else if (ConstantMayNotFitInImmedField(CV, &I)) { |
| Misha Brukman | 88be700 | 2003-10-22 03:27:45 +0000 | [diff] [blame] | 187 | // put the constant into a virtual register using a cast |
| 188 | CastInst* castI = new CastInst(CV, CV->getType(), "copyConst", |
| 189 | &insertBefore); |
| 190 | I.setOperand(opNum, castI); // replace operand with copy in v.reg. |
| 191 | } |
| Vikram S. Adve | 82dca37 | 2003-06-05 21:12:56 +0000 | [diff] [blame] | 192 | } |
| 193 | |
| Misha Brukman | 426275b | 2003-12-17 22:06:08 +0000 | [diff] [blame] | 194 | /// visitOperands - transform individual operands of all instructions: |
| 195 | /// -- Load "large" int constants into a virtual register. What is large |
| 196 | /// depends on the type of instruction and on the target architecture. |
| 197 | /// -- For any constants that cannot be put in an immediate field, |
| 198 | /// load address into virtual register first, and then load the constant. |
| 199 | /// |
| 200 | /// firstOp and lastOp can be used to skip leading and trailing operands. |
| 201 | /// If lastOp is 0, it defaults to #operands or #incoming Phi values. |
| 202 | /// |
| Chris Lattner | 898a42a | 2003-10-21 16:06:07 +0000 | [diff] [blame] | 203 | inline void PreSelection::visitOperands(Instruction &I, int firstOp) { |
| Vikram S. Adve | 82dca37 | 2003-06-05 21:12:56 +0000 | [diff] [blame] | 204 | // For any instruction other than PHI, copies go just before the instr. |
| Chris Lattner | 4439aee | 2003-10-21 16:09:23 +0000 | [diff] [blame] | 205 | for (unsigned i = firstOp, e = I.getNumOperands(); i != e; ++i) |
| 206 | visitOneOperand(I, I.getOperand(i), i, I); |
| 207 | } |
| 208 | |
| 209 | |
| 210 | void PreSelection::visitPHINode(PHINode &PN) { |
| Vikram S. Adve | 82dca37 | 2003-06-05 21:12:56 +0000 | [diff] [blame] | 211 | // For a PHI, operand copies must be before the terminator of the |
| 212 | // appropriate predecessor basic block. Remaining logic is simple |
| 213 | // so just handle PHIs and other instructions separately. |
| 214 | // |
| Chris Lattner | 4439aee | 2003-10-21 16:09:23 +0000 | [diff] [blame] | 215 | for (unsigned i = 0, e = PN.getNumIncomingValues(); i != e; ++i) |
| Chris Lattner | 73d9355 | 2003-10-21 17:22:23 +0000 | [diff] [blame] | 216 | visitOneOperand(PN, PN.getIncomingValue(i), |
| Chris Lattner | 4439aee | 2003-10-21 16:09:23 +0000 | [diff] [blame] | 217 | PN.getOperandNumForIncomingValue(i), |
| 218 | *PN.getIncomingBlock(i)->getTerminator()); |
| 219 | // do not call visitOperands! |
| Vikram S. Adve | 82dca37 | 2003-06-05 21:12:56 +0000 | [diff] [blame] | 220 | } |
| 221 | |
| Vikram S. Adve | e9ac29b | 2002-09-20 00:29:28 +0000 | [diff] [blame] | 222 | // Common work for *all* instructions. This needs to be called explicitly |
| 223 | // by other visit<InstructionType> functions. |
| Misha Brukman | 88be700 | 2003-10-22 03:27:45 +0000 | [diff] [blame] | 224 | inline void PreSelection::visitInstruction(Instruction &I) { |
| Vikram S. Adve | e9ac29b | 2002-09-20 00:29:28 +0000 | [diff] [blame] | 225 | visitOperands(I); // Perform operand transformations |
| 226 | } |
| 227 | |
| Vikram S. Adve | e9ac29b | 2002-09-20 00:29:28 +0000 | [diff] [blame] | 228 | // GetElementPtr instructions: check if pointer is a global |
| Misha Brukman | 88be700 | 2003-10-22 03:27:45 +0000 | [diff] [blame] | 229 | void PreSelection::visitGetElementPtrInst(GetElementPtrInst &I) { |
| Vikram S. Adve | cf952cb | 2003-07-02 01:23:15 +0000 | [diff] [blame] | 230 | Instruction* curI = &I; |
| Vikram S. Adve | e9ac29b | 2002-09-20 00:29:28 +0000 | [diff] [blame] | 231 | |
| Chris Lattner | dfcf8e3 | 2004-04-04 20:44:05 +0000 | [diff] [blame] | 232 | // The Sparc backend doesn't handle array indexes that are not long types, so |
| 233 | // insert a cast from whatever it is to long, if the sequential type index is |
| 234 | // not a long already. |
| 235 | unsigned Idx = 1; |
| 236 | for (gep_type_iterator TI = gep_type_begin(I), E = gep_type_end(I); TI != E; |
| 237 | ++TI, ++Idx) |
| 238 | if (isa<SequentialType>(*TI) && |
| 239 | I.getOperand(Idx)->getType() != Type::LongTy) { |
| 240 | Value *Op = I.getOperand(Idx); |
| 241 | if (Op->getType()->isUnsigned()) // Must sign extend! |
| 242 | Op = new CastInst(Op, Op->getType()->getSignedVersion(), "v9", &I); |
| 243 | if (Op->getType() != Type::LongTy) |
| 244 | Op = new CastInst(Op, Type::LongTy, "v9", &I); |
| 245 | I.setOperand(Idx, Op); |
| 246 | } |
| 247 | |
| 248 | |
| Vikram S. Adve | e9ac29b | 2002-09-20 00:29:28 +0000 | [diff] [blame] | 249 | // Decompose multidimensional array references |
| Vikram S. Adve | cf952cb | 2003-07-02 01:23:15 +0000 | [diff] [blame] | 250 | if (I.getNumIndices() >= 2) { |
| 251 | // DecomposeArrayRef() replaces I and deletes it, if successful, |
| 252 | // so remember predecessor in order to find the replacement instruction. |
| 253 | // Also remember the basic block in case there is no predecessor. |
| 254 | Instruction* prevI = I.getPrev(); |
| 255 | BasicBlock* bb = I.getParent(); |
| 256 | if (DecomposeArrayRef(&I)) |
| 257 | // first instr. replacing I |
| 258 | curI = cast<GetElementPtrInst>(prevI? prevI->getNext() : &bb->front()); |
| 259 | } |
| Vikram S. Adve | e9ac29b | 2002-09-20 00:29:28 +0000 | [diff] [blame] | 260 | |
| 261 | // Perform other transformations common to all instructions |
| Vikram S. Adve | cf952cb | 2003-07-02 01:23:15 +0000 | [diff] [blame] | 262 | visitInstruction(*curI); |
| Vikram S. Adve | e9ac29b | 2002-09-20 00:29:28 +0000 | [diff] [blame] | 263 | } |
| 264 | |
| Misha Brukman | 88be700 | 2003-10-22 03:27:45 +0000 | [diff] [blame] | 265 | void PreSelection::visitCallInst(CallInst &I) { |
| Vikram S. Adve | ba6f8e2 | 2003-05-31 07:34:57 +0000 | [diff] [blame] | 266 | // Tell visitOperands to ignore the function name if this is a direct call. |
| 267 | visitOperands(I, (/*firstOp=*/ I.getCalledFunction()? 1 : 0)); |
| 268 | } |
| 269 | |
| Misha Brukman | 426275b | 2003-12-17 22:06:08 +0000 | [diff] [blame] | 270 | /// createPreSelectionPass - Public entry point for the PreSelection pass |
| 271 | /// |
| Chris Lattner | dfcf8e3 | 2004-04-04 20:44:05 +0000 | [diff] [blame] | 272 | FunctionPass* llvm::createPreSelectionPass(const TargetMachine &TM) { |
| Misha Brukman | 81c748c | 2003-11-07 17:31:22 +0000 | [diff] [blame] | 273 | return new PreSelection(TM); |
| Vikram S. Adve | e9ac29b | 2002-09-20 00:29:28 +0000 | [diff] [blame] | 274 | } |