TargetLoweringBase.cpp revision 41418d17cced656f91038b2482bc9d173b4974b0
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"
2169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer#include "llvm/CodeGen/MachineJumpTableInfo.h"
2269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer#include "llvm/IR/DataLayout.h"
2369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer#include "llvm/IR/DerivedTypes.h"
2469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer#include "llvm/IR/GlobalVariable.h"
2569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer#include "llvm/MC/MCAsmInfo.h"
2669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer#include "llvm/MC/MCExpr.h"
2769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer#include "llvm/Support/CommandLine.h"
2869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer#include "llvm/Support/ErrorHandling.h"
2969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer#include "llvm/Support/MathExtras.h"
3069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer#include "llvm/Target/TargetLoweringObjectFile.h"
3169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer#include "llvm/Target/TargetMachine.h"
3269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer#include "llvm/Target/TargetRegisterInfo.h"
3369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer#include <cctype>
3469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramerusing namespace llvm;
3569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
3669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// InitLibcallNames - Set default libcall names.
3769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer///
3886cdbc9c29a572d422815f55fd89ff7510d1e3e8Paul Redmondstatic void InitLibcallNames(const char **Names, const TargetMachine &TM) {
3969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SHL_I16] = "__ashlhi3";
4069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SHL_I32] = "__ashlsi3";
4169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SHL_I64] = "__ashldi3";
4269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SHL_I128] = "__ashlti3";
4369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SRL_I16] = "__lshrhi3";
4469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SRL_I32] = "__lshrsi3";
4569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SRL_I64] = "__lshrdi3";
4669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SRL_I128] = "__lshrti3";
4769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SRA_I16] = "__ashrhi3";
4869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SRA_I32] = "__ashrsi3";
4969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SRA_I64] = "__ashrdi3";
5069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SRA_I128] = "__ashrti3";
5169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::MUL_I8] = "__mulqi3";
5269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::MUL_I16] = "__mulhi3";
5369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::MUL_I32] = "__mulsi3";
5469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::MUL_I64] = "__muldi3";
5569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::MUL_I128] = "__multi3";
5669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::MULO_I32] = "__mulosi4";
5769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::MULO_I64] = "__mulodi4";
5869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::MULO_I128] = "__muloti4";
5969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SDIV_I8] = "__divqi3";
6069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SDIV_I16] = "__divhi3";
6169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SDIV_I32] = "__divsi3";
6269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SDIV_I64] = "__divdi3";
6369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SDIV_I128] = "__divti3";
6469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::UDIV_I8] = "__udivqi3";
6569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::UDIV_I16] = "__udivhi3";
6669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::UDIV_I32] = "__udivsi3";
6769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::UDIV_I64] = "__udivdi3";
6869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::UDIV_I128] = "__udivti3";
6969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SREM_I8] = "__modqi3";
7069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SREM_I16] = "__modhi3";
7169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SREM_I32] = "__modsi3";
7269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SREM_I64] = "__moddi3";
7369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SREM_I128] = "__modti3";
7469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::UREM_I8] = "__umodqi3";
7569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::UREM_I16] = "__umodhi3";
7669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::UREM_I32] = "__umodsi3";
7769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::UREM_I64] = "__umoddi3";
7869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::UREM_I128] = "__umodti3";
7969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
8069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // These are generally not available.
8169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SDIVREM_I8] = 0;
8269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SDIVREM_I16] = 0;
8369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SDIVREM_I32] = 0;
8469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SDIVREM_I64] = 0;
8569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SDIVREM_I128] = 0;
8669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::UDIVREM_I8] = 0;
8769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::UDIVREM_I16] = 0;
8869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::UDIVREM_I32] = 0;
8969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::UDIVREM_I64] = 0;
9069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::UDIVREM_I128] = 0;
9169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
9269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::NEG_I32] = "__negsi2";
9369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::NEG_I64] = "__negdi2";
9469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::ADD_F32] = "__addsf3";
9569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::ADD_F64] = "__adddf3";
9669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::ADD_F80] = "__addxf3";
9769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::ADD_F128] = "__addtf3";
9869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::ADD_PPCF128] = "__gcc_qadd";
9969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SUB_F32] = "__subsf3";
10069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SUB_F64] = "__subdf3";
10169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SUB_F80] = "__subxf3";
10269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SUB_F128] = "__subtf3";
10369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SUB_PPCF128] = "__gcc_qsub";
10469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::MUL_F32] = "__mulsf3";
10569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::MUL_F64] = "__muldf3";
10669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::MUL_F80] = "__mulxf3";
10769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::MUL_F128] = "__multf3";
10869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::MUL_PPCF128] = "__gcc_qmul";
10969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::DIV_F32] = "__divsf3";
11069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::DIV_F64] = "__divdf3";
11169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::DIV_F80] = "__divxf3";
11269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::DIV_F128] = "__divtf3";
11369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::DIV_PPCF128] = "__gcc_qdiv";
11469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::REM_F32] = "fmodf";
11569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::REM_F64] = "fmod";
11669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::REM_F80] = "fmodl";
11769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::REM_F128] = "fmodl";
11869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::REM_PPCF128] = "fmodl";
11969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FMA_F32] = "fmaf";
12069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FMA_F64] = "fma";
12169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FMA_F80] = "fmal";
12269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FMA_F128] = "fmal";
12369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FMA_PPCF128] = "fmal";
12469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::POWI_F32] = "__powisf2";
12569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::POWI_F64] = "__powidf2";
12669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::POWI_F80] = "__powixf2";
12769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::POWI_F128] = "__powitf2";
12869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::POWI_PPCF128] = "__powitf2";
12969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SQRT_F32] = "sqrtf";
13069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SQRT_F64] = "sqrt";
13169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SQRT_F80] = "sqrtl";
13269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SQRT_F128] = "sqrtl";
13369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SQRT_PPCF128] = "sqrtl";
13469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::LOG_F32] = "logf";
13569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::LOG_F64] = "log";
13669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::LOG_F80] = "logl";
13769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::LOG_F128] = "logl";
13869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::LOG_PPCF128] = "logl";
13969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::LOG2_F32] = "log2f";
14069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::LOG2_F64] = "log2";
14169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::LOG2_F80] = "log2l";
14269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::LOG2_F128] = "log2l";
14369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::LOG2_PPCF128] = "log2l";
14469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::LOG10_F32] = "log10f";
14569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::LOG10_F64] = "log10";
14669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::LOG10_F80] = "log10l";
14769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::LOG10_F128] = "log10l";
14869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::LOG10_PPCF128] = "log10l";
14969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::EXP_F32] = "expf";
15069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::EXP_F64] = "exp";
15169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::EXP_F80] = "expl";
15269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::EXP_F128] = "expl";
15369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::EXP_PPCF128] = "expl";
15469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::EXP2_F32] = "exp2f";
15569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::EXP2_F64] = "exp2";
15669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::EXP2_F80] = "exp2l";
15769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::EXP2_F128] = "exp2l";
15869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::EXP2_PPCF128] = "exp2l";
15969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SIN_F32] = "sinf";
16069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SIN_F64] = "sin";
16169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SIN_F80] = "sinl";
16269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SIN_F128] = "sinl";
16369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SIN_PPCF128] = "sinl";
16469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::COS_F32] = "cosf";
16569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::COS_F64] = "cos";
16669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::COS_F80] = "cosl";
16769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::COS_F128] = "cosl";
16869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::COS_PPCF128] = "cosl";
16969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::POW_F32] = "powf";
17069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::POW_F64] = "pow";
17169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::POW_F80] = "powl";
17269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::POW_F128] = "powl";
17369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::POW_PPCF128] = "powl";
17469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::CEIL_F32] = "ceilf";
17569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::CEIL_F64] = "ceil";
17669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::CEIL_F80] = "ceill";
17769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::CEIL_F128] = "ceill";
17869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::CEIL_PPCF128] = "ceill";
17969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::TRUNC_F32] = "truncf";
18069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::TRUNC_F64] = "trunc";
18169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::TRUNC_F80] = "truncl";
18269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::TRUNC_F128] = "truncl";
18369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::TRUNC_PPCF128] = "truncl";
18469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::RINT_F32] = "rintf";
18569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::RINT_F64] = "rint";
18669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::RINT_F80] = "rintl";
18769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::RINT_F128] = "rintl";
18869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::RINT_PPCF128] = "rintl";
18969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::NEARBYINT_F32] = "nearbyintf";
19069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::NEARBYINT_F64] = "nearbyint";
19169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::NEARBYINT_F80] = "nearbyintl";
19269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::NEARBYINT_F128] = "nearbyintl";
19369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::NEARBYINT_PPCF128] = "nearbyintl";
19441418d17cced656f91038b2482bc9d173b4974b0Hal Finkel  Names[RTLIB::ROUND_F32] = "roundf";
19541418d17cced656f91038b2482bc9d173b4974b0Hal Finkel  Names[RTLIB::ROUND_F64] = "round";
19641418d17cced656f91038b2482bc9d173b4974b0Hal Finkel  Names[RTLIB::ROUND_F80] = "roundl";
19741418d17cced656f91038b2482bc9d173b4974b0Hal Finkel  Names[RTLIB::ROUND_F128] = "roundl";
19841418d17cced656f91038b2482bc9d173b4974b0Hal Finkel  Names[RTLIB::ROUND_PPCF128] = "roundl";
19969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FLOOR_F32] = "floorf";
20069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FLOOR_F64] = "floor";
20169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FLOOR_F80] = "floorl";
20269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FLOOR_F128] = "floorl";
20369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FLOOR_PPCF128] = "floorl";
20469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::COPYSIGN_F32] = "copysignf";
20569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::COPYSIGN_F64] = "copysign";
20669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::COPYSIGN_F80] = "copysignl";
20769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::COPYSIGN_F128] = "copysignl";
20869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::COPYSIGN_PPCF128] = "copysignl";
20969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPEXT_F64_F128] = "__extenddftf2";
21069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPEXT_F32_F128] = "__extendsftf2";
21169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPEXT_F32_F64] = "__extendsfdf2";
21269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPEXT_F16_F32] = "__gnu_h2f_ieee";
21369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPROUND_F32_F16] = "__gnu_f2h_ieee";
21469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPROUND_F64_F32] = "__truncdfsf2";
21569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPROUND_F80_F32] = "__truncxfsf2";
21669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPROUND_F128_F32] = "__trunctfsf2";
21769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPROUND_PPCF128_F32] = "__trunctfsf2";
21869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPROUND_F80_F64] = "__truncxfdf2";
21969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPROUND_F128_F64] = "__trunctfdf2";
22069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPROUND_PPCF128_F64] = "__trunctfdf2";
22169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPTOSINT_F32_I8] = "__fixsfqi";
22269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPTOSINT_F32_I16] = "__fixsfhi";
22369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPTOSINT_F32_I32] = "__fixsfsi";
22469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPTOSINT_F32_I64] = "__fixsfdi";
22569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPTOSINT_F32_I128] = "__fixsfti";
22669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPTOSINT_F64_I8] = "__fixdfqi";
22769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPTOSINT_F64_I16] = "__fixdfhi";
22869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPTOSINT_F64_I32] = "__fixdfsi";
22969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPTOSINT_F64_I64] = "__fixdfdi";
23069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPTOSINT_F64_I128] = "__fixdfti";
23169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPTOSINT_F80_I32] = "__fixxfsi";
23269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPTOSINT_F80_I64] = "__fixxfdi";
23369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPTOSINT_F80_I128] = "__fixxfti";
23469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPTOSINT_F128_I32] = "__fixtfsi";
23569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPTOSINT_F128_I64] = "__fixtfdi";
23669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPTOSINT_F128_I128] = "__fixtfti";
23769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPTOSINT_PPCF128_I32] = "__fixtfsi";
23869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPTOSINT_PPCF128_I64] = "__fixtfdi";
23969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPTOSINT_PPCF128_I128] = "__fixtfti";
24069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPTOUINT_F32_I8] = "__fixunssfqi";
24169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPTOUINT_F32_I16] = "__fixunssfhi";
24269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPTOUINT_F32_I32] = "__fixunssfsi";
24369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPTOUINT_F32_I64] = "__fixunssfdi";
24469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPTOUINT_F32_I128] = "__fixunssfti";
24569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPTOUINT_F64_I8] = "__fixunsdfqi";
24669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPTOUINT_F64_I16] = "__fixunsdfhi";
24769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPTOUINT_F64_I32] = "__fixunsdfsi";
24869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPTOUINT_F64_I64] = "__fixunsdfdi";
24969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPTOUINT_F64_I128] = "__fixunsdfti";
25069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPTOUINT_F80_I32] = "__fixunsxfsi";
25169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPTOUINT_F80_I64] = "__fixunsxfdi";
25269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPTOUINT_F80_I128] = "__fixunsxfti";
25369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPTOUINT_F128_I32] = "__fixunstfsi";
25469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPTOUINT_F128_I64] = "__fixunstfdi";
25569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPTOUINT_F128_I128] = "__fixunstfti";
25669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPTOUINT_PPCF128_I32] = "__fixunstfsi";
25769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPTOUINT_PPCF128_I64] = "__fixunstfdi";
25869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::FPTOUINT_PPCF128_I128] = "__fixunstfti";
25969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SINTTOFP_I32_F32] = "__floatsisf";
26069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SINTTOFP_I32_F64] = "__floatsidf";
26169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SINTTOFP_I32_F80] = "__floatsixf";
26269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SINTTOFP_I32_F128] = "__floatsitf";
26369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SINTTOFP_I32_PPCF128] = "__floatsitf";
26469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SINTTOFP_I64_F32] = "__floatdisf";
26569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SINTTOFP_I64_F64] = "__floatdidf";
26669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SINTTOFP_I64_F80] = "__floatdixf";
26769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SINTTOFP_I64_F128] = "__floatditf";
26869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SINTTOFP_I64_PPCF128] = "__floatditf";
26969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SINTTOFP_I128_F32] = "__floattisf";
27069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SINTTOFP_I128_F64] = "__floattidf";
27169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SINTTOFP_I128_F80] = "__floattixf";
27269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SINTTOFP_I128_F128] = "__floattitf";
27369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SINTTOFP_I128_PPCF128] = "__floattitf";
27469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::UINTTOFP_I32_F32] = "__floatunsisf";
27569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::UINTTOFP_I32_F64] = "__floatunsidf";
27669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::UINTTOFP_I32_F80] = "__floatunsixf";
27769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::UINTTOFP_I32_F128] = "__floatunsitf";
27869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::UINTTOFP_I32_PPCF128] = "__floatunsitf";
27969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::UINTTOFP_I64_F32] = "__floatundisf";
28069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::UINTTOFP_I64_F64] = "__floatundidf";
28169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::UINTTOFP_I64_F80] = "__floatundixf";
28269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::UINTTOFP_I64_F128] = "__floatunditf";
28369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::UINTTOFP_I64_PPCF128] = "__floatunditf";
28469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::UINTTOFP_I128_F32] = "__floatuntisf";
28569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::UINTTOFP_I128_F64] = "__floatuntidf";
28669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::UINTTOFP_I128_F80] = "__floatuntixf";
28769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::UINTTOFP_I128_F128] = "__floatuntitf";
28869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::UINTTOFP_I128_PPCF128] = "__floatuntitf";
28969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::OEQ_F32] = "__eqsf2";
29069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::OEQ_F64] = "__eqdf2";
29169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::OEQ_F128] = "__eqtf2";
29269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::UNE_F32] = "__nesf2";
29369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::UNE_F64] = "__nedf2";
29469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::UNE_F128] = "__netf2";
29569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::OGE_F32] = "__gesf2";
29669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::OGE_F64] = "__gedf2";
29769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::OGE_F128] = "__getf2";
29869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::OLT_F32] = "__ltsf2";
29969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::OLT_F64] = "__ltdf2";
30069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::OLT_F128] = "__lttf2";
30169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::OLE_F32] = "__lesf2";
30269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::OLE_F64] = "__ledf2";
30369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::OLE_F128] = "__letf2";
30469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::OGT_F32] = "__gtsf2";
30569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::OGT_F64] = "__gtdf2";
30669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::OGT_F128] = "__gttf2";
30769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::UO_F32] = "__unordsf2";
30869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::UO_F64] = "__unorddf2";
30969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::UO_F128] = "__unordtf2";
31069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::O_F32] = "__unordsf2";
31169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::O_F64] = "__unorddf2";
31269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::O_F128] = "__unordtf2";
31369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::MEMCPY] = "memcpy";
31469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::MEMMOVE] = "memmove";
31569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::MEMSET] = "memset";
31669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::UNWIND_RESUME] = "_Unwind_Resume";
31769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SYNC_VAL_COMPARE_AND_SWAP_1] = "__sync_val_compare_and_swap_1";
31869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SYNC_VAL_COMPARE_AND_SWAP_2] = "__sync_val_compare_and_swap_2";
31969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SYNC_VAL_COMPARE_AND_SWAP_4] = "__sync_val_compare_and_swap_4";
32069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SYNC_VAL_COMPARE_AND_SWAP_8] = "__sync_val_compare_and_swap_8";
32169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SYNC_LOCK_TEST_AND_SET_1] = "__sync_lock_test_and_set_1";
32269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SYNC_LOCK_TEST_AND_SET_2] = "__sync_lock_test_and_set_2";
32369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SYNC_LOCK_TEST_AND_SET_4] = "__sync_lock_test_and_set_4";
32469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SYNC_LOCK_TEST_AND_SET_8] = "__sync_lock_test_and_set_8";
32569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SYNC_FETCH_AND_ADD_1] = "__sync_fetch_and_add_1";
32669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SYNC_FETCH_AND_ADD_2] = "__sync_fetch_and_add_2";
32769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SYNC_FETCH_AND_ADD_4] = "__sync_fetch_and_add_4";
32869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SYNC_FETCH_AND_ADD_8] = "__sync_fetch_and_add_8";
32969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SYNC_FETCH_AND_SUB_1] = "__sync_fetch_and_sub_1";
33069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SYNC_FETCH_AND_SUB_2] = "__sync_fetch_and_sub_2";
33169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SYNC_FETCH_AND_SUB_4] = "__sync_fetch_and_sub_4";
33269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SYNC_FETCH_AND_SUB_8] = "__sync_fetch_and_sub_8";
33369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SYNC_FETCH_AND_AND_1] = "__sync_fetch_and_and_1";
33469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SYNC_FETCH_AND_AND_2] = "__sync_fetch_and_and_2";
33569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SYNC_FETCH_AND_AND_4] = "__sync_fetch_and_and_4";
33669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SYNC_FETCH_AND_AND_8] = "__sync_fetch_and_and_8";
33769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SYNC_FETCH_AND_OR_1] = "__sync_fetch_and_or_1";
33869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SYNC_FETCH_AND_OR_2] = "__sync_fetch_and_or_2";
33969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SYNC_FETCH_AND_OR_4] = "__sync_fetch_and_or_4";
34069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SYNC_FETCH_AND_OR_8] = "__sync_fetch_and_or_8";
34169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SYNC_FETCH_AND_XOR_1] = "__sync_fetch_and_xor_1";
34269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SYNC_FETCH_AND_XOR_2] = "__sync_fetch_and_xor_2";
34369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SYNC_FETCH_AND_XOR_4] = "__sync_fetch_and_xor_4";
34469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SYNC_FETCH_AND_XOR_8] = "__sync_fetch_and_xor_8";
34569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SYNC_FETCH_AND_NAND_1] = "__sync_fetch_and_nand_1";
34669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SYNC_FETCH_AND_NAND_2] = "__sync_fetch_and_nand_2";
34769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SYNC_FETCH_AND_NAND_4] = "__sync_fetch_and_nand_4";
34869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  Names[RTLIB::SYNC_FETCH_AND_NAND_8] = "__sync_fetch_and_nand_8";
3498688a58c53b46d2dda9bf50dafd5195790a7ed58Evan Cheng
35086cdbc9c29a572d422815f55fd89ff7510d1e3e8Paul Redmond  if (Triple(TM.getTargetTriple()).getEnvironment() == Triple::GNU) {
35186cdbc9c29a572d422815f55fd89ff7510d1e3e8Paul Redmond    Names[RTLIB::SINCOS_F32] = "sincosf";
35286cdbc9c29a572d422815f55fd89ff7510d1e3e8Paul Redmond    Names[RTLIB::SINCOS_F64] = "sincos";
35386cdbc9c29a572d422815f55fd89ff7510d1e3e8Paul Redmond    Names[RTLIB::SINCOS_F80] = "sincosl";
35486cdbc9c29a572d422815f55fd89ff7510d1e3e8Paul Redmond    Names[RTLIB::SINCOS_F128] = "sincosl";
35586cdbc9c29a572d422815f55fd89ff7510d1e3e8Paul Redmond    Names[RTLIB::SINCOS_PPCF128] = "sincosl";
35686cdbc9c29a572d422815f55fd89ff7510d1e3e8Paul Redmond  } else {
35786cdbc9c29a572d422815f55fd89ff7510d1e3e8Paul Redmond    // These are generally not available.
35886cdbc9c29a572d422815f55fd89ff7510d1e3e8Paul Redmond    Names[RTLIB::SINCOS_F32] = 0;
35986cdbc9c29a572d422815f55fd89ff7510d1e3e8Paul Redmond    Names[RTLIB::SINCOS_F64] = 0;
36086cdbc9c29a572d422815f55fd89ff7510d1e3e8Paul Redmond    Names[RTLIB::SINCOS_F80] = 0;
36186cdbc9c29a572d422815f55fd89ff7510d1e3e8Paul Redmond    Names[RTLIB::SINCOS_F128] = 0;
36286cdbc9c29a572d422815f55fd89ff7510d1e3e8Paul Redmond    Names[RTLIB::SINCOS_PPCF128] = 0;
36386cdbc9c29a572d422815f55fd89ff7510d1e3e8Paul Redmond  }
36469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer}
36569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
36669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// InitLibcallCallingConvs - Set default libcall CallingConvs.
36769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer///
36869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramerstatic void InitLibcallCallingConvs(CallingConv::ID *CCs) {
36969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  for (int i = 0; i < RTLIB::UNKNOWN_LIBCALL; ++i) {
37069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    CCs[i] = CallingConv::C;
37169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  }
37269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer}
37369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
37469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// getFPEXT - Return the FPEXT_*_* value for the given types, or
37569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// UNKNOWN_LIBCALL if there is none.
37669e42dbd006c0afb732067ece7327988b1e24c01Benjamin KramerRTLIB::Libcall RTLIB::getFPEXT(EVT OpVT, EVT RetVT) {
37769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  if (OpVT == MVT::f32) {
37869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::f64)
37969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPEXT_F32_F64;
38069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::f128)
38169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPEXT_F32_F128;
38269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  } else if (OpVT == MVT::f64) {
38369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::f128)
38469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPEXT_F64_F128;
38569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  }
38669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
38769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  return UNKNOWN_LIBCALL;
38869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer}
38969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
39069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// getFPROUND - Return the FPROUND_*_* value for the given types, or
39169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// UNKNOWN_LIBCALL if there is none.
39269e42dbd006c0afb732067ece7327988b1e24c01Benjamin KramerRTLIB::Libcall RTLIB::getFPROUND(EVT OpVT, EVT RetVT) {
39369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  if (RetVT == MVT::f32) {
39469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (OpVT == MVT::f64)
39569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPROUND_F64_F32;
39669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (OpVT == MVT::f80)
39769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPROUND_F80_F32;
39869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (OpVT == MVT::f128)
39969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPROUND_F128_F32;
40069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (OpVT == MVT::ppcf128)
40169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPROUND_PPCF128_F32;
40269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  } else if (RetVT == MVT::f64) {
40369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (OpVT == MVT::f80)
40469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPROUND_F80_F64;
40569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (OpVT == MVT::f128)
40669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPROUND_F128_F64;
40769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (OpVT == MVT::ppcf128)
40869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPROUND_PPCF128_F64;
40969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  }
41069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
41169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  return UNKNOWN_LIBCALL;
41269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer}
41369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
41469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// getFPTOSINT - Return the FPTOSINT_*_* value for the given types, or
41569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// UNKNOWN_LIBCALL if there is none.
41669e42dbd006c0afb732067ece7327988b1e24c01Benjamin KramerRTLIB::Libcall RTLIB::getFPTOSINT(EVT OpVT, EVT RetVT) {
41769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  if (OpVT == MVT::f32) {
41869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i8)
41969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOSINT_F32_I8;
42069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i16)
42169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOSINT_F32_I16;
42269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i32)
42369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOSINT_F32_I32;
42469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i64)
42569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOSINT_F32_I64;
42669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i128)
42769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOSINT_F32_I128;
42869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  } else if (OpVT == MVT::f64) {
42969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i8)
43069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOSINT_F64_I8;
43169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i16)
43269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOSINT_F64_I16;
43369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i32)
43469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOSINT_F64_I32;
43569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i64)
43669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOSINT_F64_I64;
43769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i128)
43869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOSINT_F64_I128;
43969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  } else if (OpVT == MVT::f80) {
44069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i32)
44169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOSINT_F80_I32;
44269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i64)
44369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOSINT_F80_I64;
44469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i128)
44569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOSINT_F80_I128;
44669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  } else if (OpVT == MVT::f128) {
44769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i32)
44869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOSINT_F128_I32;
44969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i64)
45069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOSINT_F128_I64;
45169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i128)
45269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOSINT_F128_I128;
45369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  } else if (OpVT == MVT::ppcf128) {
45469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i32)
45569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOSINT_PPCF128_I32;
45669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i64)
45769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOSINT_PPCF128_I64;
45869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i128)
45969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOSINT_PPCF128_I128;
46069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  }
46169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  return UNKNOWN_LIBCALL;
46269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer}
46369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
46469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// getFPTOUINT - Return the FPTOUINT_*_* value for the given types, or
46569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// UNKNOWN_LIBCALL if there is none.
46669e42dbd006c0afb732067ece7327988b1e24c01Benjamin KramerRTLIB::Libcall RTLIB::getFPTOUINT(EVT OpVT, EVT RetVT) {
46769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  if (OpVT == MVT::f32) {
46869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i8)
46969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOUINT_F32_I8;
47069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i16)
47169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOUINT_F32_I16;
47269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i32)
47369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOUINT_F32_I32;
47469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i64)
47569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOUINT_F32_I64;
47669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i128)
47769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOUINT_F32_I128;
47869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  } else if (OpVT == MVT::f64) {
47969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i8)
48069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOUINT_F64_I8;
48169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i16)
48269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOUINT_F64_I16;
48369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i32)
48469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOUINT_F64_I32;
48569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i64)
48669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOUINT_F64_I64;
48769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i128)
48869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOUINT_F64_I128;
48969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  } else if (OpVT == MVT::f80) {
49069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i32)
49169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOUINT_F80_I32;
49269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i64)
49369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOUINT_F80_I64;
49469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i128)
49569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOUINT_F80_I128;
49669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  } else if (OpVT == MVT::f128) {
49769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i32)
49869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOUINT_F128_I32;
49969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i64)
50069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOUINT_F128_I64;
50169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i128)
50269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOUINT_F128_I128;
50369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  } else if (OpVT == MVT::ppcf128) {
50469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i32)
50569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOUINT_PPCF128_I32;
50669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i64)
50769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOUINT_PPCF128_I64;
50869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i128)
50969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOUINT_PPCF128_I128;
51069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  }
51169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  return UNKNOWN_LIBCALL;
51269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer}
51369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
51469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// getSINTTOFP - Return the SINTTOFP_*_* value for the given types, or
51569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// UNKNOWN_LIBCALL if there is none.
51669e42dbd006c0afb732067ece7327988b1e24c01Benjamin KramerRTLIB::Libcall RTLIB::getSINTTOFP(EVT OpVT, EVT RetVT) {
51769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  if (OpVT == MVT::i32) {
51869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::f32)
51969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return SINTTOFP_I32_F32;
52069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::f64)
52169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return SINTTOFP_I32_F64;
52269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::f80)
52369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return SINTTOFP_I32_F80;
52469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::f128)
52569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return SINTTOFP_I32_F128;
52669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::ppcf128)
52769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return SINTTOFP_I32_PPCF128;
52869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  } else if (OpVT == MVT::i64) {
52969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::f32)
53069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return SINTTOFP_I64_F32;
53169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::f64)
53269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return SINTTOFP_I64_F64;
53369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::f80)
53469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return SINTTOFP_I64_F80;
53569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::f128)
53669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return SINTTOFP_I64_F128;
53769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::ppcf128)
53869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return SINTTOFP_I64_PPCF128;
53969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  } else if (OpVT == MVT::i128) {
54069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::f32)
54169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return SINTTOFP_I128_F32;
54269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::f64)
54369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return SINTTOFP_I128_F64;
54469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::f80)
54569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return SINTTOFP_I128_F80;
54669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::f128)
54769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return SINTTOFP_I128_F128;
54869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::ppcf128)
54969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return SINTTOFP_I128_PPCF128;
55069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  }
55169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  return UNKNOWN_LIBCALL;
55269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer}
55369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
55469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// getUINTTOFP - Return the UINTTOFP_*_* value for the given types, or
55569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// UNKNOWN_LIBCALL if there is none.
55669e42dbd006c0afb732067ece7327988b1e24c01Benjamin KramerRTLIB::Libcall RTLIB::getUINTTOFP(EVT OpVT, EVT RetVT) {
55769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  if (OpVT == MVT::i32) {
55869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::f32)
55969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return UINTTOFP_I32_F32;
56069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::f64)
56169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return UINTTOFP_I32_F64;
56269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::f80)
56369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return UINTTOFP_I32_F80;
56469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::f128)
56569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return UINTTOFP_I32_F128;
56669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::ppcf128)
56769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return UINTTOFP_I32_PPCF128;
56869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  } else if (OpVT == MVT::i64) {
56969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::f32)
57069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return UINTTOFP_I64_F32;
57169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::f64)
57269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return UINTTOFP_I64_F64;
57369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::f80)
57469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return UINTTOFP_I64_F80;
57569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::f128)
57669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return UINTTOFP_I64_F128;
57769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::ppcf128)
57869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return UINTTOFP_I64_PPCF128;
57969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  } else if (OpVT == MVT::i128) {
58069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::f32)
58169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return UINTTOFP_I128_F32;
58269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::f64)
58369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return UINTTOFP_I128_F64;
58469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::f80)
58569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return UINTTOFP_I128_F80;
58669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::f128)
58769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return UINTTOFP_I128_F128;
58869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::ppcf128)
58969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return UINTTOFP_I128_PPCF128;
59069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  }
59169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  return UNKNOWN_LIBCALL;
59269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer}
59369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
59469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// InitCmpLibcallCCs - Set default comparison libcall CC.
59569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer///
59669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramerstatic void InitCmpLibcallCCs(ISD::CondCode *CCs) {
59769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  memset(CCs, ISD::SETCC_INVALID, sizeof(ISD::CondCode)*RTLIB::UNKNOWN_LIBCALL);
59869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  CCs[RTLIB::OEQ_F32] = ISD::SETEQ;
59969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  CCs[RTLIB::OEQ_F64] = ISD::SETEQ;
60069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  CCs[RTLIB::OEQ_F128] = ISD::SETEQ;
60169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  CCs[RTLIB::UNE_F32] = ISD::SETNE;
60269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  CCs[RTLIB::UNE_F64] = ISD::SETNE;
60369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  CCs[RTLIB::UNE_F128] = ISD::SETNE;
60469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  CCs[RTLIB::OGE_F32] = ISD::SETGE;
60569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  CCs[RTLIB::OGE_F64] = ISD::SETGE;
60669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  CCs[RTLIB::OGE_F128] = ISD::SETGE;
60769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  CCs[RTLIB::OLT_F32] = ISD::SETLT;
60869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  CCs[RTLIB::OLT_F64] = ISD::SETLT;
60969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  CCs[RTLIB::OLT_F128] = ISD::SETLT;
61069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  CCs[RTLIB::OLE_F32] = ISD::SETLE;
61169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  CCs[RTLIB::OLE_F64] = ISD::SETLE;
61269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  CCs[RTLIB::OLE_F128] = ISD::SETLE;
61369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  CCs[RTLIB::OGT_F32] = ISD::SETGT;
61469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  CCs[RTLIB::OGT_F64] = ISD::SETGT;
61569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  CCs[RTLIB::OGT_F128] = ISD::SETGT;
61669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  CCs[RTLIB::UO_F32] = ISD::SETNE;
61769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  CCs[RTLIB::UO_F64] = ISD::SETNE;
61869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  CCs[RTLIB::UO_F128] = ISD::SETNE;
61969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  CCs[RTLIB::O_F32] = ISD::SETEQ;
62069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  CCs[RTLIB::O_F64] = ISD::SETEQ;
62169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  CCs[RTLIB::O_F128] = ISD::SETEQ;
62269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer}
62369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
62469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// NOTE: The constructor takes ownership of TLOF.
62569e42dbd006c0afb732067ece7327988b1e24c01Benjamin KramerTargetLoweringBase::TargetLoweringBase(const TargetMachine &tm,
62669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer                                       const TargetLoweringObjectFile *tlof)
62769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  : TM(tm), TD(TM.getDataLayout()), TLOF(*tlof) {
62813bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  initActions();
62913bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling
63013bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  // Perform these initializations only once.
63113bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  IsLittleEndian = TD->isLittleEndian();
63213bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  PointerTy = MVT::getIntegerVT(8*TD->getPointerSize(0));
63313bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  MaxStoresPerMemset = MaxStoresPerMemcpy = MaxStoresPerMemmove = 8;
63413bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  MaxStoresPerMemsetOptSize = MaxStoresPerMemcpyOptSize
63513bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling    = MaxStoresPerMemmoveOptSize = 4;
63613bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  UseUnderscoreSetJmp = false;
63713bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  UseUnderscoreLongJmp = false;
63813bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  SelectIsExpensive = false;
63913bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  IntDivIsCheap = false;
64013bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  Pow2DivIsCheap = false;
64113bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  JumpIsExpensive = false;
64213bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  PredictableSelectIsExpensive = false;
64313bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  StackPointerRegisterToSaveRestore = 0;
64413bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  ExceptionPointerRegister = 0;
64513bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  ExceptionSelectorRegister = 0;
64613bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  BooleanContents = UndefinedBooleanContent;
64713bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  BooleanVectorContents = UndefinedBooleanContent;
64813bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  SchedPreferenceInfo = Sched::ILP;
64913bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  JumpBufSize = 0;
65013bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  JumpBufAlignment = 0;
65113bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  MinFunctionAlignment = 0;
65213bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  PrefFunctionAlignment = 0;
65313bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  PrefLoopAlignment = 0;
65413bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  MinStackArgumentAlignment = 1;
65513bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  InsertFencesForAtomic = false;
65613bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  SupportJumpTables = true;
65713bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  MinimumJumpTableEntries = 4;
65813bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling
65913bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  InitLibcallNames(LibcallRoutineNames, TM);
66013bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  InitCmpLibcallCCs(CmpLibcallCCs);
66113bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  InitLibcallCallingConvs(LibcallCallingConvs);
66213bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling}
66313bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling
66413bbe1f52e8d57151e2730db49094e1c62a4c793Bill WendlingTargetLoweringBase::~TargetLoweringBase() {
66513bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  delete &TLOF;
66613bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling}
66713bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling
66813bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendlingvoid TargetLoweringBase::initActions() {
66969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // All operations default to being supported.
67069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  memset(OpActions, 0, sizeof(OpActions));
67169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  memset(LoadExtActions, 0, sizeof(LoadExtActions));
67269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  memset(TruncStoreActions, 0, sizeof(TruncStoreActions));
67369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  memset(IndexedModeActions, 0, sizeof(IndexedModeActions));
67469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  memset(CondCodeActions, 0, sizeof(CondCodeActions));
67513bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  memset(RegClassForVT, 0,MVT::LAST_VALUETYPE*sizeof(TargetRegisterClass*));
67613bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  memset(TargetDAGCombineArray, 0, array_lengthof(TargetDAGCombineArray));
67769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
67869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // Set default actions for various operations.
67969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  for (unsigned VT = 0; VT != (unsigned)MVT::LAST_VALUETYPE; ++VT) {
68069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    // Default all indexed load / store to expand.
68169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    for (unsigned IM = (unsigned)ISD::PRE_INC;
68269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer         IM != (unsigned)ISD::LAST_INDEXED_MODE; ++IM) {
68369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      setIndexedLoadAction(IM, (MVT::SimpleValueType)VT, Expand);
68469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      setIndexedStoreAction(IM, (MVT::SimpleValueType)VT, Expand);
68569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    }
68669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
68769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    // These operations default to expand.
68869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    setOperationAction(ISD::FGETSIGN, (MVT::SimpleValueType)VT, Expand);
68969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    setOperationAction(ISD::CONCAT_VECTORS, (MVT::SimpleValueType)VT, Expand);
69069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  }
69169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
69269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // Most targets ignore the @llvm.prefetch intrinsic.
69369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::PREFETCH, MVT::Other, Expand);
69469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
69569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // ConstantFP nodes default to expand.  Targets can either change this to
69669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // Legal, in which case all fp constants are legal, or use isFPImmLegal()
69769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // to optimize expansions for certain constants.
69869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::ConstantFP, MVT::f16, Expand);
69969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::ConstantFP, MVT::f32, Expand);
70069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::ConstantFP, MVT::f64, Expand);
70169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::ConstantFP, MVT::f80, Expand);
70269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::ConstantFP, MVT::f128, Expand);
70369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
70469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // These library functions default to expand.
70569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::FLOG ,  MVT::f16, Expand);
70669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::FLOG2,  MVT::f16, Expand);
70769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::FLOG10, MVT::f16, Expand);
70869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::FEXP ,  MVT::f16, Expand);
70969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::FEXP2,  MVT::f16, Expand);
71069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::FFLOOR, MVT::f16, Expand);
71169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::FNEARBYINT, MVT::f16, Expand);
71269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::FCEIL,  MVT::f16, Expand);
71369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::FRINT,  MVT::f16, Expand);
71441418d17cced656f91038b2482bc9d173b4974b0Hal Finkel  setOperationAction(ISD::FROUND, MVT::f16, Expand);
71569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::FTRUNC, MVT::f16, Expand);
71669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::FLOG ,  MVT::f32, Expand);
71769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::FLOG2,  MVT::f32, Expand);
71869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::FLOG10, MVT::f32, Expand);
71969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::FEXP ,  MVT::f32, Expand);
72069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::FEXP2,  MVT::f32, Expand);
72169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::FFLOOR, MVT::f32, Expand);
72269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::FNEARBYINT, MVT::f32, Expand);
72369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::FCEIL,  MVT::f32, Expand);
72469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::FRINT,  MVT::f32, Expand);
72541418d17cced656f91038b2482bc9d173b4974b0Hal Finkel  setOperationAction(ISD::FROUND, MVT::f32, Expand);
72669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::FTRUNC, MVT::f32, Expand);
72769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::FLOG ,  MVT::f64, Expand);
72869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::FLOG2,  MVT::f64, Expand);
72969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::FLOG10, MVT::f64, Expand);
73069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::FEXP ,  MVT::f64, Expand);
73169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::FEXP2,  MVT::f64, Expand);
73269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::FFLOOR, MVT::f64, Expand);
73369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::FNEARBYINT, MVT::f64, Expand);
73469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::FCEIL,  MVT::f64, Expand);
73569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::FRINT,  MVT::f64, Expand);
73641418d17cced656f91038b2482bc9d173b4974b0Hal Finkel  setOperationAction(ISD::FROUND, MVT::f64, Expand);
73769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::FTRUNC, MVT::f64, Expand);
73869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::FLOG ,  MVT::f128, Expand);
73969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::FLOG2,  MVT::f128, Expand);
74069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::FLOG10, MVT::f128, Expand);
74169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::FEXP ,  MVT::f128, Expand);
74269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::FEXP2,  MVT::f128, Expand);
74369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::FFLOOR, MVT::f128, Expand);
74469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::FNEARBYINT, MVT::f128, Expand);
74569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::FCEIL,  MVT::f128, Expand);
74669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::FRINT,  MVT::f128, Expand);
74741418d17cced656f91038b2482bc9d173b4974b0Hal Finkel  setOperationAction(ISD::FROUND, MVT::f128, Expand);
74869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::FTRUNC, MVT::f128, Expand);
74969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
75069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // Default ISD::TRAP to expand (which turns it into abort).
75169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::TRAP, MVT::Other, Expand);
75269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
75369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // On most systems, DEBUGTRAP and TRAP have no difference. The "Expand"
75469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // here is to inform DAG Legalizer to replace DEBUGTRAP with TRAP.
75569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  //
75669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::DEBUGTRAP, MVT::Other, Expand);
75769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer}
75869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
759a6b20ced765b67a85d9219d0c8547fc9c133e14fMichael LiaoMVT TargetLoweringBase::getScalarShiftAmountTy(EVT LHSTy) const {
76069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  return MVT::getIntegerVT(8*TD->getPointerSize(0));
76169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer}
76269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
763a6b20ced765b67a85d9219d0c8547fc9c133e14fMichael LiaoEVT TargetLoweringBase::getShiftAmountTy(EVT LHSTy) const {
764a6b20ced765b67a85d9219d0c8547fc9c133e14fMichael Liao  assert(LHSTy.isInteger() && "Shift amount is not an integer type!");
765a6b20ced765b67a85d9219d0c8547fc9c133e14fMichael Liao  if (LHSTy.isVector())
766a6b20ced765b67a85d9219d0c8547fc9c133e14fMichael Liao    return LHSTy;
767a6b20ced765b67a85d9219d0c8547fc9c133e14fMichael Liao  return getScalarShiftAmountTy(LHSTy);
768a6b20ced765b67a85d9219d0c8547fc9c133e14fMichael Liao}
769a6b20ced765b67a85d9219d0c8547fc9c133e14fMichael Liao
77069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// canOpTrap - Returns true if the operation can trap for the value type.
77169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// VT must be a legal type.
77269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramerbool TargetLoweringBase::canOpTrap(unsigned Op, EVT VT) const {
77369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  assert(isTypeLegal(VT));
77469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  switch (Op) {
77569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  default:
77669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    return false;
77769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case ISD::FDIV:
77869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case ISD::FREM:
77969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case ISD::SDIV:
78069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case ISD::UDIV:
78169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case ISD::SREM:
78269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case ISD::UREM:
78369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    return true;
78469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  }
78569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer}
78669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
78769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
78869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramerstatic unsigned getVectorTypeBreakdownMVT(MVT VT, MVT &IntermediateVT,
78969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer                                          unsigned &NumIntermediates,
79069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer                                          MVT &RegisterVT,
79169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer                                          TargetLoweringBase *TLI) {
79269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // Figure out the right, legal destination reg to copy into.
79369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  unsigned NumElts = VT.getVectorNumElements();
79469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  MVT EltTy = VT.getVectorElementType();
79569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
79669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  unsigned NumVectorRegs = 1;
79769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
79869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // FIXME: We don't support non-power-of-2-sized vectors for now.  Ideally we
79969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // could break down into LHS/RHS like LegalizeDAG does.
80069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  if (!isPowerOf2_32(NumElts)) {
80169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    NumVectorRegs = NumElts;
80269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    NumElts = 1;
80369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  }
80469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
80569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // Divide the input until we get to a supported size.  This will always
80669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // end with a scalar if the target doesn't support vectors.
80769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  while (NumElts > 1 && !TLI->isTypeLegal(MVT::getVectorVT(EltTy, NumElts))) {
80869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    NumElts >>= 1;
80969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    NumVectorRegs <<= 1;
81069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  }
81169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
81269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  NumIntermediates = NumVectorRegs;
81369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
81469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  MVT NewVT = MVT::getVectorVT(EltTy, NumElts);
81569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  if (!TLI->isTypeLegal(NewVT))
81669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    NewVT = EltTy;
81769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  IntermediateVT = NewVT;
81869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
81969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  unsigned NewVTSize = NewVT.getSizeInBits();
82069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
82169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // Convert sizes such as i33 to i64.
82269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  if (!isPowerOf2_32(NewVTSize))
82369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    NewVTSize = NextPowerOf2(NewVTSize);
82469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
82569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  MVT DestVT = TLI->getRegisterType(NewVT);
82669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  RegisterVT = DestVT;
82769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  if (EVT(DestVT).bitsLT(NewVT))    // Value is expanded, e.g. i64 -> i16.
82869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    return NumVectorRegs*(NewVTSize/DestVT.getSizeInBits());
82969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
83069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // Otherwise, promotion or legal types use the same number of registers as
83169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // the vector decimated to the appropriate level.
83269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  return NumVectorRegs;
83369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer}
83469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
83569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// isLegalRC - Return true if the value types that can be represented by the
83669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// specified register class are all legal.
83769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramerbool TargetLoweringBase::isLegalRC(const TargetRegisterClass *RC) const {
83869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  for (TargetRegisterClass::vt_iterator I = RC->vt_begin(), E = RC->vt_end();
83969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer       I != E; ++I) {
84069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (isTypeLegal(*I))
84169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return true;
84269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  }
84369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  return false;
84469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer}
84569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
84669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// findRepresentativeClass - Return the largest legal super-reg register class
84769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// of the register class for the specified type and its associated "cost".
84869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramerstd::pair<const TargetRegisterClass*, uint8_t>
84969e42dbd006c0afb732067ece7327988b1e24c01Benjamin KramerTargetLoweringBase::findRepresentativeClass(MVT VT) const {
85069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  const TargetRegisterInfo *TRI = getTargetMachine().getRegisterInfo();
85169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  const TargetRegisterClass *RC = RegClassForVT[VT.SimpleTy];
85269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  if (!RC)
85369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    return std::make_pair(RC, 0);
85469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
85569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // Compute the set of all super-register classes.
85669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  BitVector SuperRegRC(TRI->getNumRegClasses());
85769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  for (SuperRegClassIterator RCI(RC, TRI); RCI.isValid(); ++RCI)
85869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    SuperRegRC.setBitsInMask(RCI.getMask());
85969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
86069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // Find the first legal register class with the largest spill size.
86169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  const TargetRegisterClass *BestRC = RC;
86269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  for (int i = SuperRegRC.find_first(); i >= 0; i = SuperRegRC.find_next(i)) {
86369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    const TargetRegisterClass *SuperRC = TRI->getRegClass(i);
86469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    // We want the largest possible spill size.
86569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (SuperRC->getSize() <= BestRC->getSize())
86669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      continue;
86769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (!isLegalRC(SuperRC))
86869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      continue;
86969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    BestRC = SuperRC;
87069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  }
87169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  return std::make_pair(BestRC, 1);
87269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer}
87369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
87469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// computeRegisterProperties - Once all of the register classes are added,
87569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// this allows us to compute derived properties we expose.
87669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramervoid TargetLoweringBase::computeRegisterProperties() {
87769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  assert(MVT::LAST_VALUETYPE <= MVT::MAX_ALLOWED_VALUETYPE &&
87869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer         "Too many value types for ValueTypeActions to hold!");
87969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
88069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // Everything defaults to needing one register.
88169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  for (unsigned i = 0; i != MVT::LAST_VALUETYPE; ++i) {
88269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    NumRegistersForVT[i] = 1;
88369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    RegisterTypeForVT[i] = TransformToType[i] = (MVT::SimpleValueType)i;
88469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  }
88569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // ...except isVoid, which doesn't need any registers.
88669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  NumRegistersForVT[MVT::isVoid] = 0;
88769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
88869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // Find the largest integer register class.
88969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  unsigned LargestIntReg = MVT::LAST_INTEGER_VALUETYPE;
89069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  for (; RegClassForVT[LargestIntReg] == 0; --LargestIntReg)
89169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    assert(LargestIntReg != MVT::i1 && "No integer registers defined!");
89269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
89369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // Every integer value type larger than this largest register takes twice as
89469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // many registers to represent as the previous ValueType.
89569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  for (unsigned ExpandedReg = LargestIntReg + 1;
89669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer       ExpandedReg <= MVT::LAST_INTEGER_VALUETYPE; ++ExpandedReg) {
89769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    NumRegistersForVT[ExpandedReg] = 2*NumRegistersForVT[ExpandedReg-1];
89869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    RegisterTypeForVT[ExpandedReg] = (MVT::SimpleValueType)LargestIntReg;
89969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    TransformToType[ExpandedReg] = (MVT::SimpleValueType)(ExpandedReg - 1);
90069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    ValueTypeActions.setTypeAction((MVT::SimpleValueType)ExpandedReg,
90169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer                                   TypeExpandInteger);
90269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  }
90369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
90469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // Inspect all of the ValueType's smaller than the largest integer
90569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // register to see which ones need promotion.
90669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  unsigned LegalIntReg = LargestIntReg;
90769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  for (unsigned IntReg = LargestIntReg - 1;
90869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer       IntReg >= (unsigned)MVT::i1; --IntReg) {
90969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    MVT IVT = (MVT::SimpleValueType)IntReg;
91069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (isTypeLegal(IVT)) {
91169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      LegalIntReg = IntReg;
91269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    } else {
91369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      RegisterTypeForVT[IntReg] = TransformToType[IntReg] =
91469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer        (const MVT::SimpleValueType)LegalIntReg;
91569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      ValueTypeActions.setTypeAction(IVT, TypePromoteInteger);
91669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    }
91769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  }
91869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
91969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // ppcf128 type is really two f64's.
92069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  if (!isTypeLegal(MVT::ppcf128)) {
92169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    NumRegistersForVT[MVT::ppcf128] = 2*NumRegistersForVT[MVT::f64];
92269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    RegisterTypeForVT[MVT::ppcf128] = MVT::f64;
92369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    TransformToType[MVT::ppcf128] = MVT::f64;
92469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    ValueTypeActions.setTypeAction(MVT::ppcf128, TypeExpandFloat);
92569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  }
92669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
927c3c3810f514af7e08f84ef76b0c304ec264ee021Akira Hatanaka  // Decide how to handle f128. If the target does not have native f128 support,
928c3c3810f514af7e08f84ef76b0c304ec264ee021Akira Hatanaka  // expand it to i128 and we will be generating soft float library calls.
929c3c3810f514af7e08f84ef76b0c304ec264ee021Akira Hatanaka  if (!isTypeLegal(MVT::f128)) {
930c3c3810f514af7e08f84ef76b0c304ec264ee021Akira Hatanaka    NumRegistersForVT[MVT::f128] = NumRegistersForVT[MVT::i128];
931c3c3810f514af7e08f84ef76b0c304ec264ee021Akira Hatanaka    RegisterTypeForVT[MVT::f128] = RegisterTypeForVT[MVT::i128];
932c3c3810f514af7e08f84ef76b0c304ec264ee021Akira Hatanaka    TransformToType[MVT::f128] = MVT::i128;
933c3c3810f514af7e08f84ef76b0c304ec264ee021Akira Hatanaka    ValueTypeActions.setTypeAction(MVT::f128, TypeSoftenFloat);
934c3c3810f514af7e08f84ef76b0c304ec264ee021Akira Hatanaka  }
935c3c3810f514af7e08f84ef76b0c304ec264ee021Akira Hatanaka
93669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // Decide how to handle f64. If the target does not have native f64 support,
93769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // expand it to i64 and we will be generating soft float library calls.
93869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  if (!isTypeLegal(MVT::f64)) {
93969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    NumRegistersForVT[MVT::f64] = NumRegistersForVT[MVT::i64];
94069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    RegisterTypeForVT[MVT::f64] = RegisterTypeForVT[MVT::i64];
94169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    TransformToType[MVT::f64] = MVT::i64;
94269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    ValueTypeActions.setTypeAction(MVT::f64, TypeSoftenFloat);
94369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  }
94469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
94569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // Decide how to handle f32. If the target does not have native support for
94669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // f32, promote it to f64 if it is legal. Otherwise, expand it to i32.
94769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  if (!isTypeLegal(MVT::f32)) {
94869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (isTypeLegal(MVT::f64)) {
94969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      NumRegistersForVT[MVT::f32] = NumRegistersForVT[MVT::f64];
95069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      RegisterTypeForVT[MVT::f32] = RegisterTypeForVT[MVT::f64];
95169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      TransformToType[MVT::f32] = MVT::f64;
95269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      ValueTypeActions.setTypeAction(MVT::f32, TypePromoteInteger);
95369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    } else {
95469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      NumRegistersForVT[MVT::f32] = NumRegistersForVT[MVT::i32];
95569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      RegisterTypeForVT[MVT::f32] = RegisterTypeForVT[MVT::i32];
95669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      TransformToType[MVT::f32] = MVT::i32;
95769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      ValueTypeActions.setTypeAction(MVT::f32, TypeSoftenFloat);
95869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    }
95969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  }
96069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
96169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // Loop over all of the vector value types to see which need transformations.
96269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  for (unsigned i = MVT::FIRST_VECTOR_VALUETYPE;
96369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer       i <= (unsigned)MVT::LAST_VECTOR_VALUETYPE; ++i) {
96469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    MVT VT = (MVT::SimpleValueType)i;
96569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (isTypeLegal(VT)) continue;
96669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
96769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    // Determine if there is a legal wider type.  If so, we should promote to
96869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    // that wider vector type.
96969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    MVT EltVT = VT.getVectorElementType();
97069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    unsigned NElts = VT.getVectorNumElements();
97169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (NElts != 1 && !shouldSplitVectorElementType(EltVT)) {
97269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      bool IsLegalWiderType = false;
97369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      // First try to promote the elements of integer vectors. If no legal
97469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      // promotion was found, fallback to the widen-vector method.
97569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      for (unsigned nVT = i+1; nVT <= MVT::LAST_VECTOR_VALUETYPE; ++nVT) {
97669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer        MVT SVT = (MVT::SimpleValueType)nVT;
97769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer        // Promote vectors of integers to vectors with the same number
97869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer        // of elements, with a wider element type.
97969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer        if (SVT.getVectorElementType().getSizeInBits() > EltVT.getSizeInBits()
98069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer            && SVT.getVectorNumElements() == NElts &&
98169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer            isTypeLegal(SVT) && SVT.getScalarType().isInteger()) {
98269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer          TransformToType[i] = SVT;
98369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer          RegisterTypeForVT[i] = SVT;
98469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer          NumRegistersForVT[i] = 1;
98569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer          ValueTypeActions.setTypeAction(VT, TypePromoteInteger);
98669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer          IsLegalWiderType = true;
98769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer          break;
98869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer        }
98969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      }
99069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
99169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      if (IsLegalWiderType) continue;
99269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
99369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      // Try to widen the vector.
99469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      for (unsigned nVT = i+1; nVT <= MVT::LAST_VECTOR_VALUETYPE; ++nVT) {
99569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer        MVT SVT = (MVT::SimpleValueType)nVT;
99669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer        if (SVT.getVectorElementType() == EltVT &&
99769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer            SVT.getVectorNumElements() > NElts &&
99869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer            isTypeLegal(SVT)) {
99969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer          TransformToType[i] = SVT;
100069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer          RegisterTypeForVT[i] = SVT;
100169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer          NumRegistersForVT[i] = 1;
100269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer          ValueTypeActions.setTypeAction(VT, TypeWidenVector);
100369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer          IsLegalWiderType = true;
100469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer          break;
100569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer        }
100669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      }
100769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      if (IsLegalWiderType) continue;
100869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    }
100969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
101069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    MVT IntermediateVT;
101169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    MVT RegisterVT;
101269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    unsigned NumIntermediates;
101369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    NumRegistersForVT[i] =
101469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      getVectorTypeBreakdownMVT(VT, IntermediateVT, NumIntermediates,
101569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer                                RegisterVT, this);
101669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    RegisterTypeForVT[i] = RegisterVT;
101769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
101869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    MVT NVT = VT.getPow2VectorType();
101969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (NVT == VT) {
102069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      // Type is already a power of 2.  The default action is to split.
102169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      TransformToType[i] = MVT::Other;
102269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      unsigned NumElts = VT.getVectorNumElements();
102369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      ValueTypeActions.setTypeAction(VT,
102469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer            NumElts > 1 ? TypeSplitVector : TypeScalarizeVector);
102569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    } else {
102669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      TransformToType[i] = NVT;
102769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      ValueTypeActions.setTypeAction(VT, TypeWidenVector);
102869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    }
102969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  }
103069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
103169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // Determine the 'representative' register class for each value type.
103269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // An representative register class is the largest (meaning one which is
103369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // not a sub-register class / subreg register class) legal register class for
103469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // a group of value types. For example, on i386, i8, i16, and i32
103569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // representative would be GR32; while on x86_64 it's GR64.
103669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  for (unsigned i = 0; i != MVT::LAST_VALUETYPE; ++i) {
103769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    const TargetRegisterClass* RRC;
103869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    uint8_t Cost;
103969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    tie(RRC, Cost) =  findRepresentativeClass((MVT::SimpleValueType)i);
104069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    RepRegClassForVT[i] = RRC;
104169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    RepRegClassCostForVT[i] = Cost;
104269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  }
104369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer}
104469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
1045225ed7069caae9ece32d8bd3d15c6e41e21cc04bMatt ArsenaultEVT TargetLoweringBase::getSetCCResultType(LLVMContext &, EVT VT) const {
104669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  assert(!VT.isVector() && "No default SetCC type for vectors!");
104769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  return getPointerTy(0).SimpleTy;
104869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer}
104969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
105069e42dbd006c0afb732067ece7327988b1e24c01Benjamin KramerMVT::SimpleValueType TargetLoweringBase::getCmpLibcallReturnType() const {
105169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  return MVT::i32; // return the default value
105269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer}
105369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
105469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// getVectorTypeBreakdown - Vector types are broken down into some number of
105569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// legal first class types.  For example, MVT::v8f32 maps to 2 MVT::v4f32
105669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// with Altivec or SSE1, or 8 promoted MVT::f64 values with the X86 FP stack.
105769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// Similarly, MVT::v2i64 turns into 4 MVT::i32 values with both PPC and X86.
105869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer///
105969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// This method returns the number of registers needed, and the VT for each
106069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// register.  It also returns the VT and quantity of the intermediate values
106169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// before they are promoted/expanded.
106269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer///
106369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramerunsigned TargetLoweringBase::getVectorTypeBreakdown(LLVMContext &Context, EVT VT,
106469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer                                                EVT &IntermediateVT,
106569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer                                                unsigned &NumIntermediates,
106669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer                                                MVT &RegisterVT) const {
106769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  unsigned NumElts = VT.getVectorNumElements();
106869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
106969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // If there is a wider vector type with the same element type as this one,
107069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // or a promoted vector type that has the same number of elements which
107169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // are wider, then we should convert to that legal vector type.
107269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // This handles things like <2 x float> -> <4 x float> and
107369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // <4 x i1> -> <4 x i32>.
107469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  LegalizeTypeAction TA = getTypeAction(Context, VT);
107569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  if (NumElts != 1 && (TA == TypeWidenVector || TA == TypePromoteInteger)) {
107669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    EVT RegisterEVT = getTypeToTransformTo(Context, VT);
107769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (isTypeLegal(RegisterEVT)) {
107869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      IntermediateVT = RegisterEVT;
107969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      RegisterVT = RegisterEVT.getSimpleVT();
108069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      NumIntermediates = 1;
108169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return 1;
108269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    }
108369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  }
108469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
108569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // Figure out the right, legal destination reg to copy into.
108669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  EVT EltTy = VT.getVectorElementType();
108769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
108869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  unsigned NumVectorRegs = 1;
108969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
109069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // FIXME: We don't support non-power-of-2-sized vectors for now.  Ideally we
109169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // could break down into LHS/RHS like LegalizeDAG does.
109269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  if (!isPowerOf2_32(NumElts)) {
109369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    NumVectorRegs = NumElts;
109469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    NumElts = 1;
109569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  }
109669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
109769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // Divide the input until we get to a supported size.  This will always
109869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // end with a scalar if the target doesn't support vectors.
109969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  while (NumElts > 1 && !isTypeLegal(
110069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer                                   EVT::getVectorVT(Context, EltTy, NumElts))) {
110169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    NumElts >>= 1;
110269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    NumVectorRegs <<= 1;
110369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  }
110469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
110569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  NumIntermediates = NumVectorRegs;
110669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
110769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  EVT NewVT = EVT::getVectorVT(Context, EltTy, NumElts);
110869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  if (!isTypeLegal(NewVT))
110969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    NewVT = EltTy;
111069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  IntermediateVT = NewVT;
111169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
111269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  MVT DestVT = getRegisterType(Context, NewVT);
111369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  RegisterVT = DestVT;
111469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  unsigned NewVTSize = NewVT.getSizeInBits();
111569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
111669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // Convert sizes such as i33 to i64.
111769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  if (!isPowerOf2_32(NewVTSize))
111869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    NewVTSize = NextPowerOf2(NewVTSize);
111969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
112069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  if (EVT(DestVT).bitsLT(NewVT))   // Value is expanded, e.g. i64 -> i16.
112169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    return NumVectorRegs*(NewVTSize/DestVT.getSizeInBits());
112269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
112369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // Otherwise, promotion or legal types use the same number of registers as
112469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // the vector decimated to the appropriate level.
112569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  return NumVectorRegs;
112669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer}
112769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
112869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// Get the EVTs and ArgFlags collections that represent the legalized return
112969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// type of the given function.  This does not require a DAG or a return value,
113069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// and is suitable for use before any DAGs for the function are constructed.
113169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// TODO: Move this out of TargetLowering.cpp.
113269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramervoid llvm::GetReturnInfo(Type* ReturnType, AttributeSet attr,
113369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer                         SmallVectorImpl<ISD::OutputArg> &Outs,
113469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer                         const TargetLowering &TLI) {
113569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  SmallVector<EVT, 4> ValueVTs;
113669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  ComputeValueVTs(TLI, ReturnType, ValueVTs);
113769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  unsigned NumValues = ValueVTs.size();
113869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  if (NumValues == 0) return;
113969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
114069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  for (unsigned j = 0, f = NumValues; j != f; ++j) {
114169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    EVT VT = ValueVTs[j];
114269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    ISD::NodeType ExtendKind = ISD::ANY_EXTEND;
114369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
114469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (attr.hasAttribute(AttributeSet::ReturnIndex, Attribute::SExt))
114569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      ExtendKind = ISD::SIGN_EXTEND;
114669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    else if (attr.hasAttribute(AttributeSet::ReturnIndex, Attribute::ZExt))
114769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      ExtendKind = ISD::ZERO_EXTEND;
114869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
114969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    // FIXME: C calling convention requires the return type to be promoted to
115069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    // at least 32-bit. But this is not necessary for non-C calling
115169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    // conventions. The frontend should mark functions whose return values
115269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    // require promoting with signext or zeroext attributes.
115369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (ExtendKind != ISD::ANY_EXTEND && VT.isInteger()) {
115469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      MVT MinVT = TLI.getRegisterType(ReturnType->getContext(), MVT::i32);
115569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      if (VT.bitsLT(MinVT))
115669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer        VT = MinVT;
115769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    }
115869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
115969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    unsigned NumParts = TLI.getNumRegisters(ReturnType->getContext(), VT);
116069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    MVT PartVT = TLI.getRegisterType(ReturnType->getContext(), VT);
116169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
116269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    // 'inreg' on function refers to return value
116369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    ISD::ArgFlagsTy Flags = ISD::ArgFlagsTy();
116469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (attr.hasAttribute(AttributeSet::ReturnIndex, Attribute::InReg))
116569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      Flags.setInReg();
116669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
116769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    // Propagate extension type if any
116869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (attr.hasAttribute(AttributeSet::ReturnIndex, Attribute::SExt))
116969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      Flags.setSExt();
117069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    else if (attr.hasAttribute(AttributeSet::ReturnIndex, Attribute::ZExt))
117169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      Flags.setZExt();
117269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
117369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    for (unsigned i = 0; i < NumParts; ++i)
117469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      Outs.push_back(ISD::OutputArg(Flags, PartVT, /*isFixed=*/true, 0, 0));
117569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  }
117669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer}
117769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
117869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// getByValTypeAlignment - Return the desired alignment for ByVal aggregate
117969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// function arguments in the caller parameter area.  This is the actual
118069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// alignment, not its logarithm.
118169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramerunsigned TargetLoweringBase::getByValTypeAlignment(Type *Ty) const {
118269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  return TD->getCallFrameTypeAlignment(Ty);
118369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer}
118469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
118569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer//===----------------------------------------------------------------------===//
118669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer//  TargetTransformInfo Helpers
118769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer//===----------------------------------------------------------------------===//
118869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
118969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramerint TargetLoweringBase::InstructionOpcodeToISD(unsigned Opcode) const {
119069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  enum InstructionOpcodes {
119169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer#define HANDLE_INST(NUM, OPCODE, CLASS) OPCODE = NUM,
119269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer#define LAST_OTHER_INST(NUM) InstructionOpcodesCount = NUM
119369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer#include "llvm/IR/Instruction.def"
119469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  };
119569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  switch (static_cast<InstructionOpcodes>(Opcode)) {
119669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case Ret:            return 0;
119769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case Br:             return 0;
119869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case Switch:         return 0;
119969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case IndirectBr:     return 0;
120069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case Invoke:         return 0;
120169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case Resume:         return 0;
120269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case Unreachable:    return 0;
120369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case Add:            return ISD::ADD;
120469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case FAdd:           return ISD::FADD;
120569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case Sub:            return ISD::SUB;
120669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case FSub:           return ISD::FSUB;
120769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case Mul:            return ISD::MUL;
120869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case FMul:           return ISD::FMUL;
120969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case UDiv:           return ISD::UDIV;
121069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case SDiv:           return ISD::UDIV;
121169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case FDiv:           return ISD::FDIV;
121269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case URem:           return ISD::UREM;
121369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case SRem:           return ISD::SREM;
121469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case FRem:           return ISD::FREM;
121569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case Shl:            return ISD::SHL;
121669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case LShr:           return ISD::SRL;
121769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case AShr:           return ISD::SRA;
121869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case And:            return ISD::AND;
121969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case Or:             return ISD::OR;
122069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case Xor:            return ISD::XOR;
122169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case Alloca:         return 0;
122269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case Load:           return ISD::LOAD;
122369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case Store:          return ISD::STORE;
122469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case GetElementPtr:  return 0;
122569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case Fence:          return 0;
122669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case AtomicCmpXchg:  return 0;
122769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case AtomicRMW:      return 0;
122869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case Trunc:          return ISD::TRUNCATE;
122969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case ZExt:           return ISD::ZERO_EXTEND;
123069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case SExt:           return ISD::SIGN_EXTEND;
123169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case FPToUI:         return ISD::FP_TO_UINT;
123269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case FPToSI:         return ISD::FP_TO_SINT;
123369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case UIToFP:         return ISD::UINT_TO_FP;
123469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case SIToFP:         return ISD::SINT_TO_FP;
123569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case FPTrunc:        return ISD::FP_ROUND;
123669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case FPExt:          return ISD::FP_EXTEND;
123769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case PtrToInt:       return ISD::BITCAST;
123869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case IntToPtr:       return ISD::BITCAST;
123969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case BitCast:        return ISD::BITCAST;
124069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case ICmp:           return ISD::SETCC;
124169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case FCmp:           return ISD::SETCC;
124269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case PHI:            return 0;
124369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case Call:           return 0;
124469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case Select:         return ISD::SELECT;
124569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case UserOp1:        return 0;
124669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case UserOp2:        return 0;
124769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case VAArg:          return 0;
124869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case ExtractElement: return ISD::EXTRACT_VECTOR_ELT;
124969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case InsertElement:  return ISD::INSERT_VECTOR_ELT;
125069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case ShuffleVector:  return ISD::VECTOR_SHUFFLE;
125169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case ExtractValue:   return ISD::MERGE_VALUES;
125269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case InsertValue:    return ISD::MERGE_VALUES;
125369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case LandingPad:     return 0;
125469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  }
125569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
125669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  llvm_unreachable("Unknown instruction type encountered!");
125769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer}
125869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
125969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramerstd::pair<unsigned, MVT>
126069e42dbd006c0afb732067ece7327988b1e24c01Benjamin KramerTargetLoweringBase::getTypeLegalizationCost(Type *Ty) const {
126169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  LLVMContext &C = Ty->getContext();
126269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  EVT MTy = getValueType(Ty);
126369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
126469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  unsigned Cost = 1;
126569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // We keep legalizing the type until we find a legal kind. We assume that
126669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // the only operation that costs anything is the split. After splitting
126769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // we need to handle two types.
126869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  while (true) {
126969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    LegalizeKind LK = getTypeConversion(C, MTy);
127069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
127169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (LK.first == TypeLegal)
127269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return std::make_pair(Cost, MTy.getSimpleVT());
127369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
127469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (LK.first == TypeSplitVector || LK.first == TypeExpandInteger)
127569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      Cost *= 2;
127669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
127769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    // Keep legalizing the type.
127869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    MTy = LK.second;
127969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  }
128069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer}
128169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
128269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer//===----------------------------------------------------------------------===//
128369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer//  Loop Strength Reduction hooks
128469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer//===----------------------------------------------------------------------===//
128569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
128669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// isLegalAddressingMode - Return true if the addressing mode represented
128769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// by AM is legal for this target, for a load/store of the specified type.
128869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramerbool TargetLoweringBase::isLegalAddressingMode(const AddrMode &AM,
128969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer                                           Type *Ty) const {
129069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // The default implementation of this implements a conservative RISCy, r+r and
129169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // r+i addr mode.
129269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
129369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // Allows a sign-extended 16-bit immediate field.
129469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  if (AM.BaseOffs <= -(1LL << 16) || AM.BaseOffs >= (1LL << 16)-1)
129569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    return false;
129669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
129769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // No global is ever allowed as a base.
129869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  if (AM.BaseGV)
129969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    return false;
130069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
130169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // Only support r+r,
130269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  switch (AM.Scale) {
130369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case 0:  // "r+i" or just "i", depending on HasBaseReg.
130469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    break;
130569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case 1:
130669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (AM.HasBaseReg && AM.BaseOffs)  // "r+r+i" is not allowed.
130769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return false;
130869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    // Otherwise we have r+r or r+i.
130969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    break;
131069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case 2:
131169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (AM.HasBaseReg || AM.BaseOffs)  // 2*r+r  or  2*r+i is not allowed.
131269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return false;
131369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    // Allow 2*r as r+r.
131469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    break;
131569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  }
131669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
131769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  return true;
131869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer}
1319