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