TargetLowering.h revision 2652c50f74bc4a874c6a2e4b34ff2d52d479183f
187b1aac0f0c9c753ea6de3cbc6447fa832d171fbBryan Mawhinney//===-- llvm/Target/TargetLowering.h - Target Lowering Info -----*- C++ -*-===// 287b1aac0f0c9c753ea6de3cbc6447fa832d171fbBryan Mawhinney// 387b1aac0f0c9c753ea6de3cbc6447fa832d171fbBryan Mawhinney// The LLVM Compiler Infrastructure 487b1aac0f0c9c753ea6de3cbc6447fa832d171fbBryan Mawhinney// 587b1aac0f0c9c753ea6de3cbc6447fa832d171fbBryan Mawhinney// This file is distributed under the University of Illinois Open Source 687b1aac0f0c9c753ea6de3cbc6447fa832d171fbBryan Mawhinney// License. See LICENSE.TXT for details. 787b1aac0f0c9c753ea6de3cbc6447fa832d171fbBryan Mawhinney// 887b1aac0f0c9c753ea6de3cbc6447fa832d171fbBryan Mawhinney//===----------------------------------------------------------------------===// 987b1aac0f0c9c753ea6de3cbc6447fa832d171fbBryan Mawhinney// 1087b1aac0f0c9c753ea6de3cbc6447fa832d171fbBryan Mawhinney// This file describes how to lower LLVM code to machine code. This has two 1187b1aac0f0c9c753ea6de3cbc6447fa832d171fbBryan Mawhinney// main components: 1287b1aac0f0c9c753ea6de3cbc6447fa832d171fbBryan Mawhinney// 1387b1aac0f0c9c753ea6de3cbc6447fa832d171fbBryan Mawhinney// 1. Which ValueTypes are natively supported by the target. 145021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov// 2. Which operations are supported for supported ValueTypes. 155021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov// 3. Cost thresholds for alternative implementations of certain operations. 165021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov// 175021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov// In addition it has a few other components, like information about FP 185021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov// immediates. 195021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov// 20bcc0c1d1139872b64b0466d03761bc37eb05720bTim Zheng//===----------------------------------------------------------------------===// 21c2a3d0fb3a25dd3f8171d24e1815da1f7f749e13Artem Iglikov 22c2a3d0fb3a25dd3f8171d24e1815da1f7f749e13Artem Iglikov#ifndef LLVM_TARGET_TARGETLOWERING_H 23c2a3d0fb3a25dd3f8171d24e1815da1f7f749e13Artem Iglikov#define LLVM_TARGET_TARGETLOWERING_H 24c2a3d0fb3a25dd3f8171d24e1815da1f7f749e13Artem Iglikov 25c2a3d0fb3a25dd3f8171d24e1815da1f7f749e13Artem Iglikov#include "llvm/AddressingMode.h" 26c2a3d0fb3a25dd3f8171d24e1815da1f7f749e13Artem Iglikov#include "llvm/CallingConv.h" 27c2a3d0fb3a25dd3f8171d24e1815da1f7f749e13Artem Iglikov#include "llvm/InlineAsm.h" 28c2a3d0fb3a25dd3f8171d24e1815da1f7f749e13Artem Iglikov#include "llvm/Attributes.h" 29c2a3d0fb3a25dd3f8171d24e1815da1f7f749e13Artem Iglikov#include "llvm/ADT/DenseMap.h" 30c2a3d0fb3a25dd3f8171d24e1815da1f7f749e13Artem Iglikov#include "llvm/Support/CallSite.h" 31c2a3d0fb3a25dd3f8171d24e1815da1f7f749e13Artem Iglikov#include "llvm/CodeGen/SelectionDAGNodes.h" 32c2a3d0fb3a25dd3f8171d24e1815da1f7f749e13Artem Iglikov#include "llvm/CodeGen/RuntimeLibcalls.h" 33c2a3d0fb3a25dd3f8171d24e1815da1f7f749e13Artem Iglikov#include "llvm/Support/DebugLoc.h" 34c31a839fd3ecc91807d735884d09fcbaf62e9244Robert Berry#include "llvm/Target/TargetCallingConv.h" 355021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov#include "llvm/Target/TargetMachine.h" 365021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov#include <climits> 375021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov#include <map> 385021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov#include <vector> 395021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 405021918605020c44c7ee66fbc896955abdd1517fArtem Iglikovnamespace llvm { 415021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov class CallInst; 425021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov class CCState; 435021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov class FastISel; 445021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov class FunctionLoweringInfo; 455021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov class ImmutableCallSite; 465021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov class IntrinsicInst; 475021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov class MachineBasicBlock; 485021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov class MachineFunction; 495021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov class MachineInstr; 505021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov class MachineJumpTableInfo; 515021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov class MCContext; 525021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov class MCExpr; 535021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov template<typename T> class SmallVectorImpl; 545021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov class DataLayout; 555021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov class TargetRegisterClass; 565021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov class TargetLibraryInfo; 575021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov class TargetLoweringObjectFile; 585021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov class Value; 595021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 605021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov namespace Sched { 615021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov enum Preference { 625021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov None, // No preference 635021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov Source, // Follow source order. 645021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov RegPressure, // Scheduling for lowest register pressure. 655021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov Hybrid, // Scheduling for both latency and register pressure. 665021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov ILP, // Scheduling for ILP in low register pressure mode. 6739194c0582463be17513b9ba82802a703b10c934Robert Berry VLIW // Scheduling for VLIW targets. 685021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov }; 695021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov } 705021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 715021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 725021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov//===----------------------------------------------------------------------===// 732eccd0262827259d15ceaa0fca975d3243c3a699Makoto Onuki/// TargetLowering - This class defines information used to lower LLVM code to 745021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov/// legal SelectionDAG operators that the target instruction selector can accept 755021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov/// natively. 765021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov/// 775021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov/// This class also defines callbacks that targets must implement to lower 785021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov/// target-specific constructs to SelectionDAG operators. 795021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov/// 803d87a5bfaf70ba994d7b82b50fbe79d36cb2d5eaMichal Karpinskiclass TargetLowering { 815021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov TargetLowering(const TargetLowering&) LLVM_DELETED_FUNCTION; 825021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov void operator=(const TargetLowering&) LLVM_DELETED_FUNCTION; 835021918605020c44c7ee66fbc896955abdd1517fArtem Iglikovpublic: 845021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// LegalizeAction - This enum indicates whether operations are valid for a 855021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// target, and if not, what action should be used to make them valid. 86924afe2b0f721afa857a55c33da559f6efc41d32Christopher Tate enum LegalizeAction { 875021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov Legal, // The target natively supports this operation. 885021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov Promote, // This operation should be executed in a larger type. 895021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov Expand, // Try to expand this to other ops, otherwise use a libcall. 905021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov Custom // Use the LowerOperation hook to implement custom lowering. 915021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov }; 9221510f0b7571f0689dc48c4f8fdbafea883cbdd0Artem Iglikov 935021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// LegalizeTypeAction - This enum indicates whether a types are legal for a 94ab953332bca70799b908ae0bfffb10c5d7a7a7f7Bernardo Rufino /// target, and if not, what action should be used to make them valid. 955021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov enum LegalizeTypeAction { 965021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov TypeLegal, // The target natively supports this type. 97ab953332bca70799b908ae0bfffb10c5d7a7a7f7Bernardo Rufino TypePromoteInteger, // Replace this integer with a larger one. 985021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov TypeExpandInteger, // Split this integer into two of half the size. 995021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov TypeSoftenFloat, // Convert this float to a same size integer type. 1005021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov TypeExpandFloat, // Split this float into two of half the size. 1015021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov TypeScalarizeVector, // Replace this one-element vector with its element. 102f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov TypeSplitVector, // Split this vector into two of half the size. 103f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov TypeWidenVector // This vector should be widened into a larger vector. 104f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov }; 105f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov 106f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov /// LegalizeKind holds the legalization kind that needs to happen to EVT 107af547f4a15a7d6121306a5e973ae7f3709e5df3aBernardo Rufino /// in order to type-legalize it. 108f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov typedef std::pair<LegalizeTypeAction, EVT> LegalizeKind; 109924afe2b0f721afa857a55c33da559f6efc41d32Christopher Tate 110f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov enum BooleanContent { // How the target represents true/false values. 111f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov UndefinedBooleanContent, // Only bit 0 counts, the rest can hold garbage. 112f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov ZeroOrOneBooleanContent, // All bits zero except for bit 0. 113f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov ZeroOrNegativeOneBooleanContent // All bits equal to bit 0. 114f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov }; 115f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov 116f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov enum SelectSupportKind { 117f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov ScalarValSelect, // The target supports scalar selects (ex: cmov). 118f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov ScalarCondVectorVal, // The target supports selects with a scalar condition 119f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov // and vector values (ex: cmov). 120f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov VectorMaskSelect // The target supports vector selects with a vector 121f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov // mask (ex: x86 blends). 122af547f4a15a7d6121306a5e973ae7f3709e5df3aBernardo Rufino }; 1237f14edea1d84bde1824529178c609fa5961051d2Bernardo Rufino 1242c2c856b3a60e96e09261d2513b43acb7ff4b070Artem Iglikov static ISD::NodeType getExtendForContent(BooleanContent Content) { 1252c2c856b3a60e96e09261d2513b43acb7ff4b070Artem Iglikov switch (Content) { 1262c2c856b3a60e96e09261d2513b43acb7ff4b070Artem Iglikov case UndefinedBooleanContent: 127c89535567bc80583fd6ca7cfecda44d124456ee3Robert Berry // Extend by adding rubbish bits. 12821510f0b7571f0689dc48c4f8fdbafea883cbdd0Artem Iglikov return ISD::ANY_EXTEND; 129c89535567bc80583fd6ca7cfecda44d124456ee3Robert Berry case ZeroOrOneBooleanContent: 130c89535567bc80583fd6ca7cfecda44d124456ee3Robert Berry // Extend by adding zero bits. 1315021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov return ISD::ZERO_EXTEND; 1325021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov case ZeroOrNegativeOneBooleanContent: 1335021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov // Extend by copying the sign bit. 1345021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov return ISD::SIGN_EXTEND; 1355021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov } 1365021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov llvm_unreachable("Invalid content kind"); 1375021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov } 1385021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 1395021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// NOTE: The constructor takes ownership of TLOF. 1405021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov explicit TargetLowering(const TargetMachine &TM, 1415021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov const TargetLoweringObjectFile *TLOF); 1425021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov virtual ~TargetLowering(); 1435021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 1445021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov const TargetMachine &getTargetMachine() const { return TM; } 1455021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov const DataLayout *getDataLayout() const { return TD; } 1465021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov const TargetLoweringObjectFile &getObjFileLowering() const { return TLOF; } 147924afe2b0f721afa857a55c33da559f6efc41d32Christopher Tate 1485021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov bool isBigEndian() const { return !IsLittleEndian; } 1495021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov bool isLittleEndian() const { return IsLittleEndian; } 1505021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov // Return the pointer type for the given address space, defaults to 1515021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov // the pointer type from the data layout. 152fa51853ae56ed74a0c854c01851cb1435453005fBernardo Rufino // FIXME: The default needs to be removed once all the code is updated. 1535021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov virtual MVT getPointerTy(uint32_t AS = 0) const { return PointerTy; } 1545021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov virtual MVT getShiftAmountTy(EVT LHSTy) const; 1555021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 1565021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// isSelectExpensive - Return true if the select operation is expensive for 1575021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// this target. 158f9b74cc7ef0e3fc6b95e4a988361b46e90bdfd5dMichal Karpinski bool isSelectExpensive() const { return SelectIsExpensive; } 15921510f0b7571f0689dc48c4f8fdbafea883cbdd0Artem Iglikov 160fe4ae0c5b1bc3b31adc4cc2c5a0197e29e97b6bcMichal Karpinski virtual bool isSelectSupported(SelectSupportKind kind) const { return true; } 1615021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 162f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov /// isIntDivCheap() - Return true if integer divide is usually cheaper than 163f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov /// a sequence of several shifts, adds, and multiplies for this target. 164f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov bool isIntDivCheap() const { return IntDivIsCheap; } 165f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov 1665021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// isSlowDivBypassed - Returns true if target has indicated at least one 1675021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// type should be bypassed. 1685021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov bool isSlowDivBypassed() const { return !BypassSlowDivWidths.empty(); } 169f32ea1909a007d177764adfd463e2b124faf179bArtem Iglikov 1705021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// getBypassSlowDivTypes - Returns map of slow types for division or 1715021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// remainder with corresponding fast types 1725021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov const DenseMap<unsigned int, unsigned int> &getBypassSlowDivWidths() const { 1735021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov return BypassSlowDivWidths; 174f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov } 1755021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 1765021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// isPow2DivCheap() - Return true if pow2 div is cheaper than a chain of 1775021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// srl/add/sra. 1785021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov bool isPow2DivCheap() const { return Pow2DivIsCheap; } 1795021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 1805021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// isJumpExpensive() - Return true if Flow Control is an expensive operation 181f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov /// that should be avoided. 182f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov bool isJumpExpensive() const { return JumpIsExpensive; } 1835021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 1845021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// isPredictableSelectExpensive - Return true if selects are only cheaper 1855021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// than branches if the branch is unlikely to be predicted right. 1865021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov bool isPredictableSelectExpensive() const { 1875021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov return predictableSelectIsExpensive; 1885021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov } 1895021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 1905021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// getSetCCResultType - Return the ValueType of the result of SETCC 191f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov /// operations. Also used to obtain the target's preferred type for 192f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov /// the condition operand of SELECT and BRCOND nodes. In the case of 193f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov /// BRCOND the argument passed is MVT::Other since there are no other 194f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov /// operands to get a type hint from. 195f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov virtual EVT getSetCCResultType(EVT VT) const; 196f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov 197f32ea1909a007d177764adfd463e2b124faf179bArtem Iglikov /// getCmpLibcallReturnType - Return the ValueType for comparison 198f32ea1909a007d177764adfd463e2b124faf179bArtem Iglikov /// libcalls. Comparions libcalls include floating point comparion calls, 199f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov /// and Ordered/Unordered check calls on floating point numbers. 200f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov virtual 201f32ea1909a007d177764adfd463e2b124faf179bArtem Iglikov MVT::SimpleValueType getCmpLibcallReturnType() const; 2025021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 2035021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// getBooleanContents - For targets without i1 registers, this gives the 2045021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// nature of the high-bits of boolean values held in types wider than i1. 2055021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// "Boolean values" are special true/false values produced by nodes like 206f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov /// SETCC and consumed (as the condition) by nodes like SELECT and BRCOND. 207f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov /// Not to be confused with general values promoted from i1. 20802a1c08096b705f8091951ac7d9afb7f7166b66fDenis Kuznetsov /// Some cpus distinguish between vectors of boolean and scalars; the isVec 20902a1c08096b705f8091951ac7d9afb7f7166b66fDenis Kuznetsov /// parameter selects between the two kinds. For example on X86 a scalar 2105021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// boolean should be zero extended from i1, while the elements of a vector 21141349c02a8867b956ff48752c2d3dffc124fc0fcBernardo Rufino /// of booleans should be sign extended from i1. 21241349c02a8867b956ff48752c2d3dffc124fc0fcBernardo Rufino BooleanContent getBooleanContents(bool isVec) const { 21341349c02a8867b956ff48752c2d3dffc124fc0fcBernardo Rufino return isVec ? BooleanVectorContents : BooleanContents; 21441349c02a8867b956ff48752c2d3dffc124fc0fcBernardo Rufino } 2155021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 216f32ea1909a007d177764adfd463e2b124faf179bArtem Iglikov /// getSchedulingPreference - Return target scheduling preference. 2175021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov Sched::Preference getSchedulingPreference() const { 2185021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov return SchedPreferenceInfo; 2195021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov } 220f32ea1909a007d177764adfd463e2b124faf179bArtem Iglikov 2215021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// getSchedulingPreference - Some scheduler, e.g. hybrid, can switch to 2225021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// different scheduling heuristics for different nodes. This function returns 2235021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// the preference (or none) for the given node. 224f32ea1909a007d177764adfd463e2b124faf179bArtem Iglikov virtual Sched::Preference getSchedulingPreference(SDNode *) const { 225f32ea1909a007d177764adfd463e2b124faf179bArtem Iglikov return Sched::None; 2265021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov } 227bcc0c1d1139872b64b0466d03761bc37eb05720bTim Zheng 22892892163d58b580056d38f6ca2c93fb714b9e4b8Annie Meng /// getRegClassFor - Return the register class that should be used for the 229d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov /// specified value type. 230d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov virtual const TargetRegisterClass *getRegClassFor(EVT VT) const { 231d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov assert(VT.isSimple() && "getRegClassFor called on illegal type!"); 232d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov const TargetRegisterClass *RC = RegClassForVT[VT.getSimpleVT().SimpleTy]; 2335021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov assert(RC && "This value type is not natively supported!"); 234d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov return RC; 2355021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov } 2365021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 237d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov /// getRepRegClassFor - Return the 'representative' register class for the 2385021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// specified value type. The 'representative' register class is the largest 239d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov /// legal super-reg register class for the register class of the value type. 2405021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// For example, on i386 the rep register class for i8, i16, and i32 are GR32; 241d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov /// while the rep register class is GR64 on x86_64. 242d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov virtual const TargetRegisterClass *getRepRegClassFor(EVT VT) const { 243f32ea1909a007d177764adfd463e2b124faf179bArtem Iglikov assert(VT.isSimple() && "getRepRegClassFor called on illegal type!"); 244d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov const TargetRegisterClass *RC = RepRegClassForVT[VT.getSimpleVT().SimpleTy]; 245d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov return RC; 246f32ea1909a007d177764adfd463e2b124faf179bArtem Iglikov } 247d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov 248f32ea1909a007d177764adfd463e2b124faf179bArtem Iglikov /// getRepRegClassCostFor - Return the cost of the 'representative' register 249f32ea1909a007d177764adfd463e2b124faf179bArtem Iglikov /// class for the specified value type. 2505021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov virtual uint8_t getRepRegClassCostFor(EVT VT) const { 251f32ea1909a007d177764adfd463e2b124faf179bArtem Iglikov assert(VT.isSimple() && "getRepRegClassCostFor called on illegal type!"); 252f32ea1909a007d177764adfd463e2b124faf179bArtem Iglikov return RepRegClassCostForVT[VT.getSimpleVT().SimpleTy]; 2535021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov } 2545021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 255d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov /// isTypeLegal - Return true if the target has native support for the 256f32ea1909a007d177764adfd463e2b124faf179bArtem Iglikov /// specified value type. This means that it has a register that directly 2575021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// holds it without promotions or expansions. 2585021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov bool isTypeLegal(EVT VT) const { 259f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov assert(!VT.isSimple() || 2605021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov (unsigned)VT.getSimpleVT().SimpleTy < array_lengthof(RegClassForVT)); 2615021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov return VT.isSimple() && RegClassForVT[VT.getSimpleVT().SimpleTy] != 0; 262d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov } 2635021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 2645021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov class ValueTypeActionImpl { 2655021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// ValueTypeActions - For each value type, keep a LegalizeTypeAction enum 2665021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// that indicates how instruction selection should deal with the type. 2675021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov uint8_t ValueTypeActions[MVT::LAST_VALUETYPE]; 268f32ea1909a007d177764adfd463e2b124faf179bArtem Iglikov 269f32ea1909a007d177764adfd463e2b124faf179bArtem Iglikov public: 270d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov ValueTypeActionImpl() { 271f32ea1909a007d177764adfd463e2b124faf179bArtem Iglikov std::fill(ValueTypeActions, array_endof(ValueTypeActions), 0); 272d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov } 2735021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 2745021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov LegalizeTypeAction getTypeAction(MVT VT) const { 275f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov return (LegalizeTypeAction)ValueTypeActions[VT.SimpleTy]; 276f32ea1909a007d177764adfd463e2b124faf179bArtem Iglikov } 2775021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 2785021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov void setTypeAction(EVT VT, LegalizeTypeAction Action) { 279d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov unsigned I = VT.getSimpleVT().SimpleTy; 280d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov ValueTypeActions[I] = Action; 2815021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov } 2829699fe319e78c681e638e8d5dee7954e15f8a96bRobert Berry }; 2839699fe319e78c681e638e8d5dee7954e15f8a96bRobert Berry 28441349c02a8867b956ff48752c2d3dffc124fc0fcBernardo Rufino const ValueTypeActionImpl &getValueTypeActions() const { 28541349c02a8867b956ff48752c2d3dffc124fc0fcBernardo Rufino return ValueTypeActions; 28641349c02a8867b956ff48752c2d3dffc124fc0fcBernardo Rufino } 2875021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 288d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov /// getTypeAction - Return how we should legalize values of this type, either 2895021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// it is already legal (return 'Legal') or we need to promote it to a larger 290d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov /// type (return 'Promote'), or we need to expand it into multiple registers 2915021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// of smaller integer type (return 'Expand'). 'Custom' is not an option. 292d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov LegalizeTypeAction getTypeAction(LLVMContext &Context, EVT VT) const { 2935021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov return getTypeConversion(Context, VT).first; 2945021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov } 295f32ea1909a007d177764adfd463e2b124faf179bArtem Iglikov LegalizeTypeAction getTypeAction(MVT VT) const { 2965021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov return ValueTypeActions.getTypeAction(VT); 2975021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov } 2985021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 2995021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// getTypeToTransformTo - For types supported by the target, this is an 3005021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// identity function. For types that must be promoted to larger types, this 3015021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// returns the larger type to promote to. For integer types that are larger 30221510f0b7571f0689dc48c4f8fdbafea883cbdd0Artem Iglikov /// than the largest integer register, this contains one step in the expansion 3035021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// to get to the smaller register. For illegal floating point types, this 3045021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// returns the integer type to transform to. 3055021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov EVT getTypeToTransformTo(LLVMContext &Context, EVT VT) const { 3065021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov return getTypeConversion(Context, VT).second; 3075021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov } 308bcc0c1d1139872b64b0466d03761bc37eb05720bTim Zheng 309bcc0c1d1139872b64b0466d03761bc37eb05720bTim Zheng /// getTypeToExpandTo - For types supported by the target, this is an 310bcc0c1d1139872b64b0466d03761bc37eb05720bTim Zheng /// identity function. For types that must be expanded (i.e. integer types 311bcc0c1d1139872b64b0466d03761bc37eb05720bTim Zheng /// that are larger than the largest integer register or illegal floating 31292892163d58b580056d38f6ca2c93fb714b9e4b8Annie Meng /// point types), this returns the largest legal type it will be expanded to. 31392892163d58b580056d38f6ca2c93fb714b9e4b8Annie Meng EVT getTypeToExpandTo(LLVMContext &Context, EVT VT) const { 31492892163d58b580056d38f6ca2c93fb714b9e4b8Annie Meng assert(!VT.isVector()); 31592892163d58b580056d38f6ca2c93fb714b9e4b8Annie Meng while (true) { 316d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov switch (getTypeAction(Context, VT)) { 317d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov case TypeLegal: 318d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov return VT; 319d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov case TypeExpandInteger: 320d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov VT = getTypeToTransformTo(Context, VT); 321d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov break; 322d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov default: 323d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov llvm_unreachable("Type is not legal nor is it to be expanded!"); 324d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov } 325d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov } 326d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov } 327d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov 328d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov /// getVectorTypeBreakdown - Vector types are broken down into some number of 329d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov /// legal first class types. For example, EVT::v8f32 maps to 2 EVT::v4f32 330d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov /// with Altivec or SSE1, or 8 promoted EVT::f64 values with the X86 FP stack. 331d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov /// Similarly, EVT::v2i64 turns into 4 EVT::i32 values with both PPC and X86. 332d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov /// 333d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov /// This method returns the number of registers needed, and the VT for each 334d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov /// register. It also returns the VT and quantity of the intermediate values 335d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov /// before they are promoted/expanded. 336d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov /// 337d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov unsigned getVectorTypeBreakdown(LLVMContext &Context, EVT VT, 338d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov EVT &IntermediateVT, 339d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov unsigned &NumIntermediates, 340d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov EVT &RegisterVT) const; 341d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov 342d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov /// getTgtMemIntrinsic: Given an intrinsic, checks if on the target the 343d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov /// intrinsic will need to map to a MemIntrinsicNode (touches memory). If 344d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov /// this is the case, it returns true and store the intrinsic 345d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov /// information into the IntrinsicInfo that was passed to the function. 346d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov struct IntrinsicInfo { 347d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov unsigned opc; // target opcode 348d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov EVT memVT; // memory VT 349d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov const Value* ptrVal; // value representing memory location 350d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov int offset; // offset off of ptrVal 351d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov unsigned align; // alignment 352d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov bool vol; // is volatile? 353d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov bool readMem; // reads memory? 354d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov bool writeMem; // writes memory? 355d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov }; 356d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov 357d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov virtual bool getTgtMemIntrinsic(IntrinsicInfo &, const CallInst &, 358d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov unsigned /*Intrinsic*/) const { 359d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov return false; 360d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov } 361d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov 362d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov /// isFPImmLegal - Returns true if the target can instruction select the 363d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov /// specified FP immediate natively. If false, the legalizer will materialize 364d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov /// the FP immediate as a load from a constant pool. 365d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov virtual bool isFPImmLegal(const APFloat &/*Imm*/, EVT /*VT*/) const { 366d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov return false; 367d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov } 368d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov 369d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov /// isShuffleMaskLegal - Targets can use this to indicate that they only 370d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov /// support *some* VECTOR_SHUFFLE operations, those with specific masks. 371d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov /// By default, if a target supports the VECTOR_SHUFFLE node, all mask values 372d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov /// are assumed to be legal. 373d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov virtual bool isShuffleMaskLegal(const SmallVectorImpl<int> &/*Mask*/, 374d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov EVT /*VT*/) const { 375d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov return true; 376d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov } 377d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov 378d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov /// canOpTrap - Returns true if the operation can trap for the value type. 379d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov /// VT must be a legal type. By default, we optimistically assume most 380d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov /// operations don't trap except for divide and remainder. 381d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov virtual bool canOpTrap(unsigned Op, EVT VT) const; 382d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov 383d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov /// isVectorClearMaskLegal - Similar to isShuffleMaskLegal. This is 384d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov /// used by Targets can use this to indicate if there is a suitable 385d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov /// VECTOR_SHUFFLE that can be used to replace a VAND with a constant 386d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov /// pool entry. 387d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov virtual bool isVectorClearMaskLegal(const SmallVectorImpl<int> &/*Mask*/, 38839194c0582463be17513b9ba82802a703b10c934Robert Berry EVT /*VT*/) const { 389d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov return false; 390d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov } 391d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov 392d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov /// getOperationAction - Return how this operation should be treated: either 393d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov /// it is legal, needs to be promoted to a larger size, needs to be 394d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov /// expanded to some other code sequence, or the target has a custom expander 395d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov /// for it. 396d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov LegalizeAction getOperationAction(unsigned Op, EVT VT) const { 397d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov if (VT.isExtended()) return Expand; 398d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov // If a target-specific SDNode requires legalization, require the target 399d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov // to provide custom legalization for it. 400d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov if (Op > array_lengthof(OpActions[0])) return Custom; 401d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov unsigned I = (unsigned) VT.getSimpleVT().SimpleTy; 402d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov return (LegalizeAction)OpActions[I][Op]; 403d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov } 404d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov 405d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov /// isOperationLegalOrCustom - Return true if the specified operation is 406d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov /// legal on this target or can be made legal with custom lowering. This 407d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov /// is used to help guide high-level lowering decisions. 408d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov bool isOperationLegalOrCustom(unsigned Op, EVT VT) const { 409d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov return (VT == MVT::Other || isTypeLegal(VT)) && 410d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov (getOperationAction(Op, VT) == Legal || 411d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov getOperationAction(Op, VT) == Custom); 412d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov } 413d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov 414d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov /// isOperationLegal - Return true if the specified operation is legal on this 415d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov /// target. 416d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov bool isOperationLegal(unsigned Op, EVT VT) const { 417d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov return (VT == MVT::Other || isTypeLegal(VT)) && 418d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov getOperationAction(Op, VT) == Legal; 419d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov } 420d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov 421d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov /// getLoadExtAction - Return how this load with extension should be treated: 422d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov /// either it is legal, needs to be promoted to a larger size, needs to be 423d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov /// expanded to some other code sequence, or the target has a custom expander 424d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov /// for it. 425d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov LegalizeAction getLoadExtAction(unsigned ExtType, EVT VT) const { 426d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov assert(ExtType < ISD::LAST_LOADEXT_TYPE && 427d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov VT.getSimpleVT() < MVT::LAST_VALUETYPE && 428d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov "Table isn't big enough!"); 429d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov return (LegalizeAction)LoadExtActions[VT.getSimpleVT().SimpleTy][ExtType]; 430d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov } 431d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov 432d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov /// isLoadExtLegal - Return true if the specified load with extension is legal 433d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov /// on this target. 434d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov bool isLoadExtLegal(unsigned ExtType, EVT VT) const { 435d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov return VT.isSimple() && getLoadExtAction(ExtType, VT) == Legal; 436d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov } 437d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov 438d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov /// getTruncStoreAction - Return how this store with truncation should be 439d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov /// treated: either it is legal, needs to be promoted to a larger size, needs 440d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov /// to be expanded to some other code sequence, or the target has a custom 441d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov /// expander for it. 442d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov LegalizeAction getTruncStoreAction(EVT ValVT, EVT MemVT) const { 443d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov assert(ValVT.getSimpleVT() < MVT::LAST_VALUETYPE && 444d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov MemVT.getSimpleVT() < MVT::LAST_VALUETYPE && 445d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov "Table isn't big enough!"); 446d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov return (LegalizeAction)TruncStoreActions[ValVT.getSimpleVT().SimpleTy] 447d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov [MemVT.getSimpleVT().SimpleTy]; 448d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov } 449d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov 450d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov /// isTruncStoreLegal - Return true if the specified store with truncation is 451d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov /// legal on this target. 452d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov bool isTruncStoreLegal(EVT ValVT, EVT MemVT) const { 453d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov return isTypeLegal(ValVT) && MemVT.isSimple() && 454d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov getTruncStoreAction(ValVT, MemVT) == Legal; 455d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov } 456d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov 457d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov /// getIndexedLoadAction - Return how the indexed load should be treated: 4585021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// either it is legal, needs to be promoted to a larger size, needs to be 4595021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// expanded to some other code sequence, or the target has a custom expander 4605021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// for it. 461d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov LegalizeAction 462d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov getIndexedLoadAction(unsigned IdxMode, EVT VT) const { 463d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov assert(IdxMode < ISD::LAST_INDEXED_MODE && 464d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov VT.getSimpleVT() < MVT::LAST_VALUETYPE && 465d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov "Table isn't big enough!"); 466d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov unsigned Ty = (unsigned)VT.getSimpleVT().SimpleTy; 467d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov return (LegalizeAction)((IndexedModeActions[Ty][IdxMode] & 0xf0) >> 4); 468d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov } 469d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov 470d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov /// isIndexedLoadLegal - Return true if the specified indexed load is legal 471d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov /// on this target. 472d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov bool isIndexedLoadLegal(unsigned IdxMode, EVT VT) const { 473d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov return VT.isSimple() && 474d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov (getIndexedLoadAction(IdxMode, VT) == Legal || 475d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov getIndexedLoadAction(IdxMode, VT) == Custom); 476d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov } 477d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov 478d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov /// getIndexedStoreAction - Return how the indexed store should be treated: 479d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov /// either it is legal, needs to be promoted to a larger size, needs to be 480d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov /// expanded to some other code sequence, or the target has a custom expander 481d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov /// for it. 482d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov LegalizeAction 483d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov getIndexedStoreAction(unsigned IdxMode, EVT VT) const { 484d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov assert(IdxMode < ISD::LAST_INDEXED_MODE && 485d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov VT.getSimpleVT() < MVT::LAST_VALUETYPE && 486d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov "Table isn't big enough!"); 487d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov unsigned Ty = (unsigned)VT.getSimpleVT().SimpleTy; 488d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov return (LegalizeAction)(IndexedModeActions[Ty][IdxMode] & 0x0f); 489d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov } 490d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov 491d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov /// isIndexedStoreLegal - Return true if the specified indexed load is legal 492d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov /// on this target. 493d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov bool isIndexedStoreLegal(unsigned IdxMode, EVT VT) const { 494c31a839fd3ecc91807d735884d09fcbaf62e9244Robert Berry return VT.isSimple() && 495d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov (getIndexedStoreAction(IdxMode, VT) == Legal || 496d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov getIndexedStoreAction(IdxMode, VT) == Custom); 497d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov } 498c31a839fd3ecc91807d735884d09fcbaf62e9244Robert Berry 499d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov /// getCondCodeAction - Return how the condition code should be treated: 500d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov /// either it is legal, needs to be expanded to some other code sequence, 501d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov /// or the target has a custom expander for it. 502d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov LegalizeAction 503d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov getCondCodeAction(ISD::CondCode CC, EVT VT) const { 504d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov assert((unsigned)CC < array_lengthof(CondCodeActions) && 505d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov (unsigned)VT.getSimpleVT().SimpleTy < sizeof(CondCodeActions[0])*4 && 506d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov "Table isn't big enough!"); 507d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov /// The lower 5 bits of the SimpleTy index into Nth 2bit set from the 64bit 508d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov /// value and the upper 27 bits index into the second dimension of the 509d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov /// array to select what 64bit value to use. 510d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov LegalizeAction Action = (LegalizeAction) 511d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov ((CondCodeActions[CC][VT.getSimpleVT().SimpleTy >> 5] 512d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov >> (2*(VT.getSimpleVT().SimpleTy & 0x1F))) & 3); 513d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov assert(Action != Promote && "Can't promote condition code!"); 514d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov return Action; 515d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov } 516d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov 517d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov /// isCondCodeLegal - Return true if the specified condition code is legal 518d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov /// on this target. 519d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov bool isCondCodeLegal(ISD::CondCode CC, EVT VT) const { 520d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov return getCondCodeAction(CC, VT) == Legal || 521d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov getCondCodeAction(CC, VT) == Custom; 522d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov } 523d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov 524d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov 525d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov /// getTypeToPromoteTo - If the action for this operation is to promote, this 526d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov /// method returns the ValueType to promote to. 527d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov EVT getTypeToPromoteTo(unsigned Op, EVT VT) const { 528d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov assert(getOperationAction(Op, VT) == Promote && 529d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov "This operation isn't promoted!"); 530924afe2b0f721afa857a55c33da559f6efc41d32Christopher Tate 531d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov // See if this has an explicit type specified. 532d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov std::map<std::pair<unsigned, MVT::SimpleValueType>, 533d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov MVT::SimpleValueType>::const_iterator PTTI = 534924afe2b0f721afa857a55c33da559f6efc41d32Christopher Tate PromoteToType.find(std::make_pair(Op, VT.getSimpleVT().SimpleTy)); 535924afe2b0f721afa857a55c33da559f6efc41d32Christopher Tate if (PTTI != PromoteToType.end()) return PTTI->second; 536d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov 537d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov assert((VT.isInteger() || VT.isFloatingPoint()) && 538d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov "Cannot autopromote this type, add it with AddPromotedToType."); 539d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov 540d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov EVT NVT = VT; 541d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov do { 542d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov NVT = (MVT::SimpleValueType)(NVT.getSimpleVT().SimpleTy+1); 543d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov assert(NVT.isInteger() == VT.isInteger() && NVT != MVT::isVoid && 544d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov "Didn't find type to promote to!"); 545d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov } while (!isTypeLegal(NVT) || 546d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov getOperationAction(Op, NVT) == Promote); 5475021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov return NVT; 5485021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov } 5495021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 5505021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// getValueType - Return the EVT corresponding to this LLVM type. 5515021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// This is fixed by the LLVM operations except for the pointer size. If 5525021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// AllowUnknown is true, this will return MVT::Other for types with no EVT 5535021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// counterpart (e.g. structs), otherwise it will assert. 5545021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov EVT getValueType(Type *Ty, bool AllowUnknown = false) const { 5555021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov // Lower scalar pointers to native pointer types. 5565021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov if (Ty->isPointerTy()) return PointerTy; 5575021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 5585021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov if (Ty->isVectorTy()) { 5595021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov VectorType *VTy = cast<VectorType>(Ty); 5605021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov Type *Elm = VTy->getElementType(); 5615021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov // Lower vectors of pointers to native pointer types. 56273093a477dbf4422cccf19233e691c5d2fdf21f3Christopher Tate if (Elm->isPointerTy()) 56373093a477dbf4422cccf19233e691c5d2fdf21f3Christopher Tate Elm = EVT(PointerTy).getTypeForEVT(Ty->getContext()); 56473093a477dbf4422cccf19233e691c5d2fdf21f3Christopher Tate return EVT::getVectorVT(Ty->getContext(), EVT::getEVT(Elm, false), 56573093a477dbf4422cccf19233e691c5d2fdf21f3Christopher Tate VTy->getNumElements()); 5665021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov } 56773093a477dbf4422cccf19233e691c5d2fdf21f3Christopher Tate return EVT::getEVT(Ty, AllowUnknown); 56873093a477dbf4422cccf19233e691c5d2fdf21f3Christopher Tate } 56973093a477dbf4422cccf19233e691c5d2fdf21f3Christopher Tate 5708808609896023165274092265cc2b51597d6a388Christopher Tate 5718808609896023165274092265cc2b51597d6a388Christopher Tate /// getByValTypeAlignment - Return the desired alignment for ByVal aggregate 5728808609896023165274092265cc2b51597d6a388Christopher Tate /// function arguments in the caller parameter area. This is the actual 5738808609896023165274092265cc2b51597d6a388Christopher Tate /// alignment, not its logarithm. 5748808609896023165274092265cc2b51597d6a388Christopher Tate virtual unsigned getByValTypeAlignment(Type *Ty) const; 5758808609896023165274092265cc2b51597d6a388Christopher Tate 5768808609896023165274092265cc2b51597d6a388Christopher Tate /// getRegisterType - Return the type of registers that this ValueType will 5778808609896023165274092265cc2b51597d6a388Christopher Tate /// eventually require. 5788808609896023165274092265cc2b51597d6a388Christopher Tate EVT getRegisterType(MVT VT) const { 5798808609896023165274092265cc2b51597d6a388Christopher Tate assert((unsigned)VT.SimpleTy < array_lengthof(RegisterTypeForVT)); 58073093a477dbf4422cccf19233e691c5d2fdf21f3Christopher Tate return RegisterTypeForVT[VT.SimpleTy]; 5818808609896023165274092265cc2b51597d6a388Christopher Tate } 58273093a477dbf4422cccf19233e691c5d2fdf21f3Christopher Tate 5838808609896023165274092265cc2b51597d6a388Christopher Tate /// getRegisterType - Return the type of registers that this ValueType will 5848808609896023165274092265cc2b51597d6a388Christopher Tate /// eventually require. 5858808609896023165274092265cc2b51597d6a388Christopher Tate EVT getRegisterType(LLVMContext &Context, EVT VT) const { 5868808609896023165274092265cc2b51597d6a388Christopher Tate if (VT.isSimple()) { 5878808609896023165274092265cc2b51597d6a388Christopher Tate assert((unsigned)VT.getSimpleVT().SimpleTy < 5888808609896023165274092265cc2b51597d6a388Christopher Tate array_lengthof(RegisterTypeForVT)); 5895021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov return RegisterTypeForVT[VT.getSimpleVT().SimpleTy]; 59073093a477dbf4422cccf19233e691c5d2fdf21f3Christopher Tate } 5918808609896023165274092265cc2b51597d6a388Christopher Tate if (VT.isVector()) { 5928808609896023165274092265cc2b51597d6a388Christopher Tate EVT VT1, RegisterVT; 5935021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov unsigned NumIntermediates; 5948808609896023165274092265cc2b51597d6a388Christopher Tate (void)getVectorTypeBreakdown(Context, VT, VT1, 5958808609896023165274092265cc2b51597d6a388Christopher Tate NumIntermediates, RegisterVT); 5968808609896023165274092265cc2b51597d6a388Christopher Tate return RegisterVT; 5978808609896023165274092265cc2b51597d6a388Christopher Tate } 5988808609896023165274092265cc2b51597d6a388Christopher Tate if (VT.isInteger()) { 5998808609896023165274092265cc2b51597d6a388Christopher Tate return getRegisterType(Context, getTypeToTransformTo(Context, VT)); 6008808609896023165274092265cc2b51597d6a388Christopher Tate } 6015021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov llvm_unreachable("Unsupported extended type!"); 6025021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov } 6035021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 6045021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// getNumRegisters - Return the number of registers that this ValueType will 605f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov /// eventually require. This is one for any types promoted to live in larger 606f32ea1909a007d177764adfd463e2b124faf179bArtem Iglikov /// registers, but may be more than one for types (like i64) that are split 607f32ea1909a007d177764adfd463e2b124faf179bArtem Iglikov /// into pieces. For types like i140, which are first promoted then expanded, 6085021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// it is the number of registers needed to hold all the bits of the original 6095021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// type. For an i140 on a 32 bit machine this means 5 registers. 610f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov unsigned getNumRegisters(LLVMContext &Context, EVT VT) const { 6115021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov if (VT.isSimple()) { 6125021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov assert((unsigned)VT.getSimpleVT().SimpleTy < 613f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov array_lengthof(NumRegistersForVT)); 6145021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov return NumRegistersForVT[VT.getSimpleVT().SimpleTy]; 6155021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov } 616f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov if (VT.isVector()) { 6175021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov EVT VT1, VT2; 6185021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov unsigned NumIntermediates; 6195021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov return getVectorTypeBreakdown(Context, VT, VT1, NumIntermediates, VT2); 6205021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov } 6215021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov if (VT.isInteger()) { 6225021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov unsigned BitWidth = VT.getSizeInBits(); 6235021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov unsigned RegWidth = getRegisterType(Context, VT).getSizeInBits(); 6245021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov return (BitWidth + RegWidth - 1) / RegWidth; 6255021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov } 6265021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov llvm_unreachable("Unsupported extended type!"); 62721510f0b7571f0689dc48c4f8fdbafea883cbdd0Artem Iglikov } 628fe4ae0c5b1bc3b31adc4cc2c5a0197e29e97b6bcMichal Karpinski 6295021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// ShouldShrinkFPConstant - If true, then instruction selection should 6305021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// seek to shrink the FP constant of the specified type to a smaller type 631bcc0c1d1139872b64b0466d03761bc37eb05720bTim Zheng /// in order to save space and / or reduce runtime. 632bcc0c1d1139872b64b0466d03761bc37eb05720bTim Zheng virtual bool ShouldShrinkFPConstant(EVT) const { return true; } 633bcc0c1d1139872b64b0466d03761bc37eb05720bTim Zheng 634bcc0c1d1139872b64b0466d03761bc37eb05720bTim Zheng /// hasTargetDAGCombine - If true, the target has custom DAG combine 6355021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// transformations that it can perform for the specified node. 6365021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov bool hasTargetDAGCombine(ISD::NodeType NT) const { 6375021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov assert(unsigned(NT >> 3) < array_lengthof(TargetDAGCombineArray)); 6385021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov return TargetDAGCombineArray[NT >> 3] & (1 << (NT&7)); 6395021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov } 640d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov 641d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov /// This function returns the maximum number of store operations permitted 642f32ea1909a007d177764adfd463e2b124faf179bArtem Iglikov /// to replace a call to llvm.memset. The value is set by the target at the 643f9b74cc7ef0e3fc6b95e4a988361b46e90bdfd5dMichal Karpinski /// performance threshold for such a replacement. If OptSize is true, 6445021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// return the limit for functions that have OptSize attribute. 645d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov /// @brief Get maximum # of store operations permitted for llvm.memset 6465021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov unsigned getMaxStoresPerMemset(bool OptSize) const { 6475021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov return OptSize ? maxStoresPerMemsetOptSize : maxStoresPerMemset; 648d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov } 649d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov 650f32ea1909a007d177764adfd463e2b124faf179bArtem Iglikov /// This function returns the maximum number of store operations permitted 651bcc0c1d1139872b64b0466d03761bc37eb05720bTim Zheng /// to replace a call to llvm.memcpy. The value is set by the target at the 652bcc0c1d1139872b64b0466d03761bc37eb05720bTim Zheng /// performance threshold for such a replacement. If OptSize is true, 6535021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// return the limit for functions that have OptSize attribute. 654d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov /// @brief Get maximum # of store operations permitted for llvm.memcpy 6555021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov unsigned getMaxStoresPerMemcpy(bool OptSize) const { 6566d2fbdf10df2ff6794a2563b9af623f40e4f2915Robert Berry return OptSize ? maxStoresPerMemcpyOptSize : maxStoresPerMemcpy; 6576d2fbdf10df2ff6794a2563b9af623f40e4f2915Robert Berry } 658a1109ef8da76fad3ff7974cbba2e90f7638cdb3cRobert Berry 6595021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// This function returns the maximum number of store operations permitted 66021510f0b7571f0689dc48c4f8fdbafea883cbdd0Artem Iglikov /// to replace a call to llvm.memmove. The value is set by the target at the 6612c2c856b3a60e96e09261d2513b43acb7ff4b070Artem Iglikov /// performance threshold for such a replacement. If OptSize is true, 662f32ea1909a007d177764adfd463e2b124faf179bArtem Iglikov /// return the limit for functions that have OptSize attribute. 663d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov /// @brief Get maximum # of store operations permitted for llvm.memmove 664d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov unsigned getMaxStoresPerMemmove(bool OptSize) const { 665d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov return OptSize ? maxStoresPerMemmoveOptSize : maxStoresPerMemmove; 6665021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov } 6675021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 668f32ea1909a007d177764adfd463e2b124faf179bArtem Iglikov /// This function returns true if the target allows unaligned memory accesses. 66966c94726c9e65c4cb048d302bf3860f68751d35cChristopher Tate /// of the specified type. This is used, for example, in situations where an 6705021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// array copy/move/set is converted to a sequence of store operations. It's 6715021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// use helps to ensure that such replacements don't generate code that causes 672f32ea1909a007d177764adfd463e2b124faf179bArtem Iglikov /// an alignment error (trap) on the target machine. 6735021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// @brief Determine if the target supports unaligned memory accesses. 674f32ea1909a007d177764adfd463e2b124faf179bArtem Iglikov virtual bool allowsUnalignedMemoryAccesses(EVT) const { 6755021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov return false; 6765021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov } 6775021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 678d6c00c711000aa70db51f46b48a86c2884e91b15Artem Iglikov /// This function returns true if the target would benefit from code placement 6795021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// optimization. 6805021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// @brief Determine if the target should perform code placement optimization. 681f32ea1909a007d177764adfd463e2b124faf179bArtem Iglikov bool shouldOptimizeCodePlacement() const { 6825021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov return benefitFromCodePlacementOpt; 683c141d08b703b7ccf754be92f8be3a7752fc15c1aLenka Trochtova } 684c141d08b703b7ccf754be92f8be3a7752fc15c1aLenka Trochtova 685f9b74cc7ef0e3fc6b95e4a988361b46e90bdfd5dMichal Karpinski /// getOptimalMemOpType - Returns the target specific optimal type for load 686f9b74cc7ef0e3fc6b95e4a988361b46e90bdfd5dMichal Karpinski /// and store operations as a result of memset, memcpy, and memmove 687f9b74cc7ef0e3fc6b95e4a988361b46e90bdfd5dMichal Karpinski /// lowering. If DstAlign is zero that means it's safe to destination 6885021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// alignment can satisfy any constraint. Similarly if SrcAlign is zero it 6895021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// means there isn't a need to check it against alignment requirement, 690f9b74cc7ef0e3fc6b95e4a988361b46e90bdfd5dMichal Karpinski /// probably because the source does not need to be loaded. If 691f9b74cc7ef0e3fc6b95e4a988361b46e90bdfd5dMichal Karpinski /// 'IsZeroVal' is true, that means it's safe to return a 692f9b74cc7ef0e3fc6b95e4a988361b46e90bdfd5dMichal Karpinski /// non-scalar-integer type, e.g. empty string source, constant, or loaded 693f9b74cc7ef0e3fc6b95e4a988361b46e90bdfd5dMichal Karpinski /// from memory. 'MemcpyStrSrc' indicates whether the memcpy source is 6945021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// constant so it does not need to be loaded. 6955021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// It returns EVT::Other if the type should be determined using generic 6965021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// target-independent logic. 697c1741631d8fd5bd0a8576442e88c6b67e2df4408Michal Karpinski virtual EVT getOptimalMemOpType(uint64_t /*Size*/, 698c1741631d8fd5bd0a8576442e88c6b67e2df4408Michal Karpinski unsigned /*DstAlign*/, unsigned /*SrcAlign*/, 699c1741631d8fd5bd0a8576442e88c6b67e2df4408Michal Karpinski bool /*IsZeroVal*/, 700c1741631d8fd5bd0a8576442e88c6b67e2df4408Michal Karpinski bool /*MemcpyStrSrc*/, 701c1741631d8fd5bd0a8576442e88c6b67e2df4408Michal Karpinski MachineFunction &/*MF*/) const { 702c1741631d8fd5bd0a8576442e88c6b67e2df4408Michal Karpinski return MVT::Other; 703c1741631d8fd5bd0a8576442e88c6b67e2df4408Michal Karpinski } 704c1741631d8fd5bd0a8576442e88c6b67e2df4408Michal Karpinski 705c1741631d8fd5bd0a8576442e88c6b67e2df4408Michal Karpinski /// usesUnderscoreSetJmp - Determine if we should use _setjmp or setjmp 706c1741631d8fd5bd0a8576442e88c6b67e2df4408Michal Karpinski /// to implement llvm.setjmp. 707c1741631d8fd5bd0a8576442e88c6b67e2df4408Michal Karpinski bool usesUnderscoreSetJmp() const { 708c1741631d8fd5bd0a8576442e88c6b67e2df4408Michal Karpinski return UseUnderscoreSetJmp; 709c1741631d8fd5bd0a8576442e88c6b67e2df4408Michal Karpinski } 710c1741631d8fd5bd0a8576442e88c6b67e2df4408Michal Karpinski 711c1741631d8fd5bd0a8576442e88c6b67e2df4408Michal Karpinski /// usesUnderscoreLongJmp - Determine if we should use _longjmp or longjmp 712c1741631d8fd5bd0a8576442e88c6b67e2df4408Michal Karpinski /// to implement llvm.longjmp. 713c1741631d8fd5bd0a8576442e88c6b67e2df4408Michal Karpinski bool usesUnderscoreLongJmp() const { 714c1741631d8fd5bd0a8576442e88c6b67e2df4408Michal Karpinski return UseUnderscoreLongJmp; 715c1741631d8fd5bd0a8576442e88c6b67e2df4408Michal Karpinski } 716c1741631d8fd5bd0a8576442e88c6b67e2df4408Michal Karpinski 717c1741631d8fd5bd0a8576442e88c6b67e2df4408Michal Karpinski /// supportJumpTables - return whether the target can generate code for 718c1741631d8fd5bd0a8576442e88c6b67e2df4408Michal Karpinski /// jump tables. 719c1741631d8fd5bd0a8576442e88c6b67e2df4408Michal Karpinski bool supportJumpTables() const { 7205021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov return SupportJumpTables; 721f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov } 7225021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 7235021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// getMinimumJumpTableEntries - return integer threshold on number of 7245021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// blocks to use jump tables rather than if sequence. 7255021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov int getMinimumJumpTableEntries() const { 7265021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov return MinimumJumpTableEntries; 7275021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov } 7285021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 729f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov /// getStackPointerRegisterToSaveRestore - If a physical register, this 7305021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// specifies the register that llvm.savestack/llvm.restorestack should save 7315021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// and restore. 7325021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov unsigned getStackPointerRegisterToSaveRestore() const { 7335021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov return StackPointerRegisterToSaveRestore; 7345021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov } 7355021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 7365021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// getExceptionPointerRegister - If a physical register, this returns 7375021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// the register that receives the exception address on entry to a landing 7385021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// pad. 739fe4ae0c5b1bc3b31adc4cc2c5a0197e29e97b6bcMichal Karpinski unsigned getExceptionPointerRegister() const { 740ab953332bca70799b908ae0bfffb10c5d7a7a7f7Bernardo Rufino return ExceptionPointerRegister; 741ab953332bca70799b908ae0bfffb10c5d7a7a7f7Bernardo Rufino } 7428808609896023165274092265cc2b51597d6a388Christopher Tate 743ab953332bca70799b908ae0bfffb10c5d7a7a7f7Bernardo Rufino /// getExceptionSelectorRegister - If a physical register, this returns 744ab953332bca70799b908ae0bfffb10c5d7a7a7f7Bernardo Rufino /// the register that receives the exception typeid on entry to a landing 745ab953332bca70799b908ae0bfffb10c5d7a7a7f7Bernardo Rufino /// pad. 74641349c02a8867b956ff48752c2d3dffc124fc0fcBernardo Rufino unsigned getExceptionSelectorRegister() const { 74741349c02a8867b956ff48752c2d3dffc124fc0fcBernardo Rufino return ExceptionSelectorRegister; 74841349c02a8867b956ff48752c2d3dffc124fc0fcBernardo Rufino } 749ab953332bca70799b908ae0bfffb10c5d7a7a7f7Bernardo Rufino 750ab953332bca70799b908ae0bfffb10c5d7a7a7f7Bernardo Rufino /// getJumpBufSize - returns the target's jmp_buf size in bytes (if never 751ab953332bca70799b908ae0bfffb10c5d7a7a7f7Bernardo Rufino /// set, the default is 200) 752ab953332bca70799b908ae0bfffb10c5d7a7a7f7Bernardo Rufino unsigned getJumpBufSize() const { 7535021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov return JumpBufSize; 7545021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov } 7555021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 756ab953332bca70799b908ae0bfffb10c5d7a7a7f7Bernardo Rufino /// getJumpBufAlignment - returns the target's jmp_buf alignment in bytes 757ab953332bca70799b908ae0bfffb10c5d7a7a7f7Bernardo Rufino /// (if never set, the default is 0) 758ab953332bca70799b908ae0bfffb10c5d7a7a7f7Bernardo Rufino unsigned getJumpBufAlignment() const { 759ab953332bca70799b908ae0bfffb10c5d7a7a7f7Bernardo Rufino return JumpBufAlignment; 760ab953332bca70799b908ae0bfffb10c5d7a7a7f7Bernardo Rufino } 761ab953332bca70799b908ae0bfffb10c5d7a7a7f7Bernardo Rufino 762ab953332bca70799b908ae0bfffb10c5d7a7a7f7Bernardo Rufino /// getMinStackArgumentAlignment - return the minimum stack alignment of an 76341349c02a8867b956ff48752c2d3dffc124fc0fcBernardo Rufino /// argument. 764ab953332bca70799b908ae0bfffb10c5d7a7a7f7Bernardo Rufino unsigned getMinStackArgumentAlignment() const { 765ab953332bca70799b908ae0bfffb10c5d7a7a7f7Bernardo Rufino return MinStackArgumentAlignment; 766ab953332bca70799b908ae0bfffb10c5d7a7a7f7Bernardo Rufino } 767ab953332bca70799b908ae0bfffb10c5d7a7a7f7Bernardo Rufino 768ab953332bca70799b908ae0bfffb10c5d7a7a7f7Bernardo Rufino /// getMinFunctionAlignment - return the minimum function alignment. 769ab953332bca70799b908ae0bfffb10c5d7a7a7f7Bernardo Rufino /// 770ab953332bca70799b908ae0bfffb10c5d7a7a7f7Bernardo Rufino unsigned getMinFunctionAlignment() const { 771ab953332bca70799b908ae0bfffb10c5d7a7a7f7Bernardo Rufino return MinFunctionAlignment; 772fe4ae0c5b1bc3b31adc4cc2c5a0197e29e97b6bcMichal Karpinski } 773ab953332bca70799b908ae0bfffb10c5d7a7a7f7Bernardo Rufino 774ab953332bca70799b908ae0bfffb10c5d7a7a7f7Bernardo Rufino /// getPrefFunctionAlignment - return the preferred function alignment. 775ab953332bca70799b908ae0bfffb10c5d7a7a7f7Bernardo Rufino /// 776ab953332bca70799b908ae0bfffb10c5d7a7a7f7Bernardo Rufino unsigned getPrefFunctionAlignment() const { 777ab953332bca70799b908ae0bfffb10c5d7a7a7f7Bernardo Rufino return PrefFunctionAlignment; 778ab953332bca70799b908ae0bfffb10c5d7a7a7f7Bernardo Rufino } 779ab953332bca70799b908ae0bfffb10c5d7a7a7f7Bernardo Rufino 780ab953332bca70799b908ae0bfffb10c5d7a7a7f7Bernardo Rufino /// getPrefLoopAlignment - return the preferred loop alignment. 781ab953332bca70799b908ae0bfffb10c5d7a7a7f7Bernardo Rufino /// 782fe4ae0c5b1bc3b31adc4cc2c5a0197e29e97b6bcMichal Karpinski unsigned getPrefLoopAlignment() const { 783ab953332bca70799b908ae0bfffb10c5d7a7a7f7Bernardo Rufino return PrefLoopAlignment; 784ab953332bca70799b908ae0bfffb10c5d7a7a7f7Bernardo Rufino } 785ab953332bca70799b908ae0bfffb10c5d7a7a7f7Bernardo Rufino 786ab953332bca70799b908ae0bfffb10c5d7a7a7f7Bernardo Rufino /// getShouldFoldAtomicFences - return whether the combiner should fold 787ab953332bca70799b908ae0bfffb10c5d7a7a7f7Bernardo Rufino /// fence MEMBARRIER instructions into the atomic intrinsic instructions. 788ab953332bca70799b908ae0bfffb10c5d7a7a7f7Bernardo Rufino /// 7895021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov bool getShouldFoldAtomicFences() const { 7905021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov return ShouldFoldAtomicFences; 7915021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov } 7925021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 7935021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// getInsertFencesFor - return whether the DAG builder should automatically 7945021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// insert fences and reduce ordering for atomics. 7955021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// 7965021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov bool getInsertFencesForAtomic() const { 7975021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov return InsertFencesForAtomic; 7985021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov } 7995021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 80092892163d58b580056d38f6ca2c93fb714b9e4b8Annie Meng /// getPreIndexedAddressParts - returns true by value, base pointer and 80192892163d58b580056d38f6ca2c93fb714b9e4b8Annie Meng /// offset pointer and addressing mode by reference if the node's address 80292892163d58b580056d38f6ca2c93fb714b9e4b8Annie Meng /// can be legally represented as pre-indexed load / store address. 80392892163d58b580056d38f6ca2c93fb714b9e4b8Annie Meng virtual bool getPreIndexedAddressParts(SDNode * /*N*/, SDValue &/*Base*/, 8045021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov SDValue &/*Offset*/, 8058808609896023165274092265cc2b51597d6a388Christopher Tate ISD::MemIndexedMode &/*AM*/, 8065021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov SelectionDAG &/*DAG*/) const { 8075021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov return false; 8085021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov } 8095021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 8105021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// getPostIndexedAddressParts - returns true by value, base pointer and 8115021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// offset pointer and addressing mode by reference if this node can be 8125021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// combined with a load / store to form a post-indexed load / store. 8135021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov virtual bool getPostIndexedAddressParts(SDNode * /*N*/, SDNode * /*Op*/, 814f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov SDValue &/*Base*/, SDValue &/*Offset*/, 8155021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov ISD::MemIndexedMode &/*AM*/, 8165021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov SelectionDAG &/*DAG*/) const { 8175021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov return false; 8185021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov } 819ab953332bca70799b908ae0bfffb10c5d7a7a7f7Bernardo Rufino 8205021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// getJumpTableEncoding - Return the entry encoding for a jump table in the 8215021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// current function. The returned value is a member of the 8225021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// MachineJumpTableInfo::JTEntryKind enum. 8235021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov virtual unsigned getJumpTableEncoding() const; 8245021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 825ab953332bca70799b908ae0bfffb10c5d7a7a7f7Bernardo Rufino virtual const MCExpr * 8265021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov LowerCustomJumpTableEntry(const MachineJumpTableInfo * /*MJTI*/, 8279699fe319e78c681e638e8d5dee7954e15f8a96bRobert Berry const MachineBasicBlock * /*MBB*/, unsigned /*uid*/, 8285021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov MCContext &/*Ctx*/) const { 8295021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov llvm_unreachable("Need to implement this hook if target has custom JTIs"); 830f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov } 8315021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 8325021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// getPICJumpTableRelocaBase - Returns relocation base for the given PIC 8335021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// jumptable. 8345021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov virtual SDValue getPICJumpTableRelocBase(SDValue Table, 8355021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov SelectionDAG &DAG) const; 836f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov 8375021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// getPICJumpTableRelocBaseExpr - This returns the relocation base for the 8385021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// given PIC jumptable, the same as getPICJumpTableRelocBase, but as an 8395021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// MCExpr. 8405021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov virtual const MCExpr * 8415021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov getPICJumpTableRelocBaseExpr(const MachineFunction *MF, 8425021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov unsigned JTI, MCContext &Ctx) const; 8435021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 844924afe2b0f721afa857a55c33da559f6efc41d32Christopher Tate /// isOffsetFoldingLegal - Return true if folding a constant offset 8455021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// with the given GlobalAddress is legal. It is frequently not legal in 8465021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// PIC relocation models. 847ed961d90ea737f72d85b8a9105c191ed2a9b8f23Christopher Tate virtual bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const; 848924afe2b0f721afa857a55c33da559f6efc41d32Christopher Tate 8495021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// getStackCookieLocation - Return true if the target stores stack 8505021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// protector cookies at a fixed offset in some non-standard address 8515021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// space, and populates the address space and offset as 8525021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// appropriate. 8535021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov virtual bool getStackCookieLocation(unsigned &/*AddressSpace*/, 8545021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov unsigned &/*Offset*/) const { 855bcc0c1d1139872b64b0466d03761bc37eb05720bTim Zheng return false; 8567d3033b11f6ddd75c9a6e49d69bc432053ce8cbaAnnie Meng } 8577d3033b11f6ddd75c9a6e49d69bc432053ce8cbaAnnie Meng 8587d3033b11f6ddd75c9a6e49d69bc432053ce8cbaAnnie Meng /// getMaximalGlobalOffset - Returns the maximal possible offset which can be 8597d3033b11f6ddd75c9a6e49d69bc432053ce8cbaAnnie Meng /// used for loads / stores from the global. 860bcc0c1d1139872b64b0466d03761bc37eb05720bTim Zheng virtual unsigned getMaximalGlobalOffset() const { 8615021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov return 0; 8625021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov } 8635021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 8645021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov //===--------------------------------------------------------------------===// 8655021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov // TargetLowering Optimization Methods 8665021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov // 8675021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 8685021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// TargetLoweringOpt - A convenience struct that encapsulates a DAG, and two 8695021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// SDValues for returning information from TargetLowering to its clients 8705021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// that want to combine 8715021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov struct TargetLoweringOpt { 872ab953332bca70799b908ae0bfffb10c5d7a7a7f7Bernardo Rufino SelectionDAG &DAG; 87341349c02a8867b956ff48752c2d3dffc124fc0fcBernardo Rufino bool LegalTys; 87441349c02a8867b956ff48752c2d3dffc124fc0fcBernardo Rufino bool LegalOps; 87541349c02a8867b956ff48752c2d3dffc124fc0fcBernardo Rufino SDValue Old; 87641349c02a8867b956ff48752c2d3dffc124fc0fcBernardo Rufino SDValue New; 8775021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 87841349c02a8867b956ff48752c2d3dffc124fc0fcBernardo Rufino explicit TargetLoweringOpt(SelectionDAG &InDAG, 87941349c02a8867b956ff48752c2d3dffc124fc0fcBernardo Rufino bool LT, bool LO) : 88041349c02a8867b956ff48752c2d3dffc124fc0fcBernardo Rufino DAG(InDAG), LegalTys(LT), LegalOps(LO) {} 8815021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 8825021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov bool LegalTypes() const { return LegalTys; } 8835021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov bool LegalOperations() const { return LegalOps; } 884c141d08b703b7ccf754be92f8be3a7752fc15c1aLenka Trochtova 885c141d08b703b7ccf754be92f8be3a7752fc15c1aLenka Trochtova bool CombineTo(SDValue O, SDValue N) { 8865021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov Old = O; 8875021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov New = N; 8885021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov return true; 8895021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov } 8905021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 8915021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// ShrinkDemandedConstant - Check to see if the specified operand of the 8925021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// specified instruction is a constant integer. If so, check to see if 8939464a3160d3f7eb9713f50f61e2fda47d903d6d0Michal Karpinski /// there are any bits set in the constant that are not demanded. If so, 8949464a3160d3f7eb9713f50f61e2fda47d903d6d0Michal Karpinski /// shrink the constant and return true. 8959464a3160d3f7eb9713f50f61e2fda47d903d6d0Michal Karpinski bool ShrinkDemandedConstant(SDValue Op, const APInt &Demanded); 8965021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 8979464a3160d3f7eb9713f50f61e2fda47d903d6d0Michal Karpinski /// ShrinkDemandedOp - Convert x+y to (VT)((SmallVT)x+(SmallVT)y) if the 8989464a3160d3f7eb9713f50f61e2fda47d903d6d0Michal Karpinski /// casts are free. This uses isZExtFree and ZERO_EXTEND for the widening 8995021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// cast, but it could be generalized for targets with other types of 9009464a3160d3f7eb9713f50f61e2fda47d903d6d0Michal Karpinski /// implicit widening casts. 9015021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov bool ShrinkDemandedOp(SDValue Op, unsigned BitWidth, const APInt &Demanded, 902f32ea1909a007d177764adfd463e2b124faf179bArtem Iglikov DebugLoc dl); 9035021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov }; 9049464a3160d3f7eb9713f50f61e2fda47d903d6d0Michal Karpinski 9055021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// SimplifyDemandedBits - Look at Op. At this point, we know that only the 9065021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// DemandedMask bits of the result of Op are ever used downstream. If we can 9075021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// use this information to simplify Op, create a new simplified DAG node and 9085021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// return true, returning the original and new nodes in Old and New. 9095021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// Otherwise, analyze the expression and return a mask of KnownOne and 9105021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// KnownZero bits for the expression (used to simplify the caller). 9115021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// The KnownZero/One bits may only be accurate for those bits in the 9125021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// DemandedMask. 9135021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov bool SimplifyDemandedBits(SDValue Op, const APInt &DemandedMask, 9145021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov APInt &KnownZero, APInt &KnownOne, 9155021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov TargetLoweringOpt &TLO, unsigned Depth = 0) const; 916a1109ef8da76fad3ff7974cbba2e90f7638cdb3cRobert Berry 917a1109ef8da76fad3ff7974cbba2e90f7638cdb3cRobert Berry /// computeMaskedBitsForTargetNode - Determine which of the bits specified in 9185021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// Mask are known to be either zero or one and return them in the 9195021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// KnownZero/KnownOne bitsets. 9205021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov virtual void computeMaskedBitsForTargetNode(const SDValue Op, 9215021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov APInt &KnownZero, 9225021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov APInt &KnownOne, 9235021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov const SelectionDAG &DAG, 9245021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov unsigned Depth = 0) const; 9255021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 9265021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// ComputeNumSignBitsForTargetNode - This method can be implemented by 9275021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// targets that want to expose additional information about sign bits to the 9285021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// DAG Combiner. 9295021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov virtual unsigned ComputeNumSignBitsForTargetNode(SDValue Op, 9305021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov unsigned Depth = 0) const; 9315021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 9325021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov struct DAGCombinerInfo { 9335021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov void *DC; // The DAG Combiner object. 9345021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov bool BeforeLegalize; 9355021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov bool BeforeLegalizeOps; 9365021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov bool CalledByLegalizer; 9375021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov public: 9385021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov SelectionDAG &DAG; 9395021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 9405021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov DAGCombinerInfo(SelectionDAG &dag, bool bl, bool blo, bool cl, void *dc) 9415021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov : DC(dc), BeforeLegalize(bl), BeforeLegalizeOps(blo), 9425021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov CalledByLegalizer(cl), DAG(dag) {} 9435021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 9445021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov bool isBeforeLegalize() const { return BeforeLegalize; } 9455021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov bool isBeforeLegalizeOps() const { return BeforeLegalizeOps; } 946a780907d9f343726e6d9baee5f4de802b8b8f5e0Robert Berry bool isCalledByLegalizer() const { return CalledByLegalizer; } 947a780907d9f343726e6d9baee5f4de802b8b8f5e0Robert Berry 948a780907d9f343726e6d9baee5f4de802b8b8f5e0Robert Berry void AddToWorklist(SDNode *N); 9495021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov void RemoveFromWorklist(SDNode *N); 9505021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov SDValue CombineTo(SDNode *N, const std::vector<SDValue> &To, 9515021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov bool AddTo = true); 9525021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov SDValue CombineTo(SDNode *N, SDValue Res, bool AddTo = true); 9535021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov SDValue CombineTo(SDNode *N, SDValue Res0, SDValue Res1, bool AddTo = true); 9545021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 9555021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov void CommitTargetLoweringOpt(const TargetLoweringOpt &TLO); 956f32ea1909a007d177764adfd463e2b124faf179bArtem Iglikov }; 9575021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 9585021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// SimplifySetCC - Try to simplify a setcc built with the specified operands 9595021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// and cc. If it is unable to simplify it, return a null SDValue. 9605021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov SDValue SimplifySetCC(EVT VT, SDValue N0, SDValue N1, 9615021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov ISD::CondCode Cond, bool foldBooleans, 962f32ea1909a007d177764adfd463e2b124faf179bArtem Iglikov DAGCombinerInfo &DCI, DebugLoc dl) const; 9635021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 9645021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// isGAPlusOffset - Returns true (and the GlobalValue and the offset) if the 9655021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// node is a GlobalAddress + offset. 9665021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov virtual bool 9675021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov isGAPlusOffset(SDNode *N, const GlobalValue* &GA, int64_t &Offset) const; 9685021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 9695021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// PerformDAGCombine - This method will be invoked for all target nodes and 9702c2c856b3a60e96e09261d2513b43acb7ff4b070Artem Iglikov /// for any target-independent nodes that the target has registered with 9712c2c856b3a60e96e09261d2513b43acb7ff4b070Artem Iglikov /// invoke it for. 9725c90ff0f26dc3e87c70702a1a09b587cb4c82568Michal Karpinski /// 9735021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// The semantics are as follows: 9745021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// Return Value: 9755021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// SDValue.Val == 0 - No change was made 9765021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// SDValue.Val == N - N was replaced, is dead, and is already handled. 9775021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// otherwise - N should be replaced by the returned Operand. 9785021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// 9795021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// In addition, methods provided by DAGCombinerInfo may be used to perform 9805021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// more complex transformations. 9815021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// 9825021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov virtual SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const; 9835021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 9845021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// isTypeDesirableForOp - Return true if the target has native support for 9855021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// the specified value type and it is 'desirable' to use the type for the 9865021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// given node type. e.g. On x86 i16 is legal, but undesirable since i16 9875021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// instruction encodings are longer and some i16 instructions are slow. 9885021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov virtual bool isTypeDesirableForOp(unsigned /*Opc*/, EVT VT) const { 9895021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov // By default, assume all legal types are desirable. 9905021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov return isTypeLegal(VT); 9912c2c856b3a60e96e09261d2513b43acb7ff4b070Artem Iglikov } 9922c2c856b3a60e96e09261d2513b43acb7ff4b070Artem Iglikov 9935c90ff0f26dc3e87c70702a1a09b587cb4c82568Michal Karpinski /// isDesirableToPromoteOp - Return true if it is profitable for dag combiner 9945021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// to transform a floating point op of specified opcode to a equivalent op of 9955021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// an integer type. e.g. f32 load -> i32 load can be profitable on ARM. 9965021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov virtual bool isDesirableToTransformToIntegerOp(unsigned /*Opc*/, 9975021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov EVT /*VT*/) const { 9985021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov return false; 9995021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov } 10005021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 10015021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// IsDesirableToPromoteOp - This method query the target whether it is 10025021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// beneficial for dag combiner to promote the specified node. If true, it 10035021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// should return the desired promotion type by reference. 10045021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov virtual bool IsDesirableToPromoteOp(SDValue /*Op*/, EVT &/*PVT*/) const { 10055021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov return false; 10065021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov } 10075021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 10085021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov //===--------------------------------------------------------------------===// 10095021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov // TargetLowering Configuration Methods - These methods should be invoked by 10105021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov // the derived class constructor to configure this object for the target. 10115021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov // 10125021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 10135021918605020c44c7ee66fbc896955abdd1517fArtem Iglikovprotected: 10145021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// setBooleanContents - Specify how the target extends the result of a 10155021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// boolean value from i1 to a wider type. See getBooleanContents. 1016f32ea1909a007d177764adfd463e2b124faf179bArtem Iglikov void setBooleanContents(BooleanContent Ty) { BooleanContents = Ty; } 10175021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// setBooleanVectorContents - Specify how the target extends the result 10182c2c856b3a60e96e09261d2513b43acb7ff4b070Artem Iglikov /// of a vector boolean value from a vector of i1 to a wider type. See 10195c90ff0f26dc3e87c70702a1a09b587cb4c82568Michal Karpinski /// getBooleanContents. 10205021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov void setBooleanVectorContents(BooleanContent Ty) { 10215021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov BooleanVectorContents = Ty; 10225021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov } 10235021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 10245021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// setSchedulingPreference - Specify the target scheduling preference. 10255021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov void setSchedulingPreference(Sched::Preference Pref) { 10265021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov SchedPreferenceInfo = Pref; 10275021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov } 10285021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 10295021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// setUseUnderscoreSetJmp - Indicate whether this target prefers to 10305021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// use _setjmp to implement llvm.setjmp or the non _ version. 1031f32ea1909a007d177764adfd463e2b124faf179bArtem Iglikov /// Defaults to false. 103221510f0b7571f0689dc48c4f8fdbafea883cbdd0Artem Iglikov void setUseUnderscoreSetJmp(bool Val) { 103321510f0b7571f0689dc48c4f8fdbafea883cbdd0Artem Iglikov UseUnderscoreSetJmp = Val; 10345021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov } 10355021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 10365021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// setUseUnderscoreLongJmp - Indicate whether this target prefers to 10375021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// use _longjmp to implement llvm.longjmp or the non _ version. 10385021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// Defaults to false. 10395021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov void setUseUnderscoreLongJmp(bool Val) { 10405021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov UseUnderscoreLongJmp = Val; 10415021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov } 10425021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 10435021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// setSupportJumpTables - Indicate whether the target can generate code for 10445021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// jump tables. 10455021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov void setSupportJumpTables(bool Val) { 10465021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov SupportJumpTables = Val; 10475021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov } 10485021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 10495021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// setMinimumJumpTableEntries - Indicate the number of blocks to generate 10505021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// jump tables rather than if sequence. 10515021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov void setMinimumJumpTableEntries(int Val) { 10525021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov MinimumJumpTableEntries = Val; 10535021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov } 10545021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 10555021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// setStackPointerRegisterToSaveRestore - If set to a physical register, this 10565021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// specifies the register that llvm.savestack/llvm.restorestack should save 10575021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// and restore. 10585021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov void setStackPointerRegisterToSaveRestore(unsigned R) { 10595021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov StackPointerRegisterToSaveRestore = R; 10605021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov } 10615021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 10625021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// setExceptionPointerRegister - If set to a physical register, this sets 10635021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// the register that receives the exception address on entry to a landing 10645021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// pad. 10655021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov void setExceptionPointerRegister(unsigned R) { 10665021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov ExceptionPointerRegister = R; 10675021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov } 10685021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 10695021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// setExceptionSelectorRegister - If set to a physical register, this sets 10705021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// the register that receives the exception typeid on entry to a landing 10715021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// pad. 10725021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov void setExceptionSelectorRegister(unsigned R) { 10735021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov ExceptionSelectorRegister = R; 1074c31a839fd3ecc91807d735884d09fcbaf62e9244Robert Berry } 1075c31a839fd3ecc91807d735884d09fcbaf62e9244Robert Berry 1076c31a839fd3ecc91807d735884d09fcbaf62e9244Robert Berry /// SelectIsExpensive - Tells the code generator not to expand operations 10775021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// into sequences that use the select operations if possible. 1078c31a839fd3ecc91807d735884d09fcbaf62e9244Robert Berry void setSelectIsExpensive(bool isExpensive = true) { 1079c31a839fd3ecc91807d735884d09fcbaf62e9244Robert Berry SelectIsExpensive = isExpensive; 10805021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov } 10815021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 1082c31a839fd3ecc91807d735884d09fcbaf62e9244Robert Berry /// JumpIsExpensive - Tells the code generator not to expand sequence of 1083c31a839fd3ecc91807d735884d09fcbaf62e9244Robert Berry /// operations into a separate sequences that increases the amount of 1084c31a839fd3ecc91807d735884d09fcbaf62e9244Robert Berry /// flow control. 10855021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov void setJumpIsExpensive(bool isExpensive = true) { 10865021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov JumpIsExpensive = isExpensive; 10875021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov } 10885021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 10895021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// setIntDivIsCheap - Tells the code generator that integer divide is 10905021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// expensive, and if possible, should be replaced by an alternate sequence 1091f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov /// of instructions not containing an integer divide. 10925021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov void setIntDivIsCheap(bool isCheap = true) { IntDivIsCheap = isCheap; } 10935021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 10945021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// addBypassSlowDiv - Tells the code generator which bitwidths to bypass. 10955021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov void addBypassSlowDiv(unsigned int SlowBitWidth, unsigned int FastBitWidth) { 10965021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov BypassSlowDivWidths[SlowBitWidth] = FastBitWidth; 10975021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov } 10985021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 10999699fe319e78c681e638e8d5dee7954e15f8a96bRobert Berry /// setPow2DivIsCheap - Tells the code generator that it shouldn't generate 11005021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// srl/add/sra for a signed divide by power of two, and let the target handle 11015021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// it. 11025021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov void setPow2DivIsCheap(bool isCheap = true) { Pow2DivIsCheap = isCheap; } 11035021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 11049699fe319e78c681e638e8d5dee7954e15f8a96bRobert Berry /// addRegisterClass - Add the specified register class as an available 11055021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// regclass for the specified value type. This indicates the selector can 11065021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// handle values of that class natively. 1107f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov void addRegisterClass(EVT VT, const TargetRegisterClass *RC) { 11089699fe319e78c681e638e8d5dee7954e15f8a96bRobert Berry assert((unsigned)VT.getSimpleVT().SimpleTy < array_lengthof(RegClassForVT)); 11095021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov AvailableRegClasses.push_back(std::make_pair(VT, RC)); 11105021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov RegClassForVT[VT.getSimpleVT().SimpleTy] = RC; 11117f14edea1d84bde1824529178c609fa5961051d2Bernardo Rufino } 111279155590e67a30f520677d9d22e215365d595a73Bernardo Rufino 111379155590e67a30f520677d9d22e215365d595a73Bernardo Rufino /// findRepresentativeClass - Return the largest legal super-reg register class 11147f14edea1d84bde1824529178c609fa5961051d2Bernardo Rufino /// of the register class for the specified type and its associated "cost". 111579155590e67a30f520677d9d22e215365d595a73Bernardo Rufino virtual std::pair<const TargetRegisterClass*, uint8_t> 11167f14edea1d84bde1824529178c609fa5961051d2Bernardo Rufino findRepresentativeClass(EVT VT) const; 111779155590e67a30f520677d9d22e215365d595a73Bernardo Rufino 111879155590e67a30f520677d9d22e215365d595a73Bernardo Rufino /// computeRegisterProperties - Once all of the register classes are added, 111979155590e67a30f520677d9d22e215365d595a73Bernardo Rufino /// this allows us to compute derived properties we expose. 112079155590e67a30f520677d9d22e215365d595a73Bernardo Rufino void computeRegisterProperties(); 11215021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 112279155590e67a30f520677d9d22e215365d595a73Bernardo Rufino /// setOperationAction - Indicate that the specified operation does not work 112379155590e67a30f520677d9d22e215365d595a73Bernardo Rufino /// with the specified type and indicate what to do about it. 11245021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov void setOperationAction(unsigned Op, MVT VT, 112579155590e67a30f520677d9d22e215365d595a73Bernardo Rufino LegalizeAction Action) { 112679155590e67a30f520677d9d22e215365d595a73Bernardo Rufino assert(Op < array_lengthof(OpActions[0]) && "Table isn't big enough!"); 112779155590e67a30f520677d9d22e215365d595a73Bernardo Rufino OpActions[(unsigned)VT.SimpleTy][Op] = (uint8_t)Action; 112879155590e67a30f520677d9d22e215365d595a73Bernardo Rufino } 112979155590e67a30f520677d9d22e215365d595a73Bernardo Rufino 113079155590e67a30f520677d9d22e215365d595a73Bernardo Rufino /// setLoadExtAction - Indicate that the specified load with extension does 113179155590e67a30f520677d9d22e215365d595a73Bernardo Rufino /// not work with the specified type and indicate what to do about it. 113279155590e67a30f520677d9d22e215365d595a73Bernardo Rufino void setLoadExtAction(unsigned ExtType, MVT VT, 113379155590e67a30f520677d9d22e215365d595a73Bernardo Rufino LegalizeAction Action) { 113479155590e67a30f520677d9d22e215365d595a73Bernardo Rufino assert(ExtType < ISD::LAST_LOADEXT_TYPE && VT < MVT::LAST_VALUETYPE && 113579155590e67a30f520677d9d22e215365d595a73Bernardo Rufino "Table isn't big enough!"); 113679155590e67a30f520677d9d22e215365d595a73Bernardo Rufino LoadExtActions[VT.SimpleTy][ExtType] = (uint8_t)Action; 113779155590e67a30f520677d9d22e215365d595a73Bernardo Rufino } 113879155590e67a30f520677d9d22e215365d595a73Bernardo Rufino 11397f14edea1d84bde1824529178c609fa5961051d2Bernardo Rufino /// setTruncStoreAction - Indicate that the specified truncating store does 11405021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// not work with the specified type and indicate what to do about it. 11415021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov void setTruncStoreAction(MVT ValVT, MVT MemVT, 11425021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov LegalizeAction Action) { 11435021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov assert(ValVT < MVT::LAST_VALUETYPE && MemVT < MVT::LAST_VALUETYPE && 11445021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov "Table isn't big enough!"); 11455021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov TruncStoreActions[ValVT.SimpleTy][MemVT.SimpleTy] = (uint8_t)Action; 1146f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov } 11475021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 1148a1109ef8da76fad3ff7974cbba2e90f7638cdb3cRobert Berry /// setIndexedLoadAction - Indicate that the specified indexed load does or 11495021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// does not work with the specified type and indicate what to do abort 11505021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// it. NOTE: All indexed mode loads are initialized to Expand in 11515021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// TargetLowering.cpp 11525021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov void setIndexedLoadAction(unsigned IdxMode, MVT VT, 11535021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov LegalizeAction Action) { 11545021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov assert(VT < MVT::LAST_VALUETYPE && IdxMode < ISD::LAST_INDEXED_MODE && 11555021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov (unsigned)Action < 0xf && "Table isn't big enough!"); 11565021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov // Load action are kept in the upper half. 11575021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov IndexedModeActions[(unsigned)VT.SimpleTy][IdxMode] &= ~0xf0; 11585021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov IndexedModeActions[(unsigned)VT.SimpleTy][IdxMode] |= ((uint8_t)Action) <<4; 11595021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov } 11605021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 11615021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// setIndexedStoreAction - Indicate that the specified indexed store does or 11625021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// does not work with the specified type and indicate what to do about 11635021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// it. NOTE: All indexed mode stores are initialized to Expand in 11645021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// TargetLowering.cpp 116521510f0b7571f0689dc48c4f8fdbafea883cbdd0Artem Iglikov void setIndexedStoreAction(unsigned IdxMode, MVT VT, 11665021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov LegalizeAction Action) { 11675021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov assert(VT < MVT::LAST_VALUETYPE && IdxMode < ISD::LAST_INDEXED_MODE && 11685021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov (unsigned)Action < 0xf && "Table isn't big enough!"); 11695021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov // Store action are kept in the lower half. 11705021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov IndexedModeActions[(unsigned)VT.SimpleTy][IdxMode] &= ~0x0f; 11715021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov IndexedModeActions[(unsigned)VT.SimpleTy][IdxMode] |= ((uint8_t)Action); 11725021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov } 11735021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 11745021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// setCondCodeAction - Indicate that the specified condition code is or isn't 11755021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// supported on the target and indicate what to do about it. 117641349c02a8867b956ff48752c2d3dffc124fc0fcBernardo Rufino void setCondCodeAction(ISD::CondCode CC, MVT VT, 117741349c02a8867b956ff48752c2d3dffc124fc0fcBernardo Rufino LegalizeAction Action) { 117841349c02a8867b956ff48752c2d3dffc124fc0fcBernardo Rufino assert(VT < MVT::LAST_VALUETYPE && 117941349c02a8867b956ff48752c2d3dffc124fc0fcBernardo Rufino (unsigned)CC < array_lengthof(CondCodeActions) && 118041349c02a8867b956ff48752c2d3dffc124fc0fcBernardo Rufino "Table isn't big enough!"); 118141349c02a8867b956ff48752c2d3dffc124fc0fcBernardo Rufino /// The lower 5 bits of the SimpleTy index into Nth 2bit set from the 64bit 11825021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// value and the upper 27 bits index into the second dimension of the 118341349c02a8867b956ff48752c2d3dffc124fc0fcBernardo Rufino /// array to select what 64bit value to use. 118441349c02a8867b956ff48752c2d3dffc124fc0fcBernardo Rufino CondCodeActions[(unsigned)CC][VT.SimpleTy >> 5] 11855021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov &= ~(uint64_t(3UL) << (VT.SimpleTy & 0x1F)*2); 118641349c02a8867b956ff48752c2d3dffc124fc0fcBernardo Rufino CondCodeActions[(unsigned)CC][VT.SimpleTy >> 5] 118741349c02a8867b956ff48752c2d3dffc124fc0fcBernardo Rufino |= (uint64_t)Action << (VT.SimpleTy & 0x1F)*2; 118841349c02a8867b956ff48752c2d3dffc124fc0fcBernardo Rufino } 118941349c02a8867b956ff48752c2d3dffc124fc0fcBernardo Rufino 119041349c02a8867b956ff48752c2d3dffc124fc0fcBernardo Rufino /// AddPromotedToType - If Opc/OrigVT is specified as being promoted, the 119141349c02a8867b956ff48752c2d3dffc124fc0fcBernardo Rufino /// promotion code defaults to trying a larger integer/fp until it can find 119241349c02a8867b956ff48752c2d3dffc124fc0fcBernardo Rufino /// one that works. If that default is insufficient, this method can be used 119341349c02a8867b956ff48752c2d3dffc124fc0fcBernardo Rufino /// by the target to override the default. 119441349c02a8867b956ff48752c2d3dffc124fc0fcBernardo Rufino void AddPromotedToType(unsigned Opc, MVT OrigVT, MVT DestVT) { 119541349c02a8867b956ff48752c2d3dffc124fc0fcBernardo Rufino PromoteToType[std::make_pair(Opc, OrigVT.SimpleTy)] = DestVT.SimpleTy; 119641349c02a8867b956ff48752c2d3dffc124fc0fcBernardo Rufino } 119741349c02a8867b956ff48752c2d3dffc124fc0fcBernardo Rufino 11985021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// setTargetDAGCombine - Targets should invoke this method for each target 11995021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// independent node that they want to provide a custom DAG combiner for by 1200f32ea1909a007d177764adfd463e2b124faf179bArtem Iglikov /// implementing the PerformDAGCombine virtual method. 12015021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov void setTargetDAGCombine(ISD::NodeType NT) { 12025021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov assert(unsigned(NT >> 3) < array_lengthof(TargetDAGCombineArray)); 12035021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov TargetDAGCombineArray[NT >> 3] |= 1 << (NT&7); 12045021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov } 12055021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 12065021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// setJumpBufSize - Set the target's required jmp_buf buffer size (in 12075021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// bytes); default is 200 12085021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov void setJumpBufSize(unsigned Size) { 12095021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov JumpBufSize = Size; 12105021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov } 12115021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 12125021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// setJumpBufAlignment - Set the target's required jmp_buf buffer 12135021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// alignment (in bytes); default is 0 12145021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov void setJumpBufAlignment(unsigned Align) { 12155021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov JumpBufAlignment = Align; 12165021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov } 121743f2d3d3374f8c8f40fc1035135d294c8853254eChristopher Tate 12185021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// setMinFunctionAlignment - Set the target's minimum function alignment (in 121921510f0b7571f0689dc48c4f8fdbafea883cbdd0Artem Iglikov /// log2(bytes)) 12205021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov void setMinFunctionAlignment(unsigned Align) { 12215021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov MinFunctionAlignment = Align; 12225021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov } 12235021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 12245021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// setPrefFunctionAlignment - Set the target's preferred function alignment. 122543f2d3d3374f8c8f40fc1035135d294c8853254eChristopher Tate /// This should be set if there is a performance benefit to 12265021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// higher-than-minimum alignment (in log2(bytes)) 12275021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov void setPrefFunctionAlignment(unsigned Align) { 12285021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov PrefFunctionAlignment = Align; 12295021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov } 12305021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 12315021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// setPrefLoopAlignment - Set the target's preferred loop alignment. Default 12325021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// alignment is zero, it means the target does not care about loop alignment. 12335021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// The alignment is specified in log2(bytes). 12345021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov void setPrefLoopAlignment(unsigned Align) { 123543f2d3d3374f8c8f40fc1035135d294c8853254eChristopher Tate PrefLoopAlignment = Align; 123643f2d3d3374f8c8f40fc1035135d294c8853254eChristopher Tate } 12375021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 12385021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// setMinStackArgumentAlignment - Set the minimum stack alignment of an 12395021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// argument (in log2(bytes)). 12405021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov void setMinStackArgumentAlignment(unsigned Align) { 12415021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov MinStackArgumentAlignment = Align; 12425021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov } 12435021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 12445021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// setShouldFoldAtomicFences - Set if the target's implementation of the 12455021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// atomic operation intrinsics includes locking. Default is false. 12465021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov void setShouldFoldAtomicFences(bool fold) { 12475021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov ShouldFoldAtomicFences = fold; 12485021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov } 12495021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 12505021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// setInsertFencesForAtomic - Set if the DAG builder should 12515021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// automatically insert fences and reduce the order of atomic memory 12525021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// operations to Monotonic. 12535021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov void setInsertFencesForAtomic(bool fence) { 12545021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov InsertFencesForAtomic = fence; 12555021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov } 12565021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 12575021918605020c44c7ee66fbc896955abdd1517fArtem Iglikovpublic: 12585021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov //===--------------------------------------------------------------------===// 12595021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov // Lowering methods - These methods must be implemented by targets so that 12605021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov // the SelectionDAGLowering code knows how to lower these. 12615021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov // 12625021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 12635021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// LowerFormalArguments - This hook must be implemented to lower the 12645021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// incoming (formal) arguments, described by the Ins array, into the 12655021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// specified DAG. The implementation should fill in the InVals array 12665021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// with legal-type argument values, and return the resulting token 12675021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// chain value. 126843f2d3d3374f8c8f40fc1035135d294c8853254eChristopher Tate /// 12695021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov virtual SDValue 12705021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov LowerFormalArguments(SDValue /*Chain*/, CallingConv::ID /*CallConv*/, 12712c2c856b3a60e96e09261d2513b43acb7ff4b070Artem Iglikov bool /*isVarArg*/, 12722c2c856b3a60e96e09261d2513b43acb7ff4b070Artem Iglikov const SmallVectorImpl<ISD::InputArg> &/*Ins*/, 12735c90ff0f26dc3e87c70702a1a09b587cb4c82568Michal Karpinski DebugLoc /*dl*/, SelectionDAG &/*DAG*/, 12745021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov SmallVectorImpl<SDValue> &/*InVals*/) const { 12755021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov llvm_unreachable("Not Implemented"); 12765021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov } 12775021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 12785021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov struct ArgListEntry { 12795021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov SDValue Node; 12805021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov Type* Ty; 12815021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov bool isSExt : 1; 12825021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov bool isZExt : 1; 12835021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov bool isInReg : 1; 12845021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov bool isSRet : 1; 12855021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov bool isNest : 1; 128643f2d3d3374f8c8f40fc1035135d294c8853254eChristopher Tate bool isByVal : 1; 128743f2d3d3374f8c8f40fc1035135d294c8853254eChristopher Tate uint16_t Alignment; 12885021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 12895021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov ArgListEntry() : isSExt(false), isZExt(false), isInReg(false), 12905021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov isSRet(false), isNest(false), isByVal(false), Alignment(0) { } 12915021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov }; 12925021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov typedef std::vector<ArgListEntry> ArgListTy; 12935021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 12945021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// CallLoweringInfo - This structure contains all information that is 12955021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// necessary for lowering calls. It is passed to TLI::LowerCallTo when the 12965021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// SelectionDAG builder needs to lower a call, and targets will see this 12975021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// struct in their LowerCall implementation. 12985021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov struct CallLoweringInfo { 12995021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov SDValue Chain; 13005021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov Type *RetTy; 13015021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov bool RetSExt : 1; 13025021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov bool RetZExt : 1; 13035021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov bool IsVarArg : 1; 13045021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov bool IsInReg : 1; 13055021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov bool DoesNotReturn : 1; 13065021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov bool IsReturnValueUsed : 1; 13075021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 13085021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov // IsTailCall should be modified by implementations of 13095021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov // TargetLowering::LowerCall that perform tail call conversions. 13105021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov bool IsTailCall; 131143f2d3d3374f8c8f40fc1035135d294c8853254eChristopher Tate 131243f2d3d3374f8c8f40fc1035135d294c8853254eChristopher Tate unsigned NumFixedArgs; 131343f2d3d3374f8c8f40fc1035135d294c8853254eChristopher Tate CallingConv::ID CallConv; 13145021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov SDValue Callee; 13155021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov ArgListTy &Args; 13165021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov SelectionDAG &DAG; 13175021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov DebugLoc DL; 13185021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov ImmutableCallSite *CS; 13195021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov SmallVector<ISD::OutputArg, 32> Outs; 13205021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov SmallVector<SDValue, 32> OutVals; 1321f32ea1909a007d177764adfd463e2b124faf179bArtem Iglikov SmallVector<ISD::InputArg, 32> Ins; 13225021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 13235021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 13245021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// CallLoweringInfo - Constructs a call lowering context based on the 13255021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// ImmutableCallSite \p cs. 13265021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov CallLoweringInfo(SDValue chain, Type *retTy, 13275021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov FunctionType *FTy, bool isTailCall, SDValue callee, 13285021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov ArgListTy &args, SelectionDAG &dag, DebugLoc dl, 13295021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov ImmutableCallSite &cs) 13305021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov : Chain(chain), RetTy(retTy), RetSExt(cs.paramHasAttr(0, Attributes::SExt)), 13315021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov RetZExt(cs.paramHasAttr(0, Attributes::ZExt)), IsVarArg(FTy->isVarArg()), 13325021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov IsInReg(cs.paramHasAttr(0, Attributes::InReg)), 13335021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov DoesNotReturn(cs.doesNotReturn()), 13345021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov IsReturnValueUsed(!cs.getInstruction()->use_empty()), 13355021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov IsTailCall(isTailCall), NumFixedArgs(FTy->getNumParams()), 13365021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov CallConv(cs.getCallingConv()), Callee(callee), Args(args), DAG(dag), 13375021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov DL(dl), CS(&cs) {} 13385021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 13395021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// CallLoweringInfo - Constructs a call lowering context based on the 13405021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// provided call information. 13415021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov CallLoweringInfo(SDValue chain, Type *retTy, bool retSExt, bool retZExt, 13425021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov bool isVarArg, bool isInReg, unsigned numFixedArgs, 13435021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov CallingConv::ID callConv, bool isTailCall, 13445021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov bool doesNotReturn, bool isReturnValueUsed, SDValue callee, 13455021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov ArgListTy &args, SelectionDAG &dag, DebugLoc dl) 13465021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov : Chain(chain), RetTy(retTy), RetSExt(retSExt), RetZExt(retZExt), 13475021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov IsVarArg(isVarArg), IsInReg(isInReg), DoesNotReturn(doesNotReturn), 13485021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov IsReturnValueUsed(isReturnValueUsed), IsTailCall(isTailCall), 13495021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov NumFixedArgs(numFixedArgs), CallConv(callConv), Callee(callee), 13505021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov Args(args), DAG(dag), DL(dl), CS(NULL) {} 13515021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov }; 13525021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 13535021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// LowerCallTo - This function lowers an abstract call to a function into an 13545021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// actual call. This returns a pair of operands. The first element is the 13555021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// return value for the function (if RetTy is not VoidTy). The second 13565021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// element is the outgoing token chain. It calls LowerCall to do the actual 13575021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// lowering. 13585021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov std::pair<SDValue, SDValue> LowerCallTo(CallLoweringInfo &CLI) const; 13595021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 13605021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// LowerCall - This hook must be implemented to lower calls into the 13615021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// the specified DAG. The outgoing arguments to the call are described 1362f32ea1909a007d177764adfd463e2b124faf179bArtem Iglikov /// by the Outs array, and the values to be returned by the call are 13635021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// described by the Ins array. The implementation should fill in the 13645021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// InVals array with legal-type return values from the call, and return 13655021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// the resulting token chain value. 13665021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov virtual SDValue 13675021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov LowerCall(CallLoweringInfo &/*CLI*/, 136821510f0b7571f0689dc48c4f8fdbafea883cbdd0Artem Iglikov SmallVectorImpl<SDValue> &/*InVals*/) const { 136921510f0b7571f0689dc48c4f8fdbafea883cbdd0Artem Iglikov llvm_unreachable("Not Implemented"); 137021510f0b7571f0689dc48c4f8fdbafea883cbdd0Artem Iglikov } 137121510f0b7571f0689dc48c4f8fdbafea883cbdd0Artem Iglikov 13725021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// HandleByVal - Target-specific cleanup for formal ByVal parameters. 13735021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov virtual void HandleByVal(CCState *, unsigned &, unsigned) const {} 13745021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 13755021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// CanLowerReturn - This hook should be implemented to check whether the 13765021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// return values described by the Outs array can fit into the return 13775021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// registers. If false is returned, an sret-demotion is performed. 13785021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// 13795021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov virtual bool CanLowerReturn(CallingConv::ID /*CallConv*/, 13805021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov MachineFunction &/*MF*/, bool /*isVarArg*/, 13815021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov const SmallVectorImpl<ISD::OutputArg> &/*Outs*/, 13825021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov LLVMContext &/*Context*/) const 13835021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov { 13845021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov // Return true by default to get preexisting behavior. 13855021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov return true; 13865021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov } 13875021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 13885021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// LowerReturn - This hook must be implemented to lower outgoing 13895021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// return values, described by the Outs array, into the specified 13905021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// DAG. The implementation should return the resulting token chain 13915021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// value. 13925021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// 13935021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov virtual SDValue 13945021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov LowerReturn(SDValue /*Chain*/, CallingConv::ID /*CallConv*/, 13955021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov bool /*isVarArg*/, 13965021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov const SmallVectorImpl<ISD::OutputArg> &/*Outs*/, 13975021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov const SmallVectorImpl<SDValue> &/*OutVals*/, 13985021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov DebugLoc /*dl*/, SelectionDAG &/*DAG*/) const { 13995021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov llvm_unreachable("Not Implemented"); 14005021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov } 1401f32ea1909a007d177764adfd463e2b124faf179bArtem Iglikov 14025021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// isUsedByReturnOnly - Return true if result of the specified node is used 1403528c3e572a829c51053532803ff31da123ebfed9Michal Karpinski /// by a return node only. It also compute and return the input chain for the 14045021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// tail call. 14055021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// This is used to determine whether it is possible 140621510f0b7571f0689dc48c4f8fdbafea883cbdd0Artem Iglikov /// to codegen a libcall as tail call at legalization time. 14075021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov virtual bool isUsedByReturnOnly(SDNode *, SDValue &Chain) const { 14085021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov return false; 14095021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov } 141021510f0b7571f0689dc48c4f8fdbafea883cbdd0Artem Iglikov 14115021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// mayBeEmittedAsTailCall - Return true if the target may be able emit the 141221510f0b7571f0689dc48c4f8fdbafea883cbdd0Artem Iglikov /// call instruction as a tail call. This is used by optimization passes to 14135021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// determine if it's profitable to duplicate return instructions to enable 141421510f0b7571f0689dc48c4f8fdbafea883cbdd0Artem Iglikov /// tailcall optimization. 14155021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov virtual bool mayBeEmittedAsTailCall(CallInst *) const { 14165021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov return false; 14175021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov } 14185021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 14195021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// getTypeForExtArgOrReturn - Return the type that should be used to zero or 14205021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// sign extend a zeroext/signext integer argument or return value. 14215021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// FIXME: Most C calling convention requires the return type to be promoted, 14225021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// but this is not true all the time, e.g. i1 on x86-64. It is also not 14235021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// necessary for non-C calling conventions. The frontend should handle this 14245021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// and include all of the necessary information. 14255021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov virtual EVT getTypeForExtArgOrReturn(LLVMContext &Context, EVT VT, 14265021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov ISD::NodeType /*ExtendKind*/) const { 14275021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov EVT MinVT = getRegisterType(Context, MVT::i32); 14285021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov return VT.bitsLT(MinVT) ? MinVT : VT; 14295021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov } 14305021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 14315021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// LowerOperationWrapper - This callback is invoked by the type legalizer 1432f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov /// to legalize nodes with an illegal operand type but legal result types. 14335021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// It replaces the LowerOperation callback in the type Legalizer. 14345021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// The reason we can not do away with LowerOperation entirely is that 143502a1c08096b705f8091951ac7d9afb7f7166b66fDenis Kuznetsov /// LegalizeDAG isn't yet ready to use this callback. 143602a1c08096b705f8091951ac7d9afb7f7166b66fDenis Kuznetsov /// TODO: Consider merging with ReplaceNodeResults. 143702a1c08096b705f8091951ac7d9afb7f7166b66fDenis Kuznetsov 143802a1c08096b705f8091951ac7d9afb7f7166b66fDenis Kuznetsov /// The target places new result values for the node in Results (their number 14399fcc8ffd7bdc2e604df39ebaf9a5e9fd1385de4eBartosz Fabianowski /// and types must exactly match those of the original return values of 14409fcc8ffd7bdc2e604df39ebaf9a5e9fd1385de4eBartosz Fabianowski /// the node), or leaves Results empty, which indicates that the node is not 144102a1c08096b705f8091951ac7d9afb7f7166b66fDenis Kuznetsov /// to be custom lowered after all. 144202a1c08096b705f8091951ac7d9afb7f7166b66fDenis Kuznetsov /// The default implementation calls LowerOperation. 144302a1c08096b705f8091951ac7d9afb7f7166b66fDenis Kuznetsov virtual void LowerOperationWrapper(SDNode *N, 144402a1c08096b705f8091951ac7d9afb7f7166b66fDenis Kuznetsov SmallVectorImpl<SDValue> &Results, 1445a1109ef8da76fad3ff7974cbba2e90f7638cdb3cRobert Berry SelectionDAG &DAG) const; 14465021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 14475021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// LowerOperation - This callback is invoked for operations that are 14485021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// unsupported by the target, which are registered to use 'custom' lowering, 14495021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// and whose defined values are all legal. 14505021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// If the target has no operations that require custom lowering, it need not 1451f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov /// implement this. The default implementation of this aborts. 1452a780907d9f343726e6d9baee5f4de802b8b8f5e0Robert Berry virtual SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const; 14535021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 14545021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// ReplaceNodeResults - This callback is invoked when a node result type is 14555021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// illegal for the target, and the operation was registered to use 'custom' 14565021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// lowering for that result type. The target places new result values for 14575021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// the node in Results (their number and types must exactly match those of 14585021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// the original return values of the node), or leaves Results empty, which 14595021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// indicates that the node is not to be custom lowered after all. 14605021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// 14615021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// If the target has no operations that require custom lowering, it need not 14625021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// implement this. The default implementation aborts. 14635021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov virtual void ReplaceNodeResults(SDNode * /*N*/, 14645021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov SmallVectorImpl<SDValue> &/*Results*/, 14655021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov SelectionDAG &/*DAG*/) const { 14665021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov llvm_unreachable("ReplaceNodeResults not implemented for this target!"); 14675021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov } 14685021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 14695021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// getTargetNodeName() - This method returns the name of a target specific 14705021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// DAG node. 14715021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov virtual const char *getTargetNodeName(unsigned Opcode) const; 14725021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 14735021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// createFastISel - This method returns a target specific FastISel object, 14745021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// or null if the target does not support "fast" ISel. 14755021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov virtual FastISel *createFastISel(FunctionLoweringInfo &, 14765021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov const TargetLibraryInfo *) const { 14775021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov return 0; 14785021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov } 14795021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 148021510f0b7571f0689dc48c4f8fdbafea883cbdd0Artem Iglikov //===--------------------------------------------------------------------===// 14815021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov // Inline Asm Support hooks 14825021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov // 14835021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 14845021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// ExpandInlineAsm - This hook allows the target to expand an inline asm 14855021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// call to be explicit llvm code if it wants to. This is useful for 14865021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// turning simple inline asms into LLVM intrinsics, which gives the 14875021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// compiler more information about the behavior of the code. 14885021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov virtual bool ExpandInlineAsm(CallInst *) const { 14895021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov return false; 14905021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov } 14915021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 14925021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov enum ConstraintType { 14935021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov C_Register, // Constraint represents specific register(s). 14945021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov C_RegisterClass, // Constraint represents any of register(s) in class. 14955021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov C_Memory, // Memory constraint. 14965021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov C_Other, // Something else. 14975021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov C_Unknown // Unsupported constraint. 14985021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov }; 14995021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 15005021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov enum ConstraintWeight { 15015021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov // Generic weights. 15025021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov CW_Invalid = -1, // No match. 15035021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov CW_Okay = 0, // Acceptable. 15045021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov CW_Good = 1, // Good weight. 15055021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov CW_Better = 2, // Better weight. 15065021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov CW_Best = 3, // Best weight. 15075021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 15085021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov // Well-known weights. 15095021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov CW_SpecificReg = CW_Okay, // Specific register operands. 15105021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov CW_Register = CW_Good, // Register operands. 15115021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov CW_Memory = CW_Better, // Memory operands. 15125021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov CW_Constant = CW_Best, // Constant operand. 15135021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov CW_Default = CW_Okay // Default or don't know type. 15145021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov }; 15155021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 15165021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// AsmOperandInfo - This contains information for each constraint that we are 15175021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// lowering. 15185021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov struct AsmOperandInfo : public InlineAsm::ConstraintInfo { 15195021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// ConstraintCode - This contains the actual string for the code, like "m". 15205021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// TargetLowering picks the 'best' code from ConstraintInfo::Codes that 15215021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// most closely matches the operand. 15225021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov std::string ConstraintCode; 15235021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 15245021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// ConstraintType - Information about the constraint code, e.g. Register, 15255021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// RegisterClass, Memory, Other, Unknown. 15261d99c391ecd30c27be2e8f61aa9ec64546d15d4bChristopher Tate TargetLowering::ConstraintType ConstraintType; 15271d99c391ecd30c27be2e8f61aa9ec64546d15d4bChristopher Tate 15281d99c391ecd30c27be2e8f61aa9ec64546d15d4bChristopher Tate /// CallOperandval - If this is the result output operand or a 15291d99c391ecd30c27be2e8f61aa9ec64546d15d4bChristopher Tate /// clobber, this is null, otherwise it is the incoming operand to the 15301d99c391ecd30c27be2e8f61aa9ec64546d15d4bChristopher Tate /// CallInst. This gets modified as the asm is processed. 15315021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov Value *CallOperandVal; 15325021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 15335021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// ConstraintVT - The ValueType for the operand value. 15345021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov EVT ConstraintVT; 153521510f0b7571f0689dc48c4f8fdbafea883cbdd0Artem Iglikov 153621510f0b7571f0689dc48c4f8fdbafea883cbdd0Artem Iglikov /// isMatchingInputConstraint - Return true of this is an input operand that 153721510f0b7571f0689dc48c4f8fdbafea883cbdd0Artem Iglikov /// is a matching constraint like "4". 153821510f0b7571f0689dc48c4f8fdbafea883cbdd0Artem Iglikov bool isMatchingInputConstraint() const; 15395021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 15405021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// getMatchedOperand - If this is an input matching constraint, this method 15415021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// returns the output operand it matches. 15425021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov unsigned getMatchedOperand() const; 15435021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 15445021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// Copy constructor for copying from an AsmOperandInfo. 15455021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov AsmOperandInfo(const AsmOperandInfo &info) 1546f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov : InlineAsm::ConstraintInfo(info), 15475021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov ConstraintCode(info.ConstraintCode), 154821510f0b7571f0689dc48c4f8fdbafea883cbdd0Artem Iglikov ConstraintType(info.ConstraintType), 15495021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov CallOperandVal(info.CallOperandVal), 15505021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov ConstraintVT(info.ConstraintVT) { 15511d99c391ecd30c27be2e8f61aa9ec64546d15d4bChristopher Tate } 15525021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 15535021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// Copy constructor for copying from a ConstraintInfo. 15545021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov AsmOperandInfo(const InlineAsm::ConstraintInfo &info) 15555021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov : InlineAsm::ConstraintInfo(info), 15565021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov ConstraintType(TargetLowering::C_Unknown), 15575021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov CallOperandVal(0), ConstraintVT(MVT::Other) { 15585021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov } 15595021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov }; 15605021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 15615021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov typedef std::vector<AsmOperandInfo> AsmOperandInfoVector; 15625021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 15635021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// ParseConstraints - Split up the constraint string from the inline 15645021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// assembly value into the specific constraints and their prefixes, 15655021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// and also tie in the associated operand values. 15665021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// If this returns an empty vector, and if the constraint string itself 15675021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// isn't empty, there was an error parsing. 15685021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov virtual AsmOperandInfoVector ParseConstraints(ImmutableCallSite CS) const; 15695021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 15705021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// Examine constraint type and operand type and determine a weight value. 15715021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// The operand object must already have been set up with the operand type. 15725021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov virtual ConstraintWeight getMultipleConstraintMatchWeight( 15735021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov AsmOperandInfo &info, int maIndex) const; 15745021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 15755021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// Examine constraint string and operand type and determine a weight value. 15765021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// The operand object must already have been set up with the operand type. 15775021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov virtual ConstraintWeight getSingleConstraintMatchWeight( 15785246299c58888ac1ccf2acc5c6ffdbd070c251ebMichal Karpinski AsmOperandInfo &info, const char *constraint) const; 15795021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 15805021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// ComputeConstraintToUse - Determines the constraint code and constraint 15815021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// type to use for the specific AsmOperandInfo, setting 15825021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// OpInfo.ConstraintCode and OpInfo.ConstraintType. If the actual operand 15835021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// being passed in is available, it can be passed in as Op, otherwise an 15845021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// empty SDValue can be passed. 15855021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov virtual void ComputeConstraintToUse(AsmOperandInfo &OpInfo, 15865021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov SDValue Op, 15875021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov SelectionDAG *DAG = 0) const; 15885021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 15895021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// getConstraintType - Given a constraint, return the type of constraint it 15905021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// is for this target. 15915021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov virtual ConstraintType getConstraintType(const std::string &Constraint) const; 15929448196076d5a5266b3ae7e4945216b30ee88aa7Sergey Poromov 15939448196076d5a5266b3ae7e4945216b30ee88aa7Sergey Poromov /// getRegForInlineAsmConstraint - Given a physical register constraint (e.g. 15949448196076d5a5266b3ae7e4945216b30ee88aa7Sergey Poromov /// {edx}), return the register number and the register class for the 1595b1f573dca3ccdd113ca513f32c9964211ca71c78Stefanot /// register. 15965021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// 15975021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// Given a register class constraint, like 'r', if this corresponds directly 15985021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// to an LLVM register class, return a register of 0 and the register class 15995021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// pointer. 16005021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// 16012c2c856b3a60e96e09261d2513b43acb7ff4b070Artem Iglikov /// This should only be used for C_Register constraints. On error, 16022c2c856b3a60e96e09261d2513b43acb7ff4b070Artem Iglikov /// this returns a register number of 0 and a null register class pointer.. 16032c2c856b3a60e96e09261d2513b43acb7ff4b070Artem Iglikov virtual std::pair<unsigned, const TargetRegisterClass*> 16045021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov getRegForInlineAsmConstraint(const std::string &Constraint, 16055021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov EVT VT) const; 16065021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 16075021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// LowerXConstraint - try to replace an X constraint, which matches anything, 16081a30fcd99547d8da870a66e0799b40b77e783304Christopher Tate /// with another that has more specific requirements based on the type of the 1609bcc0c1d1139872b64b0466d03761bc37eb05720bTim Zheng /// corresponding operand. This returns null if there is no replacement to 1610bcc0c1d1139872b64b0466d03761bc37eb05720bTim Zheng /// make. 1611bcc0c1d1139872b64b0466d03761bc37eb05720bTim Zheng virtual const char *LowerXConstraint(EVT ConstraintVT) const; 16121a30fcd99547d8da870a66e0799b40b77e783304Christopher Tate 16131a30fcd99547d8da870a66e0799b40b77e783304Christopher Tate /// LowerAsmOperandForConstraint - Lower the specified operand into the Ops 16141a30fcd99547d8da870a66e0799b40b77e783304Christopher Tate /// vector. If it is invalid, don't add anything to Ops. 16151a30fcd99547d8da870a66e0799b40b77e783304Christopher Tate virtual void LowerAsmOperandForConstraint(SDValue Op, std::string &Constraint, 16161a30fcd99547d8da870a66e0799b40b77e783304Christopher Tate std::vector<SDValue> &Ops, 16171a30fcd99547d8da870a66e0799b40b77e783304Christopher Tate SelectionDAG &DAG) const; 16181a30fcd99547d8da870a66e0799b40b77e783304Christopher Tate 16191a30fcd99547d8da870a66e0799b40b77e783304Christopher Tate //===--------------------------------------------------------------------===// 1620516ac95746bd1091732e4bc407e2941debdc38d9Bernardo Rufino // Instruction Emitting Hooks 1621516ac95746bd1091732e4bc407e2941debdc38d9Bernardo Rufino // 1622516ac95746bd1091732e4bc407e2941debdc38d9Bernardo Rufino 1623516ac95746bd1091732e4bc407e2941debdc38d9Bernardo Rufino // EmitInstrWithCustomInserter - This method should be implemented by targets 1624516ac95746bd1091732e4bc407e2941debdc38d9Bernardo Rufino // that mark instructions with the 'usesCustomInserter' flag. These 1625516ac95746bd1091732e4bc407e2941debdc38d9Bernardo Rufino // instructions are special in various ways, which require special support to 1626516ac95746bd1091732e4bc407e2941debdc38d9Bernardo Rufino // insert. The specified MachineInstr is created but not inserted into any 1627516ac95746bd1091732e4bc407e2941debdc38d9Bernardo Rufino // basic blocks, and this method is called to expand it into a sequence of 1628516ac95746bd1091732e4bc407e2941debdc38d9Bernardo Rufino // instructions, potentially also creating new basic blocks and control flow. 16292c2c856b3a60e96e09261d2513b43acb7ff4b070Artem Iglikov virtual MachineBasicBlock * 16302c2c856b3a60e96e09261d2513b43acb7ff4b070Artem Iglikov EmitInstrWithCustomInserter(MachineInstr *MI, MachineBasicBlock *MBB) const; 16312c2c856b3a60e96e09261d2513b43acb7ff4b070Artem Iglikov 16325021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// AdjustInstrPostInstrSelection - This method should be implemented by 16335021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// targets that mark instructions with the 'hasPostISelHook' flag. These 16345021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// instructions must be adjusted after instruction selection by target hooks. 16355021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// e.g. To fill in optional defs for ARM 's' setting instructions. 1636af547f4a15a7d6121306a5e973ae7f3709e5df3aBernardo Rufino virtual void 1637af547f4a15a7d6121306a5e973ae7f3709e5df3aBernardo Rufino AdjustInstrPostInstrSelection(MachineInstr *MI, SDNode *Node) const; 1638af547f4a15a7d6121306a5e973ae7f3709e5df3aBernardo Rufino 16395021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov //===--------------------------------------------------------------------===// 16405021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov // Addressing mode description hooks (used by LSR etc). 16415021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov // 16425021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 16435021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// GetAddrModeArguments - CodeGenPrepare sinks address calculations into the 16445021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// same BB as Load/Store instructions reading the address. This allows as 16455021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// much computation as possible to be done in the address mode for that 16465021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// operand. This hook lets targets also pass back when this should be done 16475021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// on intrinsics which load/store. 1648528c3e572a829c51053532803ff31da123ebfed9Michal Karpinski virtual bool GetAddrModeArguments(IntrinsicInst *I, 16495c90ff0f26dc3e87c70702a1a09b587cb4c82568Michal Karpinski SmallVectorImpl<Value*> &Ops, 16505c90ff0f26dc3e87c70702a1a09b587cb4c82568Michal Karpinski Type *&AccessTy) const { 16512c2c856b3a60e96e09261d2513b43acb7ff4b070Artem Iglikov return false; 16525021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov } 16535021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 16545021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// isLegalAddressingMode - Return true if the addressing mode represented by 16552c2c856b3a60e96e09261d2513b43acb7ff4b070Artem Iglikov /// AM is legal for this target, for a load/store of the specified type. 16565021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// The type may be VoidTy, in which case only return true if the addressing 16575021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// mode is legal for a load/store of any legal type. 16585021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// TODO: Handle pre/postinc as well. 16595021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov virtual bool isLegalAddressingMode(const AddrMode &AM, Type *Ty) const; 16605021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 16612c2c856b3a60e96e09261d2513b43acb7ff4b070Artem Iglikov /// isLegalICmpImmediate - Return true if the specified immediate is legal 16625021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// icmp immediate, that is the target has icmp instructions which can compare 16635021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// a register against the immediate without having to materialize the 16645021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// immediate into a register. 16655021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov virtual bool isLegalICmpImmediate(int64_t) const { 16665021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov return true; 16675021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov } 16685021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 166921510f0b7571f0689dc48c4f8fdbafea883cbdd0Artem Iglikov /// isLegalAddImmediate - Return true if the specified immediate is legal 167021510f0b7571f0689dc48c4f8fdbafea883cbdd0Artem Iglikov /// add immediate, that is the target has add instructions which can add 16715021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// a register with the immediate without having to materialize the 16725021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// immediate into a register. 16735021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov virtual bool isLegalAddImmediate(int64_t) const { 16745021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov return true; 16755021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov } 1676516ac95746bd1091732e4bc407e2941debdc38d9Bernardo Rufino 1677516ac95746bd1091732e4bc407e2941debdc38d9Bernardo Rufino /// isTruncateFree - Return true if it's free to truncate a value of 16785021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// type Ty1 to type Ty2. e.g. On x86 it's free to truncate a i32 value in 16795021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// register EAX to i16 by referencing its sub-register AX. 16805021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov virtual bool isTruncateFree(Type * /*Ty1*/, Type * /*Ty2*/) const { 16815021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov return false; 16825021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov } 16835021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 168421510f0b7571f0689dc48c4f8fdbafea883cbdd0Artem Iglikov virtual bool isTruncateFree(EVT /*VT1*/, EVT /*VT2*/) const { 16855021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov return false; 16865021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov } 16875021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 16885021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// isZExtFree - Return true if any actual instruction that defines a 16895021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// value of type Ty1 implicitly zero-extends the value to Ty2 in the result 16905021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// register. This does not necessarily include registers defined in 16915021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// unknown ways, such as incoming arguments, or copies from unknown 16925021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// virtual registers. Also, if isTruncateFree(Ty2, Ty1) is true, this 16935021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// does not necessarily apply to truncate instructions. e.g. on x86-64, 16945021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// all instructions that define 32-bit values implicit zero-extend the 16955021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// result out to 64 bits. 16965021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov virtual bool isZExtFree(Type * /*Ty1*/, Type * /*Ty2*/) const { 16975021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov return false; 16985021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov } 16995021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 17005021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov virtual bool isZExtFree(EVT /*VT1*/, EVT /*VT2*/) const { 17015021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov return false; 17025021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov } 17035021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 17045021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// isFNegFree - Return true if an fneg operation is free to the point where 17055021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// it is never worthwhile to replace it with a bitwise operation. 1706bcc0c1d1139872b64b0466d03761bc37eb05720bTim Zheng virtual bool isFNegFree(EVT) const { 1707bcc0c1d1139872b64b0466d03761bc37eb05720bTim Zheng return false; 17085021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov } 17095021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 17105021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// isFAbsFree - Return true if an fneg operation is free to the point where 17115021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// it is never worthwhile to replace it with a bitwise operation. 17125021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov virtual bool isFAbsFree(EVT) const { 17135021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov return false; 17145021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov } 171521510f0b7571f0689dc48c4f8fdbafea883cbdd0Artem Iglikov 17165021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// isFMAFasterThanMulAndAdd - Return true if an FMA operation is faster than 17175021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// a pair of mul and add instructions. fmuladd intrinsics will be expanded to 17185021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// FMAs when this method returns true (and FMAs are legal), otherwise fmuladd 17195021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// is expanded to mul + add. 17205021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov virtual bool isFMAFasterThanMulAndAdd(EVT) const { 172121510f0b7571f0689dc48c4f8fdbafea883cbdd0Artem Iglikov return false; 172221510f0b7571f0689dc48c4f8fdbafea883cbdd0Artem Iglikov } 172321510f0b7571f0689dc48c4f8fdbafea883cbdd0Artem Iglikov 172421510f0b7571f0689dc48c4f8fdbafea883cbdd0Artem Iglikov /// isNarrowingProfitable - Return true if it's profitable to narrow 17255021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// operations of type VT1 to VT2. e.g. on x86, it's profitable to narrow 17265021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// from i32 to i8 but not from i32 to i16. 17275021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov virtual bool isNarrowingProfitable(EVT /*VT1*/, EVT /*VT2*/) const { 17285021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov return false; 17295021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov } 17305021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 17315021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov //===--------------------------------------------------------------------===// 17325021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov // Div utility functions 17335021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov // 17345021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov SDValue BuildExactSDIV(SDValue Op1, SDValue Op2, DebugLoc dl, 17355021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov SelectionDAG &DAG) const; 17365021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov SDValue BuildSDIV(SDNode *N, SelectionDAG &DAG, bool IsAfterLegalization, 17375021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov std::vector<SDNode*>* Created) const; 17385021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov SDValue BuildUDIV(SDNode *N, SelectionDAG &DAG, bool IsAfterLegalization, 17395021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov std::vector<SDNode*>* Created) const; 17405021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 17415021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 17425021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov //===--------------------------------------------------------------------===// 17435021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov // Runtime Library hooks 17445021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov // 17455021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 17465021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// setLibcallName - Rename the default libcall routine name for the specified 1747f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov /// libcall. 17485021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov void setLibcallName(RTLIB::Libcall Call, const char *Name) { 17495021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov LibcallRoutineNames[Call] = Name; 17505021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov } 17515021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 17525021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// getLibcallName - Get the libcall routine name for the specified libcall. 17535021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// 17545021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov const char *getLibcallName(RTLIB::Libcall Call) const { 17555021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov return LibcallRoutineNames[Call]; 17565021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov } 17575021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 17585021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// setCmpLibcallCC - Override the default CondCode to be used to test the 17595021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// result of the comparison libcall against zero. 17605021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov void setCmpLibcallCC(RTLIB::Libcall Call, ISD::CondCode CC) { 17615021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov CmpLibcallCCs[Call] = CC; 17625021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov } 176321510f0b7571f0689dc48c4f8fdbafea883cbdd0Artem Iglikov 176421510f0b7571f0689dc48c4f8fdbafea883cbdd0Artem Iglikov /// getCmpLibcallCC - Get the CondCode that's to be used to test the result of 176521510f0b7571f0689dc48c4f8fdbafea883cbdd0Artem Iglikov /// the comparison libcall against zero. 176621510f0b7571f0689dc48c4f8fdbafea883cbdd0Artem Iglikov ISD::CondCode getCmpLibcallCC(RTLIB::Libcall Call) const { 17675021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov return CmpLibcallCCs[Call]; 17685021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov } 17695021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 17705021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// setLibcallCallingConv - Set the CallingConv that should be used for the 17715021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// specified libcall. 17725021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov void setLibcallCallingConv(RTLIB::Libcall Call, CallingConv::ID CC) { 17735021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov LibcallCallingConvs[Call] = CC; 17745021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov } 17755021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 17765021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// getLibcallCallingConv - Get the CallingConv that should be used for the 17775021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// specified libcall. 17785021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov CallingConv::ID getLibcallCallingConv(RTLIB::Libcall Call) const { 17795021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov return LibcallCallingConvs[Call]; 17805021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov } 17815021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 17825021918605020c44c7ee66fbc896955abdd1517fArtem Iglikovprivate: 17835021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov const TargetMachine &TM; 17845021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov const DataLayout *TD; 17855021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov const TargetLoweringObjectFile &TLOF; 17865021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 17875021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// PointerTy - The type to use for pointers for the default address space, 17885021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// usually i32 or i64. 17895021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// 17905021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov MVT PointerTy; 17915021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 17925021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// IsLittleEndian - True if this is a little endian target. 17935021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// 17945021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov bool IsLittleEndian; 17955021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 17965021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// SelectIsExpensive - Tells the code generator not to expand operations 17975021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// into sequences that use the select operations if possible. 17985021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov bool SelectIsExpensive; 179921510f0b7571f0689dc48c4f8fdbafea883cbdd0Artem Iglikov 180021510f0b7571f0689dc48c4f8fdbafea883cbdd0Artem Iglikov /// IntDivIsCheap - Tells the code generator not to expand integer divides by 180121510f0b7571f0689dc48c4f8fdbafea883cbdd0Artem Iglikov /// constants into a sequence of muls, adds, and shifts. This is a hack until 180221510f0b7571f0689dc48c4f8fdbafea883cbdd0Artem Iglikov /// a real cost model is in place. If we ever optimize for size, this will be 18035021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// set to true unconditionally. 18045021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov bool IntDivIsCheap; 18055021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 1806f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov /// BypassSlowDivMap - Tells the code generator to bypass slow divide or 18075021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// remainder instructions. For example, BypassSlowDivWidths[32,8] tells the 18085021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// code generator to bypass 32-bit integer div/rem with an 8-bit unsigned 18095021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// integer div/rem when the operands are positive and less than 256. 18105021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov DenseMap <unsigned int, unsigned int> BypassSlowDivWidths; 18115021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 181221510f0b7571f0689dc48c4f8fdbafea883cbdd0Artem Iglikov /// Pow2DivIsCheap - Tells the code generator that it shouldn't generate 181321510f0b7571f0689dc48c4f8fdbafea883cbdd0Artem Iglikov /// srl/add/sra for a signed divide by power of two, and let the target handle 181421510f0b7571f0689dc48c4f8fdbafea883cbdd0Artem Iglikov /// it. 181521510f0b7571f0689dc48c4f8fdbafea883cbdd0Artem Iglikov bool Pow2DivIsCheap; 18165021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 18175021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// JumpIsExpensive - Tells the code generator that it shouldn't generate 18185021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// extra flow control instructions and should attempt to combine flow 18195021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// control instructions via predication. 18205021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov bool JumpIsExpensive; 18215021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 18225021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// UseUnderscoreSetJmp - This target prefers to use _setjmp to implement 18235021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// llvm.setjmp. Defaults to false. 18245021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov bool UseUnderscoreSetJmp; 18255021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 18265021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// UseUnderscoreLongJmp - This target prefers to use _longjmp to implement 18275021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// llvm.longjmp. Defaults to false. 18285021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov bool UseUnderscoreLongJmp; 18295021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 18305021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// SupportJumpTables - Whether the target can generate code for jumptables. 18315021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// If it's not true, then each jumptable must be lowered into if-then-else's. 1832a7924a6795556d29d8a4c49b0781d2b43a5639ddMichal Karpinski bool SupportJumpTables; 1833a7924a6795556d29d8a4c49b0781d2b43a5639ddMichal Karpinski 1834a7924a6795556d29d8a4c49b0781d2b43a5639ddMichal Karpinski /// MinimumJumpTableEntries - Number of blocks threshold to use jump tables. 1835a7924a6795556d29d8a4c49b0781d2b43a5639ddMichal Karpinski int MinimumJumpTableEntries; 1836a7924a6795556d29d8a4c49b0781d2b43a5639ddMichal Karpinski 1837a7924a6795556d29d8a4c49b0781d2b43a5639ddMichal Karpinski /// BooleanContents - Information about the contents of the high-bits in 18385021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// boolean values held in a type wider than i1. See getBooleanContents. 18395021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov BooleanContent BooleanContents; 18405021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// BooleanVectorContents - Information about the contents of the high-bits 18415021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// in boolean vector values when the element type is wider than i1. See 18425021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// getBooleanContents. 18435021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov BooleanContent BooleanVectorContents; 18445021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 18455021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// SchedPreferenceInfo - The target scheduling preference: shortest possible 18465021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// total cycles or lowest register usage. 18475021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov Sched::Preference SchedPreferenceInfo; 18485021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 18495021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// JumpBufSize - The size, in bytes, of the target's jmp_buf buffers 18505021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov unsigned JumpBufSize; 18515021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 18525021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// JumpBufAlignment - The alignment, in bytes, of the target's jmp_buf 1853f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov /// buffers 18545021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov unsigned JumpBufAlignment; 18555021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 18565021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// MinStackArgumentAlignment - The minimum alignment that any argument 18575021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// on the stack needs to have. 18585021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// 18595021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov unsigned MinStackArgumentAlignment; 18605021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 18615021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// MinFunctionAlignment - The minimum function alignment (used when 1862f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov /// optimizing for size, and to prevent explicitly provided alignment 1863f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov /// from leading to incorrect code). 18645021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// 18655021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov unsigned MinFunctionAlignment; 18665021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 18675021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// PrefFunctionAlignment - The preferred function alignment (used when 18685021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// alignment unspecified and optimizing for speed). 18695021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// 18705021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov unsigned PrefFunctionAlignment; 18715021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 18725021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// PrefLoopAlignment - The preferred loop alignment. 18735021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// 18745021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov unsigned PrefLoopAlignment; 18755021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 18765021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// ShouldFoldAtomicFences - Whether fencing MEMBARRIER instructions should 18775021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// be folded into the enclosed atomic intrinsic instruction by the 18785021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// combiner. 18795021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov bool ShouldFoldAtomicFences; 18805021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 18815021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// InsertFencesForAtomic - Whether the DAG builder should automatically 18825021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// insert fences and reduce ordering for atomics. (This will be set for 18835021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// for most architectures with weak memory ordering.) 18845021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov bool InsertFencesForAtomic; 1885f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov 18865021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// StackPointerRegisterToSaveRestore - If set to a physical register, this 1887f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov /// specifies the register that llvm.savestack/llvm.restorestack should save 1888f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov /// and restore. 18895021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov unsigned StackPointerRegisterToSaveRestore; 1890f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov 18915021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// ExceptionPointerRegister - If set to a physical register, this specifies 1892f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov /// the register that receives the exception address on entry to a landing 18935021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// pad. 18945021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov unsigned ExceptionPointerRegister; 189521510f0b7571f0689dc48c4f8fdbafea883cbdd0Artem Iglikov 189621510f0b7571f0689dc48c4f8fdbafea883cbdd0Artem Iglikov /// ExceptionSelectorRegister - If set to a physical register, this specifies 189721510f0b7571f0689dc48c4f8fdbafea883cbdd0Artem Iglikov /// the register that receives the exception typeid on entry to a landing 18985021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// pad. 18995021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov unsigned ExceptionSelectorRegister; 19005021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 19015021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// RegClassForVT - This indicates the default register class to use for 19025021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// each ValueType the target supports natively. 19035021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov const TargetRegisterClass *RegClassForVT[MVT::LAST_VALUETYPE]; 1904f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov unsigned char NumRegistersForVT[MVT::LAST_VALUETYPE]; 19055021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov EVT RegisterTypeForVT[MVT::LAST_VALUETYPE]; 1906f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov 19075021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// RepRegClassForVT - This indicates the "representative" register class to 19085021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// use for each ValueType the target supports natively. This information is 19095021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// used by the scheduler to track register pressure. By default, the 19105021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// representative register class is the largest legal super-reg register 1911f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov /// class of the register class of the specified type. e.g. On x86, i8, i16, 19125021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// and i32's representative class would be GR32. 19135021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov const TargetRegisterClass *RepRegClassForVT[MVT::LAST_VALUETYPE]; 19145021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 19155021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// RepRegClassCostForVT - This indicates the "cost" of the "representative" 19165021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// register class for each ValueType. The cost is used by the scheduler to 19175021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// approximate register pressure. 19185021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov uint8_t RepRegClassCostForVT[MVT::LAST_VALUETYPE]; 1919bcc0c1d1139872b64b0466d03761bc37eb05720bTim Zheng 1920bcc0c1d1139872b64b0466d03761bc37eb05720bTim Zheng /// TransformToType - For any value types we are promoting or expanding, this 1921f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov /// contains the value type that we are changing to. For Expanded types, this 1922f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov /// contains one step of the expand (e.g. i64 -> i32), even if there are 192321510f0b7571f0689dc48c4f8fdbafea883cbdd0Artem Iglikov /// multiple steps required (e.g. i64 -> i16). For types natively supported 192421510f0b7571f0689dc48c4f8fdbafea883cbdd0Artem Iglikov /// by the system, this holds the same type (e.g. i32 -> i32). 1925bcc0c1d1139872b64b0466d03761bc37eb05720bTim Zheng EVT TransformToType[MVT::LAST_VALUETYPE]; 19265021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 19275021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// OpActions - For each operation and each value type, keep a LegalizeAction 19285021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// that indicates how instruction selection should deal with the operation. 19295021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// Most operations are Legal (aka, supported natively by the target), but 19305021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// operations that are not should be described. Note that operations on 19315021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// non-legal value types are not described here. 19325021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov uint8_t OpActions[MVT::LAST_VALUETYPE][ISD::BUILTIN_OP_END]; 19335021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 1934f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov /// LoadExtActions - For each load extension type and each value type, 1935f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov /// keep a LegalizeAction that indicates how instruction selection should deal 19365021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// with a load of a specific value type and extension type. 19375021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov uint8_t LoadExtActions[MVT::LAST_VALUETYPE][ISD::LAST_LOADEXT_TYPE]; 19385021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 19395021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// TruncStoreActions - For each value type pair keep a LegalizeAction that 1940bbab23ff97688f33c5cc41d5d0e134c0d9f58c6cAndreas Gampe /// indicates whether a truncating store of a specific value type and 1941f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov /// truncating type is legal. 1942f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov uint8_t TruncStoreActions[MVT::LAST_VALUETYPE][MVT::LAST_VALUETYPE]; 194321510f0b7571f0689dc48c4f8fdbafea883cbdd0Artem Iglikov 19445021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// IndexedModeActions - For each indexed mode and each value type, 19455021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// keep a pair of LegalizeAction that indicates how instruction 19465021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// selection should deal with the load / store. The first dimension is the 19475021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// value_type for the reference. The second dimension represents the various 1948f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov /// modes for load store. 1949f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov uint8_t IndexedModeActions[MVT::LAST_VALUETYPE][ISD::LAST_INDEXED_MODE]; 19505021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 19515021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// CondCodeActions - For each condition code (ISD::CondCode) keep a 19525021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// LegalizeAction that indicates how instruction selection should 19535021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// deal with the condition code. 1954f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov /// Because each CC action takes up 2 bits, we need to have the array size 19555021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// be large enough to fit all of the value types. This can be done by 19565021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// dividing the MVT::LAST_VALUETYPE by 32 and adding one. 19575021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov uint64_t CondCodeActions[ISD::SETCC_INVALID][(MVT::LAST_VALUETYPE / 32) + 1]; 19585021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 19595021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov ValueTypeActionImpl ValueTypeActions; 19605021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 19615021918605020c44c7ee66fbc896955abdd1517fArtem Iglikovpublic: 19625021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov LegalizeKind 19635021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov getTypeConversion(LLVMContext &Context, EVT VT) const { 19645021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov // If this is a simple type, use the ComputeRegisterProp mechanism. 19655021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov if (VT.isSimple()) { 19665021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov assert((unsigned)VT.getSimpleVT().SimpleTy < 19675021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov array_lengthof(TransformToType)); 19685021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov EVT NVT = TransformToType[VT.getSimpleVT().SimpleTy]; 19695021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov LegalizeTypeAction LA = ValueTypeActions.getTypeAction(VT.getSimpleVT()); 19705021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 19715021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov assert( 19725021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov (!(NVT.isSimple() && LA != TypeLegal) || 19735021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov ValueTypeActions.getTypeAction(NVT.getSimpleVT()) != TypePromoteInteger) 19745021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov && "Promote may not follow Expand or Promote"); 19755021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 19765021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov return LegalizeKind(LA, NVT); 19775021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov } 19785021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 19795021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov // Handle Extended Scalar Types. 19805021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov if (!VT.isVector()) { 1981f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov assert(VT.isInteger() && "Float types must be simple"); 1982f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov unsigned BitSize = VT.getSizeInBits(); 19835021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov // First promote to a power-of-two size, then expand if necessary. 19847f14edea1d84bde1824529178c609fa5961051d2Bernardo Rufino if (BitSize < 8 || !isPowerOf2_32(BitSize)) { 19857f14edea1d84bde1824529178c609fa5961051d2Bernardo Rufino EVT NVT = VT.getRoundIntegerType(Context); 19867f14edea1d84bde1824529178c609fa5961051d2Bernardo Rufino assert(NVT != VT && "Unable to round integer VT"); 1987f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov LegalizeKind NextStep = getTypeConversion(Context, NVT); 1988f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov // Avoid multi-step promotion. 19895021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov if (NextStep.first == TypePromoteInteger) return NextStep; 19905021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov // Return rounded integer type. 19915021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov return LegalizeKind(TypePromoteInteger, NVT); 19925021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov } 19937f14edea1d84bde1824529178c609fa5961051d2Bernardo Rufino 19947f14edea1d84bde1824529178c609fa5961051d2Bernardo Rufino return LegalizeKind(TypeExpandInteger, 19955021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov EVT::getIntegerVT(Context, VT.getSizeInBits()/2)); 19965021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov } 19975021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 19985021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov // Handle vector types. 19995021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov unsigned NumElts = VT.getVectorNumElements(); 2000f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov EVT EltVT = VT.getVectorElementType(); 20015021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 20025021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov // Vectors with only one element are always scalarized. 20035021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov if (NumElts == 1) 20045021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov return LegalizeKind(TypeScalarizeVector, EltVT); 20055021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 20065021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov // Try to widen vector elements until a legal type is found. 2007f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov if (EltVT.isInteger()) { 2008f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov // Vectors with a number of elements that is not a power of two are always 20095021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov // widened, for example <3 x float> -> <4 x float>. 20105021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov if (!VT.isPow2VectorType()) { 20115021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov NumElts = (unsigned)NextPowerOf2(NumElts); 20125021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov EVT NVT = EVT::getVectorVT(Context, EltVT, NumElts); 20135021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov return LegalizeKind(TypeWidenVector, NVT); 20145021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov } 20155021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 20165021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov // Examine the element type. 20175021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov LegalizeKind LK = getTypeConversion(Context, EltVT); 2018bcc0c1d1139872b64b0466d03761bc37eb05720bTim Zheng 20195021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov // If type is to be expanded, split the vector. 20205021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov // <4 x i140> -> <2 x i140> 20215021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov if (LK.first == TypeExpandInteger) 2022bcc0c1d1139872b64b0466d03761bc37eb05720bTim Zheng return LegalizeKind(TypeSplitVector, 2023bcc0c1d1139872b64b0466d03761bc37eb05720bTim Zheng EVT::getVectorVT(Context, EltVT, NumElts / 2)); 2024bcc0c1d1139872b64b0466d03761bc37eb05720bTim Zheng 2025bcc0c1d1139872b64b0466d03761bc37eb05720bTim Zheng // Promote the integer element types until a legal vector type is found 2026bcc0c1d1139872b64b0466d03761bc37eb05720bTim Zheng // or until the element integer type is too big. If a legal type was not 2027bcc0c1d1139872b64b0466d03761bc37eb05720bTim Zheng // found, fallback to the usual mechanism of widening/splitting the 2028bcc0c1d1139872b64b0466d03761bc37eb05720bTim Zheng // vector. 2029f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov while (1) { 2030bcc0c1d1139872b64b0466d03761bc37eb05720bTim Zheng // Increase the bitwidth of the element to the next pow-of-two 20315021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov // (which is greater than 8 bits). 20325021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov EltVT = EVT::getIntegerVT(Context, 1 + EltVT.getSizeInBits() 20335021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov ).getRoundIntegerType(Context); 20345021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 20355021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov // Stop trying when getting a non-simple element type. 20365021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov // Note that vector elements may be greater than legal vector element 20375021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov // types. Example: X86 XMM registers hold 64bit element on 32bit systems. 20385021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov if (!EltVT.isSimple()) break; 20395021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 2040f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov // Build a new vector type and check if it is legal. 2041f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov MVT NVT = MVT::getVectorVT(EltVT.getSimpleVT(), NumElts); 20425021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov // Found a legal promoted vector type. 20435021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov if (NVT != MVT() && ValueTypeActions.getTypeAction(NVT) == TypeLegal) 20445021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov return LegalizeKind(TypePromoteInteger, 20455021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov EVT::getVectorVT(Context, EltVT, NumElts)); 20465021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov } 20475021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov } 20485021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 2049bcc0c1d1139872b64b0466d03761bc37eb05720bTim Zheng // Try to widen the vector until a legal type is found. 2050f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov // If there is no wider legal type, split the vector. 2051f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov while (1) { 20525021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov // Round up to the next power of 2. 2053f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov NumElts = (unsigned)NextPowerOf2(NumElts); 2054f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov 20555021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov // If there is no simple vector type with this many elements then there 20565021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov // cannot be a larger legal vector type. Note that this assumes that 20575021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov // there are no skipped intermediate vector types in the simple types. 20585021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov if (!EltVT.isSimple()) break; 20595021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov MVT LargerVector = MVT::getVectorVT(EltVT.getSimpleVT(), NumElts); 20605021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov if (LargerVector == MVT()) break; 20615021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 20625021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov // If this type is legal then widen the vector. 20635021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov if (ValueTypeActions.getTypeAction(LargerVector) == TypeLegal) 20645021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov return LegalizeKind(TypeWidenVector, LargerVector); 20655021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov } 20665021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 20675021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov // Widen odd vectors to next power of two. 20685021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov if (!VT.isPow2VectorType()) { 20695021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov EVT NVT = VT.getPow2VectorType(Context); 20705021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov return LegalizeKind(TypeWidenVector, NVT); 20715021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov } 20725021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 20735021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov // Vectors with illegal element types are expanded. 20745021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov EVT NVT = EVT::getVectorVT(Context, EltVT, VT.getVectorNumElements() / 2); 20755021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov return LegalizeKind(TypeSplitVector, NVT); 20765021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov } 20775021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 2078f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikovprivate: 20795021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov std::vector<std::pair<EVT, const TargetRegisterClass*> > AvailableRegClasses; 20805021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 20815021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// TargetDAGCombineArray - Targets can specify ISD nodes that they would 2082f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov /// like PerformDAGCombine callbacks for by calling setTargetDAGCombine(), 2083f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov /// which sets a bit in this array. 20847f14edea1d84bde1824529178c609fa5961051d2Bernardo Rufino unsigned char 20857f14edea1d84bde1824529178c609fa5961051d2Bernardo Rufino TargetDAGCombineArray[(ISD::BUILTIN_OP_END+CHAR_BIT-1)/CHAR_BIT]; 20865021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 20875021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// PromoteToType - For operations that must be promoted to a specific type, 20885021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// this holds the destination type. This map should be sparse, so don't hold 20895021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// it as an array. 20905021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// 20915021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// Targets add entries to this map with AddPromotedToType(..), clients access 20925021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// this with getTypeToPromoteTo(..). 2093bcc0c1d1139872b64b0466d03761bc37eb05720bTim Zheng std::map<std::pair<unsigned, MVT::SimpleValueType>, MVT::SimpleValueType> 20945021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov PromoteToType; 20955021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 20965021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// LibcallRoutineNames - Stores the name each libcall. 20975021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// 20985021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov const char *LibcallRoutineNames[RTLIB::UNKNOWN_LIBCALL]; 2099bcc0c1d1139872b64b0466d03761bc37eb05720bTim Zheng 21005021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// CmpLibcallCCs - The ISD::CondCode that should be used to test the result 21015021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// of each of the comparison libcall against zero. 21025021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov ISD::CondCode CmpLibcallCCs[RTLIB::UNKNOWN_LIBCALL]; 21035021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 21045021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// LibcallCallingConvs - Stores the CallingConv that should be used for each 21055021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// libcall. 2106bcc0c1d1139872b64b0466d03761bc37eb05720bTim Zheng CallingConv::ID LibcallCallingConvs[RTLIB::UNKNOWN_LIBCALL]; 2107f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov 2108f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikovprotected: 21095021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// When lowering \@llvm.memset this field specifies the maximum number of 2110f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov /// store operations that may be substituted for the call to memset. Targets 2111f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov /// must set this value based on the cost threshold for that target. Targets 21122c2c856b3a60e96e09261d2513b43acb7ff4b070Artem Iglikov /// should assume that the memset will be done using as many of the largest 21135021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// store operations first, followed by smaller ones, if necessary, per 21145021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// alignment restrictions. For example, storing 9 bytes on a 32-bit machine 21155021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// with 16-bit alignment would result in four 2-byte stores and one 1-byte 21165021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// store. This only applies to setting a constant array of a constant size. 21175021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// @brief Specify maximum number of store instructions per memset call. 21185021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov unsigned maxStoresPerMemset; 21195021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 21205021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// Maximum number of stores operations that may be substituted for the call 21215021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// to memset, used for functions with OptSize attribute. 21225021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov unsigned maxStoresPerMemsetOptSize; 21235021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 21245021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// When lowering \@llvm.memcpy this field specifies the maximum number of 21255021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// store operations that may be substituted for a call to memcpy. Targets 21265021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// must set this value based on the cost threshold for that target. Targets 21275021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// should assume that the memcpy will be done using as many of the largest 21285021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// store operations first, followed by smaller ones, if necessary, per 21295021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// alignment restrictions. For example, storing 7 bytes on a 32-bit machine 21305021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// with 32-bit alignment would result in one 4-byte store, a one 2-byte store 21315021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// and one 1-byte store. This only applies to copying a constant array of 21325021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// constant size. 21335021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// @brief Specify maximum bytes of store instructions per memcpy call. 21345021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov unsigned maxStoresPerMemcpy; 21355021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 21365021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// Maximum number of store operations that may be substituted for a call 21375021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// to memcpy, used for functions with OptSize attribute. 21385021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov unsigned maxStoresPerMemcpyOptSize; 21395021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 21405021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// When lowering \@llvm.memmove this field specifies the maximum number of 21415021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// store instructions that may be substituted for a call to memmove. Targets 2142bcc0c1d1139872b64b0466d03761bc37eb05720bTim Zheng /// must set this value based on the cost threshold for that target. Targets 21435021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// should assume that the memmove will be done using as many of the largest 21445021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// store operations first, followed by smaller ones, if necessary, per 21455021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// alignment restrictions. For example, moving 9 bytes on a 32-bit machine 21465021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// with 8-bit alignment would result in nine 1-byte stores. This only 21475021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// applies to copying a constant array of constant size. 21485021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// @brief Specify maximum bytes of store instructions per memmove call. 21495021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov unsigned maxStoresPerMemmove; 21505021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 2151f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov /// Maximum number of store instructions that may be substituted for a call 21525021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// to memmove, used for functions with OpSize attribute. 2153f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov unsigned maxStoresPerMemmoveOptSize; 2154f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov 21555021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// This field specifies whether the target can benefit from code placement 21565021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// optimization. 21575021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov bool benefitFromCodePlacementOpt; 21585021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 21595021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov /// predictableSelectIsExpensive - Tells the code generator that select is 2160f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov /// more expensive than a branch if the branch is usually predicted right. 2161f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov bool predictableSelectIsExpensive; 216221510f0b7571f0689dc48c4f8fdbafea883cbdd0Artem Iglikov 216321510f0b7571f0689dc48c4f8fdbafea883cbdd0Artem Iglikovprivate: 2164bcc0c1d1139872b64b0466d03761bc37eb05720bTim Zheng /// isLegalRC - Return true if the value types that can be represented by the 2165f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov /// specified register class are all legal. 2166f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov bool isLegalRC(const TargetRegisterClass *RC) const; 2167f251e3509838e3fbc62ccdba9d4cfd0527f67acdArtem Iglikov}; 21685021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov 21695021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov/// GetReturnInfo - Given an LLVM IR type and return type attributes, 21705021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov/// compute the return value EVTs and flags, and optionally also 21715021918605020c44c7ee66fbc896955abdd1517fArtem Iglikov/// the offsets, if the return value is being lowered to memory. 21725021918605020c44c7ee66fbc896955abdd1517fArtem Iglikovvoid GetReturnInfo(Type* ReturnType, Attributes attr, 217321510f0b7571f0689dc48c4f8fdbafea883cbdd0Artem Iglikov SmallVectorImpl<ISD::OutputArg> &Outs, 21744719ed513e68ac0c89f5830b2d50edb960b6ba34Bernardo Rufino const TargetLowering &TLI); 21754719ed513e68ac0c89f5830b2d50edb960b6ba34Bernardo Rufino 21764719ed513e68ac0c89f5830b2d50edb960b6ba34Bernardo Rufino} // end llvm namespace 21774719ed513e68ac0c89f5830b2d50edb960b6ba34Bernardo Rufino 21784719ed513e68ac0c89f5830b2d50edb960b6ba34Bernardo Rufino#endif 21794719ed513e68ac0c89f5830b2d50edb960b6ba34Bernardo Rufino