Brian Gaeke | 3ca4fcc | 2004-04-25 07:04:49 +0000 | [diff] [blame] | 1 | //===-- SparcV9InstrInfo.cpp - SparcV9 Instr. Selection Support Methods ---===// |
John Criswell | b576c94 | 2003-10-20 19:43:21 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file was developed by the LLVM research group and is distributed under |
| 6 | // the University of Illinois Open Source License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
Chris Lattner | 035dfbe | 2002-08-09 20:08:06 +0000 | [diff] [blame] | 9 | // |
Brian Gaeke | 3ca4fcc | 2004-04-25 07:04:49 +0000 | [diff] [blame] | 10 | // This file contains various methods of the class SparcV9InstrInfo, many of |
| 11 | // which appear to build canned sequences of MachineInstrs, and are |
| 12 | // used in instruction selection. |
| 13 | // |
Chris Lattner | 035dfbe | 2002-08-09 20:08:06 +0000 | [diff] [blame] | 14 | //===----------------------------------------------------------------------===// |
Vikram S. Adve | 30764b8 | 2001-10-18 00:01:48 +0000 | [diff] [blame] | 15 | |
Misha Brukman | 49ab7f2 | 2003-11-07 17:29:48 +0000 | [diff] [blame] | 16 | #include "llvm/Constants.h" |
| 17 | #include "llvm/DerivedTypes.h" |
| 18 | #include "llvm/Function.h" |
| 19 | #include "llvm/iTerminators.h" |
Vikram S. Adve | 30764b8 | 2001-10-18 00:01:48 +0000 | [diff] [blame] | 20 | #include "llvm/CodeGen/InstrSelection.h" |
Misha Brukman | 49ab7f2 | 2003-11-07 17:29:48 +0000 | [diff] [blame] | 21 | #include "llvm/CodeGen/MachineConstantPool.h" |
Misha Brukman | fce1143 | 2002-10-28 00:28:31 +0000 | [diff] [blame] | 22 | #include "llvm/CodeGen/MachineFunction.h" |
Chris Lattner | 2ef9a6a | 2002-12-28 20:18:21 +0000 | [diff] [blame] | 23 | #include "llvm/CodeGen/MachineFunctionInfo.h" |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 24 | #include "llvm/CodeGen/MachineCodeForInstruction.h" |
Chris Lattner | e5b1ed9 | 2003-01-15 00:03:28 +0000 | [diff] [blame] | 25 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
Brian Gaeke | e3d6807 | 2004-02-25 18:44:15 +0000 | [diff] [blame] | 26 | #include "SparcV9Internals.h" |
| 27 | #include "SparcV9InstrSelectionSupport.h" |
| 28 | #include "SparcV9InstrInfo.h" |
Vikram S. Adve | 30764b8 | 2001-10-18 00:01:48 +0000 | [diff] [blame] | 29 | |
Brian Gaeke | d0fde30 | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 30 | namespace llvm { |
| 31 | |
Vikram S. Adve | 53fd400 | 2002-07-10 21:39:50 +0000 | [diff] [blame] | 32 | static const uint32_t MAXLO = (1 << 10) - 1; // set bits set by %lo(*) |
| 33 | static const uint32_t MAXSIMM = (1 << 12) - 1; // set bits in simm13 field of OR |
| 34 | |
Chris Lattner | 795ba6c | 2003-01-15 21:36:50 +0000 | [diff] [blame] | 35 | //--------------------------------------------------------------------------- |
Vikram S. Adve | e6124d3 | 2003-07-29 19:59:23 +0000 | [diff] [blame] | 36 | // Function ConvertConstantToIntType |
Chris Lattner | 795ba6c | 2003-01-15 21:36:50 +0000 | [diff] [blame] | 37 | // |
Vikram S. Adve | e6124d3 | 2003-07-29 19:59:23 +0000 | [diff] [blame] | 38 | // Function to get the value of an integral constant in the form |
| 39 | // that must be put into the machine register. The specified constant is |
| 40 | // interpreted as (i.e., converted if necessary to) the specified destination |
| 41 | // type. The result is always returned as an uint64_t, since the representation |
| 42 | // of int64_t and uint64_t are identical. The argument can be any known const. |
Chris Lattner | 795ba6c | 2003-01-15 21:36:50 +0000 | [diff] [blame] | 43 | // |
| 44 | // isValidConstant is set to true if a valid constant was found. |
| 45 | //--------------------------------------------------------------------------- |
| 46 | |
Vikram S. Adve | e6124d3 | 2003-07-29 19:59:23 +0000 | [diff] [blame] | 47 | uint64_t |
Brian Gaeke | e3d6807 | 2004-02-25 18:44:15 +0000 | [diff] [blame] | 48 | SparcV9InstrInfo::ConvertConstantToIntType(const TargetMachine &target, |
Vikram S. Adve | e6124d3 | 2003-07-29 19:59:23 +0000 | [diff] [blame] | 49 | const Value *V, |
| 50 | const Type *destType, |
| 51 | bool &isValidConstant) const |
Chris Lattner | 795ba6c | 2003-01-15 21:36:50 +0000 | [diff] [blame] | 52 | { |
Chris Lattner | 795ba6c | 2003-01-15 21:36:50 +0000 | [diff] [blame] | 53 | isValidConstant = false; |
Vikram S. Adve | e6124d3 | 2003-07-29 19:59:23 +0000 | [diff] [blame] | 54 | uint64_t C = 0; |
Chris Lattner | 795ba6c | 2003-01-15 21:36:50 +0000 | [diff] [blame] | 55 | |
Vikram S. Adve | e6124d3 | 2003-07-29 19:59:23 +0000 | [diff] [blame] | 56 | if (! destType->isIntegral() && ! isa<PointerType>(destType)) |
| 57 | return C; |
| 58 | |
| 59 | if (! isa<Constant>(V)) |
| 60 | return C; |
| 61 | |
| 62 | // ConstantPointerRef: no conversions needed: get value and return it |
| 63 | if (const ConstantPointerRef* CPR = dyn_cast<ConstantPointerRef>(V)) { |
| 64 | // A ConstantPointerRef is just a reference to GlobalValue. |
| 65 | isValidConstant = true; // may be overwritten by recursive call |
| 66 | return (CPR->isNullValue()? 0 |
| 67 | : ConvertConstantToIntType(target, CPR->getValue(), destType, |
| 68 | isValidConstant)); |
Chris Lattner | 795ba6c | 2003-01-15 21:36:50 +0000 | [diff] [blame] | 69 | } |
Vikram S. Adve | e6124d3 | 2003-07-29 19:59:23 +0000 | [diff] [blame] | 70 | |
| 71 | // ConstantBool: no conversions needed: get value and return it |
| 72 | if (const ConstantBool *CB = dyn_cast<ConstantBool>(V)) { |
| 73 | isValidConstant = true; |
| 74 | return (uint64_t) CB->getValue(); |
| 75 | } |
| 76 | |
Brian Gaeke | 46bf5af | 2004-06-11 02:03:48 +0000 | [diff] [blame] | 77 | // ConstantPointerNull: it's really just a big, shiny version of zero. |
| 78 | if (const ConstantPointerNull *CPN = dyn_cast<ConstantPointerNull>(V)) { |
| 79 | isValidConstant = true; |
| 80 | return 0; |
| 81 | } |
| 82 | |
Vikram S. Adve | e6124d3 | 2003-07-29 19:59:23 +0000 | [diff] [blame] | 83 | // For other types of constants, some conversion may be needed. |
| 84 | // First, extract the constant operand according to its own type |
| 85 | if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(V)) |
| 86 | switch(CE->getOpcode()) { |
| 87 | case Instruction::Cast: // recursively get the value as cast |
| 88 | C = ConvertConstantToIntType(target, CE->getOperand(0), CE->getType(), |
| 89 | isValidConstant); |
| 90 | break; |
| 91 | default: // not simplifying other ConstantExprs |
| 92 | break; |
| 93 | } |
| 94 | else if (const ConstantInt *CI = dyn_cast<ConstantInt>(V)) { |
| 95 | isValidConstant = true; |
| 96 | C = CI->getRawValue(); |
| 97 | } |
| 98 | else if (const ConstantFP *CFP = dyn_cast<ConstantFP>(V)) { |
| 99 | isValidConstant = true; |
| 100 | double fC = CFP->getValue(); |
| 101 | C = (destType->isSigned()? (uint64_t) (int64_t) fC |
| 102 | : (uint64_t) fC); |
| 103 | } |
| 104 | |
| 105 | // Now if a valid value was found, convert it to destType. |
| 106 | if (isValidConstant) { |
| 107 | unsigned opSize = target.getTargetData().getTypeSize(V->getType()); |
| 108 | unsigned destSize = target.getTargetData().getTypeSize(destType); |
| 109 | uint64_t maskHi = (destSize < 8)? (1U << 8*destSize) - 1 : ~0; |
| 110 | assert(opSize <= 8 && destSize <= 8 && ">8-byte int type unexpected"); |
| 111 | |
| 112 | if (destType->isSigned()) { |
| 113 | if (opSize > destSize) // operand is larger than dest: |
| 114 | C = C & maskHi; // mask high bits |
| 115 | |
| 116 | if (opSize > destSize || |
| 117 | (opSize == destSize && ! V->getType()->isSigned())) |
| 118 | if (C & (1U << (8*destSize - 1))) |
| 119 | C = C | ~maskHi; // sign-extend from destSize to 64 bits |
| 120 | } |
| 121 | else { |
| 122 | if (opSize > destSize || (V->getType()->isSigned() && destSize < 8)) { |
| 123 | // operand is larger than dest, |
| 124 | // OR both are equal but smaller than the full register size |
| 125 | // AND operand is signed, so it may have extra sign bits: |
| 126 | // mask high bits |
| 127 | C = C & maskHi; |
| 128 | } |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | return C; |
Chris Lattner | 795ba6c | 2003-01-15 21:36:50 +0000 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | |
Vikram S. Adve | 6c0c301 | 2002-08-13 18:04:08 +0000 | [diff] [blame] | 136 | //---------------------------------------------------------------------------- |
| 137 | // Function: CreateSETUWConst |
Vikram S. Adve | 53fd400 | 2002-07-10 21:39:50 +0000 | [diff] [blame] | 138 | // |
Vikram S. Adve | 6c0c301 | 2002-08-13 18:04:08 +0000 | [diff] [blame] | 139 | // Set a 32-bit unsigned constant in the register `dest', using |
| 140 | // SETHI, OR in the worst case. This function correctly emulates |
| 141 | // the SETUW pseudo-op for SPARC v9 (if argument isSigned == false). |
| 142 | // |
| 143 | // The isSigned=true case is used to implement SETSW without duplicating code. |
| 144 | // |
| 145 | // Optimize some common cases: |
| 146 | // (1) Small value that fits in simm13 field of OR: don't need SETHI. |
| 147 | // (2) isSigned = true and C is a small negative signed value, i.e., |
| 148 | // high bits are 1, and the remaining bits fit in simm13(OR). |
| 149 | //---------------------------------------------------------------------------- |
| 150 | |
Vikram S. Adve | 53fd400 | 2002-07-10 21:39:50 +0000 | [diff] [blame] | 151 | static inline void |
| 152 | CreateSETUWConst(const TargetMachine& target, uint32_t C, |
Misha Brukman | a98cd45 | 2003-05-20 20:32:24 +0000 | [diff] [blame] | 153 | Instruction* dest, std::vector<MachineInstr*>& mvec, |
Vikram S. Adve | 6c0c301 | 2002-08-13 18:04:08 +0000 | [diff] [blame] | 154 | bool isSigned = false) |
Vikram S. Adve | 53fd400 | 2002-07-10 21:39:50 +0000 | [diff] [blame] | 155 | { |
| 156 | MachineInstr *miSETHI = NULL, *miOR = NULL; |
Vikram S. Adve | 6c0c301 | 2002-08-13 18:04:08 +0000 | [diff] [blame] | 157 | |
Vikram S. Adve | 53fd400 | 2002-07-10 21:39:50 +0000 | [diff] [blame] | 158 | // In order to get efficient code, we should not generate the SETHI if |
| 159 | // all high bits are 1 (i.e., this is a small signed value that fits in |
| 160 | // the simm13 field of OR). So we check for and handle that case specially. |
| 161 | // NOTE: The value C = 0x80000000 is bad: sC < 0 *and* -sC < 0. |
| 162 | // In fact, sC == -sC, so we have to check for this explicitly. |
| 163 | int32_t sC = (int32_t) C; |
Vikram S. Adve | 6c0c301 | 2002-08-13 18:04:08 +0000 | [diff] [blame] | 164 | bool smallNegValue =isSigned && sC < 0 && sC != -sC && -sC < (int32_t)MAXSIMM; |
| 165 | |
Vikram S. Adve | 53fd400 | 2002-07-10 21:39:50 +0000 | [diff] [blame] | 166 | // Set the high 22 bits in dest if non-zero and simm13 field of OR not enough |
Misha Brukman | 81b0686 | 2003-05-21 18:48:06 +0000 | [diff] [blame] | 167 | if (!smallNegValue && (C & ~MAXLO) && C > MAXSIMM) { |
| 168 | miSETHI = BuildMI(V9::SETHI, 2).addZImm(C).addRegDef(dest); |
| 169 | miSETHI->setOperandHi32(0); |
| 170 | mvec.push_back(miSETHI); |
| 171 | } |
Vikram S. Adve | 53fd400 | 2002-07-10 21:39:50 +0000 | [diff] [blame] | 172 | |
| 173 | // Set the low 10 or 12 bits in dest. This is necessary if no SETHI |
| 174 | // was generated, or if the low 10 bits are non-zero. |
Misha Brukman | 81b0686 | 2003-05-21 18:48:06 +0000 | [diff] [blame] | 175 | if (miSETHI==NULL || C & MAXLO) { |
| 176 | if (miSETHI) { |
| 177 | // unsigned value with high-order bits set using SETHI |
Misha Brukman | 71ed1c9 | 2003-05-27 22:35:43 +0000 | [diff] [blame] | 178 | miOR = BuildMI(V9::ORi,3).addReg(dest).addZImm(C).addRegDef(dest); |
Misha Brukman | 81b0686 | 2003-05-21 18:48:06 +0000 | [diff] [blame] | 179 | miOR->setOperandLo32(1); |
| 180 | } else { |
| 181 | // unsigned or small signed value that fits in simm13 field of OR |
| 182 | assert(smallNegValue || (C & ~MAXSIMM) == 0); |
Chris Lattner | d029cd2 | 2004-06-02 05:55:25 +0000 | [diff] [blame] | 183 | miOR = BuildMI(V9::ORi, 3).addMReg(target.getRegInfo()->getZeroRegNum()) |
Misha Brukman | 81b0686 | 2003-05-21 18:48:06 +0000 | [diff] [blame] | 184 | .addSImm(sC).addRegDef(dest); |
Vikram S. Adve | 53fd400 | 2002-07-10 21:39:50 +0000 | [diff] [blame] | 185 | } |
Misha Brukman | 81b0686 | 2003-05-21 18:48:06 +0000 | [diff] [blame] | 186 | mvec.push_back(miOR); |
| 187 | } |
Vikram S. Adve | 53fd400 | 2002-07-10 21:39:50 +0000 | [diff] [blame] | 188 | |
| 189 | assert((miSETHI || miOR) && "Oops, no code was generated!"); |
| 190 | } |
| 191 | |
Vikram S. Adve | 53fd400 | 2002-07-10 21:39:50 +0000 | [diff] [blame] | 192 | |
Vikram S. Adve | 6c0c301 | 2002-08-13 18:04:08 +0000 | [diff] [blame] | 193 | //---------------------------------------------------------------------------- |
| 194 | // Function: CreateSETSWConst |
| 195 | // |
| 196 | // Set a 32-bit signed constant in the register `dest', with sign-extension |
| 197 | // to 64 bits. This uses SETHI, OR, SRA in the worst case. |
| 198 | // This function correctly emulates the SETSW pseudo-op for SPARC v9. |
| 199 | // |
| 200 | // Optimize the same cases as SETUWConst, plus: |
| 201 | // (1) SRA is not needed for positive or small negative values. |
| 202 | //---------------------------------------------------------------------------- |
Vikram S. Adve | 53fd400 | 2002-07-10 21:39:50 +0000 | [diff] [blame] | 203 | |
Vikram S. Adve | 53fd400 | 2002-07-10 21:39:50 +0000 | [diff] [blame] | 204 | static inline void |
| 205 | CreateSETSWConst(const TargetMachine& target, int32_t C, |
Misha Brukman | a98cd45 | 2003-05-20 20:32:24 +0000 | [diff] [blame] | 206 | Instruction* dest, std::vector<MachineInstr*>& mvec) |
Vikram S. Adve | 53fd400 | 2002-07-10 21:39:50 +0000 | [diff] [blame] | 207 | { |
Vikram S. Adve | 53fd400 | 2002-07-10 21:39:50 +0000 | [diff] [blame] | 208 | // Set the low 32 bits of dest |
Vikram S. Adve | 6c0c301 | 2002-08-13 18:04:08 +0000 | [diff] [blame] | 209 | CreateSETUWConst(target, (uint32_t) C, dest, mvec, /*isSigned*/true); |
| 210 | |
Vikram S. Adve | c2f0939 | 2003-05-25 21:58:11 +0000 | [diff] [blame] | 211 | // Sign-extend to the high 32 bits if needed. |
| 212 | // NOTE: The value C = 0x80000000 is bad: -C == C and so -C is < MAXSIMM |
| 213 | if (C < 0 && (C == -C || -C > (int32_t) MAXSIMM)) |
Misha Brukman | d36e30e | 2003-06-06 09:52:23 +0000 | [diff] [blame] | 214 | mvec.push_back(BuildMI(V9::SRAi5,3).addReg(dest).addZImm(0).addRegDef(dest)); |
Vikram S. Adve | 53fd400 | 2002-07-10 21:39:50 +0000 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | |
Vikram S. Adve | 6c0c301 | 2002-08-13 18:04:08 +0000 | [diff] [blame] | 218 | //---------------------------------------------------------------------------- |
| 219 | // Function: CreateSETXConst |
| 220 | // |
Vikram S. Adve | 53fd400 | 2002-07-10 21:39:50 +0000 | [diff] [blame] | 221 | // Set a 64-bit signed or unsigned constant in the register `dest'. |
Vikram S. Adve | 6c0c301 | 2002-08-13 18:04:08 +0000 | [diff] [blame] | 222 | // Use SETUWConst for each 32 bit word, plus a left-shift-by-32 in between. |
| 223 | // This function correctly emulates the SETX pseudo-op for SPARC v9. |
| 224 | // |
| 225 | // Optimize the same cases as SETUWConst for each 32 bit word. |
| 226 | //---------------------------------------------------------------------------- |
| 227 | |
Vikram S. Adve | 53fd400 | 2002-07-10 21:39:50 +0000 | [diff] [blame] | 228 | static inline void |
| 229 | CreateSETXConst(const TargetMachine& target, uint64_t C, |
| 230 | Instruction* tmpReg, Instruction* dest, |
Misha Brukman | a98cd45 | 2003-05-20 20:32:24 +0000 | [diff] [blame] | 231 | std::vector<MachineInstr*>& mvec) |
Vikram S. Adve | 53fd400 | 2002-07-10 21:39:50 +0000 | [diff] [blame] | 232 | { |
| 233 | assert(C > (unsigned int) ~0 && "Use SETUW/SETSW for 32-bit values!"); |
| 234 | |
| 235 | MachineInstr* MI; |
| 236 | |
| 237 | // Code to set the upper 32 bits of the value in register `tmpReg' |
| 238 | CreateSETUWConst(target, (C >> 32), tmpReg, mvec); |
| 239 | |
| 240 | // Shift tmpReg left by 32 bits |
Misha Brukman | 71ed1c9 | 2003-05-27 22:35:43 +0000 | [diff] [blame] | 241 | mvec.push_back(BuildMI(V9::SLLXi6, 3).addReg(tmpReg).addZImm(32) |
Misha Brukman | a98cd45 | 2003-05-20 20:32:24 +0000 | [diff] [blame] | 242 | .addRegDef(tmpReg)); |
Vikram S. Adve | 53fd400 | 2002-07-10 21:39:50 +0000 | [diff] [blame] | 243 | |
| 244 | // Code to set the low 32 bits of the value in register `dest' |
| 245 | CreateSETUWConst(target, C, dest, mvec); |
| 246 | |
| 247 | // dest = OR(tmpReg, dest) |
Misha Brukman | 71ed1c9 | 2003-05-27 22:35:43 +0000 | [diff] [blame] | 248 | mvec.push_back(BuildMI(V9::ORr,3).addReg(dest).addReg(tmpReg).addRegDef(dest)); |
Vikram S. Adve | 53fd400 | 2002-07-10 21:39:50 +0000 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | |
Vikram S. Adve | 6c0c301 | 2002-08-13 18:04:08 +0000 | [diff] [blame] | 252 | //---------------------------------------------------------------------------- |
| 253 | // Function: CreateSETUWLabel |
| 254 | // |
| 255 | // Set a 32-bit constant (given by a symbolic label) in the register `dest'. |
| 256 | //---------------------------------------------------------------------------- |
| 257 | |
| 258 | static inline void |
| 259 | CreateSETUWLabel(const TargetMachine& target, Value* val, |
Misha Brukman | a98cd45 | 2003-05-20 20:32:24 +0000 | [diff] [blame] | 260 | Instruction* dest, std::vector<MachineInstr*>& mvec) |
Vikram S. Adve | 6c0c301 | 2002-08-13 18:04:08 +0000 | [diff] [blame] | 261 | { |
| 262 | MachineInstr* MI; |
| 263 | |
| 264 | // Set the high 22 bits in dest |
Misha Brukman | a98cd45 | 2003-05-20 20:32:24 +0000 | [diff] [blame] | 265 | MI = BuildMI(V9::SETHI, 2).addReg(val).addRegDef(dest); |
Vikram S. Adve | 6c0c301 | 2002-08-13 18:04:08 +0000 | [diff] [blame] | 266 | MI->setOperandHi32(0); |
| 267 | mvec.push_back(MI); |
| 268 | |
| 269 | // Set the low 10 bits in dest |
Misha Brukman | 71ed1c9 | 2003-05-27 22:35:43 +0000 | [diff] [blame] | 270 | MI = BuildMI(V9::ORr, 3).addReg(dest).addReg(val).addRegDef(dest); |
Vikram S. Adve | 6c0c301 | 2002-08-13 18:04:08 +0000 | [diff] [blame] | 271 | MI->setOperandLo32(1); |
| 272 | mvec.push_back(MI); |
| 273 | } |
| 274 | |
| 275 | |
| 276 | //---------------------------------------------------------------------------- |
| 277 | // Function: CreateSETXLabel |
| 278 | // |
Vikram S. Adve | 53fd400 | 2002-07-10 21:39:50 +0000 | [diff] [blame] | 279 | // Set a 64-bit constant (given by a symbolic label) in the register `dest'. |
Vikram S. Adve | 6c0c301 | 2002-08-13 18:04:08 +0000 | [diff] [blame] | 280 | //---------------------------------------------------------------------------- |
| 281 | |
Vikram S. Adve | 53fd400 | 2002-07-10 21:39:50 +0000 | [diff] [blame] | 282 | static inline void |
| 283 | CreateSETXLabel(const TargetMachine& target, |
| 284 | Value* val, Instruction* tmpReg, Instruction* dest, |
Misha Brukman | a98cd45 | 2003-05-20 20:32:24 +0000 | [diff] [blame] | 285 | std::vector<MachineInstr*>& mvec) |
Vikram S. Adve | 53fd400 | 2002-07-10 21:39:50 +0000 | [diff] [blame] | 286 | { |
| 287 | assert(isa<Constant>(val) || isa<GlobalValue>(val) && |
| 288 | "I only know about constant values and global addresses"); |
| 289 | |
| 290 | MachineInstr* MI; |
| 291 | |
Misha Brukman | a98cd45 | 2003-05-20 20:32:24 +0000 | [diff] [blame] | 292 | MI = BuildMI(V9::SETHI, 2).addPCDisp(val).addRegDef(tmpReg); |
Vikram S. Adve | 53fd400 | 2002-07-10 21:39:50 +0000 | [diff] [blame] | 293 | MI->setOperandHi64(0); |
| 294 | mvec.push_back(MI); |
| 295 | |
Misha Brukman | 71ed1c9 | 2003-05-27 22:35:43 +0000 | [diff] [blame] | 296 | MI = BuildMI(V9::ORi, 3).addReg(tmpReg).addPCDisp(val).addRegDef(tmpReg); |
Vikram S. Adve | 53fd400 | 2002-07-10 21:39:50 +0000 | [diff] [blame] | 297 | MI->setOperandLo64(1); |
| 298 | mvec.push_back(MI); |
| 299 | |
Misha Brukman | 71ed1c9 | 2003-05-27 22:35:43 +0000 | [diff] [blame] | 300 | mvec.push_back(BuildMI(V9::SLLXi6, 3).addReg(tmpReg).addZImm(32) |
Misha Brukman | a98cd45 | 2003-05-20 20:32:24 +0000 | [diff] [blame] | 301 | .addRegDef(tmpReg)); |
| 302 | MI = BuildMI(V9::SETHI, 2).addPCDisp(val).addRegDef(dest); |
Vikram S. Adve | 53fd400 | 2002-07-10 21:39:50 +0000 | [diff] [blame] | 303 | MI->setOperandHi32(0); |
| 304 | mvec.push_back(MI); |
| 305 | |
Misha Brukman | 71ed1c9 | 2003-05-27 22:35:43 +0000 | [diff] [blame] | 306 | MI = BuildMI(V9::ORr, 3).addReg(dest).addReg(tmpReg).addRegDef(dest); |
Vikram S. Adve | 53fd400 | 2002-07-10 21:39:50 +0000 | [diff] [blame] | 307 | mvec.push_back(MI); |
| 308 | |
Misha Brukman | 71ed1c9 | 2003-05-27 22:35:43 +0000 | [diff] [blame] | 309 | MI = BuildMI(V9::ORi, 3).addReg(dest).addPCDisp(val).addRegDef(dest); |
Vikram S. Adve | 53fd400 | 2002-07-10 21:39:50 +0000 | [diff] [blame] | 310 | MI->setOperandLo32(1); |
| 311 | mvec.push_back(MI); |
| 312 | } |
| 313 | |
Vikram S. Adve | 30764b8 | 2001-10-18 00:01:48 +0000 | [diff] [blame] | 314 | |
Vikram S. Adve | 6c0c301 | 2002-08-13 18:04:08 +0000 | [diff] [blame] | 315 | //---------------------------------------------------------------------------- |
| 316 | // Function: CreateUIntSetInstruction |
| 317 | // |
| 318 | // Create code to Set an unsigned constant in the register `dest'. |
| 319 | // Uses CreateSETUWConst, CreateSETSWConst or CreateSETXConst as needed. |
| 320 | // CreateSETSWConst is an optimization for the case that the unsigned value |
| 321 | // has all ones in the 33 high bits (so that sign-extension sets them all). |
| 322 | //---------------------------------------------------------------------------- |
Vikram S. Adve | 53fd400 | 2002-07-10 21:39:50 +0000 | [diff] [blame] | 323 | |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 324 | static inline void |
Vikram S. Adve | 53fd400 | 2002-07-10 21:39:50 +0000 | [diff] [blame] | 325 | CreateUIntSetInstruction(const TargetMachine& target, |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 326 | uint64_t C, Instruction* dest, |
Vikram S. Adve | 6c0c301 | 2002-08-13 18:04:08 +0000 | [diff] [blame] | 327 | std::vector<MachineInstr*>& mvec, |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 328 | MachineCodeForInstruction& mcfi) |
Vikram S. Adve | cee9d1c | 2001-12-15 00:33:36 +0000 | [diff] [blame] | 329 | { |
Vikram S. Adve | 6c0c301 | 2002-08-13 18:04:08 +0000 | [diff] [blame] | 330 | static const uint64_t lo32 = (uint32_t) ~0; |
| 331 | if (C <= lo32) // High 32 bits are 0. Set low 32 bits. |
| 332 | CreateSETUWConst(target, (uint32_t) C, dest, mvec); |
Vikram S. Adve | 940a3a4 | 2003-07-10 19:48:19 +0000 | [diff] [blame] | 333 | else if ((C & ~lo32) == ~lo32 && (C & (1U << 31))) { |
Misha Brukman | 81b0686 | 2003-05-21 18:48:06 +0000 | [diff] [blame] | 334 | // All high 33 (not 32) bits are 1s: sign-extension will take care |
| 335 | // of high 32 bits, so use the sequence for signed int |
| 336 | CreateSETSWConst(target, (int32_t) C, dest, mvec); |
| 337 | } else if (C > lo32) { |
| 338 | // C does not fit in 32 bits |
Vikram S. Adve | d0d06ad | 2003-05-31 07:32:01 +0000 | [diff] [blame] | 339 | TmpInstruction* tmpReg = new TmpInstruction(mcfi, Type::IntTy); |
Misha Brukman | 81b0686 | 2003-05-21 18:48:06 +0000 | [diff] [blame] | 340 | CreateSETXConst(target, C, tmpReg, dest, mvec); |
| 341 | } |
Vikram S. Adve | 30764b8 | 2001-10-18 00:01:48 +0000 | [diff] [blame] | 342 | } |
| 343 | |
Vikram S. Adve | 53fd400 | 2002-07-10 21:39:50 +0000 | [diff] [blame] | 344 | |
Vikram S. Adve | 6c0c301 | 2002-08-13 18:04:08 +0000 | [diff] [blame] | 345 | //---------------------------------------------------------------------------- |
| 346 | // Function: CreateIntSetInstruction |
| 347 | // |
| 348 | // Create code to Set a signed constant in the register `dest'. |
| 349 | // Really the same as CreateUIntSetInstruction. |
| 350 | //---------------------------------------------------------------------------- |
| 351 | |
| 352 | static inline void |
| 353 | CreateIntSetInstruction(const TargetMachine& target, |
| 354 | int64_t C, Instruction* dest, |
| 355 | std::vector<MachineInstr*>& mvec, |
| 356 | MachineCodeForInstruction& mcfi) |
| 357 | { |
| 358 | CreateUIntSetInstruction(target, (uint64_t) C, dest, mvec, mcfi); |
| 359 | } |
Chris Lattner | 035dfbe | 2002-08-09 20:08:06 +0000 | [diff] [blame] | 360 | |
Vikram S. Adve | 30764b8 | 2001-10-18 00:01:48 +0000 | [diff] [blame] | 361 | |
| 362 | //--------------------------------------------------------------------------- |
Vikram S. Adve | 4900116 | 2002-09-16 15:56:01 +0000 | [diff] [blame] | 363 | // Create a table of LLVM opcode -> max. immediate constant likely to |
| 364 | // be usable for that operation. |
| 365 | //--------------------------------------------------------------------------- |
| 366 | |
| 367 | // Entry == 0 ==> no immediate constant field exists at all. |
| 368 | // Entry > 0 ==> abs(immediate constant) <= Entry |
| 369 | // |
Misha Brukman | a98cd45 | 2003-05-20 20:32:24 +0000 | [diff] [blame] | 370 | std::vector<int> MaxConstantsTable(Instruction::OtherOpsEnd); |
Vikram S. Adve | 4900116 | 2002-09-16 15:56:01 +0000 | [diff] [blame] | 371 | |
| 372 | static int |
| 373 | MaxConstantForInstr(unsigned llvmOpCode) |
| 374 | { |
| 375 | int modelOpCode = -1; |
| 376 | |
Chris Lattner | 0b16ae2 | 2002-10-13 19:39:16 +0000 | [diff] [blame] | 377 | if (llvmOpCode >= Instruction::BinaryOpsBegin && |
| 378 | llvmOpCode < Instruction::BinaryOpsEnd) |
Misha Brukman | 71ed1c9 | 2003-05-27 22:35:43 +0000 | [diff] [blame] | 379 | modelOpCode = V9::ADDi; |
Vikram S. Adve | 4900116 | 2002-09-16 15:56:01 +0000 | [diff] [blame] | 380 | else |
| 381 | switch(llvmOpCode) { |
Misha Brukman | 71ed1c9 | 2003-05-27 22:35:43 +0000 | [diff] [blame] | 382 | case Instruction::Ret: modelOpCode = V9::JMPLCALLi; break; |
Vikram S. Adve | 4900116 | 2002-09-16 15:56:01 +0000 | [diff] [blame] | 383 | |
| 384 | case Instruction::Malloc: |
| 385 | case Instruction::Alloca: |
| 386 | case Instruction::GetElementPtr: |
Chris Lattner | 3b237fc | 2003-10-19 21:34:28 +0000 | [diff] [blame] | 387 | case Instruction::PHI: |
Vikram S. Adve | 4900116 | 2002-09-16 15:56:01 +0000 | [diff] [blame] | 388 | case Instruction::Cast: |
Misha Brukman | 71ed1c9 | 2003-05-27 22:35:43 +0000 | [diff] [blame] | 389 | case Instruction::Call: modelOpCode = V9::ADDi; break; |
Vikram S. Adve | 4900116 | 2002-09-16 15:56:01 +0000 | [diff] [blame] | 390 | |
| 391 | case Instruction::Shl: |
Misha Brukman | 71ed1c9 | 2003-05-27 22:35:43 +0000 | [diff] [blame] | 392 | case Instruction::Shr: modelOpCode = V9::SLLXi6; break; |
Vikram S. Adve | 4900116 | 2002-09-16 15:56:01 +0000 | [diff] [blame] | 393 | |
| 394 | default: break; |
| 395 | }; |
| 396 | |
Brian Gaeke | e3d6807 | 2004-02-25 18:44:15 +0000 | [diff] [blame] | 397 | return (modelOpCode < 0)? 0: SparcV9MachineInstrDesc[modelOpCode].maxImmedConst; |
Vikram S. Adve | 4900116 | 2002-09-16 15:56:01 +0000 | [diff] [blame] | 398 | } |
| 399 | |
| 400 | static void |
| 401 | InitializeMaxConstantsTable() |
| 402 | { |
| 403 | unsigned op; |
Chris Lattner | 0b16ae2 | 2002-10-13 19:39:16 +0000 | [diff] [blame] | 404 | assert(MaxConstantsTable.size() == Instruction::OtherOpsEnd && |
Vikram S. Adve | 4900116 | 2002-09-16 15:56:01 +0000 | [diff] [blame] | 405 | "assignments below will be illegal!"); |
Chris Lattner | 0b16ae2 | 2002-10-13 19:39:16 +0000 | [diff] [blame] | 406 | for (op = Instruction::TermOpsBegin; op < Instruction::TermOpsEnd; ++op) |
Vikram S. Adve | 4900116 | 2002-09-16 15:56:01 +0000 | [diff] [blame] | 407 | MaxConstantsTable[op] = MaxConstantForInstr(op); |
Chris Lattner | 0b16ae2 | 2002-10-13 19:39:16 +0000 | [diff] [blame] | 408 | for (op = Instruction::BinaryOpsBegin; op < Instruction::BinaryOpsEnd; ++op) |
Vikram S. Adve | 4900116 | 2002-09-16 15:56:01 +0000 | [diff] [blame] | 409 | MaxConstantsTable[op] = MaxConstantForInstr(op); |
Chris Lattner | 0b16ae2 | 2002-10-13 19:39:16 +0000 | [diff] [blame] | 410 | for (op = Instruction::MemoryOpsBegin; op < Instruction::MemoryOpsEnd; ++op) |
Vikram S. Adve | 4900116 | 2002-09-16 15:56:01 +0000 | [diff] [blame] | 411 | MaxConstantsTable[op] = MaxConstantForInstr(op); |
Chris Lattner | 0b16ae2 | 2002-10-13 19:39:16 +0000 | [diff] [blame] | 412 | for (op = Instruction::OtherOpsBegin; op < Instruction::OtherOpsEnd; ++op) |
Vikram S. Adve | 4900116 | 2002-09-16 15:56:01 +0000 | [diff] [blame] | 413 | MaxConstantsTable[op] = MaxConstantForInstr(op); |
| 414 | } |
| 415 | |
| 416 | |
| 417 | //--------------------------------------------------------------------------- |
Brian Gaeke | e3d6807 | 2004-02-25 18:44:15 +0000 | [diff] [blame] | 418 | // class SparcV9InstrInfo |
Vikram S. Adve | 30764b8 | 2001-10-18 00:01:48 +0000 | [diff] [blame] | 419 | // |
| 420 | // Purpose: |
| 421 | // Information about individual instructions. |
Brian Gaeke | e3d6807 | 2004-02-25 18:44:15 +0000 | [diff] [blame] | 422 | // Most information is stored in the SparcV9MachineInstrDesc array above. |
Vikram S. Adve | 30764b8 | 2001-10-18 00:01:48 +0000 | [diff] [blame] | 423 | // Other information is computed on demand, and most such functions |
Chris Lattner | 3501fea | 2003-01-14 22:00:31 +0000 | [diff] [blame] | 424 | // default to member functions in base class TargetInstrInfo. |
Vikram S. Adve | 30764b8 | 2001-10-18 00:01:48 +0000 | [diff] [blame] | 425 | //--------------------------------------------------------------------------- |
| 426 | |
Brian Gaeke | e3d6807 | 2004-02-25 18:44:15 +0000 | [diff] [blame] | 427 | SparcV9InstrInfo::SparcV9InstrInfo() |
Chris Lattner | dce363d | 2004-02-29 06:31:44 +0000 | [diff] [blame] | 428 | : TargetInstrInfo(SparcV9MachineInstrDesc, V9::NUM_TOTAL_OPCODES) { |
Vikram S. Adve | 4900116 | 2002-09-16 15:56:01 +0000 | [diff] [blame] | 429 | InitializeMaxConstantsTable(); |
| 430 | } |
| 431 | |
| 432 | bool |
Brian Gaeke | e3d6807 | 2004-02-25 18:44:15 +0000 | [diff] [blame] | 433 | SparcV9InstrInfo::ConstantMayNotFitInImmedField(const Constant* CV, |
Vikram S. Adve | 4900116 | 2002-09-16 15:56:01 +0000 | [diff] [blame] | 434 | const Instruction* I) const |
| 435 | { |
| 436 | if (I->getOpcode() >= MaxConstantsTable.size()) // user-defined op (or bug!) |
| 437 | return true; |
| 438 | |
| 439 | if (isa<ConstantPointerNull>(CV)) // can always use %g0 |
| 440 | return false; |
| 441 | |
Chris Lattner | ff3d5d9 | 2003-10-21 16:29:23 +0000 | [diff] [blame] | 442 | if (isa<SwitchInst>(I)) // Switch instructions will be lowered! |
| 443 | return false; |
| 444 | |
Chris Lattner | c07736a | 2003-07-23 15:22:26 +0000 | [diff] [blame] | 445 | if (const ConstantInt* CI = dyn_cast<ConstantInt>(CV)) |
| 446 | return labs((int64_t)CI->getRawValue()) > MaxConstantsTable[I->getOpcode()]; |
Vikram S. Adve | 4900116 | 2002-09-16 15:56:01 +0000 | [diff] [blame] | 447 | |
| 448 | if (isa<ConstantBool>(CV)) |
Chris Lattner | c07736a | 2003-07-23 15:22:26 +0000 | [diff] [blame] | 449 | return 1 > MaxConstantsTable[I->getOpcode()]; |
Vikram S. Adve | 4900116 | 2002-09-16 15:56:01 +0000 | [diff] [blame] | 450 | |
| 451 | return true; |
Vikram S. Adve | 30764b8 | 2001-10-18 00:01:48 +0000 | [diff] [blame] | 452 | } |
| 453 | |
Vikram S. Adve | e76af29 | 2002-03-18 03:09:15 +0000 | [diff] [blame] | 454 | // |
Vikram S. Adve | 30764b8 | 2001-10-18 00:01:48 +0000 | [diff] [blame] | 455 | // Create an instruction sequence to put the constant `val' into |
Chris Lattner | e9bb2df | 2001-12-03 22:26:30 +0000 | [diff] [blame] | 456 | // the virtual register `dest'. `val' may be a Constant or a |
Vikram S. Adve | 30764b8 | 2001-10-18 00:01:48 +0000 | [diff] [blame] | 457 | // GlobalValue, viz., the constant address of a global variable or function. |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 458 | // The generated instructions are returned in `mvec'. |
| 459 | // Any temp. registers (TmpInstruction) created are recorded in mcfi. |
Misha Brukman | fce1143 | 2002-10-28 00:28:31 +0000 | [diff] [blame] | 460 | // Any stack space required is allocated via MachineFunction. |
Vikram S. Adve | 30764b8 | 2001-10-18 00:01:48 +0000 | [diff] [blame] | 461 | // |
| 462 | void |
Brian Gaeke | e3d6807 | 2004-02-25 18:44:15 +0000 | [diff] [blame] | 463 | SparcV9InstrInfo::CreateCodeToLoadConst(const TargetMachine& target, |
Misha Brukman | d71295a | 2003-12-17 22:04:00 +0000 | [diff] [blame] | 464 | Function* F, |
| 465 | Value* val, |
| 466 | Instruction* dest, |
| 467 | std::vector<MachineInstr*>& mvec, |
| 468 | MachineCodeForInstruction& mcfi) const |
Vikram S. Adve | 30764b8 | 2001-10-18 00:01:48 +0000 | [diff] [blame] | 469 | { |
Chris Lattner | e9bb2df | 2001-12-03 22:26:30 +0000 | [diff] [blame] | 470 | assert(isa<Constant>(val) || isa<GlobalValue>(val) && |
Vikram S. Adve | 30764b8 | 2001-10-18 00:01:48 +0000 | [diff] [blame] | 471 | "I only know about constant values and global addresses"); |
| 472 | |
Vikram S. Adve | 53fd400 | 2002-07-10 21:39:50 +0000 | [diff] [blame] | 473 | // Use a "set" instruction for known constants or symbolic constants (labels) |
| 474 | // that can go in an integer reg. |
| 475 | // We have to use a "load" instruction for all other constants, |
| 476 | // in particular, floating point constants. |
Vikram S. Adve | 30764b8 | 2001-10-18 00:01:48 +0000 | [diff] [blame] | 477 | // |
| 478 | const Type* valType = val->getType(); |
| 479 | |
Vikram S. Adve | e6124d3 | 2003-07-29 19:59:23 +0000 | [diff] [blame] | 480 | // A ConstantPointerRef is just a reference to GlobalValue. |
| 481 | while (isa<ConstantPointerRef>(val)) |
Vikram S. Adve | 893cace | 2002-10-13 00:04:26 +0000 | [diff] [blame] | 482 | val = cast<ConstantPointerRef>(val)->getValue(); |
| 483 | |
Misha Brukman | 81b0686 | 2003-05-21 18:48:06 +0000 | [diff] [blame] | 484 | if (isa<GlobalValue>(val)) { |
Vikram S. Adve | 6c0c301 | 2002-08-13 18:04:08 +0000 | [diff] [blame] | 485 | TmpInstruction* tmpReg = |
Vikram S. Adve | d0d06ad | 2003-05-31 07:32:01 +0000 | [diff] [blame] | 486 | new TmpInstruction(mcfi, PointerType::get(val->getType()), val); |
Vikram S. Adve | 6c0c301 | 2002-08-13 18:04:08 +0000 | [diff] [blame] | 487 | CreateSETXLabel(target, val, tmpReg, dest, mvec); |
Vikram S. Adve | e6124d3 | 2003-07-29 19:59:23 +0000 | [diff] [blame] | 488 | return; |
| 489 | } |
Vikram S. Adve | 6c0c301 | 2002-08-13 18:04:08 +0000 | [diff] [blame] | 490 | |
Vikram S. Adve | e6124d3 | 2003-07-29 19:59:23 +0000 | [diff] [blame] | 491 | bool isValid; |
| 492 | uint64_t C = ConvertConstantToIntType(target, val, dest->getType(), isValid); |
| 493 | if (isValid) { |
| 494 | if (dest->getType()->isSigned()) |
Misha Brukman | 81b0686 | 2003-05-21 18:48:06 +0000 | [diff] [blame] | 495 | CreateUIntSetInstruction(target, C, dest, mvec, mcfi); |
Vikram S. Adve | e6124d3 | 2003-07-29 19:59:23 +0000 | [diff] [blame] | 496 | else |
| 497 | CreateIntSetInstruction(target, (int64_t) C, dest, mvec, mcfi); |
Vikram S. Adve | 6c0c301 | 2002-08-13 18:04:08 +0000 | [diff] [blame] | 498 | |
Misha Brukman | 81b0686 | 2003-05-21 18:48:06 +0000 | [diff] [blame] | 499 | } else { |
| 500 | // Make an instruction sequence to load the constant, viz: |
| 501 | // SETX <addr-of-constant>, tmpReg, addrReg |
| 502 | // LOAD /*addr*/ addrReg, /*offset*/ 0, dest |
Vikram S. Adve | 30764b8 | 2001-10-18 00:01:48 +0000 | [diff] [blame] | 503 | |
Misha Brukman | 81b0686 | 2003-05-21 18:48:06 +0000 | [diff] [blame] | 504 | // First, create a tmp register to be used by the SETX sequence. |
| 505 | TmpInstruction* tmpReg = |
Misha Brukman | 49ab7f2 | 2003-11-07 17:29:48 +0000 | [diff] [blame] | 506 | new TmpInstruction(mcfi, PointerType::get(val->getType())); |
Vikram S. Adve | a2a7094 | 2001-10-28 21:41:46 +0000 | [diff] [blame] | 507 | |
Misha Brukman | 81b0686 | 2003-05-21 18:48:06 +0000 | [diff] [blame] | 508 | // Create another TmpInstruction for the address register |
| 509 | TmpInstruction* addrReg = |
Misha Brukman | 49ab7f2 | 2003-11-07 17:29:48 +0000 | [diff] [blame] | 510 | new TmpInstruction(mcfi, PointerType::get(val->getType())); |
Vikram S. Adve | e6124d3 | 2003-07-29 19:59:23 +0000 | [diff] [blame] | 511 | |
Misha Brukman | 49ab7f2 | 2003-11-07 17:29:48 +0000 | [diff] [blame] | 512 | // Get the constant pool index for this constant |
| 513 | MachineConstantPool *CP = MachineFunction::get(F).getConstantPool(); |
| 514 | Constant *C = cast<Constant>(val); |
| 515 | unsigned CPI = CP->getConstantPoolIndex(C); |
| 516 | |
| 517 | // Put the address of the constant into a register |
| 518 | MachineInstr* MI; |
| 519 | |
| 520 | MI = BuildMI(V9::SETHI, 2).addConstantPoolIndex(CPI).addRegDef(tmpReg); |
| 521 | MI->setOperandHi64(0); |
| 522 | mvec.push_back(MI); |
| 523 | |
| 524 | MI = BuildMI(V9::ORi, 3).addReg(tmpReg).addConstantPoolIndex(CPI) |
| 525 | .addRegDef(tmpReg); |
| 526 | MI->setOperandLo64(1); |
| 527 | mvec.push_back(MI); |
| 528 | |
| 529 | mvec.push_back(BuildMI(V9::SLLXi6, 3).addReg(tmpReg).addZImm(32) |
| 530 | .addRegDef(tmpReg)); |
| 531 | MI = BuildMI(V9::SETHI, 2).addConstantPoolIndex(CPI).addRegDef(addrReg); |
| 532 | MI->setOperandHi32(0); |
| 533 | mvec.push_back(MI); |
| 534 | |
| 535 | MI = BuildMI(V9::ORr, 3).addReg(addrReg).addReg(tmpReg).addRegDef(addrReg); |
| 536 | mvec.push_back(MI); |
| 537 | |
| 538 | MI = BuildMI(V9::ORi, 3).addReg(addrReg).addConstantPoolIndex(CPI) |
| 539 | .addRegDef(addrReg); |
| 540 | MI->setOperandLo32(1); |
| 541 | mvec.push_back(MI); |
| 542 | |
| 543 | // Now load the constant from out ConstantPool label |
Misha Brukman | 81b0686 | 2003-05-21 18:48:06 +0000 | [diff] [blame] | 544 | unsigned Opcode = ChooseLoadInstruction(val->getType()); |
Misha Brukman | c559e05 | 2003-06-03 03:20:57 +0000 | [diff] [blame] | 545 | Opcode = convertOpcodeFromRegToImm(Opcode); |
Misha Brukman | 49ab7f2 | 2003-11-07 17:29:48 +0000 | [diff] [blame] | 546 | mvec.push_back(BuildMI(Opcode, 3) |
| 547 | .addReg(addrReg).addSImm((int64_t)0).addRegDef(dest)); |
Misha Brukman | 81b0686 | 2003-05-21 18:48:06 +0000 | [diff] [blame] | 548 | } |
Vikram S. Adve | 30764b8 | 2001-10-18 00:01:48 +0000 | [diff] [blame] | 549 | } |
| 550 | |
| 551 | |
Vikram S. Adve | 84c0fcb | 2002-09-05 18:33:59 +0000 | [diff] [blame] | 552 | // Create an instruction sequence to copy an integer register `val' |
| 553 | // to a floating point register `dest' by copying to memory and back. |
Vikram S. Adve | 5b6082e | 2001-11-09 02:16:40 +0000 | [diff] [blame] | 554 | // val must be an integral type. dest must be a Float or Double. |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 555 | // The generated instructions are returned in `mvec'. |
| 556 | // Any temp. registers (TmpInstruction) created are recorded in mcfi. |
Misha Brukman | fce1143 | 2002-10-28 00:28:31 +0000 | [diff] [blame] | 557 | // Any stack space required is allocated via MachineFunction. |
Vikram S. Adve | b9c3863 | 2001-11-08 04:57:53 +0000 | [diff] [blame] | 558 | // |
| 559 | void |
Brian Gaeke | e3d6807 | 2004-02-25 18:44:15 +0000 | [diff] [blame] | 560 | SparcV9InstrInfo::CreateCodeToCopyIntToFloat(const TargetMachine& target, |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 561 | Function* F, |
| 562 | Value* val, |
| 563 | Instruction* dest, |
Misha Brukman | a98cd45 | 2003-05-20 20:32:24 +0000 | [diff] [blame] | 564 | std::vector<MachineInstr*>& mvec, |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 565 | MachineCodeForInstruction& mcfi) const |
Vikram S. Adve | b9c3863 | 2001-11-08 04:57:53 +0000 | [diff] [blame] | 566 | { |
Vikram S. Adve | 84c0fcb | 2002-09-05 18:33:59 +0000 | [diff] [blame] | 567 | assert((val->getType()->isIntegral() || isa<PointerType>(val->getType())) |
| 568 | && "Source type must be integral (integer or bool) or pointer"); |
Chris Lattner | 9b62503 | 2002-05-06 16:15:30 +0000 | [diff] [blame] | 569 | assert(dest->getType()->isFloatingPoint() |
Vikram S. Adve | b9c3863 | 2001-11-08 04:57:53 +0000 | [diff] [blame] | 570 | && "Dest type must be float/double"); |
Vikram S. Adve | 84c0fcb | 2002-09-05 18:33:59 +0000 | [diff] [blame] | 571 | |
| 572 | // Get a stack slot to use for the copy |
Chris Lattner | 2ef9a6a | 2002-12-28 20:18:21 +0000 | [diff] [blame] | 573 | int offset = MachineFunction::get(F).getInfo()->allocateLocalVar(val); |
Vikram S. Adve | 84c0fcb | 2002-09-05 18:33:59 +0000 | [diff] [blame] | 574 | |
| 575 | // Get the size of the source value being copied. |
Chris Lattner | 2ef9a6a | 2002-12-28 20:18:21 +0000 | [diff] [blame] | 576 | size_t srcSize = target.getTargetData().getTypeSize(val->getType()); |
Vikram S. Adve | 84c0fcb | 2002-09-05 18:33:59 +0000 | [diff] [blame] | 577 | |
Vikram S. Adve | b9c3863 | 2001-11-08 04:57:53 +0000 | [diff] [blame] | 578 | // Store instruction stores `val' to [%fp+offset]. |
Vikram S. Adve | 84c0fcb | 2002-09-05 18:33:59 +0000 | [diff] [blame] | 579 | // The store and load opCodes are based on the size of the source value. |
| 580 | // If the value is smaller than 32 bits, we must sign- or zero-extend it |
| 581 | // to 32 bits since the load-float will load 32 bits. |
Vikram S. Adve | c190c01 | 2002-07-31 21:13:31 +0000 | [diff] [blame] | 582 | // Note that the store instruction is the same for signed and unsigned ints. |
Vikram S. Adve | 84c0fcb | 2002-09-05 18:33:59 +0000 | [diff] [blame] | 583 | const Type* storeType = (srcSize <= 4)? Type::IntTy : Type::LongTy; |
| 584 | Value* storeVal = val; |
Misha Brukman | 81b0686 | 2003-05-21 18:48:06 +0000 | [diff] [blame] | 585 | if (srcSize < target.getTargetData().getTypeSize(Type::FloatTy)) { |
| 586 | // sign- or zero-extend respectively |
Vikram S. Adve | d0d06ad | 2003-05-31 07:32:01 +0000 | [diff] [blame] | 587 | storeVal = new TmpInstruction(mcfi, storeType, val); |
Misha Brukman | 81b0686 | 2003-05-21 18:48:06 +0000 | [diff] [blame] | 588 | if (val->getType()->isSigned()) |
| 589 | CreateSignExtensionInstructions(target, F, val, storeVal, 8*srcSize, |
| 590 | mvec, mcfi); |
| 591 | else |
| 592 | CreateZeroExtensionInstructions(target, F, val, storeVal, 8*srcSize, |
| 593 | mvec, mcfi); |
| 594 | } |
Chris Lattner | 54e898e | 2003-01-15 19:23:34 +0000 | [diff] [blame] | 595 | |
Chris Lattner | d029cd2 | 2004-06-02 05:55:25 +0000 | [diff] [blame] | 596 | unsigned FPReg = target.getRegInfo()->getFramePointer(); |
Misha Brukman | c559e05 | 2003-06-03 03:20:57 +0000 | [diff] [blame] | 597 | unsigned StoreOpcode = ChooseStoreInstruction(storeType); |
| 598 | StoreOpcode = convertOpcodeFromRegToImm(StoreOpcode); |
| 599 | mvec.push_back(BuildMI(StoreOpcode, 3) |
Chris Lattner | 54e898e | 2003-01-15 19:23:34 +0000 | [diff] [blame] | 600 | .addReg(storeVal).addMReg(FPReg).addSImm(offset)); |
Vikram S. Adve | 30764b8 | 2001-10-18 00:01:48 +0000 | [diff] [blame] | 601 | |
Vikram S. Adve | b9c3863 | 2001-11-08 04:57:53 +0000 | [diff] [blame] | 602 | // Load instruction loads [%fp+offset] to `dest'. |
Vikram S. Adve | 84c0fcb | 2002-09-05 18:33:59 +0000 | [diff] [blame] | 603 | // The type of the load opCode is the floating point type that matches the |
| 604 | // stored type in size: |
| 605 | // On SparcV9: float for int or smaller, double for long. |
Vikram S. Adve | 5b6082e | 2001-11-09 02:16:40 +0000 | [diff] [blame] | 606 | // |
Vikram S. Adve | 84c0fcb | 2002-09-05 18:33:59 +0000 | [diff] [blame] | 607 | const Type* loadType = (srcSize <= 4)? Type::FloatTy : Type::DoubleTy; |
Misha Brukman | c559e05 | 2003-06-03 03:20:57 +0000 | [diff] [blame] | 608 | unsigned LoadOpcode = ChooseLoadInstruction(loadType); |
| 609 | LoadOpcode = convertOpcodeFromRegToImm(LoadOpcode); |
| 610 | mvec.push_back(BuildMI(LoadOpcode, 3) |
Chris Lattner | 54e898e | 2003-01-15 19:23:34 +0000 | [diff] [blame] | 611 | .addMReg(FPReg).addSImm(offset).addRegDef(dest)); |
Vikram S. Adve | 5b6082e | 2001-11-09 02:16:40 +0000 | [diff] [blame] | 612 | } |
| 613 | |
Vikram S. Adve | 84c0fcb | 2002-09-05 18:33:59 +0000 | [diff] [blame] | 614 | // Similarly, create an instruction sequence to copy an FP register |
| 615 | // `val' to an integer register `dest' by copying to memory and back. |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 616 | // The generated instructions are returned in `mvec'. |
Vikram S. Adve | d0d06ad | 2003-05-31 07:32:01 +0000 | [diff] [blame] | 617 | // Any temp. virtual registers (TmpInstruction) created are recorded in mcfi. |
| 618 | // Temporary stack space required is allocated via MachineFunction. |
Vikram S. Adve | 5b6082e | 2001-11-09 02:16:40 +0000 | [diff] [blame] | 619 | // |
| 620 | void |
Brian Gaeke | e3d6807 | 2004-02-25 18:44:15 +0000 | [diff] [blame] | 621 | SparcV9InstrInfo::CreateCodeToCopyFloatToInt(const TargetMachine& target, |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 622 | Function* F, |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 623 | Value* val, |
| 624 | Instruction* dest, |
Misha Brukman | a98cd45 | 2003-05-20 20:32:24 +0000 | [diff] [blame] | 625 | std::vector<MachineInstr*>& mvec, |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 626 | MachineCodeForInstruction& mcfi) const |
Vikram S. Adve | 5b6082e | 2001-11-09 02:16:40 +0000 | [diff] [blame] | 627 | { |
Vikram S. Adve | c190c01 | 2002-07-31 21:13:31 +0000 | [diff] [blame] | 628 | const Type* opTy = val->getType(); |
| 629 | const Type* destTy = dest->getType(); |
Vikram S. Adve | 84c0fcb | 2002-09-05 18:33:59 +0000 | [diff] [blame] | 630 | |
Vikram S. Adve | c190c01 | 2002-07-31 21:13:31 +0000 | [diff] [blame] | 631 | assert(opTy->isFloatingPoint() && "Source type must be float/double"); |
Vikram S. Adve | 84c0fcb | 2002-09-05 18:33:59 +0000 | [diff] [blame] | 632 | assert((destTy->isIntegral() || isa<PointerType>(destTy)) |
| 633 | && "Dest type must be integer, bool or pointer"); |
Vikram S. Adve | c190c01 | 2002-07-31 21:13:31 +0000 | [diff] [blame] | 634 | |
Vikram S. Adve | d0d06ad | 2003-05-31 07:32:01 +0000 | [diff] [blame] | 635 | // FIXME: For now, we allocate permanent space because the stack frame |
| 636 | // manager does not allow locals to be allocated (e.g., for alloca) after |
| 637 | // a temp is allocated! |
| 638 | // |
Chris Lattner | 2ef9a6a | 2002-12-28 20:18:21 +0000 | [diff] [blame] | 639 | int offset = MachineFunction::get(F).getInfo()->allocateLocalVar(val); |
Vikram S. Adve | 84c0fcb | 2002-09-05 18:33:59 +0000 | [diff] [blame] | 640 | |
Chris Lattner | d029cd2 | 2004-06-02 05:55:25 +0000 | [diff] [blame] | 641 | unsigned FPReg = target.getRegInfo()->getFramePointer(); |
Chris Lattner | 54e898e | 2003-01-15 19:23:34 +0000 | [diff] [blame] | 642 | |
Vikram S. Adve | 5b6082e | 2001-11-09 02:16:40 +0000 | [diff] [blame] | 643 | // Store instruction stores `val' to [%fp+offset]. |
Vikram S. Adve | c190c01 | 2002-07-31 21:13:31 +0000 | [diff] [blame] | 644 | // The store opCode is based only the source value being copied. |
Vikram S. Adve | 5b6082e | 2001-11-09 02:16:40 +0000 | [diff] [blame] | 645 | // |
Misha Brukman | c559e05 | 2003-06-03 03:20:57 +0000 | [diff] [blame] | 646 | unsigned StoreOpcode = ChooseStoreInstruction(opTy); |
| 647 | StoreOpcode = convertOpcodeFromRegToImm(StoreOpcode); |
| 648 | mvec.push_back(BuildMI(StoreOpcode, 3) |
Chris Lattner | 54e898e | 2003-01-15 19:23:34 +0000 | [diff] [blame] | 649 | .addReg(val).addMReg(FPReg).addSImm(offset)); |
Vikram S. Adve | 84c0fcb | 2002-09-05 18:33:59 +0000 | [diff] [blame] | 650 | |
Vikram S. Adve | 5b6082e | 2001-11-09 02:16:40 +0000 | [diff] [blame] | 651 | // Load instruction loads [%fp+offset] to `dest'. |
Vikram S. Adve | c190c01 | 2002-07-31 21:13:31 +0000 | [diff] [blame] | 652 | // The type of the load opCode is the integer type that matches the |
Vikram S. Adve | 84c0fcb | 2002-09-05 18:33:59 +0000 | [diff] [blame] | 653 | // source type in size: |
Vikram S. Adve | c190c01 | 2002-07-31 21:13:31 +0000 | [diff] [blame] | 654 | // On SparcV9: int for float, long for double. |
| 655 | // Note that we *must* use signed loads even for unsigned dest types, to |
Vikram S. Adve | 84c0fcb | 2002-09-05 18:33:59 +0000 | [diff] [blame] | 656 | // ensure correct sign-extension for UByte, UShort or UInt: |
| 657 | // |
| 658 | const Type* loadTy = (opTy == Type::FloatTy)? Type::IntTy : Type::LongTy; |
Misha Brukman | c559e05 | 2003-06-03 03:20:57 +0000 | [diff] [blame] | 659 | unsigned LoadOpcode = ChooseLoadInstruction(loadTy); |
| 660 | LoadOpcode = convertOpcodeFromRegToImm(LoadOpcode); |
| 661 | mvec.push_back(BuildMI(LoadOpcode, 3).addMReg(FPReg) |
Chris Lattner | 54e898e | 2003-01-15 19:23:34 +0000 | [diff] [blame] | 662 | .addSImm(offset).addRegDef(dest)); |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 663 | } |
| 664 | |
| 665 | |
| 666 | // Create instruction(s) to copy src to dest, for arbitrary types |
| 667 | // The generated instructions are returned in `mvec'. |
| 668 | // Any temp. registers (TmpInstruction) created are recorded in mcfi. |
Misha Brukman | fce1143 | 2002-10-28 00:28:31 +0000 | [diff] [blame] | 669 | // Any stack space required is allocated via MachineFunction. |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 670 | // |
| 671 | void |
Brian Gaeke | e3d6807 | 2004-02-25 18:44:15 +0000 | [diff] [blame] | 672 | SparcV9InstrInfo::CreateCopyInstructionsByType(const TargetMachine& target, |
Misha Brukman | d71295a | 2003-12-17 22:04:00 +0000 | [diff] [blame] | 673 | Function *F, |
| 674 | Value* src, |
| 675 | Instruction* dest, |
| 676 | std::vector<MachineInstr*>& mvec, |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 677 | MachineCodeForInstruction& mcfi) const |
| 678 | { |
| 679 | bool loadConstantToReg = false; |
| 680 | |
| 681 | const Type* resultType = dest->getType(); |
| 682 | |
| 683 | MachineOpCode opCode = ChooseAddInstructionByType(resultType); |
Brian Gaeke | f561b08 | 2004-05-30 07:34:01 +0000 | [diff] [blame] | 684 | assert (opCode != V9::INVALID_OPCODE |
| 685 | && "Unsupported result type in CreateCopyInstructionsByType()"); |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 686 | |
| 687 | // if `src' is a constant that doesn't fit in the immed field or if it is |
| 688 | // a global variable (i.e., a constant address), generate a load |
| 689 | // instruction instead of an add |
| 690 | // |
Misha Brukman | 81b0686 | 2003-05-21 18:48:06 +0000 | [diff] [blame] | 691 | if (isa<Constant>(src)) { |
Misha Brukman | a98cd45 | 2003-05-20 20:32:24 +0000 | [diff] [blame] | 692 | unsigned int machineRegNum; |
| 693 | int64_t immedValue; |
| 694 | MachineOperand::MachineOperandType opType = |
| 695 | ChooseRegOrImmed(src, opCode, target, /*canUseImmed*/ true, |
| 696 | machineRegNum, immedValue); |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 697 | |
Misha Brukman | a98cd45 | 2003-05-20 20:32:24 +0000 | [diff] [blame] | 698 | if (opType == MachineOperand::MO_VirtualRegister) |
| 699 | loadConstantToReg = true; |
| 700 | } |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 701 | else if (isa<GlobalValue>(src)) |
| 702 | loadConstantToReg = true; |
| 703 | |
Misha Brukman | 81b0686 | 2003-05-21 18:48:06 +0000 | [diff] [blame] | 704 | if (loadConstantToReg) { |
| 705 | // `src' is constant and cannot fit in immed field for the ADD |
Misha Brukman | a98cd45 | 2003-05-20 20:32:24 +0000 | [diff] [blame] | 706 | // Insert instructions to "load" the constant into a register |
Chris Lattner | d029cd2 | 2004-06-02 05:55:25 +0000 | [diff] [blame] | 707 | target.getInstrInfo()->CreateCodeToLoadConst(target, F, src, dest, |
| 708 | mvec, mcfi); |
Misha Brukman | 81b0686 | 2003-05-21 18:48:06 +0000 | [diff] [blame] | 709 | } else { |
Vikram S. Adve | d0d06ad | 2003-05-31 07:32:01 +0000 | [diff] [blame] | 710 | // Create a reg-to-reg copy instruction for the given type: |
| 711 | // -- For FP values, create a FMOVS or FMOVD instruction |
| 712 | // -- For non-FP values, create an add-with-0 instruction (opCode as above) |
| 713 | // Make `src' the second operand, in case it is a small constant! |
Misha Brukman | a98cd45 | 2003-05-20 20:32:24 +0000 | [diff] [blame] | 714 | // |
Vikram S. Adve | d0d06ad | 2003-05-31 07:32:01 +0000 | [diff] [blame] | 715 | MachineInstr* MI; |
| 716 | if (resultType->isFloatingPoint()) |
| 717 | MI = (BuildMI(resultType == Type::FloatTy? V9::FMOVS : V9::FMOVD, 2) |
| 718 | .addReg(src).addRegDef(dest)); |
| 719 | else { |
| 720 | const Type* Ty =isa<PointerType>(resultType)? Type::ULongTy :resultType; |
| 721 | MI = (BuildMI(opCode, 3) |
| 722 | .addSImm((int64_t) 0).addReg(src).addRegDef(dest)); |
| 723 | } |
Misha Brukman | a98cd45 | 2003-05-20 20:32:24 +0000 | [diff] [blame] | 724 | mvec.push_back(MI); |
| 725 | } |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 726 | } |
| 727 | |
| 728 | |
Vikram S. Adve | 84c0fcb | 2002-09-05 18:33:59 +0000 | [diff] [blame] | 729 | // Helper function for sign-extension and zero-extension. |
| 730 | // For SPARC v9, we sign-extend the given operand using SLL; SRA/SRL. |
| 731 | inline void |
| 732 | CreateBitExtensionInstructions(bool signExtend, |
| 733 | const TargetMachine& target, |
| 734 | Function* F, |
| 735 | Value* srcVal, |
Vikram S. Adve | 5cedede | 2002-09-27 14:29:45 +0000 | [diff] [blame] | 736 | Value* destVal, |
| 737 | unsigned int numLowBits, |
Misha Brukman | a98cd45 | 2003-05-20 20:32:24 +0000 | [diff] [blame] | 738 | std::vector<MachineInstr*>& mvec, |
Vikram S. Adve | 84c0fcb | 2002-09-05 18:33:59 +0000 | [diff] [blame] | 739 | MachineCodeForInstruction& mcfi) |
| 740 | { |
| 741 | MachineInstr* M; |
Vikram S. Adve | 84c0fcb | 2002-09-05 18:33:59 +0000 | [diff] [blame] | 742 | |
Vikram S. Adve | 5cedede | 2002-09-27 14:29:45 +0000 | [diff] [blame] | 743 | assert(numLowBits <= 32 && "Otherwise, nothing should be done here!"); |
| 744 | |
Misha Brukman | 81b0686 | 2003-05-21 18:48:06 +0000 | [diff] [blame] | 745 | if (numLowBits < 32) { |
| 746 | // SLL is needed since operand size is < 32 bits. |
Vikram S. Adve | d0d06ad | 2003-05-31 07:32:01 +0000 | [diff] [blame] | 747 | TmpInstruction *tmpI = new TmpInstruction(mcfi, destVal->getType(), |
Misha Brukman | a98cd45 | 2003-05-20 20:32:24 +0000 | [diff] [blame] | 748 | srcVal, destVal, "make32"); |
Misha Brukman | 71ed1c9 | 2003-05-27 22:35:43 +0000 | [diff] [blame] | 749 | mvec.push_back(BuildMI(V9::SLLXi6, 3).addReg(srcVal) |
Misha Brukman | a98cd45 | 2003-05-20 20:32:24 +0000 | [diff] [blame] | 750 | .addZImm(32-numLowBits).addRegDef(tmpI)); |
| 751 | srcVal = tmpI; |
| 752 | } |
Vikram S. Adve | 84c0fcb | 2002-09-05 18:33:59 +0000 | [diff] [blame] | 753 | |
Misha Brukman | d36e30e | 2003-06-06 09:52:23 +0000 | [diff] [blame] | 754 | mvec.push_back(BuildMI(signExtend? V9::SRAi5 : V9::SRLi5, 3) |
Misha Brukman | a98cd45 | 2003-05-20 20:32:24 +0000 | [diff] [blame] | 755 | .addReg(srcVal).addZImm(32-numLowBits).addRegDef(destVal)); |
Vikram S. Adve | 84c0fcb | 2002-09-05 18:33:59 +0000 | [diff] [blame] | 756 | } |
| 757 | |
| 758 | |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 759 | // Create instruction sequence to produce a sign-extended register value |
Vikram S. Adve | 84c0fcb | 2002-09-05 18:33:59 +0000 | [diff] [blame] | 760 | // from an arbitrary-sized integer value (sized in bits, not bytes). |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 761 | // The generated instructions are returned in `mvec'. |
| 762 | // Any temp. registers (TmpInstruction) created are recorded in mcfi. |
Misha Brukman | fce1143 | 2002-10-28 00:28:31 +0000 | [diff] [blame] | 763 | // Any stack space required is allocated via MachineFunction. |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 764 | // |
| 765 | void |
Brian Gaeke | e3d6807 | 2004-02-25 18:44:15 +0000 | [diff] [blame] | 766 | SparcV9InstrInfo::CreateSignExtensionInstructions( |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 767 | const TargetMachine& target, |
| 768 | Function* F, |
Vikram S. Adve | 84c0fcb | 2002-09-05 18:33:59 +0000 | [diff] [blame] | 769 | Value* srcVal, |
Vikram S. Adve | 5cedede | 2002-09-27 14:29:45 +0000 | [diff] [blame] | 770 | Value* destVal, |
| 771 | unsigned int numLowBits, |
Misha Brukman | a98cd45 | 2003-05-20 20:32:24 +0000 | [diff] [blame] | 772 | std::vector<MachineInstr*>& mvec, |
Vikram S. Adve | 242a808 | 2002-05-19 15:25:51 +0000 | [diff] [blame] | 773 | MachineCodeForInstruction& mcfi) const |
| 774 | { |
Vikram S. Adve | 84c0fcb | 2002-09-05 18:33:59 +0000 | [diff] [blame] | 775 | CreateBitExtensionInstructions(/*signExtend*/ true, target, F, srcVal, |
Vikram S. Adve | 5cedede | 2002-09-27 14:29:45 +0000 | [diff] [blame] | 776 | destVal, numLowBits, mvec, mcfi); |
Vikram S. Adve | 84c0fcb | 2002-09-05 18:33:59 +0000 | [diff] [blame] | 777 | } |
| 778 | |
| 779 | |
| 780 | // Create instruction sequence to produce a zero-extended register value |
| 781 | // from an arbitrary-sized integer value (sized in bits, not bytes). |
| 782 | // For SPARC v9, we sign-extend the given operand using SLL; SRL. |
| 783 | // The generated instructions are returned in `mvec'. |
| 784 | // Any temp. registers (TmpInstruction) created are recorded in mcfi. |
Misha Brukman | fce1143 | 2002-10-28 00:28:31 +0000 | [diff] [blame] | 785 | // Any stack space required is allocated via MachineFunction. |
Vikram S. Adve | 84c0fcb | 2002-09-05 18:33:59 +0000 | [diff] [blame] | 786 | // |
| 787 | void |
Brian Gaeke | e3d6807 | 2004-02-25 18:44:15 +0000 | [diff] [blame] | 788 | SparcV9InstrInfo::CreateZeroExtensionInstructions( |
Vikram S. Adve | 84c0fcb | 2002-09-05 18:33:59 +0000 | [diff] [blame] | 789 | const TargetMachine& target, |
| 790 | Function* F, |
| 791 | Value* srcVal, |
Vikram S. Adve | 5cedede | 2002-09-27 14:29:45 +0000 | [diff] [blame] | 792 | Value* destVal, |
| 793 | unsigned int numLowBits, |
Misha Brukman | a98cd45 | 2003-05-20 20:32:24 +0000 | [diff] [blame] | 794 | std::vector<MachineInstr*>& mvec, |
Vikram S. Adve | 84c0fcb | 2002-09-05 18:33:59 +0000 | [diff] [blame] | 795 | MachineCodeForInstruction& mcfi) const |
| 796 | { |
| 797 | CreateBitExtensionInstructions(/*signExtend*/ false, target, F, srcVal, |
Vikram S. Adve | 5cedede | 2002-09-27 14:29:45 +0000 | [diff] [blame] | 798 | destVal, numLowBits, mvec, mcfi); |
Vikram S. Adve | b9c3863 | 2001-11-08 04:57:53 +0000 | [diff] [blame] | 799 | } |
Brian Gaeke | d0fde30 | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 800 | |
| 801 | } // End llvm namespace |