diff options
author | Evgeniy Stepanov <eugeni.stepanov@gmail.com> | 2015-09-12 01:07:37 +0000 |
---|---|---|
committer | Evgeniy Stepanov <eugeni.stepanov@gmail.com> | 2015-09-12 01:07:37 +0000 |
commit | 93db40a147a219f6b5a60bdfe34afae33545deed (patch) | |
tree | 654a79e16a9e6a7dc051a10d2b51e3f95e791dc1 /clang/lib/CodeGen/CodeGenModule.h | |
parent | e299bc51b64a0ac346f8fea0f703b62be468a719 (diff) | |
download | bcm5719-llvm-93db40a147a219f6b5a60bdfe34afae33545deed.tar.gz bcm5719-llvm-93db40a147a219f6b5a60bdfe34afae33545deed.zip |
Always_inline codegen rewrite.
Current implementation may end up emitting an undefined reference for
an "inline __attribute__((always_inline))" function by generating an
"available_externally alwaysinline" IR function for it and then failing to
inline all the calls. This happens when a call to such function is in dead
code. As the inliner is an SCC pass, it does not process dead code.
Libc++ relies on the compiler never emitting such undefined reference.
With this patch, we emit a pair of
1. internal alwaysinline definition (called F.alwaysinline)
2a. A stub F() { musttail call F.alwaysinline }
-- or, depending on the linkage --
2b. A declaration of F.
The frontend ensures that F.inlinefunction is only used for direct
calls, and the stub is used for everything else (taking the address of
the function, really). Declaration (2b) is emitted in the case when
"inline" is meant for inlining only (like __gnu_inline__ and some
other cases).
This approach, among other nice properties, ensures that alwaysinline
functions are always internal, making it impossible for a direct call
to such function to produce an undefined symbol reference.
This patch is based on ideas by Chandler Carruth and Richard Smith.
llvm-svn: 247494
Diffstat (limited to 'clang/lib/CodeGen/CodeGenModule.h')
-rw-r--r-- | clang/lib/CodeGen/CodeGenModule.h | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.h b/clang/lib/CodeGen/CodeGenModule.h index 754e3d1d29f..e579f8bd5ec 100644 --- a/clang/lib/CodeGen/CodeGenModule.h +++ b/clang/lib/CodeGen/CodeGenModule.h @@ -489,6 +489,8 @@ private: /// MDNodes. llvm::DenseMap<QualType, llvm::Metadata *> MetadataIdMap; + llvm::SmallVector<llvm::Function*, 8> AlwaysInlineFunctions; + public: CodeGenModule(ASTContext &C, const HeaderSearchOptions &headersearchopts, const PreprocessorOptions &ppopts, @@ -1131,6 +1133,8 @@ public: /// \breif Get the declaration of std::terminate for the platform. llvm::Constant *getTerminateFn(); + void AddAlwaysInlineFunction(llvm::Function *Fn); + private: llvm::Constant * GetOrCreateLLVMFunction(StringRef MangledName, llvm::Type *Ty, GlobalDecl D, @@ -1226,6 +1230,12 @@ private: /// Emits target specific Metadata for global declarations. void EmitTargetMetadata(); + /// Replaces alwaysinline functions with a pair of internal xxx.inlinefunction + /// for direct calls, and a stub for indirect calls, and rewrites all uses of + /// those. + void RewriteAlwaysInlineFunctions(); + void RewriteAlwaysInlineFunction(llvm::Function *Fn); + /// Emit the llvm.gcov metadata used to tell LLVM where to emit the .gcno and /// .gcda files in a way that persists in .bc files. void EmitCoverageFile(); |