Skip to content

Commit feeeeff

Browse files
committed
Reorder commits. Fix clang codegen tests.
Created using spr 1.3.6-beta.1
2 parents 08d0dc1 + 2b5d430 commit feeeeff

38 files changed

+683
-57
lines changed

clang/include/clang/Basic/CodeGenOptions.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ CODEGENOPT(EnableNoundefAttrs, 1, 0) ///< Enable emitting `noundef` attributes o
7878
CODEGENOPT(DebugPassManager, 1, 0) ///< Prints debug information for the new
7979
///< pass manager.
8080
CODEGENOPT(DisableRedZone , 1, 0) ///< Set when -mno-red-zone is enabled.
81+
CODEGENOPT(CallGraphSection, 1, 0) ///< Emit a call graph section into the
82+
///< object file.
8183
CODEGENOPT(EmitCallSiteInfo, 1, 0) ///< Emit call site info only in the case of
8284
///< '-g' + 'O>0' level.
8385
CODEGENOPT(IndirectTlsSegRefs, 1, 0) ///< Set when -mno-tls-direct-seg-refs

clang/include/clang/Driver/Options.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4291,6 +4291,10 @@ defm data_sections : BoolFOption<"data-sections",
42914291
PosFlag<SetTrue, [], [ClangOption, CC1Option],
42924292
"Place each data in its own section">,
42934293
NegFlag<SetFalse>>;
4294+
defm call_graph_section : BoolFOption<"call-graph-section",
4295+
CodeGenOpts<"CallGraphSection">, DefaultFalse,
4296+
PosFlag<SetTrue, [], [CC1Option], "Emit a call graph section">,
4297+
NegFlag<SetFalse>>;
42944298
defm stack_size_section : BoolFOption<"stack-size-section",
42954299
CodeGenOpts<"StackSizeSection">, DefaultFalse,
42964300
PosFlag<SetTrue, [], [ClangOption, CC1Option],

clang/lib/CodeGen/BackendUtil.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,7 @@ static bool initTargetOptions(DiagnosticsEngine &Diags,
455455
Options.StackUsageOutput = CodeGenOpts.StackUsageOutput;
456456
Options.EmitAddrsig = CodeGenOpts.Addrsig;
457457
Options.ForceDwarfFrameSection = CodeGenOpts.ForceDwarfFrameSection;
458+
Options.EmitCallGraphSection = CodeGenOpts.CallGraphSection;
458459
Options.EmitCallSiteInfo = CodeGenOpts.EmitCallSiteInfo;
459460
Options.EnableAIXExtendedAltivecABI = LangOpts.EnableAIXExtendedAltivecABI;
460461
Options.XRayFunctionIndex = CodeGenOpts.XRayFunctionIndex;

clang/lib/CodeGen/CGCall.cpp

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include "llvm/IR/CallingConv.h"
3939
#include "llvm/IR/DataLayout.h"
4040
#include "llvm/IR/InlineAsm.h"
41+
#include "llvm/IR/Instruction.h"
4142
#include "llvm/IR/IntrinsicInst.h"
4243
#include "llvm/IR/Intrinsics.h"
4344
#include "llvm/IR/Type.h"
@@ -5772,34 +5773,21 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
57725773
Attrs = AllocAlignAttrEmitter.TryEmitAsCallSiteAttribute(Attrs);
57735774

57745775
if (CGM.getCodeGenOpts().CallGraphSection) {
5775-
// Create operand bundle only for indirect calls, not for all
5776-
if (callOrInvoke && *callOrInvoke && (*callOrInvoke)->isIndirectCall()) {
5777-
5778-
assert((TargetDecl && TargetDecl->getFunctionType() ||
5779-
Callee.getAbstractInfo().getCalleeFunctionProtoType()) &&
5780-
"cannot find callsite type");
5781-
5782-
QualType CST;
5783-
if (TargetDecl && TargetDecl->getFunctionType())
5784-
CST = QualType(TargetDecl->getFunctionType(), 0);
5785-
else if (const auto *FPT =
5786-
Callee.getAbstractInfo().getCalleeFunctionProtoType())
5787-
CST = QualType(FPT, 0);
5788-
5789-
if (!CST.isNull()) {
5790-
auto *TypeIdMD = CGM.CreateMetadataIdentifierGeneralized(CST);
5791-
auto *TypeIdMDVal =
5792-
llvm::MetadataAsValue::get(getLLVMContext(), TypeIdMD);
5793-
BundleList.emplace_back("type", TypeIdMDVal);
5794-
}
5795-
5796-
// Set type identifier metadata of indirect calls for call graph section.
5797-
if (const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(TargetDecl)) {
5798-
// Type id metadata is set only for C/C++ contexts.
5799-
if (isCXXDeclType(FD)) {
5800-
CGM.CreateFunctionTypeMetadataForIcall(FD->getType(), *callOrInvoke);
5801-
}
5802-
}
5776+
assert((TargetDecl && TargetDecl->getFunctionType() ||
5777+
Callee.getAbstractInfo().getCalleeFunctionProtoType()) &&
5778+
"cannot find callsite type");
5779+
QualType CST;
5780+
if (TargetDecl && TargetDecl->getFunctionType())
5781+
CST = QualType(TargetDecl->getFunctionType(), 0);
5782+
else if (const auto *FPT =
5783+
Callee.getAbstractInfo().getCalleeFunctionProtoType())
5784+
CST = QualType(FPT, 0);
5785+
5786+
if (!CST.isNull()) {
5787+
auto *TypeIdMD = CGM.CreateMetadataIdentifierGeneralized(CST);
5788+
auto *TypeIdMDVal =
5789+
llvm::MetadataAsValue::get(getLLVMContext(), TypeIdMD);
5790+
BundleList.emplace_back("type", TypeIdMDVal);
58035791
}
58045792
}
58055793

@@ -5817,8 +5805,18 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
58175805
CI->getCalledFunction()->getName().starts_with("_Z4sqrt")) {
58185806
SetSqrtFPAccuracy(CI);
58195807
}
5820-
if (callOrInvoke)
5808+
if (callOrInvoke) {
58215809
*callOrInvoke = CI;
5810+
if (CGM.getCodeGenOpts().CallGraphSection) {
5811+
// Set type identifier metadata of indirect calls for call graph section.
5812+
if (const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(TargetDecl)) {
5813+
// Type id metadata is set only for C/C++ contexts.
5814+
if (isCXXDeclType(FD)) {
5815+
CGM.CreateFunctionTypeMetadataForIcall(FD->getType(), *callOrInvoke);
5816+
}
5817+
}
5818+
}
5819+
}
58225820

58235821
// If this is within a function that has the guard(nocf) attribute and is an
58245822
// indirect call, add the "guard_nocf" attribute to this call to indicate that

clang/lib/CodeGen/CGExpr.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6172,13 +6172,6 @@ RValue CodeGenFunction::EmitCall(QualType CalleeType,
61726172
}
61736173
if (CallOrInvoke)
61746174
*CallOrInvoke = LocalCallOrInvoke;
6175-
6176-
// Set type identifier metadata of indirect calls for call graph section.
6177-
if (CGM.getCodeGenOpts().CallGraphSection && LocalCallOrInvoke &&
6178-
LocalCallOrInvoke->isIndirectCall())
6179-
CGM.CreateFunctionTypeMetadataForIcall(QualType(FnType, 0),
6180-
LocalCallOrInvoke);
6181-
61826175
return Call;
61836176
}
61846177

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6609,6 +6609,10 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
66096609
CmdArgs.push_back(A->getValue());
66106610
}
66116611

