Skip to content

Commit

Permalink
Merged master:1d54e75cf26a into amd-gfx:4632cf3ab52c
Browse files Browse the repository at this point in the history
Local branch amd-gfx 4632cf3 Merged master:984744a1314c into amd-gfx:93def576d34e
Remote branch master 1d54e75 [GlobalISel] Fix multiply with overflow intrinsics legalization generating invalid MIR.
  • Loading branch information
Sw authored and Sw committed Sep 30, 2020
2 parents 4632cf3 + 1d54e75 commit 2aaac36
Show file tree
Hide file tree
Showing 32 changed files with 339 additions and 280 deletions.
2 changes: 1 addition & 1 deletion clang/lib/CodeGen/CGDebugInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1726,7 +1726,7 @@ llvm::DISubprogram *CGDebugInfo::CreateCXXMemberFunction(
// info is emitted.
if (DebugKind == codegenoptions::DebugInfoConstructor)
if (const CXXConstructorDecl *CD = dyn_cast<CXXConstructorDecl>(Method))
completeClass(CD->getParent());
completeUnusedClass(*CD->getParent());

llvm::DINodeArray TParamsArray = CollectFunctionTemplateParams(Method, Unit);
llvm::DISubprogram *SP = DBuilder.createMethod(
Expand Down
21 changes: 21 additions & 0 deletions clang/lib/Headers/__clang_hip_math.h
Original file line number Diff line number Diff line change
Expand Up @@ -1221,6 +1221,27 @@ __DEVICE__
inline _Float16 pow(_Float16 __base, int __iexp) {
return __ocml_pown_f16(__base, __iexp);
}

__DEVICE__
inline float remquo(float __x, float __y, int *__quo) {
return remquof(__x, __y, __quo);
}

template <typename __T1, typename __T2>
__DEVICE__
typename __hip_enable_if<std::numeric_limits<__T1>::is_specialized &&
std::numeric_limits<__T2>::is_specialized,
double>::type
remquo(__T1 __x, __T2 __y, int *__quo) {
return remquo((double)__x, (double)__y, __quo);
}

__DEVICE__
inline float frexp(float __x, int *__nptr) { return frexpf(__x, __nptr); }

__DEVICE__
inline float modf(float __x, float *__iptr) { return modff(__x, __iptr); }

#endif

#pragma pop_macro("__DEF_FUN1")
Expand Down
6 changes: 5 additions & 1 deletion clang/test/CodeGenCXX/debug-info-limited-ctor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ struct B {
B();
} TestB;

// CHECK-DAG: !DICompositeType(tag: DW_TAG_structure_type, name: "C"{{.*}}DIFlagTypePassByValue
// CHECK-DAG: ![[C:[0-9]+]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "C"{{.*}}DIFlagTypePassByValue
struct C {
C() {}
} TestC;
Expand Down Expand Up @@ -73,3 +73,7 @@ void f(K k) {}
void L() {
auto func = [&]() {};
}

// Check that types are being added to retained types list.
// CHECK-DAG: !DICompileUnit{{.*}}retainedTypes: ![[RETAINED:[0-9]+]]
// CHECK-DAG: ![[RETAINED]] = {{.*}}![[C]]
2 changes: 1 addition & 1 deletion libcxx/include/compare
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ enum class _LIBCPP_ENUM_VIS _NCmpResult : signed char {

struct _CmpUnspecifiedParam {
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEVAL
_CmpUnspecifiedParam(int _CmpUnspecifiedParam::*) {}
_CmpUnspecifiedParam(int _CmpUnspecifiedParam::*) noexcept {}

template<typename _Tp, typename = _VSTD::enable_if_t<!_VSTD::is_same_v<_Tp, int>>>
_CmpUnspecifiedParam(_Tp) = delete;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ void test_category(T v) {
void(0 > v);
void(v >= 0);
void(0 >= v);
#ifndef _LIBCPP_HAS_NO_THREE_WAY_COMPARISON
void(v <=> 0); // expected-error 3 {{}}
void(0 <=> v); // expected-error 3 {{}}
#ifndef _LIBCPP_HAS_NO_SPACESHIP_OPERATOR
void(v <=> 0);
void(0 <=> v);
#endif
}

Expand Down
7 changes: 5 additions & 2 deletions lldb/test/API/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,14 @@ set(LLDB_TEST_USER_ARGS
# hash of filename and .text section, there *will* be conflicts inside
# the build directory.
set(LLDB_TEST_COMMON_ARGS
-s
${CMAKE_BINARY_DIR}/lldb-test-traces
-S nm
-u CXXFLAGS
-u CFLAGS
)

# Configure the traces directory.
set(LLDB_TEST_TRACE_DIRECTORY "${PROJECT_BINARY_DIR}/lldb-test-traces" CACHE PATH "The test traces directory.")

# Set the path to the default lldb test executable.
set(LLDB_DEFAULT_TEST_EXECUTABLE "${LLVM_RUNTIME_OUTPUT_INTDIR}/lldb${CMAKE_EXECUTABLE_SUFFIX}")

Expand Down Expand Up @@ -141,6 +142,7 @@ if(LLDB_BUILT_STANDALONE)
string(REPLACE ${LLVM_RUNTIME_OUTPUT_INTDIR} ${config_runtime_output_dir} LLDB_SOURCE_DIR "${LLDB_SOURCE_DIR}")
string(REPLACE ${LLVM_RUNTIME_OUTPUT_INTDIR} ${config_runtime_output_dir} LLDB_FRAMEWORK_DIR "${LLDB_FRAMEWORK_DIR}")
string(REPLACE ${LLVM_RUNTIME_OUTPUT_INTDIR} ${config_runtime_output_dir} LLDB_TEST_BUILD_DIRECTORY "${LLDB_TEST_BUILD_DIRECTORY}")
string(REPLACE ${LLVM_RUNTIME_OUTPUT_INTDIR} ${config_runtime_output_dir} LLDB_TEST_TRACE_DIRECTORY "${LLDB_TEST_TRACE_DIRECTORY}")
string(REPLACE ${LLVM_RUNTIME_OUTPUT_INTDIR} ${config_runtime_output_dir} LLDB_TEST_EXECUTABLE "${LLDB_TEST_EXECUTABLE}")
string(REPLACE ${LLVM_RUNTIME_OUTPUT_INTDIR} ${config_runtime_output_dir} LLDB_TEST_COMPILER "${LLDB_TEST_COMPILER}")
string(REPLACE ${LLVM_RUNTIME_OUTPUT_INTDIR} ${config_runtime_output_dir} LLDB_TEST_DSYMUTIL "${LLDB_TEST_DSYMUTIL}")
Expand Down Expand Up @@ -170,6 +172,7 @@ endif()
string(REPLACE ${CMAKE_CFG_INTDIR} ${dotest_args_replacement} LLDB_DOTEST_ARGS "${LLDB_DOTEST_ARGS}")
string(REPLACE ${CMAKE_CFG_INTDIR} ${dotest_args_replacement} LLDB_SOURCE_DIR "${LLDB_SOURCE_DIR}")
string(REPLACE ${CMAKE_CFG_INTDIR} ${dotest_args_replacement} LLDB_TEST_BUILD_DIRECTORY "${LLDB_TEST_BUILD_DIRECTORY}")
string(REPLACE ${CMAKE_CFG_INTDIR} ${dotest_args_replacement} LLDB_TEST_TRACE_DIRECTORY "${LLDB_TEST_TRACE_DIRECTORY}")
string(REPLACE ${CMAKE_CFG_INTDIR} ${dotest_args_replacement} LLDB_TEST_EXECUTABLE "${LLDB_TEST_EXECUTABLE}")
string(REPLACE ${CMAKE_CFG_INTDIR} ${dotest_args_replacement} LLDB_TEST_COMPILER "${LLDB_TEST_COMPILER}")
string(REPLACE ${CMAKE_CFG_INTDIR} ${dotest_args_replacement} LLDB_TEST_DSYMUTIL "${LLDB_TEST_DSYMUTIL}")
Expand Down
3 changes: 3 additions & 0 deletions lldb/test/API/lit.cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@ def delete_module_cache(path):
if is_configured('lldb_build_directory'):
dotest_cmd += ['--build-dir', config.lldb_build_directory]

if is_configured('lldb_trace_directory'):
dotest_cmd += ['-s', config.lldb_trace_directory]

if is_configured('lldb_module_cache'):
delete_module_cache(config.lldb_module_cache)
dotest_cmd += ['--lldb-module-cache-dir', config.lldb_module_cache]
Expand Down
1 change: 1 addition & 0 deletions lldb/test/API/lit.site.cfg.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ config.shared_libs = @LLVM_ENABLE_SHARED_LIBS@
config.llvm_use_sanitizer = "@LLVM_USE_SANITIZER@"
config.target_triple = "@TARGET_TRIPLE@"
config.lldb_build_directory = "@LLDB_TEST_BUILD_DIRECTORY@"
config.lldb_trace_directory = "@LLDB_TEST_TRACE_DIRECTORY@"
config.lldb_reproducer_directory = os.path.join("@LLDB_TEST_BUILD_DIRECTORY@", "reproducers")
config.python_executable = "@Python3_EXECUTABLE@"
config.dotest_args_str = "@LLDB_DOTEST_ARGS@"
Expand Down
5 changes: 5 additions & 0 deletions lldb/utils/lldb-dotest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ if(LLDB_BUILT_STANDALONE)
string(REPLACE ${LLVM_RUNTIME_OUTPUT_INTDIR} ${config_runtime_output_dir} LLDB_SOURCE_DIR_CONFIGURED "${LLDB_SOURCE_DIR}")
string(REPLACE ${LLVM_RUNTIME_OUTPUT_INTDIR} ${config_runtime_output_dir} LLDB_FRAMEWORK_DIR_CONFIGURED "${LLDB_FRAMEWORK_DIR}")
string(REPLACE ${LLVM_RUNTIME_OUTPUT_INTDIR} ${config_runtime_output_dir} LLDB_TEST_BUILD_DIRECTORY_CONFIGURED "${LLDB_TEST_BUILD_DIRECTORY}")
string(REPLACE ${LLVM_RUNTIME_OUTPUT_INTDIR} ${config_runtime_output_dir} LLDB_TEST_TRACE_DIRECTORY_CONFIGURED "${LLDB_TEST_TRACE_DIRECTORY}")
string(REPLACE ${LLVM_RUNTIME_OUTPUT_INTDIR} ${config_runtime_output_dir} LLDB_TEST_EXECUTABLE_CONFIGURED "${LLDB_TEST_EXECUTABLE}")
string(REPLACE ${LLVM_RUNTIME_OUTPUT_INTDIR} ${config_runtime_output_dir} LLDB_TEST_COMPILER_CONFIGURED "${LLDB_TEST_COMPILER}")
string(REPLACE ${LLVM_RUNTIME_OUTPUT_INTDIR} ${config_runtime_output_dir} LLDB_TEST_DSYMUTIL_CONFIGURED "${LLDB_TEST_DSYMUTIL}")
Expand All @@ -37,6 +38,7 @@ if(LLDB_BUILT_STANDALONE)
string(REPLACE ${CMAKE_CFG_INTDIR} ${config_type} LLDB_SOURCE_DIR_CONFIGURED "${LLDB_SOURCE_DIR}")
string(REPLACE ${CMAKE_CFG_INTDIR} ${config_type} LLDB_FRAMEWORK_DIR_CONFIGURED "${LLDB_FRAMEWORK_DIR}")
string(REPLACE ${CMAKE_CFG_INTDIR} ${config_type} LLDB_TEST_BUILD_DIRECTORY_CONFIGURED "${LLDB_TEST_BUILD_DIRECTORY}")
string(REPLACE ${CMAKE_CFG_INTDIR} ${config_type} LLDB_TEST_TRACE_DIRECTORY_CONFIGURED "${LLDB_TEST_TRACE_DIRECTORY}")
string(REPLACE ${CMAKE_CFG_INTDIR} ${config_type} LLDB_TEST_EXECUTABLE_CONFIGURED "${LLDB_TEST_EXECUTABLE}")
string(REPLACE ${CMAKE_CFG_INTDIR} ${config_type} LLDB_TEST_COMPILER_CONFIGURED "${LLDB_TEST_COMPILER}")
string(REPLACE ${CMAKE_CFG_INTDIR} ${config_type} LLDB_TEST_DSYMUTIL_CONFIGURED "${LLDB_TEST_DSYMUTIL}")
Expand All @@ -50,6 +52,7 @@ if(LLDB_BUILT_STANDALONE)
string(REPLACE ${CMAKE_CFG_INTDIR} "." LLDB_SOURCE_DIR_CONFIGURED "${LLDB_SOURCE_DIR}")
string(REPLACE ${CMAKE_CFG_INTDIR} "." LLDB_FRAMEWORK_DIR_CONFIGURED "${LLDB_FRAMEWORK_DIR}")
string(REPLACE ${CMAKE_CFG_INTDIR} "." LLDB_TEST_BUILD_DIRECTORY_CONFIGURED "${LLDB_TEST_BUILD_DIRECTORY}")
string(REPLACE ${CMAKE_CFG_INTDIR} "." LLDB_TEST_TRACE_DIRECTORY_CONFIGURED "${LLDB_TEST_TRACE_DIRECTORY}")
string(REPLACE ${CMAKE_CFG_INTDIR} "." LLDB_TEST_EXECUTABLE_CONFIGURED "${LLDB_TEST_EXECUTABLE}")
string(REPLACE ${CMAKE_CFG_INTDIR} "." LLDB_TEST_COMPILER_CONFIGURED "${LLDB_TEST_COMPILER}")
string(REPLACE ${CMAKE_CFG_INTDIR} "." LLDB_TEST_DSYMUTIL_CONFIGURED "${LLDB_TEST_DSYMUTIL}")
Expand All @@ -71,6 +74,7 @@ elseif(NOT "${CMAKE_CFG_INTDIR}" STREQUAL ".")
string(REPLACE ${CMAKE_CFG_INTDIR} ${LLVM_BUILD_MODE} LLDB_SOURCE_DIR_CONFIGURED "${LLDB_SOURCE_DIR}")
string(REPLACE ${CMAKE_CFG_INTDIR} ${LLVM_BUILD_MODE} LLDB_FRAMEWORK_DIR_CONFIGURED "${LLDB_FRAMEWORK_DIR}")
string(REPLACE ${CMAKE_CFG_INTDIR} ${LLVM_BUILD_MODE} LLDB_TEST_BUILD_DIRECTORY_CONFIGURED "${LLDB_TEST_BUILD_DIRECTORY}")
string(REPLACE ${CMAKE_CFG_INTDIR} ${LLVM_BUILD_MODE} LLDB_TEST_TRACE_DIRECTORY_CONFIGURED "${LLDB_TEST_TRACE_DIRECTORY}")
string(REPLACE ${CMAKE_CFG_INTDIR} ${LLVM_BUILD_MODE} LLDB_TEST_EXECUTABLE_CONFIGURED "${LLDB_TEST_EXECUTABLE}")
string(REPLACE ${CMAKE_CFG_INTDIR} ${LLVM_BUILD_MODE} LLDB_TEST_COMPILER_CONFIGURED "${LLDB_TEST_COMPILER}")
string(REPLACE ${CMAKE_CFG_INTDIR} ${LLVM_BUILD_MODE} LLDB_TEST_DSYMUTIL_CONFIGURED "${LLDB_TEST_DSYMUTIL}")
Expand All @@ -89,6 +93,7 @@ else()
set(LLDB_SOURCE_DIR_CONFIGURED "${LLDB_SOURCE_DIR}")
set(LLDB_FRAMEWORK_DIR_CONFIGURED "${LLDB_FRAMEWORK_DIR}")
set(LLDB_TEST_BUILD_DIRECTORY_CONFIGURED "${LLDB_TEST_BUILD_DIRECTORY}")
set(LLDB_TEST_TRACE_DIRECTORY_CONFIGURED "${LLDB_TEST_TRACE_DIRECTORY}")
set(LLDB_TEST_EXECUTABLE_CONFIGURED "${LLDB_TEST_EXECUTABLE}")
set(LLDB_TEST_COMPILER_CONFIGURED "${LLDB_TEST_COMPILER}")
set(LLDB_TEST_DSYMUTIL_CONFIGURED "${LLDB_TEST_DSYMUTIL}")
Expand Down
10 changes: 6 additions & 4 deletions lldb/utils/lldb-dotest/lldb-dotest.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import subprocess
import sys

dotest_path = '@LLDB_SOURCE_DIR_CONFIGURED@/test/API/dotest.py'
build_dir = '@LLDB_TEST_BUILD_DIRECTORY_CONFIGURED@'
dotest_args_str = '@LLDB_DOTEST_ARGS_CONFIGURED@'
arch = '@LLDB_TEST_ARCH@'
executable = '@LLDB_TEST_EXECUTABLE_CONFIGURED@'
Expand All @@ -12,9 +11,11 @@ dsymutil = '@LLDB_TEST_DSYMUTIL_CONFIGURED@'
filecheck = '@LLDB_TEST_FILECHECK_CONFIGURED@'
yaml2obj = '@LLDB_TEST_YAML2OBJ_CONFIGURED@'
server = '@LLDB_TEST_SERVER_CONFIGURED@'
lldb_libs_dir = "@LLDB_LIBS_DIR_CONFIGURED@"
lldb_framework_dir = "@LLDB_FRAMEWORK_DIR_CONFIGURED@"
lldb_build_dir = '@LLDB_TEST_BUILD_DIRECTORY_CONFIGURED@'
lldb_build_intel_pt = "@LLDB_BUILD_INTEL_PT@"
lldb_framework_dir = "@LLDB_FRAMEWORK_DIR_CONFIGURED@"
lldb_libs_dir = "@LLDB_LIBS_DIR_CONFIGURED@"
lldb_trace_dir = '@LLDB_TEST_TRACE_DIRECTORY_CONFIGURED@'

if __name__ == '__main__':
wrapper_args = sys.argv[1:]
Expand All @@ -23,7 +24,8 @@ if __name__ == '__main__':
cmd = [sys.executable, dotest_path]
cmd.extend(['--arch', arch])
cmd.extend(dotest_args)
cmd.extend(['--build-dir', build_dir])
cmd.extend(['-s', lldb_trace_dir])
cmd.extend(['--build-dir', lldb_build_dir])
cmd.extend(['--executable', executable])
cmd.extend(['--compiler', compiler])
cmd.extend(['--dsymutil', dsymutil])
Expand Down
2 changes: 1 addition & 1 deletion llvm/docs/HowToUpdateDebugInfo.rst
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ When to drop an instruction location
A transformation should drop debug locations if the rules for
:ref:`preserving<WhenToPreserveLocation>` and
:ref:`merging<WhenToMergeLocation>` debug locations do not apply. The API to
use is ``Instruction::setDebugLoc()``.
use is ``Instruction::dropLocation()``.

The purpose of this rule is to prevent erratic or misleading single-stepping
behavior in situations in which an instruction has no clear, unambiguous
Expand Down
23 changes: 23 additions & 0 deletions llvm/include/llvm/MC/MCAsmInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ enum LCOMMType { NoAlignment, ByteAlignment, Log2Alignment };
/// This class is intended to be used as a base class for asm
/// properties and features specific to the target.
class MCAsmInfo {
public:
/// Assembly character literal syntax types.
enum AsmCharLiteralSyntax {
ACLS_Unknown, /// Unknown; character literals not used by LLVM for this
/// target.
ACLS_SingleQuotePrefix, /// The desired character is prefixed by a single
/// quote, e.g., `'A`.
};

protected:
//===------------------------------------------------------------------===//
// Properties to be set by the target writer, used to configure asm printer.
Expand Down Expand Up @@ -200,6 +209,16 @@ class MCAsmInfo {
/// doesn't support this, it can be set to null. Defaults to "\t.asciz\t"
const char *AscizDirective;

/// This directive accepts a comma-separated list of bytes for emission as a
/// string of bytes. For targets that do not support this, it shall be set to
/// null. Defaults to null.
const char *ByteListDirective = nullptr;

/// Form used for character literals in the assembly syntax. Useful for
/// producing strings as byte lists. If a target does not use or support
/// this, it shall be set to ACLS_Unknown. Defaults to ACLS_Unknown.
AsmCharLiteralSyntax CharacterLiteralSyntax = ACLS_Unknown;

/// These directives are used to output some unit of integer data to the
/// current section. If a data directive is set to null, smaller data
/// directives will be used to emit the large sizes. Defaults to "\t.byte\t",
Expand Down Expand Up @@ -562,6 +581,10 @@ class MCAsmInfo {
}
const char *getAsciiDirective() const { return AsciiDirective; }
const char *getAscizDirective() const { return AscizDirective; }
const char *getByteListDirective() const { return ByteListDirective; }
AsmCharLiteralSyntax characterLiteralSyntax() const {
return CharacterLiteralSyntax;
}
bool getAlignmentIsInBytes() const { return AlignmentIsInBytes; }
unsigned getTextAlignFillValue() const { return TextAlignFillValue; }
const char *getGlobalDirective() const { return GlobalDirective; }
Expand Down
5 changes: 3 additions & 2 deletions llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2892,11 +2892,12 @@ LegalizerHelper::lower(MachineInstr &MI, unsigned TypeIdx, LLT LowerHintTy) {
MI.RemoveOperand(1);
Observer.changedInstr(MI);

MIRBuilder.setInsertPt(MIRBuilder.getMBB(), ++MIRBuilder.getInsertPt());

auto HiPart = MIRBuilder.buildInstr(Opcode, {Ty}, {LHS, RHS});
auto Zero = MIRBuilder.buildConstant(Ty, 0);

// Move insert point forward so we can use the Res register if needed.
MIRBuilder.setInsertPt(MIRBuilder.getMBB(), ++MIRBuilder.getInsertPt());

// For *signed* multiply, overflow is detected by checking:
// (hi != (lo >> bitwidth-1))
if (Opcode == TargetOpcode::G_SMULH) {
Expand Down
2 changes: 2 additions & 0 deletions llvm/lib/MC/MCAsmInfoXCOFF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ MCAsmInfoXCOFF::MCAsmInfoXCOFF() {
ZeroDirectiveSupportsNonZeroValue = false;
AsciiDirective = nullptr; // not supported
AscizDirective = nullptr; // not supported
ByteListDirective = "\t.byte\t";
CharacterLiteralSyntax = ACLS_SingleQuotePrefix;

// Use .vbyte for data definition to avoid directives that apply an implicit
// alignment.
Expand Down
94 changes: 72 additions & 22 deletions llvm/lib/MC/MCAsmStreamer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -971,6 +971,47 @@ void MCAsmStreamer::emitTBSSSymbol(MCSection *Section, MCSymbol *Symbol,

static inline char toOctal(int X) { return (X&7)+'0'; }

static void PrintByteList(StringRef Data, raw_ostream &OS,
MCAsmInfo::AsmCharLiteralSyntax ACLS) {
assert(!Data.empty() && "Cannot generate an empty list.");
const auto printCharacterInOctal = [&OS](unsigned char C) {
OS << '0';
OS << toOctal(C >> 6);
OS << toOctal(C >> 3);
OS << toOctal(C >> 0);
};
const auto printOneCharacterFor = [printCharacterInOctal](
auto printOnePrintingCharacter) {
return [printCharacterInOctal, printOnePrintingCharacter](unsigned char C) {
if (isPrint(C)) {
printOnePrintingCharacter(static_cast<char>(C));
return;
}
printCharacterInOctal(C);
};
};
const auto printCharacterList = [Data, &OS](const auto &printOneCharacter) {
const auto BeginPtr = Data.begin(), EndPtr = Data.end();
for (const unsigned char C : make_range(BeginPtr, EndPtr - 1)) {
printOneCharacter(C);
OS << ',';
}
printOneCharacter(*(EndPtr - 1));
};
switch (ACLS) {
case MCAsmInfo::ACLS_Unknown:
printCharacterList(printCharacterInOctal);
return;
case MCAsmInfo::ACLS_SingleQuotePrefix:
printCharacterList(printOneCharacterFor([&OS](char C) {
const char AsmCharLitBuf[2] = {'\'', C};
OS << StringRef(AsmCharLitBuf, sizeof(AsmCharLitBuf));
}));
return;
}
llvm_unreachable("Invalid AsmCharLiteralSyntax value!");
}

static void PrintQuotedString(StringRef Data, raw_ostream &OS) {
OS << '"';

Expand Down Expand Up @@ -1009,33 +1050,42 @@ void MCAsmStreamer::emitBytes(StringRef Data) {
"Cannot emit contents before setting section!");
if (Data.empty()) return;

// If only single byte is provided or no ascii or asciz directives is
// supported, emit as vector of 8bits data.
if (Data.size() == 1 ||
!(MAI->getAscizDirective() || MAI->getAsciiDirective())) {
if (MCTargetStreamer *TS = getTargetStreamer()) {
TS->emitRawBytes(Data);
const auto emitAsString = [this](StringRef Data) {
// If the data ends with 0 and the target supports .asciz, use it, otherwise
// use .ascii or a byte-list directive
if (MAI->getAscizDirective() && Data.back() == 0) {
OS << MAI->getAscizDirective();
Data = Data.substr(0, Data.size() - 1);
} else if (LLVM_LIKELY(MAI->getAsciiDirective())) {
OS << MAI->getAsciiDirective();
} else if (MAI->getByteListDirective()) {
OS << MAI->getByteListDirective();
PrintByteList(Data, OS, MAI->characterLiteralSyntax());
EmitEOL();
return true;
} else {
const char *Directive = MAI->getData8bitsDirective();
for (const unsigned char C : Data.bytes()) {
OS << Directive << (unsigned)C;
EmitEOL();
}
return false;
}

PrintQuotedString(Data, OS);
EmitEOL();
return true;
};

if (Data.size() != 1 && emitAsString(Data))
return;
}

// If the data ends with 0 and the target supports .asciz, use it, otherwise
// use .ascii
if (MAI->getAscizDirective() && Data.back() == 0) {
OS << MAI->getAscizDirective();
Data = Data.substr(0, Data.size()-1);
} else {
OS << MAI->getAsciiDirective();
// Only single byte is provided or no ascii, asciz, or byte-list directives
// are applicable. Emit as vector of individual 8bits data elements.
if (MCTargetStreamer *TS = getTargetStreamer()) {
TS->emitRawBytes(Data);
return;
}
const char *Directive = MAI->getData8bitsDirective();
for (const unsigned char C : Data.bytes()) {
OS << Directive << (unsigned)C;
EmitEOL();
}

PrintQuotedString(Data, OS);
EmitEOL();
}

void MCAsmStreamer::emitBinaryData(StringRef Data) {
Expand Down
Loading

0 comments on commit 2aaac36

Please sign in to comment.