Index: src/IceTargetLoweringX8664.cpp |
diff --git a/src/IceTargetLoweringX8664.cpp b/src/IceTargetLoweringX8664.cpp |
index c023949476080c5e6c75bad4a001fd1fb4d4886e..49a35adc8e2941ecad82295e6e8404590d61ea6b 100644 |
--- a/src/IceTargetLoweringX8664.cpp |
+++ b/src/IceTargetLoweringX8664.cpp |
@@ -24,12 +24,13 @@ std::unique_ptr<::Ice::TargetLowering> createTargetLowering(::Ice::Cfg *Func) { |
std::unique_ptr<::Ice::TargetDataLowering> |
createTargetDataLowering(::Ice::GlobalContext *Ctx) { |
- return ::Ice::X8664::TargetDataX8664::create(Ctx); |
+ return ::Ice::X8664::TargetDataX86<::Ice::X8664::TargetX8664Traits>::create( |
+ Ctx); |
} |
std::unique_ptr<::Ice::TargetHeaderLowering> |
createTargetHeaderLowering(::Ice::GlobalContext *Ctx) { |
- return ::Ice::X8664::TargetHeaderX8664::create(Ctx); |
+ return ::Ice::X8664::TargetHeaderX86::create(Ctx); |
} |
void staticInit(::Ice::GlobalContext *Ctx) { |
@@ -547,218 +548,6 @@ void TargetX8664::emitSandboxedReturn() { |
} |
} |
-void TargetX8664::emitJumpTable(const Cfg *Func, |
- const InstJumpTable *JumpTable) const { |
- if (!BuildDefs::dump()) |
- return; |
- Ostream &Str = Ctx->getStrEmit(); |
- IceString MangledName = Ctx->mangleName(Func->getFunctionName()); |
- Str << "\t.section\t.rodata." << MangledName |
- << "$jumptable,\"a\",@progbits\n"; |
- Str << "\t.align\t" << typeWidthInBytes(getPointerType()) << "\n"; |
- Str << InstJumpTable::makeName(MangledName, JumpTable->getId()) << ":"; |
- |
- // On X8664 ILP32 pointers are 32-bit hence the use of .long |
- for (SizeT I = 0; I < JumpTable->getNumTargets(); ++I) |
- Str << "\n\t.long\t" << JumpTable->getTarget(I)->getAsmName(); |
- Str << "\n"; |
-} |
- |
-namespace { |
-template <typename T> struct PoolTypeConverter {}; |
- |
-template <> struct PoolTypeConverter<float> { |
- using PrimitiveIntType = uint32_t; |
- using IceType = ConstantFloat; |
- static const Type Ty = IceType_f32; |
- static const char *TypeName; |
- static const char *AsmTag; |
- static const char *PrintfString; |
-}; |
-const char *PoolTypeConverter<float>::TypeName = "float"; |
-const char *PoolTypeConverter<float>::AsmTag = ".long"; |
-const char *PoolTypeConverter<float>::PrintfString = "0x%x"; |
- |
-template <> struct PoolTypeConverter<double> { |
- using PrimitiveIntType = uint64_t; |
- using IceType = ConstantDouble; |
- static const Type Ty = IceType_f64; |
- static const char *TypeName; |
- static const char *AsmTag; |
- static const char *PrintfString; |
-}; |
-const char *PoolTypeConverter<double>::TypeName = "double"; |
-const char *PoolTypeConverter<double>::AsmTag = ".quad"; |
-const char *PoolTypeConverter<double>::PrintfString = "0x%llx"; |
- |
-// Add converter for int type constant pooling |
-template <> struct PoolTypeConverter<uint32_t> { |
- using PrimitiveIntType = uint32_t; |
- using IceType = ConstantInteger32; |
- static const Type Ty = IceType_i32; |
- static const char *TypeName; |
- static const char *AsmTag; |
- static const char *PrintfString; |
-}; |
-const char *PoolTypeConverter<uint32_t>::TypeName = "i32"; |
-const char *PoolTypeConverter<uint32_t>::AsmTag = ".long"; |
-const char *PoolTypeConverter<uint32_t>::PrintfString = "0x%x"; |
- |
-// Add converter for int type constant pooling |
-template <> struct PoolTypeConverter<uint16_t> { |
- using PrimitiveIntType = uint32_t; |
- using IceType = ConstantInteger32; |
- static const Type Ty = IceType_i16; |
- static const char *TypeName; |
- static const char *AsmTag; |
- static const char *PrintfString; |
-}; |
-const char *PoolTypeConverter<uint16_t>::TypeName = "i16"; |
-const char *PoolTypeConverter<uint16_t>::AsmTag = ".short"; |
-const char *PoolTypeConverter<uint16_t>::PrintfString = "0x%x"; |
- |
-// Add converter for int type constant pooling |
-template <> struct PoolTypeConverter<uint8_t> { |
- using PrimitiveIntType = uint32_t; |
- using IceType = ConstantInteger32; |
- static const Type Ty = IceType_i8; |
- static const char *TypeName; |
- static const char *AsmTag; |
- static const char *PrintfString; |
-}; |
-const char *PoolTypeConverter<uint8_t>::TypeName = "i8"; |
-const char *PoolTypeConverter<uint8_t>::AsmTag = ".byte"; |
-const char *PoolTypeConverter<uint8_t>::PrintfString = "0x%x"; |
-} // end of anonymous namespace |
- |
-template <typename T> |
-void TargetDataX8664::emitConstantPool(GlobalContext *Ctx) { |
- if (!BuildDefs::dump()) |
- return; |
- Ostream &Str = Ctx->getStrEmit(); |
- Type Ty = T::Ty; |
- SizeT Align = typeAlignInBytes(Ty); |
- ConstantList Pool = Ctx->getConstantPool(Ty); |
- |
- Str << "\t.section\t.rodata.cst" << Align << ",\"aM\",@progbits," << Align |
- << "\n"; |
- Str << "\t.align\t" << Align << "\n"; |
- |
- // If reorder-pooled-constants option is set to true, we need to shuffle the |
- // constant pool before emitting it. |
- if (Ctx->getFlags().shouldReorderPooledConstants()) { |
- // Use the constant's kind value as the salt for creating random number |
- // generator. |
- Operand::OperandKind K = (*Pool.begin())->getKind(); |
- RandomNumberGenerator RNG(Ctx->getFlags().getRandomSeed(), |
- RPE_PooledConstantReordering, K); |
- RandomShuffle(Pool.begin(), Pool.end(), |
- [&RNG](uint64_t N) { return (uint32_t)RNG.next(N); }); |
- } |
- |
- for (Constant *C : Pool) { |
- if (!C->getShouldBePooled()) |
- continue; |
- auto *Const = llvm::cast<typename T::IceType>(C); |
- typename T::IceType::PrimType Value = Const->getValue(); |
- // Use memcpy() to copy bits from Value into RawValue in a way that avoids |
- // breaking strict-aliasing rules. |
- typename T::PrimitiveIntType RawValue; |
- memcpy(&RawValue, &Value, sizeof(Value)); |
- char buf[30]; |
- int CharsPrinted = |
- snprintf(buf, llvm::array_lengthof(buf), T::PrintfString, RawValue); |
- assert(CharsPrinted >= 0 && |
- (size_t)CharsPrinted < llvm::array_lengthof(buf)); |
- (void)CharsPrinted; // avoid warnings if asserts are disabled |
- Const->emitPoolLabel(Str, Ctx); |
- Str << ":\n\t" << T::AsmTag << "\t" << buf << "\t/* " << T::TypeName << " " |
- << Value << " */\n"; |
- } |
-} |
- |
-void TargetDataX8664::lowerConstants() { |
- if (Ctx->getFlags().getDisableTranslation()) |
- return; |
- // No need to emit constants from the int pool since (for x86) they are |
- // embedded as immediates in the instructions, just emit float/double. |
- switch (Ctx->getFlags().getOutFileType()) { |
- case FT_Elf: { |
- ELFObjectWriter *Writer = Ctx->getObjectWriter(); |
- |
- Writer->writeConstantPool<ConstantInteger32>(IceType_i8); |
- Writer->writeConstantPool<ConstantInteger32>(IceType_i16); |
- Writer->writeConstantPool<ConstantInteger32>(IceType_i32); |
- |
- Writer->writeConstantPool<ConstantFloat>(IceType_f32); |
- Writer->writeConstantPool<ConstantDouble>(IceType_f64); |
- } break; |
- case FT_Asm: |
- case FT_Iasm: { |
- OstreamLocker L(Ctx); |
- |
- emitConstantPool<PoolTypeConverter<uint8_t>>(Ctx); |
- emitConstantPool<PoolTypeConverter<uint16_t>>(Ctx); |
- emitConstantPool<PoolTypeConverter<uint32_t>>(Ctx); |
- |
- emitConstantPool<PoolTypeConverter<float>>(Ctx); |
- emitConstantPool<PoolTypeConverter<double>>(Ctx); |
- } break; |
- } |
-} |
- |
-void TargetDataX8664::lowerJumpTables() { |
- const bool IsPIC = Ctx->getFlags().getUseNonsfi(); |
- switch (Ctx->getFlags().getOutFileType()) { |
- case FT_Elf: { |
- ELFObjectWriter *Writer = Ctx->getObjectWriter(); |
- for (const JumpTableData &JumpTable : Ctx->getJumpTables()) |
- Writer->writeJumpTable(JumpTable, TargetX8664::Traits::FK_Abs, IsPIC); |
- } break; |
- case FT_Asm: |
- // Already emitted from Cfg |
- break; |
- case FT_Iasm: { |
- if (!BuildDefs::dump()) |
- return; |
- Ostream &Str = Ctx->getStrEmit(); |
- for (const JumpTableData &JT : Ctx->getJumpTables()) { |
- Str << "\t.section\t.rodata." << JT.getFunctionName() |
- << "$jumptable,\"a\",@progbits\n"; |
- Str << "\t.align\t" << typeWidthInBytes(getPointerType()) << "\n"; |
- Str << InstJumpTable::makeName(JT.getFunctionName(), JT.getId()) << ":"; |
- |
- // On X8664 ILP32 pointers are 32-bit hence the use of .long |
- for (intptr_t TargetOffset : JT.getTargetOffsets()) |
- Str << "\n\t.long\t" << JT.getFunctionName() << "+" << TargetOffset; |
- Str << "\n"; |
- } |
- } break; |
- } |
-} |
- |
-void TargetDataX8664::lowerGlobals(const VariableDeclarationList &Vars, |
- const IceString &SectionSuffix) { |
- const bool IsPIC = Ctx->getFlags().getUseNonsfi(); |
- switch (Ctx->getFlags().getOutFileType()) { |
- case FT_Elf: { |
- ELFObjectWriter *Writer = Ctx->getObjectWriter(); |
- Writer->writeDataSection(Vars, TargetX8664::Traits::FK_Abs, SectionSuffix, |
- IsPIC); |
- } break; |
- case FT_Asm: |
- case FT_Iasm: { |
- const IceString &TranslateOnly = Ctx->getFlags().getTranslateOnly(); |
- OstreamLocker L(Ctx); |
- for (const VariableDeclaration *Var : Vars) { |
- if (GlobalContext::matchSymbolName(Var->getName(), TranslateOnly)) { |
- emitGlobal(*Var, SectionSuffix); |
- } |
- } |
- } break; |
- } |
-} |
- |
// In some cases, there are x-macros tables for both high-level and low-level |
// instructions/operands that use the same enum key value. The tables are kept |
// separate to maintain a proper separation between abstraction layers. There |