Skip to content

Commit 19550e7

Browse files
committed
[NFC][Clang] Remove redundant function definitions
There were 3 definitions of the mergeDefaultFunctionDefinitionAttributes function: A private implementation, a version exposed in CodeGen, a version exposed in CodeGenModule. This patch removes the private and the CodeGenModule versions and keeps a single definition in CodeGen. Reviewed By: jhuber6 Differential Revision: https://reviews.llvm.org/D159256
1 parent 9536bbe commit 19550e7

File tree

3 files changed

+19
-45
lines changed

3 files changed

+19
-45
lines changed

clang/lib/CodeGen/CGCall.cpp

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2002,10 +2002,7 @@ static void getTrivialDefaultFunctionAttributes(
20022002
}
20032003
}
20042004

2005-
/// Adds attributes to \p F according to our \p CodeGenOpts and \p LangOpts, as
2006-
/// though we had emitted it ourselves. We remove any attributes on F that
2007-
/// conflict with the attributes we add here.
2008-
static void mergeDefaultFunctionDefinitionAttributes(
2005+
void CodeGen::mergeDefaultFunctionDefinitionAttributes(
20092006
llvm::Function &F, const CodeGenOptions &CodeGenOpts,
20102007
const LangOptions &LangOpts, const TargetOptions &TargetOpts,
20112008
bool WillInternalize) {
@@ -2065,15 +2062,6 @@ static void mergeDefaultFunctionDefinitionAttributes(
20652062
F.addFnAttrs(FuncAttrs);
20662063
}
20672064

2068-
void clang::CodeGen::mergeDefaultFunctionDefinitionAttributes(
2069-
llvm::Function &F, const CodeGenOptions CodeGenOpts,
2070-
const LangOptions &LangOpts, const TargetOptions &TargetOpts,
2071-
bool WillInternalize) {
2072-
2073-
::mergeDefaultFunctionDefinitionAttributes(F, CodeGenOpts, LangOpts,
2074-
TargetOpts, WillInternalize);
2075-
}
2076-
20772065
void CodeGenModule::getTrivialDefaultFunctionAttributes(
20782066
StringRef Name, bool HasOptnone, bool AttrOnCallSite,
20792067
llvm::AttrBuilder &FuncAttrs) {
@@ -2094,15 +2082,6 @@ void CodeGenModule::getDefaultFunctionAttributes(StringRef Name,
20942082
addMergableDefaultFunctionAttributes(CodeGenOpts, FuncAttrs);
20952083
}
20962084

2097-
/// Apply default attributes to \p F, accounting for merge semantics of
2098-
/// attributes that should not overwrite existing attributes.
2099-
void CodeGenModule::mergeDefaultFunctionDefinitionAttributes(
2100-
llvm::Function &F, bool WillInternalize) {
2101-
::mergeDefaultFunctionDefinitionAttributes(F, getCodeGenOpts(), getLangOpts(),
2102-
getTarget().getTargetOpts(),
2103-
WillInternalize);
2104-
}
2105-
21062085
void CodeGenModule::addDefaultFunctionDefinitionAttributes(
21072086
llvm::AttrBuilder &attrs) {
21082087
getDefaultFunctionAttributes(/*function name*/ "", /*optnone*/ false,

clang/lib/CodeGen/CGCall.h

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -395,10 +395,25 @@ class ReturnValueSlot {
395395
bool isExternallyDestructed() const { return IsExternallyDestructed; }
396396
};
397397

398-
/// Helper to add attributes to \p F according to the CodeGenOptions and
399-
/// LangOptions without requiring a CodeGenModule to be constructed.
398+
/// Adds attributes to \p F according to our \p CodeGenOpts and \p LangOpts, as
399+
/// though we had emitted it ourselves. We remove any attributes on F that
400+
/// conflict with the attributes we add here.
401+
///
402+
/// This is useful for adding attrs to bitcode modules that you want to link
403+
/// with but don't control, such as CUDA's libdevice. When linking with such
404+
/// a bitcode library, you might want to set e.g. its functions'
405+
/// "unsafe-fp-math" attribute to match the attr of the functions you're
406+
/// codegen'ing. Otherwise, LLVM will interpret the bitcode module's lack of
407+
/// unsafe-fp-math attrs as tantamount to unsafe-fp-math=false, and then LLVM
408+
/// will propagate unsafe-fp-math=false up to every transitive caller of a
409+
/// function in the bitcode library!
410+
///
411+
/// With the exception of fast-math attrs, this will only make the attributes
412+
/// on the function more conservative. But it's unsafe to call this on a
413+
/// function which relies on particular fast-math attributes for correctness.
414+
/// It's up to you to ensure that this is safe.
400415
void mergeDefaultFunctionDefinitionAttributes(llvm::Function &F,
401-
const CodeGenOptions CodeGenOpts,
416+
const CodeGenOptions &CodeGenOpts,
402417
const LangOptions &LangOpts,
403418
const TargetOptions &TargetOpts,
404419
bool WillInternalize);

clang/lib/CodeGen/CodeGenModule.h

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,26 +1259,6 @@ class CodeGenModule : public CodeGenTypeCache {
12591259
llvm::AttributeList &Attrs, unsigned &CallingConv,
12601260
bool AttrOnCallSite, bool IsThunk);
12611261

1262-
/// Adds attributes to F according to our CodeGenOptions and LangOptions, as
1263-
/// though we had emitted it ourselves. We remove any attributes on F that
1264-
/// conflict with the attributes we add here.
1265-
///
1266-
/// This is useful for adding attrs to bitcode modules that you want to link
1267-
/// with but don't control, such as CUDA's libdevice. When linking with such
1268-
/// a bitcode library, you might want to set e.g. its functions'
1269-
/// "unsafe-fp-math" attribute to match the attr of the functions you're
1270-
/// codegen'ing. Otherwise, LLVM will interpret the bitcode module's lack of
1271-
/// unsafe-fp-math attrs as tantamount to unsafe-fp-math=false, and then LLVM
1272-
/// will propagate unsafe-fp-math=false up to every transitive caller of a
1273-
/// function in the bitcode library!
1274-
///
1275-
/// With the exception of fast-math attrs, this will only make the attributes
1276-
/// on the function more conservative. But it's unsafe to call this on a
1277-
/// function which relies on particular fast-math attributes for correctness.
1278-
/// It's up to you to ensure that this is safe.
1279-
void mergeDefaultFunctionDefinitionAttributes(llvm::Function &F,
1280-
bool WillInternalize);
1281-
12821262
/// Like the overload taking a `Function &`, but intended specifically
12831263
/// for frontends that want to build on Clang's target-configuration logic.
12841264
void addDefaultFunctionDefinitionAttributes(llvm::AttrBuilder &attrs);

0 commit comments

Comments
 (0)