Index: lib/CodeGen/TargetInstrInfo.cpp =================================================================== --- lib/CodeGen/TargetInstrInfo.cpp +++ lib/CodeGen/TargetInstrInfo.cpp @@ -75,29 +75,43 @@ /// multiple instructions separated by SeparatorString or newlines. /// Variable-length instructions are not handled here; this function /// may be overloaded in the target code to do that. +/// We implement the special case of the .space directive taking only an +/// integer argument, which is the size in bytes. This is used for creating +/// inline code spacing for testing purposes using inline assembly. unsigned TargetInstrInfo::getInlineAsmLength(const char *Str, const MCAsmInfo &MAI) const { // Count the number of instructions in the asm. - bool atInsnStart = true; - unsigned InstCount = 0; + bool AtInsnStart = true; + unsigned Length = 0; for (; *Str; ++Str) { if (*Str == '\n' || strncmp(Str, MAI.getSeparatorString(), strlen(MAI.getSeparatorString())) == 0) { - atInsnStart = true; + AtInsnStart = true; } else if (strncmp(Str, MAI.getCommentString().data(), MAI.getCommentString().size()) == 0) { // Stop counting as an instruction after a comment until the next // separator. - atInsnStart = false; + AtInsnStart = false; } - if (atInsnStart && !std::isspace(static_cast(*Str))) { - ++InstCount; - atInsnStart = false; + if (AtInsnStart && !std::isspace(static_cast(*Str))) { + unsigned AddLength = MAI.getMaxInstLength(); + if (strncmp(Str, ".space", 6) == 0) { + char *EStr; + int SpaceSize; + SpaceSize = strtol(Str + 6, &EStr, 10); + SpaceSize = SpaceSize < 0 ? 0 : SpaceSize; + while (isspace(static_cast(*EStr))) + ++EStr; + if (*EStr == '\0') // Successfully parsed .space argument + AddLength = SpaceSize; + } + Length += AddLength; + AtInsnStart = false; } } - return InstCount * MAI.getMaxInstLength(); + return Length; } /// ReplaceTailWithBranchTo - Delete the instruction OldInst and everything Index: lib/Target/Mips/Mips16InstrInfo.h =================================================================== --- lib/Target/Mips/Mips16InstrInfo.h +++ lib/Target/Mips/Mips16InstrInfo.h @@ -102,9 +102,6 @@ void BuildAddiuSpImm (MachineBasicBlock &MBB, MachineBasicBlock::iterator I, int64_t Imm) const; - - unsigned getInlineAsmLength(const char *Str, - const MCAsmInfo &MAI) const override; private: unsigned getAnalyzableBrOpc(unsigned Opc) const override; Index: lib/Target/Mips/Mips16InstrInfo.cpp =================================================================== --- lib/Target/Mips/Mips16InstrInfo.cpp +++ lib/Target/Mips/Mips16InstrInfo.cpp @@ -483,45 +483,3 @@ } llvm_unreachable("unexpected Opcode in validImmediate"); } - -/// Measure the specified inline asm to determine an approximation of its -/// length. -/// Comments (which run till the next SeparatorString or newline) do not -/// count as an instruction. -/// Any other non-whitespace text is considered an instruction, with -/// multiple instructions separated by SeparatorString or newlines. -/// Variable-length instructions are not handled here; this function -/// may be overloaded in the target code to do that. -/// We implement the special case of the .space directive taking only an -/// integer argument, which is the size in bytes. This is used for creating -/// inline code spacing for testing purposes using inline assembly. -unsigned Mips16InstrInfo::getInlineAsmLength(const char *Str, - const MCAsmInfo &MAI) const { - - // Count the number of instructions in the asm. - bool atInsnStart = true; - unsigned Length = 0; - for (; *Str; ++Str) { - if (*Str == '\n' || strncmp(Str, MAI.getSeparatorString(), - strlen(MAI.getSeparatorString())) == 0) - atInsnStart = true; - if (atInsnStart && !std::isspace(static_cast(*Str))) { - if (strncmp(Str, ".space", 6)==0) { - char *EStr; int Sz; - Sz = strtol(Str+6, &EStr, 10); - while (isspace(*EStr)) ++EStr; - if (*EStr=='\0') { - DEBUG(dbgs() << "parsed .space " << Sz << '\n'); - return Sz; - } - } - Length += MAI.getMaxInstLength(); - atInsnStart = false; - } - if (atInsnStart && strncmp(Str, MAI.getCommentString().data(), - MAI.getCommentString().size()) == 0) - atInsnStart = false; - } - - return Length; -}