Skip to content

Commit e464b31

Browse files
committed
Revert "[tablegen] Emit string literals instead of char arrays"
This reverts commit ce23515. That commit broke some builds on Windows: http://lab.llvm.org:8011/builders/clang-x64-windows-msvc/builds/13870
1 parent a8c5a46 commit e464b31

File tree

6 files changed

+18
-93
lines changed

6 files changed

+18
-93
lines changed

llvm/cmake/modules/TableGen.cmake

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,6 @@ function(tablegen project ofn)
5858
endif()
5959
endif()
6060

61-
# MSVC can't support long string literals ("long" > 65534 bytes)[1], so if there's
62-
# a possibility of generated tables being consumed by MSVC, generate arrays of
63-
# char literals, instead. If we're cross-compiling, then conservatively assume
64-
# that the source might be consumed by MSVC.
65-
# [1] https://docs.microsoft.com/en-us/cpp/cpp/compiler-limits?view=vs-2017
66-
if (MSVC)
67-
list(APPEND LLVM_TABLEGEN_FLAGS "--long-string-literals=0")
68-
endif()
6961
if (CMAKE_GENERATOR MATCHES "Visual Studio")
7062
# Visual Studio has problems with llvm-tblgen's native --write-if-changed
7163
# behavior. Since it doesn't do restat optimizations anyway, just don't

