Skip to content

Commit 1fb486a

Browse files
authored
[clang] Add DisableInlineOpt code generation option
1 parent ffe1c6f commit 1fb486a

File tree

5 files changed

+26
-4
lines changed

5 files changed

+26
-4
lines changed

clang/include/clang/Basic/CodeGenOptions.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ CODEGENOPT(SanitizeMemoryUseAfterDtor, 1, 0) ///< Enable use-after-delete detect
246246
///< in MemorySanitizer
247247
CODEGENOPT(SanitizeCfiCrossDso, 1, 0) ///< Enable cross-dso support in CFI.
248248
CODEGENOPT(Jumptablerdata, 1, 0) ///< Put switch case jump tables in .rdata
249+
CODEGENOPT(DisableInlineOpt, 1, 0) ///< Disables the optimization of inline functions.
249250
CODEGENOPT(DisableCFICheckFail, 1, 0) ///< Disables the failure checks in CFI.
250251
CODEGENOPT(DisableCFICheck, 1, 0) ///< Disables the checks in CFI.
251252
CODEGENOPT(DisableCFISlowPathCheck, 1, 0) ///< Disables the slow path checks in CFI.

clang/include/clang/Driver/Options.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2435,6 +2435,10 @@ def fjumptable_rdata : Flag<["-"], "fjumptable-rdata">,
24352435
Group<f_clang_Group>,
24362436
HelpText<"Put switch case jump tables in .rdata">,
24372437
MarshallingInfoFlag<CodeGenOpts<"Jumptablerdata">>;
2438+
def fdisable_inline_opt : Flag<["-"], "fdisable-inline-opt">,
2439+
Group<f_clang_Group>,
2440+
HelpText<"Disables the optimization of inline functions">,
2441+
MarshallingInfoFlag<CodeGenOpts<"DisableInlineOpt">>;
24382442
def fdisable_cfi_check : Flag<["-"], "fdisable-cfi-check">,
24392443
Group<f_clang_Group>,
24402444
HelpText<"Disables the checks in CFI">,

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,6 +1042,11 @@ void CodeGenModule::Release() {
10421042
getModule().addModuleFlag(llvm::Module::Override, "Cross-DSO CFI", 1);
10431043
}
10441044

1045+
if (CodeGenOpts.DisableInlineOpt) {
1046+
// Indicate that we want to disable optimization of inlined functions.
1047+
getModule().addModuleFlag(llvm::Module::Override, "DisableInlineOpt", 1);
1048+
}
1049+
10451050
if (CodeGenOpts.Jumptablerdata) {
10461051
// Indicate that we want to emit jump table to .rdata.
10471052
getModule().addModuleFlag(llvm::Module::Override, "Jumptablerdata", 1);

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6792,6 +6792,10 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
67926792
CmdArgs.push_back("-mllvm");
67936793
CmdArgs.push_back("-jumptable-in-function-section=false");
67946794
}
6795+
6796+
// -fdisable-inline-opt(Disables the optimization of inline functions)
6797+
if (Args.hasArg(options::OPT_fdisable_inline_opt))
6798+
CmdArgs.push_back("-fdisable-inline-opt");
67956799

67966800
// -fdisable-cfi-check(Disables the checks in CFI)
67976801
if (Args.hasArg(options::OPT_fdisable_cfi_check))

llvm/lib/Transforms/Utils/InlineFunction.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2018,6 +2018,14 @@ inlineRetainOrClaimRVCalls(CallBase &CB, objcarc::ARCInstKind RVCallKind,
20182018
// Set volatile attribute for inlined basic block and instructions.
20192019
// This is used to preserve the volatile attribute of the original call instruction.
20202020
static void setVolatileForInlinedBB(BasicBlock *BB) {
2021+
2022+
// We need BBs belong to a function.
2023+
if (!BB->getParent()->getParent())
2024+
return;
2025+
2026+
// Set volatile attribute for the basic block if the module flag is set.
2027+
if (!BB->getParent()->getParent()->getModuleFlag("DisableInlineOpt"))
2028+
return;
20212029

20222030
// Do not set volatile attribute for basic block with only one instruction.
20232031
if (BB->size() <= 1)
@@ -2830,10 +2838,10 @@ llvm::InlineResult llvm::InlineFunction(CallBase &CB, InlineFunctionInfo &IFI,
28302838

28312839
if (MergeAttributes)
28322840
AttributeFuncs::mergeAttributesForInlining(*Caller, *CalledFunc);
2833-
#ifdef _WIN32
2841+
28342842
// Set 'volatile' to the new BB and instructions.
28352843
setVolatileForInlinedBB(OrigBB);
2836-
#endif
2844+
28372845
// We are now done with the inlining.
28382846
return InlineResult::success();
28392847
}
@@ -2997,9 +3005,9 @@ llvm::InlineResult llvm::InlineFunction(CallBase &CB, InlineFunctionInfo &IFI,
29973005

29983006
if (MergeAttributes)
29993007
AttributeFuncs::mergeAttributesForInlining(*Caller, *CalledFunc);
3000-
#ifdef _WIN32
3008+
30013009
// Set 'volatile' to the new BB and instructions.
30023010
setVolatileForInlinedBB(AfterCallBB);
3003-
#endif
3011+
30043012
return InlineResult::success();
30053013
}

0 commit comments

Comments
 (0)