Skip to content

Commit 855d024

Browse files
committed
Remove the first layer of support for "portability" warnings. This is
theoretically useful, but not useful in practice. It adds a bunch of complexity, and not much value. It's best to nuke it. One big advantage is that it means the target interfaces will soon lose their SLoc arguments and target queries can never emit diagnostics anymore (yay). Removing this also simplifies some of the core preprocessor which should make it slightly faster. Ted, I didn't simplify TripleProcessor, which can now have at most one triple, and can probably just be removed. Please poke at it when you have time. llvm-svn: 47930
1 parent 357061a commit 855d024

File tree

18 files changed

+60
-620
lines changed

18 files changed

+60
-620
lines changed

clang/AST/Builtins.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,12 @@ void Builtin::Context::InitializeBuiltins(IdentifierTable &Table,
4040
for (unsigned i = Builtin::NotBuiltin+1; i != Builtin::FirstTSBuiltin; ++i)
4141
Table.get(BuiltinInfo[i].Name).setBuiltinID(i);
4242

43-
// Step #2: handle target builtins.
44-
std::vector<const char *> NonPortableBuiltins;
45-
Target.getTargetBuiltins(TSRecords, NumTSRecords, NonPortableBuiltins);
43+
// Step #2: Get target builtins.
44+
Target.getTargetBuiltins(TSRecords, NumTSRecords);
4645

47-
// Step #2a: Register target-specific builtins.
46+
// Step #3: Register target-specific builtins.
4847
for (unsigned i = 0, e = NumTSRecords; i != e; ++i)
4948
Table.get(TSRecords[i].Name).setBuiltinID(i+Builtin::FirstTSBuiltin);
50-
51-
// Step #2b: Mark non-portable builtins as such.
52-
for (unsigned i = 0, e = NonPortableBuiltins.size(); i != e; ++i)
53-
Table.get(NonPortableBuiltins[i]).setNonPortableBuiltin(true);
5449
}
5550

5651
/// DecodeTypeFromStr - This decodes one type descriptor from Str, advancing the

