diff options
Diffstat (limited to 'llvm')
-rw-r--r-- | llvm/include/llvm/TableGen/CodeGenHelpers.h | 67 | ||||
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineAtomicRMW.cpp | 6 | ||||
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstructionCombining.cpp | 6 | ||||
-rw-r--r-- | llvm/utils/TableGen/Basic/DirectiveEmitter.cpp | 73 | ||||
-rw-r--r-- | llvm/utils/TableGen/Basic/TargetFeaturesEmitter.cpp | 36 | ||||
-rw-r--r-- | llvm/utils/TableGen/CompressInstEmitter.cpp | 2 |
6 files changed, 107 insertions, 83 deletions
diff --git a/llvm/include/llvm/TableGen/CodeGenHelpers.h b/llvm/include/llvm/TableGen/CodeGenHelpers.h new file mode 100644 index 0000000..7dca6a0 --- /dev/null +++ b/llvm/include/llvm/TableGen/CodeGenHelpers.h @@ -0,0 +1,67 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This file defines common utilities for generating C++ code. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_TABLEGEN_CODEGENHELPERS_H +#define LLVM_TABLEGEN_CODEGENHELPERS_H + +#include "llvm/ADT/STLExtras.h" +#include "llvm/ADT/StringExtras.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/Support/raw_ostream.h" +#include <string> + +namespace llvm { +// Simple RAII helper for emitting ifdef-undef-endif scope. +class IfDefEmitter { +public: + IfDefEmitter(raw_ostream &OS, StringRef Name) : Name(Name.str()), OS(OS) { + OS << "#ifdef " << Name << "\n" + << "#undef " << Name << "\n\n"; + } + ~IfDefEmitter() { OS << "\n#endif // " << Name << "\n\n"; } + +private: + std::string Name; + raw_ostream &OS; +}; + +// Simple RAII helper for emitting namespace scope. Name can be a single +// namespace (empty for anonymous namespace) or nested namespace. +class NamespaceEmitter { +public: + NamespaceEmitter(raw_ostream &OS, StringRef Name) : OS(OS) { + emitNamespaceStarts(Name); + } + + ~NamespaceEmitter() { close(); } + + // Explicit function to close the namespace scopes. + void close() { + for (StringRef NS : llvm::reverse(Namespaces)) + OS << "} // namespace " << NS << "\n"; + Namespaces.clear(); + } + +private: + void emitNamespaceStarts(StringRef Name) { + llvm::SplitString(Name, Namespaces, "::"); + for (StringRef NS : Namespaces) + OS << "namespace " << NS << " {\n"; + } + + SmallVector<StringRef, 2> Namespaces; + raw_ostream &OS; +}; + +} // end namespace llvm + +#endif // LLVM_TABLEGEN_CODEGENHELPERS_H diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAtomicRMW.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAtomicRMW.cpp index cba282c..a2e8c69 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineAtomicRMW.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineAtomicRMW.cpp @@ -15,13 +15,12 @@ using namespace llvm; -namespace { /// Return true if and only if the given instruction does not modify the memory /// location referenced. Note that an idemptent atomicrmw may still have /// ordering effects on nearby instructions, or be volatile. /// TODO: Common w/ the version in AtomicExpandPass, and change the term used. /// Idemptotent is confusing in this context. -bool isIdempotentRMW(AtomicRMWInst& RMWI) { +static bool isIdempotentRMW(AtomicRMWInst &RMWI) { if (auto CF = dyn_cast<ConstantFP>(RMWI.getValOperand())) switch(RMWI.getOperation()) { case AtomicRMWInst::FAdd: // -0.0 @@ -59,7 +58,7 @@ bool isIdempotentRMW(AtomicRMWInst& RMWI) { /// Return true if the given instruction always produces a value in memory /// equivalent to its value operand. -bool isSaturating(AtomicRMWInst& RMWI) { +static bool isSaturating(AtomicRMWInst &RMWI) { if (auto CF = dyn_cast<ConstantFP>(RMWI.getValOperand())) switch (RMWI.getOperation()) { case AtomicRMWInst::FMax: @@ -98,7 +97,6 @@ bool isSaturating(AtomicRMWInst& RMWI) { return C->isMaxValue(false); }; } -} // namespace Instruction *InstCombinerImpl::visitAtomicRMWInst(AtomicRMWInst &RMWI) { diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp index 917004c..048cdf4 100644 --- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp +++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp @@ -132,8 +132,6 @@ STATISTIC(NumReassoc , "Number of reassociations"); DEBUG_COUNTER(VisitCounter, "instcombine-visit", "Controls which instructions are visited"); -namespace llvm { - static cl::opt<bool> EnableCodeSinking("instcombine-code-sinking", cl::desc("Enable code sinking"), cl::init(true)); @@ -146,7 +144,9 @@ static cl::opt<unsigned> MaxArraySize("instcombine-maxarray-size", cl::init(1024), cl::desc("Maximum array size considered when doing a combine")); +namespace llvm { extern cl::opt<bool> ProfcheckDisableMetadataFixes; +} // end namespace llvm // FIXME: Remove this flag when it is no longer necessary to convert // llvm.dbg.declare to avoid inaccurate debug info. Setting this to false @@ -158,8 +158,6 @@ extern cl::opt<bool> ProfcheckDisableMetadataFixes; static cl::opt<unsigned> ShouldLowerDbgDeclare("instcombine-lower-dbg-declare", cl::Hidden, cl::init(true)); -} // end namespace llvm - std::optional<Instruction *> InstCombiner::targetInstCombineIntrinsic(IntrinsicInst &II) { // Handle target specific intrinsics diff --git a/llvm/utils/TableGen/Basic/DirectiveEmitter.cpp b/llvm/utils/TableGen/Basic/DirectiveEmitter.cpp index f0e2369..b4d816e 100644 --- a/llvm/utils/TableGen/Basic/DirectiveEmitter.cpp +++ b/llvm/utils/TableGen/Basic/DirectiveEmitter.cpp @@ -19,6 +19,7 @@ #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringSet.h" #include "llvm/ADT/StringSwitch.h" +#include "llvm/TableGen/CodeGenHelpers.h" #include "llvm/TableGen/Error.h" #include "llvm/TableGen/Record.h" #include "llvm/TableGen/TableGenBackend.h" @@ -30,26 +31,10 @@ using namespace llvm; namespace { -// Simple RAII helper for defining ifdef-undef-endif scopes. -class IfDefScope { -public: - IfDefScope(StringRef Name, raw_ostream &OS) : Name(Name), OS(OS) { - OS << "#ifdef " << Name << "\n" - << "#undef " << Name << "\n"; - } - - ~IfDefScope() { OS << "\n#endif // " << Name << "\n\n"; } - -private: - StringRef Name; - raw_ostream &OS; -}; -} // namespace - -namespace { enum class Frontend { LLVM, Flang, Clang }; +} // namespace -StringRef getFESpelling(Frontend FE) { +static StringRef getFESpelling(Frontend FE) { switch (FE) { case Frontend::LLVM: return "llvm"; @@ -60,7 +45,6 @@ StringRef getFESpelling(Frontend FE) { } llvm_unreachable("unknown FE kind"); } -} // namespace // Get the full namespace qualifier for the directive language. static std::string getQualifier(const DirectiveLanguage &DirLang, @@ -297,13 +281,8 @@ static void emitDirectivesDecl(const RecordKeeper &Records, raw_ostream &OS) { OS << "#include <cstddef>\n"; // for size_t OS << "#include <utility>\n"; // for std::pair OS << "\n"; - OS << "namespace llvm {\n"; - - // Open namespaces defined in the directive language - SmallVector<StringRef, 2> Namespaces; - SplitString(DirLang.getCppNamespace(), Namespaces, "::"); - for (auto Ns : Namespaces) - OS << "namespace " << Ns << " {\n"; + NamespaceEmitter LlvmNS(OS, "llvm"); + NamespaceEmitter DirLangNS(OS, DirLang.getCppNamespace()); if (DirLang.hasEnableBitmaskEnumInNamespace()) OS << "\nLLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE();\n"; @@ -380,9 +359,7 @@ static void emitDirectivesDecl(const RecordKeeper &Records, raw_ostream &OS) { OS << "\n"; } - // Closing namespaces - for (auto Ns : reverse(Namespaces)) - OS << "} // namespace " << Ns << "\n"; + DirLangNS.close(); // These specializations need to be in ::llvm. for (StringRef Enum : {"Association", "Category", "Directive", "Clause"}) { @@ -392,9 +369,7 @@ static void emitDirectivesDecl(const RecordKeeper &Records, raw_ostream &OS) { OS << " static constexpr bool is_iterable = true;\n"; OS << "};\n"; } - - OS << "} // namespace llvm\n"; - + LlvmNS.close(); OS << "#endif // LLVM_" << Lang << "_INC\n"; } @@ -971,11 +946,10 @@ static void generateDirectiveClauseSets(const DirectiveLanguage &DirLang, std::string IfDefName{"GEN_"}; IfDefName += getFESpelling(FE).upper(); IfDefName += "_DIRECTIVE_CLAUSE_SETS"; - IfDefScope Scope(IfDefName, OS); + IfDefEmitter Scope(OS, IfDefName); StringRef Namespace = getFESpelling(FE == Frontend::Flang ? Frontend::LLVM : FE); - OS << "\n"; // The namespace has to be different for clang vs flang, as 2 structs with the // same name but different layout is UB. So just put the 'clang' on in the // clang namespace. @@ -1016,9 +990,8 @@ static void generateDirectiveClauseMap(const DirectiveLanguage &DirLang, std::string IfDefName{"GEN_"}; IfDefName += getFESpelling(FE).upper(); IfDefName += "_DIRECTIVE_CLAUSE_MAP"; - IfDefScope Scope(IfDefName, OS); + IfDefEmitter Scope(OS, IfDefName); - OS << "\n"; OS << "{\n"; // The namespace has to be different for clang vs flang, as 2 structs with the @@ -1062,9 +1035,7 @@ static void generateDirectiveClauseMap(const DirectiveLanguage &DirLang, static void generateFlangClauseParserClass(const DirectiveLanguage &DirLang, raw_ostream &OS) { - IfDefScope Scope("GEN_FLANG_CLAUSE_PARSER_CLASSES", OS); - - OS << "\n"; + IfDefEmitter Scope(OS, "GEN_FLANG_CLAUSE_PARSER_CLASSES"); for (const Clause Clause : DirLang.getClauses()) { if (!Clause.getFlangClass().empty()) { @@ -1089,9 +1060,8 @@ static void generateFlangClauseParserClass(const DirectiveLanguage &DirLang, static void generateFlangClauseParserClassList(const DirectiveLanguage &DirLang, raw_ostream &OS) { - IfDefScope Scope("GEN_FLANG_CLAUSE_PARSER_CLASSES_LIST", OS); + IfDefEmitter Scope(OS, "GEN_FLANG_CLAUSE_PARSER_CLASSES_LIST"); - OS << "\n"; interleaveComma(DirLang.getClauses(), OS, [&](const Record *C) { Clause Clause(C); OS << Clause.getFormattedParserClassName() << "\n"; @@ -1102,9 +1072,8 @@ static void generateFlangClauseParserClassList(const DirectiveLanguage &DirLang, static void generateFlangClauseDump(const DirectiveLanguage &DirLang, raw_ostream &OS) { - IfDefScope Scope("GEN_FLANG_DUMP_PARSE_TREE_CLAUSES", OS); + IfDefEmitter Scope(OS, "GEN_FLANG_DUMP_PARSE_TREE_CLAUSES"); - OS << "\n"; for (const Clause Clause : DirLang.getClauses()) { OS << "NODE(" << DirLang.getFlangClauseBaseClass() << ", " << Clause.getFormattedParserClassName() << ")\n"; @@ -1116,10 +1085,9 @@ static void generateFlangClauseDump(const DirectiveLanguage &DirLang, static void generateFlangClauseUnparse(const DirectiveLanguage &DirLang, raw_ostream &OS) { - IfDefScope Scope("GEN_FLANG_CLAUSE_UNPARSE", OS); + IfDefEmitter Scope(OS, "GEN_FLANG_CLAUSE_UNPARSE"); StringRef Base = DirLang.getFlangClauseBaseClass(); - OS << "\n"; for (const Clause Clause : DirLang.getClauses()) { if (Clause.skipFlangUnparser()) @@ -1172,9 +1140,8 @@ static void generateFlangClauseUnparse(const DirectiveLanguage &DirLang, static void generateFlangClauseCheckPrototypes(const DirectiveLanguage &DirLang, raw_ostream &OS) { - IfDefScope Scope("GEN_FLANG_CLAUSE_CHECK_ENTER", OS); + IfDefEmitter Scope(OS, "GEN_FLANG_CLAUSE_CHECK_ENTER"); - OS << "\n"; for (const Clause Clause : DirLang.getClauses()) { OS << "void Enter(const parser::" << DirLang.getFlangClauseBaseClass() << "::" << Clause.getFormattedParserClassName() << " &);\n"; @@ -1186,12 +1153,11 @@ static void generateFlangClauseCheckPrototypes(const DirectiveLanguage &DirLang, static void generateFlangClauseParserKindMap(const DirectiveLanguage &DirLang, raw_ostream &OS) { - IfDefScope Scope("GEN_FLANG_CLAUSE_PARSER_KIND_MAP", OS); + IfDefEmitter Scope(OS, "GEN_FLANG_CLAUSE_PARSER_KIND_MAP"); StringRef Prefix = DirLang.getClausePrefix(); std::string Qual = getQualifier(DirLang); - OS << "\n"; for (const Record *R : DirLang.getClauses()) { Clause C(R); OS << "if constexpr (std::is_same_v<A, parser::" @@ -1216,11 +1182,10 @@ static void generateFlangClausesParser(const DirectiveLanguage &DirLang, llvm::sort(Names, [](const auto &A, const auto &B) { return A.second.Name > B.second.Name; }); - IfDefScope Scope("GEN_FLANG_CLAUSES_PARSER", OS); + IfDefEmitter Scope(OS, "GEN_FLANG_CLAUSES_PARSER"); StringRef Base = DirLang.getFlangClauseBaseClass(); unsigned LastIndex = Names.size() - 1; - OS << "\n"; OS << "TYPE_PARSER(\n"; for (auto [Index, RecSp] : llvm::enumerate(Names)) { auto [R, S] = RecSp; @@ -1313,10 +1278,9 @@ static void emitDirectivesFlangImpl(const DirectiveLanguage &DirLang, static void generateClauseClassMacro(const DirectiveLanguage &DirLang, raw_ostream &OS) { // Generate macros style information for legacy code in clang - IfDefScope Scope("GEN_CLANG_CLAUSE_CLASS", OS); + IfDefEmitter Scope(OS, "GEN_CLANG_CLAUSE_CLASS"); StringRef Prefix = DirLang.getClausePrefix(); - OS << "\n"; OS << "#ifndef CLAUSE\n"; OS << "#define CLAUSE(Enum, Str, Implicit)\n"; @@ -1375,12 +1339,11 @@ static void generateClauseClassMacro(const DirectiveLanguage &DirLang, // language. This code can be included in library. void emitDirectivesBasicImpl(const DirectiveLanguage &DirLang, raw_ostream &OS) { - IfDefScope Scope("GEN_DIRECTIVES_IMPL", OS); + IfDefEmitter Scope(OS, "GEN_DIRECTIVES_IMPL"); StringRef DPrefix = DirLang.getDirectivePrefix(); StringRef CPrefix = DirLang.getClausePrefix(); - OS << "\n"; OS << "#include \"llvm/Frontend/Directive/Spelling.h\"\n"; OS << "#include \"llvm/Support/ErrorHandling.h\"\n"; OS << "#include <utility>\n"; diff --git a/llvm/utils/TableGen/Basic/TargetFeaturesEmitter.cpp b/llvm/utils/TableGen/Basic/TargetFeaturesEmitter.cpp index 6b723bc..e2b5241 100644 --- a/llvm/utils/TableGen/Basic/TargetFeaturesEmitter.cpp +++ b/llvm/utils/TableGen/Basic/TargetFeaturesEmitter.cpp @@ -12,6 +12,7 @@ //===----------------------------------------------------------------------===// #include "TargetFeaturesEmitter.h" +#include "llvm/TableGen/CodeGenHelpers.h" #include "llvm/TableGen/Error.h" #include "llvm/TableGen/TableGenBackend.h" #include "llvm/TargetParser/SubtargetFeature.h" @@ -43,7 +44,7 @@ FeatureMapTy TargetFeaturesEmitter::enumeration(raw_ostream &OS) { PrintFatalError( "Too many subtarget features! Bump MAX_SUBTARGET_FEATURES."); - OS << "namespace " << Target << " {\n"; + NamespaceEmitter NS(OS, Target); OS << "enum {\n"; @@ -58,9 +59,8 @@ FeatureMapTy TargetFeaturesEmitter::enumeration(raw_ostream &OS) { OS << " " << "NumSubtargetFeatures = " << N << "\n"; - // Close enumeration and namespace + // Close enumeration. OS << "};\n"; - OS << "} // end namespace " << Target << "\n"; return FeatureMap; } @@ -149,25 +149,23 @@ void TargetFeaturesEmitter::printCPUKeyValues(raw_ostream &OS, void TargetFeaturesEmitter::run(raw_ostream &OS) { OS << "// Autogenerated by TargetFeatureEmitter.cpp\n\n"; - OS << "\n#ifdef GET_SUBTARGETFEATURES_ENUM\n"; - OS << "#undef GET_SUBTARGETFEATURES_ENUM\n\n"; - - OS << "namespace llvm {\n"; - auto FeatureMap = enumeration(OS); - OS << "} // end namespace llvm\n\n"; - OS << "#endif // GET_SUBTARGETFEATURES_ENUM\n\n"; + FeatureMapTy FeatureMap; + { + IfDefEmitter IfDef(OS, "GET_SUBTARGETFEATURES_ENUM"); + NamespaceEmitter NS(OS, "llvm"); + FeatureMap = enumeration(OS); + } - OS << "\n#ifdef GET_SUBTARGETFEATURES_KV\n"; - OS << "#undef GET_SUBTARGETFEATURES_KV\n\n"; + { + IfDefEmitter IfDef(OS, "GET_SUBTARGETFEATURES_KV"); + NamespaceEmitter NS(OS, "llvm"); - OS << "namespace llvm {\n"; - printFeatureKeyValues(OS, FeatureMap); - OS << "\n"; + printFeatureKeyValues(OS, FeatureMap); + OS << "\n"; - printCPUKeyValues(OS, FeatureMap); - OS << "\n"; - OS << "} // end namespace llvm\n\n"; - OS << "#endif // GET_SUBTARGETFEATURES_KV\n\n"; + printCPUKeyValues(OS, FeatureMap); + OS << "\n"; + } } static TableGen::Emitter::OptClass<TargetFeaturesEmitter> diff --git a/llvm/utils/TableGen/CompressInstEmitter.cpp b/llvm/utils/TableGen/CompressInstEmitter.cpp index ccf8385..d8c5ca7 100644 --- a/llvm/utils/TableGen/CompressInstEmitter.cpp +++ b/llvm/utils/TableGen/CompressInstEmitter.cpp @@ -167,7 +167,7 @@ bool CompressInstEmitter::validateRegister(const Record *Reg, assert(RegClass->isSubClassOf("RegisterClass") && "RegClass record should be a RegisterClass"); const CodeGenRegisterClass &RC = Target.getRegisterClass(RegClass); - const CodeGenRegister *R = Target.getRegisterByName(Reg->getName().lower()); + const CodeGenRegister *R = Target.getRegBank().getReg(Reg); assert(R != nullptr && "Register not defined!!"); return RC.contains(R); } |