TargetLoweringBase.cpp revision 15b2782ccf141930cc98507a1cb1d501fbfd4000
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  }
36415b2782ccf141930cc98507a1cb1d501fbfd4000Michael Gottesman
36515b2782ccf141930cc98507a1cb1d501fbfd4000Michael Gottesman  if (Triple(TM.getTargetTriple()).getOS() != Triple::OpenBSD) {
36615b2782ccf141930cc98507a1cb1d501fbfd4000Michael Gottesman    Names[RTLIB::STACKPROTECTOR_CHECK_FAIL] = "__stack_chk_fail";
36715b2782ccf141930cc98507a1cb1d501fbfd4000Michael Gottesman  } else {
36815b2782ccf141930cc98507a1cb1d501fbfd4000Michael Gottesman    // These are generally not available.
36915b2782ccf141930cc98507a1cb1d501fbfd4000Michael Gottesman    Names[RTLIB::STACKPROTECTOR_CHECK_FAIL] = 0;
37015b2782ccf141930cc98507a1cb1d501fbfd4000Michael Gottesman  }
37169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer}
37269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
37369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// InitLibcallCallingConvs - Set default libcall CallingConvs.
37469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer///
37569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramerstatic void InitLibcallCallingConvs(CallingConv::ID *CCs) {
37669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  for (int i = 0; i < RTLIB::UNKNOWN_LIBCALL; ++i) {
37769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    CCs[i] = CallingConv::C;
37869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  }
37969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer}
38069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
38169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// getFPEXT - Return the FPEXT_*_* value for the given types, or
38269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// UNKNOWN_LIBCALL if there is none.
38369e42dbd006c0afb732067ece7327988b1e24c01Benjamin KramerRTLIB::Libcall RTLIB::getFPEXT(EVT OpVT, EVT RetVT) {
38469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  if (OpVT == MVT::f32) {
38569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::f64)
38669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPEXT_F32_F64;
38769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::f128)
38869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPEXT_F32_F128;
38969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  } else if (OpVT == MVT::f64) {
39069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::f128)
39169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPEXT_F64_F128;
39269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  }
39369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
39469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  return UNKNOWN_LIBCALL;
39569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer}
39669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
39769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// getFPROUND - Return the FPROUND_*_* value for the given types, or
39869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// UNKNOWN_LIBCALL if there is none.
39969e42dbd006c0afb732067ece7327988b1e24c01Benjamin KramerRTLIB::Libcall RTLIB::getFPROUND(EVT OpVT, EVT RetVT) {
40069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  if (RetVT == MVT::f32) {
40169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (OpVT == MVT::f64)
40269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPROUND_F64_F32;
40369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (OpVT == MVT::f80)
40469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPROUND_F80_F32;
40569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (OpVT == MVT::f128)
40669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPROUND_F128_F32;
40769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (OpVT == MVT::ppcf128)
40869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPROUND_PPCF128_F32;
40969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  } else if (RetVT == MVT::f64) {
41069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (OpVT == MVT::f80)
41169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPROUND_F80_F64;
41269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (OpVT == MVT::f128)
41369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPROUND_F128_F64;
41469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (OpVT == MVT::ppcf128)
41569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPROUND_PPCF128_F64;
41669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  }
41769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
41869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  return UNKNOWN_LIBCALL;
41969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer}
42069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
42169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// getFPTOSINT - Return the FPTOSINT_*_* value for the given types, or
42269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// UNKNOWN_LIBCALL if there is none.
42369e42dbd006c0afb732067ece7327988b1e24c01Benjamin KramerRTLIB::Libcall RTLIB::getFPTOSINT(EVT OpVT, EVT RetVT) {
42469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  if (OpVT == MVT::f32) {
42569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i8)
42669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOSINT_F32_I8;
42769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i16)
42869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOSINT_F32_I16;
42969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i32)
43069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOSINT_F32_I32;
43169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i64)
43269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOSINT_F32_I64;
43369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i128)
43469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOSINT_F32_I128;
43569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  } else if (OpVT == MVT::f64) {
43669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i8)
43769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOSINT_F64_I8;
43869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i16)
43969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOSINT_F64_I16;
44069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i32)
44169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOSINT_F64_I32;
44269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i64)
44369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOSINT_F64_I64;
44469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i128)
44569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOSINT_F64_I128;
44669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  } else if (OpVT == MVT::f80) {
44769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i32)
44869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOSINT_F80_I32;
44969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i64)
45069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOSINT_F80_I64;
45169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i128)
45269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOSINT_F80_I128;
45369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  } else if (OpVT == MVT::f128) {
45469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i32)
45569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOSINT_F128_I32;
45669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i64)
45769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOSINT_F128_I64;
45869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i128)
45969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOSINT_F128_I128;
46069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  } else if (OpVT == MVT::ppcf128) {
46169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i32)
46269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOSINT_PPCF128_I32;
46369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i64)
46469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOSINT_PPCF128_I64;
46569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i128)
46669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOSINT_PPCF128_I128;
46769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  }
46869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  return UNKNOWN_LIBCALL;
46969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer}
47069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
47169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// getFPTOUINT - Return the FPTOUINT_*_* value for the given types, or
47269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// UNKNOWN_LIBCALL if there is none.
47369e42dbd006c0afb732067ece7327988b1e24c01Benjamin KramerRTLIB::Libcall RTLIB::getFPTOUINT(EVT OpVT, EVT RetVT) {
47469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  if (OpVT == MVT::f32) {
47569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i8)
47669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOUINT_F32_I8;
47769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i16)
47869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOUINT_F32_I16;
47969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i32)
48069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOUINT_F32_I32;
48169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i64)
48269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOUINT_F32_I64;
48369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i128)
48469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOUINT_F32_I128;
48569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  } else if (OpVT == MVT::f64) {
48669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i8)
48769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOUINT_F64_I8;
48869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i16)
48969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOUINT_F64_I16;
49069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i32)
49169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOUINT_F64_I32;
49269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i64)
49369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOUINT_F64_I64;
49469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i128)
49569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOUINT_F64_I128;
49669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  } else if (OpVT == MVT::f80) {
49769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i32)
49869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOUINT_F80_I32;
49969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i64)
50069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOUINT_F80_I64;
50169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i128)
50269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOUINT_F80_I128;
50369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  } else if (OpVT == MVT::f128) {
50469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i32)
50569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOUINT_F128_I32;
50669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i64)
50769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOUINT_F128_I64;
50869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i128)
50969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOUINT_F128_I128;
51069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  } else if (OpVT == MVT::ppcf128) {
51169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i32)
51269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOUINT_PPCF128_I32;
51369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i64)
51469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOUINT_PPCF128_I64;
51569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::i128)
51669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return FPTOUINT_PPCF128_I128;
51769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  }
51869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  return UNKNOWN_LIBCALL;
51969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer}
52069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
52169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// getSINTTOFP - Return the SINTTOFP_*_* value for the given types, or
52269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// UNKNOWN_LIBCALL if there is none.
52369e42dbd006c0afb732067ece7327988b1e24c01Benjamin KramerRTLIB::Libcall RTLIB::getSINTTOFP(EVT OpVT, EVT RetVT) {
52469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  if (OpVT == MVT::i32) {
52569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::f32)
52669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return SINTTOFP_I32_F32;
52769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::f64)
52869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return SINTTOFP_I32_F64;
52969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::f80)
53069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return SINTTOFP_I32_F80;
53169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::f128)
53269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return SINTTOFP_I32_F128;
53369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::ppcf128)
53469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return SINTTOFP_I32_PPCF128;
53569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  } else if (OpVT == MVT::i64) {
53669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::f32)
53769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return SINTTOFP_I64_F32;
53869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::f64)
53969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return SINTTOFP_I64_F64;
54069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::f80)
54169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return SINTTOFP_I64_F80;
54269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::f128)
54369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return SINTTOFP_I64_F128;
54469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::ppcf128)
54569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return SINTTOFP_I64_PPCF128;
54669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  } else if (OpVT == MVT::i128) {
54769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::f32)
54869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return SINTTOFP_I128_F32;
54969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::f64)
55069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return SINTTOFP_I128_F64;
55169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::f80)
55269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return SINTTOFP_I128_F80;
55369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::f128)
55469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return SINTTOFP_I128_F128;
55569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::ppcf128)
55669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return SINTTOFP_I128_PPCF128;
55769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  }
55869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  return UNKNOWN_LIBCALL;
55969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer}
56069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
56169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// getUINTTOFP - Return the UINTTOFP_*_* value for the given types, or
56269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// UNKNOWN_LIBCALL if there is none.
56369e42dbd006c0afb732067ece7327988b1e24c01Benjamin KramerRTLIB::Libcall RTLIB::getUINTTOFP(EVT OpVT, EVT RetVT) {
56469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  if (OpVT == MVT::i32) {
56569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::f32)
56669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return UINTTOFP_I32_F32;
56769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::f64)
56869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return UINTTOFP_I32_F64;
56969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::f80)
57069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return UINTTOFP_I32_F80;
57169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::f128)
57269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return UINTTOFP_I32_F128;
57369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::ppcf128)
57469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return UINTTOFP_I32_PPCF128;
57569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  } else if (OpVT == MVT::i64) {
57669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::f32)
57769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return UINTTOFP_I64_F32;
57869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::f64)
57969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return UINTTOFP_I64_F64;
58069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::f80)
58169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return UINTTOFP_I64_F80;
58269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::f128)
58369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return UINTTOFP_I64_F128;
58469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::ppcf128)
58569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return UINTTOFP_I64_PPCF128;
58669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  } else if (OpVT == MVT::i128) {
58769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::f32)
58869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return UINTTOFP_I128_F32;
58969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::f64)
59069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return UINTTOFP_I128_F64;
59169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::f80)
59269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return UINTTOFP_I128_F80;
59369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::f128)
59469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return UINTTOFP_I128_F128;
59569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (RetVT == MVT::ppcf128)
59669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return UINTTOFP_I128_PPCF128;
59769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  }
59869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  return UNKNOWN_LIBCALL;
59969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer}
60069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
60169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// InitCmpLibcallCCs - Set default comparison libcall CC.
60269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer///
60369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramerstatic void InitCmpLibcallCCs(ISD::CondCode *CCs) {
60469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  memset(CCs, ISD::SETCC_INVALID, sizeof(ISD::CondCode)*RTLIB::UNKNOWN_LIBCALL);
60569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  CCs[RTLIB::OEQ_F32] = ISD::SETEQ;
60669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  CCs[RTLIB::OEQ_F64] = ISD::SETEQ;
60769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  CCs[RTLIB::OEQ_F128] = ISD::SETEQ;
60869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  CCs[RTLIB::UNE_F32] = ISD::SETNE;
60969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  CCs[RTLIB::UNE_F64] = ISD::SETNE;
61069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  CCs[RTLIB::UNE_F128] = ISD::SETNE;
61169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  CCs[RTLIB::OGE_F32] = ISD::SETGE;
61269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  CCs[RTLIB::OGE_F64] = ISD::SETGE;
61369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  CCs[RTLIB::OGE_F128] = ISD::SETGE;
61469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  CCs[RTLIB::OLT_F32] = ISD::SETLT;
61569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  CCs[RTLIB::OLT_F64] = ISD::SETLT;
61669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  CCs[RTLIB::OLT_F128] = ISD::SETLT;
61769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  CCs[RTLIB::OLE_F32] = ISD::SETLE;
61869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  CCs[RTLIB::OLE_F64] = ISD::SETLE;
61969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  CCs[RTLIB::OLE_F128] = ISD::SETLE;
62069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  CCs[RTLIB::OGT_F32] = ISD::SETGT;
62169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  CCs[RTLIB::OGT_F64] = ISD::SETGT;
62269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  CCs[RTLIB::OGT_F128] = ISD::SETGT;
62369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  CCs[RTLIB::UO_F32] = ISD::SETNE;
62469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  CCs[RTLIB::UO_F64] = ISD::SETNE;
62569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  CCs[RTLIB::UO_F128] = ISD::SETNE;
62669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  CCs[RTLIB::O_F32] = ISD::SETEQ;
62769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  CCs[RTLIB::O_F64] = ISD::SETEQ;
62869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  CCs[RTLIB::O_F128] = ISD::SETEQ;
62969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer}
63069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
63169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// NOTE: The constructor takes ownership of TLOF.
63269e42dbd006c0afb732067ece7327988b1e24c01Benjamin KramerTargetLoweringBase::TargetLoweringBase(const TargetMachine &tm,
63369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer                                       const TargetLoweringObjectFile *tlof)
63469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  : TM(tm), TD(TM.getDataLayout()), TLOF(*tlof) {
63513bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  initActions();
63613bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling
63713bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  // Perform these initializations only once.
63813bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  IsLittleEndian = TD->isLittleEndian();
63913bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  PointerTy = MVT::getIntegerVT(8*TD->getPointerSize(0));
64013bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  MaxStoresPerMemset = MaxStoresPerMemcpy = MaxStoresPerMemmove = 8;
64113bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  MaxStoresPerMemsetOptSize = MaxStoresPerMemcpyOptSize
64213bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling    = MaxStoresPerMemmoveOptSize = 4;
64313bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  UseUnderscoreSetJmp = false;
64413bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  UseUnderscoreLongJmp = false;
64513bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  SelectIsExpensive = false;
64613bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  IntDivIsCheap = false;
64713bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  Pow2DivIsCheap = false;
64813bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  JumpIsExpensive = false;
64913bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  PredictableSelectIsExpensive = false;
65013bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  StackPointerRegisterToSaveRestore = 0;
65113bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  ExceptionPointerRegister = 0;
65213bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  ExceptionSelectorRegister = 0;
65313bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  BooleanContents = UndefinedBooleanContent;
65413bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  BooleanVectorContents = UndefinedBooleanContent;
65513bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  SchedPreferenceInfo = Sched::ILP;
65613bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  JumpBufSize = 0;
65713bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  JumpBufAlignment = 0;
65813bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  MinFunctionAlignment = 0;
65913bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  PrefFunctionAlignment = 0;
66013bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  PrefLoopAlignment = 0;
66113bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  MinStackArgumentAlignment = 1;
66213bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  InsertFencesForAtomic = false;
66313bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  SupportJumpTables = true;
66413bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  MinimumJumpTableEntries = 4;
66513bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling
66613bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  InitLibcallNames(LibcallRoutineNames, TM);
66713bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  InitCmpLibcallCCs(CmpLibcallCCs);
66813bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  InitLibcallCallingConvs(LibcallCallingConvs);
66913bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling}
67013bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling
67113bbe1f52e8d57151e2730db49094e1c62a4c793Bill WendlingTargetLoweringBase::~TargetLoweringBase() {
67213bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  delete &TLOF;
67313bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling}
67413bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling
67513bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendlingvoid TargetLoweringBase::initActions() {
67669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // All operations default to being supported.
67769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  memset(OpActions, 0, sizeof(OpActions));
67869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  memset(LoadExtActions, 0, sizeof(LoadExtActions));
67969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  memset(TruncStoreActions, 0, sizeof(TruncStoreActions));
68069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  memset(IndexedModeActions, 0, sizeof(IndexedModeActions));
68169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  memset(CondCodeActions, 0, sizeof(CondCodeActions));
68213bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  memset(RegClassForVT, 0,MVT::LAST_VALUETYPE*sizeof(TargetRegisterClass*));
68313bbe1f52e8d57151e2730db49094e1c62a4c793Bill Wendling  memset(TargetDAGCombineArray, 0, array_lengthof(TargetDAGCombineArray));
68469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
68569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // Set default actions for various operations.
68669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  for (unsigned VT = 0; VT != (unsigned)MVT::LAST_VALUETYPE; ++VT) {
68769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    // Default all indexed load / store to expand.
68869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    for (unsigned IM = (unsigned)ISD::PRE_INC;
68969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer         IM != (unsigned)ISD::LAST_INDEXED_MODE; ++IM) {
69069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      setIndexedLoadAction(IM, (MVT::SimpleValueType)VT, Expand);
69169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      setIndexedStoreAction(IM, (MVT::SimpleValueType)VT, Expand);
69269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    }
69369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
69469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    // These operations default to expand.
69569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    setOperationAction(ISD::FGETSIGN, (MVT::SimpleValueType)VT, Expand);
69669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    setOperationAction(ISD::CONCAT_VECTORS, (MVT::SimpleValueType)VT, Expand);
6973d7f79a02e143cfcbc85ea2091f2797285a9db84Hal Finkel
6983d7f79a02e143cfcbc85ea2091f2797285a9db84Hal Finkel    // These library functions default to expand.
6993d7f79a02e143cfcbc85ea2091f2797285a9db84Hal Finkel    setOperationAction(ISD::FROUND, (MVT::SimpleValueType)VT, Expand);
70069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  }
70169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
70269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // Most targets ignore the @llvm.prefetch intrinsic.
70369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::PREFETCH, MVT::Other, Expand);
70469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
70569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // ConstantFP nodes default to expand.  Targets can either change this to
70669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // Legal, in which case all fp constants are legal, or use isFPImmLegal()
70769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // to optimize expansions for certain constants.
70869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::ConstantFP, MVT::f16, Expand);
70969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::ConstantFP, MVT::f32, Expand);
71069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::ConstantFP, MVT::f64, Expand);
71169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::ConstantFP, MVT::f80, Expand);
71269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::ConstantFP, MVT::f128, Expand);
71369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
71469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // These library functions default to expand.
71569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::FLOG ,  MVT::f16, Expand);
71669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::FLOG2,  MVT::f16, Expand);
71769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::FLOG10, MVT::f16, Expand);
71869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::FEXP ,  MVT::f16, Expand);
71969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::FEXP2,  MVT::f16, Expand);
72069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::FFLOOR, MVT::f16, Expand);
72169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::FNEARBYINT, MVT::f16, Expand);
72269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::FCEIL,  MVT::f16, Expand);
72369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::FRINT,  MVT::f16, Expand);
72469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::FTRUNC, MVT::f16, Expand);
72569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::FLOG ,  MVT::f32, Expand);
72669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::FLOG2,  MVT::f32, Expand);
72769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::FLOG10, MVT::f32, Expand);
72869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::FEXP ,  MVT::f32, Expand);
72969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::FEXP2,  MVT::f32, Expand);
73069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::FFLOOR, MVT::f32, Expand);
73169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::FNEARBYINT, MVT::f32, Expand);
73269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::FCEIL,  MVT::f32, Expand);
73369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::FRINT,  MVT::f32, Expand);
73469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::FTRUNC, MVT::f32, Expand);
73569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::FLOG ,  MVT::f64, Expand);
73669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::FLOG2,  MVT::f64, Expand);
73769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::FLOG10, MVT::f64, Expand);
73869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::FEXP ,  MVT::f64, Expand);
73969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::FEXP2,  MVT::f64, Expand);
74069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::FFLOOR, MVT::f64, Expand);
74169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::FNEARBYINT, MVT::f64, Expand);
74269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::FCEIL,  MVT::f64, Expand);
74369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::FRINT,  MVT::f64, Expand);
74469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::FTRUNC, MVT::f64, Expand);
74569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::FLOG ,  MVT::f128, Expand);
74669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::FLOG2,  MVT::f128, Expand);
74769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::FLOG10, MVT::f128, Expand);
74869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::FEXP ,  MVT::f128, Expand);
74969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::FEXP2,  MVT::f128, Expand);
75069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::FFLOOR, MVT::f128, Expand);
75169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::FNEARBYINT, MVT::f128, Expand);
75269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::FCEIL,  MVT::f128, Expand);
75369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::FRINT,  MVT::f128, Expand);
75469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::FTRUNC, MVT::f128, Expand);
75569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
75669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // Default ISD::TRAP to expand (which turns it into abort).
75769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::TRAP, MVT::Other, Expand);
75869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
75969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // On most systems, DEBUGTRAP and TRAP have no difference. The "Expand"
76069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // here is to inform DAG Legalizer to replace DEBUGTRAP with TRAP.
76169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  //
76269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  setOperationAction(ISD::DEBUGTRAP, MVT::Other, Expand);
76369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer}
76469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
765a6b20ced765b67a85d9219d0c8547fc9c133e14fMichael LiaoMVT TargetLoweringBase::getScalarShiftAmountTy(EVT LHSTy) const {
76669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  return MVT::getIntegerVT(8*TD->getPointerSize(0));
76769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer}
76869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
769a6b20ced765b67a85d9219d0c8547fc9c133e14fMichael LiaoEVT TargetLoweringBase::getShiftAmountTy(EVT LHSTy) const {
770a6b20ced765b67a85d9219d0c8547fc9c133e14fMichael Liao  assert(LHSTy.isInteger() && "Shift amount is not an integer type!");
771a6b20ced765b67a85d9219d0c8547fc9c133e14fMichael Liao  if (LHSTy.isVector())
772a6b20ced765b67a85d9219d0c8547fc9c133e14fMichael Liao    return LHSTy;
773a6b20ced765b67a85d9219d0c8547fc9c133e14fMichael Liao  return getScalarShiftAmountTy(LHSTy);
774a6b20ced765b67a85d9219d0c8547fc9c133e14fMichael Liao}
775a6b20ced765b67a85d9219d0c8547fc9c133e14fMichael Liao
77669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// canOpTrap - Returns true if the operation can trap for the value type.
77769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// VT must be a legal type.
77869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramerbool TargetLoweringBase::canOpTrap(unsigned Op, EVT VT) const {
77969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  assert(isTypeLegal(VT));
78069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  switch (Op) {
78169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  default:
78269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    return false;
78369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case ISD::FDIV:
78469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case ISD::FREM:
78569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case ISD::SDIV:
78669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case ISD::UDIV:
78769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case ISD::SREM:
78869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case ISD::UREM:
78969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    return true;
79069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  }
79169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer}
79269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
79369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
79469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramerstatic unsigned getVectorTypeBreakdownMVT(MVT VT, MVT &IntermediateVT,
79569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer                                          unsigned &NumIntermediates,
79669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer                                          MVT &RegisterVT,
79769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer                                          TargetLoweringBase *TLI) {
79869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // Figure out the right, legal destination reg to copy into.
79969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  unsigned NumElts = VT.getVectorNumElements();
80069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  MVT EltTy = VT.getVectorElementType();
80169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
80269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  unsigned NumVectorRegs = 1;
80369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
80469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // FIXME: We don't support non-power-of-2-sized vectors for now.  Ideally we
80569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // could break down into LHS/RHS like LegalizeDAG does.
80669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  if (!isPowerOf2_32(NumElts)) {
80769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    NumVectorRegs = NumElts;
80869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    NumElts = 1;
80969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  }
81069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
81169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // Divide the input until we get to a supported size.  This will always
81269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // end with a scalar if the target doesn't support vectors.
81369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  while (NumElts > 1 && !TLI->isTypeLegal(MVT::getVectorVT(EltTy, NumElts))) {
81469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    NumElts >>= 1;
81569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    NumVectorRegs <<= 1;
81669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  }
81769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
81869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  NumIntermediates = NumVectorRegs;
81969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
82069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  MVT NewVT = MVT::getVectorVT(EltTy, NumElts);
82169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  if (!TLI->isTypeLegal(NewVT))
82269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    NewVT = EltTy;
82369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  IntermediateVT = NewVT;
82469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
82569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  unsigned NewVTSize = NewVT.getSizeInBits();
82669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
82769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // Convert sizes such as i33 to i64.
82869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  if (!isPowerOf2_32(NewVTSize))
82969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    NewVTSize = NextPowerOf2(NewVTSize);
83069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
83169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  MVT DestVT = TLI->getRegisterType(NewVT);
83269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  RegisterVT = DestVT;
83369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  if (EVT(DestVT).bitsLT(NewVT))    // Value is expanded, e.g. i64 -> i16.
83469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    return NumVectorRegs*(NewVTSize/DestVT.getSizeInBits());
83569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
83669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // Otherwise, promotion or legal types use the same number of registers as
83769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // the vector decimated to the appropriate level.
83869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  return NumVectorRegs;
83969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer}
84069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
84169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// isLegalRC - Return true if the value types that can be represented by the
84269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// specified register class are all legal.
84369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramerbool TargetLoweringBase::isLegalRC(const TargetRegisterClass *RC) const {
84469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  for (TargetRegisterClass::vt_iterator I = RC->vt_begin(), E = RC->vt_end();
84569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer       I != E; ++I) {
84669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (isTypeLegal(*I))
84769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return true;
84869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  }
84969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  return false;
85069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer}
85169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
85269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// findRepresentativeClass - Return the largest legal super-reg register class
85369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// of the register class for the specified type and its associated "cost".
85469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramerstd::pair<const TargetRegisterClass*, uint8_t>
85569e42dbd006c0afb732067ece7327988b1e24c01Benjamin KramerTargetLoweringBase::findRepresentativeClass(MVT VT) const {
85669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  const TargetRegisterInfo *TRI = getTargetMachine().getRegisterInfo();
85769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  const TargetRegisterClass *RC = RegClassForVT[VT.SimpleTy];
85869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  if (!RC)
85969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    return std::make_pair(RC, 0);
86069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
86169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // Compute the set of all super-register classes.
86269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  BitVector SuperRegRC(TRI->getNumRegClasses());
86369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  for (SuperRegClassIterator RCI(RC, TRI); RCI.isValid(); ++RCI)
86469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    SuperRegRC.setBitsInMask(RCI.getMask());
86569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
86669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // Find the first legal register class with the largest spill size.
86769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  const TargetRegisterClass *BestRC = RC;
86869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  for (int i = SuperRegRC.find_first(); i >= 0; i = SuperRegRC.find_next(i)) {
86969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    const TargetRegisterClass *SuperRC = TRI->getRegClass(i);
87069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    // We want the largest possible spill size.
87169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (SuperRC->getSize() <= BestRC->getSize())
87269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      continue;
87369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (!isLegalRC(SuperRC))
87469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      continue;
87569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    BestRC = SuperRC;
87669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  }
87769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  return std::make_pair(BestRC, 1);
87869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer}
87969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
88069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// computeRegisterProperties - Once all of the register classes are added,
88169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// this allows us to compute derived properties we expose.
88269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramervoid TargetLoweringBase::computeRegisterProperties() {
88369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  assert(MVT::LAST_VALUETYPE <= MVT::MAX_ALLOWED_VALUETYPE &&
88469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer         "Too many value types for ValueTypeActions to hold!");
88569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
88669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // Everything defaults to needing one register.
88769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  for (unsigned i = 0; i != MVT::LAST_VALUETYPE; ++i) {
88869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    NumRegistersForVT[i] = 1;
88969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    RegisterTypeForVT[i] = TransformToType[i] = (MVT::SimpleValueType)i;
89069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  }
89169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // ...except isVoid, which doesn't need any registers.
89269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  NumRegistersForVT[MVT::isVoid] = 0;
89369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
89469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // Find the largest integer register class.
89569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  unsigned LargestIntReg = MVT::LAST_INTEGER_VALUETYPE;
89669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  for (; RegClassForVT[LargestIntReg] == 0; --LargestIntReg)
89769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    assert(LargestIntReg != MVT::i1 && "No integer registers defined!");
89869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
89969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // Every integer value type larger than this largest register takes twice as
90069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // many registers to represent as the previous ValueType.
90169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  for (unsigned ExpandedReg = LargestIntReg + 1;
90269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer       ExpandedReg <= MVT::LAST_INTEGER_VALUETYPE; ++ExpandedReg) {
90369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    NumRegistersForVT[ExpandedReg] = 2*NumRegistersForVT[ExpandedReg-1];
90469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    RegisterTypeForVT[ExpandedReg] = (MVT::SimpleValueType)LargestIntReg;
90569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    TransformToType[ExpandedReg] = (MVT::SimpleValueType)(ExpandedReg - 1);
90669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    ValueTypeActions.setTypeAction((MVT::SimpleValueType)ExpandedReg,
90769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer                                   TypeExpandInteger);
90869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  }
90969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
91069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // Inspect all of the ValueType's smaller than the largest integer
91169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // register to see which ones need promotion.
91269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  unsigned LegalIntReg = LargestIntReg;
91369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  for (unsigned IntReg = LargestIntReg - 1;
91469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer       IntReg >= (unsigned)MVT::i1; --IntReg) {
91569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    MVT IVT = (MVT::SimpleValueType)IntReg;
91669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (isTypeLegal(IVT)) {
91769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      LegalIntReg = IntReg;
91869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    } else {
91969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      RegisterTypeForVT[IntReg] = TransformToType[IntReg] =
92069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer        (const MVT::SimpleValueType)LegalIntReg;
92169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      ValueTypeActions.setTypeAction(IVT, TypePromoteInteger);
92269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    }
92369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  }
92469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
92569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // ppcf128 type is really two f64's.
92669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  if (!isTypeLegal(MVT::ppcf128)) {
92769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    NumRegistersForVT[MVT::ppcf128] = 2*NumRegistersForVT[MVT::f64];
92869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    RegisterTypeForVT[MVT::ppcf128] = MVT::f64;
92969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    TransformToType[MVT::ppcf128] = MVT::f64;
93069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    ValueTypeActions.setTypeAction(MVT::ppcf128, TypeExpandFloat);
93169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  }
93269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
933c3c3810f514af7e08f84ef76b0c304ec264ee021Akira Hatanaka  // Decide how to handle f128. If the target does not have native f128 support,
934c3c3810f514af7e08f84ef76b0c304ec264ee021Akira Hatanaka  // expand it to i128 and we will be generating soft float library calls.
935c3c3810f514af7e08f84ef76b0c304ec264ee021Akira Hatanaka  if (!isTypeLegal(MVT::f128)) {
936c3c3810f514af7e08f84ef76b0c304ec264ee021Akira Hatanaka    NumRegistersForVT[MVT::f128] = NumRegistersForVT[MVT::i128];
937c3c3810f514af7e08f84ef76b0c304ec264ee021Akira Hatanaka    RegisterTypeForVT[MVT::f128] = RegisterTypeForVT[MVT::i128];
938c3c3810f514af7e08f84ef76b0c304ec264ee021Akira Hatanaka    TransformToType[MVT::f128] = MVT::i128;
939c3c3810f514af7e08f84ef76b0c304ec264ee021Akira Hatanaka    ValueTypeActions.setTypeAction(MVT::f128, TypeSoftenFloat);
940c3c3810f514af7e08f84ef76b0c304ec264ee021Akira Hatanaka  }
941c3c3810f514af7e08f84ef76b0c304ec264ee021Akira Hatanaka
94269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // Decide how to handle f64. If the target does not have native f64 support,
94369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // expand it to i64 and we will be generating soft float library calls.
94469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  if (!isTypeLegal(MVT::f64)) {
94569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    NumRegistersForVT[MVT::f64] = NumRegistersForVT[MVT::i64];
94669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    RegisterTypeForVT[MVT::f64] = RegisterTypeForVT[MVT::i64];
94769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    TransformToType[MVT::f64] = MVT::i64;
94869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    ValueTypeActions.setTypeAction(MVT::f64, TypeSoftenFloat);
94969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  }
95069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
95169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // Decide how to handle f32. If the target does not have native support for
95269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // f32, promote it to f64 if it is legal. Otherwise, expand it to i32.
95369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  if (!isTypeLegal(MVT::f32)) {
95469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (isTypeLegal(MVT::f64)) {
95569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      NumRegistersForVT[MVT::f32] = NumRegistersForVT[MVT::f64];
95669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      RegisterTypeForVT[MVT::f32] = RegisterTypeForVT[MVT::f64];
95769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      TransformToType[MVT::f32] = MVT::f64;
95869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      ValueTypeActions.setTypeAction(MVT::f32, TypePromoteInteger);
95969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    } else {
96069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      NumRegistersForVT[MVT::f32] = NumRegistersForVT[MVT::i32];
96169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      RegisterTypeForVT[MVT::f32] = RegisterTypeForVT[MVT::i32];
96269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      TransformToType[MVT::f32] = MVT::i32;
96369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      ValueTypeActions.setTypeAction(MVT::f32, TypeSoftenFloat);
96469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    }
96569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  }
96669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
96769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // Loop over all of the vector value types to see which need transformations.
96869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  for (unsigned i = MVT::FIRST_VECTOR_VALUETYPE;
96969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer       i <= (unsigned)MVT::LAST_VECTOR_VALUETYPE; ++i) {
97069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    MVT VT = (MVT::SimpleValueType)i;
97169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (isTypeLegal(VT)) continue;
97269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
97369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    // Determine if there is a legal wider type.  If so, we should promote to
97469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    // that wider vector type.
97569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    MVT EltVT = VT.getVectorElementType();
97669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    unsigned NElts = VT.getVectorNumElements();
97769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (NElts != 1 && !shouldSplitVectorElementType(EltVT)) {
97869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      bool IsLegalWiderType = false;
97969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      // First try to promote the elements of integer vectors. If no legal
98069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      // promotion was found, fallback to the widen-vector method.
98169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      for (unsigned nVT = i+1; nVT <= MVT::LAST_VECTOR_VALUETYPE; ++nVT) {
98269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer        MVT SVT = (MVT::SimpleValueType)nVT;
98369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer        // Promote vectors of integers to vectors with the same number
98469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer        // of elements, with a wider element type.
98569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer        if (SVT.getVectorElementType().getSizeInBits() > EltVT.getSizeInBits()
98669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer            && SVT.getVectorNumElements() == NElts &&
98769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer            isTypeLegal(SVT) && SVT.getScalarType().isInteger()) {
98869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer          TransformToType[i] = SVT;
98969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer          RegisterTypeForVT[i] = SVT;
99069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer          NumRegistersForVT[i] = 1;
99169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer          ValueTypeActions.setTypeAction(VT, TypePromoteInteger);
99269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer          IsLegalWiderType = true;
99369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer          break;
99469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer        }
99569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      }
99669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
99769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      if (IsLegalWiderType) continue;
99869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
99969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      // Try to widen the vector.
100069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      for (unsigned nVT = i+1; nVT <= MVT::LAST_VECTOR_VALUETYPE; ++nVT) {
100169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer        MVT SVT = (MVT::SimpleValueType)nVT;
100269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer        if (SVT.getVectorElementType() == EltVT &&
100369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer            SVT.getVectorNumElements() > NElts &&
100469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer            isTypeLegal(SVT)) {
100569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer          TransformToType[i] = SVT;
100669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer          RegisterTypeForVT[i] = SVT;
100769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer          NumRegistersForVT[i] = 1;
100869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer          ValueTypeActions.setTypeAction(VT, TypeWidenVector);
100969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer          IsLegalWiderType = true;
101069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer          break;
101169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer        }
101269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      }
101369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      if (IsLegalWiderType) continue;
101469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    }
101569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
101669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    MVT IntermediateVT;
101769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    MVT RegisterVT;
101869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    unsigned NumIntermediates;
101969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    NumRegistersForVT[i] =
102069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      getVectorTypeBreakdownMVT(VT, IntermediateVT, NumIntermediates,
102169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer                                RegisterVT, this);
102269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    RegisterTypeForVT[i] = RegisterVT;
102369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
102469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    MVT NVT = VT.getPow2VectorType();
102569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (NVT == VT) {
102669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      // Type is already a power of 2.  The default action is to split.
102769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      TransformToType[i] = MVT::Other;
102869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      unsigned NumElts = VT.getVectorNumElements();
102969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      ValueTypeActions.setTypeAction(VT,
103069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer            NumElts > 1 ? TypeSplitVector : TypeScalarizeVector);
103169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    } else {
103269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      TransformToType[i] = NVT;
103369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      ValueTypeActions.setTypeAction(VT, TypeWidenVector);
103469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    }
103569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  }
103669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
103769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // Determine the 'representative' register class for each value type.
103869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // An representative register class is the largest (meaning one which is
103969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // not a sub-register class / subreg register class) legal register class for
104069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // a group of value types. For example, on i386, i8, i16, and i32
104169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // representative would be GR32; while on x86_64 it's GR64.
104269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  for (unsigned i = 0; i != MVT::LAST_VALUETYPE; ++i) {
104369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    const TargetRegisterClass* RRC;
104469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    uint8_t Cost;
104569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    tie(RRC, Cost) =  findRepresentativeClass((MVT::SimpleValueType)i);
104669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    RepRegClassForVT[i] = RRC;
104769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    RepRegClassCostForVT[i] = Cost;
104869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  }
104969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer}
105069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
1051225ed7069caae9ece32d8bd3d15c6e41e21cc04bMatt ArsenaultEVT TargetLoweringBase::getSetCCResultType(LLVMContext &, EVT VT) const {
105269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  assert(!VT.isVector() && "No default SetCC type for vectors!");
105369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  return getPointerTy(0).SimpleTy;
105469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer}
105569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
105669e42dbd006c0afb732067ece7327988b1e24c01Benjamin KramerMVT::SimpleValueType TargetLoweringBase::getCmpLibcallReturnType() const {
105769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  return MVT::i32; // return the default value
105869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer}
105969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
106069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// getVectorTypeBreakdown - Vector types are broken down into some number of
106169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// legal first class types.  For example, MVT::v8f32 maps to 2 MVT::v4f32
106269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// with Altivec or SSE1, or 8 promoted MVT::f64 values with the X86 FP stack.
106369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// Similarly, MVT::v2i64 turns into 4 MVT::i32 values with both PPC and X86.
106469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer///
106569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// This method returns the number of registers needed, and the VT for each
106669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// register.  It also returns the VT and quantity of the intermediate values
106769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// before they are promoted/expanded.
106869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer///
106969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramerunsigned TargetLoweringBase::getVectorTypeBreakdown(LLVMContext &Context, EVT VT,
107069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer                                                EVT &IntermediateVT,
107169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer                                                unsigned &NumIntermediates,
107269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer                                                MVT &RegisterVT) const {
107369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  unsigned NumElts = VT.getVectorNumElements();
107469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
107569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // If there is a wider vector type with the same element type as this one,
107669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // or a promoted vector type that has the same number of elements which
107769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // are wider, then we should convert to that legal vector type.
107869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // This handles things like <2 x float> -> <4 x float> and
107969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // <4 x i1> -> <4 x i32>.
108069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  LegalizeTypeAction TA = getTypeAction(Context, VT);
108169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  if (NumElts != 1 && (TA == TypeWidenVector || TA == TypePromoteInteger)) {
108269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    EVT RegisterEVT = getTypeToTransformTo(Context, VT);
108369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (isTypeLegal(RegisterEVT)) {
108469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      IntermediateVT = RegisterEVT;
108569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      RegisterVT = RegisterEVT.getSimpleVT();
108669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      NumIntermediates = 1;
108769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return 1;
108869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    }
108969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  }
109069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
109169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // Figure out the right, legal destination reg to copy into.
109269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  EVT EltTy = VT.getVectorElementType();
109369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
109469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  unsigned NumVectorRegs = 1;
109569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
109669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // FIXME: We don't support non-power-of-2-sized vectors for now.  Ideally we
109769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // could break down into LHS/RHS like LegalizeDAG does.
109869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  if (!isPowerOf2_32(NumElts)) {
109969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    NumVectorRegs = NumElts;
110069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    NumElts = 1;
110169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  }
110269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
110369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // Divide the input until we get to a supported size.  This will always
110469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // end with a scalar if the target doesn't support vectors.
110569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  while (NumElts > 1 && !isTypeLegal(
110669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer                                   EVT::getVectorVT(Context, EltTy, NumElts))) {
110769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    NumElts >>= 1;
110869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    NumVectorRegs <<= 1;
110969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  }
111069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
111169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  NumIntermediates = NumVectorRegs;
111269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
111369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  EVT NewVT = EVT::getVectorVT(Context, EltTy, NumElts);
111469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  if (!isTypeLegal(NewVT))
111569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    NewVT = EltTy;
111669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  IntermediateVT = NewVT;
111769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
111869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  MVT DestVT = getRegisterType(Context, NewVT);
111969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  RegisterVT = DestVT;
112069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  unsigned NewVTSize = NewVT.getSizeInBits();
112169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
112269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // Convert sizes such as i33 to i64.
112369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  if (!isPowerOf2_32(NewVTSize))
112469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    NewVTSize = NextPowerOf2(NewVTSize);
112569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
112669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  if (EVT(DestVT).bitsLT(NewVT))   // Value is expanded, e.g. i64 -> i16.
112769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    return NumVectorRegs*(NewVTSize/DestVT.getSizeInBits());
112869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
112969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // Otherwise, promotion or legal types use the same number of registers as
113069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // the vector decimated to the appropriate level.
113169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  return NumVectorRegs;
113269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer}
113369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
113469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// Get the EVTs and ArgFlags collections that represent the legalized return
113569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// type of the given function.  This does not require a DAG or a return value,
113669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// and is suitable for use before any DAGs for the function are constructed.
113769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// TODO: Move this out of TargetLowering.cpp.
113869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramervoid llvm::GetReturnInfo(Type* ReturnType, AttributeSet attr,
113969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer                         SmallVectorImpl<ISD::OutputArg> &Outs,
114069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer                         const TargetLowering &TLI) {
114169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  SmallVector<EVT, 4> ValueVTs;
114269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  ComputeValueVTs(TLI, ReturnType, ValueVTs);
114369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  unsigned NumValues = ValueVTs.size();
114469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  if (NumValues == 0) return;
114569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
114669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  for (unsigned j = 0, f = NumValues; j != f; ++j) {
114769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    EVT VT = ValueVTs[j];
114869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    ISD::NodeType ExtendKind = ISD::ANY_EXTEND;
114969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
115069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (attr.hasAttribute(AttributeSet::ReturnIndex, Attribute::SExt))
115169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      ExtendKind = ISD::SIGN_EXTEND;
115269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    else if (attr.hasAttribute(AttributeSet::ReturnIndex, Attribute::ZExt))
115369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      ExtendKind = ISD::ZERO_EXTEND;
115469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
115569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    // FIXME: C calling convention requires the return type to be promoted to
115669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    // at least 32-bit. But this is not necessary for non-C calling
115769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    // conventions. The frontend should mark functions whose return values
115869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    // require promoting with signext or zeroext attributes.
115969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (ExtendKind != ISD::ANY_EXTEND && VT.isInteger()) {
116069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      MVT MinVT = TLI.getRegisterType(ReturnType->getContext(), MVT::i32);
116169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      if (VT.bitsLT(MinVT))
116269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer        VT = MinVT;
116369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    }
116469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
116569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    unsigned NumParts = TLI.getNumRegisters(ReturnType->getContext(), VT);
116669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    MVT PartVT = TLI.getRegisterType(ReturnType->getContext(), VT);
116769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
116869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    // 'inreg' on function refers to return value
116969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    ISD::ArgFlagsTy Flags = ISD::ArgFlagsTy();
117069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (attr.hasAttribute(AttributeSet::ReturnIndex, Attribute::InReg))
117169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      Flags.setInReg();
117269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
117369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    // Propagate extension type if any
117469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (attr.hasAttribute(AttributeSet::ReturnIndex, Attribute::SExt))
117569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      Flags.setSExt();
117669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    else if (attr.hasAttribute(AttributeSet::ReturnIndex, Attribute::ZExt))
117769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      Flags.setZExt();
117869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
117969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    for (unsigned i = 0; i < NumParts; ++i)
118069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      Outs.push_back(ISD::OutputArg(Flags, PartVT, /*isFixed=*/true, 0, 0));
118169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  }
118269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer}
118369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
118469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// getByValTypeAlignment - Return the desired alignment for ByVal aggregate
118569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// function arguments in the caller parameter area.  This is the actual
118669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// alignment, not its logarithm.
118769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramerunsigned TargetLoweringBase::getByValTypeAlignment(Type *Ty) const {
118869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  return TD->getCallFrameTypeAlignment(Ty);
118969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer}
119069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
119169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer//===----------------------------------------------------------------------===//
119269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer//  TargetTransformInfo Helpers
119369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer//===----------------------------------------------------------------------===//
119469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
119569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramerint TargetLoweringBase::InstructionOpcodeToISD(unsigned Opcode) const {
119669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  enum InstructionOpcodes {
119769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer#define HANDLE_INST(NUM, OPCODE, CLASS) OPCODE = NUM,
119869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer#define LAST_OTHER_INST(NUM) InstructionOpcodesCount = NUM
119969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer#include "llvm/IR/Instruction.def"
120069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  };
120169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  switch (static_cast<InstructionOpcodes>(Opcode)) {
120269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case Ret:            return 0;
120369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case Br:             return 0;
120469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case Switch:         return 0;
120569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case IndirectBr:     return 0;
120669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case Invoke:         return 0;
120769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case Resume:         return 0;
120869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case Unreachable:    return 0;
120969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case Add:            return ISD::ADD;
121069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case FAdd:           return ISD::FADD;
121169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case Sub:            return ISD::SUB;
121269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case FSub:           return ISD::FSUB;
121369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case Mul:            return ISD::MUL;
121469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case FMul:           return ISD::FMUL;
121569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case UDiv:           return ISD::UDIV;
121669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case SDiv:           return ISD::UDIV;
121769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case FDiv:           return ISD::FDIV;
121869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case URem:           return ISD::UREM;
121969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case SRem:           return ISD::SREM;
122069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case FRem:           return ISD::FREM;
122169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case Shl:            return ISD::SHL;
122269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case LShr:           return ISD::SRL;
122369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case AShr:           return ISD::SRA;
122469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case And:            return ISD::AND;
122569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case Or:             return ISD::OR;
122669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case Xor:            return ISD::XOR;
122769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case Alloca:         return 0;
122869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case Load:           return ISD::LOAD;
122969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case Store:          return ISD::STORE;
123069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case GetElementPtr:  return 0;
123169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case Fence:          return 0;
123269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case AtomicCmpXchg:  return 0;
123369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case AtomicRMW:      return 0;
123469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case Trunc:          return ISD::TRUNCATE;
123569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case ZExt:           return ISD::ZERO_EXTEND;
123669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case SExt:           return ISD::SIGN_EXTEND;
123769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case FPToUI:         return ISD::FP_TO_UINT;
123869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case FPToSI:         return ISD::FP_TO_SINT;
123969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case UIToFP:         return ISD::UINT_TO_FP;
124069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case SIToFP:         return ISD::SINT_TO_FP;
124169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case FPTrunc:        return ISD::FP_ROUND;
124269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case FPExt:          return ISD::FP_EXTEND;
124369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case PtrToInt:       return ISD::BITCAST;
124469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case IntToPtr:       return ISD::BITCAST;
124569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case BitCast:        return ISD::BITCAST;
124669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case ICmp:           return ISD::SETCC;
124769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case FCmp:           return ISD::SETCC;
124869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case PHI:            return 0;
124969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case Call:           return 0;
125069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case Select:         return ISD::SELECT;
125169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case UserOp1:        return 0;
125269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case UserOp2:        return 0;
125369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case VAArg:          return 0;
125469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case ExtractElement: return ISD::EXTRACT_VECTOR_ELT;
125569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case InsertElement:  return ISD::INSERT_VECTOR_ELT;
125669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case ShuffleVector:  return ISD::VECTOR_SHUFFLE;
125769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case ExtractValue:   return ISD::MERGE_VALUES;
125869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case InsertValue:    return ISD::MERGE_VALUES;
125969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case LandingPad:     return 0;
126069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  }
126169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
126269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  llvm_unreachable("Unknown instruction type encountered!");
126369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer}
126469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
126569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramerstd::pair<unsigned, MVT>
126669e42dbd006c0afb732067ece7327988b1e24c01Benjamin KramerTargetLoweringBase::getTypeLegalizationCost(Type *Ty) const {
126769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  LLVMContext &C = Ty->getContext();
126869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  EVT MTy = getValueType(Ty);
126969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
127069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  unsigned Cost = 1;
127169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // We keep legalizing the type until we find a legal kind. We assume that
127269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // the only operation that costs anything is the split. After splitting
127369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // we need to handle two types.
127469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  while (true) {
127569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    LegalizeKind LK = getTypeConversion(C, MTy);
127669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
127769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (LK.first == TypeLegal)
127869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return std::make_pair(Cost, MTy.getSimpleVT());
127969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
128069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (LK.first == TypeSplitVector || LK.first == TypeExpandInteger)
128169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      Cost *= 2;
128269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
128369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    // Keep legalizing the type.
128469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    MTy = LK.second;
128569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  }
128669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer}
128769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
128869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer//===----------------------------------------------------------------------===//
128969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer//  Loop Strength Reduction hooks
129069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer//===----------------------------------------------------------------------===//
129169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
129269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// isLegalAddressingMode - Return true if the addressing mode represented
129369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer/// by AM is legal for this target, for a load/store of the specified type.
129469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramerbool TargetLoweringBase::isLegalAddressingMode(const AddrMode &AM,
129569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer                                           Type *Ty) const {
129669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // The default implementation of this implements a conservative RISCy, r+r and
129769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // r+i addr mode.
129869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
129969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // Allows a sign-extended 16-bit immediate field.
130069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  if (AM.BaseOffs <= -(1LL << 16) || AM.BaseOffs >= (1LL << 16)-1)
130169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    return false;
130269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
130369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // No global is ever allowed as a base.
130469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  if (AM.BaseGV)
130569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    return false;
130669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
130769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  // Only support r+r,
130869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  switch (AM.Scale) {
130969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case 0:  // "r+i" or just "i", depending on HasBaseReg.
131069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    break;
131169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case 1:
131269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (AM.HasBaseReg && AM.BaseOffs)  // "r+r+i" is not allowed.
131369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return false;
131469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    // Otherwise we have r+r or r+i.
131569e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    break;
131669e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  case 2:
131769e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    if (AM.HasBaseReg || AM.BaseOffs)  // 2*r+r  or  2*r+i is not allowed.
131869e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer      return false;
131969e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    // Allow 2*r as r+r.
132069e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer    break;
132169e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  }
132269e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer
132369e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer  return true;
132469e42dbd006c0afb732067ece7327988b1e24c01Benjamin Kramer}
1325