| Index: src/IceTargetLoweringX8632.cpp
|
| diff --git a/src/IceTargetLoweringX8632.cpp b/src/IceTargetLoweringX8632.cpp
|
| index e9164f624504a741752a2dd22d1150debc44ff7f..046022252c4d930029a47297d43440339fd7db98 100644
|
| --- a/src/IceTargetLoweringX8632.cpp
|
| +++ b/src/IceTargetLoweringX8632.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::X8632::TargetDataX8632::create(Ctx);
|
| + return ::Ice::X8632::TargetDataX86<::Ice::X8632::TargetX8632Traits>::create(
|
| + Ctx);
|
| }
|
|
|
| std::unique_ptr<::Ice::TargetHeaderLowering>
|
| createTargetHeaderLowering(::Ice::GlobalContext *Ctx) {
|
| - return ::Ice::X8632::TargetHeaderX8632::create(Ctx);
|
| + return ::Ice::X8632::TargetHeaderX86::create(Ctx);
|
| }
|
|
|
| void staticInit(::Ice::GlobalContext *Ctx) {
|
| @@ -269,228 +270,6 @@ void TargetX8632::emitSandboxedReturn() {
|
| lowerIndirectJump(T_ecx);
|
| }
|
|
|
| -void TargetX8632::emitJumpTable(const Cfg *Func,
|
| - const InstJumpTable *JumpTable) const {
|
| - if (!BuildDefs::dump())
|
| - return;
|
| - Ostream &Str = Ctx->getStrEmit();
|
| - const bool UseNonsfi = Ctx->getFlags().getUseNonsfi();
|
| - const IceString MangledName = Ctx->mangleName(Func->getFunctionName());
|
| - const IceString Prefix = UseNonsfi ? ".data.rel.ro." : ".rodata.";
|
| - Str << "\t.section\t" << Prefix << MangledName
|
| - << "$jumptable,\"a\",@progbits\n";
|
| - Str << "\t.align\t" << typeWidthInBytes(getPointerType()) << "\n";
|
| - Str << InstJumpTable::makeName(MangledName, JumpTable->getId()) << ":";
|
| -
|
| - // On X8632 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";
|
| -}
|
| -
|
| -TargetDataX8632::TargetDataX8632(GlobalContext *Ctx)
|
| - : TargetDataLowering(Ctx) {}
|
| -
|
| -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 TargetDataX8632::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() && !Pool.empty()) {
|
| - // 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 TargetDataX8632::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 TargetDataX8632::lowerJumpTables() {
|
| - const bool IsPIC = Ctx->getFlags().getUseNonsfi();
|
| - switch (Ctx->getFlags().getOutFileType()) {
|
| - case FT_Elf: {
|
| - ELFObjectWriter *Writer = Ctx->getObjectWriter();
|
| - for (const JumpTableData &JT : Ctx->getJumpTables())
|
| - Writer->writeJumpTable(JT, TargetX8632::Traits::FK_Abs, IsPIC);
|
| - } break;
|
| - case FT_Asm:
|
| - // Already emitted from Cfg
|
| - break;
|
| - case FT_Iasm: {
|
| - if (!BuildDefs::dump())
|
| - return;
|
| - Ostream &Str = Ctx->getStrEmit();
|
| - const IceString Prefix = IsPIC ? ".data.rel.ro." : ".rodata.";
|
| - for (const JumpTableData &JT : Ctx->getJumpTables()) {
|
| - Str << "\t.section\t" << Prefix << JT.getFunctionName()
|
| - << "$jumptable,\"a\",@progbits\n";
|
| - Str << "\t.align\t" << typeWidthInBytes(getPointerType()) << "\n";
|
| - Str << InstJumpTable::makeName(JT.getFunctionName(), JT.getId()) << ":";
|
| -
|
| - // On X8632 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 TargetDataX8632::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, TargetX8632::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;
|
| - }
|
| -}
|
| -
|
| -TargetHeaderX8632::TargetHeaderX8632(GlobalContext *Ctx)
|
| - : TargetHeaderLowering(Ctx) {}
|
| -
|
| // 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
|
|
|