Mercurial > hg > CbC > CbC_llvm
diff lib/Target/X86/X86LegalizerInfo.cpp @ 148:63bd29f05246
merged
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 14 Aug 2019 19:46:37 +0900 |
parents | c2174574ed3a |
children |
line wrap: on
line diff
--- a/lib/Target/X86/X86LegalizerInfo.cpp Sun Dec 23 19:23:36 2018 +0900 +++ b/lib/Target/X86/X86LegalizerInfo.cpp Wed Aug 14 19:46:37 2019 +0900 @@ -1,9 +1,8 @@ //===- X86LegalizerInfo.cpp --------------------------------------*- C++ -*-==// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// /// \file @@ -14,6 +13,7 @@ #include "X86LegalizerInfo.h" #include "X86Subtarget.h" #include "X86TargetMachine.h" +#include "llvm/CodeGen/GlobalISel/LegalizerHelper.h" #include "llvm/CodeGen/TargetOpcodes.h" #include "llvm/CodeGen/ValueTypes.h" #include "llvm/IR/DerivedTypes.h" @@ -82,11 +82,30 @@ G_CONSTANT, 0, widenToLargerTypesAndNarrowToLargest); computeTables(); + verify(*STI.getInstrInfo()); +} + +bool X86LegalizerInfo::legalizeIntrinsic(MachineInstr &MI, + MachineRegisterInfo &MRI, + MachineIRBuilder &MIRBuilder) const { + switch (MI.getIntrinsicID()) { + case Intrinsic::memcpy: + case Intrinsic::memset: + case Intrinsic::memmove: + if (createMemLibcall(MIRBuilder, MRI, MI) == + LegalizerHelper::UnableToLegalize) + return false; + MI.eraseFromParent(); + return true; + default: + break; + } + return true; } void X86LegalizerInfo::setLegalizerInfo32bit() { - const LLT p0 = LLT::pointer(0, TM.getPointerSize() * 8); + const LLT p0 = LLT::pointer(0, TM.getPointerSizeInBits(0)); const LLT s1 = LLT::scalar(1); const LLT s8 = LLT::scalar(8); const LLT s16 = LLT::scalar(16); @@ -124,6 +143,26 @@ setAction({G_GEP, p0}, Legal); setAction({G_GEP, 1, s32}, Legal); + if (!Subtarget.is64Bit()) { + getActionDefinitionsBuilder(G_PTRTOINT) + .legalForCartesianProduct({s1, s8, s16, s32}, {p0}) + .maxScalar(0, s32) + .widenScalarToNextPow2(0, /*Min*/ 8); + getActionDefinitionsBuilder(G_INTTOPTR).legalFor({{p0, s32}}); + + // Shifts and SDIV + getActionDefinitionsBuilder( + {G_SDIV, G_SREM, G_UDIV, G_UREM}) + .legalFor({s8, s16, s32}) + .clampScalar(0, s8, s32); + + getActionDefinitionsBuilder( + {G_SHL, G_LSHR, G_ASHR}) + .legalFor({{s8, s8}, {s16, s8}, {s32, s8}}) + .clampScalar(0, s8, s32) + .clampScalar(1, s8, s8); + } + // Control-flow setAction({G_BRCOND, s1}, Legal); @@ -138,6 +177,7 @@ setAction({G_ANYEXT, Ty}, Legal); } setAction({G_ANYEXT, s128}, Legal); + getActionDefinitionsBuilder(G_SEXT_INREG).lower(); // Comparison setAction({G_ICMP, s1}, Legal); @@ -161,6 +201,11 @@ if (!Subtarget.is64Bit()) return; + const LLT p0 = LLT::pointer(0, TM.getPointerSizeInBits(0)); + const LLT s1 = LLT::scalar(1); + const LLT s8 = LLT::scalar(8); + const LLT s16 = LLT::scalar(16); + const LLT s32 = LLT::scalar(32); const LLT s64 = LLT::scalar(64); const LLT s128 = LLT::scalar(128); @@ -179,6 +224,11 @@ // Pointer-handling setAction({G_GEP, 1, s64}, Legal); + getActionDefinitionsBuilder(G_PTRTOINT) + .legalForCartesianProduct({s1, s8, s16, s32, s64}, {p0}) + .maxScalar(0, s64) + .widenScalarToNextPow2(0, /*Min*/ 8); + getActionDefinitionsBuilder(G_INTTOPTR).legalFor({{p0, s64}}); // Constants setAction({TargetOpcode::G_CONSTANT, s64}, Legal); @@ -188,9 +238,42 @@ setAction({extOp, s64}, Legal); } + getActionDefinitionsBuilder(G_SITOFP) + .legalForCartesianProduct({s32, s64}) + .clampScalar(1, s32, s64) + .widenScalarToNextPow2(1) + .clampScalar(0, s32, s64) + .widenScalarToNextPow2(0); + + getActionDefinitionsBuilder(G_FPTOSI) + .legalForCartesianProduct({s32, s64}) + .clampScalar(1, s32, s64) + .widenScalarToNextPow2(0) + .clampScalar(0, s32, s64) + .widenScalarToNextPow2(1); + // Comparison setAction({G_ICMP, 1, s64}, Legal); + getActionDefinitionsBuilder(G_FCMP) + .legalForCartesianProduct({s8}, {s32, s64}) + .clampScalar(0, s8, s8) + .clampScalar(1, s32, s64) + .widenScalarToNextPow2(1); + + // Divisions + getActionDefinitionsBuilder( + {G_SDIV, G_SREM, G_UDIV, G_UREM}) + .legalFor({s8, s16, s32, s64}) + .clampScalar(0, s8, s64); + + // Shifts + getActionDefinitionsBuilder( + {G_SHL, G_LSHR, G_ASHR}) + .legalFor({{s8, s8}, {s16, s8}, {s32, s8}, {s64, s8}}) + .clampScalar(0, s8, s64) + .clampScalar(1, s8, s8); + // Merge/Unmerge setAction({G_MERGE_VALUES, s128}, Legal); setAction({G_UNMERGE_VALUES, 1, s128}, Legal); @@ -220,7 +303,7 @@ // Merge/Unmerge for (const auto &Ty : {v4s32, v2s64}) { - setAction({G_MERGE_VALUES, Ty}, Legal); + setAction({G_CONCAT_VECTORS, Ty}, Legal); setAction({G_UNMERGE_VALUES, 1, Ty}, Legal); } setAction({G_MERGE_VALUES, 1, s64}, Legal); @@ -256,17 +339,20 @@ setAction({G_FPEXT, s64}, Legal); setAction({G_FPEXT, 1, s32}, Legal); + setAction({G_FPTRUNC, s32}, Legal); + setAction({G_FPTRUNC, 1, s64}, Legal); + // Constants setAction({TargetOpcode::G_FCONSTANT, s64}, Legal); // Merge/Unmerge for (const auto &Ty : {v16s8, v32s8, v8s16, v16s16, v4s32, v8s32, v2s64, v4s64}) { - setAction({G_MERGE_VALUES, Ty}, Legal); + setAction({G_CONCAT_VECTORS, Ty}, Legal); setAction({G_UNMERGE_VALUES, 1, Ty}, Legal); } for (const auto &Ty : {v16s8, v8s16, v4s32, v2s64}) { - setAction({G_MERGE_VALUES, 1, Ty}, Legal); + setAction({G_CONCAT_VECTORS, 1, Ty}, Legal); setAction({G_UNMERGE_VALUES, Ty}, Legal); } } @@ -313,12 +399,12 @@ // Merge/Unmerge for (const auto &Ty : {v32s8, v64s8, v16s16, v32s16, v8s32, v16s32, v4s64, v8s64}) { - setAction({G_MERGE_VALUES, Ty}, Legal); + setAction({G_CONCAT_VECTORS, Ty}, Legal); setAction({G_UNMERGE_VALUES, 1, Ty}, Legal); } for (const auto &Ty : {v16s8, v32s8, v8s16, v16s16, v4s32, v8s32, v2s64, v4s64}) { - setAction({G_MERGE_VALUES, 1, Ty}, Legal); + setAction({G_CONCAT_VECTORS, 1, Ty}, Legal); setAction({G_UNMERGE_VALUES, Ty}, Legal); } } @@ -346,11 +432,11 @@ // Merge/Unmerge for (const auto &Ty : {v64s8, v32s16, v16s32, v8s64}) { - setAction({G_MERGE_VALUES, Ty}, Legal); + setAction({G_CONCAT_VECTORS, Ty}, Legal); setAction({G_UNMERGE_VALUES, 1, Ty}, Legal); } for (const auto &Ty : {v32s8, v16s16, v8s32, v4s64}) { - setAction({G_MERGE_VALUES, 1, Ty}, Legal); + setAction({G_CONCAT_VECTORS, 1, Ty}, Legal); setAction({G_UNMERGE_VALUES, Ty}, Legal); } }