TargetLoweringBase.cpp revision 6948897e478cbd66626159776a8017b3c18579b9
169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer//===-- TargetLoweringBase.cpp - Implement the TargetLoweringBase class ---===//
269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer//
369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer//                     The LLVM Compiler Infrastructure
469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer//
569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer// This file is distributed under the University of Illinois Open Source
669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer// License. See LICENSE.TXT for details.
769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer//
869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer//===----------------------------------------------------------------------===//
969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer//
1069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer// This implements the TargetLoweringBase class.
1169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer//
1269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer//===----------------------------------------------------------------------===//
1369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
1469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer#include "llvm/Target/TargetLowering.h"
1569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer#include "llvm/ADT/BitVector.h"
1669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer#include "llvm/ADT/STLExtras.h"
1786cdbc9c29a572d422815f55fd89ff7510d1e3e8Paul Redmond#include "llvm/ADT/Triple.h"
1869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer#include "llvm/CodeGen/Analysis.h"
1969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer#include "llvm/CodeGen/MachineFrameInfo.h"
2069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer#include "llvm/CodeGen/MachineFunction.h"
2136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines#include "llvm/CodeGen/MachineInstrBuilder.h"
2269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer#include "llvm/CodeGen/MachineJumpTableInfo.h"
2336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines#include "llvm/CodeGen/StackMaps.h"
2469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer#include "llvm/IR/DataLayout.h"
2569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer#include "llvm/IR/DerivedTypes.h"
2669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer#include "llvm/IR/GlobalVariable.h"
2736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines#include "llvm/IR/Mangler.h"
2869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer#include "llvm/MC/MCAsmInfo.h"
2936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines#include "llvm/MC/MCContext.h"
3069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer#include "llvm/MC/MCExpr.h"
3169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer#include "llvm/Support/CommandLine.h"
3269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer#include "llvm/Support/ErrorHandling.h"
3369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer#include "llvm/Support/MathExtras.h"
3469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer#include "llvm/Target/TargetLoweringObjectFile.h"
3569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer#include "llvm/Target/TargetMachine.h"
3669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer#include "llvm/Target/TargetRegisterInfo.h"
3737ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines#include "llvm/Target/TargetSubtargetInfo.h"
3869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer#include <cctype>
3969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramerusing namespace llvm;
4069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
4169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// InitLibcallNames - Set default libcall names.
4269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer///
43c6a4f5e819217e1e12c458aed8e7b122e23a3a58Stephen Hinesstatic void InitLibcallNames(const char **Names, const Triple &TT) {
4469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SHL_I16] = "__ashlhi3";
4569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SHL_I32] = "__ashlsi3";
4669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SHL_I64] = "__ashldi3";
4769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SHL_I128] = "__ashlti3";
4869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SRL_I16] = "__lshrhi3";
4969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SRL_I32] = "__lshrsi3";
5069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SRL_I64] = "__lshrdi3";
5169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SRL_I128] = "__lshrti3";
5269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SRA_I16] = "__ashrhi3";
5369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SRA_I32] = "__ashrsi3";
5469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SRA_I64] = "__ashrdi3";
5569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SRA_I128] = "__ashrti3";
5669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::MUL_I8] = "__mulqi3";
5769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::MUL_I16] = "__mulhi3";
5869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::MUL_I32] = "__mulsi3";
5969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::MUL_I64] = "__muldi3";
6069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::MUL_I128] = "__multi3";
6169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::MULO_I32] = "__mulosi4";
6269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::MULO_I64] = "__mulodi4";
6369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::MULO_I128] = "__muloti4";
6469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SDIV_I8] = "__divqi3";
6569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SDIV_I16] = "__divhi3";
6669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SDIV_I32] = "__divsi3";
6769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SDIV_I64] = "__divdi3";
6869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SDIV_I128] = "__divti3";
6969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::UDIV_I8] = "__udivqi3";
7069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::UDIV_I16] = "__udivhi3";
7169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::UDIV_I32] = "__udivsi3";
7269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::UDIV_I64] = "__udivdi3";
7369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::UDIV_I128] = "__udivti3";
7469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SREM_I8] = "__modqi3";
7569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SREM_I16] = "__modhi3";
7669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SREM_I32] = "__modsi3";
7769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SREM_I64] = "__moddi3";
7869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SREM_I128] = "__modti3";
7969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::UREM_I8] = "__umodqi3";
8069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::UREM_I16] = "__umodhi3";
8169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::UREM_I32] = "__umodsi3";
8269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::UREM_I64] = "__umoddi3";
8369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::UREM_I128] = "__umodti3";
8469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
8569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // These are generally not available.
86dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  Names[RTLIB::SDIVREM_I8] = nullptr;
87dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  Names[RTLIB::SDIVREM_I16] = nullptr;
88dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  Names[RTLIB::SDIVREM_I32] = nullptr;
89dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  Names[RTLIB::SDIVREM_I64] = nullptr;
90dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  Names[RTLIB::SDIVREM_I128] = nullptr;
91dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  Names[RTLIB::UDIVREM_I8] = nullptr;
92dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  Names[RTLIB::UDIVREM_I16] = nullptr;
93dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  Names[RTLIB::UDIVREM_I32] = nullptr;
94dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  Names[RTLIB::UDIVREM_I64] = nullptr;
95dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  Names[RTLIB::UDIVREM_I128] = nullptr;
9669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
9769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::NEG_I32] = "__negsi2";
9869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::NEG_I64] = "__negdi2";
9969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::ADD_F32] = "__addsf3";
10069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::ADD_F64] = "__adddf3";
10169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::ADD_F80] = "__addxf3";
10269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::ADD_F128] = "__addtf3";
10369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::ADD_PPCF128] = "__gcc_qadd";
10469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SUB_F32] = "__subsf3";
10569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SUB_F64] = "__subdf3";
10669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SUB_F80] = "__subxf3";
10769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SUB_F128] = "__subtf3";
10869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SUB_PPCF128] = "__gcc_qsub";
10969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::MUL_F32] = "__mulsf3";
11069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::MUL_F64] = "__muldf3";
11169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::MUL_F80] = "__mulxf3";
11269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::MUL_F128] = "__multf3";
11369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::MUL_PPCF128] = "__gcc_qmul";
11469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::DIV_F32] = "__divsf3";
11569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::DIV_F64] = "__divdf3";
11669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::DIV_F80] = "__divxf3";
11769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::DIV_F128] = "__divtf3";
11869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::DIV_PPCF128] = "__gcc_qdiv";
11969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::REM_F32] = "fmodf";
12069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::REM_F64] = "fmod";
12169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::REM_F80] = "fmodl";
12269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::REM_F128] = "fmodl";
12369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::REM_PPCF128] = "fmodl";
12469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FMA_F32] = "fmaf";
12569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FMA_F64] = "fma";
12669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FMA_F80] = "fmal";
12769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FMA_F128] = "fmal";
12869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FMA_PPCF128] = "fmal";
12969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::POWI_F32] = "__powisf2";
13069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::POWI_F64] = "__powidf2";
13169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::POWI_F80] = "__powixf2";
13269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::POWI_F128] = "__powitf2";
13369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::POWI_PPCF128] = "__powitf2";
13469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SQRT_F32] = "sqrtf";
13569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SQRT_F64] = "sqrt";
13669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SQRT_F80] = "sqrtl";
13769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SQRT_F128] = "sqrtl";
13869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SQRT_PPCF128] = "sqrtl";
13969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::LOG_F32] = "logf";
14069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::LOG_F64] = "log";
14169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::LOG_F80] = "logl";
14269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::LOG_F128] = "logl";
14369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::LOG_PPCF128] = "logl";
14469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::LOG2_F32] = "log2f";
14569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::LOG2_F64] = "log2";
14669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::LOG2_F80] = "log2l";
14769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::LOG2_F128] = "log2l";
14869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::LOG2_PPCF128] = "log2l";
14969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::LOG10_F32] = "log10f";
15069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::LOG10_F64] = "log10";
15169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::LOG10_F80] = "log10l";
15269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::LOG10_F128] = "log10l";
15369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::LOG10_PPCF128] = "log10l";
15469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::EXP_F32] = "expf";
15569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::EXP_F64] = "exp";
15669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::EXP_F80] = "expl";
15769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::EXP_F128] = "expl";
15869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::EXP_PPCF128] = "expl";
15969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::EXP2_F32] = "exp2f";
16069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::EXP2_F64] = "exp2";
16169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::EXP2_F80] = "exp2l";
16269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::EXP2_F128] = "exp2l";
16369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::EXP2_PPCF128] = "exp2l";
16469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SIN_F32] = "sinf";
16569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SIN_F64] = "sin";
16669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SIN_F80] = "sinl";
16769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SIN_F128] = "sinl";
16869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SIN_PPCF128] = "sinl";
16969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::COS_F32] = "cosf";
17069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::COS_F64] = "cos";
17169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::COS_F80] = "cosl";
17269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::COS_F128] = "cosl";
17369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::COS_PPCF128] = "cosl";
17469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::POW_F32] = "powf";
17569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::POW_F64] = "pow";
17669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::POW_F80] = "powl";
17769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::POW_F128] = "powl";
17869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::POW_PPCF128] = "powl";
17969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::CEIL_F32] = "ceilf";
18069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::CEIL_F64] = "ceil";
18169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::CEIL_F80] = "ceill";
18269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::CEIL_F128] = "ceill";
18369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::CEIL_PPCF128] = "ceill";
18469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::TRUNC_F32] = "truncf";
18569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::TRUNC_F64] = "trunc";
18669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::TRUNC_F80] = "truncl";
18769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::TRUNC_F128] = "truncl";
18869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::TRUNC_PPCF128] = "truncl";
18969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::RINT_F32] = "rintf";
19069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::RINT_F64] = "rint";
19169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::RINT_F80] = "rintl";
19269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::RINT_F128] = "rintl";
19369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::RINT_PPCF128] = "rintl";
19469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::NEARBYINT_F32] = "nearbyintf";
19569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::NEARBYINT_F64] = "nearbyint";
19669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::NEARBYINT_F80] = "nearbyintl";
19769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::NEARBYINT_F128] = "nearbyintl";
19869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::NEARBYINT_PPCF128] = "nearbyintl";
19941418d17cced656f91038b2482bc9d173b4974b0Hal Finkel  Names[RTLIB::ROUND_F32] = "roundf";
20041418d17cced656f91038b2482bc9d173b4974b0Hal Finkel  Names[RTLIB::ROUND_F64] = "round";
20141418d17cced656f91038b2482bc9d173b4974b0Hal Finkel  Names[RTLIB::ROUND_F80] = "roundl";
20241418d17cced656f91038b2482bc9d173b4974b0Hal Finkel  Names[RTLIB::ROUND_F128] = "roundl";
20341418d17cced656f91038b2482bc9d173b4974b0Hal Finkel  Names[RTLIB::ROUND_PPCF128] = "roundl";
20469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FLOOR_F32] = "floorf";
20569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FLOOR_F64] = "floor";
20669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FLOOR_F80] = "floorl";
20769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FLOOR_F128] = "floorl";
20869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FLOOR_PPCF128] = "floorl";
20937ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  Names[RTLIB::FMIN_F32] = "fminf";
21037ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  Names[RTLIB::FMIN_F64] = "fmin";
21137ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  Names[RTLIB::FMIN_F80] = "fminl";
21237ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  Names[RTLIB::FMIN_F128] = "fminl";
21337ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  Names[RTLIB::FMIN_PPCF128] = "fminl";
21437ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  Names[RTLIB::FMAX_F32] = "fmaxf";
21537ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  Names[RTLIB::FMAX_F64] = "fmax";
21637ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  Names[RTLIB::FMAX_F80] = "fmaxl";
21737ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  Names[RTLIB::FMAX_F128] = "fmaxl";
21837ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  Names[RTLIB::FMAX_PPCF128] = "fmaxl";
21936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Names[RTLIB::ROUND_F32] = "roundf";
22036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Names[RTLIB::ROUND_F64] = "round";
22136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Names[RTLIB::ROUND_F80] = "roundl";
22236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Names[RTLIB::ROUND_F128] = "roundl";
22336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Names[RTLIB::ROUND_PPCF128] = "roundl";
22469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::COPYSIGN_F32] = "copysignf";
22569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::COPYSIGN_F64] = "copysign";
22669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::COPYSIGN_F80] = "copysignl";
22769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::COPYSIGN_F128] = "copysignl";
22869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::COPYSIGN_PPCF128] = "copysignl";
22969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPEXT_F64_F128] = "__extenddftf2";
23069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPEXT_F32_F128] = "__extendsftf2";
23169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPEXT_F32_F64] = "__extendsfdf2";
23269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPEXT_F16_F32] = "__gnu_h2f_ieee";
23369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPROUND_F32_F16] = "__gnu_f2h_ieee";
23437ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  Names[RTLIB::FPROUND_F64_F16] = "__truncdfhf2";
23537ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  Names[RTLIB::FPROUND_F80_F16] = "__truncxfhf2";
23637ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  Names[RTLIB::FPROUND_F128_F16] = "__trunctfhf2";
23737ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  Names[RTLIB::FPROUND_PPCF128_F16] = "__trunctfhf2";
23869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPROUND_F64_F32] = "__truncdfsf2";
23969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPROUND_F80_F32] = "__truncxfsf2";
24069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPROUND_F128_F32] = "__trunctfsf2";
24169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPROUND_PPCF128_F32] = "__trunctfsf2";
24269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPROUND_F80_F64] = "__truncxfdf2";
24369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPROUND_F128_F64] = "__trunctfdf2";
24469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPROUND_PPCF128_F64] = "__trunctfdf2";
24569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPTOSINT_F32_I8] = "__fixsfqi";
24669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPTOSINT_F32_I16] = "__fixsfhi";
24769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPTOSINT_F32_I32] = "__fixsfsi";
24869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPTOSINT_F32_I64] = "__fixsfdi";
24969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPTOSINT_F32_I128] = "__fixsfti";
25069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPTOSINT_F64_I8] = "__fixdfqi";
25169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPTOSINT_F64_I16] = "__fixdfhi";
25269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPTOSINT_F64_I32] = "__fixdfsi";
25369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPTOSINT_F64_I64] = "__fixdfdi";
25469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPTOSINT_F64_I128] = "__fixdfti";
25569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPTOSINT_F80_I32] = "__fixxfsi";
25669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPTOSINT_F80_I64] = "__fixxfdi";
25769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPTOSINT_F80_I128] = "__fixxfti";
25869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPTOSINT_F128_I32] = "__fixtfsi";
25969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPTOSINT_F128_I64] = "__fixtfdi";
26069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPTOSINT_F128_I128] = "__fixtfti";
26169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPTOSINT_PPCF128_I32] = "__fixtfsi";
26269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPTOSINT_PPCF128_I64] = "__fixtfdi";
26369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPTOSINT_PPCF128_I128] = "__fixtfti";
26469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPTOUINT_F32_I8] = "__fixunssfqi";
26569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPTOUINT_F32_I16] = "__fixunssfhi";
26669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPTOUINT_F32_I32] = "__fixunssfsi";
26769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPTOUINT_F32_I64] = "__fixunssfdi";
26869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPTOUINT_F32_I128] = "__fixunssfti";
26969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPTOUINT_F64_I8] = "__fixunsdfqi";
27069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPTOUINT_F64_I16] = "__fixunsdfhi";
27169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPTOUINT_F64_I32] = "__fixunsdfsi";
27269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPTOUINT_F64_I64] = "__fixunsdfdi";
27369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPTOUINT_F64_I128] = "__fixunsdfti";
27469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPTOUINT_F80_I32] = "__fixunsxfsi";
27569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPTOUINT_F80_I64] = "__fixunsxfdi";
27669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPTOUINT_F80_I128] = "__fixunsxfti";
27769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPTOUINT_F128_I32] = "__fixunstfsi";
27869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPTOUINT_F128_I64] = "__fixunstfdi";
27969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPTOUINT_F128_I128] = "__fixunstfti";
28069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPTOUINT_PPCF128_I32] = "__fixunstfsi";
28169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPTOUINT_PPCF128_I64] = "__fixunstfdi";
28269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPTOUINT_PPCF128_I128] = "__fixunstfti";
28369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SINTTOFP_I32_F32] = "__floatsisf";
28469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SINTTOFP_I32_F64] = "__floatsidf";
28569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SINTTOFP_I32_F80] = "__floatsixf";
28669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SINTTOFP_I32_F128] = "__floatsitf";
28769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SINTTOFP_I32_PPCF128] = "__floatsitf";
28869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SINTTOFP_I64_F32] = "__floatdisf";
28969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SINTTOFP_I64_F64] = "__floatdidf";
29069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SINTTOFP_I64_F80] = "__floatdixf";
29169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SINTTOFP_I64_F128] = "__floatditf";
29269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SINTTOFP_I64_PPCF128] = "__floatditf";
29369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SINTTOFP_I128_F32] = "__floattisf";
29469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SINTTOFP_I128_F64] = "__floattidf";
29569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SINTTOFP_I128_F80] = "__floattixf";
29669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SINTTOFP_I128_F128] = "__floattitf";
29769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SINTTOFP_I128_PPCF128] = "__floattitf";
29869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::UINTTOFP_I32_F32] = "__floatunsisf";
29969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::UINTTOFP_I32_F64] = "__floatunsidf";
30069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::UINTTOFP_I32_F80] = "__floatunsixf";
30169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::UINTTOFP_I32_F128] = "__floatunsitf";
30269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::UINTTOFP_I32_PPCF128] = "__floatunsitf";
30369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::UINTTOFP_I64_F32] = "__floatundisf";
30469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::UINTTOFP_I64_F64] = "__floatundidf";
30569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::UINTTOFP_I64_F80] = "__floatundixf";
30669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::UINTTOFP_I64_F128] = "__floatunditf";
30769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::UINTTOFP_I64_PPCF128] = "__floatunditf";
30869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::UINTTOFP_I128_F32] = "__floatuntisf";
30969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::UINTTOFP_I128_F64] = "__floatuntidf";
31069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::UINTTOFP_I128_F80] = "__floatuntixf";
31169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::UINTTOFP_I128_F128] = "__floatuntitf";
31269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::UINTTOFP_I128_PPCF128] = "__floatuntitf";
31369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::OEQ_F32] = "__eqsf2";
31469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::OEQ_F64] = "__eqdf2";
31569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::OEQ_F128] = "__eqtf2";
31669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::UNE_F32] = "__nesf2";
31769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::UNE_F64] = "__nedf2";
31869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::UNE_F128] = "__netf2";
31969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::OGE_F32] = "__gesf2";
32069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::OGE_F64] = "__gedf2";
32169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::OGE_F128] = "__getf2";
32269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::OLT_F32] = "__ltsf2";
32369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::OLT_F64] = "__ltdf2";
32469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::OLT_F128] = "__lttf2";
32569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::OLE_F32] = "__lesf2";
32669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::OLE_F64] = "__ledf2";
32769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::OLE_F128] = "__letf2";
32869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::OGT_F32] = "__gtsf2";
32969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::OGT_F64] = "__gtdf2";
33069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::OGT_F128] = "__gttf2";
33169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::UO_F32] = "__unordsf2";
33269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::UO_F64] = "__unorddf2";
33369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::UO_F128] = "__unordtf2";
33469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::O_F32] = "__unordsf2";
33569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::O_F64] = "__unorddf2";
33669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::O_F128] = "__unordtf2";
33769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::MEMCPY] = "memcpy";
33869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::MEMMOVE] = "memmove";
33969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::MEMSET] = "memset";
34069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::UNWIND_RESUME] = "_Unwind_Resume";
34169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SYNC_VAL_COMPARE_AND_SWAP_1] = "__sync_val_compare_and_swap_1";
34269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SYNC_VAL_COMPARE_AND_SWAP_2] = "__sync_val_compare_and_swap_2";
34369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SYNC_VAL_COMPARE_AND_SWAP_4] = "__sync_val_compare_and_swap_4";
34469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SYNC_VAL_COMPARE_AND_SWAP_8] = "__sync_val_compare_and_swap_8";
345641bea117d2f5e68c11156b9eea1c9270825dfb9David Majnemer  Names[RTLIB::SYNC_VAL_COMPARE_AND_SWAP_16] = "__sync_val_compare_and_swap_16";
34669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SYNC_LOCK_TEST_AND_SET_1] = "__sync_lock_test_and_set_1";
34769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SYNC_LOCK_TEST_AND_SET_2] = "__sync_lock_test_and_set_2";
34869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SYNC_LOCK_TEST_AND_SET_4] = "__sync_lock_test_and_set_4";
34969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SYNC_LOCK_TEST_AND_SET_8] = "__sync_lock_test_and_set_8";
350641bea117d2f5e68c11156b9eea1c9270825dfb9David Majnemer  Names[RTLIB::SYNC_LOCK_TEST_AND_SET_16] = "__sync_lock_test_and_set_16";
35169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SYNC_FETCH_AND_ADD_1] = "__sync_fetch_and_add_1";
35269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SYNC_FETCH_AND_ADD_2] = "__sync_fetch_and_add_2";
35369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SYNC_FETCH_AND_ADD_4] = "__sync_fetch_and_add_4";
35469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SYNC_FETCH_AND_ADD_8] = "__sync_fetch_and_add_8";
355641bea117d2f5e68c11156b9eea1c9270825dfb9David Majnemer  Names[RTLIB::SYNC_FETCH_AND_ADD_16] = "__sync_fetch_and_add_16";
35669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SYNC_FETCH_AND_SUB_1] = "__sync_fetch_and_sub_1";
35769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SYNC_FETCH_AND_SUB_2] = "__sync_fetch_and_sub_2";
35869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SYNC_FETCH_AND_SUB_4] = "__sync_fetch_and_sub_4";
35969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SYNC_FETCH_AND_SUB_8] = "__sync_fetch_and_sub_8";
360641bea117d2f5e68c11156b9eea1c9270825dfb9David Majnemer  Names[RTLIB::SYNC_FETCH_AND_SUB_16] = "__sync_fetch_and_sub_16";
36169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SYNC_FETCH_AND_AND_1] = "__sync_fetch_and_and_1";
36269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SYNC_FETCH_AND_AND_2] = "__sync_fetch_and_and_2";
36369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SYNC_FETCH_AND_AND_4] = "__sync_fetch_and_and_4";
36469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SYNC_FETCH_AND_AND_8] = "__sync_fetch_and_and_8";
365641bea117d2f5e68c11156b9eea1c9270825dfb9David Majnemer  Names[RTLIB::SYNC_FETCH_AND_AND_16] = "__sync_fetch_and_and_16";
36669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SYNC_FETCH_AND_OR_1] = "__sync_fetch_and_or_1";
36769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SYNC_FETCH_AND_OR_2] = "__sync_fetch_and_or_2";
36869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SYNC_FETCH_AND_OR_4] = "__sync_fetch_and_or_4";
36969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SYNC_FETCH_AND_OR_8] = "__sync_fetch_and_or_8";
370641bea117d2f5e68c11156b9eea1c9270825dfb9David Majnemer  Names[RTLIB::SYNC_FETCH_AND_OR_16] = "__sync_fetch_and_or_16";
37169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SYNC_FETCH_AND_XOR_1] = "__sync_fetch_and_xor_1";
37269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SYNC_FETCH_AND_XOR_2] = "__sync_fetch_and_xor_2";
37369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SYNC_FETCH_AND_XOR_4] = "__sync_fetch_and_xor_4";
37469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SYNC_FETCH_AND_XOR_8] = "__sync_fetch_and_xor_8";
375641bea117d2f5e68c11156b9eea1c9270825dfb9David Majnemer  Names[RTLIB::SYNC_FETCH_AND_XOR_16] = "__sync_fetch_and_xor_16";
37669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SYNC_FETCH_AND_NAND_1] = "__sync_fetch_and_nand_1";
37769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SYNC_FETCH_AND_NAND_2] = "__sync_fetch_and_nand_2";
37869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SYNC_FETCH_AND_NAND_4] = "__sync_fetch_and_nand_4";
37969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SYNC_FETCH_AND_NAND_8] = "__sync_fetch_and_nand_8";
380641bea117d2f5e68c11156b9eea1c9270825dfb9David Majnemer  Names[RTLIB::SYNC_FETCH_AND_NAND_16] = "__sync_fetch_and_nand_16";
3815a42ae81f742aaab826b7a72cb0a9a7e5a957a07Tim Northover  Names[RTLIB::SYNC_FETCH_AND_MAX_1] = "__sync_fetch_and_max_1";
3825a42ae81f742aaab826b7a72cb0a9a7e5a957a07Tim Northover  Names[RTLIB::SYNC_FETCH_AND_MAX_2] = "__sync_fetch_and_max_2";
3835a42ae81f742aaab826b7a72cb0a9a7e5a957a07Tim Northover  Names[RTLIB::SYNC_FETCH_AND_MAX_4] = "__sync_fetch_and_max_4";
3845a42ae81f742aaab826b7a72cb0a9a7e5a957a07Tim Northover  Names[RTLIB::SYNC_FETCH_AND_MAX_8] = "__sync_fetch_and_max_8";
3855a42ae81f742aaab826b7a72cb0a9a7e5a957a07Tim Northover  Names[RTLIB::SYNC_FETCH_AND_MAX_16] = "__sync_fetch_and_max_16";
3865a42ae81f742aaab826b7a72cb0a9a7e5a957a07Tim Northover  Names[RTLIB::SYNC_FETCH_AND_UMAX_1] = "__sync_fetch_and_umax_1";
3875a42ae81f742aaab826b7a72cb0a9a7e5a957a07Tim Northover  Names[RTLIB::SYNC_FETCH_AND_UMAX_2] = "__sync_fetch_and_umax_2";
3885a42ae81f742aaab826b7a72cb0a9a7e5a957a07Tim Northover  Names[RTLIB::SYNC_FETCH_AND_UMAX_4] = "__sync_fetch_and_umax_4";
3895a42ae81f742aaab826b7a72cb0a9a7e5a957a07Tim Northover  Names[RTLIB::SYNC_FETCH_AND_UMAX_8] = "__sync_fetch_and_umax_8";
3905a42ae81f742aaab826b7a72cb0a9a7e5a957a07Tim Northover  Names[RTLIB::SYNC_FETCH_AND_UMAX_16] = "__sync_fetch_and_umax_16";
3915a42ae81f742aaab826b7a72cb0a9a7e5a957a07Tim Northover  Names[RTLIB::SYNC_FETCH_AND_MIN_1] = "__sync_fetch_and_min_1";
3925a42ae81f742aaab826b7a72cb0a9a7e5a957a07Tim Northover  Names[RTLIB::SYNC_FETCH_AND_MIN_2] = "__sync_fetch_and_min_2";
3935a42ae81f742aaab826b7a72cb0a9a7e5a957a07Tim Northover  Names[RTLIB::SYNC_FETCH_AND_MIN_4] = "__sync_fetch_and_min_4";
3945a42ae81f742aaab826b7a72cb0a9a7e5a957a07Tim Northover  Names[RTLIB::SYNC_FETCH_AND_MIN_8] = "__sync_fetch_and_min_8";
3955a42ae81f742aaab826b7a72cb0a9a7e5a957a07Tim Northover  Names[RTLIB::SYNC_FETCH_AND_MIN_16] = "__sync_fetch_and_min_16";
3965a42ae81f742aaab826b7a72cb0a9a7e5a957a07Tim Northover  Names[RTLIB::SYNC_FETCH_AND_UMIN_1] = "__sync_fetch_and_umin_1";
3975a42ae81f742aaab826b7a72cb0a9a7e5a957a07Tim Northover  Names[RTLIB::SYNC_FETCH_AND_UMIN_2] = "__sync_fetch_and_umin_2";
3985a42ae81f742aaab826b7a72cb0a9a7e5a957a07Tim Northover  Names[RTLIB::SYNC_FETCH_AND_UMIN_4] = "__sync_fetch_and_umin_4";
3995a42ae81f742aaab826b7a72cb0a9a7e5a957a07Tim Northover  Names[RTLIB::SYNC_FETCH_AND_UMIN_8] = "__sync_fetch_and_umin_8";
4005a42ae81f742aaab826b7a72cb0a9a7e5a957a07Tim Northover  Names[RTLIB::SYNC_FETCH_AND_UMIN_16] = "__sync_fetch_and_umin_16";
4018688a58c53b46d2dda9bf50dafd5195790a7ed58Evan Cheng
402c6a4f5e819217e1e12c458aed8e7b122e23a3a58Stephen Hines  if (TT.getEnvironment() == Triple::GNU) {
40386cdbc9c29a572d422815f55fd89ff7510d1e3e8Paul Redmond    Names[RTLIB::SINCOS_F32] = "sincosf";
40486cdbc9c29a572d422815f55fd89ff7510d1e3e8Paul Redmond    Names[RTLIB::SINCOS_F64] = "sincos";
40586cdbc9c29a572d422815f55fd89ff7510d1e3e8Paul Redmond    Names[RTLIB::SINCOS_F80] = "sincosl";
40686cdbc9c29a572d422815f55fd89ff7510d1e3e8Paul Redmond    Names[RTLIB::SINCOS_F128] = "sincosl";
40786cdbc9c29a572d422815f55fd89ff7510d1e3e8Paul Redmond    Names[RTLIB::SINCOS_PPCF128] = "sincosl";
40886cdbc9c29a572d422815f55fd89ff7510d1e3e8Paul Redmond  } else {
40986cdbc9c29a572d422815f55fd89ff7510d1e3e8Paul Redmond    // These are generally not available.
410dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines    Names[RTLIB::SINCOS_F32] = nullptr;
411dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines    Names[RTLIB::SINCOS_F64] = nullptr;
412dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines    Names[RTLIB::SINCOS_F80] = nullptr;
413dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines    Names[RTLIB::SINCOS_F128] = nullptr;
414dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines    Names[RTLIB::SINCOS_PPCF128] = nullptr;
41586cdbc9c29a572d422815f55fd89ff7510d1e3e8Paul Redmond  }
41615b2782ccf141930cc98507a1cb1d501fbfd4000Michael Gottesman
417ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines  if (!TT.isOSOpenBSD()) {
41815b2782ccf141930cc98507a1cb1d501fbfd4000Michael Gottesman    Names[RTLIB::STACKPROTECTOR_CHECK_FAIL] = "__stack_chk_fail";
41915b2782ccf141930cc98507a1cb1d501fbfd4000Michael Gottesman  } else {
42015b2782ccf141930cc98507a1cb1d501fbfd4000Michael Gottesman    // These are generally not available.
421dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines    Names[RTLIB::STACKPROTECTOR_CHECK_FAIL] = nullptr;
42215b2782ccf141930cc98507a1cb1d501fbfd4000Michael Gottesman  }
4236948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar
4246948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar  // For f16/f32 conversions, Darwin uses the standard naming scheme, instead
4256948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar  // of the gnueabi-style __gnu_*_ieee.
4266948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar  // FIXME: What about other targets?
4276948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar  if (TT.isOSDarwin()) {
4286948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar    Names[RTLIB::FPEXT_F16_F32] = "__extendhfsf2";
4296948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar    Names[RTLIB::FPROUND_F32_F16] = "__truncsfhf2";
4306948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar  }
43169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer}
43269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
43369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// InitLibcallCallingConvs - Set default libcall CallingConvs.
43469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer///
43569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramerstatic void InitLibcallCallingConvs(CallingConv::ID *CCs) {
43669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  for (int i = 0; i < RTLIB::UNKNOWN_LIBCALL; ++i) {
43769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    CCs[i] = CallingConv::C;
43869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  }
43969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer}
44069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
44169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// getFPEXT - Return the FPEXT_*_* value for the given types, or
44269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// UNKNOWN_LIBCALL if there is none.
44369e42dbd006c0afb732067ece7327988b1e24c01Benjamin KramerRTLIB::Libcall RTLIB::getFPEXT(EVT OpVT, EVT RetVT) {
44437ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  if (OpVT == MVT::f16) {
44537ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines    if (RetVT == MVT::f32)
44637ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines      return FPEXT_F16_F32;
44737ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  } else if (OpVT == MVT::f32) {
44869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::f64)
44969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPEXT_F32_F64;
45069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::f128)
45169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPEXT_F32_F128;
45269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  } else if (OpVT == MVT::f64) {
45369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::f128)
45469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPEXT_F64_F128;
45569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  }
45669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
45769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  return UNKNOWN_LIBCALL;
45869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer}
45969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
46069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// getFPROUND - Return the FPROUND_*_* value for the given types, or
46169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// UNKNOWN_LIBCALL if there is none.
46269e42dbd006c0afb732067ece7327988b1e24c01Benjamin KramerRTLIB::Libcall RTLIB::getFPROUND(EVT OpVT, EVT RetVT) {
46337ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  if (RetVT == MVT::f16) {
46437ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines    if (OpVT == MVT::f32)
46537ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines      return FPROUND_F32_F16;
46637ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines    if (OpVT == MVT::f64)
46737ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines      return FPROUND_F64_F16;
46837ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines    if (OpVT == MVT::f80)
46937ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines      return FPROUND_F80_F16;
47037ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines    if (OpVT == MVT::f128)
47137ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines      return FPROUND_F128_F16;
47237ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines    if (OpVT == MVT::ppcf128)
47337ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines      return FPROUND_PPCF128_F16;
47437ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  } else if (RetVT == MVT::f32) {
47569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (OpVT == MVT::f64)
47669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPROUND_F64_F32;
47769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (OpVT == MVT::f80)
47869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPROUND_F80_F32;
47969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (OpVT == MVT::f128)
48069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPROUND_F128_F32;
48169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (OpVT == MVT::ppcf128)
48269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPROUND_PPCF128_F32;
48369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  } else if (RetVT == MVT::f64) {
48469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (OpVT == MVT::f80)
48569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPROUND_F80_F64;
48669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (OpVT == MVT::f128)
48769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPROUND_F128_F64;
48869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (OpVT == MVT::ppcf128)
48969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPROUND_PPCF128_F64;
49069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  }
49169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
49269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  return UNKNOWN_LIBCALL;
49369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer}
49469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
49569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// getFPTOSINT - Return the FPTOSINT_*_* value for the given types, or
49669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// UNKNOWN_LIBCALL if there is none.
49769e42dbd006c0afb732067ece7327988b1e24c01Benjamin KramerRTLIB::Libcall RTLIB::getFPTOSINT(EVT OpVT, EVT RetVT) {
49869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  if (OpVT == MVT::f32) {
49969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i8)
50069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOSINT_F32_I8;
50169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i16)
50269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOSINT_F32_I16;
50369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i32)
50469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOSINT_F32_I32;
50569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i64)
50669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOSINT_F32_I64;
50769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i128)
50869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOSINT_F32_I128;
50969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  } else if (OpVT == MVT::f64) {
51069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i8)
51169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOSINT_F64_I8;
51269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i16)
51369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOSINT_F64_I16;
51469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i32)
51569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOSINT_F64_I32;
51669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i64)
51769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOSINT_F64_I64;
51869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i128)
51969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOSINT_F64_I128;
52069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  } else if (OpVT == MVT::f80) {
52169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i32)
52269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOSINT_F80_I32;
52369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i64)
52469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOSINT_F80_I64;
52569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i128)
52669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOSINT_F80_I128;
52769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  } else if (OpVT == MVT::f128) {
52869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i32)
52969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOSINT_F128_I32;
53069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i64)
53169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOSINT_F128_I64;
53269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i128)
53369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOSINT_F128_I128;
53469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  } else if (OpVT == MVT::ppcf128) {
53569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i32)
53669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOSINT_PPCF128_I32;
53769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i64)
53869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOSINT_PPCF128_I64;
53969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i128)
54069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOSINT_PPCF128_I128;
54169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  }
54269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  return UNKNOWN_LIBCALL;
54369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer}
54469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
54569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// getFPTOUINT - Return the FPTOUINT_*_* value for the given types, or
54669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// UNKNOWN_LIBCALL if there is none.
54769e42dbd006c0afb732067ece7327988b1e24c01Benjamin KramerRTLIB::Libcall RTLIB::getFPTOUINT(EVT OpVT, EVT RetVT) {
54869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  if (OpVT == MVT::f32) {
54969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i8)
55069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOUINT_F32_I8;
55169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i16)
55269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOUINT_F32_I16;
55369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i32)
55469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOUINT_F32_I32;
55569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i64)
55669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOUINT_F32_I64;
55769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i128)
55869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOUINT_F32_I128;
55969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  } else if (OpVT == MVT::f64) {
56069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i8)
56169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOUINT_F64_I8;
56269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i16)
56369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOUINT_F64_I16;
56469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i32)
56569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOUINT_F64_I32;
56669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i64)
56769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOUINT_F64_I64;
56869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i128)
56969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOUINT_F64_I128;
57069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  } else if (OpVT == MVT::f80) {
57169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i32)
57269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOUINT_F80_I32;
57369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i64)
57469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOUINT_F80_I64;
57569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i128)
57669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOUINT_F80_I128;
57769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  } else if (OpVT == MVT::f128) {
57869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i32)
57969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOUINT_F128_I32;
58069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i64)
58169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOUINT_F128_I64;
58269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i128)
58369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOUINT_F128_I128;
58469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  } else if (OpVT == MVT::ppcf128) {
58569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i32)
58669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOUINT_PPCF128_I32;
58769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i64)
58869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOUINT_PPCF128_I64;
58969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i128)
59069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOUINT_PPCF128_I128;
59169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  }
59269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  return UNKNOWN_LIBCALL;
59369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer}
59469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
59569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// getSINTTOFP - Return the SINTTOFP_*_* value for the given types, or
59669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// UNKNOWN_LIBCALL if there is none.
59769e42dbd006c0afb732067ece7327988b1e24c01Benjamin KramerRTLIB::Libcall RTLIB::getSINTTOFP(EVT OpVT, EVT RetVT) {
59869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  if (OpVT == MVT::i32) {
59969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::f32)
60069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return SINTTOFP_I32_F32;
60169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::f64)
60269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return SINTTOFP_I32_F64;
60369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::f80)
60469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return SINTTOFP_I32_F80;
60569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::f128)
60669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return SINTTOFP_I32_F128;
60769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::ppcf128)
60869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return SINTTOFP_I32_PPCF128;
60969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  } else if (OpVT == MVT::i64) {
61069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::f32)
61169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return SINTTOFP_I64_F32;
61269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::f64)
61369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return SINTTOFP_I64_F64;
61469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::f80)
61569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return SINTTOFP_I64_F80;
61669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::f128)
61769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return SINTTOFP_I64_F128;
61869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::ppcf128)
61969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return SINTTOFP_I64_PPCF128;
62069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  } else if (OpVT == MVT::i128) {
62169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::f32)
62269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return SINTTOFP_I128_F32;
62369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::f64)
62469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return SINTTOFP_I128_F64;
62569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::f80)
62669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return SINTTOFP_I128_F80;
62769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::f128)
62869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return SINTTOFP_I128_F128;
62969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::ppcf128)
63069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return SINTTOFP_I128_PPCF128;
63169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  }
63269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  return UNKNOWN_LIBCALL;
63369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer}
63469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
63569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// getUINTTOFP - Return the UINTTOFP_*_* value for the given types, or
63669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// UNKNOWN_LIBCALL if there is none.
63769e42dbd006c0afb732067ece7327988b1e24c01Benjamin KramerRTLIB::Libcall RTLIB::getUINTTOFP(EVT OpVT, EVT RetVT) {
63869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  if (OpVT == MVT::i32) {
63969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::f32)
64069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return UINTTOFP_I32_F32;
64169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::f64)
64269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return UINTTOFP_I32_F64;
64369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::f80)
64469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return UINTTOFP_I32_F80;
64569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::f128)
64669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return UINTTOFP_I32_F128;
64769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::ppcf128)
64869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return UINTTOFP_I32_PPCF128;
64969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  } else if (OpVT == MVT::i64) {
65069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::f32)
65169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return UINTTOFP_I64_F32;
65269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::f64)
65369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return UINTTOFP_I64_F64;
65469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::f80)
65569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return UINTTOFP_I64_F80;
65669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::f128)
65769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return UINTTOFP_I64_F128;
65869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::ppcf128)
65969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return UINTTOFP_I64_PPCF128;
66069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  } else if (OpVT == MVT::i128) {
66169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::f32)
66269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return UINTTOFP_I128_F32;
66369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::f64)
66469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return UINTTOFP_I128_F64;
66569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::f80)
66669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return UINTTOFP_I128_F80;
66769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::f128)
66869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return UINTTOFP_I128_F128;
66969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::ppcf128)
67069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return UINTTOFP_I128_PPCF128;
67169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  }
67269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  return UNKNOWN_LIBCALL;
67369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer}
67469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
6754c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga NainarRTLIB::Libcall RTLIB::getATOMIC(unsigned Opc, MVT VT) {
6764c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar#define OP_TO_LIBCALL(Name, Enum)                                              \
6774c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar  case Name:                                                                   \
6784c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar    switch (VT.SimpleTy) {                                                     \
6794c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar    default:                                                                   \
6804c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar      return UNKNOWN_LIBCALL;                                                  \
6814c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar    case MVT::i8:                                                              \
6824c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar      return Enum##_1;                                                         \
6834c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar    case MVT::i16:                                                             \
6844c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar      return Enum##_2;                                                         \
6854c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar    case MVT::i32:                                                             \
6864c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar      return Enum##_4;                                                         \
6874c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar    case MVT::i64:                                                             \
6884c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar      return Enum##_8;                                                         \
6894c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar    case MVT::i128:                                                            \
6904c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar      return Enum##_16;                                                        \
6914c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar    }
6924c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar
6934c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar  switch (Opc) {
6944c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar    OP_TO_LIBCALL(ISD::ATOMIC_SWAP, SYNC_LOCK_TEST_AND_SET)
6954c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar    OP_TO_LIBCALL(ISD::ATOMIC_CMP_SWAP, SYNC_VAL_COMPARE_AND_SWAP)
6964c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar    OP_TO_LIBCALL(ISD::ATOMIC_LOAD_ADD, SYNC_FETCH_AND_ADD)
6974c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar    OP_TO_LIBCALL(ISD::ATOMIC_LOAD_SUB, SYNC_FETCH_AND_SUB)
6984c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar    OP_TO_LIBCALL(ISD::ATOMIC_LOAD_AND, SYNC_FETCH_AND_AND)
6994c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar    OP_TO_LIBCALL(ISD::ATOMIC_LOAD_OR, SYNC_FETCH_AND_OR)
7004c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar    OP_TO_LIBCALL(ISD::ATOMIC_LOAD_XOR, SYNC_FETCH_AND_XOR)
7014c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar    OP_TO_LIBCALL(ISD::ATOMIC_LOAD_NAND, SYNC_FETCH_AND_NAND)
7024c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar    OP_TO_LIBCALL(ISD::ATOMIC_LOAD_MAX, SYNC_FETCH_AND_MAX)
7034c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar    OP_TO_LIBCALL(ISD::ATOMIC_LOAD_UMAX, SYNC_FETCH_AND_UMAX)
7044c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar    OP_TO_LIBCALL(ISD::ATOMIC_LOAD_MIN, SYNC_FETCH_AND_MIN)
7054c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar    OP_TO_LIBCALL(ISD::ATOMIC_LOAD_UMIN, SYNC_FETCH_AND_UMIN)
7064c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar  }
7074c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar
7084c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar#undef OP_TO_LIBCALL
7094c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar
7104c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar  return UNKNOWN_LIBCALL;
7114c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar}
7124c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar
71369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// InitCmpLibcallCCs - Set default comparison libcall CC.
71469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer///
71569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramerstatic void InitCmpLibcallCCs(ISD::CondCode *CCs) {
71669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  memset(CCs, ISD::SETCC_INVALID, sizeof(ISD::CondCode)*RTLIB::UNKNOWN_LIBCALL);
71769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  CCs[RTLIB::OEQ_F32] = ISD::SETEQ;
71869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  CCs[RTLIB::OEQ_F64] = ISD::SETEQ;
71969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  CCs[RTLIB::OEQ_F128] = ISD::SETEQ;
72069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  CCs[RTLIB::UNE_F32] = ISD::SETNE;
72169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  CCs[RTLIB::UNE_F64] = ISD::SETNE;
72269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  CCs[RTLIB::UNE_F128] = ISD::SETNE;
72369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  CCs[RTLIB::OGE_F32] = ISD::SETGE;
72469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  CCs[RTLIB::OGE_F64] = ISD::SETGE;
72569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  CCs[RTLIB::OGE_F128] = ISD::SETGE;
72669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  CCs[RTLIB::OLT_F32] = ISD::SETLT;
72769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  CCs[RTLIB::OLT_F64] = ISD::SETLT;
72869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  CCs[RTLIB::OLT_F128] = ISD::SETLT;
72969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  CCs[RTLIB::OLE_F32] = ISD::SETLE;
73069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  CCs[RTLIB::OLE_F64] = ISD::SETLE;
73169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  CCs[RTLIB::OLE_F128] = ISD::SETLE;
73269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  CCs[RTLIB::OGT_F32] = ISD::SETGT;
73369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  CCs[RTLIB::OGT_F64] = ISD::SETGT;
73469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  CCs[RTLIB::OGT_F128] = ISD::SETGT;
73569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  CCs[RTLIB::UO_F32] = ISD::SETNE;
73669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  CCs[RTLIB::UO_F64] = ISD::SETNE;
73769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  CCs[RTLIB::UO_F128] = ISD::SETNE;
73869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  CCs[RTLIB::O_F32] = ISD::SETEQ;
73969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  CCs[RTLIB::O_F64] = ISD::SETEQ;
74069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  CCs[RTLIB::O_F128] = ISD::SETEQ;
74169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer}
74269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
74337ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines/// NOTE: The TargetMachine owns TLOF.
7444c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga NainarTargetLoweringBase::TargetLoweringBase(const TargetMachine &tm) : TM(tm) {
74513bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  initActions();
74613bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling
74713bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  // Perform these initializations only once.
7484c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar  IsLittleEndian = getDataLayout()->isLittleEndian();
74913bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  MaxStoresPerMemset = MaxStoresPerMemcpy = MaxStoresPerMemmove = 8;
75013bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  MaxStoresPerMemsetOptSize = MaxStoresPerMemcpyOptSize
75113bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling    = MaxStoresPerMemmoveOptSize = 4;
75213bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  UseUnderscoreSetJmp = false;
75313bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  UseUnderscoreLongJmp = false;
75413bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  SelectIsExpensive = false;
75536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  HasMultipleConditionRegisters = false;
756dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  HasExtractBitsInsn = false;
75713bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  IntDivIsCheap = false;
758ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines  FsqrtIsCheap = false;
75937ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  Pow2SDivIsCheap = false;
76013bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  JumpIsExpensive = false;
76113bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  PredictableSelectIsExpensive = false;
76236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  MaskAndBranchFoldingIsLegal = false;
763ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines  EnableExtLdPromotion = false;
76437ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  HasFloatingPointExceptions = true;
76513bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  StackPointerRegisterToSaveRestore = 0;
76613bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  ExceptionPointerRegister = 0;
76713bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  ExceptionSelectorRegister = 0;
76813bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  BooleanContents = UndefinedBooleanContent;
769c6a4f5e819217e1e12c458aed8e7b122e23a3a58Stephen Hines  BooleanFloatContents = UndefinedBooleanContent;
77013bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  BooleanVectorContents = UndefinedBooleanContent;
77113bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  SchedPreferenceInfo = Sched::ILP;
77213bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  JumpBufSize = 0;
77313bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  JumpBufAlignment = 0;
77413bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  MinFunctionAlignment = 0;
77513bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  PrefFunctionAlignment = 0;
77613bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  PrefLoopAlignment = 0;
77713bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  MinStackArgumentAlignment = 1;
77813bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  InsertFencesForAtomic = false;
77913bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  MinimumJumpTableEntries = 4;
78013bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling
781c6a4f5e819217e1e12c458aed8e7b122e23a3a58Stephen Hines  InitLibcallNames(LibcallRoutineNames, Triple(TM.getTargetTriple()));
78213bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  InitCmpLibcallCCs(CmpLibcallCCs);
78313bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  InitLibcallCallingConvs(LibcallCallingConvs);
78413bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling}
78513bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling
78613bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendlingvoid TargetLoweringBase::initActions() {
78769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // All operations default to being supported.
78869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  memset(OpActions, 0, sizeof(OpActions));
78969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  memset(LoadExtActions, 0, sizeof(LoadExtActions));
79069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  memset(TruncStoreActions, 0, sizeof(TruncStoreActions));
79169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  memset(IndexedModeActions, 0, sizeof(IndexedModeActions));
79269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  memset(CondCodeActions, 0, sizeof(CondCodeActions));
79313bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  memset(RegClassForVT, 0,MVT::LAST_VALUETYPE*sizeof(TargetRegisterClass*));
79413bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  memset(TargetDAGCombineArray, 0, array_lengthof(TargetDAGCombineArray));
79569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
79669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // Set default actions for various operations.
797ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines  for (MVT VT : MVT::all_valuetypes()) {
79869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    // Default all indexed load / store to expand.
79969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    for (unsigned IM = (unsigned)ISD::PRE_INC;
80069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer         IM != (unsigned)ISD::LAST_INDEXED_MODE; ++IM) {
801ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines      setIndexedLoadAction(IM, VT, Expand);
802ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines      setIndexedStoreAction(IM, VT, Expand);
80369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    }
80469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
805c6a4f5e819217e1e12c458aed8e7b122e23a3a58Stephen Hines    // Most backends expect to see the node which just returns the value loaded.
806ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines    setOperationAction(ISD::ATOMIC_CMP_SWAP_WITH_SUCCESS, VT, Expand);
807c6a4f5e819217e1e12c458aed8e7b122e23a3a58Stephen Hines
80869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    // These operations default to expand.
809ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines    setOperationAction(ISD::FGETSIGN, VT, Expand);
810ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines    setOperationAction(ISD::CONCAT_VECTORS, VT, Expand);
811ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines    setOperationAction(ISD::FMINNUM, VT, Expand);
812ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines    setOperationAction(ISD::FMAXNUM, VT, Expand);
813ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines    setOperationAction(ISD::FMAD, VT, Expand);
8146948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar    setOperationAction(ISD::SMIN, VT, Expand);
8156948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar    setOperationAction(ISD::SMAX, VT, Expand);
8166948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar    setOperationAction(ISD::UMIN, VT, Expand);
8176948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar    setOperationAction(ISD::UMAX, VT, Expand);
8186948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar
8196948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar    // Overflow operations default to expand
8206948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar    setOperationAction(ISD::SADDO, VT, Expand);
8216948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar    setOperationAction(ISD::SSUBO, VT, Expand);
8226948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar    setOperationAction(ISD::UADDO, VT, Expand);
8236948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar    setOperationAction(ISD::USUBO, VT, Expand);
8246948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar    setOperationAction(ISD::SMULO, VT, Expand);
8256948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar    setOperationAction(ISD::UMULO, VT, Expand);
8263d7f79a02e143cfcbc85ea2091f2797285a9db84Hal Finkel
8273d7f79a02e143cfcbc85ea2091f2797285a9db84Hal Finkel    // These library functions default to expand.
828ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines    setOperationAction(ISD::FROUND, VT, Expand);
82966d1fa6f4b443ac9f8bcea5d1f71a73ada733a42Hal Finkel
83066d1fa6f4b443ac9f8bcea5d1f71a73ada733a42Hal Finkel    // These operations default to expand for vector types.
831ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines    if (VT.isVector()) {
832ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines      setOperationAction(ISD::FCOPYSIGN, VT, Expand);
833ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines      setOperationAction(ISD::ANY_EXTEND_VECTOR_INREG, VT, Expand);
834ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines      setOperationAction(ISD::SIGN_EXTEND_VECTOR_INREG, VT, Expand);
835ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines      setOperationAction(ISD::ZERO_EXTEND_VECTOR_INREG, VT, Expand);
836c6a4f5e819217e1e12c458aed8e7b122e23a3a58Stephen Hines    }
83769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  }
83869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
83969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // Most targets ignore the @llvm.prefetch intrinsic.
84069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::PREFETCH, MVT::Other, Expand);
84169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
84269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // ConstantFP nodes default to expand.  Targets can either change this to
84369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // Legal, in which case all fp constants are legal, or use isFPImmLegal()
84469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // to optimize expansions for certain constants.
84569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::ConstantFP, MVT::f16, Expand);
84669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::ConstantFP, MVT::f32, Expand);
84769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::ConstantFP, MVT::f64, Expand);
84869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::ConstantFP, MVT::f80, Expand);
84969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::ConstantFP, MVT::f128, Expand);
85069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
85169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // These library functions default to expand.
8524c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar  for (MVT VT : {MVT::f32, MVT::f64, MVT::f128}) {
8534c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar    setOperationAction(ISD::FLOG ,      VT, Expand);
8544c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar    setOperationAction(ISD::FLOG2,      VT, Expand);
8554c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar    setOperationAction(ISD::FLOG10,     VT, Expand);
8564c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar    setOperationAction(ISD::FEXP ,      VT, Expand);
8574c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar    setOperationAction(ISD::FEXP2,      VT, Expand);
8584c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar    setOperationAction(ISD::FFLOOR,     VT, Expand);
8594c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar    setOperationAction(ISD::FMINNUM,    VT, Expand);
8604c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar    setOperationAction(ISD::FMAXNUM,    VT, Expand);
8614c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar    setOperationAction(ISD::FNEARBYINT, VT, Expand);
8624c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar    setOperationAction(ISD::FCEIL,      VT, Expand);
8634c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar    setOperationAction(ISD::FRINT,      VT, Expand);
8644c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar    setOperationAction(ISD::FTRUNC,     VT, Expand);
8654c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar    setOperationAction(ISD::FROUND,     VT, Expand);
8664c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar  }
86769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
86869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // Default ISD::TRAP to expand (which turns it into abort).
86969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::TRAP, MVT::Other, Expand);
87069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
87169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // On most systems, DEBUGTRAP and TRAP have no difference. The "Expand"
87269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // here is to inform DAG Legalizer to replace DEBUGTRAP with TRAP.
87369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  //
87469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::DEBUGTRAP, MVT::Other, Expand);
87569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer}
87669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
877da25cd3e6de8f21005590c2de49868f883cf2410Tom StellardMVT TargetLoweringBase::getPointerTy(uint32_t AS) const {
878da25cd3e6de8f21005590c2de49868f883cf2410Tom Stellard  return MVT::getIntegerVT(getPointerSizeInBits(AS));
879da25cd3e6de8f21005590c2de49868f883cf2410Tom Stellard}
880da25cd3e6de8f21005590c2de49868f883cf2410Tom Stellard
881da25cd3e6de8f21005590c2de49868f883cf2410Tom Stellardunsigned TargetLoweringBase::getPointerSizeInBits(uint32_t AS) const {
8824c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar  return getDataLayout()->getPointerSizeInBits(AS);
883da25cd3e6de8f21005590c2de49868f883cf2410Tom Stellard}
884da25cd3e6de8f21005590c2de49868f883cf2410Tom Stellard
885da25cd3e6de8f21005590c2de49868f883cf2410Tom Stellardunsigned TargetLoweringBase::getPointerTypeSizeInBits(Type *Ty) const {
886da25cd3e6de8f21005590c2de49868f883cf2410Tom Stellard  assert(Ty->isPointerTy());
887da25cd3e6de8f21005590c2de49868f883cf2410Tom Stellard  return getPointerSizeInBits(Ty->getPointerAddressSpace());
888da25cd3e6de8f21005590c2de49868f883cf2410Tom Stellard}
889da25cd3e6de8f21005590c2de49868f883cf2410Tom Stellard
890a6b20ced765b67a85d9219d0c8547fc9c133e14fMichael LiaoMVT TargetLoweringBase::getScalarShiftAmountTy(EVT LHSTy) const {
8914c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar  return MVT::getIntegerVT(8 * getDataLayout()->getPointerSize(0));
89269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer}
89369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
894a6b20ced765b67a85d9219d0c8547fc9c133e14fMichael LiaoEVT TargetLoweringBase::getShiftAmountTy(EVT LHSTy) const {
895a6b20ced765b67a85d9219d0c8547fc9c133e14fMichael Liao  assert(LHSTy.isInteger() && "Shift amount is not an integer type!");
896a6b20ced765b67a85d9219d0c8547fc9c133e14fMichael Liao  if (LHSTy.isVector())
897a6b20ced765b67a85d9219d0c8547fc9c133e14fMichael Liao    return LHSTy;
898a6b20ced765b67a85d9219d0c8547fc9c133e14fMichael Liao  return getScalarShiftAmountTy(LHSTy);
899a6b20ced765b67a85d9219d0c8547fc9c133e14fMichael Liao}
900a6b20ced765b67a85d9219d0c8547fc9c133e14fMichael Liao
90169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// canOpTrap - Returns true if the operation can trap for the value type.
90269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// VT must be a legal type.
90369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramerbool TargetLoweringBase::canOpTrap(unsigned Op, EVT VT) const {
90469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  assert(isTypeLegal(VT));
90569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  switch (Op) {
90669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  default:
90769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    return false;
90869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case ISD::FDIV:
90969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case ISD::FREM:
91069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case ISD::SDIV:
91169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case ISD::UDIV:
91269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case ISD::SREM:
91369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case ISD::UREM:
91469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    return true;
91569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  }
91669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer}
91769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
918ebe69fe11e48d322045d5949c83283927a0d790bStephen HinesTargetLoweringBase::LegalizeKind
919ebe69fe11e48d322045d5949c83283927a0d790bStephen HinesTargetLoweringBase::getTypeConversion(LLVMContext &Context, EVT VT) const {
920ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines  // If this is a simple type, use the ComputeRegisterProp mechanism.
921ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines  if (VT.isSimple()) {
922ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines    MVT SVT = VT.getSimpleVT();
923ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines    assert((unsigned)SVT.SimpleTy < array_lengthof(TransformToType));
924ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines    MVT NVT = TransformToType[SVT.SimpleTy];
925ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines    LegalizeTypeAction LA = ValueTypeActions.getTypeAction(SVT);
926ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines
927ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines    assert((LA == TypeLegal || LA == TypeSoftenFloat ||
928ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines            ValueTypeActions.getTypeAction(NVT) != TypePromoteInteger) &&
929ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines           "Promote may not follow Expand or Promote");
930ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines
931ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines    if (LA == TypeSplitVector)
932ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines      return LegalizeKind(LA,
933ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines                          EVT::getVectorVT(Context, SVT.getVectorElementType(),
934ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines                                           SVT.getVectorNumElements() / 2));
935ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines    if (LA == TypeScalarizeVector)
936ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines      return LegalizeKind(LA, SVT.getVectorElementType());
937ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines    return LegalizeKind(LA, NVT);
938ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines  }
939ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines
940ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines  // Handle Extended Scalar Types.
941ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines  if (!VT.isVector()) {
942ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines    assert(VT.isInteger() && "Float types must be simple");
943ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines    unsigned BitSize = VT.getSizeInBits();
944ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines    // First promote to a power-of-two size, then expand if necessary.
945ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines    if (BitSize < 8 || !isPowerOf2_32(BitSize)) {
946ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines      EVT NVT = VT.getRoundIntegerType(Context);
947ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines      assert(NVT != VT && "Unable to round integer VT");
948ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines      LegalizeKind NextStep = getTypeConversion(Context, NVT);
949ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines      // Avoid multi-step promotion.
950ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines      if (NextStep.first == TypePromoteInteger)
951ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines        return NextStep;
952ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines      // Return rounded integer type.
953ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines      return LegalizeKind(TypePromoteInteger, NVT);
954ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines    }
955ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines
956ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines    return LegalizeKind(TypeExpandInteger,
957ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines                        EVT::getIntegerVT(Context, VT.getSizeInBits() / 2));
958ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines  }
959ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines
960ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines  // Handle vector types.
961ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines  unsigned NumElts = VT.getVectorNumElements();
962ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines  EVT EltVT = VT.getVectorElementType();
963ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines
964ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines  // Vectors with only one element are always scalarized.
965ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines  if (NumElts == 1)
966ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines    return LegalizeKind(TypeScalarizeVector, EltVT);
967ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines
968ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines  // Try to widen vector elements until the element type is a power of two and
969ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines  // promote it to a legal type later on, for example:
970ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines  // <3 x i8> -> <4 x i8> -> <4 x i32>
971ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines  if (EltVT.isInteger()) {
972ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines    // Vectors with a number of elements that is not a power of two are always
973ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines    // widened, for example <3 x i8> -> <4 x i8>.
974ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines    if (!VT.isPow2VectorType()) {
975ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines      NumElts = (unsigned)NextPowerOf2(NumElts);
976ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines      EVT NVT = EVT::getVectorVT(Context, EltVT, NumElts);
977ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines      return LegalizeKind(TypeWidenVector, NVT);
978ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines    }
979ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines
980ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines    // Examine the element type.
981ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines    LegalizeKind LK = getTypeConversion(Context, EltVT);
982ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines
983ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines    // If type is to be expanded, split the vector.
984ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines    //  <4 x i140> -> <2 x i140>
985ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines    if (LK.first == TypeExpandInteger)
986ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines      return LegalizeKind(TypeSplitVector,
987ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines                          EVT::getVectorVT(Context, EltVT, NumElts / 2));
988ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines
989ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines    // Promote the integer element types until a legal vector type is found
990ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines    // or until the element integer type is too big. If a legal type was not
991ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines    // found, fallback to the usual mechanism of widening/splitting the
992ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines    // vector.
993ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines    EVT OldEltVT = EltVT;
994ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines    while (1) {
995ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines      // Increase the bitwidth of the element to the next pow-of-two
996ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines      // (which is greater than 8 bits).
997ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines      EltVT = EVT::getIntegerVT(Context, 1 + EltVT.getSizeInBits())
998ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines                  .getRoundIntegerType(Context);
999ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines
1000ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines      // Stop trying when getting a non-simple element type.
1001ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines      // Note that vector elements may be greater than legal vector element
1002ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines      // types. Example: X86 XMM registers hold 64bit element on 32bit
1003ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines      // systems.
1004ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines      if (!EltVT.isSimple())
1005ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines        break;
1006ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines
1007ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines      // Build a new vector type and check if it is legal.
1008ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines      MVT NVT = MVT::getVectorVT(EltVT.getSimpleVT(), NumElts);
1009ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines      // Found a legal promoted vector type.
1010ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines      if (NVT != MVT() && ValueTypeActions.getTypeAction(NVT) == TypeLegal)
1011ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines        return LegalizeKind(TypePromoteInteger,
1012ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines                            EVT::getVectorVT(Context, EltVT, NumElts));
1013ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines    }
1014ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines
1015ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines    // Reset the type to the unexpanded type if we did not find a legal vector
1016ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines    // type with a promoted vector element type.
1017ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines    EltVT = OldEltVT;
1018ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines  }
1019ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines
1020ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines  // Try to widen the vector until a legal type is found.
1021ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines  // If there is no wider legal type, split the vector.
1022ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines  while (1) {
1023ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines    // Round up to the next power of 2.
1024ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines    NumElts = (unsigned)NextPowerOf2(NumElts);
1025ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines
1026ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines    // If there is no simple vector type with this many elements then there
1027ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines    // cannot be a larger legal vector type.  Note that this assumes that
1028ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines    // there are no skipped intermediate vector types in the simple types.
1029ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines    if (!EltVT.isSimple())
1030ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines      break;
1031ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines    MVT LargerVector = MVT::getVectorVT(EltVT.getSimpleVT(), NumElts);
1032ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines    if (LargerVector == MVT())
1033ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines      break;
1034ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines
1035ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines    // If this type is legal then widen the vector.
1036ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines    if (ValueTypeActions.getTypeAction(LargerVector) == TypeLegal)
1037ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines      return LegalizeKind(TypeWidenVector, LargerVector);
1038ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines  }
1039ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines
1040ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines  // Widen odd vectors to next power of two.
1041ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines  if (!VT.isPow2VectorType()) {
1042ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines    EVT NVT = VT.getPow2VectorType(Context);
1043ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines    return LegalizeKind(TypeWidenVector, NVT);
1044ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines  }
1045ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines
1046ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines  // Vectors with illegal element types are expanded.
1047ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines  EVT NVT = EVT::getVectorVT(Context, EltVT, VT.getVectorNumElements() / 2);
1048ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines  return LegalizeKind(TypeSplitVector, NVT);
1049ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines}
105069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
105169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramerstatic unsigned getVectorTypeBreakdownMVT(MVT VT, MVT &IntermediateVT,
105269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer                                          unsigned &NumIntermediates,
105369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer                                          MVT &RegisterVT,
105469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer                                          TargetLoweringBase *TLI) {
105569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // Figure out the right, legal destination reg to copy into.
105669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  unsigned NumElts = VT.getVectorNumElements();
105769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  MVT EltTy = VT.getVectorElementType();
105869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
105969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  unsigned NumVectorRegs = 1;
106069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
106169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // FIXME: We don't support non-power-of-2-sized vectors for now.  Ideally we
106269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // could break down into LHS/RHS like LegalizeDAG does.
106369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  if (!isPowerOf2_32(NumElts)) {
106469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    NumVectorRegs = NumElts;
106569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    NumElts = 1;
106669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  }
106769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
106869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // Divide the input until we get to a supported size.  This will always
106969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // end with a scalar if the target doesn't support vectors.
107069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  while (NumElts > 1 && !TLI->isTypeLegal(MVT::getVectorVT(EltTy, NumElts))) {
107169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    NumElts >>= 1;
107269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    NumVectorRegs <<= 1;
107369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  }
107469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
107569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  NumIntermediates = NumVectorRegs;
107669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
107769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  MVT NewVT = MVT::getVectorVT(EltTy, NumElts);
107869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  if (!TLI->isTypeLegal(NewVT))
107969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    NewVT = EltTy;
108069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  IntermediateVT = NewVT;
108169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
108269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  unsigned NewVTSize = NewVT.getSizeInBits();
108369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
108469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // Convert sizes such as i33 to i64.
108569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  if (!isPowerOf2_32(NewVTSize))
108669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    NewVTSize = NextPowerOf2(NewVTSize);
108769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
108869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  MVT DestVT = TLI->getRegisterType(NewVT);
108969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  RegisterVT = DestVT;
109069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  if (EVT(DestVT).bitsLT(NewVT))    // Value is expanded, e.g. i64 -> i16.
109169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    return NumVectorRegs*(NewVTSize/DestVT.getSizeInBits());
109269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
109369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // Otherwise, promotion or legal types use the same number of registers as
109469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // the vector decimated to the appropriate level.
109569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  return NumVectorRegs;
109669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer}
109769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
109869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// isLegalRC - Return true if the value types that can be represented by the
109969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// specified register class are all legal.
110069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramerbool TargetLoweringBase::isLegalRC(const TargetRegisterClass *RC) const {
110169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  for (TargetRegisterClass::vt_iterator I = RC->vt_begin(), E = RC->vt_end();
110269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer       I != E; ++I) {
110369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (isTypeLegal(*I))
110469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return true;
110569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  }
110669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  return false;
110769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer}
110869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
110936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines/// Replace/modify any TargetFrameIndex operands with a targte-dependent
111036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines/// sequence of memory operands that is recognized by PrologEpilogInserter.
111136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen HinesMachineBasicBlock*
111236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen HinesTargetLoweringBase::emitPatchPoint(MachineInstr *MI,
111336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                                   MachineBasicBlock *MBB) const {
111436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  MachineFunction &MF = *MI->getParent()->getParent();
111536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
111636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // MI changes inside this loop as we grow operands.
111736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  for(unsigned OperIdx = 0; OperIdx != MI->getNumOperands(); ++OperIdx) {
111836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    MachineOperand &MO = MI->getOperand(OperIdx);
111936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    if (!MO.isFI())
112036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines      continue;
112136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
112236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    // foldMemoryOperand builds a new MI after replacing a single FI operand
112336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    // with the canonical set of five x86 addressing-mode operands.
112436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    int FI = MO.getIndex();
112536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    MachineInstrBuilder MIB = BuildMI(MF, MI->getDebugLoc(), MI->getDesc());
112636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
112736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    // Copy operands before the frame-index.
112836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    for (unsigned i = 0; i < OperIdx; ++i)
112936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines      MIB.addOperand(MI->getOperand(i));
113036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    // Add frame index operands: direct-mem-ref tag, #FI, offset.
113136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    MIB.addImm(StackMaps::DirectMemRefOp);
113236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    MIB.addOperand(MI->getOperand(OperIdx));
113336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    MIB.addImm(0);
113436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    // Copy the operands after the frame index.
113536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    for (unsigned i = OperIdx + 1; i != MI->getNumOperands(); ++i)
113636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines      MIB.addOperand(MI->getOperand(i));
113736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
113836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    // Inherit previous memory operands.
113936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    MIB->setMemRefs(MI->memoperands_begin(), MI->memoperands_end());
114036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    assert(MIB->mayLoad() && "Folded a stackmap use to a non-load!");
114136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
114236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    // Add a new memory operand for this FI.
114336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    const MachineFrameInfo &MFI = *MF.getFrameInfo();
114436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    assert(MFI.getObjectOffset(FI) != -1);
1145ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines
1146ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines    unsigned Flags = MachineMemOperand::MOLoad;
1147ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines    if (MI->getOpcode() == TargetOpcode::STATEPOINT) {
1148ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines      Flags |= MachineMemOperand::MOStore;
1149ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines      Flags |= MachineMemOperand::MOVolatile;
1150ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines    }
115137ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines    MachineMemOperand *MMO = MF.getMachineMemOperand(
1152ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines        MachinePointerInfo::getFixedStack(FI), Flags,
1153ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines        TM.getDataLayout()->getPointerSize(), MFI.getObjectAlignment(FI));
115436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    MIB->addMemOperand(MF, MMO);
115536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
115636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    // Replace the instruction and update the operand index.
115736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    MBB->insert(MachineBasicBlock::iterator(MI), MIB);
115836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    OperIdx += (MIB->getNumOperands() - MI->getNumOperands()) - 1;
115936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    MI->eraseFromParent();
116036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    MI = MIB;
116136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  }
116236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  return MBB;
116336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines}
116436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
116569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// findRepresentativeClass - Return the largest legal super-reg register class
116669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// of the register class for the specified type and its associated "cost".
11674c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar// This function is in TargetLowering because it uses RegClassForVT which would
11684c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar// need to be moved to TargetRegisterInfo and would necessitate moving
11694c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar// isTypeLegal over as well - a massive change that would just require
11704c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar// TargetLowering having a TargetRegisterInfo class member that it would use.
1171ebe69fe11e48d322045d5949c83283927a0d790bStephen Hinesstd::pair<const TargetRegisterClass *, uint8_t>
1172ebe69fe11e48d322045d5949c83283927a0d790bStephen HinesTargetLoweringBase::findRepresentativeClass(const TargetRegisterInfo *TRI,
1173ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines                                            MVT VT) const {
117469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  const TargetRegisterClass *RC = RegClassForVT[VT.SimpleTy];
117569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  if (!RC)
117669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    return std::make_pair(RC, 0);
117769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
117869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // Compute the set of all super-register classes.
117969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  BitVector SuperRegRC(TRI->getNumRegClasses());
118069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  for (SuperRegClassIterator RCI(RC, TRI); RCI.isValid(); ++RCI)
118169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    SuperRegRC.setBitsInMask(RCI.getMask());
118269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
118369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // Find the first legal register class with the largest spill size.
118469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  const TargetRegisterClass *BestRC = RC;
118569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  for (int i = SuperRegRC.find_first(); i >= 0; i = SuperRegRC.find_next(i)) {
118669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    const TargetRegisterClass *SuperRC = TRI->getRegClass(i);
118769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    // We want the largest possible spill size.
118869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (SuperRC->getSize() <= BestRC->getSize())
118969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      continue;
119069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (!isLegalRC(SuperRC))
119169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      continue;
119269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    BestRC = SuperRC;
119369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  }
119469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  return std::make_pair(BestRC, 1);
119569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer}
119669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
119769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// computeRegisterProperties - Once all of the register classes are added,
119869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// this allows us to compute derived properties we expose.
1199ebe69fe11e48d322045d5949c83283927a0d790bStephen Hinesvoid TargetLoweringBase::computeRegisterProperties(
1200ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines    const TargetRegisterInfo *TRI) {
120137ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  static_assert(MVT::LAST_VALUETYPE <= MVT::MAX_ALLOWED_VALUETYPE,
120237ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines                "Too many value types for ValueTypeActions to hold!");
120369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
120469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // Everything defaults to needing one register.
120569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  for (unsigned i = 0; i != MVT::LAST_VALUETYPE; ++i) {
120669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    NumRegistersForVT[i] = 1;
120769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    RegisterTypeForVT[i] = TransformToType[i] = (MVT::SimpleValueType)i;
120869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  }
120969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // ...except isVoid, which doesn't need any registers.
121069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  NumRegistersForVT[MVT::isVoid] = 0;
121169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
121269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // Find the largest integer register class.
121369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  unsigned LargestIntReg = MVT::LAST_INTEGER_VALUETYPE;
1214dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  for (; RegClassForVT[LargestIntReg] == nullptr; --LargestIntReg)
121569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    assert(LargestIntReg != MVT::i1 && "No integer registers defined!");
121669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
121769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // Every integer value type larger than this largest register takes twice as
121869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // many registers to represent as the previous ValueType.
121969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  for (unsigned ExpandedReg = LargestIntReg + 1;
122069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer       ExpandedReg <= MVT::LAST_INTEGER_VALUETYPE; ++ExpandedReg) {
122169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    NumRegistersForVT[ExpandedReg] = 2*NumRegistersForVT[ExpandedReg-1];
122269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    RegisterTypeForVT[ExpandedReg] = (MVT::SimpleValueType)LargestIntReg;
122369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    TransformToType[ExpandedReg] = (MVT::SimpleValueType)(ExpandedReg - 1);
122469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    ValueTypeActions.setTypeAction((MVT::SimpleValueType)ExpandedReg,
122569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer                                   TypeExpandInteger);
122669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  }
122769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
122869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // Inspect all of the ValueType's smaller than the largest integer
122969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // register to see which ones need promotion.
123069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  unsigned LegalIntReg = LargestIntReg;
123169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  for (unsigned IntReg = LargestIntReg - 1;
123269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer       IntReg >= (unsigned)MVT::i1; --IntReg) {
123369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    MVT IVT = (MVT::SimpleValueType)IntReg;
123469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (isTypeLegal(IVT)) {
123569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      LegalIntReg = IntReg;
123669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    } else {
123769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      RegisterTypeForVT[IntReg] = TransformToType[IntReg] =
123869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer        (const MVT::SimpleValueType)LegalIntReg;
123969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      ValueTypeActions.setTypeAction(IVT, TypePromoteInteger);
124069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    }
124169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  }
124269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
124369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // ppcf128 type is really two f64's.
124469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  if (!isTypeLegal(MVT::ppcf128)) {
124569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    NumRegistersForVT[MVT::ppcf128] = 2*NumRegistersForVT[MVT::f64];
124669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    RegisterTypeForVT[MVT::ppcf128] = MVT::f64;
124769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    TransformToType[MVT::ppcf128] = MVT::f64;
124869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    ValueTypeActions.setTypeAction(MVT::ppcf128, TypeExpandFloat);
124969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  }
125069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
1251c3c3810f514af7e08f84ef76b0c304ec264ee021Akira Hatanaka  // Decide how to handle f128. If the target does not have native f128 support,
1252c3c3810f514af7e08f84ef76b0c304ec264ee021Akira Hatanaka  // expand it to i128 and we will be generating soft float library calls.
1253c3c3810f514af7e08f84ef76b0c304ec264ee021Akira Hatanaka  if (!isTypeLegal(MVT::f128)) {
1254c3c3810f514af7e08f84ef76b0c304ec264ee021Akira Hatanaka    NumRegistersForVT[MVT::f128] = NumRegistersForVT[MVT::i128];
1255c3c3810f514af7e08f84ef76b0c304ec264ee021Akira Hatanaka    RegisterTypeForVT[MVT::f128] = RegisterTypeForVT[MVT::i128];
1256c3c3810f514af7e08f84ef76b0c304ec264ee021Akira Hatanaka    TransformToType[MVT::f128] = MVT::i128;
1257c3c3810f514af7e08f84ef76b0c304ec264ee021Akira Hatanaka    ValueTypeActions.setTypeAction(MVT::f128, TypeSoftenFloat);
1258c3c3810f514af7e08f84ef76b0c304ec264ee021Akira Hatanaka  }
1259c3c3810f514af7e08f84ef76b0c304ec264ee021Akira Hatanaka
126069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // Decide how to handle f64. If the target does not have native f64 support,
126169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // expand it to i64 and we will be generating soft float library calls.
126269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  if (!isTypeLegal(MVT::f64)) {
126369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    NumRegistersForVT[MVT::f64] = NumRegistersForVT[MVT::i64];
126469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    RegisterTypeForVT[MVT::f64] = RegisterTypeForVT[MVT::i64];
126569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    TransformToType[MVT::f64] = MVT::i64;
126669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    ValueTypeActions.setTypeAction(MVT::f64, TypeSoftenFloat);
126769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  }
126869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
12690c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar  // Decide how to handle f32. If the target does not have native f32 support,
12700c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar  // expand it to i32 and we will be generating soft float library calls.
127169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  if (!isTypeLegal(MVT::f32)) {
12720c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar    NumRegistersForVT[MVT::f32] = NumRegistersForVT[MVT::i32];
12730c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar    RegisterTypeForVT[MVT::f32] = RegisterTypeForVT[MVT::i32];
12740c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar    TransformToType[MVT::f32] = MVT::i32;
12750c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar    ValueTypeActions.setTypeAction(MVT::f32, TypeSoftenFloat);
127669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  }
127769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
127837ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  if (!isTypeLegal(MVT::f16)) {
1279a18e6af1712fd41c4a705a19ad71f6e9ac7a4e68Pirama Arumuga Nainar    // If the target has native f32 support, promote f16 operations to f32.  If
1280a18e6af1712fd41c4a705a19ad71f6e9ac7a4e68Pirama Arumuga Nainar    // f32 is not supported, generate soft float library calls.
1281a18e6af1712fd41c4a705a19ad71f6e9ac7a4e68Pirama Arumuga Nainar    if (isTypeLegal(MVT::f32)) {
1282a18e6af1712fd41c4a705a19ad71f6e9ac7a4e68Pirama Arumuga Nainar      NumRegistersForVT[MVT::f16] = NumRegistersForVT[MVT::f32];
1283a18e6af1712fd41c4a705a19ad71f6e9ac7a4e68Pirama Arumuga Nainar      RegisterTypeForVT[MVT::f16] = RegisterTypeForVT[MVT::f32];
1284a18e6af1712fd41c4a705a19ad71f6e9ac7a4e68Pirama Arumuga Nainar      TransformToType[MVT::f16] = MVT::f32;
1285a18e6af1712fd41c4a705a19ad71f6e9ac7a4e68Pirama Arumuga Nainar      ValueTypeActions.setTypeAction(MVT::f16, TypePromoteFloat);
1286a18e6af1712fd41c4a705a19ad71f6e9ac7a4e68Pirama Arumuga Nainar    } else {
1287a18e6af1712fd41c4a705a19ad71f6e9ac7a4e68Pirama Arumuga Nainar      NumRegistersForVT[MVT::f16] = NumRegistersForVT[MVT::i16];
1288a18e6af1712fd41c4a705a19ad71f6e9ac7a4e68Pirama Arumuga Nainar      RegisterTypeForVT[MVT::f16] = RegisterTypeForVT[MVT::i16];
1289a18e6af1712fd41c4a705a19ad71f6e9ac7a4e68Pirama Arumuga Nainar      TransformToType[MVT::f16] = MVT::i16;
1290a18e6af1712fd41c4a705a19ad71f6e9ac7a4e68Pirama Arumuga Nainar      ValueTypeActions.setTypeAction(MVT::f16, TypeSoftenFloat);
1291a18e6af1712fd41c4a705a19ad71f6e9ac7a4e68Pirama Arumuga Nainar    }
129237ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  }
129337ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines
129469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // Loop over all of the vector value types to see which need transformations.
129569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  for (unsigned i = MVT::FIRST_VECTOR_VALUETYPE;
129669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer       i <= (unsigned)MVT::LAST_VECTOR_VALUETYPE; ++i) {
1297c6a4f5e819217e1e12c458aed8e7b122e23a3a58Stephen Hines    MVT VT = (MVT::SimpleValueType) i;
1298c6a4f5e819217e1e12c458aed8e7b122e23a3a58Stephen Hines    if (isTypeLegal(VT))
1299c6a4f5e819217e1e12c458aed8e7b122e23a3a58Stephen Hines      continue;
130069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
130169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    MVT EltVT = VT.getVectorElementType();
130269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    unsigned NElts = VT.getVectorNumElements();
1303c6a4f5e819217e1e12c458aed8e7b122e23a3a58Stephen Hines    bool IsLegalWiderType = false;
1304c6a4f5e819217e1e12c458aed8e7b122e23a3a58Stephen Hines    LegalizeTypeAction PreferredAction = getPreferredVectorAction(VT);
1305c6a4f5e819217e1e12c458aed8e7b122e23a3a58Stephen Hines    switch (PreferredAction) {
1306c6a4f5e819217e1e12c458aed8e7b122e23a3a58Stephen Hines    case TypePromoteInteger: {
1307c6a4f5e819217e1e12c458aed8e7b122e23a3a58Stephen Hines      // Try to promote the elements of integer vectors. If no legal
1308c6a4f5e819217e1e12c458aed8e7b122e23a3a58Stephen Hines      // promotion was found, fall through to the widen-vector method.
1309c6a4f5e819217e1e12c458aed8e7b122e23a3a58Stephen Hines      for (unsigned nVT = i + 1; nVT <= MVT::LAST_VECTOR_VALUETYPE; ++nVT) {
1310c6a4f5e819217e1e12c458aed8e7b122e23a3a58Stephen Hines        MVT SVT = (MVT::SimpleValueType) nVT;
131169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer        // Promote vectors of integers to vectors with the same number
131269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer        // of elements, with a wider element type.
131369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer        if (SVT.getVectorElementType().getSizeInBits() > EltVT.getSizeInBits()
1314c6a4f5e819217e1e12c458aed8e7b122e23a3a58Stephen Hines            && SVT.getVectorNumElements() == NElts && isTypeLegal(SVT)
1315c6a4f5e819217e1e12c458aed8e7b122e23a3a58Stephen Hines            && SVT.getScalarType().isInteger()) {
131669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer          TransformToType[i] = SVT;
131769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer          RegisterTypeForVT[i] = SVT;
131869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer          NumRegistersForVT[i] = 1;
131969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer          ValueTypeActions.setTypeAction(VT, TypePromoteInteger);
132069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer          IsLegalWiderType = true;
132169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer          break;
132269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer        }
132369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      }
1324c6a4f5e819217e1e12c458aed8e7b122e23a3a58Stephen Hines      if (IsLegalWiderType)
1325c6a4f5e819217e1e12c458aed8e7b122e23a3a58Stephen Hines        break;
1326c6a4f5e819217e1e12c458aed8e7b122e23a3a58Stephen Hines    }
1327c6a4f5e819217e1e12c458aed8e7b122e23a3a58Stephen Hines    case TypeWidenVector: {
132869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      // Try to widen the vector.
1329c6a4f5e819217e1e12c458aed8e7b122e23a3a58Stephen Hines      for (unsigned nVT = i + 1; nVT <= MVT::LAST_VECTOR_VALUETYPE; ++nVT) {
1330c6a4f5e819217e1e12c458aed8e7b122e23a3a58Stephen Hines        MVT SVT = (MVT::SimpleValueType) nVT;
1331c6a4f5e819217e1e12c458aed8e7b122e23a3a58Stephen Hines        if (SVT.getVectorElementType() == EltVT
1332c6a4f5e819217e1e12c458aed8e7b122e23a3a58Stephen Hines            && SVT.getVectorNumElements() > NElts && isTypeLegal(SVT)) {
133369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer          TransformToType[i] = SVT;
133469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer          RegisterTypeForVT[i] = SVT;
133569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer          NumRegistersForVT[i] = 1;
133669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer          ValueTypeActions.setTypeAction(VT, TypeWidenVector);
133769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer          IsLegalWiderType = true;
133869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer          break;
133969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer        }
134069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      }
1341c6a4f5e819217e1e12c458aed8e7b122e23a3a58Stephen Hines      if (IsLegalWiderType)
1342c6a4f5e819217e1e12c458aed8e7b122e23a3a58Stephen Hines        break;
134369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    }
1344c6a4f5e819217e1e12c458aed8e7b122e23a3a58Stephen Hines    case TypeSplitVector:
1345c6a4f5e819217e1e12c458aed8e7b122e23a3a58Stephen Hines    case TypeScalarizeVector: {
1346c6a4f5e819217e1e12c458aed8e7b122e23a3a58Stephen Hines      MVT IntermediateVT;
1347c6a4f5e819217e1e12c458aed8e7b122e23a3a58Stephen Hines      MVT RegisterVT;
1348c6a4f5e819217e1e12c458aed8e7b122e23a3a58Stephen Hines      unsigned NumIntermediates;
1349c6a4f5e819217e1e12c458aed8e7b122e23a3a58Stephen Hines      NumRegistersForVT[i] = getVectorTypeBreakdownMVT(VT, IntermediateVT,
1350c6a4f5e819217e1e12c458aed8e7b122e23a3a58Stephen Hines          NumIntermediates, RegisterVT, this);
1351c6a4f5e819217e1e12c458aed8e7b122e23a3a58Stephen Hines      RegisterTypeForVT[i] = RegisterVT;
1352c6a4f5e819217e1e12c458aed8e7b122e23a3a58Stephen Hines
1353c6a4f5e819217e1e12c458aed8e7b122e23a3a58Stephen Hines      MVT NVT = VT.getPow2VectorType();
1354c6a4f5e819217e1e12c458aed8e7b122e23a3a58Stephen Hines      if (NVT == VT) {
1355c6a4f5e819217e1e12c458aed8e7b122e23a3a58Stephen Hines        // Type is already a power of 2.  The default action is to split.
1356c6a4f5e819217e1e12c458aed8e7b122e23a3a58Stephen Hines        TransformToType[i] = MVT::Other;
1357c6a4f5e819217e1e12c458aed8e7b122e23a3a58Stephen Hines        if (PreferredAction == TypeScalarizeVector)
1358c6a4f5e819217e1e12c458aed8e7b122e23a3a58Stephen Hines          ValueTypeActions.setTypeAction(VT, TypeScalarizeVector);
135937ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines        else if (PreferredAction == TypeSplitVector)
1360c6a4f5e819217e1e12c458aed8e7b122e23a3a58Stephen Hines          ValueTypeActions.setTypeAction(VT, TypeSplitVector);
136137ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines        else
136237ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines          // Set type action according to the number of elements.
136337ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines          ValueTypeActions.setTypeAction(VT, NElts == 1 ? TypeScalarizeVector
136437ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines                                                        : TypeSplitVector);
1365c6a4f5e819217e1e12c458aed8e7b122e23a3a58Stephen Hines      } else {
1366c6a4f5e819217e1e12c458aed8e7b122e23a3a58Stephen Hines        TransformToType[i] = NVT;
1367c6a4f5e819217e1e12c458aed8e7b122e23a3a58Stephen Hines        ValueTypeActions.setTypeAction(VT, TypeWidenVector);
1368c6a4f5e819217e1e12c458aed8e7b122e23a3a58Stephen Hines      }
1369c6a4f5e819217e1e12c458aed8e7b122e23a3a58Stephen Hines      break;
1370c6a4f5e819217e1e12c458aed8e7b122e23a3a58Stephen Hines    }
1371c6a4f5e819217e1e12c458aed8e7b122e23a3a58Stephen Hines    default:
1372c6a4f5e819217e1e12c458aed8e7b122e23a3a58Stephen Hines      llvm_unreachable("Unknown vector legalization action!");
137369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    }
137469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  }
137569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
137669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // Determine the 'representative' register class for each value type.
137769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // An representative register class is the largest (meaning one which is
137869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // not a sub-register class / subreg register class) legal register class for
137969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // a group of value types. For example, on i386, i8, i16, and i32
138069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // representative would be GR32; while on x86_64 it's GR64.
138169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  for (unsigned i = 0; i != MVT::LAST_VALUETYPE; ++i) {
138269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    const TargetRegisterClass* RRC;
138369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    uint8_t Cost;
1384ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines    std::tie(RRC, Cost) = findRepresentativeClass(TRI, (MVT::SimpleValueType)i);
138569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    RepRegClassForVT[i] = RRC;
138669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    RepRegClassCostForVT[i] = Cost;
138769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  }
138869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer}
138969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
1390225ed7069caae9ece32d8bd3d15c6e41e21cc04bMatt ArsenaultEVT TargetLoweringBase::getSetCCResultType(LLVMContext &, EVT VT) const {
139169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  assert(!VT.isVector() && "No default SetCC type for vectors!");
139269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  return getPointerTy(0).SimpleTy;
139369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer}
139469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
139569e42dbd006c0afb732067ece7327988b1e24c01Benjamin KramerMVT::SimpleValueType TargetLoweringBase::getCmpLibcallReturnType() const {
139669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  return MVT::i32; // return the default value
139769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer}
139869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
139969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// getVectorTypeBreakdown - Vector types are broken down into some number of
140069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// legal first class types.  For example, MVT::v8f32 maps to 2 MVT::v4f32
140169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// with Altivec or SSE1, or 8 promoted MVT::f64 values with the X86 FP stack.
140269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// Similarly, MVT::v2i64 turns into 4 MVT::i32 values with both PPC and X86.
140369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer///
140469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// This method returns the number of registers needed, and the VT for each
140569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// register.  It also returns the VT and quantity of the intermediate values
140669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// before they are promoted/expanded.
140769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer///
140869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramerunsigned TargetLoweringBase::getVectorTypeBreakdown(LLVMContext &Context, EVT VT,
140969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer                                                EVT &IntermediateVT,
141069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer                                                unsigned &NumIntermediates,
141169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer                                                MVT &RegisterVT) const {
141269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  unsigned NumElts = VT.getVectorNumElements();
141369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
141469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // If there is a wider vector type with the same element type as this one,
141569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // or a promoted vector type that has the same number of elements which
141669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // are wider, then we should convert to that legal vector type.
141769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // This handles things like <2 x float> -> <4 x float> and
141869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // <4 x i1> -> <4 x i32>.
141969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  LegalizeTypeAction TA = getTypeAction(Context, VT);
142069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  if (NumElts != 1 && (TA == TypeWidenVector || TA == TypePromoteInteger)) {
142169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    EVT RegisterEVT = getTypeToTransformTo(Context, VT);
142269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (isTypeLegal(RegisterEVT)) {
142369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      IntermediateVT = RegisterEVT;
142469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      RegisterVT = RegisterEVT.getSimpleVT();
142569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      NumIntermediates = 1;
142669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return 1;
142769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    }
142869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  }
142969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
143069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // Figure out the right, legal destination reg to copy into.
143169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  EVT EltTy = VT.getVectorElementType();
143269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
143369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  unsigned NumVectorRegs = 1;
143469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
143569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // FIXME: We don't support non-power-of-2-sized vectors for now.  Ideally we
143669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // could break down into LHS/RHS like LegalizeDAG does.
143769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  if (!isPowerOf2_32(NumElts)) {
143869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    NumVectorRegs = NumElts;
143969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    NumElts = 1;
144069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  }
144169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
144269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // Divide the input until we get to a supported size.  This will always
144369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // end with a scalar if the target doesn't support vectors.
144469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  while (NumElts > 1 && !isTypeLegal(
144569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer                                   EVT::getVectorVT(Context, EltTy, NumElts))) {
144669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    NumElts >>= 1;
144769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    NumVectorRegs <<= 1;
144869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  }
144969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
145069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  NumIntermediates = NumVectorRegs;
145169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
145269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  EVT NewVT = EVT::getVectorVT(Context, EltTy, NumElts);
145369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  if (!isTypeLegal(NewVT))
145469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    NewVT = EltTy;
145569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  IntermediateVT = NewVT;
145669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
145769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  MVT DestVT = getRegisterType(Context, NewVT);
145869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  RegisterVT = DestVT;
145969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  unsigned NewVTSize = NewVT.getSizeInBits();
146069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
146169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // Convert sizes such as i33 to i64.
146269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  if (!isPowerOf2_32(NewVTSize))
146369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    NewVTSize = NextPowerOf2(NewVTSize);
146469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
146569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  if (EVT(DestVT).bitsLT(NewVT))   // Value is expanded, e.g. i64 -> i16.
146669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    return NumVectorRegs*(NewVTSize/DestVT.getSizeInBits());
146769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
146869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // Otherwise, promotion or legal types use the same number of registers as
146969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // the vector decimated to the appropriate level.
147069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  return NumVectorRegs;
147169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer}
147269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
147369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// Get the EVTs and ArgFlags collections that represent the legalized return
147469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// type of the given function.  This does not require a DAG or a return value,
147569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// and is suitable for use before any DAGs for the function are constructed.
147669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// TODO: Move this out of TargetLowering.cpp.
147769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramervoid llvm::GetReturnInfo(Type* ReturnType, AttributeSet attr,
147869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer                         SmallVectorImpl<ISD::OutputArg> &Outs,
147969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer                         const TargetLowering &TLI) {
148069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  SmallVector<EVT, 4> ValueVTs;
148169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  ComputeValueVTs(TLI, ReturnType, ValueVTs);
148269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  unsigned NumValues = ValueVTs.size();
148369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  if (NumValues == 0) return;
148469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
148569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  for (unsigned j = 0, f = NumValues; j != f; ++j) {
148669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    EVT VT = ValueVTs[j];
148769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    ISD::NodeType ExtendKind = ISD::ANY_EXTEND;
148869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
148969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (attr.hasAttribute(AttributeSet::ReturnIndex, Attribute::SExt))
149069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      ExtendKind = ISD::SIGN_EXTEND;
149169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    else if (attr.hasAttribute(AttributeSet::ReturnIndex, Attribute::ZExt))
149269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      ExtendKind = ISD::ZERO_EXTEND;
149369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
149469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    // FIXME: C calling convention requires the return type to be promoted to
149569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    // at least 32-bit. But this is not necessary for non-C calling
149669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    // conventions. The frontend should mark functions whose return values
149769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    // require promoting with signext or zeroext attributes.
149869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (ExtendKind != ISD::ANY_EXTEND && VT.isInteger()) {
149969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      MVT MinVT = TLI.getRegisterType(ReturnType->getContext(), MVT::i32);
150069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      if (VT.bitsLT(MinVT))
150169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer        VT = MinVT;
150269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    }
150369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
150469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    unsigned NumParts = TLI.getNumRegisters(ReturnType->getContext(), VT);
150569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    MVT PartVT = TLI.getRegisterType(ReturnType->getContext(), VT);
150669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
150769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    // 'inreg' on function refers to return value
150869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    ISD::ArgFlagsTy Flags = ISD::ArgFlagsTy();
150969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (attr.hasAttribute(AttributeSet::ReturnIndex, Attribute::InReg))
151069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      Flags.setInReg();
151169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
151269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    // Propagate extension type if any
151369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (attr.hasAttribute(AttributeSet::ReturnIndex, Attribute::SExt))
151469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      Flags.setSExt();
151569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    else if (attr.hasAttribute(AttributeSet::ReturnIndex, Attribute::ZExt))
151669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      Flags.setZExt();
151769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
151869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    for (unsigned i = 0; i < NumParts; ++i)
1519d0716b064744598ba7df33b8b47de0375c450570Tom Stellard      Outs.push_back(ISD::OutputArg(Flags, PartVT, VT, /*isFixed=*/true, 0, 0));
152069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  }
152169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer}
152269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
152369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// getByValTypeAlignment - Return the desired alignment for ByVal aggregate
152469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// function arguments in the caller parameter area.  This is the actual
152569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// alignment, not its logarithm.
152669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramerunsigned TargetLoweringBase::getByValTypeAlignment(Type *Ty) const {
15274c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar  return getDataLayout()->getABITypeAlignment(Ty);
152869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer}
152969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
153069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer//===----------------------------------------------------------------------===//
153169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer//  TargetTransformInfo Helpers
153269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer//===----------------------------------------------------------------------===//
153369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
153469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramerint TargetLoweringBase::InstructionOpcodeToISD(unsigned Opcode) const {
153569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  enum InstructionOpcodes {
153669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer#define HANDLE_INST(NUM, OPCODE, CLASS) OPCODE = NUM,
153769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer#define LAST_OTHER_INST(NUM) InstructionOpcodesCount = NUM
153869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer#include "llvm/IR/Instruction.def"
153969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  };
154069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  switch (static_cast<InstructionOpcodes>(Opcode)) {
154169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case Ret:            return 0;
154269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case Br:             return 0;
154369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case Switch:         return 0;
154469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case IndirectBr:     return 0;
154569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case Invoke:         return 0;
154669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case Resume:         return 0;
154769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case Unreachable:    return 0;
154869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case Add:            return ISD::ADD;
154969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case FAdd:           return ISD::FADD;
155069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case Sub:            return ISD::SUB;
155169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case FSub:           return ISD::FSUB;
155269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case Mul:            return ISD::MUL;
155369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case FMul:           return ISD::FMUL;
155469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case UDiv:           return ISD::UDIV;
1555dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  case SDiv:           return ISD::SDIV;
155669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case FDiv:           return ISD::FDIV;
155769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case URem:           return ISD::UREM;
155869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case SRem:           return ISD::SREM;
155969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case FRem:           return ISD::FREM;
156069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case Shl:            return ISD::SHL;
156169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case LShr:           return ISD::SRL;
156269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case AShr:           return ISD::SRA;
156369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case And:            return ISD::AND;
156469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case Or:             return ISD::OR;
156569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case Xor:            return ISD::XOR;
156669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case Alloca:         return 0;
156769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case Load:           return ISD::LOAD;
156869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case Store:          return ISD::STORE;
156969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case GetElementPtr:  return 0;
157069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case Fence:          return 0;
157169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case AtomicCmpXchg:  return 0;
157269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case AtomicRMW:      return 0;
157369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case Trunc:          return ISD::TRUNCATE;
157469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case ZExt:           return ISD::ZERO_EXTEND;
157569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case SExt:           return ISD::SIGN_EXTEND;
157669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case FPToUI:         return ISD::FP_TO_UINT;
157769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case FPToSI:         return ISD::FP_TO_SINT;
157869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case UIToFP:         return ISD::UINT_TO_FP;
157969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case SIToFP:         return ISD::SINT_TO_FP;
158069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case FPTrunc:        return ISD::FP_ROUND;
158169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case FPExt:          return ISD::FP_EXTEND;
158269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case PtrToInt:       return ISD::BITCAST;
158369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case IntToPtr:       return ISD::BITCAST;
158469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case BitCast:        return ISD::BITCAST;
158559d3ae6cdc4316ad338cd848251f33a236ccb36cMatt Arsenault  case AddrSpaceCast:  return ISD::ADDRSPACECAST;
158669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case ICmp:           return ISD::SETCC;
158769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case FCmp:           return ISD::SETCC;
158869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case PHI:            return 0;
158969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case Call:           return 0;
159069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case Select:         return ISD::SELECT;
159169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case UserOp1:        return 0;
159269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case UserOp2:        return 0;
159369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case VAArg:          return 0;
159469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case ExtractElement: return ISD::EXTRACT_VECTOR_ELT;
159569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case InsertElement:  return ISD::INSERT_VECTOR_ELT;
159669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case ShuffleVector:  return ISD::VECTOR_SHUFFLE;
159769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case ExtractValue:   return ISD::MERGE_VALUES;
159869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case InsertValue:    return ISD::MERGE_VALUES;
159969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case LandingPad:     return 0;
160069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  }
160169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
160269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  llvm_unreachable("Unknown instruction type encountered!");
160369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer}
160469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
160569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramerstd::pair<unsigned, MVT>
160669e42dbd006c0afb732067ece7327988b1e24c01Benjamin KramerTargetLoweringBase::getTypeLegalizationCost(Type *Ty) const {
160769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  LLVMContext &C = Ty->getContext();
160869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  EVT MTy = getValueType(Ty);
160969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
161069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  unsigned Cost = 1;
161169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // We keep legalizing the type until we find a legal kind. We assume that
161269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // the only operation that costs anything is the split. After splitting
161369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // we need to handle two types.
161469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  while (true) {
161569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    LegalizeKind LK = getTypeConversion(C, MTy);
161669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
161769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (LK.first == TypeLegal)
161869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return std::make_pair(Cost, MTy.getSimpleVT());
161969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
162069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (LK.first == TypeSplitVector || LK.first == TypeExpandInteger)
162169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      Cost *= 2;
162269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
162369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    // Keep legalizing the type.
162469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    MTy = LK.second;
162569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  }
162669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer}
162769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
162869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer//===----------------------------------------------------------------------===//
162969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer//  Loop Strength Reduction hooks
163069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer//===----------------------------------------------------------------------===//
163169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
163269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// isLegalAddressingMode - Return true if the addressing mode represented
163369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// by AM is legal for this target, for a load/store of the specified type.
163469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramerbool TargetLoweringBase::isLegalAddressingMode(const AddrMode &AM,
16356948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar                                               Type *Ty,
16366948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar                                               unsigned AS) const {
163769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // The default implementation of this implements a conservative RISCy, r+r and
163869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // r+i addr mode.
163969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
164069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // Allows a sign-extended 16-bit immediate field.
164169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  if (AM.BaseOffs <= -(1LL << 16) || AM.BaseOffs >= (1LL << 16)-1)
164269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    return false;
164369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
164469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // No global is ever allowed as a base.
164569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  if (AM.BaseGV)
164669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    return false;
164769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
164869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // Only support r+r,
164969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  switch (AM.Scale) {
165069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case 0:  // "r+i" or just "i", depending on HasBaseReg.
165169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    break;
165269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case 1:
165369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (AM.HasBaseReg && AM.BaseOffs)  // "r+r+i" is not allowed.
165469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return false;
165569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    // Otherwise we have r+r or r+i.
165669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    break;
165769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case 2:
165869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (AM.HasBaseReg || AM.BaseOffs)  // 2*r+r  or  2*r+i is not allowed.
165969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return false;
166069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    // Allow 2*r as r+r.
166169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    break;
166236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  default: // Don't allow n * r
166336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    return false;
166469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  }
166569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
166669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  return true;
166769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer}
1668