llvm/utils/TableGen/AsmWriterEmitter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ void AsmWriterEmitter::EmitPrintInstruction(raw_ostream &O) {
381381

382382
// Emit the string table itself.
383383
O << " static const char AsmStrs[] = {\n";
384-
StringTable.emit_string_literals(O);
384+
StringTable.emit(O, printChar);
385385
O << " };\n\n";
386386

387387
// Emit the lookup tables in pieces to minimize wasted bytes.
@@ -538,7 +538,7 @@ emitRegisterNameString(raw_ostream &O, StringRef AltName,
538538

539539
StringTable.layout();
540540
O << " static const char AsmStrs" << AltName << "[] = {\n";
541-
StringTable.emit_string_literals(O);
541+
StringTable.emit(O, printChar);
542542
O << " };\n\n";
543543

544544
O << " static const " << getMinimalTypeForRange(StringTable.size() - 1, 32)

llvm/utils/TableGen/InstrInfoEmitter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ void InstrInfoEmitter::run(raw_ostream &OS) {
570570
// Emit the array of instruction names.
571571
InstrNames.layout();
572572
OS << "extern const char " << TargetName << "InstrNameData[] = {\n";
573-
InstrNames.emit_string_literals(OS);
573+
InstrNames.emit(OS, printChar);
574574
OS << "};\n\n";
575575

576576
OS << "extern const unsigned " << TargetName <<"InstrNameIndices[] = {";

llvm/utils/TableGen/RegisterInfoEmitter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -993,7 +993,7 @@ RegisterInfoEmitter::runMCDesc(raw_ostream &OS, CodeGenTarget &Target,
993993
// Emit the string table.
994994
RegStrings.layout();
995995
OS << "extern const char " << TargetName << "RegStrings[] = {\n";
996-
RegStrings.emit_string_literals(OS);
996+
RegStrings.emit(OS, printChar);
997997
OS << "};\n\n";
998998

999999
OS << "extern const MCRegisterDesc " << TargetName
@@ -1066,7 +1066,7 @@ RegisterInfoEmitter::runMCDesc(raw_ostream &OS, CodeGenTarget &Target,
10661066

10671067
RegClassStrings.layout();
10681068
OS << "extern const char " << TargetName << "RegClassStrings[] = {\n";
1069-
RegClassStrings.emit_string_literals(OS);
1069+
RegClassStrings.emit(OS, printChar);
10701070
OS << "};\n\n";
10711071

10721072
OS << "extern const MCRegisterClass " << TargetName

llvm/utils/TableGen/SequenceToOffsetTable.h

Lines changed: 13 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#ifndef LLVM_UTILS_TABLEGEN_SEQUENCETOOFFSETTABLE_H
1616
#define LLVM_UTILS_TABLEGEN_SEQUENCETOOFFSETTABLE_H
1717

18-
#include "llvm/Support/CommandLine.h"
1918
#include "llvm/Support/raw_ostream.h"
2019
#include <algorithm>
2120
#include <cassert>
@@ -24,61 +23,6 @@
2423
#include <map>
2524

2625
namespace llvm {
27-
extern llvm::cl::opt<bool> EmitLongStrLiterals;
28-
29-
// Helper function for SequenceToOffsetTable<string>.
30-
static inline void printStrLitEscChar(raw_ostream &OS, char C) {
31-
const char *Escapes[] = {
32-
"\\000", "\\001", "\\002", "\\003", "\\004", "\\005", "\\006", "\\007",
33-
"\\010", "\\t", "\\n", "\\013", "\\014", "\\r", "\\016", "\\017",
34-
"\\020", "\\021", "\\022", "\\023", "\\024", "\\025", "\\026", "\\027",
35-
"\\030", "\\031", "\\032", "\\033", "\\034", "\\035", "\\036", "\\037",
36-
" ", "!", "\\\"", "#", "$", "%", "&", "'",
37-
"(", ")", "*", "+", ",", "-", ".", "/",
38-
"0", "1", "2", "3", "4", "5", "6", "7",
39-
"8", "9", ":", ";", "<", "=", ">", "?",
40-
"@", "A", "B", "C", "D", "E", "F", "G",
41-
"H", "I", "J", "K", "L", "M", "N", "O",
42-
"P", "Q", "R", "S", "T", "U", "V", "W",
43-
"X", "Y", "Z", "[", "\\\\", "]", "^", "_",
44-
"`", "a", "b", "c", "d", "e", "f", "g",
45-
"h", "i", "j", "k", "l", "m", "n", "o",
46-
"p", "q", "r", "s", "t", "u", "v", "w",
47-
"x", "y", "z", "{", "|", "}", "~", "\\177",
48-
"\\200", "\\201", "\\202", "\\203", "\\204", "\\205", "\\206", "\\207",
49-
"\\210", "\\211", "\\212", "\\213", "\\214", "\\215", "\\216", "\\217",
50-
"\\220", "\\221", "\\222", "\\223", "\\224", "\\225", "\\226", "\\227",
51-
"\\230", "\\231", "\\232", "\\233", "\\234", "\\235", "\\236", "\\237",
52-
"\\240", "\\241", "\\242", "\\243", "\\244", "\\245", "\\246", "\\247",
53-
"\\250", "\\251", "\\252", "\\253", "\\254", "\\255", "\\256", "\\257",
54-
"\\260", "\\261", "\\262", "\\263", "\\264", "\\265", "\\266", "\\267",
55-
"\\270", "\\271", "\\272", "\\273", "\\274", "\\275", "\\276", "\\277",
56-
"\\300", "\\301", "\\302", "\\303", "\\304", "\\305", "\\306", "\\307",
57-
"\\310", "\\311", "\\312", "\\313", "\\314", "\\315", "\\316", "\\317",
58-
"\\320", "\\321", "\\322", "\\323", "\\324", "\\325", "\\326", "\\327",
59-
"\\330", "\\331", "\\332", "\\333", "\\334", "\\335", "\\336", "\\337",
60-
"\\340", "\\341", "\\342", "\\343", "\\344", "\\345", "\\346", "\\347",
61-
"\\350", "\\351", "\\352", "\\353", "\\354", "\\355", "\\356", "\\357",
62-
"\\360", "\\361", "\\362", "\\363", "\\364", "\\365", "\\366", "\\367",
63-
"\\370", "\\371", "\\372", "\\373", "\\374", "\\375", "\\376", "\\377"};
64-
65-
static_assert(sizeof Escapes / sizeof Escapes[0] ==
66-
std::numeric_limits<unsigned char>::max() + 1,
67-
"unsupported character type");
68-
OS << Escapes[static_cast<unsigned char>(C)];
69-
}
70-
71-
static inline void printChar(raw_ostream &OS, char C) {
72-
unsigned char UC(C);
73-
if (isalnum(UC) || ispunct(UC)) {
74-
OS << '\'';
75-
if (C == '\\' || C == '\'')
76-
OS << '\\';
77-
OS << C << '\'';
78-
} else {
79-
OS << unsigned(UC);
80-
}
81-
}
8226

8327
/// SequenceToOffsetTable - Collect a number of terminated sequences of T.
8428
/// Compute the layout of a table that contains all the sequences, possibly by
@@ -164,24 +108,6 @@ class SequenceToOffsetTable {
164108
return I->second + (I->first.size() - Seq.size());
165109
}
166110

167-
/// `emit_string_literals` - Print out the table as the body of an array
168-
/// initializer, where each element is a C string literal terminated by
169-
/// `Term`. Calls the the given `Print` function to format individual
170-
/// elements.
171-
void emit_string_literals(raw_ostream &OS) const {
172-
assert(Entries && "Call layout() before emit_string_literals()");
173-
if (!EmitLongStrLiterals) {
174-
return emit(OS, printChar, "0");
175-
}
176-
for (auto I : Seqs) {
177-
OS << " /* " << I.second << " */ \"";
178-
for (auto C: I.first) {
179-
printStrLitEscChar(OS, C);
180-
}
181-
OS << "\\0\"\n";
182-
}
183-
}
184-
185111
/// emit - Print out the table as the body of an array initializer.
186112
/// Use the Print function to print elements.
187113
void emit(raw_ostream &OS,
@@ -201,6 +127,19 @@ class SequenceToOffsetTable {
201127
}
202128
};
203129

130+
// Helper function for SequenceToOffsetTable<string>.
131+
static inline void printChar(raw_ostream &OS, char C) {
132+
unsigned char UC(C);
133+
if (isalnum(UC) || ispunct(UC)) {
134+
OS << '\'';
135+
if (C == '\\' || C == '\'')
136+
OS << '\\';
137+
OS << C << '\'';
138+
} else {
139+
OS << unsigned(UC);
140+
}
141+
}
142+
204143
} // end namespace llvm
205144

206145
#endif

llvm/utils/TableGen/TableGen.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,6 @@ namespace llvm {
6060
/// Storage for TimeRegionsOpt as a global so that backends aren't required to
6161
/// include CommandLine.h
6262
bool TimeRegions = false;
63-
cl::opt<bool> EmitLongStrLiterals(
64-
"long-string-literals",
65-
cl::desc("when emitting large string tables, prefer string literals over "
66-
"comma-separated char literals. This can be a readability and "
67-
"compile-time performance win, but upsets some compilers"),
68-
cl::Hidden, cl::init(true));
6963
} // end namespace llvm
7064

7165
namespace {

0 commit comments

Comments
 (0)