Vikram S. Adve | 243dd45 | 2001-09-18 13:03:13 +0000 | [diff] [blame] | 1 | // $Id$ |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 2 | //*************************************************************************** |
| 3 | // File: |
| 4 | // SparcInstrSelection.cpp |
| 5 | // |
| 6 | // Purpose: |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 7 | // BURS instruction selection for SPARC V9 architecture. |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 8 | // |
| 9 | // History: |
| 10 | // 7/02/01 - Vikram Adve - Created |
| 11 | //**************************************************************************/ |
| 12 | |
| 13 | #include "SparcInternals.h" |
Vikram S. Adve | 7fe2787 | 2001-10-18 00:26:20 +0000 | [diff] [blame] | 14 | #include "SparcInstrSelectionSupport.h" |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 15 | #include "SparcRegClassInfo.h" |
Vikram S. Adve | 8557b22 | 2001-10-10 20:56:33 +0000 | [diff] [blame] | 16 | #include "llvm/CodeGen/InstrSelectionSupport.h" |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 17 | #include "llvm/CodeGen/MachineInstr.h" |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 18 | #include "llvm/CodeGen/MachineInstrAnnot.h" |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 19 | #include "llvm/CodeGen/InstrForest.h" |
| 20 | #include "llvm/CodeGen/InstrSelection.h" |
Chris Lattner | 9c46108 | 2002-02-03 07:50:56 +0000 | [diff] [blame] | 21 | #include "llvm/CodeGen/MachineCodeForMethod.h" |
| 22 | #include "llvm/CodeGen/MachineCodeForInstruction.h" |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 23 | #include "llvm/DerivedTypes.h" |
| 24 | #include "llvm/iTerminators.h" |
| 25 | #include "llvm/iMemory.h" |
| 26 | #include "llvm/iOther.h" |
| 27 | #include "llvm/BasicBlock.h" |
Chris Lattner | 2fbfdcf | 2002-04-07 20:49:59 +0000 | [diff] [blame] | 28 | #include "llvm/Function.h" |
Chris Lattner | 31bcdb8 | 2002-04-28 19:55:58 +0000 | [diff] [blame] | 29 | #include "llvm/Constants.h" |
Chris Lattner | cee8f9a | 2001-11-27 00:03:19 +0000 | [diff] [blame] | 30 | #include "Support/MathExtras.h" |
Chris Lattner | 749655f | 2001-10-13 06:54:30 +0000 | [diff] [blame] | 31 | #include <math.h> |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 32 | using std::vector; |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 33 | |
| 34 | //************************* Forward Declarations ***************************/ |
| 35 | |
| 36 | |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 37 | static void SetMemOperands_Internal (vector<MachineInstr*>& mvec, |
| 38 | vector<MachineInstr*>::iterator mvecI, |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 39 | const InstructionNode* vmInstrNode, |
| 40 | Value* ptrVal, |
Vikram S. Adve | fd3900a | 2002-03-24 03:33:02 +0000 | [diff] [blame] | 41 | std::vector<Value*>& idxVec, |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 42 | bool allConstantIndices, |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 43 | const TargetMachine& target); |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 44 | |
| 45 | |
| 46 | //************************ Internal Functions ******************************/ |
| 47 | |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 48 | |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 49 | static inline MachineOpCode |
| 50 | ChooseBprInstruction(const InstructionNode* instrNode) |
| 51 | { |
| 52 | MachineOpCode opCode; |
| 53 | |
| 54 | Instruction* setCCInstr = |
| 55 | ((InstructionNode*) instrNode->leftChild())->getInstruction(); |
| 56 | |
| 57 | switch(setCCInstr->getOpcode()) |
| 58 | { |
| 59 | case Instruction::SetEQ: opCode = BRZ; break; |
| 60 | case Instruction::SetNE: opCode = BRNZ; break; |
| 61 | case Instruction::SetLE: opCode = BRLEZ; break; |
| 62 | case Instruction::SetGE: opCode = BRGEZ; break; |
| 63 | case Instruction::SetLT: opCode = BRLZ; break; |
| 64 | case Instruction::SetGT: opCode = BRGZ; break; |
| 65 | default: |
| 66 | assert(0 && "Unrecognized VM instruction!"); |
| 67 | opCode = INVALID_OPCODE; |
| 68 | break; |
| 69 | } |
| 70 | |
| 71 | return opCode; |
| 72 | } |
| 73 | |
| 74 | |
| 75 | static inline MachineOpCode |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 76 | ChooseBpccInstruction(const InstructionNode* instrNode, |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 77 | const BinaryOperator* setCCInstr) |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 78 | { |
| 79 | MachineOpCode opCode = INVALID_OPCODE; |
| 80 | |
| 81 | bool isSigned = setCCInstr->getOperand(0)->getType()->isSigned(); |
| 82 | |
| 83 | if (isSigned) |
| 84 | { |
| 85 | switch(setCCInstr->getOpcode()) |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 86 | { |
| 87 | case Instruction::SetEQ: opCode = BE; break; |
| 88 | case Instruction::SetNE: opCode = BNE; break; |
| 89 | case Instruction::SetLE: opCode = BLE; break; |
| 90 | case Instruction::SetGE: opCode = BGE; break; |
| 91 | case Instruction::SetLT: opCode = BL; break; |
| 92 | case Instruction::SetGT: opCode = BG; break; |
| 93 | default: |
| 94 | assert(0 && "Unrecognized VM instruction!"); |
| 95 | break; |
| 96 | } |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 97 | } |
| 98 | else |
| 99 | { |
| 100 | switch(setCCInstr->getOpcode()) |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 101 | { |
| 102 | case Instruction::SetEQ: opCode = BE; break; |
| 103 | case Instruction::SetNE: opCode = BNE; break; |
| 104 | case Instruction::SetLE: opCode = BLEU; break; |
| 105 | case Instruction::SetGE: opCode = BCC; break; |
| 106 | case Instruction::SetLT: opCode = BCS; break; |
| 107 | case Instruction::SetGT: opCode = BGU; break; |
| 108 | default: |
| 109 | assert(0 && "Unrecognized VM instruction!"); |
| 110 | break; |
| 111 | } |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | return opCode; |
| 115 | } |
| 116 | |
| 117 | static inline MachineOpCode |
| 118 | ChooseBFpccInstruction(const InstructionNode* instrNode, |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 119 | const BinaryOperator* setCCInstr) |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 120 | { |
| 121 | MachineOpCode opCode = INVALID_OPCODE; |
| 122 | |
| 123 | switch(setCCInstr->getOpcode()) |
| 124 | { |
| 125 | case Instruction::SetEQ: opCode = FBE; break; |
| 126 | case Instruction::SetNE: opCode = FBNE; break; |
| 127 | case Instruction::SetLE: opCode = FBLE; break; |
| 128 | case Instruction::SetGE: opCode = FBGE; break; |
| 129 | case Instruction::SetLT: opCode = FBL; break; |
| 130 | case Instruction::SetGT: opCode = FBG; break; |
| 131 | default: |
| 132 | assert(0 && "Unrecognized VM instruction!"); |
| 133 | break; |
| 134 | } |
| 135 | |
| 136 | return opCode; |
| 137 | } |
| 138 | |
| 139 | |
Vikram S. Adve | b7f06f4 | 2001-11-04 19:34:49 +0000 | [diff] [blame] | 140 | // Create a unique TmpInstruction for a boolean value, |
| 141 | // representing the CC register used by a branch on that value. |
| 142 | // For now, hack this using a little static cache of TmpInstructions. |
| 143 | // Eventually the entire BURG instruction selection should be put |
| 144 | // into a separate class that can hold such information. |
Vikram S. Adve | ff5a09e | 2001-11-08 05:04:09 +0000 | [diff] [blame] | 145 | // The static cache is not too bad because the memory for these |
Chris Lattner | 2fbfdcf | 2002-04-07 20:49:59 +0000 | [diff] [blame] | 146 | // TmpInstructions will be freed along with the rest of the Function anyway. |
Vikram S. Adve | b7f06f4 | 2001-11-04 19:34:49 +0000 | [diff] [blame] | 147 | // |
| 148 | static TmpInstruction* |
Chris Lattner | 2fbfdcf | 2002-04-07 20:49:59 +0000 | [diff] [blame] | 149 | GetTmpForCC(Value* boolVal, const Function *F, const Type* ccType) |
Vikram S. Adve | b7f06f4 | 2001-11-04 19:34:49 +0000 | [diff] [blame] | 150 | { |
Chris Lattner | 09ff112 | 2002-07-24 21:21:32 +0000 | [diff] [blame] | 151 | typedef hash_map<const Value*, TmpInstruction*> BoolTmpCache; |
Vikram S. Adve | b7f06f4 | 2001-11-04 19:34:49 +0000 | [diff] [blame] | 152 | static BoolTmpCache boolToTmpCache; // Map boolVal -> TmpInstruction* |
Chris Lattner | 2fbfdcf | 2002-04-07 20:49:59 +0000 | [diff] [blame] | 153 | static const Function *lastFunction = 0;// Use to flush cache between funcs |
Vikram S. Adve | b7f06f4 | 2001-11-04 19:34:49 +0000 | [diff] [blame] | 154 | |
| 155 | assert(boolVal->getType() == Type::BoolTy && "Weird but ok! Delete assert"); |
| 156 | |
Chris Lattner | 2fbfdcf | 2002-04-07 20:49:59 +0000 | [diff] [blame] | 157 | if (lastFunction != F) |
Vikram S. Adve | b7f06f4 | 2001-11-04 19:34:49 +0000 | [diff] [blame] | 158 | { |
Chris Lattner | 2fbfdcf | 2002-04-07 20:49:59 +0000 | [diff] [blame] | 159 | lastFunction = F; |
Vikram S. Adve | b7f06f4 | 2001-11-04 19:34:49 +0000 | [diff] [blame] | 160 | boolToTmpCache.clear(); |
| 161 | } |
| 162 | |
Vikram S. Adve | ff5a09e | 2001-11-08 05:04:09 +0000 | [diff] [blame] | 163 | // Look for tmpI and create a new one otherwise. The new value is |
| 164 | // directly written to map using the ref returned by operator[]. |
Vikram S. Adve | b7f06f4 | 2001-11-04 19:34:49 +0000 | [diff] [blame] | 165 | TmpInstruction*& tmpI = boolToTmpCache[boolVal]; |
| 166 | if (tmpI == NULL) |
Chris Lattner | 9c46108 | 2002-02-03 07:50:56 +0000 | [diff] [blame] | 167 | tmpI = new TmpInstruction(ccType, boolVal); |
Vikram S. Adve | b7f06f4 | 2001-11-04 19:34:49 +0000 | [diff] [blame] | 168 | |
| 169 | return tmpI; |
| 170 | } |
| 171 | |
| 172 | |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 173 | static inline MachineOpCode |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 174 | ChooseBccInstruction(const InstructionNode* instrNode, |
| 175 | bool& isFPBranch) |
| 176 | { |
| 177 | InstructionNode* setCCNode = (InstructionNode*) instrNode->leftChild(); |
| 178 | BinaryOperator* setCCInstr = (BinaryOperator*) setCCNode->getInstruction(); |
| 179 | const Type* setCCType = setCCInstr->getOperand(0)->getType(); |
| 180 | |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 181 | isFPBranch = setCCType->isFloatingPoint(); // Return value: don't delete! |
| 182 | |
| 183 | if (isFPBranch) |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 184 | return ChooseBFpccInstruction(instrNode, setCCInstr); |
| 185 | else |
| 186 | return ChooseBpccInstruction(instrNode, setCCInstr); |
| 187 | } |
| 188 | |
| 189 | |
| 190 | static inline MachineOpCode |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 191 | ChooseMovFpccInstruction(const InstructionNode* instrNode) |
| 192 | { |
| 193 | MachineOpCode opCode = INVALID_OPCODE; |
| 194 | |
| 195 | switch(instrNode->getInstruction()->getOpcode()) |
| 196 | { |
| 197 | case Instruction::SetEQ: opCode = MOVFE; break; |
| 198 | case Instruction::SetNE: opCode = MOVFNE; break; |
| 199 | case Instruction::SetLE: opCode = MOVFLE; break; |
| 200 | case Instruction::SetGE: opCode = MOVFGE; break; |
| 201 | case Instruction::SetLT: opCode = MOVFL; break; |
| 202 | case Instruction::SetGT: opCode = MOVFG; break; |
| 203 | default: |
| 204 | assert(0 && "Unrecognized VM instruction!"); |
| 205 | break; |
| 206 | } |
| 207 | |
| 208 | return opCode; |
| 209 | } |
| 210 | |
| 211 | |
| 212 | // Assumes that SUBcc v1, v2 -> v3 has been executed. |
| 213 | // In most cases, we want to clear v3 and then follow it by instruction |
| 214 | // MOVcc 1 -> v3. |
| 215 | // Set mustClearReg=false if v3 need not be cleared before conditional move. |
| 216 | // Set valueToMove=0 if we want to conditionally move 0 instead of 1 |
| 217 | // (i.e., we want to test inverse of a condition) |
Vikram S. Adve | 243dd45 | 2001-09-18 13:03:13 +0000 | [diff] [blame] | 218 | // (The latter two cases do not seem to arise because SetNE needs nothing.) |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 219 | // |
| 220 | static MachineOpCode |
| 221 | ChooseMovpccAfterSub(const InstructionNode* instrNode, |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 222 | bool& mustClearReg, |
| 223 | int& valueToMove) |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 224 | { |
| 225 | MachineOpCode opCode = INVALID_OPCODE; |
| 226 | mustClearReg = true; |
| 227 | valueToMove = 1; |
| 228 | |
| 229 | switch(instrNode->getInstruction()->getOpcode()) |
| 230 | { |
Vikram S. Adve | 243dd45 | 2001-09-18 13:03:13 +0000 | [diff] [blame] | 231 | case Instruction::SetEQ: opCode = MOVE; break; |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 232 | case Instruction::SetLE: opCode = MOVLE; break; |
| 233 | case Instruction::SetGE: opCode = MOVGE; break; |
| 234 | case Instruction::SetLT: opCode = MOVL; break; |
| 235 | case Instruction::SetGT: opCode = MOVG; break; |
Vikram S. Adve | 243dd45 | 2001-09-18 13:03:13 +0000 | [diff] [blame] | 236 | case Instruction::SetNE: assert(0 && "No move required!"); break; |
| 237 | default: assert(0 && "Unrecognized VM instr!"); break; |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | return opCode; |
| 241 | } |
| 242 | |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 243 | static inline MachineOpCode |
Vikram S. Adve | dbc4fad | 2002-04-25 04:37:51 +0000 | [diff] [blame] | 244 | ChooseConvertToFloatInstr(OpLabel vopCode, const Type* opType) |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 245 | { |
| 246 | MachineOpCode opCode = INVALID_OPCODE; |
| 247 | |
Vikram S. Adve | dbc4fad | 2002-04-25 04:37:51 +0000 | [diff] [blame] | 248 | switch(vopCode) |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 249 | { |
| 250 | case ToFloatTy: |
| 251 | if (opType == Type::SByteTy || opType == Type::ShortTy || opType == Type::IntTy) |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 252 | opCode = FITOS; |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 253 | else if (opType == Type::LongTy) |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 254 | opCode = FXTOS; |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 255 | else if (opType == Type::DoubleTy) |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 256 | opCode = FDTOS; |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 257 | else if (opType == Type::FloatTy) |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 258 | ; |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 259 | else |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 260 | assert(0 && "Cannot convert this type to FLOAT on SPARC"); |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 261 | break; |
| 262 | |
| 263 | case ToDoubleTy: |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 264 | // This is usually used in conjunction with CreateCodeToCopyIntToFloat(). |
| 265 | // Both functions should treat the integer as a 32-bit value for types |
| 266 | // of 4 bytes or less, and as a 64-bit value otherwise. |
Vikram S. Adve | fd3900a | 2002-03-24 03:33:02 +0000 | [diff] [blame] | 267 | if (opType == Type::SByteTy || opType == Type::UByteTy || |
| 268 | opType == Type::ShortTy || opType == Type::UShortTy || |
| 269 | opType == Type::IntTy || opType == Type::UIntTy) |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 270 | opCode = FITOD; |
Vikram S. Adve | fd3900a | 2002-03-24 03:33:02 +0000 | [diff] [blame] | 271 | else if (opType == Type::LongTy || opType == Type::ULongTy) |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 272 | opCode = FXTOD; |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 273 | else if (opType == Type::FloatTy) |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 274 | opCode = FSTOD; |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 275 | else if (opType == Type::DoubleTy) |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 276 | ; |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 277 | else |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 278 | assert(0 && "Cannot convert this type to DOUBLE on SPARC"); |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 279 | break; |
| 280 | |
| 281 | default: |
| 282 | break; |
| 283 | } |
| 284 | |
| 285 | return opCode; |
| 286 | } |
| 287 | |
| 288 | static inline MachineOpCode |
Vikram S. Adve | 1e60669 | 2002-07-31 21:01:34 +0000 | [diff] [blame^] | 289 | ChooseConvertToIntInstr(Type::PrimitiveID tid, const Type* opType) |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 290 | { |
| 291 | MachineOpCode opCode = INVALID_OPCODE;; |
| 292 | |
Vikram S. Adve | 1e60669 | 2002-07-31 21:01:34 +0000 | [diff] [blame^] | 293 | if (tid==Type::SByteTyID || tid==Type::ShortTyID || tid==Type::IntTyID || |
| 294 | tid==Type::UByteTyID || tid==Type::UShortTyID || tid==Type::UIntTyID) |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 295 | { |
| 296 | switch (opType->getPrimitiveID()) |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 297 | { |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 298 | case Type::FloatTyID: opCode = FSTOI; break; |
| 299 | case Type::DoubleTyID: opCode = FDTOI; break; |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 300 | default: |
| 301 | assert(0 && "Non-numeric non-bool type cannot be converted to Int"); |
| 302 | break; |
| 303 | } |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 304 | } |
Vikram S. Adve | 1e60669 | 2002-07-31 21:01:34 +0000 | [diff] [blame^] | 305 | else if (tid==Type::LongTyID || tid==Type::ULongTyID) |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 306 | { |
| 307 | switch (opType->getPrimitiveID()) |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 308 | { |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 309 | case Type::FloatTyID: opCode = FSTOX; break; |
| 310 | case Type::DoubleTyID: opCode = FDTOX; break; |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 311 | default: |
| 312 | assert(0 && "Non-numeric non-bool type cannot be converted to Long"); |
| 313 | break; |
| 314 | } |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 315 | } |
| 316 | else |
| 317 | assert(0 && "Should not get here, Mo!"); |
| 318 | |
| 319 | return opCode; |
| 320 | } |
| 321 | |
Vikram S. Adve | dbc4fad | 2002-04-25 04:37:51 +0000 | [diff] [blame] | 322 | MachineInstr* |
Vikram S. Adve | 1e60669 | 2002-07-31 21:01:34 +0000 | [diff] [blame^] | 323 | CreateConvertToIntInstr(Type::PrimitiveID destTID, Value* srcVal,Value* destVal) |
Vikram S. Adve | dbc4fad | 2002-04-25 04:37:51 +0000 | [diff] [blame] | 324 | { |
Vikram S. Adve | 1e60669 | 2002-07-31 21:01:34 +0000 | [diff] [blame^] | 325 | MachineOpCode opCode = ChooseConvertToIntInstr(destTID, srcVal->getType()); |
Vikram S. Adve | dbc4fad | 2002-04-25 04:37:51 +0000 | [diff] [blame] | 326 | assert(opCode != INVALID_OPCODE && "Expected to need conversion!"); |
| 327 | |
| 328 | MachineInstr* M = new MachineInstr(opCode); |
| 329 | M->SetMachineOperandVal(0, MachineOperand::MO_VirtualRegister, srcVal); |
| 330 | M->SetMachineOperandVal(1, MachineOperand::MO_VirtualRegister, destVal); |
| 331 | return M; |
| 332 | } |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 333 | |
Vikram S. Adve | 1e60669 | 2002-07-31 21:01:34 +0000 | [diff] [blame^] | 334 | // CreateCodeToConvertIntToFloat: Convert FP value to signed or unsigned integer |
| 335 | // The FP value must be converted to the dest type in an FP register, |
| 336 | // and the result is then copied from FP to int register via memory. |
| 337 | static void |
| 338 | CreateCodeToConvertIntToFloat (const TargetMachine& target, |
| 339 | Value* opVal, |
| 340 | Instruction* destI, |
| 341 | std::vector<MachineInstr*>& mvec, |
| 342 | MachineCodeForInstruction& mcfi) |
| 343 | { |
| 344 | // Create a temporary to represent the FP register into which the |
| 345 | // int value will placed after conversion. The type of this temporary |
| 346 | // depends on the type of FP register to use: single-prec for a 32-bit |
| 347 | // int or smaller; double-prec for a 64-bit int. |
| 348 | // |
| 349 | const Type* destTypeToUse = (destI->getType() == Type::LongTy)? Type::DoubleTy |
| 350 | : Type::FloatTy; |
| 351 | Value* destForCast = new TmpInstruction(destTypeToUse, opVal); |
| 352 | mcfi.addTemp(destForCast); |
| 353 | |
| 354 | // Create the fp-to-int conversion code |
| 355 | MachineInstr* M = CreateConvertToIntInstr(destI->getType()->getPrimitiveID(), |
| 356 | opVal, destForCast); |
| 357 | mvec.push_back(M); |
| 358 | |
| 359 | // Create the fpreg-to-intreg copy code |
| 360 | target.getInstrInfo(). |
| 361 | CreateCodeToCopyFloatToInt(target, destI->getParent()->getParent(), |
| 362 | (TmpInstruction*)destForCast, destI, mvec, mcfi); |
| 363 | } |
| 364 | |
| 365 | |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 366 | static inline MachineOpCode |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 367 | ChooseAddInstruction(const InstructionNode* instrNode) |
| 368 | { |
| 369 | return ChooseAddInstructionByType(instrNode->getInstruction()->getType()); |
| 370 | } |
| 371 | |
| 372 | |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 373 | static inline MachineInstr* |
| 374 | CreateMovFloatInstruction(const InstructionNode* instrNode, |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 375 | const Type* resultType) |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 376 | { |
| 377 | MachineInstr* minstr = new MachineInstr((resultType == Type::FloatTy) |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 378 | ? FMOVS : FMOVD); |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 379 | minstr->SetMachineOperandVal(0, MachineOperand::MO_VirtualRegister, |
| 380 | instrNode->leftChild()->getValue()); |
| 381 | minstr->SetMachineOperandVal(1, MachineOperand::MO_VirtualRegister, |
| 382 | instrNode->getValue()); |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 383 | return minstr; |
| 384 | } |
| 385 | |
| 386 | static inline MachineInstr* |
| 387 | CreateAddConstInstruction(const InstructionNode* instrNode) |
| 388 | { |
| 389 | MachineInstr* minstr = NULL; |
| 390 | |
| 391 | Value* constOp = ((InstrTreeNode*) instrNode->rightChild())->getValue(); |
Chris Lattner | e9bb2df | 2001-12-03 22:26:30 +0000 | [diff] [blame] | 392 | assert(isa<Constant>(constOp)); |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 393 | |
| 394 | // Cases worth optimizing are: |
| 395 | // (1) Add with 0 for float or double: use an FMOV of appropriate type, |
| 396 | // instead of an FADD (1 vs 3 cycles). There is no integer MOV. |
| 397 | // |
Chris Lattner | 9b62503 | 2002-05-06 16:15:30 +0000 | [diff] [blame] | 398 | if (ConstantFP *FPC = dyn_cast<ConstantFP>(constOp)) { |
| 399 | double dval = FPC->getValue(); |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 400 | if (dval == 0.0) |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 401 | minstr = CreateMovFloatInstruction(instrNode, |
| 402 | instrNode->getInstruction()->getType()); |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 403 | } |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 404 | |
| 405 | return minstr; |
| 406 | } |
| 407 | |
| 408 | |
| 409 | static inline MachineOpCode |
Vikram S. Adve | 510eec7 | 2001-11-04 21:59:14 +0000 | [diff] [blame] | 410 | ChooseSubInstructionByType(const Type* resultType) |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 411 | { |
| 412 | MachineOpCode opCode = INVALID_OPCODE; |
| 413 | |
Chris Lattner | 9b62503 | 2002-05-06 16:15:30 +0000 | [diff] [blame] | 414 | if (resultType->isIntegral() || isa<PointerType>(resultType)) |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 415 | { |
| 416 | opCode = SUB; |
| 417 | } |
| 418 | else |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 419 | switch(resultType->getPrimitiveID()) |
| 420 | { |
| 421 | case Type::FloatTyID: opCode = FSUBS; break; |
| 422 | case Type::DoubleTyID: opCode = FSUBD; break; |
| 423 | default: assert(0 && "Invalid type for SUB instruction"); break; |
| 424 | } |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 425 | |
| 426 | return opCode; |
| 427 | } |
| 428 | |
| 429 | |
| 430 | static inline MachineInstr* |
| 431 | CreateSubConstInstruction(const InstructionNode* instrNode) |
| 432 | { |
| 433 | MachineInstr* minstr = NULL; |
| 434 | |
| 435 | Value* constOp = ((InstrTreeNode*) instrNode->rightChild())->getValue(); |
Chris Lattner | e9bb2df | 2001-12-03 22:26:30 +0000 | [diff] [blame] | 436 | assert(isa<Constant>(constOp)); |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 437 | |
| 438 | // Cases worth optimizing are: |
| 439 | // (1) Sub with 0 for float or double: use an FMOV of appropriate type, |
| 440 | // instead of an FSUB (1 vs 3 cycles). There is no integer MOV. |
| 441 | // |
Chris Lattner | 9b62503 | 2002-05-06 16:15:30 +0000 | [diff] [blame] | 442 | if (ConstantFP *FPC = dyn_cast<ConstantFP>(constOp)) { |
| 443 | double dval = FPC->getValue(); |
| 444 | if (dval == 0.0) |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 445 | minstr = CreateMovFloatInstruction(instrNode, |
| 446 | instrNode->getInstruction()->getType()); |
Chris Lattner | 9b62503 | 2002-05-06 16:15:30 +0000 | [diff] [blame] | 447 | } |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 448 | |
| 449 | return minstr; |
| 450 | } |
| 451 | |
| 452 | |
| 453 | static inline MachineOpCode |
| 454 | ChooseFcmpInstruction(const InstructionNode* instrNode) |
| 455 | { |
| 456 | MachineOpCode opCode = INVALID_OPCODE; |
| 457 | |
| 458 | Value* operand = ((InstrTreeNode*) instrNode->leftChild())->getValue(); |
| 459 | switch(operand->getType()->getPrimitiveID()) { |
| 460 | case Type::FloatTyID: opCode = FCMPS; break; |
| 461 | case Type::DoubleTyID: opCode = FCMPD; break; |
| 462 | default: assert(0 && "Invalid type for FCMP instruction"); break; |
| 463 | } |
| 464 | |
| 465 | return opCode; |
| 466 | } |
| 467 | |
| 468 | |
| 469 | // Assumes that leftArg and rightArg are both cast instructions. |
| 470 | // |
| 471 | static inline bool |
| 472 | BothFloatToDouble(const InstructionNode* instrNode) |
| 473 | { |
| 474 | InstrTreeNode* leftArg = instrNode->leftChild(); |
| 475 | InstrTreeNode* rightArg = instrNode->rightChild(); |
| 476 | InstrTreeNode* leftArgArg = leftArg->leftChild(); |
| 477 | InstrTreeNode* rightArgArg = rightArg->leftChild(); |
| 478 | assert(leftArg->getValue()->getType() == rightArg->getValue()->getType()); |
| 479 | |
| 480 | // Check if both arguments are floats cast to double |
| 481 | return (leftArg->getValue()->getType() == Type::DoubleTy && |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 482 | leftArgArg->getValue()->getType() == Type::FloatTy && |
| 483 | rightArgArg->getValue()->getType() == Type::FloatTy); |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 484 | } |
| 485 | |
| 486 | |
| 487 | static inline MachineOpCode |
Vikram S. Adve | 510eec7 | 2001-11-04 21:59:14 +0000 | [diff] [blame] | 488 | ChooseMulInstructionByType(const Type* resultType) |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 489 | { |
| 490 | MachineOpCode opCode = INVALID_OPCODE; |
| 491 | |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 492 | if (resultType->isIntegral()) |
Vikram S. Adve | 510eec7 | 2001-11-04 21:59:14 +0000 | [diff] [blame] | 493 | opCode = MULX; |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 494 | else |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 495 | switch(resultType->getPrimitiveID()) |
| 496 | { |
| 497 | case Type::FloatTyID: opCode = FMULS; break; |
| 498 | case Type::DoubleTyID: opCode = FMULD; break; |
| 499 | default: assert(0 && "Invalid type for MUL instruction"); break; |
| 500 | } |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 501 | |
| 502 | return opCode; |
| 503 | } |
| 504 | |
| 505 | |
Vikram S. Adve | 510eec7 | 2001-11-04 21:59:14 +0000 | [diff] [blame] | 506 | |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 507 | static inline MachineInstr* |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 508 | CreateIntNegInstruction(const TargetMachine& target, |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 509 | Value* vreg) |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 510 | { |
| 511 | MachineInstr* minstr = new MachineInstr(SUB); |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 512 | minstr->SetMachineOperandReg(0, target.getRegInfo().getZeroRegNum()); |
| 513 | minstr->SetMachineOperandVal(1, MachineOperand::MO_VirtualRegister, vreg); |
| 514 | minstr->SetMachineOperandVal(2, MachineOperand::MO_VirtualRegister, vreg); |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 515 | return minstr; |
| 516 | } |
| 517 | |
| 518 | |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 519 | // Create instruction sequence for any shift operation. |
| 520 | // SLL or SLLX on an operand smaller than the integer reg. size (64bits) |
| 521 | // requires a second instruction for explicit sign-extension. |
| 522 | // Note that we only have to worry about a sign-bit appearing in the |
| 523 | // most significant bit of the operand after shifting (e.g., bit 32 of |
| 524 | // Int or bit 16 of Short), so we do not have to worry about results |
| 525 | // that are as large as a normal integer register. |
| 526 | // |
| 527 | static inline void |
| 528 | CreateShiftInstructions(const TargetMachine& target, |
| 529 | Function* F, |
| 530 | MachineOpCode shiftOpCode, |
| 531 | Value* argVal1, |
| 532 | Value* optArgVal2, /* Use optArgVal2 if not NULL */ |
| 533 | unsigned int optShiftNum, /* else use optShiftNum */ |
| 534 | Instruction* destVal, |
| 535 | vector<MachineInstr*>& mvec, |
| 536 | MachineCodeForInstruction& mcfi) |
| 537 | { |
| 538 | assert((optArgVal2 != NULL || optShiftNum <= 64) && |
| 539 | "Large shift sizes unexpected, but can be handled below: " |
| 540 | "You need to check whether or not it fits in immed field below"); |
| 541 | |
| 542 | // If this is a logical left shift of a type smaller than the standard |
| 543 | // integer reg. size, we have to extend the sign-bit into upper bits |
| 544 | // of dest, so we need to put the result of the SLL into a temporary. |
| 545 | // |
| 546 | Value* shiftDest = destVal; |
| 547 | const Type* opType = argVal1->getType(); |
| 548 | unsigned opSize = target.DataLayout.getTypeSize(argVal1->getType()); |
| 549 | if ((shiftOpCode == SLL || shiftOpCode == SLLX) |
| 550 | && opSize < target.DataLayout.getIntegerRegize()) |
| 551 | { // put SLL result into a temporary |
| 552 | shiftDest = new TmpInstruction(argVal1, optArgVal2, "sllTmp"); |
| 553 | mcfi.addTemp(shiftDest); |
| 554 | } |
| 555 | |
| 556 | MachineInstr* M = (optArgVal2 != NULL) |
| 557 | ? Create3OperandInstr(shiftOpCode, argVal1, optArgVal2, shiftDest) |
| 558 | : Create3OperandInstr_UImmed(shiftOpCode, argVal1, optShiftNum, shiftDest); |
| 559 | mvec.push_back(M); |
| 560 | |
| 561 | if (shiftDest != destVal) |
| 562 | { // extend the sign-bit of the result into all upper bits of dest |
| 563 | assert(8*opSize <= 32 && "Unexpected type size > 4 and < IntRegSize?"); |
| 564 | target.getInstrInfo(). |
| 565 | CreateSignExtensionInstructions(target, F, shiftDest, 8*opSize, |
| 566 | destVal, mvec, mcfi); |
| 567 | } |
| 568 | } |
| 569 | |
| 570 | |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 571 | // Does not create any instructions if we cannot exploit constant to |
Vikram S. Adve | fd3900a | 2002-03-24 03:33:02 +0000 | [diff] [blame] | 572 | // create a cheaper instruction. |
| 573 | // This returns the approximate cost of the instructions generated, |
| 574 | // which is used to pick the cheapest when both operands are constant. |
| 575 | static inline unsigned int |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 576 | CreateMulConstInstruction(const TargetMachine &target, Function* F, |
| 577 | Value* lval, Value* rval, Instruction* destVal, |
| 578 | vector<MachineInstr*>& mvec, |
| 579 | MachineCodeForInstruction& mcfi) |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 580 | { |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 581 | /* Use max. multiply cost, viz., cost of MULX */ |
Vikram S. Adve | fd3900a | 2002-03-24 03:33:02 +0000 | [diff] [blame] | 582 | unsigned int cost = target.getInstrInfo().minLatency(MULX); |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 583 | unsigned int firstNewInstr = mvec.size(); |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 584 | |
| 585 | Value* constOp = rval; |
| 586 | if (! isa<Constant>(constOp)) |
Vikram S. Adve | fd3900a | 2002-03-24 03:33:02 +0000 | [diff] [blame] | 587 | return cost; |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 588 | |
| 589 | // Cases worth optimizing are: |
| 590 | // (1) Multiply by 0 or 1 for any type: replace with copy (ADD or FMOV) |
| 591 | // (2) Multiply by 2^x for integer types: replace with Shift |
| 592 | // |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 593 | const Type* resultType = destVal->getType(); |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 594 | |
Chris Lattner | 9b62503 | 2002-05-06 16:15:30 +0000 | [diff] [blame] | 595 | if (resultType->isIntegral() || isa<PointerType>(resultType)) |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 596 | { |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 597 | bool isValidConst; |
| 598 | int64_t C = GetConstantValueAsSignedInt(constOp, isValidConst); |
| 599 | if (isValidConst) |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 600 | { |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 601 | unsigned pow; |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 602 | bool needNeg = false; |
| 603 | if (C < 0) |
| 604 | { |
| 605 | needNeg = true; |
| 606 | C = -C; |
| 607 | } |
| 608 | |
| 609 | if (C == 0 || C == 1) |
| 610 | { |
Vikram S. Adve | fd3900a | 2002-03-24 03:33:02 +0000 | [diff] [blame] | 611 | cost = target.getInstrInfo().minLatency(ADD); |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 612 | MachineInstr* M = (C == 0) |
| 613 | ? Create3OperandInstr_Reg(ADD, |
| 614 | target.getRegInfo().getZeroRegNum(), |
| 615 | target.getRegInfo().getZeroRegNum(), |
| 616 | destVal) |
| 617 | : Create3OperandInstr_Reg(ADD, lval, |
| 618 | target.getRegInfo().getZeroRegNum(), |
| 619 | destVal); |
| 620 | mvec.push_back(M); |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 621 | } |
Chris Lattner | 36346c7 | 2002-05-19 21:20:19 +0000 | [diff] [blame] | 622 | else if (isPowerOf2(C, pow)) |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 623 | { |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 624 | unsigned int opSize = target.DataLayout.getTypeSize(resultType); |
| 625 | MachineOpCode opCode = (opSize <= 32)? SLL : SLLX; |
| 626 | CreateShiftInstructions(target, F, opCode, lval, NULL, pow, |
| 627 | destVal, mvec, mcfi); |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 628 | } |
| 629 | |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 630 | if (mvec.size() > 0 && needNeg) |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 631 | { // insert <reg = SUB 0, reg> after the instr to flip the sign |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 632 | MachineInstr* M = CreateIntNegInstruction(target, destVal); |
| 633 | mvec.push_back(M); |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 634 | } |
| 635 | } |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 636 | } |
| 637 | else |
| 638 | { |
Chris Lattner | 9b62503 | 2002-05-06 16:15:30 +0000 | [diff] [blame] | 639 | if (ConstantFP *FPC = dyn_cast<ConstantFP>(constOp)) |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 640 | { |
Chris Lattner | 9b62503 | 2002-05-06 16:15:30 +0000 | [diff] [blame] | 641 | double dval = FPC->getValue(); |
Vikram S. Adve | 6ad7c55 | 2001-11-09 02:18:16 +0000 | [diff] [blame] | 642 | if (fabs(dval) == 1) |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 643 | { |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 644 | MachineOpCode opCode = (dval < 0) |
Vikram S. Adve | 6ad7c55 | 2001-11-09 02:18:16 +0000 | [diff] [blame] | 645 | ? (resultType == Type::FloatTy? FNEGS : FNEGD) |
| 646 | : (resultType == Type::FloatTy? FMOVS : FMOVD); |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 647 | MachineInstr* M = Create2OperandInstr(opCode, lval, destVal); |
| 648 | mvec.push_back(M); |
Vikram S. Adve | 6ad7c55 | 2001-11-09 02:18:16 +0000 | [diff] [blame] | 649 | } |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 650 | } |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 651 | } |
| 652 | |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 653 | if (firstNewInstr < mvec.size()) |
Vikram S. Adve | fd3900a | 2002-03-24 03:33:02 +0000 | [diff] [blame] | 654 | { |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 655 | cost = 0; |
| 656 | for (unsigned int i=firstNewInstr; i < mvec.size(); ++i) |
| 657 | cost += target.getInstrInfo().minLatency(mvec[i]->getOpCode()); |
Vikram S. Adve | fd3900a | 2002-03-24 03:33:02 +0000 | [diff] [blame] | 658 | } |
| 659 | |
| 660 | return cost; |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 661 | } |
| 662 | |
| 663 | |
Vikram S. Adve | fd3900a | 2002-03-24 03:33:02 +0000 | [diff] [blame] | 664 | // Does not create any instructions if we cannot exploit constant to |
| 665 | // create a cheaper instruction. |
| 666 | // |
| 667 | static inline void |
| 668 | CreateCheapestMulConstInstruction(const TargetMachine &target, |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 669 | Function* F, |
| 670 | Value* lval, Value* rval, |
| 671 | Instruction* destVal, |
| 672 | vector<MachineInstr*>& mvec, |
| 673 | MachineCodeForInstruction& mcfi) |
Vikram S. Adve | fd3900a | 2002-03-24 03:33:02 +0000 | [diff] [blame] | 674 | { |
| 675 | Value* constOp; |
| 676 | if (isa<Constant>(lval) && isa<Constant>(rval)) |
| 677 | { // both operands are constant: try both orders! |
| 678 | vector<MachineInstr*> mvec1, mvec2; |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 679 | unsigned int lcost = CreateMulConstInstruction(target, F, lval, rval, |
| 680 | destVal, mvec1, mcfi); |
| 681 | unsigned int rcost = CreateMulConstInstruction(target, F, rval, lval, |
| 682 | destVal, mvec2, mcfi); |
Vikram S. Adve | fd3900a | 2002-03-24 03:33:02 +0000 | [diff] [blame] | 683 | vector<MachineInstr*>& mincostMvec = (lcost <= rcost)? mvec1 : mvec2; |
| 684 | vector<MachineInstr*>& maxcostMvec = (lcost <= rcost)? mvec2 : mvec1; |
| 685 | mvec.insert(mvec.end(), mincostMvec.begin(), mincostMvec.end()); |
| 686 | |
| 687 | for (unsigned int i=0; i < maxcostMvec.size(); ++i) |
| 688 | delete maxcostMvec[i]; |
| 689 | } |
| 690 | else if (isa<Constant>(rval)) // rval is constant, but not lval |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 691 | CreateMulConstInstruction(target, F, lval, rval, destVal, mvec, mcfi); |
Vikram S. Adve | fd3900a | 2002-03-24 03:33:02 +0000 | [diff] [blame] | 692 | else if (isa<Constant>(lval)) // lval is constant, but not rval |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 693 | CreateMulConstInstruction(target, F, lval, rval, destVal, mvec, mcfi); |
Vikram S. Adve | fd3900a | 2002-03-24 03:33:02 +0000 | [diff] [blame] | 694 | |
| 695 | // else neither is constant |
| 696 | return; |
| 697 | } |
| 698 | |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 699 | // Return NULL if we cannot exploit constant to create a cheaper instruction |
| 700 | static inline void |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 701 | CreateMulInstruction(const TargetMachine &target, Function* F, |
| 702 | Value* lval, Value* rval, Instruction* destVal, |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 703 | vector<MachineInstr*>& mvec, |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 704 | MachineCodeForInstruction& mcfi, |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 705 | MachineOpCode forceMulOp = INVALID_MACHINE_OPCODE) |
| 706 | { |
| 707 | unsigned int L = mvec.size(); |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 708 | CreateCheapestMulConstInstruction(target,F, lval, rval, destVal, mvec, mcfi); |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 709 | if (mvec.size() == L) |
| 710 | { // no instructions were added so create MUL reg, reg, reg. |
| 711 | // Use FSMULD if both operands are actually floats cast to doubles. |
| 712 | // Otherwise, use the default opcode for the appropriate type. |
| 713 | MachineOpCode mulOp = ((forceMulOp != INVALID_MACHINE_OPCODE) |
| 714 | ? forceMulOp |
| 715 | : ChooseMulInstructionByType(destVal->getType())); |
| 716 | MachineInstr* M = new MachineInstr(mulOp); |
| 717 | M->SetMachineOperandVal(0, MachineOperand::MO_VirtualRegister, lval); |
| 718 | M->SetMachineOperandVal(1, MachineOperand::MO_VirtualRegister, rval); |
| 719 | M->SetMachineOperandVal(2, MachineOperand::MO_VirtualRegister, destVal); |
| 720 | mvec.push_back(M); |
| 721 | } |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 722 | } |
| 723 | |
| 724 | |
Vikram S. Adve | 510eec7 | 2001-11-04 21:59:14 +0000 | [diff] [blame] | 725 | // Generate a divide instruction for Div or Rem. |
| 726 | // For Rem, this assumes that the operand type will be signed if the result |
| 727 | // type is signed. This is correct because they must have the same sign. |
| 728 | // |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 729 | static inline MachineOpCode |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 730 | ChooseDivInstruction(TargetMachine &target, |
| 731 | const InstructionNode* instrNode) |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 732 | { |
| 733 | MachineOpCode opCode = INVALID_OPCODE; |
| 734 | |
| 735 | const Type* resultType = instrNode->getInstruction()->getType(); |
| 736 | |
| 737 | if (resultType->isIntegral()) |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 738 | opCode = resultType->isSigned()? SDIVX : UDIVX; |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 739 | else |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 740 | switch(resultType->getPrimitiveID()) |
| 741 | { |
| 742 | case Type::FloatTyID: opCode = FDIVS; break; |
| 743 | case Type::DoubleTyID: opCode = FDIVD; break; |
| 744 | default: assert(0 && "Invalid type for DIV instruction"); break; |
| 745 | } |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 746 | |
| 747 | return opCode; |
| 748 | } |
| 749 | |
| 750 | |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 751 | // Return NULL if we cannot exploit constant to create a cheaper instruction |
| 752 | static inline void |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 753 | CreateDivConstInstruction(TargetMachine &target, |
| 754 | const InstructionNode* instrNode, |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 755 | vector<MachineInstr*>& mvec) |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 756 | { |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 757 | MachineInstr* minstr1 = NULL; |
| 758 | MachineInstr* minstr2 = NULL; |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 759 | |
| 760 | Value* constOp = ((InstrTreeNode*) instrNode->rightChild())->getValue(); |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 761 | if (! isa<Constant>(constOp)) |
| 762 | return; |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 763 | |
| 764 | // Cases worth optimizing are: |
| 765 | // (1) Divide by 1 for any type: replace with copy (ADD or FMOV) |
| 766 | // (2) Divide by 2^x for integer types: replace with SR[L or A]{X} |
| 767 | // |
| 768 | const Type* resultType = instrNode->getInstruction()->getType(); |
| 769 | |
| 770 | if (resultType->isIntegral()) |
| 771 | { |
| 772 | unsigned pow; |
| 773 | bool isValidConst; |
| 774 | int64_t C = GetConstantValueAsSignedInt(constOp, isValidConst); |
| 775 | if (isValidConst) |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 776 | { |
| 777 | bool needNeg = false; |
| 778 | if (C < 0) |
| 779 | { |
| 780 | needNeg = true; |
| 781 | C = -C; |
| 782 | } |
| 783 | |
| 784 | if (C == 1) |
| 785 | { |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 786 | minstr1 = new MachineInstr(ADD); |
Vikram S. Adve | fd3900a | 2002-03-24 03:33:02 +0000 | [diff] [blame] | 787 | minstr1->SetMachineOperandVal(0, |
| 788 | MachineOperand::MO_VirtualRegister, |
| 789 | instrNode->leftChild()->getValue()); |
| 790 | minstr1->SetMachineOperandReg(1, |
| 791 | target.getRegInfo().getZeroRegNum()); |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 792 | } |
Chris Lattner | 36346c7 | 2002-05-19 21:20:19 +0000 | [diff] [blame] | 793 | else if (isPowerOf2(C, pow)) |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 794 | { |
| 795 | MachineOpCode opCode= ((resultType->isSigned()) |
| 796 | ? (resultType==Type::LongTy)? SRAX : SRA |
| 797 | : (resultType==Type::LongTy)? SRLX : SRL); |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 798 | minstr1 = new MachineInstr(opCode); |
Vikram S. Adve | fd3900a | 2002-03-24 03:33:02 +0000 | [diff] [blame] | 799 | minstr1->SetMachineOperandVal(0, |
| 800 | MachineOperand::MO_VirtualRegister, |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 801 | instrNode->leftChild()->getValue()); |
Vikram S. Adve | fd3900a | 2002-03-24 03:33:02 +0000 | [diff] [blame] | 802 | minstr1->SetMachineOperandConst(1, |
| 803 | MachineOperand::MO_UnextendedImmed, |
| 804 | pow); |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 805 | } |
| 806 | |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 807 | if (minstr1 && needNeg) |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 808 | { // insert <reg = SUB 0, reg> after the instr to flip the sign |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 809 | minstr2 = CreateIntNegInstruction(target, |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 810 | instrNode->getValue()); |
| 811 | } |
| 812 | } |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 813 | } |
| 814 | else |
| 815 | { |
Chris Lattner | 9b62503 | 2002-05-06 16:15:30 +0000 | [diff] [blame] | 816 | if (ConstantFP *FPC = dyn_cast<ConstantFP>(constOp)) |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 817 | { |
Chris Lattner | 9b62503 | 2002-05-06 16:15:30 +0000 | [diff] [blame] | 818 | double dval = FPC->getValue(); |
Vikram S. Adve | 6ad7c55 | 2001-11-09 02:18:16 +0000 | [diff] [blame] | 819 | if (fabs(dval) == 1) |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 820 | { |
| 821 | bool needNeg = (dval < 0); |
| 822 | |
| 823 | MachineOpCode opCode = needNeg |
| 824 | ? (resultType == Type::FloatTy? FNEGS : FNEGD) |
| 825 | : (resultType == Type::FloatTy? FMOVS : FMOVD); |
| 826 | |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 827 | minstr1 = new MachineInstr(opCode); |
Vikram S. Adve | fd3900a | 2002-03-24 03:33:02 +0000 | [diff] [blame] | 828 | minstr1->SetMachineOperandVal(0, |
| 829 | MachineOperand::MO_VirtualRegister, |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 830 | instrNode->leftChild()->getValue()); |
| 831 | } |
| 832 | } |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 833 | } |
| 834 | |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 835 | if (minstr1 != NULL) |
| 836 | minstr1->SetMachineOperandVal(2, MachineOperand::MO_VirtualRegister, |
| 837 | instrNode->getValue()); |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 838 | |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 839 | if (minstr1) |
| 840 | mvec.push_back(minstr1); |
| 841 | if (minstr2) |
| 842 | mvec.push_back(minstr2); |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 843 | } |
| 844 | |
| 845 | |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 846 | static void |
| 847 | CreateCodeForVariableSizeAlloca(const TargetMachine& target, |
| 848 | Instruction* result, |
| 849 | unsigned int tsize, |
| 850 | Value* numElementsVal, |
| 851 | vector<MachineInstr*>& getMvec) |
| 852 | { |
| 853 | MachineInstr* M; |
| 854 | |
| 855 | // Create a Value to hold the (constant) element size |
| 856 | Value* tsizeVal = ConstantSInt::get(Type::IntTy, tsize); |
| 857 | |
| 858 | // Get the constant offset from SP for dynamically allocated storage |
| 859 | // and create a temporary Value to hold it. |
Chris Lattner | 2fbfdcf | 2002-04-07 20:49:59 +0000 | [diff] [blame] | 860 | assert(result && result->getParent() && "Result value is not part of a fn?"); |
| 861 | Function *F = result->getParent()->getParent(); |
| 862 | MachineCodeForMethod& mcInfo = MachineCodeForMethod::get(F); |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 863 | bool growUp; |
| 864 | ConstantSInt* dynamicAreaOffset = |
| 865 | ConstantSInt::get(Type::IntTy, |
| 866 | target.getFrameInfo().getDynamicAreaOffset(mcInfo,growUp)); |
| 867 | assert(! growUp && "Has SPARC v9 stack frame convention changed?"); |
| 868 | |
| 869 | // Create a temporary value to hold the result of MUL |
| 870 | TmpInstruction* tmpProd = new TmpInstruction(numElementsVal, tsizeVal); |
| 871 | MachineCodeForInstruction::get(result).addTemp(tmpProd); |
| 872 | |
| 873 | // Instruction 1: mul numElements, typeSize -> tmpProd |
| 874 | M = new MachineInstr(MULX); |
| 875 | M->SetMachineOperandVal(0, MachineOperand::MO_VirtualRegister, numElementsVal); |
| 876 | M->SetMachineOperandVal(1, MachineOperand::MO_VirtualRegister, tsizeVal); |
| 877 | M->SetMachineOperandVal(2, MachineOperand::MO_VirtualRegister, tmpProd); |
| 878 | getMvec.push_back(M); |
| 879 | |
| 880 | // Instruction 2: sub %sp, tmpProd -> %sp |
| 881 | M = new MachineInstr(SUB); |
| 882 | M->SetMachineOperandReg(0, target.getRegInfo().getStackPointer()); |
| 883 | M->SetMachineOperandVal(1, MachineOperand::MO_VirtualRegister, tmpProd); |
| 884 | M->SetMachineOperandReg(2, target.getRegInfo().getStackPointer()); |
| 885 | getMvec.push_back(M); |
| 886 | |
| 887 | // Instruction 3: add %sp, frameSizeBelowDynamicArea -> result |
| 888 | M = new MachineInstr(ADD); |
| 889 | M->SetMachineOperandReg(0, target.getRegInfo().getStackPointer()); |
| 890 | M->SetMachineOperandVal(1, MachineOperand::MO_VirtualRegister, dynamicAreaOffset); |
| 891 | M->SetMachineOperandVal(2, MachineOperand::MO_VirtualRegister, result); |
| 892 | getMvec.push_back(M); |
| 893 | } |
| 894 | |
| 895 | |
| 896 | static void |
| 897 | CreateCodeForFixedSizeAlloca(const TargetMachine& target, |
| 898 | Instruction* result, |
| 899 | unsigned int tsize, |
| 900 | unsigned int numElements, |
| 901 | vector<MachineInstr*>& getMvec) |
| 902 | { |
Vikram S. Adve | fd3900a | 2002-03-24 03:33:02 +0000 | [diff] [blame] | 903 | assert(result && result->getParent() && |
Chris Lattner | 2fbfdcf | 2002-04-07 20:49:59 +0000 | [diff] [blame] | 904 | "Result value is not part of a function?"); |
| 905 | Function *F = result->getParent()->getParent(); |
| 906 | MachineCodeForMethod &mcInfo = MachineCodeForMethod::get(F); |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 907 | |
Chris Lattner | 2fbfdcf | 2002-04-07 20:49:59 +0000 | [diff] [blame] | 908 | // Check if the offset would small enough to use as an immediate in |
| 909 | // load/stores (check LDX because all load/stores have the same-size immediate |
| 910 | // field). If not, put the variable in the dynamically sized area of the |
| 911 | // frame. |
Vikram S. Adve | fd3900a | 2002-03-24 03:33:02 +0000 | [diff] [blame] | 912 | unsigned int paddedSizeIgnored; |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 913 | int offsetFromFP = mcInfo.computeOffsetforLocalVar(target, result, |
Vikram S. Adve | fd3900a | 2002-03-24 03:33:02 +0000 | [diff] [blame] | 914 | paddedSizeIgnored, |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 915 | tsize * numElements); |
| 916 | if (! target.getInstrInfo().constantFitsInImmedField(LDX, offsetFromFP)) |
| 917 | { |
| 918 | CreateCodeForVariableSizeAlloca(target, result, tsize, |
| 919 | ConstantSInt::get(Type::IntTy,numElements), |
| 920 | getMvec); |
| 921 | return; |
| 922 | } |
| 923 | |
| 924 | // else offset fits in immediate field so go ahead and allocate it. |
| 925 | offsetFromFP = mcInfo.allocateLocalVar(target, result, tsize * numElements); |
| 926 | |
| 927 | // Create a temporary Value to hold the constant offset. |
| 928 | // This is needed because it may not fit in the immediate field. |
| 929 | ConstantSInt* offsetVal = ConstantSInt::get(Type::IntTy, offsetFromFP); |
| 930 | |
| 931 | // Instruction 1: add %fp, offsetFromFP -> result |
| 932 | MachineInstr* M = new MachineInstr(ADD); |
| 933 | M->SetMachineOperandReg(0, target.getRegInfo().getFramePointer()); |
| 934 | M->SetMachineOperandVal(1, MachineOperand::MO_VirtualRegister, offsetVal); |
| 935 | M->SetMachineOperandVal(2, MachineOperand::MO_VirtualRegister, result); |
| 936 | |
| 937 | getMvec.push_back(M); |
| 938 | } |
| 939 | |
| 940 | |
| 941 | |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 942 | |
| 943 | |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 944 | //------------------------------------------------------------------------ |
| 945 | // Function SetOperandsForMemInstr |
| 946 | // |
| 947 | // Choose addressing mode for the given load or store instruction. |
| 948 | // Use [reg+reg] if it is an indexed reference, and the index offset is |
| 949 | // not a constant or if it cannot fit in the offset field. |
| 950 | // Use [reg+offset] in all other cases. |
| 951 | // |
| 952 | // This assumes that all array refs are "lowered" to one of these forms: |
| 953 | // %x = load (subarray*) ptr, constant ; single constant offset |
| 954 | // %x = load (subarray*) ptr, offsetVal ; single non-constant offset |
| 955 | // Generally, this should happen via strength reduction + LICM. |
| 956 | // Also, strength reduction should take care of using the same register for |
| 957 | // the loop index variable and an array index, when that is profitable. |
| 958 | //------------------------------------------------------------------------ |
| 959 | |
| 960 | static void |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 961 | SetOperandsForMemInstr(vector<MachineInstr*>& mvec, |
| 962 | vector<MachineInstr*>::iterator mvecI, |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 963 | const InstructionNode* vmInstrNode, |
| 964 | const TargetMachine& target) |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 965 | { |
| 966 | MemAccessInst* memInst = (MemAccessInst*) vmInstrNode->getInstruction(); |
| 967 | |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 968 | // Variables to hold the index vector and ptr value. |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 969 | // The major work here is to extract these for all 3 instruction types |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 970 | // and to try to fold chains of constant indices into a single offset. |
| 971 | // After that, we call SetMemOperands_Internal(), which creates the |
| 972 | // appropriate operands for the machine instruction. |
Vikram S. Adve | a10d1a7 | 2002-03-31 19:07:35 +0000 | [diff] [blame] | 973 | vector<Value*> idxVec; |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 974 | bool allConstantIndices = true; |
| 975 | Value* ptrVal = memInst->getPointerOperand(); |
Vikram S. Adve | a10d1a7 | 2002-03-31 19:07:35 +0000 | [diff] [blame] | 976 | |
| 977 | // If there is a GetElemPtr instruction to fold in to this instr, |
| 978 | // it must be in the left child for Load and GetElemPtr, and in the |
| 979 | // right child for Store instructions. |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 980 | InstrTreeNode* ptrChild = (vmInstrNode->getOpLabel() == Instruction::Store |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 981 | ? vmInstrNode->rightChild() |
| 982 | : vmInstrNode->leftChild()); |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 983 | |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 984 | // Check if all indices are constant for this instruction |
| 985 | for (MemAccessInst::op_iterator OI=memInst->idx_begin(); |
| 986 | OI != memInst->idx_end(); ++OI) |
| 987 | if (! isa<ConstantUInt>(*OI)) |
| 988 | { |
| 989 | allConstantIndices = false; |
| 990 | break; |
| 991 | } |
| 992 | |
| 993 | // If we have only constant indices, fold chains of constant indices |
| 994 | // in this and any preceding GetElemPtr instructions. |
| 995 | if (allConstantIndices && |
| 996 | ptrChild->getOpLabel() == Instruction::GetElementPtr || |
| 997 | ptrChild->getOpLabel() == GetElemPtrIdx) |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 998 | { |
Vikram S. Adve | fd3900a | 2002-03-24 03:33:02 +0000 | [diff] [blame] | 999 | Value* newPtr = FoldGetElemChain((InstructionNode*) ptrChild, idxVec); |
| 1000 | if (newPtr) |
| 1001 | ptrVal = newPtr; |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 1002 | } |
| 1003 | |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 1004 | // Append the index vector of the current instruction, if any. |
| 1005 | // Discard any leading [0] index. |
| 1006 | if (memInst->idx_begin() != memInst->idx_end()) |
| 1007 | { |
Chris Lattner | db241dc | 2002-06-05 18:11:37 +0000 | [diff] [blame] | 1008 | const ConstantUInt* CV = dyn_cast<ConstantUInt>(memInst->idx_begin()->get()); |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 1009 | unsigned zeroOrIOne = (CV && CV->getType() == Type::UIntTy && |
| 1010 | (CV->getValue() == 0))? 1 : 0; |
| 1011 | idxVec.insert(idxVec.end(), |
| 1012 | memInst->idx_begin()+zeroOrIOne, memInst->idx_end()); |
| 1013 | } |
| 1014 | |
| 1015 | // Now create the appropriate operands for the machine instruction |
| 1016 | SetMemOperands_Internal(mvec, mvecI, vmInstrNode, |
| 1017 | ptrVal, idxVec, allConstantIndices, target); |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 1018 | } |
| 1019 | |
| 1020 | |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1021 | // Generate the correct operands (and additional instructions if needed) |
| 1022 | // for the given pointer and given index vector. |
| 1023 | // |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 1024 | static void |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1025 | SetMemOperands_Internal(vector<MachineInstr*>& mvec, |
| 1026 | vector<MachineInstr*>::iterator mvecI, |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1027 | const InstructionNode* vmInstrNode, |
| 1028 | Value* ptrVal, |
Vikram S. Adve | fd3900a | 2002-03-24 03:33:02 +0000 | [diff] [blame] | 1029 | vector<Value*>& idxVec, |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 1030 | bool allConstantIndices, |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1031 | const TargetMachine& target) |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 1032 | { |
| 1033 | MemAccessInst* memInst = (MemAccessInst*) vmInstrNode->getInstruction(); |
| 1034 | |
| 1035 | // Initialize so we default to storing the offset in a register. |
Chris Lattner | 8e5c0b4 | 2001-11-07 14:01:59 +0000 | [diff] [blame] | 1036 | int64_t smallConstOffset = 0; |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 1037 | Value* valueForRegOffset = NULL; |
| 1038 | MachineOperand::MachineOperandType offsetOpType =MachineOperand::MO_VirtualRegister; |
| 1039 | |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1040 | // Check if there is an index vector and if so, compute the |
| 1041 | // right offset for structures and for arrays |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 1042 | // |
| 1043 | if (idxVec.size() > 0) |
| 1044 | { |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1045 | const PointerType* ptrType = cast<PointerType>(ptrVal->getType()); |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 1046 | |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 1047 | // If all indices are constant, compute the combined offset directly. |
| 1048 | if (allConstantIndices) |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1049 | { |
Vikram S. Adve | fd3900a | 2002-03-24 03:33:02 +0000 | [diff] [blame] | 1050 | // Compute the offset value using the index vector. Create a |
| 1051 | // virtual reg. for it since it may not fit in the immed field. |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 1052 | uint64_t offset = target.DataLayout.getIndexedOffset(ptrType,idxVec); |
| 1053 | valueForRegOffset = ConstantSInt::get(Type::LongTy, offset); |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1054 | } |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 1055 | else |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1056 | { |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 1057 | // There is at least one non-constant offset. Therefore, this must |
| 1058 | // be an array ref, and must have been lowered to a single offset. |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1059 | assert((memInst->getNumOperands() |
| 1060 | == (unsigned) 1 + memInst->getFirstIndexOperandNumber()) |
| 1061 | && "Array refs must be lowered before Instruction Selection"); |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1062 | |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1063 | Value* arrayOffsetVal = * memInst->idx_begin(); |
| 1064 | |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 1065 | // Handle special common case of leading [0] index. |
| 1066 | ConstantUInt* CV = dyn_cast<ConstantUInt>(idxVec.front()); |
| 1067 | bool firstIndexIsZero = bool(CV && CV->getType() == Type::UIntTy && |
| 1068 | (CV->getValue() == 0)); |
| 1069 | |
Vikram S. Adve | fd3900a | 2002-03-24 03:33:02 +0000 | [diff] [blame] | 1070 | // If index is 0, the offset value is just 0. Otherwise, |
| 1071 | // generate a MUL instruction to compute address from index. |
| 1072 | // The call to getTypeSize() will fail if size is not constant. |
| 1073 | // CreateMulInstruction() folds constants intelligently enough. |
| 1074 | // |
| 1075 | if (firstIndexIsZero) |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1076 | { |
Vikram S. Adve | fd3900a | 2002-03-24 03:33:02 +0000 | [diff] [blame] | 1077 | offsetOpType = MachineOperand::MO_SignExtendedImmed; |
| 1078 | smallConstOffset = 0; |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1079 | } |
Vikram S. Adve | fd3900a | 2002-03-24 03:33:02 +0000 | [diff] [blame] | 1080 | else |
| 1081 | { |
| 1082 | vector<MachineInstr*> mulVec; |
| 1083 | Instruction* addr = new TmpInstruction(Type::UIntTy, memInst); |
| 1084 | MachineCodeForInstruction::get(memInst).addTemp(addr); |
| 1085 | |
| 1086 | unsigned int eltSize = |
| 1087 | target.DataLayout.getTypeSize(ptrType->getElementType()); |
| 1088 | assert(eltSize > 0 && "Invalid or non-const array element size"); |
| 1089 | ConstantUInt* eltVal = ConstantUInt::get(Type::UIntTy, eltSize); |
| 1090 | |
| 1091 | CreateMulInstruction(target, |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 1092 | memInst->getParent()->getParent(), |
Vikram S. Adve | fd3900a | 2002-03-24 03:33:02 +0000 | [diff] [blame] | 1093 | arrayOffsetVal, /* lval, not likely const */ |
| 1094 | eltVal, /* rval, likely constant */ |
| 1095 | addr, /* result*/ |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 1096 | mulVec, |
| 1097 | MachineCodeForInstruction::get(memInst), |
| 1098 | INVALID_MACHINE_OPCODE); |
Vikram S. Adve | fd3900a | 2002-03-24 03:33:02 +0000 | [diff] [blame] | 1099 | assert(mulVec.size() > 0 && "No multiply instruction created?"); |
| 1100 | for (vector<MachineInstr*>::const_iterator I = mulVec.begin(); |
| 1101 | I != mulVec.end(); ++I) |
| 1102 | { |
| 1103 | mvecI = mvec.insert(mvecI, *I); // ptr to inserted value |
| 1104 | ++mvecI; // ptr to mem. instr. |
| 1105 | } |
| 1106 | |
| 1107 | valueForRegOffset = addr; |
| 1108 | } |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1109 | } |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 1110 | } |
| 1111 | else |
| 1112 | { |
| 1113 | offsetOpType = MachineOperand::MO_SignExtendedImmed; |
| 1114 | smallConstOffset = 0; |
| 1115 | } |
| 1116 | |
Vikram S. Adve | a10d1a7 | 2002-03-31 19:07:35 +0000 | [diff] [blame] | 1117 | // For STORE: |
| 1118 | // Operand 0 is value, operand 1 is ptr, operand 2 is offset |
| 1119 | // For LOAD or GET_ELEMENT_PTR, |
| 1120 | // Operand 0 is ptr, operand 1 is offset, operand 2 is result. |
| 1121 | // |
| 1122 | unsigned offsetOpNum, ptrOpNum; |
| 1123 | if (memInst->getOpcode() == Instruction::Store) |
| 1124 | { |
| 1125 | (*mvecI)->SetMachineOperandVal(0, MachineOperand::MO_VirtualRegister, |
| 1126 | vmInstrNode->leftChild()->getValue()); |
| 1127 | ptrOpNum = 1; |
| 1128 | offsetOpNum = 2; |
| 1129 | } |
| 1130 | else |
| 1131 | { |
| 1132 | ptrOpNum = 0; |
| 1133 | offsetOpNum = 1; |
| 1134 | (*mvecI)->SetMachineOperandVal(2, MachineOperand::MO_VirtualRegister, |
| 1135 | memInst); |
| 1136 | } |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 1137 | |
Vikram S. Adve | a10d1a7 | 2002-03-31 19:07:35 +0000 | [diff] [blame] | 1138 | (*mvecI)->SetMachineOperandVal(ptrOpNum, MachineOperand::MO_VirtualRegister, |
| 1139 | ptrVal); |
| 1140 | |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 1141 | if (offsetOpType == MachineOperand::MO_VirtualRegister) |
| 1142 | { |
| 1143 | assert(valueForRegOffset != NULL); |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1144 | (*mvecI)->SetMachineOperandVal(offsetOpNum, offsetOpType, |
| 1145 | valueForRegOffset); |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 1146 | } |
| 1147 | else |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1148 | (*mvecI)->SetMachineOperandConst(offsetOpNum, offsetOpType, |
| 1149 | smallConstOffset); |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 1150 | } |
| 1151 | |
| 1152 | |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 1153 | // |
| 1154 | // Substitute operand `operandNum' of the instruction in node `treeNode' |
Vikram S. Adve | c025fc1 | 2001-10-14 23:28:43 +0000 | [diff] [blame] | 1155 | // in place of the use(s) of that instruction in node `parent'. |
| 1156 | // Check both explicit and implicit operands! |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1157 | // Also make sure to skip over a parent who: |
| 1158 | // (1) is a list node in the Burg tree, or |
| 1159 | // (2) itself had its results forwarded to its parent |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 1160 | // |
| 1161 | static void |
| 1162 | ForwardOperand(InstructionNode* treeNode, |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1163 | InstrTreeNode* parent, |
| 1164 | int operandNum) |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 1165 | { |
Vikram S. Adve | 243dd45 | 2001-09-18 13:03:13 +0000 | [diff] [blame] | 1166 | assert(treeNode && parent && "Invalid invocation of ForwardOperand"); |
| 1167 | |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 1168 | Instruction* unusedOp = treeNode->getInstruction(); |
| 1169 | Value* fwdOp = unusedOp->getOperand(operandNum); |
Vikram S. Adve | 243dd45 | 2001-09-18 13:03:13 +0000 | [diff] [blame] | 1170 | |
| 1171 | // The parent itself may be a list node, so find the real parent instruction |
| 1172 | while (parent->getNodeType() != InstrTreeNode::NTInstructionNode) |
| 1173 | { |
| 1174 | parent = parent->parent(); |
| 1175 | assert(parent && "ERROR: Non-instruction node has no parent in tree."); |
| 1176 | } |
| 1177 | InstructionNode* parentInstrNode = (InstructionNode*) parent; |
| 1178 | |
| 1179 | Instruction* userInstr = parentInstrNode->getInstruction(); |
Chris Lattner | 9c46108 | 2002-02-03 07:50:56 +0000 | [diff] [blame] | 1180 | MachineCodeForInstruction &mvec = MachineCodeForInstruction::get(userInstr); |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1181 | |
| 1182 | // The parent's mvec would be empty if it was itself forwarded. |
| 1183 | // Recursively call ForwardOperand in that case... |
| 1184 | // |
| 1185 | if (mvec.size() == 0) |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 1186 | { |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1187 | assert(parent->parent() != NULL && |
| 1188 | "Parent could not have been forwarded, yet has no instructions?"); |
| 1189 | ForwardOperand(treeNode, parent->parent(), operandNum); |
| 1190 | } |
| 1191 | else |
| 1192 | { |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1193 | for (unsigned i=0, N=mvec.size(); i < N; i++) |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1194 | { |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1195 | MachineInstr* minstr = mvec[i]; |
| 1196 | for (unsigned i=0, numOps=minstr->getNumOperands(); i < numOps; ++i) |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1197 | { |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1198 | const MachineOperand& mop = minstr->getOperand(i); |
| 1199 | if (mop.getOperandType() == MachineOperand::MO_VirtualRegister && |
| 1200 | mop.getVRegValue() == unusedOp) |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 1201 | minstr->SetMachineOperandVal(i, |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1202 | MachineOperand::MO_VirtualRegister, fwdOp); |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1203 | } |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1204 | |
| 1205 | for (unsigned i=0,numOps=minstr->getNumImplicitRefs(); i<numOps; ++i) |
| 1206 | if (minstr->getImplicitRef(i) == unusedOp) |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 1207 | minstr->setImplicitRef(i, fwdOp, |
Vikram S. Adve | 6418eac | 2002-07-08 23:30:14 +0000 | [diff] [blame] | 1208 | minstr->implicitRefIsDefined(i), |
| 1209 | minstr->implicitRefIsDefinedAndUsed(i)); |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1210 | } |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 1211 | } |
| 1212 | } |
| 1213 | |
| 1214 | |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 1215 | inline bool |
| 1216 | AllUsesAreBranches(const Instruction* setccI) |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1217 | { |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 1218 | for (Value::use_const_iterator UI=setccI->use_begin(), UE=setccI->use_end(); |
| 1219 | UI != UE; ++UI) |
| 1220 | if (! isa<TmpInstruction>(*UI) // ignore tmp instructions here |
| 1221 | && cast<Instruction>(*UI)->getOpcode() != Instruction::Br) |
| 1222 | return false; |
| 1223 | return true; |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1224 | } |
| 1225 | |
Vikram S. Adve | fb36112 | 2001-10-22 13:36:31 +0000 | [diff] [blame] | 1226 | //******************* Externally Visible Functions *************************/ |
| 1227 | |
Vikram S. Adve | fb36112 | 2001-10-22 13:36:31 +0000 | [diff] [blame] | 1228 | //------------------------------------------------------------------------ |
| 1229 | // External Function: ThisIsAChainRule |
| 1230 | // |
| 1231 | // Purpose: |
| 1232 | // Check if a given BURG rule is a chain rule. |
| 1233 | //------------------------------------------------------------------------ |
| 1234 | |
| 1235 | extern bool |
| 1236 | ThisIsAChainRule(int eruleno) |
| 1237 | { |
| 1238 | switch(eruleno) |
| 1239 | { |
| 1240 | case 111: // stmt: reg |
| 1241 | case 113: // stmt: bool |
| 1242 | case 123: |
| 1243 | case 124: |
| 1244 | case 125: |
| 1245 | case 126: |
| 1246 | case 127: |
| 1247 | case 128: |
| 1248 | case 129: |
| 1249 | case 130: |
| 1250 | case 131: |
| 1251 | case 132: |
| 1252 | case 133: |
| 1253 | case 155: |
| 1254 | case 221: |
| 1255 | case 222: |
| 1256 | case 241: |
| 1257 | case 242: |
| 1258 | case 243: |
| 1259 | case 244: |
Vikram S. Adve | 85e1e9c | 2002-04-01 20:28:48 +0000 | [diff] [blame] | 1260 | case 321: |
Vikram S. Adve | fb36112 | 2001-10-22 13:36:31 +0000 | [diff] [blame] | 1261 | return true; break; |
| 1262 | |
| 1263 | default: |
| 1264 | return false; break; |
| 1265 | } |
| 1266 | } |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 1267 | |
| 1268 | |
| 1269 | //------------------------------------------------------------------------ |
| 1270 | // External Function: GetInstructionsByRule |
| 1271 | // |
| 1272 | // Purpose: |
| 1273 | // Choose machine instructions for the SPARC according to the |
| 1274 | // patterns chosen by the BURG-generated parser. |
| 1275 | //------------------------------------------------------------------------ |
| 1276 | |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1277 | void |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 1278 | GetInstructionsByRule(InstructionNode* subtreeRoot, |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1279 | int ruleForNode, |
| 1280 | short* nts, |
Vikram S. Adve | ff5a09e | 2001-11-08 05:04:09 +0000 | [diff] [blame] | 1281 | TargetMachine &target, |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1282 | vector<MachineInstr*>& mvec) |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 1283 | { |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 1284 | bool checkCast = false; // initialize here to use fall-through |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 1285 | int nextRule; |
| 1286 | int forwardOperandNum = -1; |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1287 | unsigned int allocaSize = 0; |
| 1288 | MachineInstr* M, *M2; |
| 1289 | unsigned int L; |
| 1290 | |
| 1291 | mvec.clear(); |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 1292 | |
Vikram S. Adve | fd3900a | 2002-03-24 03:33:02 +0000 | [diff] [blame] | 1293 | // If the code for this instruction was folded into the parent (user), |
| 1294 | // then do nothing! |
| 1295 | if (subtreeRoot->isFoldedIntoParent()) |
| 1296 | return; |
| 1297 | |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1298 | // |
| 1299 | // Let's check for chain rules outside the switch so that we don't have |
| 1300 | // to duplicate the list of chain rule production numbers here again |
| 1301 | // |
| 1302 | if (ThisIsAChainRule(ruleForNode)) |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 1303 | { |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1304 | // Chain rules have a single nonterminal on the RHS. |
| 1305 | // Get the rule that matches the RHS non-terminal and use that instead. |
| 1306 | // |
| 1307 | assert(nts[0] && ! nts[1] |
| 1308 | && "A chain rule should have only one RHS non-terminal!"); |
| 1309 | nextRule = burm_rule(subtreeRoot->state, nts[0]); |
| 1310 | nts = burm_nts[nextRule]; |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1311 | GetInstructionsByRule(subtreeRoot, nextRule, nts, target, mvec); |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 1312 | } |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1313 | else |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 1314 | { |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1315 | switch(ruleForNode) { |
| 1316 | case 1: // stmt: Ret |
| 1317 | case 2: // stmt: RetValue(reg) |
Vikram S. Adve | b7f06f4 | 2001-11-04 19:34:49 +0000 | [diff] [blame] | 1318 | { // NOTE: Prepass of register allocation is responsible |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1319 | // for moving return value to appropriate register. |
| 1320 | // Mark the return-address register as a hidden virtual reg. |
Vikram S. Adve | a995e60 | 2001-10-11 04:23:19 +0000 | [diff] [blame] | 1321 | // Mark the return value register as an implicit ref of |
| 1322 | // the machine instruction. |
Vikram S. Adve | b7f06f4 | 2001-11-04 19:34:49 +0000 | [diff] [blame] | 1323 | // Finally put a NOP in the delay slot. |
Chris Lattner | e9bb2df | 2001-12-03 22:26:30 +0000 | [diff] [blame] | 1324 | ReturnInst *returnInstr = |
| 1325 | cast<ReturnInst>(subtreeRoot->getInstruction()); |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1326 | assert(returnInstr->getOpcode() == Instruction::Ret); |
| 1327 | |
Chris Lattner | 9c46108 | 2002-02-03 07:50:56 +0000 | [diff] [blame] | 1328 | Instruction* returnReg = new TmpInstruction(returnInstr); |
| 1329 | MachineCodeForInstruction::get(returnInstr).addTemp(returnReg); |
Vikram S. Adve | fb36112 | 2001-10-22 13:36:31 +0000 | [diff] [blame] | 1330 | |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1331 | M = new MachineInstr(JMPLRET); |
| 1332 | M->SetMachineOperandReg(0, MachineOperand::MO_VirtualRegister, |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1333 | returnReg); |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1334 | M->SetMachineOperandConst(1,MachineOperand::MO_SignExtendedImmed, |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 1335 | (int64_t)8); |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1336 | M->SetMachineOperandReg(2, target.getRegInfo().getZeroRegNum()); |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1337 | |
Vikram S. Adve | a995e60 | 2001-10-11 04:23:19 +0000 | [diff] [blame] | 1338 | if (returnInstr->getReturnValue() != NULL) |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1339 | M->addImplicitRef(returnInstr->getReturnValue()); |
Vikram S. Adve | a995e60 | 2001-10-11 04:23:19 +0000 | [diff] [blame] | 1340 | |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1341 | mvec.push_back(M); |
| 1342 | mvec.push_back(new MachineInstr(NOP)); |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1343 | |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1344 | break; |
Vikram S. Adve | b7f06f4 | 2001-11-04 19:34:49 +0000 | [diff] [blame] | 1345 | } |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1346 | |
| 1347 | case 3: // stmt: Store(reg,reg) |
| 1348 | case 4: // stmt: Store(reg,ptrreg) |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1349 | mvec.push_back(new MachineInstr( |
| 1350 | ChooseStoreInstruction( |
| 1351 | subtreeRoot->leftChild()->getValue()->getType()))); |
| 1352 | SetOperandsForMemInstr(mvec, mvec.end()-1, subtreeRoot, target); |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1353 | break; |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 1354 | |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1355 | case 5: // stmt: BrUncond |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1356 | M = new MachineInstr(BA); |
Vikram S. Adve | 6418eac | 2002-07-08 23:30:14 +0000 | [diff] [blame] | 1357 | M->SetMachineOperandVal(0, MachineOperand::MO_PCRelativeDisp, |
Chris Lattner | e9bb2df | 2001-12-03 22:26:30 +0000 | [diff] [blame] | 1358 | cast<BranchInst>(subtreeRoot->getInstruction())->getSuccessor(0)); |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1359 | mvec.push_back(M); |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1360 | |
| 1361 | // delay slot |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1362 | mvec.push_back(new MachineInstr(NOP)); |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1363 | break; |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 1364 | |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1365 | case 206: // stmt: BrCond(setCCconst) |
Vikram S. Adve | b7f06f4 | 2001-11-04 19:34:49 +0000 | [diff] [blame] | 1366 | { // setCCconst => boolean was computed with `%b = setCC type reg1 const' |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1367 | // If the constant is ZERO, we can use the branch-on-integer-register |
| 1368 | // instructions and avoid the SUBcc instruction entirely. |
| 1369 | // Otherwise this is just the same as case 5, so just fall through. |
Vikram S. Adve | b7f06f4 | 2001-11-04 19:34:49 +0000 | [diff] [blame] | 1370 | // |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1371 | InstrTreeNode* constNode = subtreeRoot->leftChild()->rightChild(); |
| 1372 | assert(constNode && |
| 1373 | constNode->getNodeType() ==InstrTreeNode::NTConstNode); |
Chris Lattner | e9bb2df | 2001-12-03 22:26:30 +0000 | [diff] [blame] | 1374 | Constant *constVal = cast<Constant>(constNode->getValue()); |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1375 | bool isValidConst; |
Vikram S. Adve | fd3900a | 2002-03-24 03:33:02 +0000 | [diff] [blame] | 1376 | |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1377 | if ((constVal->getType()->isIntegral() |
Chris Lattner | 9b62503 | 2002-05-06 16:15:30 +0000 | [diff] [blame] | 1378 | || isa<PointerType>(constVal->getType())) |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1379 | && GetConstantValueAsSignedInt(constVal, isValidConst) == 0 |
| 1380 | && isValidConst) |
| 1381 | { |
| 1382 | // That constant is a zero after all... |
| 1383 | // Use the left child of setCC as the first argument! |
Vikram S. Adve | fd3900a | 2002-03-24 03:33:02 +0000 | [diff] [blame] | 1384 | // Mark the setCC node so that no code is generated for it. |
| 1385 | InstructionNode* setCCNode = (InstructionNode*) |
| 1386 | subtreeRoot->leftChild(); |
| 1387 | assert(setCCNode->getOpLabel() == SetCCOp); |
| 1388 | setCCNode->markFoldedIntoParent(); |
| 1389 | |
| 1390 | BranchInst* brInst=cast<BranchInst>(subtreeRoot->getInstruction()); |
| 1391 | |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1392 | M = new MachineInstr(ChooseBprInstruction(subtreeRoot)); |
| 1393 | M->SetMachineOperandVal(0, MachineOperand::MO_VirtualRegister, |
Vikram S. Adve | fd3900a | 2002-03-24 03:33:02 +0000 | [diff] [blame] | 1394 | setCCNode->leftChild()->getValue()); |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1395 | M->SetMachineOperandVal(1, MachineOperand::MO_PCRelativeDisp, |
| 1396 | brInst->getSuccessor(0)); |
| 1397 | mvec.push_back(M); |
Vikram S. Adve | fd3900a | 2002-03-24 03:33:02 +0000 | [diff] [blame] | 1398 | |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1399 | // delay slot |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1400 | mvec.push_back(new MachineInstr(NOP)); |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1401 | |
| 1402 | // false branch |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1403 | M = new MachineInstr(BA); |
Vikram S. Adve | 6418eac | 2002-07-08 23:30:14 +0000 | [diff] [blame] | 1404 | M->SetMachineOperandVal(0, MachineOperand::MO_PCRelativeDisp, |
Vikram S. Adve | fd3900a | 2002-03-24 03:33:02 +0000 | [diff] [blame] | 1405 | brInst->getSuccessor(1)); |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1406 | mvec.push_back(M); |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1407 | |
| 1408 | // delay slot |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1409 | mvec.push_back(new MachineInstr(NOP)); |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1410 | |
| 1411 | break; |
| 1412 | } |
| 1413 | // ELSE FALL THROUGH |
Vikram S. Adve | b7f06f4 | 2001-11-04 19:34:49 +0000 | [diff] [blame] | 1414 | } |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1415 | |
| 1416 | case 6: // stmt: BrCond(bool) |
Vikram S. Adve | b7f06f4 | 2001-11-04 19:34:49 +0000 | [diff] [blame] | 1417 | { // bool => boolean was computed with some boolean operator |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1418 | // (SetCC, Not, ...). We need to check whether the type was a FP, |
| 1419 | // signed int or unsigned int, and check the branching condition in |
| 1420 | // order to choose the branch to use. |
Vikram S. Adve | b7f06f4 | 2001-11-04 19:34:49 +0000 | [diff] [blame] | 1421 | // If it is an integer CC, we also need to find the unique |
| 1422 | // TmpInstruction representing that CC. |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1423 | // |
Vikram S. Adve | b7f06f4 | 2001-11-04 19:34:49 +0000 | [diff] [blame] | 1424 | BranchInst* brInst = cast<BranchInst>(subtreeRoot->getInstruction()); |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1425 | bool isFPBranch; |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1426 | M = new MachineInstr(ChooseBccInstruction(subtreeRoot, isFPBranch)); |
Vikram S. Adve | b7f06f4 | 2001-11-04 19:34:49 +0000 | [diff] [blame] | 1427 | |
Vikram S. Adve | ff5a09e | 2001-11-08 05:04:09 +0000 | [diff] [blame] | 1428 | Value* ccValue = GetTmpForCC(subtreeRoot->leftChild()->getValue(), |
| 1429 | brInst->getParent()->getParent(), |
| 1430 | isFPBranch? Type::FloatTy : Type::IntTy); |
Vikram S. Adve | b7f06f4 | 2001-11-04 19:34:49 +0000 | [diff] [blame] | 1431 | |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1432 | M->SetMachineOperandVal(0, MachineOperand::MO_CCRegister, ccValue); |
| 1433 | M->SetMachineOperandVal(1, MachineOperand::MO_PCRelativeDisp, |
| 1434 | brInst->getSuccessor(0)); |
| 1435 | mvec.push_back(M); |
Vikram S. Adve | b7f06f4 | 2001-11-04 19:34:49 +0000 | [diff] [blame] | 1436 | |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1437 | // delay slot |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1438 | mvec.push_back(new MachineInstr(NOP)); |
Vikram S. Adve | b7f06f4 | 2001-11-04 19:34:49 +0000 | [diff] [blame] | 1439 | |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1440 | // false branch |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1441 | M = new MachineInstr(BA); |
Vikram S. Adve | 6418eac | 2002-07-08 23:30:14 +0000 | [diff] [blame] | 1442 | M->SetMachineOperandVal(0, MachineOperand::MO_PCRelativeDisp, |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1443 | brInst->getSuccessor(1)); |
| 1444 | mvec.push_back(M); |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1445 | |
| 1446 | // delay slot |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1447 | mvec.push_back(new MachineInstr(NOP)); |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1448 | break; |
Vikram S. Adve | b7f06f4 | 2001-11-04 19:34:49 +0000 | [diff] [blame] | 1449 | } |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1450 | |
| 1451 | case 208: // stmt: BrCond(boolconst) |
Vikram S. Adve | b7f06f4 | 2001-11-04 19:34:49 +0000 | [diff] [blame] | 1452 | { |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1453 | // boolconst => boolean is a constant; use BA to first or second label |
Chris Lattner | e9bb2df | 2001-12-03 22:26:30 +0000 | [diff] [blame] | 1454 | Constant* constVal = |
| 1455 | cast<Constant>(subtreeRoot->leftChild()->getValue()); |
| 1456 | unsigned dest = cast<ConstantBool>(constVal)->getValue()? 0 : 1; |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1457 | |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1458 | M = new MachineInstr(BA); |
Vikram S. Adve | 6418eac | 2002-07-08 23:30:14 +0000 | [diff] [blame] | 1459 | M->SetMachineOperandVal(0, MachineOperand::MO_PCRelativeDisp, |
Chris Lattner | 3550420 | 2002-04-27 03:14:39 +0000 | [diff] [blame] | 1460 | cast<BranchInst>(subtreeRoot->getInstruction())->getSuccessor(dest)); |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1461 | mvec.push_back(M); |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1462 | |
| 1463 | // delay slot |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1464 | mvec.push_back(new MachineInstr(NOP)); |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1465 | break; |
Vikram S. Adve | b7f06f4 | 2001-11-04 19:34:49 +0000 | [diff] [blame] | 1466 | } |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1467 | |
| 1468 | case 8: // stmt: BrCond(boolreg) |
Vikram S. Adve | b7f06f4 | 2001-11-04 19:34:49 +0000 | [diff] [blame] | 1469 | { // boolreg => boolean is stored in an existing register. |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1470 | // Just use the branch-on-integer-register instruction! |
| 1471 | // |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1472 | M = new MachineInstr(BRNZ); |
| 1473 | M->SetMachineOperandVal(0, MachineOperand::MO_VirtualRegister, |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1474 | subtreeRoot->leftChild()->getValue()); |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1475 | M->SetMachineOperandVal(1, MachineOperand::MO_PCRelativeDisp, |
Chris Lattner | 3550420 | 2002-04-27 03:14:39 +0000 | [diff] [blame] | 1476 | cast<BranchInst>(subtreeRoot->getInstruction())->getSuccessor(0)); |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1477 | mvec.push_back(M); |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1478 | |
| 1479 | // delay slot |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1480 | mvec.push_back(new MachineInstr(NOP)); |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1481 | |
| 1482 | // false branch |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1483 | M = new MachineInstr(BA); |
Vikram S. Adve | 6418eac | 2002-07-08 23:30:14 +0000 | [diff] [blame] | 1484 | M->SetMachineOperandVal(0, MachineOperand::MO_PCRelativeDisp, |
Chris Lattner | 3550420 | 2002-04-27 03:14:39 +0000 | [diff] [blame] | 1485 | cast<BranchInst>(subtreeRoot->getInstruction())->getSuccessor(1)); |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1486 | mvec.push_back(M); |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1487 | |
| 1488 | // delay slot |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1489 | mvec.push_back(new MachineInstr(NOP)); |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1490 | break; |
Vikram S. Adve | b7f06f4 | 2001-11-04 19:34:49 +0000 | [diff] [blame] | 1491 | } |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 1492 | |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1493 | case 9: // stmt: Switch(reg) |
| 1494 | assert(0 && "*** SWITCH instruction is not implemented yet."); |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1495 | break; |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 1496 | |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1497 | case 10: // reg: VRegList(reg, reg) |
| 1498 | assert(0 && "VRegList should never be the topmost non-chain rule"); |
| 1499 | break; |
| 1500 | |
Vikram S. Adve | ff5a09e | 2001-11-08 05:04:09 +0000 | [diff] [blame] | 1501 | case 21: // bool: Not(bool): Both these are implemented as: |
Vikram S. Adve | 85e1e9c | 2002-04-01 20:28:48 +0000 | [diff] [blame] | 1502 | case 421: // reg: BNot(reg) : reg = reg XOR-NOT 0 |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1503 | M = new MachineInstr(XNOR); |
| 1504 | M->SetMachineOperandVal(0, MachineOperand::MO_VirtualRegister, |
| 1505 | subtreeRoot->leftChild()->getValue()); |
| 1506 | M->SetMachineOperandReg(1, target.getRegInfo().getZeroRegNum()); |
| 1507 | M->SetMachineOperandVal(2, MachineOperand::MO_VirtualRegister, |
| 1508 | subtreeRoot->getValue()); |
| 1509 | mvec.push_back(M); |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1510 | break; |
| 1511 | |
| 1512 | case 322: // reg: ToBoolTy(bool): |
| 1513 | case 22: // reg: ToBoolTy(reg): |
Vikram S. Adve | 6ad7c55 | 2001-11-09 02:18:16 +0000 | [diff] [blame] | 1514 | { |
| 1515 | const Type* opType = subtreeRoot->leftChild()->getValue()->getType(); |
Chris Lattner | 9b62503 | 2002-05-06 16:15:30 +0000 | [diff] [blame] | 1516 | assert(opType->isIntegral() || isa<PointerType>(opType) |
Vikram S. Adve | 6ad7c55 | 2001-11-09 02:18:16 +0000 | [diff] [blame] | 1517 | || opType == Type::BoolTy); |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1518 | forwardOperandNum = 0; // forward first operand to user |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1519 | break; |
Vikram S. Adve | 6ad7c55 | 2001-11-09 02:18:16 +0000 | [diff] [blame] | 1520 | } |
| 1521 | |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1522 | case 23: // reg: ToUByteTy(reg) |
| 1523 | case 25: // reg: ToUShortTy(reg) |
| 1524 | case 27: // reg: ToUIntTy(reg) |
| 1525 | case 29: // reg: ToULongTy(reg) |
Vikram S. Adve | 6ad7c55 | 2001-11-09 02:18:16 +0000 | [diff] [blame] | 1526 | { |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 1527 | Instruction* destI = subtreeRoot->getInstruction(); |
| 1528 | Value* opVal = subtreeRoot->leftChild()->getValue(); |
Vikram S. Adve | 6ad7c55 | 2001-11-09 02:18:16 +0000 | [diff] [blame] | 1529 | const Type* opType = subtreeRoot->leftChild()->getValue()->getType(); |
Vikram S. Adve | 1e60669 | 2002-07-31 21:01:34 +0000 | [diff] [blame^] | 1530 | if (opType->isIntegral() |
| 1531 | || isa<PointerType>(opType) |
| 1532 | || opType == Type::BoolTy) |
| 1533 | { |
| 1534 | unsigned opSize = target.DataLayout.getTypeSize(opType); |
| 1535 | unsigned destSize = target.DataLayout.getTypeSize(destI->getType()); |
| 1536 | if (opSize > destSize || |
| 1537 | (opType->isSigned() |
| 1538 | && destSize < target.DataLayout.getIntegerRegize())) |
| 1539 | { // operand is larger than dest, |
| 1540 | // OR both are equal but smaller than the full register size |
| 1541 | // AND operand is signed, so it may have extra sign bits: |
| 1542 | // mask high bits using AND |
| 1543 | M = Create3OperandInstr(AND, opVal, |
| 1544 | ConstantUInt::get(Type::ULongTy, |
| 1545 | ((uint64_t) 1 << 8*destSize) - 1), |
| 1546 | destI); |
| 1547 | mvec.push_back(M); |
| 1548 | } |
| 1549 | else |
| 1550 | forwardOperandNum = 0; // forward first operand to user |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 1551 | } |
Vikram S. Adve | 1e60669 | 2002-07-31 21:01:34 +0000 | [diff] [blame^] | 1552 | else if (opType->isFloatingPoint()) |
| 1553 | CreateCodeToConvertIntToFloat(target, opVal, destI, mvec, |
| 1554 | MachineCodeForInstruction::get(destI)); |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 1555 | else |
Vikram S. Adve | 1e60669 | 2002-07-31 21:01:34 +0000 | [diff] [blame^] | 1556 | assert(0 && "Unrecognized operand type for convert-to-unsigned"); |
| 1557 | |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1558 | break; |
Vikram S. Adve | 6ad7c55 | 2001-11-09 02:18:16 +0000 | [diff] [blame] | 1559 | } |
| 1560 | |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1561 | case 24: // reg: ToSByteTy(reg) |
| 1562 | case 26: // reg: ToShortTy(reg) |
| 1563 | case 28: // reg: ToIntTy(reg) |
| 1564 | case 30: // reg: ToLongTy(reg) |
Vikram S. Adve | 6ad7c55 | 2001-11-09 02:18:16 +0000 | [diff] [blame] | 1565 | { |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 1566 | Instruction* destI = subtreeRoot->getInstruction(); |
| 1567 | Value* opVal = subtreeRoot->leftChild()->getValue(); |
| 1568 | MachineCodeForInstruction& mcfi =MachineCodeForInstruction::get(destI); |
Vikram S. Adve | 1e60669 | 2002-07-31 21:01:34 +0000 | [diff] [blame^] | 1569 | |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 1570 | const Type* opType = opVal->getType(); |
Vikram S. Adve | 6ad7c55 | 2001-11-09 02:18:16 +0000 | [diff] [blame] | 1571 | if (opType->isIntegral() |
Chris Lattner | 9b62503 | 2002-05-06 16:15:30 +0000 | [diff] [blame] | 1572 | || isa<PointerType>(opType) |
Vikram S. Adve | 6ad7c55 | 2001-11-09 02:18:16 +0000 | [diff] [blame] | 1573 | || opType == Type::BoolTy) |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1574 | { |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 1575 | // These operand types have the same format as the destination, |
| 1576 | // but may have different size: add sign bits or mask as needed. |
| 1577 | // |
| 1578 | const Type* destType = destI->getType(); |
| 1579 | unsigned opSize = target.DataLayout.getTypeSize(opType); |
| 1580 | unsigned destSize = target.DataLayout.getTypeSize(destType); |
Vikram S. Adve | 1e60669 | 2002-07-31 21:01:34 +0000 | [diff] [blame^] | 1581 | if (opSize < destSize && !opType->isSigned()) |
| 1582 | { // operand is unsigned and smaller than dest: sign-extend |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 1583 | target.getInstrInfo().CreateSignExtensionInstructions(target, destI->getParent()->getParent(), opVal, 8*opSize, destI, mvec, mcfi); |
| 1584 | } |
| 1585 | else if (opSize > destSize) |
| 1586 | { // operand is larger than dest: mask high bits using AND |
| 1587 | // and then sign-extend using SRA by 0! |
| 1588 | // |
| 1589 | TmpInstruction *tmpI = new TmpInstruction(destType, opVal, |
| 1590 | destI, "maskHi"); |
| 1591 | mcfi.addTemp(tmpI); |
| 1592 | M = Create3OperandInstr(AND, opVal, |
| 1593 | ConstantUInt::get(Type::UIntTy, |
| 1594 | ((uint64_t) 1 << 8*destSize)-1), |
| 1595 | tmpI); |
| 1596 | mvec.push_back(M); |
| 1597 | |
| 1598 | target.getInstrInfo().CreateSignExtensionInstructions(target, destI->getParent()->getParent(), tmpI, 8*destSize, destI, mvec, mcfi); |
| 1599 | } |
Vikram S. Adve | 6ad7c55 | 2001-11-09 02:18:16 +0000 | [diff] [blame] | 1600 | else |
Vikram S. Adve | 1e60669 | 2002-07-31 21:01:34 +0000 | [diff] [blame^] | 1601 | forwardOperandNum = 0; // forward first operand to user |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1602 | } |
Vikram S. Adve | 1e60669 | 2002-07-31 21:01:34 +0000 | [diff] [blame^] | 1603 | else if (opType->isFloatingPoint()) |
| 1604 | CreateCodeToConvertIntToFloat(target, opVal, destI, mvec, mcfi); |
| 1605 | else |
| 1606 | assert(0 && "Unrecognized operand type for convert-to-signed"); |
| 1607 | |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1608 | break; |
Vikram S. Adve | 6ad7c55 | 2001-11-09 02:18:16 +0000 | [diff] [blame] | 1609 | } |
| 1610 | |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1611 | case 31: // reg: ToFloatTy(reg): |
| 1612 | case 32: // reg: ToDoubleTy(reg): |
| 1613 | case 232: // reg: ToDoubleTy(Constant): |
| 1614 | |
| 1615 | // If this instruction has a parent (a user) in the tree |
| 1616 | // and the user is translated as an FsMULd instruction, |
| 1617 | // then the cast is unnecessary. So check that first. |
| 1618 | // In the future, we'll want to do the same for the FdMULq instruction, |
| 1619 | // so do the check here instead of only for ToFloatTy(reg). |
| 1620 | // |
| 1621 | if (subtreeRoot->parent() != NULL && |
Chris Lattner | 9c46108 | 2002-02-03 07:50:56 +0000 | [diff] [blame] | 1622 | MachineCodeForInstruction::get(((InstructionNode*)subtreeRoot->parent())->getInstruction())[0]->getOpCode() == FSMULD) |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1623 | { |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1624 | forwardOperandNum = 0; // forward first operand to user |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1625 | } |
| 1626 | else |
| 1627 | { |
Vikram S. Adve | 6ad7c55 | 2001-11-09 02:18:16 +0000 | [diff] [blame] | 1628 | Value* leftVal = subtreeRoot->leftChild()->getValue(); |
| 1629 | const Type* opType = leftVal->getType(); |
Vikram S. Adve | dbc4fad | 2002-04-25 04:37:51 +0000 | [diff] [blame] | 1630 | MachineOpCode opCode=ChooseConvertToFloatInstr( |
| 1631 | subtreeRoot->getOpLabel(), opType); |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1632 | if (opCode == INVALID_OPCODE) // no conversion needed |
| 1633 | { |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1634 | forwardOperandNum = 0; // forward first operand to user |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1635 | } |
| 1636 | else |
| 1637 | { |
Vikram S. Adve | ff5a09e | 2001-11-08 05:04:09 +0000 | [diff] [blame] | 1638 | // If the source operand is a non-FP type it must be |
| 1639 | // first copied from int to float register via memory! |
| 1640 | Instruction *dest = subtreeRoot->getInstruction(); |
| 1641 | Value* srcForCast; |
| 1642 | int n = 0; |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 1643 | if (! opType->isFloatingPoint()) |
Vikram S. Adve | ff5a09e | 2001-11-08 05:04:09 +0000 | [diff] [blame] | 1644 | { |
| 1645 | // Create a temporary to represent the FP register |
| 1646 | // into which the integer will be copied via memory. |
Vikram S. Adve | 6ad7c55 | 2001-11-09 02:18:16 +0000 | [diff] [blame] | 1647 | // The type of this temporary will determine the FP |
| 1648 | // register used: single-prec for a 32-bit int or smaller, |
| 1649 | // double-prec for a 64-bit int. |
| 1650 | // |
| 1651 | const Type* srcTypeToUse = |
| 1652 | (leftVal->getType() == Type::LongTy)? Type::DoubleTy |
| 1653 | : Type::FloatTy; |
| 1654 | |
Chris Lattner | 9c46108 | 2002-02-03 07:50:56 +0000 | [diff] [blame] | 1655 | srcForCast = new TmpInstruction(srcTypeToUse, dest); |
Vikram S. Adve | dbc4fad | 2002-04-25 04:37:51 +0000 | [diff] [blame] | 1656 | MachineCodeForInstruction &destMCFI = |
Chris Lattner | 9c46108 | 2002-02-03 07:50:56 +0000 | [diff] [blame] | 1657 | MachineCodeForInstruction::get(dest); |
Vikram S. Adve | dbc4fad | 2002-04-25 04:37:51 +0000 | [diff] [blame] | 1658 | destMCFI.addTemp(srcForCast); |
Vikram S. Adve | ff5a09e | 2001-11-08 05:04:09 +0000 | [diff] [blame] | 1659 | |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 1660 | target.getInstrInfo().CreateCodeToCopyIntToFloat(target, |
Vikram S. Adve | ff5a09e | 2001-11-08 05:04:09 +0000 | [diff] [blame] | 1661 | dest->getParent()->getParent(), |
| 1662 | leftVal, (TmpInstruction*) srcForCast, |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 1663 | mvec, destMCFI); |
Vikram S. Adve | ff5a09e | 2001-11-08 05:04:09 +0000 | [diff] [blame] | 1664 | } |
| 1665 | else |
| 1666 | srcForCast = leftVal; |
| 1667 | |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1668 | M = new MachineInstr(opCode); |
| 1669 | M->SetMachineOperandVal(0, MachineOperand::MO_VirtualRegister, |
| 1670 | srcForCast); |
| 1671 | M->SetMachineOperandVal(1, MachineOperand::MO_VirtualRegister, |
| 1672 | dest); |
| 1673 | mvec.push_back(M); |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1674 | } |
| 1675 | } |
| 1676 | break; |
| 1677 | |
| 1678 | case 19: // reg: ToArrayTy(reg): |
| 1679 | case 20: // reg: ToPointerTy(reg): |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1680 | forwardOperandNum = 0; // forward first operand to user |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1681 | break; |
| 1682 | |
| 1683 | case 233: // reg: Add(reg, Constant) |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1684 | M = CreateAddConstInstruction(subtreeRoot); |
| 1685 | if (M != NULL) |
| 1686 | { |
| 1687 | mvec.push_back(M); |
| 1688 | break; |
| 1689 | } |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1690 | // ELSE FALL THROUGH |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1691 | |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1692 | case 33: // reg: Add(reg, reg) |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1693 | mvec.push_back(new MachineInstr(ChooseAddInstruction(subtreeRoot))); |
| 1694 | Set3OperandsFromInstr(mvec.back(), subtreeRoot, target); |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1695 | break; |
| 1696 | |
| 1697 | case 234: // reg: Sub(reg, Constant) |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1698 | M = CreateSubConstInstruction(subtreeRoot); |
| 1699 | if (M != NULL) |
| 1700 | { |
| 1701 | mvec.push_back(M); |
| 1702 | break; |
| 1703 | } |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1704 | // ELSE FALL THROUGH |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1705 | |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1706 | case 34: // reg: Sub(reg, reg) |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1707 | mvec.push_back(new MachineInstr(ChooseSubInstructionByType( |
| 1708 | subtreeRoot->getInstruction()->getType()))); |
| 1709 | Set3OperandsFromInstr(mvec.back(), subtreeRoot, target); |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1710 | break; |
| 1711 | |
| 1712 | case 135: // reg: Mul(todouble, todouble) |
| 1713 | checkCast = true; |
| 1714 | // FALL THROUGH |
| 1715 | |
| 1716 | case 35: // reg: Mul(reg, reg) |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1717 | { |
| 1718 | MachineOpCode forceOp = ((checkCast && BothFloatToDouble(subtreeRoot)) |
| 1719 | ? FSMULD |
| 1720 | : INVALID_MACHINE_OPCODE); |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 1721 | Instruction* mulInstr = subtreeRoot->getInstruction(); |
| 1722 | CreateMulInstruction(target, mulInstr->getParent()->getParent(), |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1723 | subtreeRoot->leftChild()->getValue(), |
| 1724 | subtreeRoot->rightChild()->getValue(), |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 1725 | mulInstr, mvec, |
| 1726 | MachineCodeForInstruction::get(mulInstr),forceOp); |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1727 | break; |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1728 | } |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1729 | case 335: // reg: Mul(todouble, todoubleConst) |
| 1730 | checkCast = true; |
| 1731 | // FALL THROUGH |
| 1732 | |
| 1733 | case 235: // reg: Mul(reg, Constant) |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1734 | { |
| 1735 | MachineOpCode forceOp = ((checkCast && BothFloatToDouble(subtreeRoot)) |
| 1736 | ? FSMULD |
| 1737 | : INVALID_MACHINE_OPCODE); |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 1738 | Instruction* mulInstr = subtreeRoot->getInstruction(); |
| 1739 | CreateMulInstruction(target, mulInstr->getParent()->getParent(), |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1740 | subtreeRoot->leftChild()->getValue(), |
| 1741 | subtreeRoot->rightChild()->getValue(), |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 1742 | mulInstr, mvec, |
| 1743 | MachineCodeForInstruction::get(mulInstr), |
| 1744 | forceOp); |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1745 | break; |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1746 | } |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1747 | case 236: // reg: Div(reg, Constant) |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1748 | L = mvec.size(); |
| 1749 | CreateDivConstInstruction(target, subtreeRoot, mvec); |
| 1750 | if (mvec.size() > L) |
| 1751 | break; |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1752 | // ELSE FALL THROUGH |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1753 | |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1754 | case 36: // reg: Div(reg, reg) |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1755 | mvec.push_back(new MachineInstr(ChooseDivInstruction(target, subtreeRoot))); |
| 1756 | Set3OperandsFromInstr(mvec.back(), subtreeRoot, target); |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1757 | break; |
| 1758 | |
| 1759 | case 37: // reg: Rem(reg, reg) |
| 1760 | case 237: // reg: Rem(reg, Constant) |
Vikram S. Adve | 510eec7 | 2001-11-04 21:59:14 +0000 | [diff] [blame] | 1761 | { |
| 1762 | Instruction* remInstr = subtreeRoot->getInstruction(); |
| 1763 | |
Chris Lattner | 9c46108 | 2002-02-03 07:50:56 +0000 | [diff] [blame] | 1764 | TmpInstruction* quot = new TmpInstruction( |
Vikram S. Adve | 510eec7 | 2001-11-04 21:59:14 +0000 | [diff] [blame] | 1765 | subtreeRoot->leftChild()->getValue(), |
| 1766 | subtreeRoot->rightChild()->getValue()); |
Chris Lattner | 9c46108 | 2002-02-03 07:50:56 +0000 | [diff] [blame] | 1767 | TmpInstruction* prod = new TmpInstruction( |
Vikram S. Adve | 510eec7 | 2001-11-04 21:59:14 +0000 | [diff] [blame] | 1768 | quot, |
| 1769 | subtreeRoot->rightChild()->getValue()); |
Chris Lattner | 9c46108 | 2002-02-03 07:50:56 +0000 | [diff] [blame] | 1770 | MachineCodeForInstruction::get(remInstr).addTemp(quot).addTemp(prod); |
Vikram S. Adve | 510eec7 | 2001-11-04 21:59:14 +0000 | [diff] [blame] | 1771 | |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1772 | M = new MachineInstr(ChooseDivInstruction(target, subtreeRoot)); |
| 1773 | Set3OperandsFromInstr(M, subtreeRoot, target); |
| 1774 | M->SetMachineOperandVal(2, MachineOperand::MO_VirtualRegister,quot); |
| 1775 | mvec.push_back(M); |
Vikram S. Adve | 510eec7 | 2001-11-04 21:59:14 +0000 | [diff] [blame] | 1776 | |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1777 | M = new MachineInstr(ChooseMulInstructionByType( |
Vikram S. Adve | 510eec7 | 2001-11-04 21:59:14 +0000 | [diff] [blame] | 1778 | subtreeRoot->getInstruction()->getType())); |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1779 | M->SetMachineOperandVal(0, MachineOperand::MO_VirtualRegister,quot); |
| 1780 | M->SetMachineOperandVal(1, MachineOperand::MO_VirtualRegister, |
Vikram S. Adve | 510eec7 | 2001-11-04 21:59:14 +0000 | [diff] [blame] | 1781 | subtreeRoot->rightChild()->getValue()); |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1782 | M->SetMachineOperandVal(2, MachineOperand::MO_VirtualRegister,prod); |
| 1783 | mvec.push_back(M); |
Vikram S. Adve | 510eec7 | 2001-11-04 21:59:14 +0000 | [diff] [blame] | 1784 | |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1785 | M = new MachineInstr(ChooseSubInstructionByType( |
Vikram S. Adve | 510eec7 | 2001-11-04 21:59:14 +0000 | [diff] [blame] | 1786 | subtreeRoot->getInstruction()->getType())); |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1787 | Set3OperandsFromInstr(M, subtreeRoot, target); |
| 1788 | M->SetMachineOperandVal(1, MachineOperand::MO_VirtualRegister,prod); |
| 1789 | mvec.push_back(M); |
Vikram S. Adve | 510eec7 | 2001-11-04 21:59:14 +0000 | [diff] [blame] | 1790 | |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1791 | break; |
Vikram S. Adve | 510eec7 | 2001-11-04 21:59:14 +0000 | [diff] [blame] | 1792 | } |
| 1793 | |
Vikram S. Adve | ff5a09e | 2001-11-08 05:04:09 +0000 | [diff] [blame] | 1794 | case 38: // bool: And(bool, bool) |
| 1795 | case 238: // bool: And(bool, boolconst) |
| 1796 | case 338: // reg : BAnd(reg, reg) |
| 1797 | case 538: // reg : BAnd(reg, Constant) |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1798 | mvec.push_back(new MachineInstr(AND)); |
| 1799 | Set3OperandsFromInstr(mvec.back(), subtreeRoot, target); |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1800 | break; |
| 1801 | |
Vikram S. Adve | ff5a09e | 2001-11-08 05:04:09 +0000 | [diff] [blame] | 1802 | case 138: // bool: And(bool, not) |
| 1803 | case 438: // bool: BAnd(bool, not) |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1804 | mvec.push_back(new MachineInstr(ANDN)); |
| 1805 | Set3OperandsFromInstr(mvec.back(), subtreeRoot, target); |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1806 | break; |
| 1807 | |
Vikram S. Adve | ff5a09e | 2001-11-08 05:04:09 +0000 | [diff] [blame] | 1808 | case 39: // bool: Or(bool, bool) |
| 1809 | case 239: // bool: Or(bool, boolconst) |
| 1810 | case 339: // reg : BOr(reg, reg) |
| 1811 | case 539: // reg : BOr(reg, Constant) |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 1812 | mvec.push_back(new MachineInstr(OR)); |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1813 | Set3OperandsFromInstr(mvec.back(), subtreeRoot, target); |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1814 | break; |
| 1815 | |
Vikram S. Adve | ff5a09e | 2001-11-08 05:04:09 +0000 | [diff] [blame] | 1816 | case 139: // bool: Or(bool, not) |
| 1817 | case 439: // bool: BOr(bool, not) |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1818 | mvec.push_back(new MachineInstr(ORN)); |
| 1819 | Set3OperandsFromInstr(mvec.back(), subtreeRoot, target); |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1820 | break; |
| 1821 | |
Vikram S. Adve | ff5a09e | 2001-11-08 05:04:09 +0000 | [diff] [blame] | 1822 | case 40: // bool: Xor(bool, bool) |
| 1823 | case 240: // bool: Xor(bool, boolconst) |
| 1824 | case 340: // reg : BXor(reg, reg) |
| 1825 | case 540: // reg : BXor(reg, Constant) |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1826 | mvec.push_back(new MachineInstr(XOR)); |
| 1827 | Set3OperandsFromInstr(mvec.back(), subtreeRoot, target); |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1828 | break; |
| 1829 | |
Vikram S. Adve | ff5a09e | 2001-11-08 05:04:09 +0000 | [diff] [blame] | 1830 | case 140: // bool: Xor(bool, not) |
| 1831 | case 440: // bool: BXor(bool, not) |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1832 | mvec.push_back(new MachineInstr(XNOR)); |
| 1833 | Set3OperandsFromInstr(mvec.back(), subtreeRoot, target); |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1834 | break; |
| 1835 | |
| 1836 | case 41: // boolconst: SetCC(reg, Constant) |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1837 | // |
Vikram S. Adve | fd3900a | 2002-03-24 03:33:02 +0000 | [diff] [blame] | 1838 | // If the SetCC was folded into the user (parent), it will be |
| 1839 | // caught above. All other cases are the same as case 42, |
| 1840 | // so just fall through. |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1841 | // |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1842 | case 42: // bool: SetCC(reg, reg): |
| 1843 | { |
Vikram S. Adve | b7f06f4 | 2001-11-04 19:34:49 +0000 | [diff] [blame] | 1844 | // This generates a SUBCC instruction, putting the difference in |
| 1845 | // a result register, and setting a condition code. |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1846 | // |
Vikram S. Adve | b7f06f4 | 2001-11-04 19:34:49 +0000 | [diff] [blame] | 1847 | // If the boolean result of the SetCC is used by anything other |
Vikram S. Adve | 6418eac | 2002-07-08 23:30:14 +0000 | [diff] [blame] | 1848 | // than a branch instruction, or if it is used outside the current |
| 1849 | // basic block, the boolean must be |
Vikram S. Adve | b7f06f4 | 2001-11-04 19:34:49 +0000 | [diff] [blame] | 1850 | // computed and stored in the result register. Otherwise, discard |
| 1851 | // the difference (by using %g0) and keep only the condition code. |
| 1852 | // |
| 1853 | // To compute the boolean result in a register we use a conditional |
| 1854 | // move, unless the result of the SUBCC instruction can be used as |
| 1855 | // the bool! This assumes that zero is FALSE and any non-zero |
| 1856 | // integer is TRUE. |
| 1857 | // |
| 1858 | InstructionNode* parentNode = (InstructionNode*) subtreeRoot->parent(); |
| 1859 | Instruction* setCCInstr = subtreeRoot->getInstruction(); |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 1860 | |
Vikram S. Adve | 6418eac | 2002-07-08 23:30:14 +0000 | [diff] [blame] | 1861 | bool keepBoolVal = parentNode == NULL || |
| 1862 | ! AllUsesAreBranches(setCCInstr); |
Vikram S. Adve | b7f06f4 | 2001-11-04 19:34:49 +0000 | [diff] [blame] | 1863 | bool subValIsBoolVal = setCCInstr->getOpcode() == Instruction::SetNE; |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1864 | bool keepSubVal = keepBoolVal && subValIsBoolVal; |
| 1865 | bool computeBoolVal = keepBoolVal && ! subValIsBoolVal; |
| 1866 | |
| 1867 | bool mustClearReg; |
| 1868 | int valueToMove; |
Chris Lattner | 8e5c0b4 | 2001-11-07 14:01:59 +0000 | [diff] [blame] | 1869 | MachineOpCode movOpCode = 0; |
Vikram S. Adve | 6418eac | 2002-07-08 23:30:14 +0000 | [diff] [blame] | 1870 | |
Vikram S. Adve | ff5a09e | 2001-11-08 05:04:09 +0000 | [diff] [blame] | 1871 | // Mark the 4th operand as being a CC register, and as a def |
| 1872 | // A TmpInstruction is created to represent the CC "result". |
| 1873 | // Unlike other instances of TmpInstruction, this one is used |
| 1874 | // by machine code of multiple LLVM instructions, viz., |
| 1875 | // the SetCC and the branch. Make sure to get the same one! |
| 1876 | // Note that we do this even for FP CC registers even though they |
| 1877 | // are explicit operands, because the type of the operand |
| 1878 | // needs to be a floating point condition code, not an integer |
| 1879 | // condition code. Think of this as casting the bool result to |
| 1880 | // a FP condition code register. |
| 1881 | // |
Vikram S. Adve | 6ad7c55 | 2001-11-09 02:18:16 +0000 | [diff] [blame] | 1882 | Value* leftVal = subtreeRoot->leftChild()->getValue(); |
Chris Lattner | 9b62503 | 2002-05-06 16:15:30 +0000 | [diff] [blame] | 1883 | bool isFPCompare = leftVal->getType()->isFloatingPoint(); |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1884 | |
Vikram S. Adve | ff5a09e | 2001-11-08 05:04:09 +0000 | [diff] [blame] | 1885 | TmpInstruction* tmpForCC = GetTmpForCC(setCCInstr, |
| 1886 | setCCInstr->getParent()->getParent(), |
Chris Lattner | 9b62503 | 2002-05-06 16:15:30 +0000 | [diff] [blame] | 1887 | isFPCompare ? Type::FloatTy : Type::IntTy); |
Chris Lattner | 9c46108 | 2002-02-03 07:50:56 +0000 | [diff] [blame] | 1888 | MachineCodeForInstruction::get(setCCInstr).addTemp(tmpForCC); |
Vikram S. Adve | ff5a09e | 2001-11-08 05:04:09 +0000 | [diff] [blame] | 1889 | |
| 1890 | if (! isFPCompare) |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1891 | { |
| 1892 | // Integer condition: dest. should be %g0 or an integer register. |
| 1893 | // If result must be saved but condition is not SetEQ then we need |
| 1894 | // a separate instruction to compute the bool result, so discard |
| 1895 | // result of SUBcc instruction anyway. |
| 1896 | // |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1897 | M = new MachineInstr(SUBcc); |
| 1898 | Set3OperandsFromInstr(M, subtreeRoot, target, ! keepSubVal); |
| 1899 | M->SetMachineOperandVal(3, MachineOperand::MO_CCRegister, |
| 1900 | tmpForCC, /*def*/true); |
| 1901 | mvec.push_back(M); |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1902 | |
| 1903 | if (computeBoolVal) |
| 1904 | { // recompute bool using the integer condition codes |
| 1905 | movOpCode = |
| 1906 | ChooseMovpccAfterSub(subtreeRoot,mustClearReg,valueToMove); |
| 1907 | } |
| 1908 | } |
| 1909 | else |
| 1910 | { |
| 1911 | // FP condition: dest of FCMP should be some FCCn register |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1912 | M = new MachineInstr(ChooseFcmpInstruction(subtreeRoot)); |
| 1913 | M->SetMachineOperandVal(0, MachineOperand::MO_CCRegister, |
Vikram S. Adve | ff5a09e | 2001-11-08 05:04:09 +0000 | [diff] [blame] | 1914 | tmpForCC); |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1915 | M->SetMachineOperandVal(1,MachineOperand::MO_VirtualRegister, |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1916 | subtreeRoot->leftChild()->getValue()); |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1917 | M->SetMachineOperandVal(2,MachineOperand::MO_VirtualRegister, |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1918 | subtreeRoot->rightChild()->getValue()); |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1919 | mvec.push_back(M); |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1920 | |
| 1921 | if (computeBoolVal) |
| 1922 | {// recompute bool using the FP condition codes |
| 1923 | mustClearReg = true; |
| 1924 | valueToMove = 1; |
| 1925 | movOpCode = ChooseMovFpccInstruction(subtreeRoot); |
| 1926 | } |
| 1927 | } |
| 1928 | |
| 1929 | if (computeBoolVal) |
| 1930 | { |
| 1931 | if (mustClearReg) |
| 1932 | {// Unconditionally set register to 0 |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1933 | M = new MachineInstr(SETHI); |
| 1934 | M->SetMachineOperandConst(0,MachineOperand::MO_UnextendedImmed, |
| 1935 | (int64_t)0); |
| 1936 | M->SetMachineOperandVal(1, MachineOperand::MO_VirtualRegister, |
| 1937 | setCCInstr); |
| 1938 | mvec.push_back(M); |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1939 | } |
| 1940 | |
| 1941 | // Now conditionally move `valueToMove' (0 or 1) into the register |
Vikram S. Adve | 6418eac | 2002-07-08 23:30:14 +0000 | [diff] [blame] | 1942 | // Mark the register as a use (as well as a def) because the old |
| 1943 | // value should be retained if the condition is false. |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1944 | M = new MachineInstr(movOpCode); |
| 1945 | M->SetMachineOperandVal(0, MachineOperand::MO_CCRegister, |
| 1946 | tmpForCC); |
| 1947 | M->SetMachineOperandConst(1, MachineOperand::MO_UnextendedImmed, |
| 1948 | valueToMove); |
| 1949 | M->SetMachineOperandVal(2, MachineOperand::MO_VirtualRegister, |
Vikram S. Adve | 6418eac | 2002-07-08 23:30:14 +0000 | [diff] [blame] | 1950 | setCCInstr, /*isDef*/ true, |
| 1951 | /*isDefAndUse*/ true); |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1952 | mvec.push_back(M); |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1953 | } |
| 1954 | break; |
| 1955 | } |
| 1956 | |
| 1957 | case 43: // boolreg: VReg |
| 1958 | case 44: // boolreg: Constant |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1959 | break; |
| 1960 | |
| 1961 | case 51: // reg: Load(reg) |
| 1962 | case 52: // reg: Load(ptrreg) |
| 1963 | case 53: // reg: LoadIdx(reg,reg) |
| 1964 | case 54: // reg: LoadIdx(ptrreg,reg) |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1965 | mvec.push_back(new MachineInstr(ChooseLoadInstruction( |
| 1966 | subtreeRoot->getValue()->getType()))); |
| 1967 | SetOperandsForMemInstr(mvec, mvec.end()-1, subtreeRoot, target); |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1968 | break; |
| 1969 | |
| 1970 | case 55: // reg: GetElemPtr(reg) |
| 1971 | case 56: // reg: GetElemPtrIdx(reg,reg) |
Vikram S. Adve | fd3900a | 2002-03-24 03:33:02 +0000 | [diff] [blame] | 1972 | // If the GetElemPtr was folded into the user (parent), it will be |
| 1973 | // caught above. For other cases, we have to compute the address. |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1974 | mvec.push_back(new MachineInstr(ADD)); |
| 1975 | SetOperandsForMemInstr(mvec, mvec.end()-1, subtreeRoot, target); |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1976 | break; |
Vikram S. Adve | fd3900a | 2002-03-24 03:33:02 +0000 | [diff] [blame] | 1977 | |
Vikram S. Adve | b7f06f4 | 2001-11-04 19:34:49 +0000 | [diff] [blame] | 1978 | case 57: // reg: Alloca: Implement as 1 instruction: |
| 1979 | { // add %fp, offsetFromFP -> result |
Vikram S. Adve | fd3900a | 2002-03-24 03:33:02 +0000 | [diff] [blame] | 1980 | AllocationInst* instr = |
| 1981 | cast<AllocationInst>(subtreeRoot->getInstruction()); |
| 1982 | unsigned int tsize = |
| 1983 | target.findOptimalStorageSize(instr->getAllocatedType()); |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1984 | assert(tsize != 0); |
| 1985 | CreateCodeForFixedSizeAlloca(target, instr, tsize, 1, mvec); |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1986 | break; |
Vikram S. Adve | b7f06f4 | 2001-11-04 19:34:49 +0000 | [diff] [blame] | 1987 | } |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1988 | |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1989 | case 58: // reg: Alloca(reg): Implement as 3 instructions: |
| 1990 | // mul num, typeSz -> tmp |
| 1991 | // sub %sp, tmp -> %sp |
Vikram S. Adve | b7f06f4 | 2001-11-04 19:34:49 +0000 | [diff] [blame] | 1992 | { // add %sp, frameSizeBelowDynamicArea -> result |
Vikram S. Adve | fd3900a | 2002-03-24 03:33:02 +0000 | [diff] [blame] | 1993 | AllocationInst* instr = |
| 1994 | cast<AllocationInst>(subtreeRoot->getInstruction()); |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 1995 | const Type* eltType = instr->getAllocatedType(); |
| 1996 | |
Vikram S. Adve | fd3900a | 2002-03-24 03:33:02 +0000 | [diff] [blame] | 1997 | // If #elements is constant, use simpler code for fixed-size allocas |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 1998 | int tsize = (int) target.findOptimalStorageSize(eltType); |
Vikram S. Adve | fd3900a | 2002-03-24 03:33:02 +0000 | [diff] [blame] | 1999 | Value* numElementsVal = NULL; |
| 2000 | bool isArray = instr->isArrayAllocation(); |
| 2001 | |
| 2002 | if (!isArray || |
| 2003 | isa<Constant>(numElementsVal = instr->getArraySize())) |
| 2004 | { // total size is constant: generate code for fixed-size alloca |
| 2005 | unsigned int numElements = isArray? |
| 2006 | cast<ConstantUInt>(numElementsVal)->getValue() : 1; |
| 2007 | CreateCodeForFixedSizeAlloca(target, instr, tsize, |
| 2008 | numElements, mvec); |
| 2009 | } |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 2010 | else // total size is not constant. |
| 2011 | CreateCodeForVariableSizeAlloca(target, instr, tsize, |
Vikram S. Adve | fd3900a | 2002-03-24 03:33:02 +0000 | [diff] [blame] | 2012 | numElementsVal, mvec); |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 2013 | break; |
Vikram S. Adve | b7f06f4 | 2001-11-04 19:34:49 +0000 | [diff] [blame] | 2014 | } |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 2015 | |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 2016 | case 61: // reg: Call |
Vikram S. Adve | dbc4fad | 2002-04-25 04:37:51 +0000 | [diff] [blame] | 2017 | { // Generate a direct (CALL) or indirect (JMPL). depending |
| 2018 | // Mark the return-address register and the indirection |
| 2019 | // register (if any) as hidden virtual registers. |
Vikram S. Adve | a995e60 | 2001-10-11 04:23:19 +0000 | [diff] [blame] | 2020 | // Also, mark the operands of the Call and return value (if |
| 2021 | // any) as implicit operands of the CALL machine instruction. |
Vikram S. Adve | b7f06f4 | 2001-11-04 19:34:49 +0000 | [diff] [blame] | 2022 | // |
Vikram S. Adve | dbc4fad | 2002-04-25 04:37:51 +0000 | [diff] [blame] | 2023 | // If this is a varargs function, floating point arguments |
| 2024 | // have to passed in integer registers so insert |
| 2025 | // copy-float-to-int instructions for each float operand. |
| 2026 | // |
Chris Lattner | b00c582 | 2001-10-02 03:41:24 +0000 | [diff] [blame] | 2027 | CallInst *callInstr = cast<CallInst>(subtreeRoot->getInstruction()); |
Chris Lattner | 749655f | 2001-10-13 06:54:30 +0000 | [diff] [blame] | 2028 | Value *callee = callInstr->getCalledValue(); |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 2029 | |
Vikram S. Adve | a10d1a7 | 2002-03-31 19:07:35 +0000 | [diff] [blame] | 2030 | // Create hidden virtual register for return address, with type void*. |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 2031 | TmpInstruction* retAddrReg = |
Vikram S. Adve | a10d1a7 | 2002-03-31 19:07:35 +0000 | [diff] [blame] | 2032 | new TmpInstruction(PointerType::get(Type::VoidTy), callInstr); |
Chris Lattner | 9c46108 | 2002-02-03 07:50:56 +0000 | [diff] [blame] | 2033 | MachineCodeForInstruction::get(callInstr).addTemp(retAddrReg); |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 2034 | |
Vikram S. Adve | ea21a6c | 2001-10-20 20:57:06 +0000 | [diff] [blame] | 2035 | // Generate the machine instruction and its operands. |
| 2036 | // Use CALL for direct function calls; this optimistically assumes |
| 2037 | // the PC-relative address fits in the CALL address field (22 bits). |
| 2038 | // Use JMPL for indirect calls. |
| 2039 | // |
Chris Lattner | b0d0472 | 2002-03-26 17:58:12 +0000 | [diff] [blame] | 2040 | if (isa<Function>(callee)) |
Vikram S. Adve | ea21a6c | 2001-10-20 20:57:06 +0000 | [diff] [blame] | 2041 | { // direct function call |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 2042 | M = new MachineInstr(CALL); |
| 2043 | M->SetMachineOperandVal(0, MachineOperand::MO_PCRelativeDisp, |
| 2044 | callee); |
Vikram S. Adve | ea21a6c | 2001-10-20 20:57:06 +0000 | [diff] [blame] | 2045 | } |
| 2046 | else |
| 2047 | { // indirect function call |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 2048 | M = new MachineInstr(JMPLCALL); |
| 2049 | M->SetMachineOperandVal(0, MachineOperand::MO_VirtualRegister, |
| 2050 | callee); |
| 2051 | M->SetMachineOperandConst(1, MachineOperand::MO_SignExtendedImmed, |
| 2052 | (int64_t) 0); |
| 2053 | M->SetMachineOperandVal(2, MachineOperand::MO_VirtualRegister, |
| 2054 | retAddrReg); |
Vikram S. Adve | ea21a6c | 2001-10-20 20:57:06 +0000 | [diff] [blame] | 2055 | } |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 2056 | |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 2057 | mvec.push_back(M); |
Vikram S. Adve | a10d1a7 | 2002-03-31 19:07:35 +0000 | [diff] [blame] | 2058 | |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 2059 | const FunctionType* funcType = |
| 2060 | cast<FunctionType>(cast<PointerType>(callee->getType()) |
| 2061 | ->getElementType()); |
| 2062 | bool isVarArgs = funcType->isVarArg(); |
| 2063 | bool noPrototype = isVarArgs && funcType->getNumParams() == 0; |
Vikram S. Adve | dbc4fad | 2002-04-25 04:37:51 +0000 | [diff] [blame] | 2064 | |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 2065 | // Use an annotation to pass information about call arguments |
| 2066 | // to the register allocator. |
| 2067 | CallArgsDescriptor* argDesc = new CallArgsDescriptor(callInstr, |
| 2068 | retAddrReg, isVarArgs, noPrototype); |
| 2069 | M->addAnnotation(argDesc); |
Vikram S. Adve | a995e60 | 2001-10-11 04:23:19 +0000 | [diff] [blame] | 2070 | |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 2071 | assert(callInstr->getOperand(0) == callee |
| 2072 | && "This is assumed in the loop below!"); |
| 2073 | |
| 2074 | for (unsigned i=1, N=callInstr->getNumOperands(); i < N; ++i) |
| 2075 | { |
| 2076 | Value* argVal = callInstr->getOperand(i); |
| 2077 | Instruction* intArgReg = NULL; |
| 2078 | |
| 2079 | // Check for FP arguments to varargs functions. |
| 2080 | // Any such argument in the first $K$ args must be passed in an |
| 2081 | // integer register, where K = #integer argument registers. |
| 2082 | if (isVarArgs && argVal->getType()->isFloatingPoint()) |
| 2083 | { |
| 2084 | // If it is a function with no prototype, pass value |
| 2085 | // as an FP value as well as a varargs value |
| 2086 | if (noPrototype) |
| 2087 | argDesc->getArgInfo(i-1).setUseFPArgReg(); |
| 2088 | |
| 2089 | // If this arg. is in the first $K$ regs, add a copy |
| 2090 | // float-to-int instruction to pass the value as an integer. |
| 2091 | if (i < target.getRegInfo().GetNumOfIntArgRegs()) |
| 2092 | { |
| 2093 | MachineCodeForInstruction &destMCFI = |
| 2094 | MachineCodeForInstruction::get(callInstr); |
| 2095 | intArgReg = new TmpInstruction(Type::IntTy, argVal); |
| 2096 | destMCFI.addTemp(intArgReg); |
| 2097 | |
| 2098 | vector<MachineInstr*> copyMvec; |
| 2099 | target.getInstrInfo().CreateCodeToCopyFloatToInt(target, |
| 2100 | callInstr->getParent()->getParent(), |
| 2101 | argVal, (TmpInstruction*) intArgReg, |
| 2102 | copyMvec, destMCFI); |
| 2103 | mvec.insert(mvec.begin(),copyMvec.begin(),copyMvec.end()); |
| 2104 | |
| 2105 | argDesc->getArgInfo(i-1).setUseIntArgReg(); |
| 2106 | argDesc->getArgInfo(i-1).setArgCopy(intArgReg); |
| 2107 | } |
| 2108 | else |
| 2109 | // Cannot fit in first $K$ regs so pass the arg on the stack |
| 2110 | argDesc->getArgInfo(i-1).setUseStackSlot(); |
| 2111 | } |
| 2112 | |
| 2113 | if (intArgReg) |
| 2114 | mvec.back()->addImplicitRef(intArgReg); |
| 2115 | |
| 2116 | mvec.back()->addImplicitRef(argVal); |
| 2117 | } |
| 2118 | |
| 2119 | // Add the return value as an implicit ref. The call operands |
| 2120 | // were added above. |
Vikram S. Adve | ea21a6c | 2001-10-20 20:57:06 +0000 | [diff] [blame] | 2121 | if (callInstr->getType() != Type::VoidTy) |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 2122 | mvec.back()->addImplicitRef(callInstr, /*isDef*/ true); |
Vikram S. Adve | a995e60 | 2001-10-11 04:23:19 +0000 | [diff] [blame] | 2123 | |
Vikram S. Adve | ea21a6c | 2001-10-20 20:57:06 +0000 | [diff] [blame] | 2124 | // For the CALL instruction, the ret. addr. reg. is also implicit |
Chris Lattner | b0d0472 | 2002-03-26 17:58:12 +0000 | [diff] [blame] | 2125 | if (isa<Function>(callee)) |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 2126 | mvec.back()->addImplicitRef(retAddrReg, /*isDef*/ true); |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 2127 | |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 2128 | // delay slot |
| 2129 | mvec.push_back(new MachineInstr(NOP)); |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 2130 | break; |
Vikram S. Adve | b7f06f4 | 2001-11-04 19:34:49 +0000 | [diff] [blame] | 2131 | } |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 2132 | |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 2133 | case 62: // reg: Shl(reg, reg) |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 2134 | { |
| 2135 | Value* argVal1 = subtreeRoot->leftChild()->getValue(); |
| 2136 | Value* argVal2 = subtreeRoot->rightChild()->getValue(); |
| 2137 | Instruction* shlInstr = subtreeRoot->getInstruction(); |
| 2138 | |
| 2139 | const Type* opType = argVal1->getType(); |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 2140 | assert(opType->isIntegral() |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 2141 | || opType == Type::BoolTy |
| 2142 | || isa<PointerType>(opType)&&"Shl unsupported for other types"); |
| 2143 | |
| 2144 | CreateShiftInstructions(target, shlInstr->getParent()->getParent(), |
| 2145 | (opType == Type::LongTy)? SLLX : SLL, |
| 2146 | argVal1, argVal2, 0, shlInstr, mvec, |
| 2147 | MachineCodeForInstruction::get(shlInstr)); |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 2148 | break; |
Vikram S. Adve | 6ad7c55 | 2001-11-09 02:18:16 +0000 | [diff] [blame] | 2149 | } |
| 2150 | |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 2151 | case 63: // reg: Shr(reg, reg) |
Vikram S. Adve | 6ad7c55 | 2001-11-09 02:18:16 +0000 | [diff] [blame] | 2152 | { const Type* opType = subtreeRoot->leftChild()->getValue()->getType(); |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 2153 | assert(opType->isIntegral() |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 2154 | || isa<PointerType>(opType)&&"Shr unsupported for other types"); |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 2155 | mvec.push_back(new MachineInstr((opType->isSigned() |
| 2156 | ? ((opType == Type::LongTy)? SRAX : SRA) |
| 2157 | : ((opType == Type::LongTy)? SRLX : SRL)))); |
| 2158 | Set3OperandsFromInstr(mvec.back(), subtreeRoot, target); |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 2159 | break; |
Vikram S. Adve | 6ad7c55 | 2001-11-09 02:18:16 +0000 | [diff] [blame] | 2160 | } |
| 2161 | |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 2162 | case 64: // reg: Phi(reg,reg) |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 2163 | break; // don't forward the value |
| 2164 | |
Vikram S. Adve | 3438b21 | 2001-11-12 18:54:11 +0000 | [diff] [blame] | 2165 | #undef NEED_PHI_MACHINE_INSTRS |
| 2166 | #ifdef NEED_PHI_MACHINE_INSTRS |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 2167 | { // This instruction has variable #operands, so resultPos is 0. |
| 2168 | Instruction* phi = subtreeRoot->getInstruction(); |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 2169 | M = new MachineInstr(PHI, 1 + phi->getNumOperands()); |
| 2170 | M->SetMachineOperandVal(0, MachineOperand::MO_VirtualRegister, |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 2171 | subtreeRoot->getValue()); |
| 2172 | for (unsigned i=0, N=phi->getNumOperands(); i < N; i++) |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 2173 | M->SetMachineOperandVal(i+1, MachineOperand::MO_VirtualRegister, |
| 2174 | phi->getOperand(i)); |
| 2175 | mvec.push_back(M); |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 2176 | break; |
| 2177 | } |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 2178 | #endif // NEED_PHI_MACHINE_INSTRS |
Vikram S. Adve | 6ad7c55 | 2001-11-09 02:18:16 +0000 | [diff] [blame] | 2179 | |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 2180 | |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 2181 | case 71: // reg: VReg |
| 2182 | case 72: // reg: Constant |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 2183 | break; // don't forward the value |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 2184 | |
| 2185 | default: |
| 2186 | assert(0 && "Unrecognized BURG rule"); |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 2187 | break; |
| 2188 | } |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 2189 | } |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 2190 | |
| 2191 | if (forwardOperandNum >= 0) |
| 2192 | { // We did not generate a machine instruction but need to use operand. |
| 2193 | // If user is in the same tree, replace Value in its machine operand. |
| 2194 | // If not, insert a copy instruction which should get coalesced away |
| 2195 | // by register allocation. |
| 2196 | if (subtreeRoot->parent() != NULL) |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 2197 | ForwardOperand(subtreeRoot, subtreeRoot->parent(), forwardOperandNum); |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 2198 | else |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 2199 | { |
Vikram S. Adve | 7fe2787 | 2001-10-18 00:26:20 +0000 | [diff] [blame] | 2200 | vector<MachineInstr*> minstrVec; |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 2201 | Instruction* instr = subtreeRoot->getInstruction(); |
| 2202 | target.getInstrInfo(). |
| 2203 | CreateCopyInstructionsByType(target, |
| 2204 | instr->getParent()->getParent(), |
| 2205 | instr->getOperand(forwardOperandNum), |
| 2206 | instr, minstrVec, |
| 2207 | MachineCodeForInstruction::get(instr)); |
Vikram S. Adve | 7fe2787 | 2001-10-18 00:26:20 +0000 | [diff] [blame] | 2208 | assert(minstrVec.size() > 0); |
Vikram S. Adve | 7482532 | 2002-03-18 03:15:35 +0000 | [diff] [blame] | 2209 | mvec.insert(mvec.end(), minstrVec.begin(), minstrVec.end()); |
Vikram S. Adve | 4cecdd2 | 2001-10-01 00:12:53 +0000 | [diff] [blame] | 2210 | } |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 2211 | } |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 2212 | } |