llvm.org GIT mirror llvm / c8d7bc8
Enable emitting of constant values in non-default address space as well. The APIs emitting constants now take an additional parameter signifying the address space in which to emit. The APIs like getData8BitsDirective() etc are made virtual enabling targets to be able to define appropirate directivers for various sizes and address spaces. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@63377 91177308-0d34-0410-b5e6-96231b3b80d8 Sanjiv Gupta 10 years ago
7 changed file(s) with 121 addition(s) and 118 deletion(s). Raw diff Collapse all Expand all
308308 protected:
309309 /// EmitZeros - Emit a block of zeros.
310310 ///
311 void EmitZeros(uint64_t NumZeros) const;
311 void EmitZeros(uint64_t NumZeros, unsigned AddrSpace = 0) const;
312312
313313 /// EmitString - Emit a zero-byte-terminated string constant.
314314 ///
319319 void EmitConstantValueOnly(const Constant *CV);
320320
321321 /// EmitGlobalConstant - Print a general LLVM constant to the .s file.
322 void EmitGlobalConstant(const Constant* CV);
322 void EmitGlobalConstant(const Constant* CV, unsigned AddrSpace = 0);
323323
324324 virtual void EmitMachineConstantPoolValue(MachineConstantPoolValue *MCPV);
325325
350350
351351 /// printDataDirective - This method prints the asm directive for the
352352 /// specified type.
353 void printDataDirective(const Type *type);
353 void printDataDirective(const Type *type, unsigned AddrSpace = 0);
354354
355355 /// printSuffixedName - This prints a name with preceding
356356 /// getPrivateGlobalPrefix and the specified suffix, handling quoted names
370370 const GlobalValue *findGlobalValue(const Constant* CV);
371371 void EmitLLVMUsedList(Constant *List);
372372 void EmitXXStructorList(Constant *List);
373 void EmitGlobalConstantStruct(const ConstantStruct* CVS);
373 void EmitGlobalConstantStruct(const ConstantStruct* CVS,
374 unsigned AddrSpace);
374375 void EmitGlobalConstantArray(const ConstantArray* CVA);
375376 void EmitGlobalConstantVector(const ConstantVector* CP);
376 void EmitGlobalConstantFP(const ConstantFP* CFP);
377 void EmitGlobalConstantLargeInt(const ConstantInt* CI);
377 void EmitGlobalConstantFP(const ConstantFP* CFP, unsigned AddrSpace);
378 void EmitGlobalConstantLargeInt(const ConstantInt* CI, unsigned AddrSpace);
378379 GCMetadataPrinter *GetOrCreateGCPrinter(GCStrategy *C);
379380 };
380381 }
597597
598598 static unsigned getULEB128Size(unsigned Value);
599599
600 // Data directive accessors
601 //
602 virtual const char *getData8bitsDirective(unsigned AddrSpace = 0) const {
603 return Data8bitsDirective;
604 }
605 virtual const char *getData16bitsDirective(unsigned AddrSpace = 0) const {
606 return Data16bitsDirective;
607 }
608 virtual const char *getData32bitsDirective(unsigned AddrSpace = 0) const {
609 return Data32bitsDirective;
610 }
611 virtual const char *getData64bitsDirective(unsigned AddrSpace = 0) const {
612 return Data64bitsDirective;
613 }
614
600615 // Accessors.
601616 //
602617 const Section *getTextSection() const {
710725 const char *getAscizDirective() const {
711726 return AscizDirective;
712727 }
713 const char *getData8bitsDirective() const {
714 return Data8bitsDirective;
715 }
716 const char *getData16bitsDirective() const {
717 return Data16bitsDirective;
718 }
719 const char *getData32bitsDirective() const {
720 return Data32bitsDirective;
721 }
722 const char *getData64bitsDirective() const {
723 return Data64bitsDirective;
724 }
725728 const char *getJumpTableDirective() const {
726729 return JumpTableDirective;
727730 }
769769
770770 /// EmitZeros - Emit a block of zeros.
771771 ///
772 void AsmPrinter::EmitZeros(uint64_t NumZeros) const {
772 void AsmPrinter::EmitZeros(uint64_t NumZeros, unsigned AddrSpace) const {
773773 if (NumZeros) {
774774 if (TAI->getZeroDirective()) {
775775 O << TAI->getZeroDirective() << NumZeros;
778778 O << '\n';
779779 } else {
780780 for (; NumZeros; --NumZeros)
781 O << TAI->getData8bitsDirective() << "0\n";
781 O << TAI->getData8bitsDirective(AddrSpace) << "0\n";
782782 }
783783 }
784784 }
955955 EmitGlobalConstant(CP->getOperand(I));
956956 }
957957
958 void AsmPrinter::EmitGlobalConstantStruct(const ConstantStruct *CVS) {
958 void AsmPrinter::EmitGlobalConstantStruct(const ConstantStruct *CVS,
959 unsigned AddrSpace) {
959960 // Print the fields in successive locations. Pad to align if needed!
960961 const TargetData *TD = TM.getTargetData();
961962 unsigned Size = TD->getTypePaddedSize(CVS->getType());
971972 sizeSoFar += fieldSize + padSize;
972973
973974 // Now print the actual field value.
974 EmitGlobalConstant(field);
975 EmitGlobalConstant(field, AddrSpace);
975976
976977 // Insert padding - this may include padding to increase the size of the
977978 // current field up to the ABI size (if the struct is not packed) as well
978979 // as padding to ensure that the next field starts at the right offset.
979 EmitZeros(padSize);
980 EmitZeros(padSize, AddrSpace);
980981 }
981982 assert(sizeSoFar == cvsLayout->getSizeInBytes() &&
982983 "Layout of constant struct may be incorrect!");
983984 }
984985
985 void AsmPrinter::EmitGlobalConstantFP(const ConstantFP *CFP) {
986 void AsmPrinter::EmitGlobalConstantFP(const ConstantFP *CFP,
987 unsigned AddrSpace) {
986988 // FP Constants are printed as integer constants to avoid losing
987989 // precision...
988990 const TargetData *TD = TM.getTargetData();
989991 if (CFP->getType() == Type::DoubleTy) {
990992 double Val = CFP->getValueAPF().convertToDouble(); // for comment only
991993 uint64_t i = CFP->getValueAPF().bitcastToAPInt().getZExtValue();
992 if (TAI->getData64bitsDirective())
993 O << TAI->getData64bitsDirective() << i << '\t'
994 if (TAI->getData64bitsDirective(AddrSpace))
995 O << TAI->getData64bitsDirective(AddrSpace) << i << '\t'
994996 << TAI->getCommentString() << " double value: " << Val << '\n';
995997 else if (TD->isBigEndian()) {
996 O << TAI->getData32bitsDirective() << unsigned(i >> 32)
998 O << TAI->getData32bitsDirective(AddrSpace) << unsigned(i >> 32)
997999 << '\t' << TAI->getCommentString()
9981000 << " double most significant word " << Val << '\n';
999 O << TAI->getData32bitsDirective() << unsigned(i)
1001 O << TAI->getData32bitsDirective(AddrSpace) << unsigned(i)
10001002 << '\t' << TAI->getCommentString()
10011003 << " double least significant word " << Val << '\n';
10021004 } else {
1003 O << TAI->getData32bitsDirective() << unsigned(i)
1005 O << TAI->getData32bitsDirective(AddrSpace) << unsigned(i)
10041006 << '\t' << TAI->getCommentString()
10051007 << " double least significant word " << Val << '\n';
1006 O << TAI->getData32bitsDirective() << unsigned(i >> 32)
1008 O << TAI->getData32bitsDirective(AddrSpace) << unsigned(i >> 32)
10071009 << '\t' << TAI->getCommentString()
10081010 << " double most significant word " << Val << '\n';
10091011 }
10101012 return;
10111013 } else if (CFP->getType() == Type::FloatTy) {
10121014 float Val = CFP->getValueAPF().convertToFloat(); // for comment only
1013 O << TAI->getData32bitsDirective()
1015 O << TAI->getData32bitsDirective(AddrSpace)
10141016 << CFP->getValueAPF().bitcastToAPInt().getZExtValue()
10151017 << '\t' << TAI->getCommentString() << " float " << Val << '\n';
10161018 return;
10251027 DoubleVal.convert(APFloat::IEEEdouble, APFloat::rmNearestTiesToEven,
10261028 &ignored);
10271029 if (TD->isBigEndian()) {
1028 O << TAI->getData16bitsDirective() << uint16_t(p[0] >> 48)
1030 O << TAI->getData16bitsDirective(AddrSpace) << uint16_t(p[0] >> 48)
10291031 << '\t' << TAI->getCommentString()
10301032 << " long double most significant halfword of ~"
10311033 << DoubleVal.convertToDouble() << '\n';
1032 O << TAI->getData16bitsDirective() << uint16_t(p[0] >> 32)
1034 O << TAI->getData16bitsDirective(AddrSpace) << uint16_t(p[0] >> 32)
10331035 << '\t' << TAI->getCommentString()
10341036 << " long double next halfword\n";
1035 O << TAI->getData16bitsDirective() << uint16_t(p[0] >> 16)
1037 O << TAI->getData16bitsDirective(AddrSpace) << uint16_t(p[0] >> 16)
10361038 << '\t' << TAI->getCommentString()
10371039 << " long double next halfword\n";
1038 O << TAI->getData16bitsDirective() << uint16_t(p[0])
1040 O << TAI->getData16bitsDirective(AddrSpace) << uint16_t(p[0])
10391041 << '\t' << TAI->getCommentString()
10401042 << " long double next halfword\n";
1041 O << TAI->getData16bitsDirective() << uint16_t(p[1])
1043 O << TAI->getData16bitsDirective(AddrSpace) << uint16_t(p[1])
10421044 << '\t' << TAI->getCommentString()
10431045 << " long double least significant halfword\n";
10441046 } else {
1045 O << TAI->getData16bitsDirective() << uint16_t(p[1])
1047 O << TAI->getData16bitsDirective(AddrSpace) << uint16_t(p[1])
10461048 << '\t' << TAI->getCommentString()
10471049 << " long double least significant halfword of ~"
10481050 << DoubleVal.convertToDouble() << '\n';
1049 O << TAI->getData16bitsDirective() << uint16_t(p[0])
1051 O << TAI->getData16bitsDirective(AddrSpace) << uint16_t(p[0])
10501052 << '\t' << TAI->getCommentString()
10511053 << " long double next halfword\n";
1052 O << TAI->getData16bitsDirective() << uint16_t(p[0] >> 16)
1054 O << TAI->getData16bitsDirective(AddrSpace) << uint16_t(p[0] >> 16)
10531055 << '\t' << TAI->getCommentString()
10541056 << " long double next halfword\n";
1055 O << TAI->getData16bitsDirective() << uint16_t(p[0] >> 32)
1057 O << TAI->getData16bitsDirective(AddrSpace) << uint16_t(p[0] >> 32)
10561058 << '\t' << TAI->getCommentString()
10571059 << " long double next halfword\n";
1058 O << TAI->getData16bitsDirective() << uint16_t(p[0] >> 48)
1060 O << TAI->getData16bitsDirective(AddrSpace) << uint16_t(p[0] >> 48)
10591061 << '\t' << TAI->getCommentString()
10601062 << " long double most significant halfword\n";
10611063 }
10621064 EmitZeros(TD->getTypePaddedSize(Type::X86_FP80Ty) -
1063 TD->getTypeStoreSize(Type::X86_FP80Ty));
1065 TD->getTypeStoreSize(Type::X86_FP80Ty), AddrSpace);
10641066 return;
10651067 } else if (CFP->getType() == Type::PPC_FP128Ty) {
10661068 // all long double variants are printed as hex
10681070 APInt api = CFP->getValueAPF().bitcastToAPInt();
10691071 const uint64_t *p = api.getRawData();
10701072 if (TD->isBigEndian()) {
1071 O << TAI->getData32bitsDirective() << uint32_t(p[0] >> 32)
1073 O << TAI->getData32bitsDirective(AddrSpace) << uint32_t(p[0] >> 32)
10721074 << '\t' << TAI->getCommentString()
10731075 << " long double most significant word\n";
1074 O << TAI->getData32bitsDirective() << uint32_t(p[0])
1076 O << TAI->getData32bitsDirective(AddrSpace) << uint32_t(p[0])
10751077 << '\t' << TAI->getCommentString()
10761078 << " long double next word\n";
1077 O << TAI->getData32bitsDirective() << uint32_t(p[1] >> 32)
1079 O << TAI->getData32bitsDirective(AddrSpace) << uint32_t(p[1] >> 32)
10781080 << '\t' << TAI->getCommentString()
10791081 << " long double next word\n";
1080 O << TAI->getData32bitsDirective() << uint32_t(p[1])
1082 O << TAI->getData32bitsDirective(AddrSpace) << uint32_t(p[1])
10811083 << '\t' << TAI->getCommentString()
10821084 << " long double least significant word\n";
10831085 } else {
1084 O << TAI->getData32bitsDirective() << uint32_t(p[1])
1086 O << TAI->getData32bitsDirective(AddrSpace) << uint32_t(p[1])
10851087 << '\t' << TAI->getCommentString()
10861088 << " long double least significant word\n";
1087 O << TAI->getData32bitsDirective() << uint32_t(p[1] >> 32)
1089 O << TAI->getData32bitsDirective(AddrSpace) << uint32_t(p[1] >> 32)
10881090 << '\t' << TAI->getCommentString()
10891091 << " long double next word\n";
1090 O << TAI->getData32bitsDirective() << uint32_t(p[0])
1092 O << TAI->getData32bitsDirective(AddrSpace) << uint32_t(p[0])
10911093 << '\t' << TAI->getCommentString()
10921094 << " long double next word\n";
1093 O << TAI->getData32bitsDirective() << uint32_t(p[0] >> 32)
1095 O << TAI->getData32bitsDirective(AddrSpace) << uint32_t(p[0] >> 32)
10941096 << '\t' << TAI->getCommentString()
10951097 << " long double most significant word\n";
10961098 }
10981100 } else assert(0 && "Floating point constant type not handled");
10991101 }
11001102
1101 void AsmPrinter::EmitGlobalConstantLargeInt(const ConstantInt *CI) {
1103 void AsmPrinter::EmitGlobalConstantLargeInt(const ConstantInt *CI,
1104 unsigned AddrSpace) {
11021105 const TargetData *TD = TM.getTargetData();
11031106 unsigned BitWidth = CI->getBitWidth();
11041107 assert(isPowerOf2_32(BitWidth) &&
11151118 else
11161119 Val = RawData[i];
11171120
1118 if (TAI->getData64bitsDirective())
1119 O << TAI->getData64bitsDirective() << Val << '\n';
1121 if (TAI->getData64bitsDirective(AddrSpace))
1122 O << TAI->getData64bitsDirective(AddrSpace) << Val << '\n';
11201123 else if (TD->isBigEndian()) {
1121 O << TAI->getData32bitsDirective() << unsigned(Val >> 32)
1124 O << TAI->getData32bitsDirective(AddrSpace) << unsigned(Val >> 32)
11221125 << '\t' << TAI->getCommentString()
11231126 << " Double-word most significant word " << Val << '\n';
1124 O << TAI->getData32bitsDirective() << unsigned(Val)
1127 O << TAI->getData32bitsDirective(AddrSpace) << unsigned(Val)
11251128 << '\t' << TAI->getCommentString()
11261129 << " Double-word least significant word " << Val << '\n';
11271130 } else {
1128 O << TAI->getData32bitsDirective() << unsigned(Val)
1131 O << TAI->getData32bitsDirective(AddrSpace) << unsigned(Val)
11291132 << '\t' << TAI->getCommentString()
11301133 << " Double-word least significant word " << Val << '\n';
1131 O << TAI->getData32bitsDirective() << unsigned(Val >> 32)
1134 O << TAI->getData32bitsDirective(AddrSpace) << unsigned(Val >> 32)
11321135 << '\t' << TAI->getCommentString()
11331136 << " Double-word most significant word " << Val << '\n';
11341137 }
11361139 }
11371140
11381141 /// EmitGlobalConstant - Print a general LLVM constant to the .s file.
1139 void AsmPrinter::EmitGlobalConstant(const Constant *CV) {
1142 void AsmPrinter::EmitGlobalConstant(const Constant *CV, unsigned AddrSpace) {
11401143 const TargetData *TD = TM.getTargetData();
11411144 const Type *type = CV->getType();
11421145 unsigned Size = TD->getTypePaddedSize(type);
11431146
11441147 if (CV->isNullValue() || isa(CV)) {
1145 EmitZeros(Size);
1148 EmitZeros(Size, AddrSpace);
11461149 return;
11471150 } else if (const ConstantArray *CVA = dyn_cast(CV)) {
11481151 EmitGlobalConstantArray(CVA);
11491152 return;
11501153 } else if (const ConstantStruct *CVS = dyn_cast(CV)) {
1151 EmitGlobalConstantStruct(CVS);
1154 EmitGlobalConstantStruct(CVS, AddrSpace);
11521155 return;
11531156 } else if (const ConstantFP *CFP = dyn_cast(CV)) {
1154 EmitGlobalConstantFP(CFP);
1157 EmitGlobalConstantFP(CFP, AddrSpace);
11551158 return;
11561159 } else if (const ConstantInt *CI = dyn_cast(CV)) {
11571160 // Small integers are handled below; large integers are handled here.
11581161 if (Size > 4) {
1159 EmitGlobalConstantLargeInt(CI);
1162 EmitGlobalConstantLargeInt(CI, AddrSpace);
11601163 return;
11611164 }
11621165 } else if (const ConstantVector *CP = dyn_cast(CV)) {
11641167 return;
11651168 }
11661169
1167 printDataDirective(type);
1170 printDataDirective(type, AddrSpace);
11681171 EmitConstantValueOnly(CV);
11691172 if (const ConstantInt *CI = dyn_cast(CV)) {
11701173 SmallString<40> S;
14901493
14911494 /// printDataDirective - This method prints the asm directive for the
14921495 /// specified type.
1493 void AsmPrinter::printDataDirective(const Type *type) {
1496 void AsmPrinter::printDataDirective(const Type *type, unsigned AddrSpace) {
14941497 const TargetData *TD = TM.getTargetData();
14951498 switch (type->getTypeID()) {
14961499 case Type::IntegerTyID: {
14971500 unsigned BitWidth = cast(type)->getBitWidth();
14981501 if (BitWidth <= 8)
1499 O << TAI->getData8bitsDirective();
1502 O << TAI->getData8bitsDirective(AddrSpace);
15001503 else if (BitWidth <= 16)
1501 O << TAI->getData16bitsDirective();
1504 O << TAI->getData16bitsDirective(AddrSpace);
15021505 else if (BitWidth <= 32)
1503 O << TAI->getData32bitsDirective();
1506 O << TAI->getData32bitsDirective(AddrSpace);
15041507 else if (BitWidth <= 64) {
1505 assert(TAI->getData64bitsDirective() &&
1508 assert(TAI->getData64bitsDirective(AddrSpace) &&
15061509 "Target cannot handle 64-bit constant exprs!");
1507 O << TAI->getData64bitsDirective();
1510 O << TAI->getData64bitsDirective(AddrSpace);
15081511 } else {
15091512 assert(0 && "Target cannot handle given data directive width!");
15101513 }
15121515 }
15131516 case Type::PointerTyID:
15141517 if (TD->getPointerSize() == 8) {
1515 assert(TAI->getData64bitsDirective() &&
1518 assert(TAI->getData64bitsDirective(AddrSpace) &&
15161519 "Target cannot handle 64-bit pointer exprs!");
1517 O << TAI->getData64bitsDirective();
1520 O << TAI->getData64bitsDirective(AddrSpace);
15181521 } else if (TD->getPointerSize() == 2) {
1519 O << TAI->getData16bitsDirective();
1522 O << TAI->getData16bitsDirective(AddrSpace);
15201523 } else if (TD->getPointerSize() == 1) {
1521 O << TAI->getData8bitsDirective();
1524 O << TAI->getData8bitsDirective(AddrSpace);
15221525 } else {
1523 O << TAI->getData32bitsDirective();
1526 O << TAI->getData32bitsDirective(AddrSpace);
15241527 }
15251528 break;
15261529 case Type::FloatTyID: case Type::DoubleTyID:
241241 continue;
242242
243243 O << name;
244 EmitGlobalConstant(C);
245 }
246 }
247 }
248
249 void PIC16AsmPrinter::EmitConstantValueOnly(const Constant* CV) {
250 if (const ConstantInt *CI = dyn_cast(CV)) {
251 unsigned BitWidth = CI->getBitWidth();
252 int Val = CI->getZExtValue();
253 if (BitWidth == 8) {
254 // Expecting db directive here. In case of romdata we need to pad the
255 // word with zeros.
256 if (IsRomData)
257 O << 0 <<", ";
258 O << Val;
259 }
260 else if (BitWidth == 16) {
261 unsigned Element1, Element2;
262 Element1 = 0x00ff & Val;
263 Element2 = 0x00ff & (Val >> 8);
264 if (IsRomData)
265 O << 0 <<", "<
266 else
267 O << Element1 <<", "<< Element2;
268 }
269 else if (BitWidth == 32) {
270 unsigned Element1, Element2, Element3, Element4;
271 Element1 = 0x00ff & Val;
272 Element2 = 0x00ff & (Val >> 8);
273 Element3 = 0x00ff & (Val >> 16);
274 Element4 = 0x00ff & (Val >> 24);
275 if (IsRomData)
276 O << 0 <<", "<< Element1 <<", "<< 0 <<", "<< Element2 <<", "<< 0
277 <<", "<< Element3 <<", "<< 0 <<", "<< Element4;
278 else
279 O << Element1 <<", "<< Element2 <<", "<< Element3 <<", "<< Element4;
280 }
281 return;
282 }
283 AsmPrinter::EmitConstantValueOnly(CV);
244 EmitGlobalConstant(C, AddrSpace);
245 }
246 }
284247 }
285248
286249 void PIC16AsmPrinter::EmitRomData (Module &M)
307270 continue;
308271
309272 O << name;
310 EmitGlobalConstant(C);
273 EmitGlobalConstant(C, AddrSpace);
311274 O << "\n";
312275 }
313276 }
4242 void EmitInitData (Module &M);
4343 void EmitUnInitData (Module &M);
4444 void EmitRomData (Module &M);
45 virtual void EmitConstantValueOnly(const Constant *CV);
4645 void emitFunctionData(MachineFunction &MF);
4746 void emitFunctionTempData(MachineFunction &MF, unsigned &FrameSize);
4847
2121 : TargetAsmInfo(TM) {
2222 CommentString = ";";
2323 Data8bitsDirective = " db ";
24 Data16bitsDirective = " db ";
25 Data32bitsDirective = " db ";
24 Data16bitsDirective = " dw ";
25 Data32bitsDirective = " dl ";
26 RomData8bitsDirective = " dw ";
27 RomData16bitsDirective = " rom_di ";
28 RomData8bitsDirective = " rom_dl ";
2629 ZeroDirective = NULL;
2730 AsciiDirective = " dt ";
2831 AscizDirective = NULL;
3235 DataSection = getNamedSection("idata.# IDATA", SectionFlags::Writeable);
3336 SwitchToSectionDirective = "";
3437 }
38
39 const char *PIC16TargetAsmInfo::getData8bitsDirective(unsigned AddrSpace)
40 const {
41 if (AddrSpace == PIC16ISD::ROM_SPACE)
42 return RomData8bitsDirective;
43 else
44 return Data8bitsDirective;
45 }
46
47 const char *PIC16TargetAsmInfo::getData16bitsDirective(unsigned AddrSpace)
48 const {
49 if (AddrSpace == PIC16ISD::ROM_SPACE)
50 return RomData16bitsDirective;
51 else
52 return Data16bitsDirective;
53 }
54
55 const char *PIC16TargetAsmInfo::getData32bitsDirective(unsigned AddrSpace)
56 const {
57 if (AddrSpace == PIC16ISD::ROM_SPACE)
58 return RomData32bitsDirective;
59 else
60 return Data32bitsDirective;
61 }
62
2222
2323 struct PIC16TargetAsmInfo : public TargetAsmInfo {
2424 PIC16TargetAsmInfo(const PIC16TargetMachine &TM);
25 const char *RomData8bitsDirective;
26 const char *RomData16bitsDirective;
27 const char *RomData32bitsDirective;
2528 public :
29 virtual const char *getData8bitsDirective(unsigned AddrSpace = 0) const;
30 virtual const char *getData16bitsDirective(unsigned AddrSpace = 0) const;
31 virtual const char *getData32bitsDirective(unsigned AddrSpace = 0) const;
2632 };
2733
2834 } // namespace llvm