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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@47930 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/Basic/IdentifierTable.cpp b/Basic/IdentifierTable.cpp
index 45d8881..65e984a 100644
--- a/Basic/IdentifierTable.cpp
+++ b/Basic/IdentifierTable.cpp
@@ -32,9 +32,7 @@
HasMacro = false;
IsExtension = false;
IsPoisoned = false;
- IsOtherTargetMacro = false;
IsCPPOperatorKeyword = false;
- IsNonPortableBuiltin = false;
FETokenInfo = 0;
}
@@ -203,8 +201,6 @@
CASE( 8, 'u', 'a', unassert);
CASE(12, 'i', 'c', include_next);
- CASE(13, 'd', 'f', define_target);
- CASE(19, 'd', 'f', define_other_target);
#undef CASE
#undef HASH
}
@@ -406,9 +402,7 @@
S.EmitBool(hasMacroDefinition());
S.EmitBool(isExtensionToken());
S.EmitBool(isPoisoned());
- S.EmitBool(isOtherTargetMacro());
S.EmitBool(isCPlusPlusOperatorKeyword());
- S.EmitBool(isNonPortableBuiltin());
// FIXME: FETokenInfo
}
@@ -419,9 +413,7 @@
setHasMacroDefinition(D.ReadBool());
setIsExtensionToken(D.ReadBool());
setIsPoisoned(D.ReadBool());
- setIsOtherTargetMacro(D.ReadBool());
setIsCPlusPlusOperatorKeyword(D.ReadBool());
- setNonPortableBuiltin(D.ReadBool());
// FIXME: FETokenInfo
}
diff --git a/Basic/TargetInfo.cpp b/Basic/TargetInfo.cpp
index 15472a4..8701b38 100644
--- a/Basic/TargetInfo.cpp
+++ b/Basic/TargetInfo.cpp
@@ -54,167 +54,28 @@
//===----------------------------------------------------------------------===//
TargetInfo::~TargetInfo() {
- delete PrimaryTarget;
- for (unsigned i = 0; i < SecondaryTargets.size(); ++i)
- delete SecondaryTargets[i];
+ delete Target;
}
const char* TargetInfo::getTargetTriple() const {
- return PrimaryTarget->getTargetTriple();
+ return Target->getTargetTriple();
}
const char *TargetInfo::getTargetPrefix() const {
- return PrimaryTarget->getTargetPrefix();
-}
-
-/// DiagnoseNonPortability - When a use of a non-portable target feature is
-/// used, this method emits the diagnostic and marks the translation unit as
-/// non-portable.
-void TargetInfo::DiagnoseNonPortability(FullSourceLoc Loc,
- unsigned DiagKind) {
- NonPortable = true;
- if (Diag && Loc.isValid()) Diag->Report(Loc, DiagKind);
-}
-
-/// GetTargetDefineMap - Get the set of target #defines in an associative
-/// collection for easy lookup.
-static void GetTargetDefineMap(const TargetInfoImpl *Target,
- llvm::StringMap<std::string> &Map) {
- std::vector<char> Defines;
- Defines.reserve(4096);
- Target->getTargetDefines(Defines);
-
- for (const char *DefStr = &Defines[0], *E = DefStr+Defines.size();
- DefStr != E;) {
- // Skip the '#define ' portion.
- assert(memcmp(DefStr, "#define ", strlen("#define ")) == 0 &&
- "#define didn't start with #define!");
- DefStr += strlen("#define ");
-
- // Find the divider between the key and value.
- const char *SpacePos = strchr(DefStr, ' ');
-
- std::string &Entry = Map.GetOrCreateValue(DefStr, SpacePos).getValue();
-
- const char *EndPos = strchr(SpacePos+1, '\n');
- Entry = std::string(SpacePos+1, EndPos);
- DefStr = EndPos+1;
- }
+ return Target->getTargetPrefix();
}
/// getTargetDefines - Appends the target-specific #define values for this
/// target set to the specified buffer.
void TargetInfo::getTargetDefines(std::vector<char> &Buffer) {
- // If we have no secondary targets, be a bit more efficient.
- if (SecondaryTargets.empty()) {
- PrimaryTarget->getTargetDefines(Buffer);
- return;
- }
-
- // This is tricky in the face of secondary targets. Specifically,
- // target-specific #defines that are present and identical across all
- // secondary targets are turned into #defines, #defines that are present in
- // the primary target but are missing or different in the secondary targets
- // are turned into #define_target, and #defines that are not defined in the
- // primary, but are defined in a secondary are turned into
- // #define_other_target. This allows the preprocessor to correctly track uses
- // of target-specific macros.
-
- // Get the set of primary #defines.
- llvm::StringMap<std::string> PrimaryDefines;
- GetTargetDefineMap(PrimaryTarget, PrimaryDefines);
-
- // Get the sets of secondary #defines.
- llvm::StringMap<std::string> *SecondaryDefines
- = new llvm::StringMap<std::string>[SecondaryTargets.size()];
- for (unsigned i = 0, e = SecondaryTargets.size(); i != e; ++i)
- GetTargetDefineMap(SecondaryTargets[i], SecondaryDefines[i]);
-
- // Loop over all defines in the primary target, processing them until we run
- // out.
- for (llvm::StringMap<std::string>::iterator PDI =
- PrimaryDefines.begin(), E = PrimaryDefines.end(); PDI != E; ++PDI) {
- std::string DefineName(PDI->getKeyData(),
- PDI->getKeyData() + PDI->getKeyLength());
- std::string DefineValue = PDI->getValue();
-
- // Check to see whether all secondary targets have this #define and whether
- // it is to the same value. Remember if not, but remove the #define from
- // their collection in any case if they have it.
- bool isPortable = true;
-
- for (unsigned i = 0, e = SecondaryTargets.size(); i != e; ++i) {
- llvm::StringMap<std::string>::iterator I =
- SecondaryDefines[i].find(&DefineName[0],
- &DefineName[0]+DefineName.size());
- if (I == SecondaryDefines[i].end()) {
- // Secondary target doesn't have this #define.
- isPortable = false;
- } else {
- // Secondary target has this define, remember if it disagrees.
- if (isPortable)
- isPortable = I->getValue() == DefineValue;
- // Remove it from the secondary target unconditionally.
- SecondaryDefines[i].erase(I);
- }
- }
-
- // If this define is non-portable, turn it into #define_target, otherwise
- // just use #define.
- const char *Command = isPortable ? "#define " : "#define_target ";
- Buffer.insert(Buffer.end(), Command, Command+strlen(Command));
-
- // Insert "defname defvalue\n".
- Buffer.insert(Buffer.end(), DefineName.begin(), DefineName.end());
- Buffer.push_back(' ');
- Buffer.insert(Buffer.end(), DefineValue.begin(), DefineValue.end());
- Buffer.push_back('\n');
- }
-
- // Now that all of the primary target's defines have been handled and removed
- // from the secondary target's define sets, go through the remaining secondary
- // target's #defines and taint them.
- for (unsigned i = 0, e = SecondaryTargets.size(); i != e; ++i) {
- llvm::StringMap<std::string> &Defs = SecondaryDefines[i];
- while (!Defs.empty()) {
- const char *DefStart = Defs.begin()->getKeyData();
- const char *DefEnd = DefStart + Defs.begin()->getKeyLength();
-
- // Insert "#define_other_target defname".
- const char *Command = "#define_other_target ";
- Buffer.insert(Buffer.end(), Command, Command+strlen(Command));
- Buffer.insert(Buffer.end(), DefStart, DefEnd);
- Buffer.push_back('\n');
-
- // If any other secondary targets have this same define, remove it from
- // them to avoid duplicate #define_other_target directives.
- for (unsigned j = i+1; j != e; ++j) {
- llvm::StringMap<std::string>::iterator I =
- SecondaryDefines[j].find(DefStart, DefEnd);
- if (I != SecondaryDefines[j].end())
- SecondaryDefines[j].erase(I);
- }
- Defs.erase(Defs.begin());
- }
- }
-
- delete[] SecondaryDefines;
+ Target->getTargetDefines(Buffer);
}
/// ComputeWCharWidth - Determine the width of the wchar_t type for the primary
/// target, diagnosing whether this is non-portable across the secondary
/// targets.
void TargetInfo::ComputeWCharInfo(FullSourceLoc Loc) {
- PrimaryTarget->getWCharInfo(WCharWidth, WCharAlign);
-
- // Check whether this is portable across the secondary targets if the T-U is
- // portable so far.
- for (unsigned i = 0, e = SecondaryTargets.size(); i != e; ++i) {
- unsigned Width, Align;
- SecondaryTargets[i]->getWCharInfo(Width, Align);
- if (Width != WCharWidth || Align != WCharAlign)
- return DiagnoseNonPortability(Loc, diag::port_wchar_t);
- }
+ Target->getWCharInfo(WCharWidth, WCharAlign);
}
@@ -222,69 +83,18 @@
/// the current primary target, and info about which builtins are non-portable
/// across the current set of primary and secondary targets.
void TargetInfo::getTargetBuiltins(const Builtin::Info *&Records,
- unsigned &NumRecords,
- std::vector<const char *> &NPortable) const {
+ unsigned &NumRecords) const {
// Get info about what actual builtins we will expose.
- PrimaryTarget->getTargetBuiltins(Records, NumRecords);
- if (SecondaryTargets.empty()) return;
-
- // Compute the set of non-portable builtins.
-
- // Start by computing a mapping from the primary target's builtins to their
- // info records for efficient lookup.
- llvm::StringMap<const Builtin::Info*> PrimaryRecs;
- for (unsigned i = 0, e = NumRecords; i != e; ++i) {
- const char *BIName = Records[i].Name;
- PrimaryRecs.GetOrCreateValue(BIName, BIName+strlen(BIName)).getValue()
- = Records+i;
- }
-
- for (unsigned i = 0, e = SecondaryTargets.size(); i != e; ++i) {
- // Get the builtins for this secondary target.
- const Builtin::Info *Records2nd;
- unsigned NumRecords2nd;
- SecondaryTargets[i]->getTargetBuiltins(Records2nd, NumRecords2nd);
-
- // Remember all of the secondary builtin names.
- std::set<std::string> BuiltinNames2nd;
-
- for (unsigned j = 0, e = NumRecords2nd; j != e; ++j) {
- BuiltinNames2nd.insert(Records2nd[j].Name);
-
- // Check to see if the primary target has this builtin.
- llvm::StringMap<const Builtin::Info*>::iterator I =
- PrimaryRecs.find(Records2nd[j].Name,
- Records2nd[j].Name+strlen(Records2nd[j].Name));
- if (I != PrimaryRecs.end()) {
- const Builtin::Info *PrimBI = I->getValue();
- // If does. If they are not identical, mark the builtin as being
- // non-portable.
- if (Records2nd[j] != *PrimBI)
- NPortable.push_back(PrimBI->Name);
- } else {
- // The primary target doesn't have this, it is non-portable.
- NPortable.push_back(Records2nd[j].Name);
- }
- }
-
- // Now that we checked all the secondary builtins, check to see if the
- // primary target has any builtins that the secondary one doesn't. If so,
- // then those are non-portable.
- for (unsigned j = 0, e = NumRecords; j != e; ++j) {
- if (!BuiltinNames2nd.count(Records[j].Name))
- NPortable.push_back(Records[j].Name);
- }
- }
+ Target->getTargetBuiltins(Records, NumRecords);
}
/// getVAListDeclaration - Return the declaration to use for
/// __builtin_va_list, which is target-specific.
const char *TargetInfo::getVAListDeclaration() const {
- return PrimaryTarget->getVAListDeclaration();
+ return Target->getVAListDeclaration();
}
-static void removeGCCRegisterPrefix(const char *&Name)
-{
+static void removeGCCRegisterPrefix(const char *&Name) {
if (Name[0] == '%' || Name[0] == '#')
Name++;
}
@@ -304,7 +114,7 @@
strcmp(Name, "cc") == 0)
return true;
- PrimaryTarget->getGCCRegNames(Names, NumNames);
+ Target->getGCCRegNames(Names, NumNames);
// If we have a number it maps to an entry in the register name array.
if (isdigit(Name[0])) {
@@ -324,7 +134,7 @@
const TargetInfoImpl::GCCRegAlias *Aliases;
unsigned NumAliases;
- PrimaryTarget->getGCCRegAliases(Aliases, NumAliases);
+ Target->getGCCRegAliases(Aliases, NumAliases);
for (unsigned i = 0; i < NumAliases; i++) {
for (unsigned j = 0 ; j < llvm::array_lengthof(Aliases[i].Aliases); j++) {
if (!Aliases[i].Aliases[j])
@@ -346,7 +156,7 @@
const char * const *Names;
unsigned NumNames;
- PrimaryTarget->getGCCRegNames(Names, NumNames);
+ Target->getGCCRegNames(Names, NumNames);
// First, check if we have a number.
if (isdigit(Name[0])) {
@@ -363,7 +173,7 @@
const TargetInfoImpl::GCCRegAlias *Aliases;
unsigned NumAliases;
- PrimaryTarget->getGCCRegAliases(Aliases, NumAliases);
+ Target->getGCCRegAliases(Aliases, NumAliases);
for (unsigned i = 0; i < NumAliases; i++) {
for (unsigned j = 0 ; j < llvm::array_lengthof(Aliases[i].Aliases); j++) {
if (!Aliases[i].Aliases[j])
@@ -392,7 +202,7 @@
while (*Name) {
switch (*Name) {
default:
- if (!PrimaryTarget->validateAsmConstraint(*Name, info)) {
+ if (!Target->validateAsmConstraint(*Name, info)) {
// FIXME: This assert is in place temporarily
// so we can add more constraints as we hit it.
// Eventually, an unknown constraint should just be treated as 'g'.
@@ -431,7 +241,7 @@
// Check if matching constraint is out of bounds.
if (i >= NumOutputs)
return false;
- } else if (!PrimaryTarget->validateAsmConstraint(*Name, info)) {
+ } else if (!Target->validateAsmConstraint(*Name, info)) {
// FIXME: This assert is in place temporarily
// so we can add more constraints as we hit it.
// Eventually, an unknown constraint should just be treated as 'g'.
@@ -461,12 +271,11 @@
}
std::string TargetInfo::convertConstraint(const char Constraint) const {
- return PrimaryTarget->convertConstraint(Constraint);
+ return Target->convertConstraint(Constraint);
}
-const char *TargetInfo::getClobbers() const
-{
- return PrimaryTarget->getClobbers();
+const char *TargetInfo::getClobbers() const {
+ return Target->getClobbers();
}
diff --git a/Basic/Targets.cpp b/Basic/Targets.cpp
index 7d64942..d170fbe 100644
--- a/Basic/Targets.cpp
+++ b/Basic/Targets.cpp
@@ -776,54 +776,27 @@
TT[4] == '-' && TT[1] - '3' < 6);
}
-/// CreateTarget - Create the TargetInfoImpl object for the specified target
-/// enum value.
-static TargetInfoImpl *CreateTarget(const std::string& T) {
+/// CreateTargetInfo - Return the target info object for the specified target
+/// triple.
+TargetInfo* TargetInfo::CreateTargetInfo(const std::string &T) {
if (T.find("ppc-") == 0 || T.find("powerpc-") == 0)
- return new DarwinPPCTargetInfo(T);
- else if (T.find("ppc64-") == 0 || T.find("powerpc64-") == 0)
- return new DarwinPPC64TargetInfo(T);
- else if (T.find("sparc-") == 0)
- return new SolarisSparcV8TargetInfo(T); // ugly hack
- else if (T.find("x86_64-") == 0)
- return new DarwinX86_64TargetInfo(T);
- else if (IsX86(T))
- return new DarwinI386TargetInfo(T);
- else if (T.find("bogusW16W16-") == 0) // For testing portability.
- return new LinuxTargetInfo(T);
- else
- return NULL;
-}
-
-/// CreateTargetInfo - Return the set of target info objects as specified by
-/// the -arch command line option.
-TargetInfo* TargetInfo::CreateTargetInfo(const std::string* TriplesStart,
- const std::string* TriplesEnd,
- Diagnostic *Diags) {
-
- // Create the primary target and target info.
- TargetInfoImpl* PrimaryTarget = CreateTarget(*TriplesStart);
-
- if (!PrimaryTarget)
- return NULL;
+ return new TargetInfo(new DarwinPPCTargetInfo(T));
- TargetInfo *TI = new TargetInfo(PrimaryTarget, Diags);
+ if (T.find("ppc64-") == 0 || T.find("powerpc64-") == 0)
+ return new TargetInfo(new DarwinPPC64TargetInfo(T));
- // Add all secondary targets.
- for (const std::string* I=TriplesStart+1; I != TriplesEnd; ++I) {
- TargetInfoImpl* SecondaryTarget = CreateTarget(*I);
-
- if (!SecondaryTarget) {
- fprintf (stderr,
- "Warning: secondary target '%s' unrecognized.\n",
- I->c_str());
-
- continue;
- }
-
- TI->AddSecondaryTarget(SecondaryTarget);
- }
+ if (T.find("sparc-") == 0)
+ return new TargetInfo(new SolarisSparcV8TargetInfo(T)); // ugly hack
- return TI;
+ if (T.find("x86_64-") == 0)
+ return new TargetInfo(new DarwinX86_64TargetInfo(T));
+
+ if (IsX86(T))
+ return new TargetInfo(new DarwinI386TargetInfo(T));
+
+ if (T.find("bogusW16W16-") == 0) // For testing portability.
+ return new TargetInfo(new LinuxTargetInfo(T));
+
+ return NULL;
}