Path: blob/main/contrib/llvm-project/llvm/lib/Target/PowerPC/GISel/PPCLegalizerInfo.cpp
35294 views
//===- PPCLegalizerInfo.h ----------------------------------------*- C++ -*-==//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7/// \file8/// This file implements the targeting of the Machinelegalizer class for PowerPC9//===----------------------------------------------------------------------===//1011#include "PPCLegalizerInfo.h"12#include "llvm/CodeGen/GlobalISel/LegalizerHelper.h"13#include "llvm/Support/Debug.h"1415#define DEBUG_TYPE "ppc-legalinfo"1617using namespace llvm;18using namespace LegalizeActions;19using namespace LegalizeMutations;20using namespace LegalityPredicates;2122static LegalityPredicate isRegisterType(unsigned TypeIdx) {23return [=](const LegalityQuery &Query) {24const LLT QueryTy = Query.Types[TypeIdx];25unsigned TypeSize = QueryTy.getSizeInBits();2627if (TypeSize % 32 == 1 || TypeSize > 128)28return false;2930// Check if this is a legal PowerPC vector type.31if (QueryTy.isVector()) {32const int EltSize = QueryTy.getElementType().getSizeInBits();33return (EltSize == 8 || EltSize == 16 || EltSize == 32 || EltSize == 64);34}3536return true;37};38}3940PPCLegalizerInfo::PPCLegalizerInfo(const PPCSubtarget &ST) {41using namespace TargetOpcode;42const LLT P0 = LLT::pointer(0, 64);43const LLT S1 = LLT::scalar(1);44const LLT S8 = LLT::scalar(8);45const LLT S16 = LLT::scalar(16);46const LLT S32 = LLT::scalar(32);47const LLT S64 = LLT::scalar(64);48const LLT V16S8 = LLT::fixed_vector(16, 8);49const LLT V8S16 = LLT::fixed_vector(8, 16);50const LLT V4S32 = LLT::fixed_vector(4, 32);51const LLT V2S64 = LLT::fixed_vector(2, 64);52getActionDefinitionsBuilder(G_IMPLICIT_DEF).legalFor({S64});53getActionDefinitionsBuilder(G_CONSTANT)54.legalFor({S32, S64})55.clampScalar(0, S64, S64);56getActionDefinitionsBuilder({G_ZEXT, G_SEXT, G_ANYEXT})57.legalForCartesianProduct({S64}, {S1, S8, S16, S32})58.clampScalar(0, S64, S64);59getActionDefinitionsBuilder({G_AND, G_OR, G_XOR})60.legalFor({S64, V4S32})61.clampScalar(0, S64, S64)62.bitcastIf(typeIsNot(0, V4S32), changeTo(0, V4S32));63getActionDefinitionsBuilder({G_ADD, G_SUB})64.legalFor({S64, V16S8, V8S16, V4S32, V2S64})65.clampScalar(0, S64, S64);66getActionDefinitionsBuilder(G_BITCAST)67.legalIf(all(isRegisterType(0), isRegisterType(1)))68.lower();6970getActionDefinitionsBuilder({G_FADD, G_FSUB, G_FMUL, G_FDIV})71.legalFor({S32, S64, V4S32, V2S64});7273getActionDefinitionsBuilder(G_FCMP).legalForCartesianProduct({S1},74{S32, S64});7576getActionDefinitionsBuilder({G_FPTOSI, G_FPTOUI})77.legalForCartesianProduct({S64}, {S32, S64});7879getActionDefinitionsBuilder({G_SITOFP, G_UITOFP})80.legalForCartesianProduct({S32, S64}, {S64});8182getActionDefinitionsBuilder({G_LOAD, G_STORE})83.legalForTypesWithMemDesc({{S64, P0, S64, 8}, {S32, P0, S32, 4}});8485getActionDefinitionsBuilder(G_FCONSTANT).lowerFor({S32, S64});86getActionDefinitionsBuilder(G_CONSTANT_POOL).legalFor({P0});8788getLegacyLegalizerInfo().computeTables();89}909192