6612+
if (Args.hasFlag(options::OPT_fcall_graph_section,
6613+
options::OPT_fno_call_graph_section, false))
6614+
CmdArgs.push_back("-fcall-graph-section");
6615+
66126616
Args.addOptInFlag(CmdArgs, options::OPT_fstack_size_section,
66136617
options::OPT_fno_stack_size_section);
66146618

clang/test/CodeGen/call-graph-section-1.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Tests that we assign appropriate identifiers to indirect calls and targets
22
// specifically for C++ class and instance methods.
33

4-
// RUN: %clang_cc1 -triple x86_64-unknown-linux -fcall-graph-section -S \
4+
// RUN: %clang_cc1 -triple x86_64-unknown-linux -fcall-graph-section \
55
// RUN: -emit-llvm -o %t %s
66
// RUN: FileCheck --check-prefix=FT %s < %t
77
// RUN: FileCheck --check-prefix=CST %s < %t

clang/test/CodeGen/call-graph-section-2.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Tests that we assign appropriate identifiers to indirect calls and targets
22
// specifically for C++ templates.
33

4-
// RUN: %clang_cc1 -triple x86_64-unknown-linux -fcall-graph-section -S \
4+
// RUN: %clang_cc1 -triple x86_64-unknown-linux -fcall-graph-section \
55
// RUN: -emit-llvm -o %t %s
66
// RUN: FileCheck --check-prefix=FT %s < %t
77
// RUN: FileCheck --check-prefix=CST %s < %t

clang/test/CodeGen/call-graph-section-3.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Tests that we assign appropriate identifiers to indirect calls and targets
22
// specifically for virtual methods.
33

4-
// RUN: %clang_cc1 -triple x86_64-unknown-linux -fcall-graph-section -S \
4+
// RUN: %clang_cc1 -triple x86_64-unknown-linux -fcall-graph-section \
55
// RUN: -emit-llvm -o %t %s
66
// RUN: FileCheck --check-prefix=FT %s < %t
77
// RUN: FileCheck --check-prefix=CST %s < %t

clang/test/CodeGen/call-graph-section.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// Tests that we assign appropriate identifiers to indirect calls and targets.
22

3-
// RUN: %clang_cc1 -triple x86_64-unknown-linux -fcall-graph-section -S \
3+
// RUN: %clang_cc1 -triple x86_64-unknown-linux -fcall-graph-section \
44
// RUN: -emit-llvm -o - %s | FileCheck --check-prefixes=CHECK,ITANIUM %s
55

6-
// RUN: %clang_cc1 -triple x86_64-pc-windows-msvc -fcall-graph-section -S \
6+
// RUN: %clang_cc1 -triple x86_64-pc-windows-msvc -fcall-graph-section \
77
// RUN: -emit-llvm -o - %s | FileCheck --check-prefixes=CHECK,MS %s
88

99
// CHECK-DAG: define {{(dso_local)?}} void @foo({{.*}} !type [[F_TVOID:![0-9]+]]
@@ -82,4 +82,4 @@ void stf() {
8282
// MS-DAG: [[F_TPTR]] = !{i64 0, !"[email protected]"}
8383

8484
// ITANIUM-DAG: [[F_TSTRUCT]] = !{i64 0, !"_ZTSFv3st2PvE.generalized"}
85-
// MS-DAG: [[F_TSTRUCT]] = !{i64 0, !"?6AXUst2@@[email protected]"}
85+
// MS-DAG: [[F_TSTRUCT]] = !{i64 0, !"?6AXUst2@@[email protected]"}

0 commit comments

Comments
 (0)