From: Chris Lattner Date: Mon, 30 Apr 2007 17:16:27 +0000 (+0000) Subject: refactor some code, no functionality change X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=3ff90dc1c8aaa5d9be94cdca8c4a7e71f45da8fd;hp=1f6f4c7346b6d78f097f25777211fdd4e4267086;p=oota-llvm.git refactor some code, no functionality change git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@36590 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp b/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp index 023bbfd0906..58a00bb7310 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp +++ b/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp @@ -3134,44 +3134,6 @@ GetRegistersForValue(const std::string &ConstrCode, return RegsForValue(); } -/// getConstraintGenerality - Return an integer indicating how general CT is. -static unsigned getConstraintGenerality(TargetLowering::ConstraintType CT) { - switch (CT) { - default: assert(0 && "Unknown constraint type!"); - case TargetLowering::C_Other: - case TargetLowering::C_Unknown: - return 0; - case TargetLowering::C_Register: - return 1; - case TargetLowering::C_RegisterClass: - return 2; - case TargetLowering::C_Memory: - return 3; - } -} - -static std::string GetMostGeneralConstraint(std::vector &C, - const TargetLowering &TLI) { - assert(!C.empty() && "Must have at least one constraint"); - if (C.size() == 1) return C[0]; - - std::string *Current = &C[0]; - // If we have multiple constraints, try to pick the most general one ahead - // of time. This isn't a wonderful solution, but handles common cases. - TargetLowering::ConstraintType Flavor = TLI.getConstraintType(Current[0]); - for (unsigned j = 1, e = C.size(); j != e; ++j) { - TargetLowering::ConstraintType ThisFlavor = TLI.getConstraintType(C[j]); - if (getConstraintGenerality(ThisFlavor) > - getConstraintGenerality(Flavor)) { - // This constraint letter is more general than the previous one, - // use it. - Flavor = ThisFlavor; - Current = &C[j]; - } - } - return *Current; -} - namespace { /// AsmOperandInfo - This contains information for each constraint that we are /// lowering. @@ -3197,9 +3159,59 @@ struct AsmOperandInfo : public InlineAsm::ConstraintInfo { ConstraintType(TargetLowering::C_Unknown), CallOperand(0,0), CallOperandVal(0), ConstraintVT(MVT::Other) { } + + void ComputeConstraintToUse(const TargetLowering &TLI); }; } // end anon namespace. +/// getConstraintGenerality - Return an integer indicating how general CT is. +static unsigned getConstraintGenerality(TargetLowering::ConstraintType CT) { + switch (CT) { + default: assert(0 && "Unknown constraint type!"); + case TargetLowering::C_Other: + case TargetLowering::C_Unknown: + return 0; + case TargetLowering::C_Register: + return 1; + case TargetLowering::C_RegisterClass: + return 2; + case TargetLowering::C_Memory: + return 3; + } +} + +void AsmOperandInfo::ComputeConstraintToUse(const TargetLowering &TLI) { + assert(!Codes.empty() && "Must have at least one constraint"); + + std::string *Current = &Codes[0]; + TargetLowering::ConstraintType CurType = TLI.getConstraintType(*Current); + if (Codes.size() == 1) { // Single-letter constraints ('r') are very common. + ConstraintCode = *Current; + ConstraintType = CurType; + return; + } + + unsigned CurGenerality = getConstraintGenerality(CurType); + + // If we have multiple constraints, try to pick the most general one ahead + // of time. This isn't a wonderful solution, but handles common cases. + for (unsigned j = 1, e = Codes.size(); j != e; ++j) { + TargetLowering::ConstraintType ThisType = TLI.getConstraintType(Codes[j]); + unsigned ThisGenerality = getConstraintGenerality(ThisType); + if (ThisGenerality > CurGenerality) { + // This constraint letter is more general than the previous one, + // use it. + CurType = ThisType; + Current = &Codes[j]; + CurGenerality = ThisGenerality; + } + } + + ConstraintCode = *Current; + ConstraintType = CurType; +} + + /// visitInlineAsm - Handle a call to an InlineAsm object. /// void SelectionDAGLowering::visitInlineAsm(CallInst &I) { @@ -3274,12 +3286,8 @@ void SelectionDAGLowering::visitInlineAsm(CallInst &I) { OpInfo.ConstraintVT = OpVT; - // Compute the constraint code to use. - OpInfo.ConstraintCode = GetMostGeneralConstraint(OpInfo.Codes, TLI); - - // Compute the constraint type. - // FIXME: merge this into GetMostGeneralConstraint. - OpInfo.ConstraintType = TLI.getConstraintType(OpInfo.ConstraintCode); + // Compute the constraint code and ConstraintType to use. + OpInfo.ComputeConstraintToUse(TLI); // If this is a memory input, and if the operand is not indirect, do what we