clang/AST/TranslationUnit.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,7 @@ TranslationUnit* TranslationUnit::Create(llvm::Deserializer& Dezr,
191191
{ // Read the TargetInfo.
192192
llvm::SerializedPtrID PtrID = Dezr.ReadPtrID();
193193
char* triple = Dezr.ReadCStr(NULL,0,true);
194-
std::string Triple(triple);
195-
Dezr.RegisterPtr(PtrID,TargetInfo::CreateTargetInfo(&Triple,
196-
&Triple+1));
194+
Dezr.RegisterPtr(PtrID,TargetInfo::CreateTargetInfo(std::string(triple)));
197195
delete [] triple;
198196
}
199197

clang/Basic/IdentifierTable.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@ IdentifierInfo::IdentifierInfo() {
3232
HasMacro = false;
3333
IsExtension = false;
3434
IsPoisoned = false;
35-
IsOtherTargetMacro = false;
3635
IsCPPOperatorKeyword = false;
37-
IsNonPortableBuiltin = false;
3836
FETokenInfo = 0;
3937
}
4038

@@ -203,8 +201,6 @@ tok::PPKeywordKind IdentifierInfo::getPPKeywordID() const {
203201

204202
CASE( 8, 'u', 'a', unassert);
205203
CASE(12, 'i', 'c', include_next);
206-
CASE(13, 'd', 'f', define_target);
207-
CASE(19, 'd', 'f', define_other_target);
208204
#undef CASE
209205
#undef HASH
210206
}
@@ -406,9 +402,7 @@ void IdentifierInfo::Emit(llvm::Serializer& S) const {
406402
S.EmitBool(hasMacroDefinition());
407403
S.EmitBool(isExtensionToken());
408404
S.EmitBool(isPoisoned());
409-
S.EmitBool(isOtherTargetMacro());
410405
S.EmitBool(isCPlusPlusOperatorKeyword());
411-
S.EmitBool(isNonPortableBuiltin());
412406
// FIXME: FETokenInfo
413407
}
414408

@@ -419,9 +413,7 @@ void IdentifierInfo::Read(llvm::Deserializer& D) {
419413
setHasMacroDefinition(D.ReadBool());
420414
setIsExtensionToken(D.ReadBool());
421415
setIsPoisoned(D.ReadBool());
422-
setIsOtherTargetMacro(D.ReadBool());
423416
setIsCPlusPlusOperatorKeyword(D.ReadBool());
424-
setNonPortableBuiltin(D.ReadBool());
425417
// FIXME: FETokenInfo
426418
}
427419

clang/Basic/TargetInfo.cpp

Lines changed: 18 additions & 209 deletions
Original file line numberDiff line numberDiff line change
@@ -54,237 +54,47 @@ void TargetInfo::getLongDoubleInfo(uint64_t &Size, unsigned &Align,
5454
//===----------------------------------------------------------------------===//
5555

5656
TargetInfo::~TargetInfo() {
57-
delete PrimaryTarget;
58-
for (unsigned i = 0; i < SecondaryTargets.size(); ++i)
59-
delete SecondaryTargets[i];
57+
delete Target;
6058
}
6159

6260
const char* TargetInfo::getTargetTriple() const {
63-
return PrimaryTarget->getTargetTriple();
61+
return Target->getTargetTriple();
6462
}
6563

6664
const char *TargetInfo::getTargetPrefix() const {
67-
return PrimaryTarget->getTargetPrefix();
68-
}
69-
70-
/// DiagnoseNonPortability - When a use of a non-portable target feature is
71-
/// used, this method emits the diagnostic and marks the translation unit as
72-
/// non-portable.
73-
void TargetInfo::DiagnoseNonPortability(FullSourceLoc Loc,
74-
unsigned DiagKind) {
75-
NonPortable = true;
76-
if (Diag && Loc.isValid()) Diag->Report(Loc, DiagKind);
77-
}
78-
79-
/// GetTargetDefineMap - Get the set of target #defines in an associative
80-
/// collection for easy lookup.
81-
static void GetTargetDefineMap(const TargetInfoImpl *Target,
82-
llvm::StringMap<std::string> &Map) {
83-
std::vector<char> Defines;
84-
Defines.reserve(4096);
85-
Target->getTargetDefines(Defines);
86-
87-
for (const char *DefStr = &Defines[0], *E = DefStr+Defines.size();
88-
DefStr != E;) {
89-
// Skip the '#define ' portion.
90-
assert(memcmp(DefStr, "#define ", strlen("#define ")) == 0 &&
91-
"#define didn't start with #define!");
92-
DefStr += strlen("#define ");
93-
94-
// Find the divider between the key and value.
95-
const char *SpacePos = strchr(DefStr, ' ');
96-
97-
std::string &Entry = Map.GetOrCreateValue(DefStr, SpacePos).getValue();
98-
99-
const char *EndPos = strchr(SpacePos+1, '\n');
100-
Entry = std::string(SpacePos+1, EndPos);
101-
DefStr = EndPos+1;
102-
}
65+
return Target->getTargetPrefix();
10366
}
10467

10568
/// getTargetDefines - Appends the target-specific #define values for this
10669
/// target set to the specified buffer.
10770
void TargetInfo::getTargetDefines(std::vector<char> &Buffer) {
108-
// If we have no secondary targets, be a bit more efficient.
109-
if (SecondaryTargets.empty()) {
110-
PrimaryTarget->getTargetDefines(Buffer);
111-
return;
112-
}
113-
114-
// This is tricky in the face of secondary targets. Specifically,
115-
// target-specific #defines that are present and identical across all
116-
// secondary targets are turned into #defines, #defines that are present in
117-
// the primary target but are missing or different in the secondary targets
118-
// are turned into #define_target, and #defines that are not defined in the
119-
// primary, but are defined in a secondary are turned into
120-
// #define_other_target. This allows the preprocessor to correctly track uses
121-
// of target-specific macros.
122-
123-
// Get the set of primary #defines.
124-
llvm::StringMap<std::string> PrimaryDefines;
125-
GetTargetDefineMap(PrimaryTarget, PrimaryDefines);
126-
127-
// Get the sets of secondary #defines.
128-
llvm::StringMap<std::string> *SecondaryDefines
129-
= new llvm::StringMap<std::string>[SecondaryTargets.size()];
130-
for (unsigned i = 0, e = SecondaryTargets.size(); i != e; ++i)
131-
GetTargetDefineMap(SecondaryTargets[i], SecondaryDefines[i]);
132-
133-
// Loop over all defines in the primary target, processing them until we run
134-
// out.
135-
for (llvm::StringMap<std::string>::iterator PDI =
136-
PrimaryDefines.begin(), E = PrimaryDefines.end(); PDI != E; ++PDI) {
137-
std::string DefineName(PDI->getKeyData(),
138-
PDI->getKeyData() + PDI->getKeyLength());
139-
std::string DefineValue = PDI->getValue();
140-
141-
// Check to see whether all secondary targets have this #define and whether
142-
// it is to the same value. Remember if not, but remove the #define from
143-
// their collection in any case if they have it.
144-
bool isPortable = true;
145-
146-
for (unsigned i = 0, e = SecondaryTargets.size(); i != e; ++i) {
147-
llvm::StringMap<std::string>::iterator I =
148-
SecondaryDefines[i].find(&DefineName[0],
149-
&DefineName[0]+DefineName.size());
150-
if (I == SecondaryDefines[i].end()) {
151-
// Secondary target doesn't have this #define.
152-
isPortable = false;
153-
} else {
154-
// Secondary target has this define, remember if it disagrees.
155-
if (isPortable)
156-
isPortable = I->getValue() == DefineValue;
157-
// Remove it from the secondary target unconditionally.
158-
SecondaryDefines[i].erase(I);
159-
}
160-
}
161-
162-
// If this define is non-portable, turn it into #define_target, otherwise
163-
// just use #define.
164-
const char *Command = isPortable ? "#define " : "#define_target ";
165-
Buffer.insert(Buffer.end(), Command, Command+strlen(Command));
166-
167-
// Insert "defname defvalue\n".
168-
Buffer.insert(Buffer.end(), DefineName.begin(), DefineName.end());
169-
Buffer.push_back(' ');
170-
Buffer.insert(Buffer.end(), DefineValue.begin(), DefineValue.end());
171-
Buffer.push_back('\n');
172-
}
173-
174-
// Now that all of the primary target's defines have been handled and removed
175-
// from the secondary target's define sets, go through the remaining secondary
176-
// target's #defines and taint them.
177-
for (unsigned i = 0, e = SecondaryTargets.size(); i != e; ++i) {
178-
llvm::StringMap<std::string> &Defs = SecondaryDefines[i];
179-
while (!Defs.empty()) {
180-
const char *DefStart = Defs.begin()->getKeyData();
181-
const char *DefEnd = DefStart + Defs.begin()->getKeyLength();
182-
183-
// Insert "#define_other_target defname".
184-
const char *Command = "#define_other_target ";
185-
Buffer.insert(Buffer.end(), Command, Command+strlen(Command));
186-
Buffer.insert(Buffer.end(), DefStart, DefEnd);
187-
Buffer.push_back('\n');
188-
189-
// If any other secondary targets have this same define, remove it from
190-
// them to avoid duplicate #define_other_target directives.
191-
for (unsigned j = i+1; j != e; ++j) {
192-
llvm::StringMap<std::string>::iterator I =
193-
SecondaryDefines[j].find(DefStart, DefEnd);
194-
if (I != SecondaryDefines[j].end())
195-
SecondaryDefines[j].erase(I);
196-
}
197-
Defs.erase(Defs.begin());
198-
}
199-
}
200-
201-
delete[] SecondaryDefines;
71+
Target->getTargetDefines(Buffer);
20272
}
20373

20474
/// ComputeWCharWidth - Determine the width of the wchar_t type for the primary
20575
/// target, diagnosing whether this is non-portable across the secondary
20676
/// targets.
20777
void TargetInfo::ComputeWCharInfo(FullSourceLoc Loc) {
208-
PrimaryTarget->getWCharInfo(WCharWidth, WCharAlign);
209-
210-
// Check whether this is portable across the secondary targets if the T-U is
211-
// portable so far.
212-
for (unsigned i = 0, e = SecondaryTargets.size(); i != e; ++i) {
213-
unsigned Width, Align;
214-
SecondaryTargets[i]->getWCharInfo(Width, Align);
215-
if (Width != WCharWidth || Align != WCharAlign)
216-
return DiagnoseNonPortability(Loc, diag::port_wchar_t);
217-
}
78+
Target->getWCharInfo(WCharWidth, WCharAlign);
21879
}
21980

22081

22182
/// getTargetBuiltins - Return information about target-specific builtins for
22283
/// the current primary target, and info about which builtins are non-portable
22384
/// across the current set of primary and secondary targets.
22485
void TargetInfo::getTargetBuiltins(const Builtin::Info *&Records,
225-
unsigned &NumRecords,
226-
std::vector<const char *> &NPortable) const {
86+
unsigned &NumRecords) const {
22787
// Get info about what actual builtins we will expose.
228-
PrimaryTarget->getTargetBuiltins(Records, NumRecords);
229-
if (SecondaryTargets.empty()) return;
230-
231-
// Compute the set of non-portable builtins.
232-
233-
// Start by computing a mapping from the primary target's builtins to their
234-
// info records for efficient lookup.
235-
llvm::StringMap<const Builtin::Info*> PrimaryRecs;
236-
for (unsigned i = 0, e = NumRecords; i != e; ++i) {
237-
const char *BIName = Records[i].Name;
238-
PrimaryRecs.GetOrCreateValue(BIName, BIName+strlen(BIName)).getValue()
239-
= Records+i;
240-
}
241-
242-
for (unsigned i = 0, e = SecondaryTargets.size(); i != e; ++i) {
243-
// Get the builtins for this secondary target.
244-
const Builtin::Info *Records2nd;
245-
unsigned NumRecords2nd;
246-
SecondaryTargets[i]->getTargetBuiltins(Records2nd, NumRecords2nd);
247-
248-
// Remember all of the secondary builtin names.
249-
std::set<std::string> BuiltinNames2nd;
250-
251-
for (unsigned j = 0, e = NumRecords2nd; j != e; ++j) {
252-
BuiltinNames2nd.insert(Records2nd[j].Name);
253-
254-
// Check to see if the primary target has this builtin.
255-
llvm::StringMap<const Builtin::Info*>::iterator I =
256-
PrimaryRecs.find(Records2nd[j].Name,
257-
Records2nd[j].Name+strlen(Records2nd[j].Name));
258-
if (I != PrimaryRecs.end()) {
259-
const Builtin::Info *PrimBI = I->getValue();
260-
// If does. If they are not identical, mark the builtin as being
261-
// non-portable.
262-
if (Records2nd[j] != *PrimBI)
263-
NPortable.push_back(PrimBI->Name);
264-
} else {
265-
// The primary target doesn't have this, it is non-portable.
266-
NPortable.push_back(Records2nd[j].Name);
267-
}
268-
}
269-
270-
// Now that we checked all the secondary builtins, check to see if the
271-
// primary target has any builtins that the secondary one doesn't. If so,
272-
// then those are non-portable.
273-
for (unsigned j = 0, e = NumRecords; j != e; ++j) {
274-
if (!BuiltinNames2nd.count(Records[j].Name))
275-
NPortable.push_back(Records[j].Name);
276-
}
277-
}
88+
Target->getTargetBuiltins(Records, NumRecords);
27889
}
27990

28091
/// getVAListDeclaration - Return the declaration to use for
28192
/// __builtin_va_list, which is target-specific.
28293
const char *TargetInfo::getVAListDeclaration() const {
283-
return PrimaryTarget->getVAListDeclaration();
94+
return Target->getVAListDeclaration();
28495
}
28596

286-
static void removeGCCRegisterPrefix(const char *&Name)
287-
{
97+
static void removeGCCRegisterPrefix(const char *&Name) {
28898
if (Name[0] == '%' || Name[0] == '#')
28999
Name++;
290100
}
@@ -304,7 +114,7 @@ bool TargetInfo::isValidGCCRegisterName(const char *Name) const {
304114
strcmp(Name, "cc") == 0)
305115
return true;
306116

307-
PrimaryTarget->getGCCRegNames(Names, NumNames);
117+
Target->getGCCRegNames(Names, NumNames);
308118

309119
// If we have a number it maps to an entry in the register name array.
310120
if (isdigit(Name[0])) {
@@ -324,7 +134,7 @@ bool TargetInfo::isValidGCCRegisterName(const char *Name) const {
324134
const TargetInfoImpl::GCCRegAlias *Aliases;
325135
unsigned NumAliases;
326136

327-
PrimaryTarget->getGCCRegAliases(Aliases, NumAliases);
137+
Target->getGCCRegAliases(Aliases, NumAliases);
328138
for (unsigned i = 0; i < NumAliases; i++) {
329139
for (unsigned j = 0 ; j < llvm::array_lengthof(Aliases[i].Aliases); j++) {
330140
if (!Aliases[i].Aliases[j])
@@ -346,7 +156,7 @@ const char *TargetInfo::getNormalizedGCCRegisterName(const char *Name) const
346156
const char * const *Names;
347157
unsigned NumNames;
348158

349-
PrimaryTarget->getGCCRegNames(Names, NumNames);
159+
Target->getGCCRegNames(Names, NumNames);
350160

351161
// First, check if we have a number.
352162
if (isdigit(Name[0])) {
@@ -363,7 +173,7 @@ const char *TargetInfo::getNormalizedGCCRegisterName(const char *Name) const
363173
const TargetInfoImpl::GCCRegAlias *Aliases;
364174
unsigned NumAliases;
365175

366-
PrimaryTarget->getGCCRegAliases(Aliases, NumAliases);
176+
Target->getGCCRegAliases(Aliases, NumAliases);
367177
for (unsigned i = 0; i < NumAliases; i++) {
368178
for (unsigned j = 0 ; j < llvm::array_lengthof(Aliases[i].Aliases); j++) {
369179
if (!Aliases[i].Aliases[j])
@@ -392,7 +202,7 @@ bool TargetInfo::validateOutputConstraint(const char *Name,
392202
while (*Name) {
393203
switch (*Name) {
394204
default:
395-
if (!PrimaryTarget->validateAsmConstraint(*Name, info)) {
205+
if (!Target->validateAsmConstraint(*Name, info)) {
396206
// FIXME: This assert is in place temporarily
397207
// so we can add more constraints as we hit it.
398208
// Eventually, an unknown constraint should just be treated as 'g'.
@@ -431,7 +241,7 @@ bool TargetInfo::validateInputConstraint(const char *Name,
431241
// Check if matching constraint is out of bounds.
432242
if (i >= NumOutputs)
433243
return false;
434-
} else if (!PrimaryTarget->validateAsmConstraint(*Name, info)) {
244+
} else if (!Target->validateAsmConstraint(*Name, info)) {
435245
// FIXME: This assert is in place temporarily
436246
// so we can add more constraints as we hit it.
437247
// Eventually, an unknown constraint should just be treated as 'g'.
@@ -461,12 +271,11 @@ bool TargetInfo::validateInputConstraint(const char *Name,
461271
}
462272

463273
std::string TargetInfo::convertConstraint(const char Constraint) const {
464-
return PrimaryTarget->convertConstraint(Constraint);
274+
return Target->convertConstraint(Constraint);
465275
}
466276

467-
const char *TargetInfo::getClobbers() const
468-
{
469-
return PrimaryTarget->getClobbers();
277+
const char *TargetInfo::getClobbers() const {
278+
return Target->getClobbers();
470279
}
471280

472281

0 commit comments

Comments
 (0)