llvm.org GIT mirror llvm / 44ab89e
Inline asm multiple alternative constraints development phase 2 - improved basic logic, added initial platform support. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@117667 91177308-0d34-0410-b5e6-96231b3b80d8 John Thompson 9 years ago
26 changed file(s) with 519 addition(s) and 102 deletion(s). Raw diff Collapse all Expand all
5151
5252 /// hasInlineAsmMemConstraint - Return true if the inline asm instruction being
5353 /// processed uses a memory 'm' constraint.
54 bool hasInlineAsmMemConstraint(std::vector &CInfos,
54 bool hasInlineAsmMemConstraint(InlineAsm::ConstraintInfoVector &CInfos,
5555 const TargetLowering &TLI);
5656
5757 /// getFCmpCondCode - Return the ISD condition code corresponding to
1515 #ifndef LLVM_INLINEASM_H
1616 #define LLVM_INLINEASM_H
1717
18 #include "llvm/ADT/SmallVector.h"
1819 #include "llvm/Value.h"
19 #include
2020
2121 namespace llvm {
2222
8686 isClobber // '~x'
8787 };
8888
89 typedef SmallVector ConstraintCodeVector;
90
8991 struct SubConstraintInfo {
9092 /// MatchingInput - If this is not -1, this is an output constraint where an
9193 /// input constraint is required to match it (e.g. "0"). The value is the
9496 signed char MatchingInput;
9597 /// Code - The constraint code, either the register name (in braces) or the
9698 /// constraint letter/number.
97 std::vector Codes;
99 ConstraintCodeVector Codes;
98100 /// Default constructor.
99101 SubConstraintInfo() : MatchingInput(-1) {}
100102 };
103
104 typedef SmallVector SubConstraintInfoVector;
105 struct ConstraintInfo;
106 typedef SmallVector ConstraintInfoVector;
101107
102108 struct ConstraintInfo {
103109 /// Type - The basic type of the constraint: input/output/clobber
130136
131137 /// Code - The constraint code, either the register name (in braces) or the
132138 /// constraint letter/number.
133 std::vector Codes;
139 ConstraintCodeVector Codes;
134140
135141 /// isMultipleAlternative - '|': has multiple-alternative constraints.
136142 bool isMultipleAlternative;
137143
138144 /// multipleAlternatives - If there are multiple alternative constraints,
139145 /// this array will contain them. Otherwise it will be empty.
140 std::vector multipleAlternatives;
146 SubConstraintInfoVector multipleAlternatives;
141147
142148 /// The currently selected alternative constraint index.
143149 unsigned currentAlternativeIndex;
151157 /// Parse - Analyze the specified string (e.g. "=*&{eax}") and fill in the
152158 /// fields in this structure. If the constraint string is not understood,
153159 /// return true, otherwise return false.
154 bool Parse(StringRef Str,
155 std::vector &ConstraintsSoFar);
160 bool Parse(StringRef Str, ConstraintInfoVector &ConstraintsSoFar);
156161
157162 /// selectAlternative - Point this constraint to the alternative constraint
158163 /// indicated by the index.
162167 /// ParseConstraints - Split up the constraint string into the specific
163168 /// constraints and their prefixes. If this returns an empty vector, and if
164169 /// the constraint string itself isn't empty, there was an error parsing.
165 static std::vector
166 ParseConstraints(StringRef ConstraintString);
170 static ConstraintInfoVector ParseConstraints(StringRef ConstraintString);
167171
168172 /// ParseConstraints - Parse the constraints of this inlineasm object,
169173 /// returning them the same way that ParseConstraints(str) does.
170 std::vector
171 ParseConstraints() const {
174 ConstraintInfoVector ParseConstraints() const {
172175 return ParseConstraints(Constraints);
173176 }
174177
13191319 C_Unknown // Unsupported constraint.
13201320 };
13211321
1322 enum ConstraintWeight {
1323 // Generic weights.
1324 CW_Invalid = -1, // No match.
1325 CW_Okay = 0, // Acceptable.
1326 CW_Good = 1, // Good weight.
1327 CW_Better = 2, // Better weight.
1328 CW_Best = 3, // Best weight.
1329
1330 // Well-known weights.
1331 CW_SpecificReg = CW_Okay, // Specific register operands.
1332 CW_Register = CW_Good, // Register operands.
1333 CW_Memory = CW_Better, // Memory operands.
1334 CW_Constant = CW_Best, // Constant operand.
1335 CW_Default = CW_Okay // Default or don't know type.
1336 };
1337
13221338 /// AsmOperandInfo - This contains information for each constraint that we are
13231339 /// lowering.
13241340 struct AsmOperandInfo : public InlineAsm::ConstraintInfo {
13641380 }
13651381 };
13661382
1383 typedef SmallVector AsmOperandInfoVector;
1384
13671385 /// ParseConstraints - Split up the constraint string from the inline
13681386 /// assembly value into the specific constraints and their prefixes,
13691387 /// and also tie in the associated operand values.
13701388 /// If this returns an empty vector, and if the constraint string itself
13711389 /// isn't empty, there was an error parsing.
1372 virtual std::vector ParseConstraints(
1373 ImmutableCallSite CS) const;
1390 virtual AsmOperandInfoVector ParseConstraints(ImmutableCallSite CS) const;
13741391
1375 /// Examine constraint type and operand type and determine a weight value,
1376 /// where: -1 = invalid match, and 0 = so-so match to 5 = good match.
1392 /// Examine constraint type and operand type and determine a weight value.
13771393 /// The operand object must already have been set up with the operand type.
1378 virtual int getMultipleConstraintMatchWeight(
1394 virtual ConstraintWeight getMultipleConstraintMatchWeight(
13791395 AsmOperandInfo &info, int maIndex) const;
13801396
1381 /// Examine constraint string and operand type and determine a weight value,
1382 /// where: -1 = invalid match, and 0 = so-so match to 3 = good match.
1397 /// Examine constraint string and operand type and determine a weight value.
13831398 /// The operand object must already have been set up with the operand type.
1384 virtual int getSingleConstraintMatchWeight(
1399 virtual ConstraintWeight getSingleConstraintMatchWeight(
13851400 AsmOperandInfo &info, const char *constraint) const;
13861401
13871402 /// ComputeConstraintToUse - Determines the constraint code and constraint
124124 /// hasInlineAsmMemConstraint - Return true if the inline asm instruction being
125125 /// processed uses a memory 'm' constraint.
126126 bool
127 llvm::hasInlineAsmMemConstraint(std::vector &CInfos,
127 llvm::hasInlineAsmMemConstraint(InlineAsm::ConstraintInfoVector &CInfos,
128128 const TargetLowering &TLI) {
129129 for (unsigned i = 0, e = CInfos.size(); i != e; ++i) {
130130 InlineAsm::ConstraintInfo &CI = CInfos[i];
52205220 }
52215221 };
52225222
5223 typedef SmallVector SDISelAsmOperandInfoVector;
5224
52235225 } // end llvm namespace.
52245226
52255227 /// isAllocatableRegister - If the specified register is safe to allocate,
54575459 const InlineAsm *IA = cast(CS.getCalledValue());
54585460
54595461 /// ConstraintOperands - Information about all of the constraints.
5460 std::vector ConstraintOperands;
5462 SDISelAsmOperandInfoVector ConstraintOperands;
54615463
54625464 std::set OutputRegs, InputRegs;
54635465
5464 std::vector TargetConstraints = TLI.ParseConstraints(CS);
5466 TargetLowering::AsmOperandInfoVector TargetConstraints = TLI.ParseConstraints(CS);
54655467 bool hasMemory = false;
54665468
54675469 unsigned ArgNo = 0; // ArgNo - The argument of the CallInst.
26632663 /// and also tie in the associated operand values.
26642664 /// If this returns an empty vector, and if the constraint string itself
26652665 /// isn't empty, there was an error parsing.
2666 std::vector TargetLowering::ParseConstraints(
2666 TargetLowering::AsmOperandInfoVector TargetLowering::ParseConstraints(
26672667 ImmutableCallSite CS) const {
26682668 /// ConstraintOperands - Information about all of the constraints.
2669 std::vector ConstraintOperands;
2669 AsmOperandInfoVector ConstraintOperands;
26702670 const InlineAsm *IA = cast(CS.getCalledValue());
26712671 unsigned maCount = 0; // Largest number of multiple alternative constraints.
26722672
26732673 // Do a prepass over the constraints, canonicalizing them, and building up the
26742674 // ConstraintOperands list.
2675 std::vector
2675 InlineAsm::ConstraintInfoVector
26762676 ConstraintInfos = IA->ParseConstraints();
26772677
26782678 unsigned ArgNo = 0; // ArgNo - The argument of the CallInst.
26862686 if (OpInfo.multipleAlternatives.size() > maCount)
26872687 maCount = OpInfo.multipleAlternatives.size();
26882688
2689 EVT OpVT = MVT::Other;
2689 OpInfo.ConstraintVT = MVT::Other;
26902690
26912691 // Compute the value type for each operand.
26922692 switch (OpInfo.Type) {
27022702 assert(!CS.getType()->isVoidTy() &&
27032703 "Bad inline asm!");
27042704 if (const StructType *STy = dyn_cast(CS.getType())) {
2705 OpVT = getValueType(STy->getElementType(ResNo));
2705 OpInfo.ConstraintVT = getValueType(STy->getElementType(ResNo));
27062706 } else {
27072707 assert(ResNo == 0 && "Asm only has one result!");
2708 OpVT = getValueType(CS.getType());
2708 OpInfo.ConstraintVT = getValueType(CS.getType());
27092709 }
27102710 ++ResNo;
27112711 break;
27152715 case InlineAsm::isClobber:
27162716 // Nothing to do.
27172717 break;
2718 }
2719
2720 if (OpInfo.CallOperandVal) {
2721 const llvm::Type *OpTy = OpInfo.CallOperandVal->getType();
2722 if (OpInfo.isIndirect) {
2723 const llvm::PointerType *PtrTy = dyn_cast(OpTy);
2724 if (!PtrTy)
2725 report_fatal_error("Indirect operand for inline asm not a pointer!");
2726 OpTy = PtrTy->getElementType();
2727 }
2728 // If OpTy is not a single value, it may be a struct/union that we
2729 // can tile with integers.
2730 if (!OpTy->isSingleValueType() && OpTy->isSized()) {
2731 unsigned BitSize = TD->getTypeSizeInBits(OpTy);
2732 switch (BitSize) {
2733 default: break;
2734 case 1:
2735 case 8:
2736 case 16:
2737 case 32:
2738 case 64:
2739 case 128:
2740 OpTy = IntegerType::get(OpTy->getContext(), BitSize);
2741 break;
2742 }
2743 } else if (dyn_cast(OpTy)) {
2744 OpInfo.ConstraintVT = MVT::getIntegerVT(8*TD->getPointerSize());
2745 } else {
2746 OpInfo.ConstraintVT = EVT::getEVT(OpTy, true);
2747 }
27182748 }
27192749 }
27202750
27362766 if (OpInfo.Type == InlineAsm::isClobber)
27372767 continue;
27382768
2739 // If this is an output operand with a matching input operand, look up the
2740 // matching input. If their types mismatch, e.g. one is an integer, the
2741 // other is floating point, or their sizes are different, flag it as an
2742 // maCantMatch.
2769 // If this is an output operand with a matching input operand,
2770 // look up the matching input. If their types mismatch, e.g. one
2771 // is an integer, the other is floating point, or their sizes are
2772 // different, flag it as an maCantMatch.
27432773 if (OpInfo.hasMatchingInput()) {
27442774 AsmOperandInfo &Input = ConstraintOperands[OpInfo.MatchingInput];
2745
27462775 if (OpInfo.ConstraintVT != Input.ConstraintVT) {
27472776 if ((OpInfo.ConstraintVT.isInteger() !=
27482777 Input.ConstraintVT.isInteger()) ||
27512780 weightSum = -1; // Can't match.
27522781 break;
27532782 }
2754 Input.ConstraintVT = OpInfo.ConstraintVT;
27552783 }
27562784 }
2757
27582785 weight = getMultipleConstraintMatchWeight(OpInfo, maIndex);
27592786 if (weight == -1) {
27602787 weightSum = -1;
27912818 // error.
27922819 if (OpInfo.hasMatchingInput()) {
27932820 AsmOperandInfo &Input = ConstraintOperands[OpInfo.MatchingInput];
2794
2821
27952822 if (OpInfo.ConstraintVT != Input.ConstraintVT) {
27962823 if ((OpInfo.ConstraintVT.isInteger() !=
27972824 Input.ConstraintVT.isInteger()) ||
28012828 " with a matching output constraint of"
28022829 " incompatible type!");
28032830 }
2804 Input.ConstraintVT = OpInfo.ConstraintVT;
2805 }
2831 }
2832
28062833 }
28072834 }
28082835
28272854 }
28282855 }
28292856
2830 /// Examine constraint type and operand type and determine a weight value,
2831 /// where: -1 = invalid match, and 0 = so-so match to 3 = good match.
2857 /// Examine constraint type and operand type and determine a weight value.
28322858 /// This object must already have been set up with the operand type
28332859 /// and the current alternative constraint selected.
2834 int TargetLowering::getMultipleConstraintMatchWeight(
2860 TargetLowering::ConstraintWeight
2861 TargetLowering::getMultipleConstraintMatchWeight(
28352862 AsmOperandInfo &info, int maIndex) const {
2836 std::vector *rCodes;
2863 InlineAsm::ConstraintCodeVector *rCodes;
28372864 if (maIndex >= (int)info.multipleAlternatives.size())
28382865 rCodes = &info.Codes;
28392866 else
28402867 rCodes = &info.multipleAlternatives[maIndex].Codes;
2841 int BestWeight = -1;
2868 ConstraintWeight BestWeight = CW_Invalid;
28422869
28432870 // Loop over the options, keeping track of the most general one.
28442871 for (unsigned i = 0, e = rCodes->size(); i != e; ++i) {
2845 int weight = getSingleConstraintMatchWeight(info, (*rCodes)[i].c_str());
2872 ConstraintWeight weight =
2873 getSingleConstraintMatchWeight(info, (*rCodes)[i].c_str());
28462874 if (weight > BestWeight)
28472875 BestWeight = weight;
28482876 }
28502878 return BestWeight;
28512879 }
28522880
2853 /// Examine constraint type and operand type and determine a weight value,
2854 /// where: -1 = invalid match, and 0 = so-so match to 3 = good match.
2881 /// Examine constraint type and operand type and determine a weight value.
28552882 /// This object must already have been set up with the operand type
28562883 /// and the current alternative constraint selected.
2857 int TargetLowering::getSingleConstraintMatchWeight(
2884 TargetLowering::ConstraintWeight
2885 TargetLowering::getSingleConstraintMatchWeight(
28582886 AsmOperandInfo &info, const char *constraint) const {
2859 int weight = -1;
2887 ConstraintWeight weight = CW_Invalid;
28602888 Value *CallOperandVal = info.CallOperandVal;
28612889 // If we don't have a value, we can't do a match,
28622890 // but allow it at the lowest weight.
28632891 if (CallOperandVal == NULL)
2864 return 0;
2892 return CW_Default;
28652893 // Look at the constraint type.
28662894 switch (*constraint) {
28672895 case 'i': // immediate integer.
28682896 case 'n': // immediate integer with a known value.
2869 weight = 0;
2870 if (info.CallOperandVal) {
2871 if (isa(info.CallOperandVal))
2872 weight = 3;
2873 else
2874 weight = -1;
2875 }
2897 if (isa(CallOperandVal))
2898 weight = CW_Constant;
28762899 break;
28772900 case 's': // non-explicit intregal immediate.
2878 weight = 0;
2879 if (info.CallOperandVal) {
2880 if (isa(info.CallOperandVal))
2881 weight = 3;
2882 else
2883 weight = -1;
2884 }
2901 if (isa(CallOperandVal))
2902 weight = CW_Constant;
28852903 break;
2904 case 'E': // immediate float if host format.
2905 case 'F': // immediate float.
2906 if (isa(CallOperandVal))
2907 weight = CW_Constant;
2908 break;
2909 case '<': // memory operand with autodecrement.
2910 case '>': // memory operand with autoincrement.
28862911 case 'm': // memory operand.
28872912 case 'o': // offsettable memory operand
28882913 case 'V': // non-offsettable memory operand
2889 weight = 2;
2914 weight = CW_Memory;
28902915 break;
2916 case 'r': // general register.
28912917 case 'g': // general register, memory operand or immediate integer.
2918 // note: Clang converts "g" to "imr".
2919 if (CallOperandVal->getType()->isIntegerTy())
2920 weight = CW_Register;
2921 break;
28922922 case 'X': // any operand.
2893 weight = 1;
2894 break;
28952923 default:
2896 weight = 0;
2924 weight = CW_Default;
28972925 break;
28982926 }
28992927 return weight;
54405440 return TargetLowering::getConstraintType(Constraint);
54415441 }
54425442
5443 /// Examine constraint type and operand type and determine a weight value.
5444 /// This object must already have been set up with the operand type
5445 /// and the current alternative constraint selected.
5446 TargetLowering::ConstraintWeight
5447 ARMTargetLowering::getSingleConstraintMatchWeight(
5448 AsmOperandInfo &info, const char *constraint) const {
5449 ConstraintWeight weight = CW_Invalid;
5450 Value *CallOperandVal = info.CallOperandVal;
5451 // If we don't have a value, we can't do a match,
5452 // but allow it at the lowest weight.
5453 if (CallOperandVal == NULL)
5454 return CW_Default;
5455 const Type *type = CallOperandVal->getType();
5456 // Look at the constraint type.
5457 switch (*constraint) {
5458 default:
5459 weight = TargetLowering::getSingleConstraintMatchWeight(info, constraint);
5460 break;
5461 case 'l':
5462 if (type->isIntegerTy()) {
5463 if (Subtarget->isThumb())
5464 weight = CW_SpecificReg;
5465 else
5466 weight = CW_Register;
5467 }
5468 break;
5469 case 'w':
5470 if (type->isFloatingPointTy())
5471 weight = CW_Register;
5472 break;
5473 }
5474 return weight;
5475 }
5476
54435477 std::pair
54445478 ARMTargetLowering::getRegForInlineAsmConstraint(const std::string &Constraint,
54455479 EVT VT) const {
240240
241241
242242 ConstraintType getConstraintType(const std::string &Constraint) const;
243
244 /// Examine constraint string and operand type and determine a weight value.
245 /// The operand object must already have been set up with the operand type.
246 ConstraintWeight getSingleConstraintMatchWeight(
247 AsmOperandInfo &info, const char *constraint) const;
248
243249 std::pair
244250 getRegForInlineAsmConstraint(const std::string &Constraint,
245251 EVT VT) const;
2626 #include "llvm/Function.h"
2727 #include "llvm/Module.h"
2828 #include "llvm/Intrinsics.h"
29 #include "llvm/Type.h"
2930 #include "llvm/Support/CommandLine.h"
3031 #include "llvm/Support/ErrorHandling.h"
3132 #include "llvm/Support/raw_ostream.h"
800801 }
801802 }
802803 return TargetLowering::getConstraintType(Constraint);
804 }
805
806 /// Examine constraint type and operand type and determine a weight value.
807 /// This object must already have been set up with the operand type
808 /// and the current alternative constraint selected.
809 TargetLowering::ConstraintWeight
810 AlphaTargetLowering::getSingleConstraintMatchWeight(
811 AsmOperandInfo &info, const char *constraint) const {
812 ConstraintWeight weight = CW_Invalid;
813 Value *CallOperandVal = info.CallOperandVal;
814 // If we don't have a value, we can't do a match,
815 // but allow it at the lowest weight.
816 if (CallOperandVal == NULL)
817 return CW_Default;
818 // Look at the constraint type.
819 switch (*constraint) {
820 default:
821 weight = TargetLowering::getSingleConstraintMatchWeight(info, constraint);
822 break;
823 case 'f':
824 weight = CW_Register;
825 break;
826 }
827 return weight;
803828 }
804829
805830 std::vector AlphaTargetLowering::
8686
8787 ConstraintType getConstraintType(const std::string &Constraint) const;
8888
89 /// Examine constraint string and operand type and determine a weight value.
90 /// The operand object must already have been set up with the operand type.
91 ConstraintWeight getSingleConstraintMatchWeight(
92 AsmOperandInfo &info, const char *constraint) const;
93
8994 std::vector
9095 getRegClassForInlineAsmConstraint(const std::string &Constraint,
9196 EVT VT) const;
1414 #include "BlackfinISelLowering.h"
1515 #include "BlackfinTargetMachine.h"
1616 #include "llvm/Function.h"
17 #include "llvm/Type.h"
1718 #include "llvm/CodeGen/CallingConvLower.h"
1819 #include "llvm/CodeGen/MachineFrameInfo.h"
1920 #include "llvm/CodeGen/MachineFunction.h"
548549 return TargetLowering::getConstraintType(Constraint);
549550 }
550551
552 /// Examine constraint type and operand type and determine a weight value.
553 /// This object must already have been set up with the operand type
554 /// and the current alternative constraint selected.
555 TargetLowering::ConstraintWeight
556 BlackfinTargetLowering::getSingleConstraintMatchWeight(
557 AsmOperandInfo &info, const char *constraint) const {
558 ConstraintWeight weight = CW_Invalid;
559 Value *CallOperandVal = info.CallOperandVal;
560 // If we don't have a value, we can't do a match,
561 // but allow it at the lowest weight.
562 if (CallOperandVal == NULL)
563 return CW_Default;
564 // Look at the constraint type.
565 switch (*constraint) {
566 default:
567 weight = TargetLowering::getSingleConstraintMatchWeight(info, constraint);
568 break;
569
570 // Blackfin-specific constraints
571 case 'a':
572 case 'd':
573 case 'z':
574 case 'D':
575 case 'W':
576 case 'e':
577 case 'b':
578 case 'v':
579 case 'f':
580 case 'c':
581 case 't':
582 case 'u':
583 case 'k':
584 case 'x':
585 case 'y':
586 case 'w':
587 return CW_Register;
588 case 'A':
589 case 'B':
590 case 'C':
591 case 'Z':
592 case 'Y':
593 return CW_SpecificReg;
594 }
595 return weight;
596 }
597
551598 /// getRegForInlineAsmConstraint - Return register no and class for a C_Register
552599 /// constraint.
553600 std::pair BlackfinTargetLowering::
3838 SelectionDAG &DAG) const;
3939
4040 ConstraintType getConstraintType(const std::string &Constraint) const;
41
42 /// Examine constraint string and operand type and determine a weight value.
43 /// The operand object must already have been set up with the operand type.
44 ConstraintWeight getSingleConstraintMatchWeight(
45 AsmOperandInfo &info, const char *constraint) const;
46
4147 std::pair
4248 getRegForInlineAsmConstraint(const std::string &Constraint, EVT VT) const;
4349 std::vector
31923192 // handle communitivity
31933193 void CWriter::visitInlineAsm(CallInst &CI) {
31943194 InlineAsm* as = cast(CI.getCalledValue());
3195 std::vector Constraints = as->ParseConstraints();
3195 InlineAsm::ConstraintInfoVector Constraints = as->ParseConstraints();
31963196
31973197 std::vector > ResultVals;
31983198 if (CI.getType() == Type::getVoidTy(CI.getContext()))
32123212 bool IsFirst = true;
32133213
32143214 // Convert over all the output constraints.
3215 for (std::vector::iterator I = Constraints.begin(),
3215 for (InlineAsm::ConstraintInfoVector::iterator I = Constraints.begin(),
32163216 E = Constraints.end(); I != E; ++I) {
32173217
32183218 if (I->Type != InlineAsm::isOutput) {
32543254 Out << "\n :";
32553255 IsFirst = true;
32563256 ValueCount = 0;
3257 for (std::vector::iterator I = Constraints.begin(),
3257 for (InlineAsm::ConstraintInfoVector::iterator I = Constraints.begin(),
32583258 E = Constraints.end(); I != E; ++I) {
32593259 if (I->Type != InlineAsm::isInput) {
32603260 ++ValueCount;
32833283
32843284 // Convert over the clobber constraints.
32853285 IsFirst = true;
3286 for (std::vector::iterator I = Constraints.begin(),
3286 for (InlineAsm::ConstraintInfoVector::iterator I = Constraints.begin(),
32873287 E = Constraints.end(); I != E; ++I) {
32883288 if (I->Type != InlineAsm::isClobber)
32893289 continue; // Ignore non-input constraints.
1919 #include "llvm/Function.h"
2020 #include "llvm/Intrinsics.h"
2121 #include "llvm/CallingConv.h"
22 #include "llvm/Type.h"
2223 #include "llvm/CodeGen/CallingConvLower.h"
2324 #include "llvm/CodeGen/MachineFrameInfo.h"
2425 #include "llvm/CodeGen/MachineFunction.h"
29882989 return TargetLowering::getConstraintType(ConstraintLetter);
29892990 }
29902991
2992 /// Examine constraint type and operand type and determine a weight value.
2993 /// This object must already have been set up with the operand type
2994 /// and the current alternative constraint selected.
2995 TargetLowering::ConstraintWeight
2996 SPUTargetLowering::getSingleConstraintMatchWeight(
2997 AsmOperandInfo &info, const char *constraint) const {
2998 ConstraintWeight weight = CW_Invalid;
2999 Value *CallOperandVal = info.CallOperandVal;
3000 // If we don't have a value, we can't do a match,
3001 // but allow it at the lowest weight.
3002 if (CallOperandVal == NULL)
3003 return CW_Default;
3004 // Look at the constraint type.
3005 switch (*constraint) {
3006 default:
3007 weight = TargetLowering::getSingleConstraintMatchWeight(info, constraint);
3008 break;
3009 //FIXME: Seems like the supported constraint letters were just copied
3010 // from PPC, as the following doesn't correspond to the GCC docs.
3011 // I'm leaving it so until someone adds the corresponding lowering support.
3012 case 'b':
3013 case 'r':
3014 case 'f':
3015 case 'd':
3016 case 'v':
3017 case 'y':
3018 weight = CW_Register;
3019 break;
3020 }
3021 return weight;
3022 }
3023
29913024 std::pair
29923025 SPUTargetLowering::getRegForInlineAsmConstraint(const std::string &Constraint,
29933026 EVT VT) const
128128
129129 ConstraintType getConstraintType(const std::string &ConstraintLetter) const;
130130
131 /// Examine constraint string and operand type and determine a weight value.
132 /// The operand object must already have been set up with the operand type.
133 ConstraintWeight getSingleConstraintMatchWeight(
134 AsmOperandInfo &info, const char *constraint) const;
135
131136 std::pair
132137 getRegForInlineAsmConstraint(const std::string &Constraint,
133138 EVT VT) const;
907907 return TargetLowering::getConstraintType(Constraint);
908908 }
909909
910 /// Examine constraint type and operand type and determine a weight value.
911 /// This object must already have been set up with the operand type
912 /// and the current alternative constraint selected.
913 TargetLowering::ConstraintWeight
914 MBlazeTargetLowering::getSingleConstraintMatchWeight(
915 AsmOperandInfo &info, const char *constraint) const {
916 ConstraintWeight weight = CW_Invalid;
917 Value *CallOperandVal = info.CallOperandVal;
918 // If we don't have a value, we can't do a match,
919 // but allow it at the lowest weight.
920 if (CallOperandVal == NULL)
921 return CW_Default;
922 const Type *type = CallOperandVal->getType();
923 // Look at the constraint type.
924 switch (*constraint) {
925 default:
926 weight = TargetLowering::getSingleConstraintMatchWeight(info, constraint);
927 break;
928 case 'd':
929 case 'y':
930 if (type->isIntegerTy())
931 weight = CW_Register;
932 break;
933 case 'f':
934 if (type->isFloatTy())
935 weight = CW_Register;
936 break;
937 }
938 return weight;
939 }
940
910941 /// getRegClassForInlineAsmConstraint - Given a constraint letter (e.g. "r"),
911942 /// return a list of registers that can be used to satisfy the constraint.
912943 /// This should only be used for C_RegisterClass constraints.
152152 // Inline asm support
153153 ConstraintType getConstraintType(const std::string &Constraint) const;
154154
155 /// Examine constraint string and operand type and determine a weight value.
156 /// The operand object must already have been set up with the operand type.
157 ConstraintWeight getSingleConstraintMatchWeight(
158 AsmOperandInfo &info, const char *constraint) const;
159
155160 std::pair
156161 getRegForInlineAsmConstraint(const std::string &Constraint,
157162 EVT VT) const;
12681268 return TargetLowering::getConstraintType(Constraint);
12691269 }
12701270
1271 /// Examine constraint type and operand type and determine a weight value.
1272 /// This object must already have been set up with the operand type
1273 /// and the current alternative constraint selected.
1274 TargetLowering::ConstraintWeight
1275 MipsTargetLowering::getSingleConstraintMatchWeight(
1276 AsmOperandInfo &info, const char *constraint) const {
1277 ConstraintWeight weight = CW_Invalid;
1278 Value *CallOperandVal = info.CallOperandVal;
1279 // If we don't have a value, we can't do a match,
1280 // but allow it at the lowest weight.
1281 if (CallOperandVal == NULL)
1282 return CW_Default;
1283 const Type *type = CallOperandVal->getType();
1284 // Look at the constraint type.
1285 switch (*constraint) {
1286 default:
1287 weight = TargetLowering::getSingleConstraintMatchWeight(info, constraint);
1288 break;
1289 case 'd':
1290 case 'y':
1291 if (type->isIntegerTy())
1292 weight = CW_Register;
1293 break;
1294 case 'f':
1295 if (type->isFloatTy())
1296 weight = CW_Register;
1297 break;
1298 }
1299 return weight;
1300 }
1301
12711302 /// getRegClassForInlineAsmConstraint - Given a constraint letter (e.g. "r"),
12721303 /// return a list of registers that can be used to satisfy the constraint.
12731304 /// This should only be used for C_RegisterClass constraints.
138138 // Inline asm support
139139 ConstraintType getConstraintType(const std::string &Constraint) const;
140140
141 /// Examine constraint string and operand type and determine a weight value.
142 /// The operand object must already have been set up with the operand type.
143 ConstraintWeight getSingleConstraintMatchWeight(
144 AsmOperandInfo &info, const char *constraint) const;
145
141146 std::pair
142147 getRegForInlineAsmConstraint(const std::string &Constraint,
143148 EVT VT) const;
24722472 // node so that legalize doesn't hack it.
24732473 if (GlobalAddressSDNode *G = dyn_cast(Callee)) {
24742474 Callee = DAG.getTargetGlobalAddress(G->getGlobal(), dl,
2475 Callee.getValueType());
2475 Callee.getValueType());
24762476 needIndirectCall = false;
24772477 }
24782478 }
24792479 if (ExternalSymbolSDNode *S = dyn_cast(Callee)) {
24802480 Callee = DAG.getTargetExternalSymbol(S->getSymbol(),
2481 Callee.getValueType());
2481 Callee.getValueType());
24822482 needIndirectCall = false;
24832483 }
24842484 if (needIndirectCall) {
53735373 return TargetLowering::getConstraintType(Constraint);
53745374 }
53755375
5376 /// Examine constraint type and operand type and determine a weight value.
5377 /// This object must already have been set up with the operand type
5378 /// and the current alternative constraint selected.
5379 TargetLowering::ConstraintWeight
5380 PPCTargetLowering::getSingleConstraintMatchWeight(
5381 AsmOperandInfo &info, const char *constraint) const {
5382 ConstraintWeight weight = CW_Invalid;
5383 Value *CallOperandVal = info.CallOperandVal;
5384 // If we don't have a value, we can't do a match,
5385 // but allow it at the lowest weight.
5386 if (CallOperandVal == NULL)
5387 return CW_Default;
5388 const Type *type = CallOperandVal->getType();
5389 // Look at the constraint type.
5390 switch (*constraint) {
5391 default:
5392 weight = TargetLowering::getSingleConstraintMatchWeight(info, constraint);
5393 break;
5394 case 'b':
5395 if (type->isIntegerTy())
5396 weight = CW_Register;
5397 break;
5398 case 'f':
5399 if (type->isFloatTy())
5400 weight = CW_Register;
5401 break;
5402 case 'd':
5403 if (type->isDoubleTy())
5404 weight = CW_Register;
5405 break;
5406 case 'v':
5407 if (type->isVectorTy())
5408 weight = CW_Register;
5409 break;
5410 case 'y':
5411 weight = CW_Register;
5412 break;
5413 }
5414 return weight;
5415 }
5416
53765417 std::pair
53775418 PPCTargetLowering::getRegForInlineAsmConstraint(const std::string &Constraint,
53785419 EVT VT) const {
307307 bool is8bit, unsigned Opcode) const;
308308
309309 ConstraintType getConstraintType(const std::string &Constraint) const;
310
311 /// Examine constraint string and operand type and determine a weight value.
312 /// The operand object must already have been set up with the operand type.
313 ConstraintWeight getSingleConstraintMatchWeight(
314 AsmOperandInfo &info, const char *constraint) const;
315
310316 std::pair
311317 getRegForInlineAsmConstraint(const std::string &Constraint,
312318 EVT VT) const;
1142711427
1142811428 bool X86TargetLowering::ExpandInlineAsm(CallInst *CI) const {
1142911429 InlineAsm *IA = cast(CI->getCalledValue());
11430 std::vector Constraints = IA->ParseConstraints();
11430 InlineAsm::ConstraintInfoVector Constraints = IA->ParseConstraints();
1143111431
1143211432 std::string AsmStr = IA->getAsmString();
1143311433
1150711507 X86TargetLowering::getConstraintType(const std::string &Constraint) const {
1150811508 if (Constraint.size() == 1) {
1150911509 switch (Constraint[0]) {
11510 case 'R':
11511 case 'q':
11512 case 'Q':
11513 case 'f':
11514 case 't':
11515 case 'u':
11516 case 'y':
11517 case 'x':
11518 case 'Y':
11519 return C_RegisterClass;
11520 case 'a':
11521 case 'b':
11522 case 'c':
11523 case 'd':
11524 case 'S':
11525 case 'D':
1151011526 case 'A':
1151111527 return C_Register;
11512 case 'f':
11513 case 'r':
11514 case 'R':
11515 case 'l':
11516 case 'q':
11517 case 'Q':
11518 case 'x':
11519 case 'y':
11520 case 'Y':
11521 return C_RegisterClass;
11528 case 'I':
11529 case 'J':
11530 case 'K':
11531 case 'L':
11532 case 'M':
11533 case 'N':
11534 case 'G':
11535 case 'C':
1152211536 case 'e':
1152311537 case 'Z':
1152411538 return C_Other;
1152911543 return TargetLowering::getConstraintType(Constraint);
1153011544 }
1153111545
11532 /// Examine constraint type and operand type and determine a weight value,
11533 /// where: -1 = invalid match, and 0 = so-so match to 3 = good match.
11546 /// Examine constraint type and operand type and determine a weight value.
1153411547 /// This object must already have been set up with the operand type
1153511548 /// and the current alternative constraint selected.
11536 int X86TargetLowering::getSingleConstraintMatchWeight(
11549 TargetLowering::ConstraintWeight
11550 X86TargetLowering::getSingleConstraintMatchWeight(
1153711551 AsmOperandInfo &info, const char *constraint) const {
11538 int weight = -1;
11552 ConstraintWeight weight = CW_Invalid;
1153911553 Value *CallOperandVal = info.CallOperandVal;
1154011554 // If we don't have a value, we can't do a match,
1154111555 // but allow it at the lowest weight.
1154211556 if (CallOperandVal == NULL)
11543 return 0;
11557 return CW_Default;
11558 const Type *type = CallOperandVal->getType();
1154411559 // Look at the constraint type.
1154511560 switch (*constraint) {
1154611561 default:
11547 return TargetLowering::getSingleConstraintMatchWeight(info, constraint);
11562 weight = TargetLowering::getSingleConstraintMatchWeight(info, constraint);
11563 case 'R':
11564 case 'q':
11565 case 'Q':
11566 case 'a':
11567 case 'b':
11568 case 'c':
11569 case 'd':
11570 case 'S':
11571 case 'D':
11572 case 'A':
11573 if (CallOperandVal->getType()->isIntegerTy())
11574 weight = CW_SpecificReg;
11575 break;
11576 case 'f':
11577 case 't':
11578 case 'u':
11579 if (type->isFloatingPointTy())
11580 weight = CW_SpecificReg;
11581 break;
11582 case 'y':
11583 if (type->isX86_MMXTy() && !DisableMMX && Subtarget->hasMMX())
11584 weight = CW_SpecificReg;
11585 break;
11586 case 'x':
11587 case 'Y':
11588 if ((type->getPrimitiveSizeInBits() == 128) && Subtarget->hasSSE1())
11589 weight = CW_Register;
1154811590 break;
1154911591 case 'I':
1155011592 if (ConstantInt *C = dyn_cast(info.CallOperandVal)) {
1155111593 if (C->getZExtValue() <= 31)
11552 weight = 3;
11594 weight = CW_Constant;
1155311595 }
1155411596 break;
11555 // etc.
11597 case 'J':
11598 if (ConstantInt *C = dyn_cast(CallOperandVal)) {
11599 if (C->getZExtValue() <= 63)
11600 weight = CW_Constant;
11601 }
11602 break;
11603 case 'K':
11604 if (ConstantInt *C = dyn_cast(CallOperandVal)) {
11605 if ((C->getSExtValue() >= -0x80) && (C->getSExtValue() <= 0x7f))
11606 weight = CW_Constant;
11607 }
11608 break;
11609 case 'L':
11610 if (ConstantInt *C = dyn_cast(CallOperandVal)) {
11611 if ((C->getZExtValue() == 0xff) || (C->getZExtValue() == 0xffff))
11612 weight = CW_Constant;
11613 }
11614 break;
11615 case 'M':
11616 if (ConstantInt *C = dyn_cast(CallOperandVal)) {
11617 if (C->getZExtValue() <= 3)
11618 weight = CW_Constant;
11619 }
11620 break;
11621 case 'N':
11622 if (ConstantInt *C = dyn_cast(CallOperandVal)) {
11623 if (C->getZExtValue() <= 0xff)
11624 weight = CW_Constant;
11625 }
11626 break;
11627 case 'G':
11628 case 'C':
11629 if (dyn_cast(CallOperandVal)) {
11630 weight = CW_Constant;
11631 }
11632 break;
11633 case 'e':
11634 if (ConstantInt *C = dyn_cast(CallOperandVal)) {
11635 if ((C->getSExtValue() >= -0x80000000LL) &&
11636 (C->getSExtValue() <= 0x7fffffffLL))
11637 weight = CW_Constant;
11638 }
11639 break;
11640 case 'Z':
11641 if (ConstantInt *C = dyn_cast(CallOperandVal)) {
11642 if (C->getZExtValue() <= 0xffffffff)
11643 weight = CW_Constant;
11644 }
11645 break;
1155611646 }
1155711647 return weight;
1155811648 }
541541
542542 ConstraintType getConstraintType(const std::string &Constraint) const;
543543
544 /// Examine constraint string and operand type and determine a weight value,
545 /// where: -1 = invalid match, and 0 = so-so match to 3 = good match.
544 /// Examine constraint string and operand type and determine a weight value.
546545 /// The operand object must already have been set up with the operand type.
547 virtual int getSingleConstraintMatchWeight(
546 virtual ConstraintWeight getSingleConstraintMatchWeight(
548547 AsmOperandInfo &info, const char *constraint) const;
549548
550549 std::vector
742742 DenseMap &SunkAddrs) {
743743 bool MadeChange = false;
744744
745 std::vector TargetConstraints = TLI->ParseConstraints(CS);
745 TargetLowering::AsmOperandInfoVector TargetConstraints = TLI->ParseConstraints(CS);
746746 unsigned ArgNo = 0;
747747 for (unsigned i = 0, e = TargetConstraints.size(); i != e; ++i) {
748748 TargetLowering::AsmOperandInfo &OpInfo = TargetConstraints[i];
379379 /// return false.
380380 static bool IsOperandAMemoryOperand(CallInst *CI, InlineAsm *IA, Value *OpVal,
381381 const TargetLowering &TLI) {
382 std::vector TargetConstraints = TLI.ParseConstraints(ImmutableCallSite(CI));
382 TargetLowering::AsmOperandInfoVector TargetConstraints = TLI.ParseConstraints(ImmutableCallSite(CI));
383383 for (unsigned i = 0, e = TargetConstraints.size(); i != e; ++i) {
384384 TargetLowering::AsmOperandInfo &OpInfo = TargetConstraints[i];
385385
7575 /// fields in this structure. If the constraint string is not understood,
7676 /// return true, otherwise return false.
7777 bool InlineAsm::ConstraintInfo::Parse(StringRef Str,
78 std::vector &ConstraintsSoFar) {
78 InlineAsm::ConstraintInfoVector &ConstraintsSoFar) {
7979 StringRef::iterator I = Str.begin(), E = Str.end();
8080 unsigned multipleAlternativeCount = Str.count('|') + 1;
8181 unsigned multipleAlternativeIndex = 0;
82 std::vector *pCodes = &Codes;
82 ConstraintCodeVector *pCodes = &Codes;
8383
8484 // Initialize
8585 isMultipleAlternative = (multipleAlternativeCount > 1 ? true : false);
201201 }
202202 }
203203
204 std::vector
204 InlineAsm::ConstraintInfoVector
205205 InlineAsm::ParseConstraints(StringRef Constraints) {
206 std::vector Result;
206 ConstraintInfoVector Result;
207207
208208 // Scan the constraints string.
209209 for (StringRef::iterator I = Constraints.begin(),
238238 bool InlineAsm::Verify(const FunctionType *Ty, StringRef ConstStr) {
239239 if (Ty->isVarArg()) return false;
240240
241 std::vector Constraints = ParseConstraints(ConstStr);
241 ConstraintInfoVector Constraints = ParseConstraints(ConstStr);
242242
243243 // Error parsing constraints.
244244 if (Constraints.empty() && !ConstStr.empty()) return false;