19#define DEBUG_TYPE "forceattrs"
23 case Attribute::AlwaysInline:
24 return F.hasFnAttribute(Attribute::NoInline);
26 case Attribute::NoInline:
27 return F.hasFnAttribute(Attribute::AlwaysInline);
29 case Attribute::OptimizeNone:
30 return F.hasFnAttribute(Attribute::MinSize) ||
31 F.hasFnAttribute(Attribute::OptimizeForSize) ||
32 F.hasFnAttribute(Attribute::OptimizeForDebugging);
34 case Attribute::MinSize:
35 return F.hasFnAttribute(Attribute::OptimizeNone) ||
36 F.hasFnAttribute(Attribute::OptimizeForDebugging);
38 case Attribute::OptimizeForSize:
39 return F.hasFnAttribute(Attribute::OptimizeNone) ||
40 F.hasFnAttribute(Attribute::OptimizeForDebugging);
42 case Attribute::OptimizeForDebugging:
43 return F.hasFnAttribute(Attribute::OptimizeNone) ||
44 F.hasFnAttribute(Attribute::MinSize) ||
45 F.hasFnAttribute(Attribute::OptimizeForSize);
57 auto ParseFunctionAndAttr = [&](
StringRef S) {
59 if (S.contains(
':')) {
61 if (KV.first !=
F.getName())
63 AttributeText = KV.second;
70 <<
" unknown or not a function attribute!\n");
75 for (
const auto &S : Opts.force_attribute) {
76 auto Kind = ParseFunctionAndAttr(S);
83 for (
const auto &S : Opts.force_remove_attribute) {
84 auto Kind = ParseFunctionAndAttr(S);
95 if (!Opts.forceattrs_csv_path.empty()) {
98 std::error_code EC = BufferOrError.getError();
99 M.getContext().emitError(
"cannot open CSV file: " + EC.message());
103 StringRef Buffer = BufferOrError.get()->getBuffer();
107 auto SplitPair = It->
split(
',');
108 if (SplitPair.second.empty())
110 Function *Func = M.getFunction(SplitPair.first);
112 if (Func->isDeclaration())
114 auto SecondSplitPair = SplitPair.second.split(
'=');
115 if (!SecondSplitPair.second.empty()) {
116 Func->addFnAttr(SecondSplitPair.first, SecondSplitPair.second);
125 Func->addFnAttr(AttrKind);
128 errs() <<
"Cannot add " << SplitPair.second
129 <<
" as an attribute name.\n";
133 <<
" does not exist.\n";
139 if (!Opts.force_attribute.empty() || !Opts.force_remove_attribute.empty()) {
static bool hasConflictingFnAttr(Attribute::AttrKind Kind, Function &F)
static void forceAttributes(const IPOOptions &Opts, Function &F)
If F has any forced attributes given on the command line, add them.
Super simple passes to force specific function attrs from the commandline into the IR for debugging p...
Module.h This file contains the declarations for the Module class.
static LLVM_ABI Attribute::AttrKind getAttrKindFromName(StringRef AttrName)
static LLVM_ABI bool canUseAsFnAttr(AttrKind Kind)
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results,...
@ None
No attributes have been set.
This interface provides simple read-only access to a block of memory, and provides simple methods for...
static std::unique_ptr< MemoryBuffer > getMemBuffer(StringRef InputData, StringRef BufferName="", bool RequiresNullTerminator=true)
Open the specified memory range as a MemoryBuffer.
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFileOrSTDIN(const Twine &Filename, bool IsText=false, bool RequiresNullTerminator=true, std::optional< Align > Alignment=std::nullopt)
Open the specified file as a MemoryBuffer, or open stdin if the Filename is "-".
A Module instance is used to store all the information related to an LLVM module.
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Represent a constant reference to a string, i.e.
std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
A forward iterator which reads text lines from a buffer.
int64_t line_number() const
Return the current line number. May return any number at EOF.
bool is_at_end() const
Return true if we're an "end" iterator or have reached EOF.
This is an optimization pass for GlobalISel generic memory operations.
const IPOOptions & getIPOOptions(const LLVMContext &C)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
LLVM_ABI raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.
LLVM_ABI PreservedAnalyses run(Module &M, ModuleAnalysisManager &)