2008-07-30 07:18:29 +08:00
|
|
|
//===--- CodeGenModule.h - Per-Module state for LLVM CodeGen ----*- C++ -*-===//
|
2007-05-24 14:29:05 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2007-05-24 14:29:05 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2009-02-14 03:12:34 +08:00
|
|
|
// This is the internal per-translation-unit state used for llvm translation.
|
2007-05-24 14:29:05 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-08-14 00:25:19 +08:00
|
|
|
#ifndef LLVM_CLANG_LIB_CODEGEN_CODEGENMODULE_H
|
|
|
|
#define LLVM_CLANG_LIB_CODEGEN_CODEGENMODULE_H
|
2007-05-24 14:29:05 +08:00
|
|
|
|
2012-12-04 17:13:33 +08:00
|
|
|
#include "CGVTables.h"
|
Compute and preserve alignment more faithfully in IR-generation.
Introduce an Address type to bundle a pointer value with an
alignment. Introduce APIs on CGBuilderTy to work with Address
values. Change core APIs on CGF/CGM to traffic in Address where
appropriate. Require alignments to be non-zero. Update a ton
of code to compute and propagate alignment information.
As part of this, I've promoted CGBuiltin's EmitPointerWithAlignment
helper function to CGF and made use of it in a number of places in
the expression emitter.
The end result is that we should now be significantly more correct
when performing operations on objects that are locally known to
be under-aligned. Since alignment is not reliably tracked in the
type system, there are inherent limits to this, but at least we
are no longer confused by standard operations like derived-to-base
conversions and array-to-pointer decay. I've also fixed a large
number of bugs where we were applying the complete-object alignment
to a pointer instead of the non-virtual alignment, although most of
these were hidden by the very conservative approach we took with
member alignment.
Also, because IRGen now reliably asserts on zero alignments, we
should no longer be subject to an absurd but frustrating recurring
bug where an incomplete type would report a zero alignment and then
we'd naively do a alignmentAtOffset on it and emit code using an
alignment equal to the largest power-of-two factor of the offset.
We should also now be emitting much more aggressive alignment
attributes in the presence of over-alignment. In particular,
field access now uses alignmentAtOffset instead of min.
Several times in this patch, I had to change the existing
code-generation pattern in order to more effectively use
the Address APIs. For the most part, this seems to be a strict
improvement, like doing pointer arithmetic with GEPs instead of
ptrtoint. That said, I've tried very hard to not change semantics,
but it is likely that I've failed in a few places, for which I
apologize.
ABIArgInfo now always carries the assumed alignment of indirect and
indirect byval arguments. In order to cut down on what was already
a dauntingly large patch, I changed the code to never set align
attributes in the IR on non-byval indirect arguments. That is,
we still generate code which assumes that indirect arguments have
the given alignment, but we don't express this information to the
backend except where it's semantically required (i.e. on byvals).
This is likely a minor regression for those targets that did provide
this information, but it'll be trivial to add it back in a later
patch.
I partially punted on applying this work to CGBuiltin. Please
do not add more uses of the CreateDefaultAligned{Load,Store}
APIs; they will be going away eventually.
llvm-svn: 246985
2015-09-08 16:05:57 +08:00
|
|
|
#include "CodeGenTypeCache.h"
|
2012-12-04 17:13:33 +08:00
|
|
|
#include "CodeGenTypes.h"
|
2014-08-02 05:35:28 +08:00
|
|
|
#include "SanitizerMetadata.h"
|
2009-05-05 12:44:02 +08:00
|
|
|
#include "clang/AST/DeclCXX.h"
|
2009-09-11 08:07:24 +08:00
|
|
|
#include "clang/AST/DeclObjC.h"
|
2016-03-03 13:21:39 +08:00
|
|
|
#include "clang/AST/DeclOpenMP.h"
|
2011-06-14 12:02:39 +08:00
|
|
|
#include "clang/AST/GlobalDecl.h"
|
2011-01-14 02:57:25 +08:00
|
|
|
#include "clang/AST/Mangle.h"
|
2012-12-04 17:13:33 +08:00
|
|
|
#include "clang/Basic/ABI.h"
|
|
|
|
#include "clang/Basic/LangOptions.h"
|
2013-01-15 01:21:00 +08:00
|
|
|
#include "clang/Basic/Module.h"
|
2021-02-23 03:47:29 +08:00
|
|
|
#include "clang/Basic/NoSanitizeList.h"
|
2020-02-28 06:16:47 +08:00
|
|
|
#include "clang/Basic/TargetInfo.h"
|
2017-03-30 08:29:36 +08:00
|
|
|
#include "clang/Basic/XRayLists.h"
|
2021-03-06 02:49:47 +08:00
|
|
|
#include "clang/Lex/PreprocessorOptions.h"
|
2007-06-20 12:44:43 +08:00
|
|
|
#include "llvm/ADT/DenseMap.h"
|
2013-01-15 01:21:00 +08:00
|
|
|
#include "llvm/ADT/SetVector.h"
|
2010-03-05 02:17:24 +08:00
|
|
|
#include "llvm/ADT/SmallPtrSet.h"
|
2012-12-04 17:13:33 +08:00
|
|
|
#include "llvm/ADT/StringMap.h"
|
2013-01-02 19:45:17 +08:00
|
|
|
#include "llvm/IR/Module.h"
|
2014-03-04 19:18:19 +08:00
|
|
|
#include "llvm/IR/ValueHandle.h"
|
2016-01-16 08:31:22 +08:00
|
|
|
#include "llvm/Transforms/Utils/SanitizerStats.h"
|
2009-01-04 10:08:04 +08:00
|
|
|
|
2007-05-24 14:29:05 +08:00
|
|
|
namespace llvm {
|
2014-05-09 08:57:59 +08:00
|
|
|
class Module;
|
|
|
|
class Constant;
|
|
|
|
class ConstantInt;
|
|
|
|
class Function;
|
|
|
|
class GlobalValue;
|
|
|
|
class DataLayout;
|
|
|
|
class FunctionType;
|
|
|
|
class LLVMContext;
|
[OpenMP] Use the OpenMP-IR-Builder
This is a follow up patch to use the OpenMP-IR-Builder, as discussed on
the mailing list ([1] and later) and at the US Dev Meeting'19.
[1] http://lists.flang-compiler.org/pipermail/flang-dev_lists.flang-compiler.org/2019-May/000197.html
Reviewers: kiranchandramohan, ABataev, RaviNarayanaswamy, gtbercea, grokos, sdmitriev, JonChesterfield, hfinkel, fghanim
Subscribers: ppenzin, penzn, llvm-commits, cfe-commits, jfb, guansong, bollu, hiraditya, mgorny
Tags: #clang
Differential Revision: https://reviews.llvm.org/D69922
2019-11-05 13:00:36 +08:00
|
|
|
class OpenMPIRBuilder;
|
2014-05-09 08:57:59 +08:00
|
|
|
class IndexedInstrProfReader;
|
2015-06-23 07:07:51 +08:00
|
|
|
}
|
2007-06-16 07:05:46 +08:00
|
|
|
|
2007-05-24 14:29:05 +08:00
|
|
|
namespace clang {
|
2014-05-09 08:57:59 +08:00
|
|
|
class ASTContext;
|
|
|
|
class AtomicType;
|
|
|
|
class FunctionDecl;
|
|
|
|
class IdentifierInfo;
|
|
|
|
class ObjCMethodDecl;
|
|
|
|
class ObjCImplementationDecl;
|
|
|
|
class ObjCCategoryImplDecl;
|
|
|
|
class ObjCProtocolDecl;
|
|
|
|
class ObjCEncodeExpr;
|
|
|
|
class BlockExpr;
|
|
|
|
class CharUnits;
|
|
|
|
class Decl;
|
|
|
|
class Expr;
|
|
|
|
class Stmt;
|
|
|
|
class InitListExpr;
|
|
|
|
class StringLiteral;
|
|
|
|
class NamedDecl;
|
|
|
|
class ValueDecl;
|
|
|
|
class VarDecl;
|
|
|
|
class LangOptions;
|
|
|
|
class CodeGenOptions;
|
2015-06-30 10:26:03 +08:00
|
|
|
class HeaderSearchOptions;
|
2014-05-09 08:57:59 +08:00
|
|
|
class DiagnosticsEngine;
|
|
|
|
class AnnotateAttr;
|
|
|
|
class CXXDestructorDecl;
|
|
|
|
class Module;
|
2014-08-05 02:41:51 +08:00
|
|
|
class CoverageSourceInfo;
|
2019-12-10 08:11:56 +08:00
|
|
|
class TargetAttr;
|
|
|
|
class InitSegAttr;
|
|
|
|
struct ParsedTargetAttr;
|
2009-02-14 03:12:34 +08:00
|
|
|
|
2007-05-24 14:29:05 +08:00
|
|
|
namespace CodeGen {
|
|
|
|
|
2014-05-09 08:57:59 +08:00
|
|
|
class CallArgList;
|
|
|
|
class CodeGenFunction;
|
|
|
|
class CodeGenTBAA;
|
|
|
|
class CGCXXABI;
|
|
|
|
class CGDebugInfo;
|
|
|
|
class CGObjCRuntime;
|
|
|
|
class CGOpenCLRuntime;
|
|
|
|
class CGOpenMPRuntime;
|
|
|
|
class CGCUDARuntime;
|
|
|
|
class BlockFieldFlags;
|
|
|
|
class FunctionArgList;
|
2014-08-05 02:41:51 +08:00
|
|
|
class CoverageMappingModuleGen;
|
2016-04-05 02:33:08 +08:00
|
|
|
class TargetCodeGenInfo;
|
2014-05-09 08:57:59 +08:00
|
|
|
|
2016-12-01 07:25:13 +08:00
|
|
|
enum ForDefinition_t : bool {
|
|
|
|
NotForDefinition = false,
|
|
|
|
ForDefinition = true
|
|
|
|
};
|
|
|
|
|
2014-05-09 08:57:59 +08:00
|
|
|
struct OrderGlobalInits {
|
|
|
|
unsigned int priority;
|
|
|
|
unsigned int lex_order;
|
|
|
|
OrderGlobalInits(unsigned int p, unsigned int l)
|
2010-06-27 14:32:58 +08:00
|
|
|
: priority(p), lex_order(l) {}
|
2014-05-09 08:57:59 +08:00
|
|
|
|
|
|
|
bool operator==(const OrderGlobalInits &RHS) const {
|
|
|
|
return priority == RHS.priority && lex_order == RHS.lex_order;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator<(const OrderGlobalInits &RHS) const {
|
|
|
|
return std::tie(priority, lex_order) <
|
|
|
|
std::tie(RHS.priority, RHS.lex_order);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-10-22 02:06:43 +08:00
|
|
|
struct ObjCEntrypoints {
|
|
|
|
ObjCEntrypoints() { memset(this, 0, sizeof(*this)); }
|
|
|
|
|
2018-12-08 13:13:50 +08:00
|
|
|
/// void objc_alloc(id);
|
2019-02-06 00:42:33 +08:00
|
|
|
llvm::FunctionCallee objc_alloc;
|
2018-12-08 13:13:50 +08:00
|
|
|
|
|
|
|
/// void objc_allocWithZone(id);
|
2019-02-06 00:42:33 +08:00
|
|
|
llvm::FunctionCallee objc_allocWithZone;
|
2018-12-08 13:13:50 +08:00
|
|
|
|
2019-02-15 03:58:37 +08:00
|
|
|
/// void objc_alloc_init(id);
|
|
|
|
llvm::FunctionCallee objc_alloc_init;
|
|
|
|
|
2018-12-08 13:13:50 +08:00
|
|
|
/// void objc_autoreleasePoolPop(void*);
|
2019-02-06 00:42:33 +08:00
|
|
|
llvm::FunctionCallee objc_autoreleasePoolPop;
|
2011-06-16 07:02:42 +08:00
|
|
|
|
2018-12-19 04:33:00 +08:00
|
|
|
/// void objc_autoreleasePoolPop(void*);
|
|
|
|
/// Note this method is used when we are using exception handling
|
2019-02-06 00:42:33 +08:00
|
|
|
llvm::FunctionCallee objc_autoreleasePoolPopInvoke;
|
2018-12-19 04:33:00 +08:00
|
|
|
|
2011-06-16 07:02:42 +08:00
|
|
|
/// void *objc_autoreleasePoolPush(void);
|
2019-02-06 00:42:33 +08:00
|
|
|
llvm::Function *objc_autoreleasePoolPush;
|
2011-06-16 07:02:42 +08:00
|
|
|
|
|
|
|
/// id objc_autorelease(id);
|
2019-02-06 00:42:33 +08:00
|
|
|
llvm::Function *objc_autorelease;
|
2011-06-16 07:02:42 +08:00
|
|
|
|
2018-12-22 05:00:32 +08:00
|
|
|
/// id objc_autorelease(id);
|
|
|
|
/// Note this is the runtime method not the intrinsic.
|
2019-02-06 00:42:33 +08:00
|
|
|
llvm::FunctionCallee objc_autoreleaseRuntimeFunction;
|
2018-12-22 05:00:32 +08:00
|
|
|
|
2011-06-16 07:02:42 +08:00
|
|
|
/// id objc_autoreleaseReturnValue(id);
|
2019-02-06 00:42:33 +08:00
|
|
|
llvm::Function *objc_autoreleaseReturnValue;
|
2011-06-16 07:02:42 +08:00
|
|
|
|
|
|
|
/// void objc_copyWeak(id *dest, id *src);
|
2019-02-06 00:42:33 +08:00
|
|
|
llvm::Function *objc_copyWeak;
|
2011-06-16 07:02:42 +08:00
|
|
|
|
|
|
|
/// void objc_destroyWeak(id*);
|
2019-02-06 00:42:33 +08:00
|
|
|
llvm::Function *objc_destroyWeak;
|
2011-06-16 07:02:42 +08:00
|
|
|
|
|
|
|
/// id objc_initWeak(id*, id);
|
2019-02-06 00:42:33 +08:00
|
|
|
llvm::Function *objc_initWeak;
|
2011-06-16 07:02:42 +08:00
|
|
|
|
|
|
|
/// id objc_loadWeak(id*);
|
2019-02-06 00:42:33 +08:00
|
|
|
llvm::Function *objc_loadWeak;
|
2011-06-16 07:02:42 +08:00
|
|
|
|
|
|
|
/// id objc_loadWeakRetained(id*);
|
2019-02-06 00:42:33 +08:00
|
|
|
llvm::Function *objc_loadWeakRetained;
|
2011-06-16 07:02:42 +08:00
|
|
|
|
|
|
|
/// void objc_moveWeak(id *dest, id *src);
|
2019-02-06 00:42:33 +08:00
|
|
|
llvm::Function *objc_moveWeak;
|
2011-06-16 07:02:42 +08:00
|
|
|
|
|
|
|
/// id objc_retain(id);
|
2019-02-06 00:42:33 +08:00
|
|
|
llvm::Function *objc_retain;
|
2011-06-16 07:02:42 +08:00
|
|
|
|
2018-12-22 05:00:32 +08:00
|
|
|
/// id objc_retain(id);
|
|
|
|
/// Note this is the runtime method not the intrinsic.
|
2019-02-06 00:42:33 +08:00
|
|
|
llvm::FunctionCallee objc_retainRuntimeFunction;
|
2018-12-22 05:00:32 +08:00
|
|
|
|
2011-06-16 07:02:42 +08:00
|
|
|
/// id objc_retainAutorelease(id);
|
2019-02-06 00:42:33 +08:00
|
|
|
llvm::Function *objc_retainAutorelease;
|
2011-06-16 07:02:42 +08:00
|
|
|
|
|
|
|
/// id objc_retainAutoreleaseReturnValue(id);
|
2019-02-06 00:42:33 +08:00
|
|
|
llvm::Function *objc_retainAutoreleaseReturnValue;
|
2011-06-16 07:02:42 +08:00
|
|
|
|
|
|
|
/// id objc_retainAutoreleasedReturnValue(id);
|
2019-02-06 00:42:33 +08:00
|
|
|
llvm::Function *objc_retainAutoreleasedReturnValue;
|
2011-06-16 07:02:42 +08:00
|
|
|
|
|
|
|
/// id objc_retainBlock(id);
|
2019-02-06 00:42:33 +08:00
|
|
|
llvm::Function *objc_retainBlock;
|
2011-06-16 07:02:42 +08:00
|
|
|
|
|
|
|
/// void objc_release(id);
|
2019-02-06 00:42:33 +08:00
|
|
|
llvm::Function *objc_release;
|
2011-06-16 07:02:42 +08:00
|
|
|
|
2018-12-22 05:00:32 +08:00
|
|
|
/// void objc_release(id);
|
|
|
|
/// Note this is the runtime method not the intrinsic.
|
2019-02-06 00:42:33 +08:00
|
|
|
llvm::FunctionCallee objc_releaseRuntimeFunction;
|
2018-12-22 05:00:32 +08:00
|
|
|
|
2017-02-12 01:24:09 +08:00
|
|
|
/// void objc_storeStrong(id*, id);
|
2019-02-06 00:42:33 +08:00
|
|
|
llvm::Function *objc_storeStrong;
|
2011-06-16 07:02:42 +08:00
|
|
|
|
|
|
|
/// id objc_storeWeak(id*, id);
|
2019-02-06 00:42:33 +08:00
|
|
|
llvm::Function *objc_storeWeak;
|
2011-06-16 07:02:42 +08:00
|
|
|
|
2016-01-28 02:32:30 +08:00
|
|
|
/// id objc_unsafeClaimAutoreleasedReturnValue(id);
|
2019-02-06 00:42:33 +08:00
|
|
|
llvm::Function *objc_unsafeClaimAutoreleasedReturnValue;
|
2016-01-28 02:32:30 +08:00
|
|
|
|
2011-06-16 07:02:42 +08:00
|
|
|
/// A void(void) inline asm to use to mark that the return value of
|
|
|
|
/// a call will be immediately retain.
|
|
|
|
llvm::InlineAsm *retainAutoreleasedReturnValueMarker;
|
2013-03-23 10:35:54 +08:00
|
|
|
|
|
|
|
/// void clang.arc.use(...);
|
2019-02-06 00:42:33 +08:00
|
|
|
llvm::Function *clang_arc_use;
|
2021-02-11 06:47:06 +08:00
|
|
|
|
|
|
|
/// void clang.arc.noop.use(...);
|
|
|
|
llvm::Function *clang_arc_noop_use;
|
2011-06-16 07:02:42 +08:00
|
|
|
};
|
2013-01-18 19:30:38 +08:00
|
|
|
|
2014-04-16 05:22:35 +08:00
|
|
|
/// This class records statistics on instrumentation based profiling.
|
2014-06-26 09:45:07 +08:00
|
|
|
class InstrProfStats {
|
|
|
|
uint32_t VisitedInMainFile;
|
|
|
|
uint32_t MissingInMainFile;
|
2014-04-16 05:22:35 +08:00
|
|
|
uint32_t Visited;
|
|
|
|
uint32_t Missing;
|
|
|
|
uint32_t Mismatched;
|
2014-06-26 09:45:07 +08:00
|
|
|
|
|
|
|
public:
|
|
|
|
InstrProfStats()
|
|
|
|
: VisitedInMainFile(0), MissingInMainFile(0), Visited(0), Missing(0),
|
|
|
|
Mismatched(0) {}
|
|
|
|
/// Record that we've visited a function and whether or not that function was
|
|
|
|
/// in the main source file.
|
|
|
|
void addVisited(bool MainFile) {
|
|
|
|
if (MainFile)
|
|
|
|
++VisitedInMainFile;
|
|
|
|
++Visited;
|
|
|
|
}
|
|
|
|
/// Record that a function we've visited has no profile data.
|
|
|
|
void addMissing(bool MainFile) {
|
|
|
|
if (MainFile)
|
|
|
|
++MissingInMainFile;
|
|
|
|
++Missing;
|
|
|
|
}
|
|
|
|
/// Record that a function we've visited has mismatched profile data.
|
|
|
|
void addMismatched(bool MainFile) { ++Mismatched; }
|
|
|
|
/// Whether or not the stats we've gathered indicate any potential problems.
|
|
|
|
bool hasDiagnostics() { return Missing || Mismatched; }
|
|
|
|
/// Report potential problems we've found to \c Diags.
|
|
|
|
void reportDiagnostics(DiagnosticsEngine &Diags, StringRef MainFile);
|
2014-04-16 05:22:35 +08:00
|
|
|
};
|
|
|
|
|
2015-09-08 16:21:11 +08:00
|
|
|
/// A pair of helper functions for a __block variable.
|
|
|
|
class BlockByrefHelpers : public llvm::FoldingSetNode {
|
|
|
|
// MSVC requires this type to be complete in order to process this
|
|
|
|
// header.
|
|
|
|
public:
|
|
|
|
llvm::Constant *CopyHelper;
|
|
|
|
llvm::Constant *DisposeHelper;
|
|
|
|
|
|
|
|
/// The alignment of the field. This is important because
|
|
|
|
/// different offsets to the field within the byref struct need to
|
|
|
|
/// have different helper functions.
|
|
|
|
CharUnits Alignment;
|
|
|
|
|
2019-05-21 19:37:54 +08:00
|
|
|
BlockByrefHelpers(CharUnits alignment)
|
|
|
|
: CopyHelper(nullptr), DisposeHelper(nullptr), Alignment(alignment) {}
|
2015-09-08 16:21:11 +08:00
|
|
|
BlockByrefHelpers(const BlockByrefHelpers &) = default;
|
|
|
|
virtual ~BlockByrefHelpers();
|
|
|
|
|
|
|
|
void Profile(llvm::FoldingSetNodeID &id) const {
|
|
|
|
id.AddInteger(Alignment.getQuantity());
|
|
|
|
profileImpl(id);
|
|
|
|
}
|
|
|
|
virtual void profileImpl(llvm::FoldingSetNodeID &id) const = 0;
|
|
|
|
|
|
|
|
virtual bool needsCopy() const { return true; }
|
|
|
|
virtual void emitCopy(CodeGenFunction &CGF, Address dest, Address src) = 0;
|
|
|
|
|
|
|
|
virtual bool needsDispose() const { return true; }
|
|
|
|
virtual void emitDispose(CodeGenFunction &CGF, Address field) = 0;
|
|
|
|
};
|
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// This class organizes the cross-function state that is used while generating
|
|
|
|
/// LLVM code.
|
2011-02-15 17:22:45 +08:00
|
|
|
class CodeGenModule : public CodeGenTypeCache {
|
2015-02-16 06:54:08 +08:00
|
|
|
CodeGenModule(const CodeGenModule &) = delete;
|
|
|
|
void operator=(const CodeGenModule &) = delete;
|
2009-02-24 12:21:31 +08:00
|
|
|
|
2014-12-30 16:12:39 +08:00
|
|
|
public:
|
2014-05-24 05:13:45 +08:00
|
|
|
struct Structor {
|
|
|
|
Structor() : Priority(0), Initializer(nullptr), AssociatedData(nullptr) {}
|
|
|
|
Structor(int Priority, llvm::Constant *Initializer,
|
|
|
|
llvm::Constant *AssociatedData)
|
|
|
|
: Priority(Priority), Initializer(Initializer),
|
|
|
|
AssociatedData(AssociatedData) {}
|
|
|
|
int Priority;
|
|
|
|
llvm::Constant *Initializer;
|
|
|
|
llvm::Constant *AssociatedData;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef std::vector<Structor> CtorList;
|
2008-08-01 08:01:51 +08:00
|
|
|
|
2014-12-30 16:12:39 +08:00
|
|
|
private:
|
2007-05-24 14:29:05 +08:00
|
|
|
ASTContext &Context;
|
2012-03-11 15:00:24 +08:00
|
|
|
const LangOptions &LangOpts;
|
2015-06-30 10:26:03 +08:00
|
|
|
const HeaderSearchOptions &HeaderSearchOpts; // Only used for debug info.
|
|
|
|
const PreprocessorOptions &PreprocessorOpts; // Only used for debug info.
|
2009-11-13 01:24:48 +08:00
|
|
|
const CodeGenOptions &CodeGenOpts;
|
Add a flag to debug automatic variable initialization
Summary:
Add -ftrivial-auto-var-init-stop-after= to limit the number of times
stack variables are initialized when -ftrivial-auto-var-init= is used to
initialize stack variables to zero or a pattern. This flag can be used
to bisect uninitialized uses of a stack variable exposed by automatic
variable initialization, such as http://crrev.com/c/2020401.
Reviewers: jfb, vitalybuka, kcc, glider, rsmith, rjmccall, pcc, eugenis, vlad.tsyrklevich
Reviewed By: jfb
Subscribers: phosek, hubert.reinterpretcast, srhines, MaskRay, george.burgess.iv, dexonsmith, inglorion, gbiv, llozano, manojgupta, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D77168
2020-06-09 02:53:23 +08:00
|
|
|
unsigned NumAutoVarInit = 0;
|
2007-06-16 07:05:46 +08:00
|
|
|
llvm::Module &TheModule;
|
2011-09-26 07:23:43 +08:00
|
|
|
DiagnosticsEngine &Diags;
|
2013-04-17 06:48:15 +08:00
|
|
|
const TargetInfo &Target;
|
2014-03-08 04:03:18 +08:00
|
|
|
std::unique_ptr<CGCXXABI> ABI;
|
2013-04-17 06:48:15 +08:00
|
|
|
llvm::LLVMContext &VMContext;
|
2021-03-06 02:49:47 +08:00
|
|
|
std::string ModuleNameHash = "";
|
2009-10-07 09:06:45 +08:00
|
|
|
|
2016-04-14 07:37:17 +08:00
|
|
|
std::unique_ptr<CodeGenTBAA> TBAA;
|
2018-07-31 03:24:48 +08:00
|
|
|
|
2016-04-14 07:37:17 +08:00
|
|
|
mutable std::unique_ptr<TargetCodeGenInfo> TheTargetCodeGenInfo;
|
2018-07-31 03:24:48 +08:00
|
|
|
|
2013-04-17 06:48:15 +08:00
|
|
|
// This should not be moved earlier, since its initialization depends on some
|
|
|
|
// of the previous reference members being already initialized and also checks
|
|
|
|
// if TheTargetCodeGenInfo is NULL
|
|
|
|
CodeGenTypes Types;
|
2018-07-31 03:24:48 +08:00
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Holds information about C++ vtables.
|
2010-03-23 12:11:45 +08:00
|
|
|
CodeGenVTables VTables;
|
2010-04-09 00:07:47 +08:00
|
|
|
|
2016-04-14 07:37:17 +08:00
|
|
|
std::unique_ptr<CGObjCRuntime> ObjCRuntime;
|
|
|
|
std::unique_ptr<CGOpenCLRuntime> OpenCLRuntime;
|
|
|
|
std::unique_ptr<CGOpenMPRuntime> OpenMPRuntime;
|
|
|
|
std::unique_ptr<CGCUDARuntime> CUDARuntime;
|
|
|
|
std::unique_ptr<CGDebugInfo> DebugInfo;
|
|
|
|
std::unique_ptr<ObjCEntrypoints> ObjCData;
|
|
|
|
llvm::MDNode *NoObjCARCExceptionsMetadata = nullptr;
|
2014-04-19 05:52:00 +08:00
|
|
|
std::unique_ptr<llvm::IndexedInstrProfReader> PGOReader;
|
2014-04-16 05:22:35 +08:00
|
|
|
InstrProfStats PGOStats;
|
2016-01-16 08:31:22 +08:00
|
|
|
std::unique_ptr<llvm::SanitizerStatReport> SanStats;
|
2008-07-31 00:32:24 +08:00
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
// A set of references that have only been seen via a weakref so far. This is
|
|
|
|
// used to remove the weak of the reference if we ever see a direct reference
|
|
|
|
// or a definition.
|
2010-03-05 02:17:24 +08:00
|
|
|
llvm::SmallPtrSet<llvm::GlobalValue*, 10> WeakRefReferences;
|
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// This contains all the decls which have definitions but/ which are deferred
|
|
|
|
/// for emission and therefore should only be output if they are actually
|
|
|
|
/// used. If a decl is in this, then it is known to have not been referenced
|
|
|
|
/// yet.
|
2014-06-06 06:10:59 +08:00
|
|
|
std::map<StringRef, GlobalDecl> DeferredDecls;
|
2009-03-21 17:44:56 +08:00
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// This is a list of deferred decls which we have seen that *are* actually
|
|
|
|
/// referenced. These get code generated when the module is done.
|
2017-05-01 14:12:13 +08:00
|
|
|
std::vector<GlobalDecl> DeferredDeclsToEmit;
|
|
|
|
void addDeferredDeclToEmit(GlobalDecl GD) {
|
|
|
|
DeferredDeclsToEmit.emplace_back(GD);
|
2013-12-09 22:59:08 +08:00
|
|
|
}
|
2009-04-16 06:08:45 +08:00
|
|
|
|
2013-10-23 03:26:13 +08:00
|
|
|
/// List of alias we have emitted. Used to make sure that what they point to
|
|
|
|
/// is defined once we get to the end of the of the translation unit.
|
|
|
|
std::vector<GlobalDecl> Aliases;
|
|
|
|
|
Implement Attribute Target MultiVersioning
GCC's attribute 'target', in addition to being an optimization hint,
also allows function multiversioning. We currently have the former
implemented, this is the latter's implementation.
This works by enabling functions with the same name/signature to coexist,
so that they can all be emitted. Multiversion state is stored in the
FunctionDecl itself, and SemaDecl manages the definitions.
Note that it ends up having to permit redefinition of functions so
that they can all be emitted. Additionally, all versions of the function
must be emitted, so this also manages that.
Note that this includes some additional rules that GCC does not, since
defining something as a MultiVersion function after a usage has been made illegal.
The only 'history rewriting' that happens is if a function is emitted before
it has been converted to a multiversion'ed function, at which point its name
needs to be changed.
Function templates and virtual functions are NOT yet supported (not supported
in GCC either).
Additionally, constructors/destructors are disallowed, but the former is
planned.
llvm-svn: 322028
2018-01-09 05:34:17 +08:00
|
|
|
/// List of multiversion functions that have to be emitted. Used to make sure
|
|
|
|
/// we properly emit the iFunc.
|
|
|
|
std::vector<GlobalDecl> MultiVersionFuncs;
|
|
|
|
|
2013-11-06 05:37:29 +08:00
|
|
|
typedef llvm::StringMap<llvm::TrackingVH<llvm::Constant> > ReplacementsTy;
|
|
|
|
ReplacementsTy Replacements;
|
|
|
|
|
2015-08-31 21:20:44 +08:00
|
|
|
/// List of global values to be replaced with something else. Used when we
|
|
|
|
/// want to replace a GlobalValue but can't identify it by its mangled name
|
|
|
|
/// anymore (because the name is already taken).
|
|
|
|
llvm::SmallVector<std::pair<llvm::GlobalValue *, llvm::Constant *>, 8>
|
|
|
|
GlobalValReplacements;
|
|
|
|
|
2019-06-15 01:46:37 +08:00
|
|
|
/// Variables for which we've emitted globals containing their constant
|
|
|
|
/// values along with the corresponding globals, for opportunistic reuse.
|
|
|
|
llvm::DenseMap<const VarDecl*, llvm::GlobalVariable*> InitializerConstants;
|
|
|
|
|
2015-08-31 21:20:44 +08:00
|
|
|
/// Set of global decls for which we already diagnosed mangled name conflict.
|
|
|
|
/// Required to not issue a warning (on a mangling conflict) multiple times
|
|
|
|
/// for the same decl.
|
|
|
|
llvm::DenseSet<GlobalDecl> DiagnosedConflictingDefinitions;
|
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// A queue of (optional) vtables to consider emitting.
|
2013-01-26 06:31:03 +08:00
|
|
|
std::vector<const CXXRecordDecl*> DeferredVTables;
|
|
|
|
|
2017-06-01 16:04:05 +08:00
|
|
|
/// A queue of (optional) vtables that may be emitted opportunistically.
|
|
|
|
std::vector<const CXXRecordDecl *> OpportunisticVTables;
|
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// List of global values which are required to be present in the object file;
|
|
|
|
/// bitcast to i8*. This is used for forcing visibility of symbols which may
|
|
|
|
/// otherwise be optimized out.
|
2017-05-02 01:08:00 +08:00
|
|
|
std::vector<llvm::WeakTrackingVH> LLVMUsed;
|
|
|
|
std::vector<llvm::WeakTrackingVH> LLVMCompilerUsed;
|
2009-02-14 03:12:34 +08:00
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Store the list of global constructors and their respective priorities to
|
|
|
|
/// be emitted when the translation unit is complete.
|
2008-08-01 08:01:51 +08:00
|
|
|
CtorList GlobalCtors;
|
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Store the list of global destructors and their respective priorities to be
|
|
|
|
/// emitted when the translation unit is complete.
|
2008-08-01 08:01:51 +08:00
|
|
|
CtorList GlobalDtors;
|
|
|
|
|
2014-07-03 17:30:33 +08:00
|
|
|
/// An ordered map of canonical GlobalDecls to their mangled names.
|
|
|
|
llvm::MapVector<GlobalDecl, StringRef> MangledDeclNames;
|
2014-06-06 06:10:59 +08:00
|
|
|
llvm::StringMap<GlobalDecl, llvm::BumpPtrAllocator> Manglings;
|
|
|
|
|
2018-07-20 22:13:28 +08:00
|
|
|
// An ordered map of canonical GlobalDecls paired with the cpu-index for
|
|
|
|
// cpu-specific name manglings.
|
|
|
|
llvm::MapVector<std::pair<GlobalDecl, unsigned>, StringRef>
|
|
|
|
CPUSpecificMangledDeclNames;
|
|
|
|
llvm::StringMap<std::pair<GlobalDecl, unsigned>, llvm::BumpPtrAllocator>
|
|
|
|
CPUSpecificManglings;
|
|
|
|
|
2011-09-10 06:41:49 +08:00
|
|
|
/// Global annotations.
|
2008-04-19 07:43:57 +08:00
|
|
|
std::vector<llvm::Constant*> Annotations;
|
2009-02-14 03:12:34 +08:00
|
|
|
|
2011-09-10 06:41:49 +08:00
|
|
|
/// Map used to get unique annotation strings.
|
|
|
|
llvm::StringMap<llvm::Constant*> AnnotationStrings;
|
|
|
|
|
2020-10-26 16:58:20 +08:00
|
|
|
/// Used for uniquing of annotation arguments.
|
|
|
|
llvm::DenseMap<unsigned, llvm::Constant *> AnnotationArgs;
|
|
|
|
|
2015-04-06 06:47:07 +08:00
|
|
|
llvm::StringMap<llvm::GlobalVariable *> CFConstantStringMap;
|
2014-03-25 05:43:36 +08:00
|
|
|
|
2014-07-30 05:20:12 +08:00
|
|
|
llvm::DenseMap<llvm::Constant *, llvm::GlobalVariable *> ConstantStringMap;
|
2012-03-09 11:27:46 +08:00
|
|
|
llvm::DenseMap<const Decl*, llvm::Constant *> StaticLocalDeclMap;
|
2012-03-31 05:00:39 +08:00
|
|
|
llvm::DenseMap<const Decl*, llvm::GlobalVariable*> StaticLocalDeclGuardMap;
|
2013-06-05 08:46:14 +08:00
|
|
|
llvm::DenseMap<const Expr*, llvm::Constant *> MaterializedGlobalTemporaryMap;
|
|
|
|
|
2012-01-09 03:13:23 +08:00
|
|
|
llvm::DenseMap<QualType, llvm::Constant *> AtomicSetterHelperFnMap;
|
|
|
|
llvm::DenseMap<QualType, llvm::Constant *> AtomicGetterHelperFnMap;
|
2008-08-24 02:37:06 +08:00
|
|
|
|
2013-11-08 09:09:22 +08:00
|
|
|
/// Map used to get unique type descriptor constants for sanitizers.
|
|
|
|
llvm::DenseMap<QualType, llvm::Constant *> TypeDescriptorMap;
|
|
|
|
|
2013-04-06 13:00:46 +08:00
|
|
|
/// Map used to track internal linkage functions declared within
|
|
|
|
/// extern "C" regions.
|
2013-04-13 09:28:18 +08:00
|
|
|
typedef llvm::MapVector<IdentifierInfo *,
|
|
|
|
llvm::GlobalValue *> StaticExternCMap;
|
2013-04-06 13:00:46 +08:00
|
|
|
StaticExternCMap StaticExternCValues;
|
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// thread_local variables defined or used in this TU.
|
2015-12-01 09:10:48 +08:00
|
|
|
std::vector<const VarDecl *> CXXThreadLocals;
|
2013-04-20 00:42:07 +08:00
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// thread_local variables with initializers that need to run
|
2013-04-20 00:42:07 +08:00
|
|
|
/// before any thread_local variable in this TU is odr-used.
|
2014-10-05 13:05:40 +08:00
|
|
|
std::vector<llvm::Function *> CXXThreadLocalInits;
|
2015-12-01 09:10:48 +08:00
|
|
|
std::vector<const VarDecl *> CXXThreadLocalInitVars;
|
2013-04-20 00:42:07 +08:00
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Global variables with initializers that need to run before main.
|
2014-10-05 13:05:40 +08:00
|
|
|
std::vector<llvm::Function *> CXXGlobalInits;
|
2010-07-16 07:40:35 +08:00
|
|
|
|
|
|
|
/// When a C++ decl with an initializer is deferred, null is
|
|
|
|
/// appended to CXXGlobalInits, and the index of that null is placed
|
|
|
|
/// here so that the initializer will be performed in the correct
|
2015-04-15 09:08:06 +08:00
|
|
|
/// order. Once the decl is emitted, the index is replaced with ~0U to ensure
|
|
|
|
/// that we don't re-emit the initializer.
|
2010-07-16 07:40:35 +08:00
|
|
|
llvm::DenseMap<const Decl*, unsigned> DelayedCXXInitPosition;
|
2018-07-31 03:24:48 +08:00
|
|
|
|
2012-11-07 06:44:45 +08:00
|
|
|
typedef std::pair<OrderGlobalInits, llvm::Function*> GlobalInitData;
|
|
|
|
|
|
|
|
struct GlobalInitPriorityCmp {
|
|
|
|
bool operator()(const GlobalInitData &LHS,
|
|
|
|
const GlobalInitData &RHS) const {
|
|
|
|
return LHS.first.priority < RHS.first.priority;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Global variables with initializers whose order of initialization is set by
|
|
|
|
/// init_priority attribute.
|
2012-11-07 06:44:45 +08:00
|
|
|
SmallVector<GlobalInitData, 8> PrioritizedCXXGlobalInits;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Global destructor functions and arguments that need to run on termination.
|
2020-05-28 05:04:43 +08:00
|
|
|
/// When UseSinitAndSterm is set, it instead contains sterm finalizer
|
|
|
|
/// functions, which also run on unloading a shared library.
|
2019-02-07 09:14:17 +08:00
|
|
|
std::vector<
|
|
|
|
std::tuple<llvm::FunctionType *, llvm::WeakTrackingVH, llvm::Constant *>>
|
2020-05-28 05:04:43 +08:00
|
|
|
CXXGlobalDtorsOrStermFinalizers;
|
2010-03-20 12:15:41 +08:00
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// The complete set of modules that has been imported.
|
2013-01-15 01:21:00 +08:00
|
|
|
llvm::SetVector<clang::Module *> ImportedModules;
|
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// The set of modules for which the module initializers
|
2016-10-15 02:55:44 +08:00
|
|
|
/// have been emitted.
|
|
|
|
llvm::SmallPtrSet<clang::Module *, 16> EmittedModuleInitializers;
|
|
|
|
|
[ELF] Implement Dependent Libraries Feature
This patch implements a limited form of autolinking primarily designed to allow
either the --dependent-library compiler option, or "comment lib" pragmas (
https://docs.microsoft.com/en-us/cpp/preprocessor/comment-c-cpp?view=vs-2017) in
C/C++ e.g. #pragma comment(lib, "foo"), to cause an ELF linker to automatically
add the specified library to the link when processing the input file generated
by the compiler.
Currently this extension is unique to LLVM and LLD. However, care has been taken
to design this feature so that it could be supported by other ELF linkers.
The design goals were to provide:
- A simple linking model for developers to reason about.
- The ability to to override autolinking from the linker command line.
- Source code compatibility, where possible, with "comment lib" pragmas in other
environments (MSVC in particular).
Dependent library support is implemented differently for ELF platforms than on
the other platforms. Primarily this difference is that on ELF we pass the
dependent library specifiers directly to the linker without manipulating them.
This is in contrast to other platforms where they are mapped to a specific
linker option by the compiler. This difference is a result of the greater
variety of ELF linkers and the fact that ELF linkers tend to handle libraries in
a more complicated fashion than on other platforms. This forces us to defer
handling the specifiers to the linker.
In order to achieve a level of source code compatibility with other platforms
we have restricted this feature to work with libraries that meet the following
"reasonable" requirements:
1. There are no competing defined symbols in a given set of libraries, or
if they exist, the program owner doesn't care which is linked to their
program.
2. There may be circular dependencies between libraries.
The binary representation is a mergeable string section (SHF_MERGE,
SHF_STRINGS), called .deplibs, with custom type SHT_LLVM_DEPENDENT_LIBRARIES
(0x6fff4c04). The compiler forms this section by concatenating the arguments of
the "comment lib" pragmas and --dependent-library options in the order they are
encountered. Partial (-r, -Ur) links are handled by concatenating .deplibs
sections with the normal mergeable string section rules. As an example, #pragma
comment(lib, "foo") would result in:
.section ".deplibs","MS",@llvm_dependent_libraries,1
.asciz "foo"
For LTO, equivalent information to the contents of a the .deplibs section can be
retrieved by the LLD for bitcode input files.
LLD processes the dependent library specifiers in the following way:
1. Dependent libraries which are found from the specifiers in .deplibs sections
of relocatable object files are added when the linker decides to include that
file (which could itself be in a library) in the link. Dependent libraries
behave as if they were appended to the command line after all other options. As
a consequence the set of dependent libraries are searched last to resolve
symbols.
2. It is an error if a file cannot be found for a given specifier.
3. Any command line options in effect at the end of the command line parsing apply
to the dependent libraries, e.g. --whole-archive.
4. The linker tries to add a library or relocatable object file from each of the
strings in a .deplibs section by; first, handling the string as if it was
specified on the command line; second, by looking for the string in each of the
library search paths in turn; third, by looking for a lib<string>.a or
lib<string>.so (depending on the current mode of the linker) in each of the
library search paths.
5. A new command line option --no-dependent-libraries tells LLD to ignore the
dependent libraries.
Rationale for the above points:
1. Adding the dependent libraries last makes the process simple to understand
from a developers perspective. All linkers are able to implement this scheme.
2. Error-ing for libraries that are not found seems like better behavior than
failing the link during symbol resolution.
3. It seems useful for the user to be able to apply command line options which
will affect all of the dependent libraries. There is a potential problem of
surprise for developers, who might not realize that these options would apply
to these "invisible" input files; however, despite the potential for surprise,
this is easy for developers to reason about and gives developers the control
that they may require.
4. This algorithm takes into account all of the different ways that ELF linkers
find input files. The different search methods are tried by the linker in most
obvious to least obvious order.
5. I considered adding finer grained control over which dependent libraries were
ignored (e.g. MSVC has /nodefaultlib:<library>); however, I concluded that this
is not necessary: if finer control is required developers can fall back to using
the command line directly.
RFC thread: http://lists.llvm.org/pipermail/llvm-dev/2019-March/131004.html.
Differential Revision: https://reviews.llvm.org/D60274
llvm-svn: 360984
2019-05-17 11:44:15 +08:00
|
|
|
/// A vector of metadata strings for linker options.
|
2017-06-13 04:10:48 +08:00
|
|
|
SmallVector<llvm::MDNode *, 16> LinkerOptionsMetadata;
|
2013-05-08 21:44:39 +08:00
|
|
|
|
[ELF] Implement Dependent Libraries Feature
This patch implements a limited form of autolinking primarily designed to allow
either the --dependent-library compiler option, or "comment lib" pragmas (
https://docs.microsoft.com/en-us/cpp/preprocessor/comment-c-cpp?view=vs-2017) in
C/C++ e.g. #pragma comment(lib, "foo"), to cause an ELF linker to automatically
add the specified library to the link when processing the input file generated
by the compiler.
Currently this extension is unique to LLVM and LLD. However, care has been taken
to design this feature so that it could be supported by other ELF linkers.
The design goals were to provide:
- A simple linking model for developers to reason about.
- The ability to to override autolinking from the linker command line.
- Source code compatibility, where possible, with "comment lib" pragmas in other
environments (MSVC in particular).
Dependent library support is implemented differently for ELF platforms than on
the other platforms. Primarily this difference is that on ELF we pass the
dependent library specifiers directly to the linker without manipulating them.
This is in contrast to other platforms where they are mapped to a specific
linker option by the compiler. This difference is a result of the greater
variety of ELF linkers and the fact that ELF linkers tend to handle libraries in
a more complicated fashion than on other platforms. This forces us to defer
handling the specifiers to the linker.
In order to achieve a level of source code compatibility with other platforms
we have restricted this feature to work with libraries that meet the following
"reasonable" requirements:
1. There are no competing defined symbols in a given set of libraries, or
if they exist, the program owner doesn't care which is linked to their
program.
2. There may be circular dependencies between libraries.
The binary representation is a mergeable string section (SHF_MERGE,
SHF_STRINGS), called .deplibs, with custom type SHT_LLVM_DEPENDENT_LIBRARIES
(0x6fff4c04). The compiler forms this section by concatenating the arguments of
the "comment lib" pragmas and --dependent-library options in the order they are
encountered. Partial (-r, -Ur) links are handled by concatenating .deplibs
sections with the normal mergeable string section rules. As an example, #pragma
comment(lib, "foo") would result in:
.section ".deplibs","MS",@llvm_dependent_libraries,1
.asciz "foo"
For LTO, equivalent information to the contents of a the .deplibs section can be
retrieved by the LLD for bitcode input files.
LLD processes the dependent library specifiers in the following way:
1. Dependent libraries which are found from the specifiers in .deplibs sections
of relocatable object files are added when the linker decides to include that
file (which could itself be in a library) in the link. Dependent libraries
behave as if they were appended to the command line after all other options. As
a consequence the set of dependent libraries are searched last to resolve
symbols.
2. It is an error if a file cannot be found for a given specifier.
3. Any command line options in effect at the end of the command line parsing apply
to the dependent libraries, e.g. --whole-archive.
4. The linker tries to add a library or relocatable object file from each of the
strings in a .deplibs section by; first, handling the string as if it was
specified on the command line; second, by looking for the string in each of the
library search paths in turn; third, by looking for a lib<string>.a or
lib<string>.so (depending on the current mode of the linker) in each of the
library search paths.
5. A new command line option --no-dependent-libraries tells LLD to ignore the
dependent libraries.
Rationale for the above points:
1. Adding the dependent libraries last makes the process simple to understand
from a developers perspective. All linkers are able to implement this scheme.
2. Error-ing for libraries that are not found seems like better behavior than
failing the link during symbol resolution.
3. It seems useful for the user to be able to apply command line options which
will affect all of the dependent libraries. There is a potential problem of
surprise for developers, who might not realize that these options would apply
to these "invisible" input files; however, despite the potential for surprise,
this is easy for developers to reason about and gives developers the control
that they may require.
4. This algorithm takes into account all of the different ways that ELF linkers
find input files. The different search methods are tried by the linker in most
obvious to least obvious order.
5. I considered adding finer grained control over which dependent libraries were
ignored (e.g. MSVC has /nodefaultlib:<library>); however, I concluded that this
is not necessary: if finer control is required developers can fall back to using
the command line directly.
RFC thread: http://lists.llvm.org/pipermail/llvm-dev/2019-March/131004.html.
Differential Revision: https://reviews.llvm.org/D60274
llvm-svn: 360984
2019-05-17 11:44:15 +08:00
|
|
|
/// A vector of metadata strings for dependent libraries for ELF.
|
|
|
|
SmallVector<llvm::MDNode *, 16> ELFDependentLibraries;
|
|
|
|
|
2011-08-09 23:54:21 +08:00
|
|
|
/// @name Cache for Objective-C runtime types
|
|
|
|
/// @{
|
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Cached reference to the class for constant strings. This value has type
|
|
|
|
/// int * but is actually an Obj-C class pointer.
|
2017-05-02 01:08:00 +08:00
|
|
|
llvm::WeakTrackingVH CFConstantStringClassRef;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// The type used to describe the state of a fast enumeration in
|
2011-08-10 01:23:49 +08:00
|
|
|
/// Objective-C's for..in loop.
|
|
|
|
QualType ObjCFastEnumerationStateType;
|
2018-07-31 03:24:48 +08:00
|
|
|
|
2011-08-09 23:54:21 +08:00
|
|
|
/// @}
|
|
|
|
|
2010-01-23 10:40:42 +08:00
|
|
|
/// Lazily create the Objective-C runtime
|
|
|
|
void createObjCRuntime();
|
|
|
|
|
2011-09-20 05:14:35 +08:00
|
|
|
void createOpenCLRuntime();
|
2014-05-06 18:08:46 +08:00
|
|
|
void createOpenMPRuntime();
|
2011-10-07 02:29:37 +08:00
|
|
|
void createCUDARuntime();
|
2011-09-20 05:14:35 +08:00
|
|
|
|
2011-12-19 22:41:01 +08:00
|
|
|
bool isTriviallyRecursive(const FunctionDecl *F);
|
2013-06-06 01:49:37 +08:00
|
|
|
bool shouldEmitFunction(GlobalDecl GD);
|
2017-06-01 16:04:05 +08:00
|
|
|
bool shouldOpportunisticallyEmitVTables();
|
2016-12-28 15:27:40 +08:00
|
|
|
/// Map used to be sure we don't emit the same CompoundLiteral twice.
|
|
|
|
llvm::DenseMap<const CompoundLiteralExpr *, llvm::GlobalVariable *>
|
|
|
|
EmittedCompoundLiterals;
|
|
|
|
|
2016-12-22 10:50:20 +08:00
|
|
|
/// Map of the global blocks we've emitted, so that we don't have to re-emit
|
|
|
|
/// them if the constexpr evaluator gets aggressive.
|
|
|
|
llvm::DenseMap<const BlockExpr *, llvm::Constant *> EmittedGlobalBlocks;
|
|
|
|
|
2010-07-16 08:00:15 +08:00
|
|
|
/// @name Cache for Blocks Runtime Globals
|
|
|
|
/// @{
|
|
|
|
|
2016-04-14 07:37:17 +08:00
|
|
|
llvm::Constant *NSConcreteGlobalBlock = nullptr;
|
|
|
|
llvm::Constant *NSConcreteStackBlock = nullptr;
|
2010-07-16 08:00:19 +08:00
|
|
|
|
2019-02-06 00:42:33 +08:00
|
|
|
llvm::FunctionCallee BlockObjectAssign = nullptr;
|
|
|
|
llvm::FunctionCallee BlockObjectDispose = nullptr;
|
2010-07-16 08:00:15 +08:00
|
|
|
|
2016-04-14 07:37:17 +08:00
|
|
|
llvm::Type *BlockDescriptorType = nullptr;
|
|
|
|
llvm::Type *GenericBlockLiteralType = nullptr;
|
2011-02-08 16:22:06 +08:00
|
|
|
|
|
|
|
struct {
|
|
|
|
int GlobalUniqueCount;
|
|
|
|
} Block;
|
2013-01-18 19:30:38 +08:00
|
|
|
|
2019-11-08 04:46:26 +08:00
|
|
|
GlobalDecl initializedGlobalDecl;
|
|
|
|
|
|
|
|
/// @}
|
|
|
|
|
2013-03-23 14:43:35 +08:00
|
|
|
/// void @llvm.lifetime.start(i64 %size, i8* nocapture <ptr>)
|
2019-02-06 03:17:50 +08:00
|
|
|
llvm::Function *LifetimeStartFn = nullptr;
|
2013-03-23 14:43:35 +08:00
|
|
|
|
|
|
|
/// void @llvm.lifetime.end(i64 %size, i8* nocapture <ptr>)
|
2019-02-06 03:17:50 +08:00
|
|
|
llvm::Function *LifetimeEndFn = nullptr;
|
2013-03-23 14:43:35 +08:00
|
|
|
|
2014-08-02 05:35:28 +08:00
|
|
|
std::unique_ptr<SanitizerMetadata> SanitizerMD;
|
|
|
|
|
2017-12-13 08:14:17 +08:00
|
|
|
llvm::MapVector<const Decl *, bool> DeferredEmptyCoverageMappingDecls;
|
2014-08-05 02:41:51 +08:00
|
|
|
|
|
|
|
std::unique_ptr<CoverageMappingModuleGen> CoverageMapping;
|
2015-09-09 07:01:30 +08:00
|
|
|
|
|
|
|
/// Mapping from canonical types to their metadata identifiers. We need to
|
|
|
|
/// maintain this mapping because identifiers may be formed from distinct
|
|
|
|
/// MDNodes.
|
2017-11-01 06:39:44 +08:00
|
|
|
typedef llvm::DenseMap<QualType, llvm::Metadata *> MetadataTypeMap;
|
|
|
|
MetadataTypeMap MetadataIdMap;
|
2018-06-26 10:15:47 +08:00
|
|
|
MetadataTypeMap VirtualMetadataIdMap;
|
2017-11-01 06:39:44 +08:00
|
|
|
MetadataTypeMap GeneralizedMetadataIdMap;
|
2015-09-09 07:01:30 +08:00
|
|
|
|
2007-05-24 14:29:05 +08:00
|
|
|
public:
|
2015-07-25 00:04:29 +08:00
|
|
|
CodeGenModule(ASTContext &C, const HeaderSearchOptions &headersearchopts,
|
2015-06-30 10:26:03 +08:00
|
|
|
const PreprocessorOptions &ppopts,
|
2015-07-25 00:04:29 +08:00
|
|
|
const CodeGenOptions &CodeGenOpts, llvm::Module &M,
|
2014-08-05 02:41:51 +08:00
|
|
|
DiagnosticsEngine &Diags,
|
|
|
|
CoverageSourceInfo *CoverageInfo = nullptr);
|
2008-08-06 02:50:11 +08:00
|
|
|
|
2008-03-01 16:45:05 +08:00
|
|
|
~CodeGenModule();
|
2009-02-14 03:12:34 +08:00
|
|
|
|
2013-12-09 22:59:08 +08:00
|
|
|
void clear();
|
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Finalize LLVM code generation.
|
2008-08-06 02:50:11 +08:00
|
|
|
void Release();
|
2008-08-12 02:12:00 +08:00
|
|
|
|
2017-09-12 06:11:57 +08:00
|
|
|
/// Return true if we should emit location information for expressions.
|
|
|
|
bool getExpressionLocationsEnabled() const;
|
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Return a reference to the configured Objective-C runtime.
|
2009-02-14 03:12:34 +08:00
|
|
|
CGObjCRuntime &getObjCRuntime() {
|
2011-07-28 04:29:46 +08:00
|
|
|
if (!ObjCRuntime) createObjCRuntime();
|
|
|
|
return *ObjCRuntime;
|
2008-08-12 02:12:00 +08:00
|
|
|
}
|
2009-02-14 03:12:34 +08:00
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Return true iff an Objective-C runtime has been configured.
|
2011-07-28 04:29:46 +08:00
|
|
|
bool hasObjCRuntime() { return !!ObjCRuntime; }
|
2008-08-12 02:12:00 +08:00
|
|
|
|
2021-03-06 02:49:47 +08:00
|
|
|
const std::string &getModuleNameHash() const { return ModuleNameHash; }
|
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Return a reference to the configured OpenCL runtime.
|
2011-09-20 05:14:35 +08:00
|
|
|
CGOpenCLRuntime &getOpenCLRuntime() {
|
2014-05-21 13:09:00 +08:00
|
|
|
assert(OpenCLRuntime != nullptr);
|
2011-09-20 05:14:35 +08:00
|
|
|
return *OpenCLRuntime;
|
|
|
|
}
|
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Return a reference to the configured OpenMP runtime.
|
2014-05-06 18:08:46 +08:00
|
|
|
CGOpenMPRuntime &getOpenMPRuntime() {
|
|
|
|
assert(OpenMPRuntime != nullptr);
|
|
|
|
return *OpenMPRuntime;
|
|
|
|
}
|
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Return a reference to the configured CUDA runtime.
|
2011-10-07 02:29:37 +08:00
|
|
|
CGCUDARuntime &getCUDARuntime() {
|
2014-05-21 13:09:00 +08:00
|
|
|
assert(CUDARuntime != nullptr);
|
2011-10-07 02:29:37 +08:00
|
|
|
return *CUDARuntime;
|
|
|
|
}
|
|
|
|
|
2015-10-22 02:06:43 +08:00
|
|
|
ObjCEntrypoints &getObjCEntrypoints() const {
|
|
|
|
assert(ObjCData != nullptr);
|
|
|
|
return *ObjCData;
|
2011-06-16 07:02:42 +08:00
|
|
|
}
|
|
|
|
|
2020-10-29 13:48:59 +08:00
|
|
|
// Version checking functions, used to implement ObjC's @available:
|
2017-02-24 05:08:08 +08:00
|
|
|
// i32 @__isOSVersionAtLeast(i32, i32, i32)
|
2019-02-06 00:42:33 +08:00
|
|
|
llvm::FunctionCallee IsOSVersionAtLeastFn = nullptr;
|
2020-10-29 13:48:59 +08:00
|
|
|
// i32 @__isPlatformVersionAtLeast(i32, i32, i32, i32)
|
|
|
|
llvm::FunctionCallee IsPlatformVersionAtLeastFn = nullptr;
|
2017-02-24 05:08:08 +08:00
|
|
|
|
2014-04-19 05:52:00 +08:00
|
|
|
InstrProfStats &getPGOStats() { return PGOStats; }
|
|
|
|
llvm::IndexedInstrProfReader *getPGOReader() const { return PGOReader.get(); }
|
2014-01-07 06:27:43 +08:00
|
|
|
|
2014-08-05 02:41:51 +08:00
|
|
|
CoverageMappingModuleGen *getCoverageMapping() const {
|
|
|
|
return CoverageMapping.get();
|
|
|
|
}
|
|
|
|
|
2012-03-09 11:27:46 +08:00
|
|
|
llvm::Constant *getStaticLocalDeclAddress(const VarDecl *D) {
|
|
|
|
return StaticLocalDeclMap[D];
|
2010-04-19 05:01:23 +08:00
|
|
|
}
|
2018-07-31 03:24:48 +08:00
|
|
|
void setStaticLocalDeclAddress(const VarDecl *D,
|
2012-03-09 11:27:46 +08:00
|
|
|
llvm::Constant *C) {
|
|
|
|
StaticLocalDeclMap[D] = C;
|
2010-04-19 05:01:23 +08:00
|
|
|
}
|
|
|
|
|
2014-10-08 09:07:54 +08:00
|
|
|
llvm::Constant *
|
|
|
|
getOrCreateStaticVarDecl(const VarDecl &D,
|
|
|
|
llvm::GlobalValue::LinkageTypes Linkage);
|
|
|
|
|
2012-03-31 05:00:39 +08:00
|
|
|
llvm::GlobalVariable *getStaticLocalDeclGuardAddress(const VarDecl *D) {
|
|
|
|
return StaticLocalDeclGuardMap[D];
|
|
|
|
}
|
2018-07-31 03:24:48 +08:00
|
|
|
void setStaticLocalDeclGuardAddress(const VarDecl *D,
|
2012-03-31 05:00:39 +08:00
|
|
|
llvm::GlobalVariable *C) {
|
|
|
|
StaticLocalDeclGuardMap[D] = C;
|
|
|
|
}
|
|
|
|
|
2019-06-15 01:46:37 +08:00
|
|
|
Address createUnnamedGlobalFrom(const VarDecl &D, llvm::Constant *Constant,
|
|
|
|
CharUnits Align);
|
|
|
|
|
2014-06-06 06:10:59 +08:00
|
|
|
bool lookupRepresentativeDecl(StringRef MangledName,
|
|
|
|
GlobalDecl &Result) const;
|
|
|
|
|
2012-01-09 03:13:23 +08:00
|
|
|
llvm::Constant *getAtomicSetterHelperFnMap(QualType Ty) {
|
|
|
|
return AtomicSetterHelperFnMap[Ty];
|
2012-01-07 06:33:54 +08:00
|
|
|
}
|
2012-01-09 03:13:23 +08:00
|
|
|
void setAtomicSetterHelperFnMap(QualType Ty,
|
2012-01-07 06:33:54 +08:00
|
|
|
llvm::Constant *Fn) {
|
2012-01-09 03:13:23 +08:00
|
|
|
AtomicSetterHelperFnMap[Ty] = Fn;
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm::Constant *getAtomicGetterHelperFnMap(QualType Ty) {
|
|
|
|
return AtomicGetterHelperFnMap[Ty];
|
|
|
|
}
|
|
|
|
void setAtomicGetterHelperFnMap(QualType Ty,
|
|
|
|
llvm::Constant *Fn) {
|
|
|
|
AtomicGetterHelperFnMap[Ty] = Fn;
|
2012-01-07 06:33:54 +08:00
|
|
|
}
|
|
|
|
|
2014-05-24 00:07:43 +08:00
|
|
|
llvm::Constant *getTypeDescriptorFromMap(QualType Ty) {
|
2013-11-08 09:09:22 +08:00
|
|
|
return TypeDescriptorMap[Ty];
|
|
|
|
}
|
2014-05-24 00:07:43 +08:00
|
|
|
void setTypeDescriptorInMap(QualType Ty, llvm::Constant *C) {
|
2013-11-08 09:09:22 +08:00
|
|
|
TypeDescriptorMap[Ty] = C;
|
|
|
|
}
|
|
|
|
|
2016-04-14 07:37:17 +08:00
|
|
|
CGDebugInfo *getModuleDebugInfo() { return DebugInfo.get(); }
|
2011-03-08 02:29:53 +08:00
|
|
|
|
2012-02-16 08:57:37 +08:00
|
|
|
llvm::MDNode *getNoObjCARCExceptionsMetadata() {
|
|
|
|
if (!NoObjCARCExceptionsMetadata)
|
2014-12-10 02:39:32 +08:00
|
|
|
NoObjCARCExceptionsMetadata = llvm::MDNode::get(getLLVMContext(), None);
|
2012-02-16 08:57:37 +08:00
|
|
|
return NoObjCARCExceptionsMetadata;
|
|
|
|
}
|
|
|
|
|
2007-05-30 07:17:50 +08:00
|
|
|
ASTContext &getContext() const { return Context; }
|
2012-03-11 15:00:24 +08:00
|
|
|
const LangOptions &getLangOpts() const { return LangOpts; }
|
2015-06-30 10:26:03 +08:00
|
|
|
const HeaderSearchOptions &getHeaderSearchOpts()
|
|
|
|
const { return HeaderSearchOpts; }
|
|
|
|
const PreprocessorOptions &getPreprocessorOpts()
|
|
|
|
const { return PreprocessorOpts; }
|
2013-04-17 06:48:15 +08:00
|
|
|
const CodeGenOptions &getCodeGenOpts() const { return CodeGenOpts; }
|
2007-06-16 07:05:46 +08:00
|
|
|
llvm::Module &getModule() const { return TheModule; }
|
2011-09-26 07:23:43 +08:00
|
|
|
DiagnosticsEngine &getDiags() const { return Diags; }
|
2015-07-25 00:04:29 +08:00
|
|
|
const llvm::DataLayout &getDataLayout() const {
|
|
|
|
return TheModule.getDataLayout();
|
|
|
|
}
|
2013-04-17 06:48:15 +08:00
|
|
|
const TargetInfo &getTarget() const { return Target; }
|
2016-09-14 23:17:46 +08:00
|
|
|
const llvm::Triple &getTriple() const { return Target.getTriple(); }
|
2014-09-19 09:54:22 +08:00
|
|
|
bool supportsCOMDAT() const;
|
2015-01-16 05:36:08 +08:00
|
|
|
void maybeSetTrivialComdat(const Decl &D, llvm::GlobalObject &GO);
|
2014-09-19 09:54:22 +08:00
|
|
|
|
2013-12-29 05:58:40 +08:00
|
|
|
CGCXXABI &getCXXABI() const { return *ABI; }
|
2009-07-15 07:10:40 +08:00
|
|
|
llvm::LLVMContext &getLLVMContext() { return VMContext; }
|
2014-05-21 13:09:00 +08:00
|
|
|
|
|
|
|
bool shouldUseTBAA() const { return TBAA != nullptr; }
|
2011-02-26 16:07:02 +08:00
|
|
|
|
2018-07-31 03:24:48 +08:00
|
|
|
const TargetCodeGenInfo &getTargetCodeGenInfo();
|
|
|
|
|
2013-04-17 06:48:15 +08:00
|
|
|
CodeGenTypes &getTypes() { return Types; }
|
2018-07-31 03:24:48 +08:00
|
|
|
|
2013-04-17 06:48:15 +08:00
|
|
|
CodeGenVTables &getVTables() { return VTables; }
|
2013-08-21 14:25:03 +08:00
|
|
|
|
2013-11-05 23:54:58 +08:00
|
|
|
ItaniumVTableContext &getItaniumVTableContext() {
|
|
|
|
return VTables.getItaniumVTableContext();
|
2013-10-09 19:33:51 +08:00
|
|
|
}
|
2013-04-17 06:48:15 +08:00
|
|
|
|
2013-11-05 23:54:58 +08:00
|
|
|
MicrosoftVTableContext &getMicrosoftVTableContext() {
|
|
|
|
return VTables.getMicrosoftVTableContext();
|
2013-08-21 14:25:03 +08:00
|
|
|
}
|
|
|
|
|
2014-12-30 16:12:39 +08:00
|
|
|
CtorList &getGlobalCtors() { return GlobalCtors; }
|
|
|
|
CtorList &getGlobalDtors() { return GlobalDtors; }
|
|
|
|
|
2017-10-02 17:54:47 +08:00
|
|
|
/// getTBAATypeInfo - Get metadata used to describe accesses to objects of
|
|
|
|
/// the given type.
|
|
|
|
llvm::MDNode *getTBAATypeInfo(QualType QTy);
|
|
|
|
|
2017-10-05 19:08:17 +08:00
|
|
|
/// getTBAAAccessInfo - Get TBAA information that describes an access to
|
|
|
|
/// an object of the given type.
|
|
|
|
TBAAAccessInfo getTBAAAccessInfo(QualType AccessType);
|
|
|
|
|
|
|
|
/// getTBAAVTablePtrAccessInfo - Get the TBAA information that describes an
|
|
|
|
/// access to a virtual table pointer.
|
2017-11-27 17:39:29 +08:00
|
|
|
TBAAAccessInfo getTBAAVTablePtrAccessInfo(llvm::Type *VTablePtrType);
|
2017-10-05 19:08:17 +08:00
|
|
|
|
2012-09-29 05:58:29 +08:00
|
|
|
llvm::MDNode *getTBAAStructInfo(QualType QTy);
|
2017-10-03 18:52:39 +08:00
|
|
|
|
2017-10-06 16:17:48 +08:00
|
|
|
/// getTBAABaseTypeInfo - Get metadata that describes the given base access
|
|
|
|
/// type. Return null if the type is not suitable for use in TBAA access tags.
|
|
|
|
llvm::MDNode *getTBAABaseTypeInfo(QualType QTy);
|
|
|
|
|
2017-10-05 19:08:17 +08:00
|
|
|
/// getTBAAAccessTagInfo - Get TBAA tag for a given memory access.
|
|
|
|
llvm::MDNode *getTBAAAccessTagInfo(TBAAAccessInfo Info);
|
2010-10-15 07:06:10 +08:00
|
|
|
|
2017-10-17 17:12:13 +08:00
|
|
|
/// mergeTBAAInfoForCast - Get merged TBAA information for the purposes of
|
|
|
|
/// type casts.
|
|
|
|
TBAAAccessInfo mergeTBAAInfoForCast(TBAAAccessInfo SourceInfo,
|
|
|
|
TBAAAccessInfo TargetInfo);
|
|
|
|
|
2017-10-31 19:05:34 +08:00
|
|
|
/// mergeTBAAInfoForConditionalOperator - Get merged TBAA information for the
|
|
|
|
/// purposes of conditional operator.
|
|
|
|
TBAAAccessInfo mergeTBAAInfoForConditionalOperator(TBAAAccessInfo InfoA,
|
|
|
|
TBAAAccessInfo InfoB);
|
|
|
|
|
2018-01-25 22:21:55 +08:00
|
|
|
/// mergeTBAAInfoForMemoryTransfer - Get merged TBAA information for the
|
|
|
|
/// purposes of memory transfer calls.
|
|
|
|
TBAAAccessInfo mergeTBAAInfoForMemoryTransfer(TBAAAccessInfo DestInfo,
|
|
|
|
TBAAAccessInfo SrcInfo);
|
|
|
|
|
2017-10-31 19:05:34 +08:00
|
|
|
/// getTBAAInfoForSubobject - Get TBAA information for an access with a given
|
|
|
|
/// base lvalue.
|
|
|
|
TBAAAccessInfo getTBAAInfoForSubobject(LValue Base, QualType AccessType) {
|
2017-12-03 11:10:13 +08:00
|
|
|
if (Base.getTBAAInfo().isMayAlias())
|
|
|
|
return TBAAAccessInfo::getMayAliasInfo();
|
2017-10-31 19:05:34 +08:00
|
|
|
return getTBAAAccessInfo(AccessType);
|
|
|
|
}
|
|
|
|
|
2012-02-17 14:48:11 +08:00
|
|
|
bool isTypeConstant(QualType QTy, bool ExcludeCtorDtor);
|
|
|
|
|
2013-03-08 05:37:17 +08:00
|
|
|
bool isPaddedAtomicType(QualType type);
|
|
|
|
bool isPaddedAtomicType(const AtomicType *type);
|
|
|
|
|
2017-10-05 19:08:17 +08:00
|
|
|
/// DecorateInstructionWithTBAA - Decorate the instruction with a TBAA tag.
|
2015-09-16 05:46:55 +08:00
|
|
|
void DecorateInstructionWithTBAA(llvm::Instruction *Inst,
|
2017-10-05 19:08:17 +08:00
|
|
|
TBAAAccessInfo TBAAInfo);
|
2015-09-16 05:46:55 +08:00
|
|
|
|
|
|
|
/// Adds !invariant.barrier !tag to instruction
|
|
|
|
void DecorateInstructionWithInvariantGroup(llvm::Instruction *I,
|
|
|
|
const CXXRecordDecl *RD);
|
2010-10-15 07:06:10 +08:00
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Emit the given number of characters as a value of type size_t.
|
2011-06-25 05:55:10 +08:00
|
|
|
llvm::ConstantInt *getSize(CharUnits numChars);
|
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Set the visibility for the given LLVM GlobalValue.
|
2018-02-08 03:04:41 +08:00
|
|
|
void setGlobalVisibility(llvm::GlobalValue *GV, const NamedDecl *D) const;
|
2018-02-08 06:15:33 +08:00
|
|
|
|
2018-02-23 08:22:15 +08:00
|
|
|
void setDSOLocal(llvm::GlobalValue *GV) const;
|
2018-02-08 06:15:33 +08:00
|
|
|
|
2018-03-01 08:35:47 +08:00
|
|
|
void setDLLImportDLLExport(llvm::GlobalValue *GV, GlobalDecl D) const;
|
|
|
|
void setDLLImportDLLExport(llvm::GlobalValue *GV, const NamedDecl *D) const;
|
|
|
|
/// Set visibility, dllimport/dllexport and dso_local.
|
2018-02-24 03:30:48 +08:00
|
|
|
/// This must be called after dllimport/dllexport is set.
|
2018-03-01 08:35:47 +08:00
|
|
|
void setGVProperties(llvm::GlobalValue *GV, GlobalDecl GD) const;
|
2018-02-08 06:15:33 +08:00
|
|
|
void setGVProperties(llvm::GlobalValue *GV, const NamedDecl *D) const;
|
2009-04-14 14:00:08 +08:00
|
|
|
|
2019-06-08 03:10:08 +08:00
|
|
|
void setGVPropertiesAux(llvm::GlobalValue *GV, const NamedDecl *D) const;
|
|
|
|
|
2014-10-16 06:38:23 +08:00
|
|
|
/// Set the TLS mode for the given LLVM GlobalValue for the thread-local
|
2014-05-09 09:34:38 +08:00
|
|
|
/// variable declaration D.
|
2014-10-16 06:38:23 +08:00
|
|
|
void setTLSMode(llvm::GlobalValue *GV, const VarDecl &D) const;
|
2012-06-28 16:01:44 +08:00
|
|
|
|
2020-06-16 14:30:36 +08:00
|
|
|
/// Get LLVM TLS mode from CodeGenOptions.
|
|
|
|
llvm::GlobalVariable::ThreadLocalMode GetDefaultLLVMTLSModel() const;
|
|
|
|
|
2011-01-30 04:59:35 +08:00
|
|
|
static llvm::GlobalValue::VisibilityTypes GetLLVMVisibility(Visibility V) {
|
|
|
|
switch (V) {
|
|
|
|
case DefaultVisibility: return llvm::GlobalValue::DefaultVisibility;
|
|
|
|
case HiddenVisibility: return llvm::GlobalValue::HiddenVisibility;
|
|
|
|
case ProtectedVisibility: return llvm::GlobalValue::ProtectedVisibility;
|
|
|
|
}
|
|
|
|
llvm_unreachable("unknown visibility!");
|
|
|
|
}
|
|
|
|
|
2016-12-01 07:25:13 +08:00
|
|
|
llvm::Constant *GetAddrOfGlobal(GlobalDecl GD,
|
|
|
|
ForDefinition_t IsForDefinition
|
|
|
|
= NotForDefinition);
|
2010-02-19 09:32:20 +08:00
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Will return a global variable of the given type. If a variable with a
|
|
|
|
/// different type already exists then a new variable with the right type
|
|
|
|
/// will be created and all uses of the old variable will be replaced with a
|
|
|
|
/// bitcast to the new variable.
|
2011-01-30 02:20:20 +08:00
|
|
|
llvm::GlobalVariable *
|
2011-07-20 14:58:45 +08:00
|
|
|
CreateOrReplaceCXXRuntimeVariable(StringRef Name, llvm::Type *Ty,
|
2018-09-12 22:09:06 +08:00
|
|
|
llvm::GlobalValue::LinkageTypes Linkage,
|
|
|
|
unsigned Alignment);
|
2011-01-30 02:20:20 +08:00
|
|
|
|
2020-05-28 05:04:43 +08:00
|
|
|
llvm::Function *CreateGlobalInitOrCleanUpFunction(
|
|
|
|
llvm::FunctionType *ty, const Twine &name, const CGFunctionInfo &FI,
|
2020-07-16 04:12:22 +08:00
|
|
|
SourceLocation Loc = SourceLocation(), bool TLS = false);
|
2014-10-05 13:05:40 +08:00
|
|
|
|
2017-07-08 21:24:52 +08:00
|
|
|
/// Return the AST address space of the underlying global variable for D, as
|
2014-05-09 09:34:38 +08:00
|
|
|
/// determined by its declaration. Normally this is the same as the address
|
|
|
|
/// space of D's type, but in CUDA, address spaces are associated with
|
2017-07-08 21:24:52 +08:00
|
|
|
/// declarations, not types. If D is nullptr, return the default address
|
|
|
|
/// space for global variable.
|
|
|
|
///
|
|
|
|
/// For languages without explicit address spaces, if D has default address
|
|
|
|
/// space, target-specific global or constant address space may be returned.
|
Convert clang::LangAS to a strongly typed enum
Summary:
Convert clang::LangAS to a strongly typed enum
Currently both clang AST address spaces and target specific address spaces
are represented as unsigned which can lead to subtle errors if the wrong
type is passed. It is especially confusing in the CodeGen files as it is
not possible to see what kind of address space should be passed to a
function without looking at the implementation.
I originally made this change for our LLVM fork for the CHERI architecture
where we make extensive use of address spaces to differentiate between
capabilities and pointers. When merging the upstream changes I usually
run into some test failures or runtime crashes because the wrong kind of
address space is passed to a function. By converting the LangAS enum to a
C++11 we can catch these errors at compile time. Additionally, it is now
obvious from the function signature which kind of address space it expects.
I found the following errors while writing this patch:
- ItaniumRecordLayoutBuilder::LayoutField was passing a clang AST address
space to TargetInfo::getPointer{Width,Align}()
- TypePrinter::printAttributedAfter() prints the numeric value of the
clang AST address space instead of the target address space.
However, this code is not used so I kept the current behaviour
- initializeForBlockHeader() in CGBlocks.cpp was passing
LangAS::opencl_generic to TargetInfo::getPointer{Width,Align}()
- CodeGenFunction::EmitBlockLiteral() was passing a AST address space to
TargetInfo::getPointerWidth()
- CGOpenMPRuntimeNVPTX::translateParameter() passed a target address space
to Qualifiers::addAddressSpace()
- CGOpenMPRuntimeNVPTX::getParameterAddress() was using
llvm::Type::getPointerTo() with a AST address space
- clang_getAddressSpace() returns either a LangAS or a target address
space. As this is exposed to C I have kept the current behaviour and
added a comment stating that it is probably not correct.
Other than this the patch should not cause any functional changes.
Reviewers: yaxunl, pcc, bader
Reviewed By: yaxunl, bader
Subscribers: jlebar, jholewinski, nhaehnle, Anastasia, cfe-commits
Differential Revision: https://reviews.llvm.org/D38816
llvm-svn: 315871
2017-10-16 02:48:14 +08:00
|
|
|
LangAS GetGlobalVarAddressSpace(const VarDecl *D);
|
2012-05-21 05:08:35 +08:00
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Return the llvm::Constant for the address of the given global variable.
|
2016-01-14 18:41:16 +08:00
|
|
|
/// If Ty is non-null and if the global doesn't exist, then it will be created
|
2014-05-09 09:34:38 +08:00
|
|
|
/// with the specified type instead of whatever the normal requested type
|
2018-04-06 23:14:32 +08:00
|
|
|
/// would be. If IsForDefinition is true, it is guaranteed that an actual
|
2016-01-14 18:41:16 +08:00
|
|
|
/// global with type Ty will be returned, not conversion of a variable with
|
|
|
|
/// the same mangled name but some other type.
|
2009-03-21 17:16:30 +08:00
|
|
|
llvm::Constant *GetAddrOfGlobalVar(const VarDecl *D,
|
2016-01-14 18:41:16 +08:00
|
|
|
llvm::Type *Ty = nullptr,
|
2016-12-01 07:25:13 +08:00
|
|
|
ForDefinition_t IsForDefinition
|
|
|
|
= NotForDefinition);
|
2008-07-30 07:18:29 +08:00
|
|
|
|
2018-05-15 03:20:12 +08:00
|
|
|
/// Return the AST address space of string literal, which is used to emit
|
|
|
|
/// the string literal as global variable in LLVM IR.
|
|
|
|
/// Note: This is not necessarily the address space of the string literal
|
|
|
|
/// in AST. For address space agnostic language, e.g. C++, string literal
|
|
|
|
/// in AST is always in default address space.
|
|
|
|
LangAS getStringLiteralAddressSpace() const;
|
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Return the address of the given function. If Ty is non-null, then this
|
|
|
|
/// function will use the specified type if it has to create it.
|
2015-09-30 04:56:43 +08:00
|
|
|
llvm::Constant *GetAddrOfFunction(GlobalDecl GD, llvm::Type *Ty = nullptr,
|
2013-12-09 12:29:47 +08:00
|
|
|
bool ForVTable = false,
|
2015-08-31 21:20:44 +08:00
|
|
|
bool DontDefer = false,
|
2016-12-01 07:25:13 +08:00
|
|
|
ForDefinition_t IsForDefinition
|
|
|
|
= NotForDefinition);
|
2008-08-14 07:20:05 +08:00
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Get the address of the RTTI descriptor for the given type.
|
2010-04-30 09:15:21 +08:00
|
|
|
llvm::Constant *GetAddrOfRTTIDescriptor(QualType Ty, bool ForEH = false);
|
2009-12-11 10:46:30 +08:00
|
|
|
|
Rework how UuidAttr, CXXUuidofExpr, and GUID template arguments and constants are represented.
Summary:
Previously, we treated CXXUuidofExpr as quite a special case: it was the
only kind of expression that could be a canonical template argument, it
could be a constant lvalue base object, and so on. In addition, we
represented the UUID value as a string, whose source form we did not
preserve faithfully, and that we partially parsed in multiple different
places.
With this patch, we create an MSGuidDecl object to represent the
implicit object of type 'struct _GUID' created by a UuidAttr. Each
UuidAttr holds a pointer to its 'struct _GUID' and its original
(as-written) UUID string. A non-value-dependent CXXUuidofExpr behaves
like a DeclRefExpr denoting that MSGuidDecl object. We cache an APValue
representation of the GUID on the MSGuidDecl and use it from constant
evaluation where needed.
This allows removing a lot of the special-case logic to handle these
expressions. Unfortunately, many parts of Clang assume there are only
a couple of interesting kinds of ValueDecl, so the total amount of
special-case logic is not really reduced very much.
This fixes a few bugs and issues:
* PR38490: we now support reading from GUID objects returned from
__uuidof during constant evaluation.
* Our Itanium mangling for a non-instantiation-dependent template
argument involving __uuidof no longer depends on which CXXUuidofExpr
template argument we happened to see first.
* We now predeclare ::_GUID, and permit use of __uuidof without
any header inclusion, better matching MSVC's behavior. We do not
predefine ::__s_GUID, though; that seems like a step too far.
* Our IR representation for GUID constants now uses the correct IR type
wherever possible. We will still fall back to using the
{i32, i16, i16, [8 x i8]}
layout if a definition of struct _GUID is not available. This is not
ideal: in principle the two layouts could have different padding.
Reviewers: rnk, jdoerfert
Subscribers: arphaman, cfe-commits, aeubanks
Tags: #clang
Differential Revision: https://reviews.llvm.org/D78171
2020-04-12 13:15:29 +08:00
|
|
|
/// Get the address of a GUID.
|
|
|
|
ConstantAddress GetAddrOfMSGuidDecl(const MSGuidDecl *GD);
|
2012-10-11 18:13:44 +08:00
|
|
|
|
2020-09-21 14:16:08 +08:00
|
|
|
/// Get the address of a template parameter object.
|
|
|
|
ConstantAddress
|
|
|
|
GetAddrOfTemplateParamObject(const TemplateParamObjectDecl *TPO);
|
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Get the address of the thunk for the given global decl.
|
[MS] Emit vftable thunks for functions with incomplete prototypes
Summary:
The following class hierarchy requires that we be able to emit a
this-adjusting thunk for B::foo in C's vftable:
struct Incomplete;
struct A {
virtual A* foo(Incomplete p) = 0;
};
struct B : virtual A {
void foo(Incomplete p) override;
};
struct C : B { int c; };
This TU is valid, but lacks a definition of 'Incomplete', which makes it
hard to build a thunk for the final overrider, B::foo.
Before this change, Clang gives up attempting to emit the thunk, because
it assumes that if the parameter types are incomplete, it must be
emitting the thunk for optimization purposes. This is untrue for the MS
ABI, where the implementation of B::foo has no idea what thunks C's
vftable may require. Clang needs to emit the thunk without necessarily
having access to the complete prototype of foo.
This change makes Clang emit a musttail variadic call when it needs such
a thunk. I call these "unprototyped" thunks, because they only prototype
the "this" parameter, which must always come first in the MS C++ ABI.
These thunks work, but they create ugly LLVM IR. If the call to the
thunk is devirtualized, it will be a call to a bitcast of a function
pointer. Today, LLVM cannot inline through such a call, but I want to
address that soon, because we also use this pattern for virtual member
pointer thunks.
This change also implements an old FIXME in the code about reusing the
thunk's computed CGFunctionInfo as much as possible. Now we don't end up
computing the thunk's mangled name and arranging it's prototype up to
around three times.
Fixes PR25641
Reviewers: rjmccall, rsmith, hans
Subscribers: Prazek, cfe-commits
Differential Revision: https://reviews.llvm.org/D45112
llvm-svn: 329009
2018-04-03 04:20:33 +08:00
|
|
|
llvm::Constant *GetAddrOfThunk(StringRef Name, llvm::Type *FnTy,
|
|
|
|
GlobalDecl GD);
|
2010-03-24 01:17:29 +08:00
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Get a reference to the target of VD.
|
Compute and preserve alignment more faithfully in IR-generation.
Introduce an Address type to bundle a pointer value with an
alignment. Introduce APIs on CGBuilderTy to work with Address
values. Change core APIs on CGF/CGM to traffic in Address where
appropriate. Require alignments to be non-zero. Update a ton
of code to compute and propagate alignment information.
As part of this, I've promoted CGBuiltin's EmitPointerWithAlignment
helper function to CGF and made use of it in a number of places in
the expression emitter.
The end result is that we should now be significantly more correct
when performing operations on objects that are locally known to
be under-aligned. Since alignment is not reliably tracked in the
type system, there are inherent limits to this, but at least we
are no longer confused by standard operations like derived-to-base
conversions and array-to-pointer decay. I've also fixed a large
number of bugs where we were applying the complete-object alignment
to a pointer instead of the non-virtual alignment, although most of
these were hidden by the very conservative approach we took with
member alignment.
Also, because IRGen now reliably asserts on zero alignments, we
should no longer be subject to an absurd but frustrating recurring
bug where an incomplete type would report a zero alignment and then
we'd naively do a alignmentAtOffset on it and emit code using an
alignment equal to the largest power-of-two factor of the offset.
We should also now be emitting much more aggressive alignment
attributes in the presence of over-alignment. In particular,
field access now uses alignmentAtOffset instead of min.
Several times in this patch, I had to change the existing
code-generation pattern in order to more effectively use
the Address APIs. For the most part, this seems to be a strict
improvement, like doing pointer arithmetic with GEPs instead of
ptrtoint. That said, I've tried very hard to not change semantics,
but it is likely that I've failed in a few places, for which I
apologize.
ABIArgInfo now always carries the assumed alignment of indirect and
indirect byval arguments. In order to cut down on what was already
a dauntingly large patch, I changed the code to never set align
attributes in the IR on non-byval indirect arguments. That is,
we still generate code which assumes that indirect arguments have
the given alignment, but we don't express this information to the
backend except where it's semantically required (i.e. on byvals).
This is likely a minor regression for those targets that did provide
this information, but it'll be trivial to add it back in a later
patch.
I partially punted on applying this work to CGBuiltin. Please
do not add more uses of the CreateDefaultAligned{Load,Store}
APIs; they will be going away eventually.
llvm-svn: 246985
2015-09-08 16:05:57 +08:00
|
|
|
ConstantAddress GetWeakRefReference(const ValueDecl *VD);
|
|
|
|
|
|
|
|
/// Returns the assumed alignment of an opaque pointer to the given class.
|
|
|
|
CharUnits getClassPointerAlignment(const CXXRecordDecl *CD);
|
|
|
|
|
2020-02-01 11:06:21 +08:00
|
|
|
/// Returns the minimum object size for an object of the given class type
|
|
|
|
/// (or a class derived from it).
|
|
|
|
CharUnits getMinimumClassObjectSize(const CXXRecordDecl *CD);
|
|
|
|
|
|
|
|
/// Returns the minimum object size for an object of the given type.
|
|
|
|
CharUnits getMinimumObjectSize(QualType Ty) {
|
|
|
|
if (CXXRecordDecl *RD = Ty->getAsCXXRecordDecl())
|
|
|
|
return getMinimumClassObjectSize(RD);
|
|
|
|
return getContext().getTypeSizeInChars(Ty);
|
|
|
|
}
|
|
|
|
|
Compute and preserve alignment more faithfully in IR-generation.
Introduce an Address type to bundle a pointer value with an
alignment. Introduce APIs on CGBuilderTy to work with Address
values. Change core APIs on CGF/CGM to traffic in Address where
appropriate. Require alignments to be non-zero. Update a ton
of code to compute and propagate alignment information.
As part of this, I've promoted CGBuiltin's EmitPointerWithAlignment
helper function to CGF and made use of it in a number of places in
the expression emitter.
The end result is that we should now be significantly more correct
when performing operations on objects that are locally known to
be under-aligned. Since alignment is not reliably tracked in the
type system, there are inherent limits to this, but at least we
are no longer confused by standard operations like derived-to-base
conversions and array-to-pointer decay. I've also fixed a large
number of bugs where we were applying the complete-object alignment
to a pointer instead of the non-virtual alignment, although most of
these were hidden by the very conservative approach we took with
member alignment.
Also, because IRGen now reliably asserts on zero alignments, we
should no longer be subject to an absurd but frustrating recurring
bug where an incomplete type would report a zero alignment and then
we'd naively do a alignmentAtOffset on it and emit code using an
alignment equal to the largest power-of-two factor of the offset.
We should also now be emitting much more aggressive alignment
attributes in the presence of over-alignment. In particular,
field access now uses alignmentAtOffset instead of min.
Several times in this patch, I had to change the existing
code-generation pattern in order to more effectively use
the Address APIs. For the most part, this seems to be a strict
improvement, like doing pointer arithmetic with GEPs instead of
ptrtoint. That said, I've tried very hard to not change semantics,
but it is likely that I've failed in a few places, for which I
apologize.
ABIArgInfo now always carries the assumed alignment of indirect and
indirect byval arguments. In order to cut down on what was already
a dauntingly large patch, I changed the code to never set align
attributes in the IR on non-byval indirect arguments. That is,
we still generate code which assumes that indirect arguments have
the given alignment, but we don't express this information to the
backend except where it's semantically required (i.e. on byvals).
This is likely a minor regression for those targets that did provide
this information, but it'll be trivial to add it back in a later
patch.
I partially punted on applying this work to CGBuiltin. Please
do not add more uses of the CreateDefaultAligned{Load,Store}
APIs; they will be going away eventually.
llvm-svn: 246985
2015-09-08 16:05:57 +08:00
|
|
|
/// Returns the assumed alignment of a virtual base of a class.
|
|
|
|
CharUnits getVBaseAlignment(CharUnits DerivedAlign,
|
|
|
|
const CXXRecordDecl *Derived,
|
|
|
|
const CXXRecordDecl *VBase);
|
|
|
|
|
|
|
|
/// Given a class pointer with an actual known alignment, and the
|
|
|
|
/// expected alignment of an object at a dynamic offset w.r.t that
|
|
|
|
/// pointer, return the alignment to assume at the offset.
|
|
|
|
CharUnits getDynamicOffsetAlignment(CharUnits ActualAlign,
|
|
|
|
const CXXRecordDecl *Class,
|
|
|
|
CharUnits ExpectedTargetAlign);
|
2010-03-05 02:17:24 +08:00
|
|
|
|
2015-06-23 15:31:11 +08:00
|
|
|
CharUnits
|
|
|
|
computeNonVirtualBaseClassOffset(const CXXRecordDecl *DerivedClass,
|
|
|
|
CastExpr::path_const_iterator Start,
|
|
|
|
CastExpr::path_const_iterator End);
|
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Returns the offset from a derived class to a class. Returns null if the
|
|
|
|
/// offset is 0.
|
2010-04-25 05:23:59 +08:00
|
|
|
llvm::Constant *
|
|
|
|
GetNonVirtualBaseClassOffset(const CXXRecordDecl *ClassDecl,
|
2010-08-07 14:22:56 +08:00
|
|
|
CastExpr::path_const_iterator PathBegin,
|
|
|
|
CastExpr::path_const_iterator PathEnd);
|
2011-02-08 16:22:06 +08:00
|
|
|
|
Compute and preserve alignment more faithfully in IR-generation.
Introduce an Address type to bundle a pointer value with an
alignment. Introduce APIs on CGBuilderTy to work with Address
values. Change core APIs on CGF/CGM to traffic in Address where
appropriate. Require alignments to be non-zero. Update a ton
of code to compute and propagate alignment information.
As part of this, I've promoted CGBuiltin's EmitPointerWithAlignment
helper function to CGF and made use of it in a number of places in
the expression emitter.
The end result is that we should now be significantly more correct
when performing operations on objects that are locally known to
be under-aligned. Since alignment is not reliably tracked in the
type system, there are inherent limits to this, but at least we
are no longer confused by standard operations like derived-to-base
conversions and array-to-pointer decay. I've also fixed a large
number of bugs where we were applying the complete-object alignment
to a pointer instead of the non-virtual alignment, although most of
these were hidden by the very conservative approach we took with
member alignment.
Also, because IRGen now reliably asserts on zero alignments, we
should no longer be subject to an absurd but frustrating recurring
bug where an incomplete type would report a zero alignment and then
we'd naively do a alignmentAtOffset on it and emit code using an
alignment equal to the largest power-of-two factor of the offset.
We should also now be emitting much more aggressive alignment
attributes in the presence of over-alignment. In particular,
field access now uses alignmentAtOffset instead of min.
Several times in this patch, I had to change the existing
code-generation pattern in order to more effectively use
the Address APIs. For the most part, this seems to be a strict
improvement, like doing pointer arithmetic with GEPs instead of
ptrtoint. That said, I've tried very hard to not change semantics,
but it is likely that I've failed in a few places, for which I
apologize.
ABIArgInfo now always carries the assumed alignment of indirect and
indirect byval arguments. In order to cut down on what was already
a dauntingly large patch, I changed the code to never set align
attributes in the IR on non-byval indirect arguments. That is,
we still generate code which assumes that indirect arguments have
the given alignment, but we don't express this information to the
backend except where it's semantically required (i.e. on byvals).
This is likely a minor regression for those targets that did provide
this information, but it'll be trivial to add it back in a later
patch.
I partially punted on applying this work to CGBuiltin. Please
do not add more uses of the CreateDefaultAligned{Load,Store}
APIs; they will be going away eventually.
llvm-svn: 246985
2015-09-08 16:05:57 +08:00
|
|
|
llvm::FoldingSet<BlockByrefHelpers> ByrefHelpersCache;
|
2011-02-08 16:22:06 +08:00
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Fetches the global unique block count.
|
2011-02-23 06:38:33 +08:00
|
|
|
int getUniqueBlockCount() { return ++Block.GlobalUniqueCount; }
|
2018-07-31 03:24:48 +08:00
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Fetches the type of a generic block descriptor.
|
2011-07-10 01:41:47 +08:00
|
|
|
llvm::Type *getBlockDescriptorType();
|
2011-02-08 16:22:06 +08:00
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// The type of a generic block literal.
|
2011-07-10 01:41:47 +08:00
|
|
|
llvm::Type *getGenericBlockLiteralType();
|
2011-02-08 16:22:06 +08:00
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Gets the address of a block which requires no captures.
|
2016-11-03 10:21:43 +08:00
|
|
|
llvm::Constant *GetAddrOfGlobalBlock(const BlockExpr *BE, StringRef Name);
|
2016-12-22 10:50:20 +08:00
|
|
|
|
|
|
|
/// Returns the address of a block which requires no caputres, or null if
|
|
|
|
/// we've yet to emit the block for BE.
|
|
|
|
llvm::Constant *getAddrOfGlobalBlockIfEmitted(const BlockExpr *BE) {
|
|
|
|
return EmittedGlobalBlocks.lookup(BE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Notes that BE's global block is available via Addr. Asserts that BE
|
|
|
|
/// isn't already emitted.
|
|
|
|
void setAddrOfGlobalBlock(const BlockExpr *BE, llvm::Constant *Addr);
|
2018-07-31 03:24:48 +08:00
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Return a pointer to a constant CFString object for the given string.
|
Compute and preserve alignment more faithfully in IR-generation.
Introduce an Address type to bundle a pointer value with an
alignment. Introduce APIs on CGBuilderTy to work with Address
values. Change core APIs on CGF/CGM to traffic in Address where
appropriate. Require alignments to be non-zero. Update a ton
of code to compute and propagate alignment information.
As part of this, I've promoted CGBuiltin's EmitPointerWithAlignment
helper function to CGF and made use of it in a number of places in
the expression emitter.
The end result is that we should now be significantly more correct
when performing operations on objects that are locally known to
be under-aligned. Since alignment is not reliably tracked in the
type system, there are inherent limits to this, but at least we
are no longer confused by standard operations like derived-to-base
conversions and array-to-pointer decay. I've also fixed a large
number of bugs where we were applying the complete-object alignment
to a pointer instead of the non-virtual alignment, although most of
these were hidden by the very conservative approach we took with
member alignment.
Also, because IRGen now reliably asserts on zero alignments, we
should no longer be subject to an absurd but frustrating recurring
bug where an incomplete type would report a zero alignment and then
we'd naively do a alignmentAtOffset on it and emit code using an
alignment equal to the largest power-of-two factor of the offset.
We should also now be emitting much more aggressive alignment
attributes in the presence of over-alignment. In particular,
field access now uses alignmentAtOffset instead of min.
Several times in this patch, I had to change the existing
code-generation pattern in order to more effectively use
the Address APIs. For the most part, this seems to be a strict
improvement, like doing pointer arithmetic with GEPs instead of
ptrtoint. That said, I've tried very hard to not change semantics,
but it is likely that I've failed in a few places, for which I
apologize.
ABIArgInfo now always carries the assumed alignment of indirect and
indirect byval arguments. In order to cut down on what was already
a dauntingly large patch, I changed the code to never set align
attributes in the IR on non-byval indirect arguments. That is,
we still generate code which assumes that indirect arguments have
the given alignment, but we don't express this information to the
backend except where it's semantically required (i.e. on byvals).
This is likely a minor regression for those targets that did provide
this information, but it'll be trivial to add it back in a later
patch.
I partially punted on applying this work to CGBuiltin. Please
do not add more uses of the CreateDefaultAligned{Load,Store}
APIs; they will be going away eventually.
llvm-svn: 246985
2015-09-08 16:05:57 +08:00
|
|
|
ConstantAddress GetAddrOfConstantCFString(const StringLiteral *Literal);
|
2014-05-09 09:34:38 +08:00
|
|
|
|
|
|
|
/// Return a pointer to a constant NSString object for the given string. Or a
|
|
|
|
/// user defined String object as defined via
|
2010-10-20 01:19:29 +08:00
|
|
|
/// -fconstant-string-class=class_name option.
|
Compute and preserve alignment more faithfully in IR-generation.
Introduce an Address type to bundle a pointer value with an
alignment. Introduce APIs on CGBuilderTy to work with Address
values. Change core APIs on CGF/CGM to traffic in Address where
appropriate. Require alignments to be non-zero. Update a ton
of code to compute and propagate alignment information.
As part of this, I've promoted CGBuiltin's EmitPointerWithAlignment
helper function to CGF and made use of it in a number of places in
the expression emitter.
The end result is that we should now be significantly more correct
when performing operations on objects that are locally known to
be under-aligned. Since alignment is not reliably tracked in the
type system, there are inherent limits to this, but at least we
are no longer confused by standard operations like derived-to-base
conversions and array-to-pointer decay. I've also fixed a large
number of bugs where we were applying the complete-object alignment
to a pointer instead of the non-virtual alignment, although most of
these were hidden by the very conservative approach we took with
member alignment.
Also, because IRGen now reliably asserts on zero alignments, we
should no longer be subject to an absurd but frustrating recurring
bug where an incomplete type would report a zero alignment and then
we'd naively do a alignmentAtOffset on it and emit code using an
alignment equal to the largest power-of-two factor of the offset.
We should also now be emitting much more aggressive alignment
attributes in the presence of over-alignment. In particular,
field access now uses alignmentAtOffset instead of min.
Several times in this patch, I had to change the existing
code-generation pattern in order to more effectively use
the Address APIs. For the most part, this seems to be a strict
improvement, like doing pointer arithmetic with GEPs instead of
ptrtoint. That said, I've tried very hard to not change semantics,
but it is likely that I've failed in a few places, for which I
apologize.
ABIArgInfo now always carries the assumed alignment of indirect and
indirect byval arguments. In order to cut down on what was already
a dauntingly large patch, I changed the code to never set align
attributes in the IR on non-byval indirect arguments. That is,
we still generate code which assumes that indirect arguments have
the given alignment, but we don't express this information to the
backend except where it's semantically required (i.e. on byvals).
This is likely a minor regression for those targets that did provide
this information, but it'll be trivial to add it back in a later
patch.
I partially punted on applying this work to CGBuiltin. Please
do not add more uses of the CreateDefaultAligned{Load,Store}
APIs; they will be going away eventually.
llvm-svn: 246985
2015-09-08 16:05:57 +08:00
|
|
|
ConstantAddress GetAddrOfConstantString(const StringLiteral *Literal);
|
2008-02-11 08:02:17 +08:00
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Return a constant array for the given string.
|
2011-11-01 10:23:42 +08:00
|
|
|
llvm::Constant *GetConstantArrayFromStringLiteral(const StringLiteral *E);
|
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Return a pointer to a constant array for the given string literal.
|
Compute and preserve alignment more faithfully in IR-generation.
Introduce an Address type to bundle a pointer value with an
alignment. Introduce APIs on CGBuilderTy to work with Address
values. Change core APIs on CGF/CGM to traffic in Address where
appropriate. Require alignments to be non-zero. Update a ton
of code to compute and propagate alignment information.
As part of this, I've promoted CGBuiltin's EmitPointerWithAlignment
helper function to CGF and made use of it in a number of places in
the expression emitter.
The end result is that we should now be significantly more correct
when performing operations on objects that are locally known to
be under-aligned. Since alignment is not reliably tracked in the
type system, there are inherent limits to this, but at least we
are no longer confused by standard operations like derived-to-base
conversions and array-to-pointer decay. I've also fixed a large
number of bugs where we were applying the complete-object alignment
to a pointer instead of the non-virtual alignment, although most of
these were hidden by the very conservative approach we took with
member alignment.
Also, because IRGen now reliably asserts on zero alignments, we
should no longer be subject to an absurd but frustrating recurring
bug where an incomplete type would report a zero alignment and then
we'd naively do a alignmentAtOffset on it and emit code using an
alignment equal to the largest power-of-two factor of the offset.
We should also now be emitting much more aggressive alignment
attributes in the presence of over-alignment. In particular,
field access now uses alignmentAtOffset instead of min.
Several times in this patch, I had to change the existing
code-generation pattern in order to more effectively use
the Address APIs. For the most part, this seems to be a strict
improvement, like doing pointer arithmetic with GEPs instead of
ptrtoint. That said, I've tried very hard to not change semantics,
but it is likely that I've failed in a few places, for which I
apologize.
ABIArgInfo now always carries the assumed alignment of indirect and
indirect byval arguments. In order to cut down on what was already
a dauntingly large patch, I changed the code to never set align
attributes in the IR on non-byval indirect arguments. That is,
we still generate code which assumes that indirect arguments have
the given alignment, but we don't express this information to the
backend except where it's semantically required (i.e. on byvals).
This is likely a minor regression for those targets that did provide
this information, but it'll be trivial to add it back in a later
patch.
I partially punted on applying this work to CGBuiltin. Please
do not add more uses of the CreateDefaultAligned{Load,Store}
APIs; they will be going away eventually.
llvm-svn: 246985
2015-09-08 16:05:57 +08:00
|
|
|
ConstantAddress
|
2014-10-09 16:45:04 +08:00
|
|
|
GetAddrOfConstantStringFromLiteral(const StringLiteral *S,
|
|
|
|
StringRef Name = ".str");
|
2008-08-11 04:25:57 +08:00
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Return a pointer to a constant array for the given ObjCEncodeExpr node.
|
Compute and preserve alignment more faithfully in IR-generation.
Introduce an Address type to bundle a pointer value with an
alignment. Introduce APIs on CGBuilderTy to work with Address
values. Change core APIs on CGF/CGM to traffic in Address where
appropriate. Require alignments to be non-zero. Update a ton
of code to compute and propagate alignment information.
As part of this, I've promoted CGBuiltin's EmitPointerWithAlignment
helper function to CGF and made use of it in a number of places in
the expression emitter.
The end result is that we should now be significantly more correct
when performing operations on objects that are locally known to
be under-aligned. Since alignment is not reliably tracked in the
type system, there are inherent limits to this, but at least we
are no longer confused by standard operations like derived-to-base
conversions and array-to-pointer decay. I've also fixed a large
number of bugs where we were applying the complete-object alignment
to a pointer instead of the non-virtual alignment, although most of
these were hidden by the very conservative approach we took with
member alignment.
Also, because IRGen now reliably asserts on zero alignments, we
should no longer be subject to an absurd but frustrating recurring
bug where an incomplete type would report a zero alignment and then
we'd naively do a alignmentAtOffset on it and emit code using an
alignment equal to the largest power-of-two factor of the offset.
We should also now be emitting much more aggressive alignment
attributes in the presence of over-alignment. In particular,
field access now uses alignmentAtOffset instead of min.
Several times in this patch, I had to change the existing
code-generation pattern in order to more effectively use
the Address APIs. For the most part, this seems to be a strict
improvement, like doing pointer arithmetic with GEPs instead of
ptrtoint. That said, I've tried very hard to not change semantics,
but it is likely that I've failed in a few places, for which I
apologize.
ABIArgInfo now always carries the assumed alignment of indirect and
indirect byval arguments. In order to cut down on what was already
a dauntingly large patch, I changed the code to never set align
attributes in the IR on non-byval indirect arguments. That is,
we still generate code which assumes that indirect arguments have
the given alignment, but we don't express this information to the
backend except where it's semantically required (i.e. on byvals).
This is likely a minor regression for those targets that did provide
this information, but it'll be trivial to add it back in a later
patch.
I partially punted on applying this work to CGBuiltin. Please
do not add more uses of the CreateDefaultAligned{Load,Store}
APIs; they will be going away eventually.
llvm-svn: 246985
2015-09-08 16:05:57 +08:00
|
|
|
ConstantAddress
|
2014-07-11 06:18:36 +08:00
|
|
|
GetAddrOfConstantStringFromObjCEncode(const ObjCEncodeExpr *);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Returns a pointer to a character array containing the literal and a
|
|
|
|
/// terminating '\0' character. The result has pointer to array type.
|
2008-10-18 05:56:50 +08:00
|
|
|
///
|
2009-02-14 03:12:34 +08:00
|
|
|
/// \param GlobalName If provided, the name to use for the global (if one is
|
|
|
|
/// created).
|
Compute and preserve alignment more faithfully in IR-generation.
Introduce an Address type to bundle a pointer value with an
alignment. Introduce APIs on CGBuilderTy to work with Address
values. Change core APIs on CGF/CGM to traffic in Address where
appropriate. Require alignments to be non-zero. Update a ton
of code to compute and propagate alignment information.
As part of this, I've promoted CGBuiltin's EmitPointerWithAlignment
helper function to CGF and made use of it in a number of places in
the expression emitter.
The end result is that we should now be significantly more correct
when performing operations on objects that are locally known to
be under-aligned. Since alignment is not reliably tracked in the
type system, there are inherent limits to this, but at least we
are no longer confused by standard operations like derived-to-base
conversions and array-to-pointer decay. I've also fixed a large
number of bugs where we were applying the complete-object alignment
to a pointer instead of the non-virtual alignment, although most of
these were hidden by the very conservative approach we took with
member alignment.
Also, because IRGen now reliably asserts on zero alignments, we
should no longer be subject to an absurd but frustrating recurring
bug where an incomplete type would report a zero alignment and then
we'd naively do a alignmentAtOffset on it and emit code using an
alignment equal to the largest power-of-two factor of the offset.
We should also now be emitting much more aggressive alignment
attributes in the presence of over-alignment. In particular,
field access now uses alignmentAtOffset instead of min.
Several times in this patch, I had to change the existing
code-generation pattern in order to more effectively use
the Address APIs. For the most part, this seems to be a strict
improvement, like doing pointer arithmetic with GEPs instead of
ptrtoint. That said, I've tried very hard to not change semantics,
but it is likely that I've failed in a few places, for which I
apologize.
ABIArgInfo now always carries the assumed alignment of indirect and
indirect byval arguments. In order to cut down on what was already
a dauntingly large patch, I changed the code to never set align
attributes in the IR on non-byval indirect arguments. That is,
we still generate code which assumes that indirect arguments have
the given alignment, but we don't express this information to the
backend except where it's semantically required (i.e. on byvals).
This is likely a minor regression for those targets that did provide
this information, but it'll be trivial to add it back in a later
patch.
I partially punted on applying this work to CGBuiltin. Please
do not add more uses of the CreateDefaultAligned{Load,Store}
APIs; they will be going away eventually.
llvm-svn: 246985
2015-09-08 16:05:57 +08:00
|
|
|
ConstantAddress
|
2014-07-11 06:18:36 +08:00
|
|
|
GetAddrOfConstantCString(const std::string &Str,
|
Compute and preserve alignment more faithfully in IR-generation.
Introduce an Address type to bundle a pointer value with an
alignment. Introduce APIs on CGBuilderTy to work with Address
values. Change core APIs on CGF/CGM to traffic in Address where
appropriate. Require alignments to be non-zero. Update a ton
of code to compute and propagate alignment information.
As part of this, I've promoted CGBuiltin's EmitPointerWithAlignment
helper function to CGF and made use of it in a number of places in
the expression emitter.
The end result is that we should now be significantly more correct
when performing operations on objects that are locally known to
be under-aligned. Since alignment is not reliably tracked in the
type system, there are inherent limits to this, but at least we
are no longer confused by standard operations like derived-to-base
conversions and array-to-pointer decay. I've also fixed a large
number of bugs where we were applying the complete-object alignment
to a pointer instead of the non-virtual alignment, although most of
these were hidden by the very conservative approach we took with
member alignment.
Also, because IRGen now reliably asserts on zero alignments, we
should no longer be subject to an absurd but frustrating recurring
bug where an incomplete type would report a zero alignment and then
we'd naively do a alignmentAtOffset on it and emit code using an
alignment equal to the largest power-of-two factor of the offset.
We should also now be emitting much more aggressive alignment
attributes in the presence of over-alignment. In particular,
field access now uses alignmentAtOffset instead of min.
Several times in this patch, I had to change the existing
code-generation pattern in order to more effectively use
the Address APIs. For the most part, this seems to be a strict
improvement, like doing pointer arithmetic with GEPs instead of
ptrtoint. That said, I've tried very hard to not change semantics,
but it is likely that I've failed in a few places, for which I
apologize.
ABIArgInfo now always carries the assumed alignment of indirect and
indirect byval arguments. In order to cut down on what was already
a dauntingly large patch, I changed the code to never set align
attributes in the IR on non-byval indirect arguments. That is,
we still generate code which assumes that indirect arguments have
the given alignment, but we don't express this information to the
backend except where it's semantically required (i.e. on byvals).
This is likely a minor regression for those targets that did provide
this information, but it'll be trivial to add it back in a later
patch.
I partially punted on applying this work to CGBuiltin. Please
do not add more uses of the CreateDefaultAligned{Load,Store}
APIs; they will be going away eventually.
llvm-svn: 246985
2015-09-08 16:05:57 +08:00
|
|
|
const char *GlobalName = nullptr);
|
2011-11-23 06:48:32 +08:00
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Returns a pointer to a constant global variable for the given file-scope
|
|
|
|
/// compound literal expression.
|
Compute and preserve alignment more faithfully in IR-generation.
Introduce an Address type to bundle a pointer value with an
alignment. Introduce APIs on CGBuilderTy to work with Address
values. Change core APIs on CGF/CGM to traffic in Address where
appropriate. Require alignments to be non-zero. Update a ton
of code to compute and propagate alignment information.
As part of this, I've promoted CGBuiltin's EmitPointerWithAlignment
helper function to CGF and made use of it in a number of places in
the expression emitter.
The end result is that we should now be significantly more correct
when performing operations on objects that are locally known to
be under-aligned. Since alignment is not reliably tracked in the
type system, there are inherent limits to this, but at least we
are no longer confused by standard operations like derived-to-base
conversions and array-to-pointer decay. I've also fixed a large
number of bugs where we were applying the complete-object alignment
to a pointer instead of the non-virtual alignment, although most of
these were hidden by the very conservative approach we took with
member alignment.
Also, because IRGen now reliably asserts on zero alignments, we
should no longer be subject to an absurd but frustrating recurring
bug where an incomplete type would report a zero alignment and then
we'd naively do a alignmentAtOffset on it and emit code using an
alignment equal to the largest power-of-two factor of the offset.
We should also now be emitting much more aggressive alignment
attributes in the presence of over-alignment. In particular,
field access now uses alignmentAtOffset instead of min.
Several times in this patch, I had to change the existing
code-generation pattern in order to more effectively use
the Address APIs. For the most part, this seems to be a strict
improvement, like doing pointer arithmetic with GEPs instead of
ptrtoint. That said, I've tried very hard to not change semantics,
but it is likely that I've failed in a few places, for which I
apologize.
ABIArgInfo now always carries the assumed alignment of indirect and
indirect byval arguments. In order to cut down on what was already
a dauntingly large patch, I changed the code to never set align
attributes in the IR on non-byval indirect arguments. That is,
we still generate code which assumes that indirect arguments have
the given alignment, but we don't express this information to the
backend except where it's semantically required (i.e. on byvals).
This is likely a minor regression for those targets that did provide
this information, but it'll be trivial to add it back in a later
patch.
I partially punted on applying this work to CGBuiltin. Please
do not add more uses of the CreateDefaultAligned{Load,Store}
APIs; they will be going away eventually.
llvm-svn: 246985
2015-09-08 16:05:57 +08:00
|
|
|
ConstantAddress GetAddrOfConstantCompoundLiteral(const CompoundLiteralExpr*E);
|
2013-06-05 08:46:14 +08:00
|
|
|
|
2016-12-28 15:27:40 +08:00
|
|
|
/// If it's been emitted already, returns the GlobalVariable corresponding to
|
|
|
|
/// a compound literal. Otherwise, returns null.
|
|
|
|
llvm::GlobalVariable *
|
|
|
|
getAddrOfConstantCompoundLiteralIfEmitted(const CompoundLiteralExpr *E);
|
|
|
|
|
|
|
|
/// Notes that CLE's GlobalVariable is GV. Asserts that CLE isn't already
|
|
|
|
/// emitted.
|
|
|
|
void setAddrOfConstantCompoundLiteral(const CompoundLiteralExpr *CLE,
|
|
|
|
llvm::GlobalVariable *GV);
|
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Returns a pointer to a global variable representing a temporary
|
2013-06-05 08:46:14 +08:00
|
|
|
/// with static or thread storage duration.
|
Compute and preserve alignment more faithfully in IR-generation.
Introduce an Address type to bundle a pointer value with an
alignment. Introduce APIs on CGBuilderTy to work with Address
values. Change core APIs on CGF/CGM to traffic in Address where
appropriate. Require alignments to be non-zero. Update a ton
of code to compute and propagate alignment information.
As part of this, I've promoted CGBuiltin's EmitPointerWithAlignment
helper function to CGF and made use of it in a number of places in
the expression emitter.
The end result is that we should now be significantly more correct
when performing operations on objects that are locally known to
be under-aligned. Since alignment is not reliably tracked in the
type system, there are inherent limits to this, but at least we
are no longer confused by standard operations like derived-to-base
conversions and array-to-pointer decay. I've also fixed a large
number of bugs where we were applying the complete-object alignment
to a pointer instead of the non-virtual alignment, although most of
these were hidden by the very conservative approach we took with
member alignment.
Also, because IRGen now reliably asserts on zero alignments, we
should no longer be subject to an absurd but frustrating recurring
bug where an incomplete type would report a zero alignment and then
we'd naively do a alignmentAtOffset on it and emit code using an
alignment equal to the largest power-of-two factor of the offset.
We should also now be emitting much more aggressive alignment
attributes in the presence of over-alignment. In particular,
field access now uses alignmentAtOffset instead of min.
Several times in this patch, I had to change the existing
code-generation pattern in order to more effectively use
the Address APIs. For the most part, this seems to be a strict
improvement, like doing pointer arithmetic with GEPs instead of
ptrtoint. That said, I've tried very hard to not change semantics,
but it is likely that I've failed in a few places, for which I
apologize.
ABIArgInfo now always carries the assumed alignment of indirect and
indirect byval arguments. In order to cut down on what was already
a dauntingly large patch, I changed the code to never set align
attributes in the IR on non-byval indirect arguments. That is,
we still generate code which assumes that indirect arguments have
the given alignment, but we don't express this information to the
backend except where it's semantically required (i.e. on byvals).
This is likely a minor regression for those targets that did provide
this information, but it'll be trivial to add it back in a later
patch.
I partially punted on applying this work to CGBuiltin. Please
do not add more uses of the CreateDefaultAligned{Load,Store}
APIs; they will be going away eventually.
llvm-svn: 246985
2015-09-08 16:05:57 +08:00
|
|
|
ConstantAddress GetAddrOfGlobalTemporary(const MaterializeTemporaryExpr *E,
|
2013-06-05 08:46:14 +08:00
|
|
|
const Expr *Inner);
|
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Retrieve the record type that describes the state of an
|
2011-08-10 01:23:49 +08:00
|
|
|
/// Objective-C fast enumeration loop (for..in).
|
|
|
|
QualType getObjCFastEnumerationStateType();
|
2014-09-09 00:01:27 +08:00
|
|
|
|
2014-09-16 03:34:18 +08:00
|
|
|
// Produce code for this constructor/destructor. This method doesn't try
|
|
|
|
// to apply any ABI rules about which other constructors/destructors
|
|
|
|
// are needed or if they are alias to each other.
|
2019-03-23 07:05:10 +08:00
|
|
|
llvm::Function *codegenCXXStructor(GlobalDecl GD);
|
2014-09-16 03:34:18 +08:00
|
|
|
|
2014-09-11 23:42:06 +08:00
|
|
|
/// Return the address of the constructor/destructor of the given type.
|
2015-08-31 21:20:44 +08:00
|
|
|
llvm::Constant *
|
2019-03-23 07:05:10 +08:00
|
|
|
getAddrOfCXXStructor(GlobalDecl GD, const CGFunctionInfo *FnInfo = nullptr,
|
2014-09-09 00:01:27 +08:00
|
|
|
llvm::FunctionType *FnType = nullptr,
|
2016-12-01 07:25:13 +08:00
|
|
|
bool DontDefer = false,
|
2019-02-07 09:14:17 +08:00
|
|
|
ForDefinition_t IsForDefinition = NotForDefinition) {
|
2019-03-23 07:05:10 +08:00
|
|
|
return cast<llvm::Constant>(getAddrAndTypeOfCXXStructor(GD, FnInfo, FnType,
|
|
|
|
DontDefer,
|
2019-02-07 09:14:17 +08:00
|
|
|
IsForDefinition)
|
|
|
|
.getCallee());
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm::FunctionCallee getAddrAndTypeOfCXXStructor(
|
2019-03-23 07:05:10 +08:00
|
|
|
GlobalDecl GD, const CGFunctionInfo *FnInfo = nullptr,
|
2019-02-07 09:14:17 +08:00
|
|
|
llvm::FunctionType *FnType = nullptr, bool DontDefer = false,
|
|
|
|
ForDefinition_t IsForDefinition = NotForDefinition);
|
2014-09-09 00:01:27 +08:00
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Given a builtin id for a function like "__builtin_fabsf", return a
|
|
|
|
/// Function* for "fabsf".
|
2016-10-27 07:46:34 +08:00
|
|
|
llvm::Constant *getBuiltinLibFunction(const FunctionDecl *FD,
|
|
|
|
unsigned BuiltinID);
|
2008-08-14 07:20:05 +08:00
|
|
|
|
2013-05-05 08:41:58 +08:00
|
|
|
llvm::Function *getIntrinsic(unsigned IID, ArrayRef<llvm::Type*> Tys = None);
|
2008-07-30 07:18:29 +08:00
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Emit code for a single top level declaration.
|
2008-08-16 07:26:23 +08:00
|
|
|
void EmitTopLevelDecl(Decl *D);
|
2008-07-30 07:18:29 +08:00
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Stored a deferred empty coverage mapping for an unused
|
2014-08-05 02:41:51 +08:00
|
|
|
/// and thus uninstrumented top level declaration.
|
|
|
|
void AddDeferredUnusedCoverageMapping(Decl *D);
|
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Remove the deferred empty coverage mapping as this
|
2014-08-05 02:41:51 +08:00
|
|
|
/// declaration is actually instrumented.
|
|
|
|
void ClearUnusedCoverageMapping(const Decl *D);
|
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Emit all the deferred coverage mappings
|
2014-08-05 02:41:51 +08:00
|
|
|
/// for the uninstrumented functions.
|
|
|
|
void EmitDeferredUnusedCoverageMappings();
|
|
|
|
|
2019-11-26 01:50:58 +08:00
|
|
|
/// Emit an alias for "main" if it has no arguments (needed for wasm).
|
|
|
|
void EmitMainVoidAlias();
|
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Tell the consumer that this variable has been instantiated.
|
2012-03-08 23:51:03 +08:00
|
|
|
void HandleCXXStaticMemberVarInstantiation(VarDecl *VD);
|
2012-03-05 18:54:55 +08:00
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// If the declaration has internal linkage but is inside an
|
2013-04-06 13:00:46 +08:00
|
|
|
/// extern "C" linkage specification, prepare to emit an alias for it
|
|
|
|
/// to the expected name.
|
|
|
|
template<typename SomeDecl>
|
|
|
|
void MaybeHandleStaticInExternC(const SomeDecl *D, llvm::GlobalValue *GV);
|
|
|
|
|
2014-03-07 06:15:10 +08:00
|
|
|
/// Add a global to a list to be added to the llvm.used metadata.
|
2020-03-26 23:21:45 +08:00
|
|
|
void addUsedGlobal(llvm::GlobalValue *GV);
|
2014-03-07 06:15:10 +08:00
|
|
|
|
|
|
|
/// Add a global to a list to be added to the llvm.compiler.used metadata.
|
|
|
|
void addCompilerUsedGlobal(llvm::GlobalValue *GV);
|
2009-02-14 04:29:50 +08:00
|
|
|
|
Change some addUsedGlobal to addUsedOrCompilerUsedGlobal
An global value in the `llvm.used` list does not have GC root semantics on ELF targets.
This will be changed in a subsequent backend patch.
Change some `llvm.used` in the ELF code path to use `llvm.compiler.used` to
prevent undesired GC root semantics.
Change one extern "C" alias (due to `__attribute__((used))` in extern "C") to use `llvm.compiler.used` on all targets.
GNU ld has a rule "`__start_/__stop_` references from a live input section retain the associated C identifier name sections",
which LLD may drop entirely (currently refined to exclude SHF_LINK_ORDER/SHF_GROUP) in a future release (the rule makes it clumsy to GC metadata sections; D96914 added a way to try the potential future behavior).
For `llvm.used` global values defined in a C identifier name section, keep using `llvm.used` so that
the future LLD change will not affect them.
rnk kindly categorized the changes:
```
ObjC/blocks: this wants GC root semantics, since ObjC mainly runs on Mac.
MS C++ ABI stuff: wants GC root semantics, no change
OpenMP: unsure, but GC root semantics probably don't hurt
CodeGenModule: affected in this patch to *not* use GC root semantics so that __attribute__((used)) behavior remains the same on ELF, plus two other minor use cases that don't want GC semantics
Coverage: Probably want GC root semantics
CGExpr.cpp: refers to LTO, wants GC root
CGDeclCXX.cpp: one is MS ABI specific, so yes GC root, one is some other C++ init functionality, which should form GC roots (C++ initializers can have side effects and must run)
CGDecl.cpp: Changed in this patch for __attribute__((used))
```
Differential Revision: https://reviews.llvm.org/D97446
2021-02-27 02:42:07 +08:00
|
|
|
/// Add a global to a list to be added to the llvm.compiler.used metadata.
|
|
|
|
void addUsedOrCompilerUsedGlobal(llvm::GlobalValue *GV);
|
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Add a destructor and object to add to the C++ global destructor function.
|
2019-02-07 09:14:17 +08:00
|
|
|
void AddCXXDtorEntry(llvm::FunctionCallee DtorFn, llvm::Constant *Object) {
|
2020-05-28 05:04:43 +08:00
|
|
|
CXXGlobalDtorsOrStermFinalizers.emplace_back(DtorFn.getFunctionType(),
|
|
|
|
DtorFn.getCallee(), Object);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Add an sterm finalizer to the C++ global cleanup function.
|
|
|
|
void AddCXXStermFinalizerEntry(llvm::FunctionCallee DtorFn) {
|
|
|
|
CXXGlobalDtorsOrStermFinalizers.emplace_back(DtorFn.getFunctionType(),
|
|
|
|
DtorFn.getCallee(), nullptr);
|
2010-06-19 13:52:45 +08:00
|
|
|
}
|
2010-03-20 12:15:41 +08:00
|
|
|
|
2020-07-16 04:12:22 +08:00
|
|
|
/// Add an sterm finalizer to its own llvm.global_dtors entry.
|
|
|
|
void AddCXXStermFinalizerToGlobalDtor(llvm::Function *StermFinalizer,
|
|
|
|
int Priority) {
|
|
|
|
AddGlobalDtor(StermFinalizer, Priority);
|
|
|
|
}
|
|
|
|
|
2019-02-06 00:42:33 +08:00
|
|
|
/// Create or return a runtime function declaration with the specified type
|
2019-10-28 05:17:40 +08:00
|
|
|
/// and name. If \p AssumeConvergent is true, the call will have the
|
|
|
|
/// convergent attribute added.
|
2019-02-06 00:42:33 +08:00
|
|
|
llvm::FunctionCallee
|
2016-12-15 14:59:05 +08:00
|
|
|
CreateRuntimeFunction(llvm::FunctionType *Ty, StringRef Name,
|
2017-03-22 00:57:30 +08:00
|
|
|
llvm::AttributeList ExtraAttrs = llvm::AttributeList(),
|
2019-10-28 05:17:40 +08:00
|
|
|
bool Local = false, bool AssumeConvergent = false);
|
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Create a new runtime global variable with the specified type and name.
|
2011-07-18 12:24:23 +08:00
|
|
|
llvm::Constant *CreateRuntimeVariable(llvm::Type *Ty,
|
2011-07-20 14:58:45 +08:00
|
|
|
StringRef Name);
|
2008-10-01 08:49:24 +08:00
|
|
|
|
2010-07-16 08:00:15 +08:00
|
|
|
///@name Custom Blocks Runtime Interfaces
|
|
|
|
///@{
|
|
|
|
|
|
|
|
llvm::Constant *getNSConcreteGlobalBlock();
|
|
|
|
llvm::Constant *getNSConcreteStackBlock();
|
2019-02-06 00:42:33 +08:00
|
|
|
llvm::FunctionCallee getBlockObjectAssign();
|
|
|
|
llvm::FunctionCallee getBlockObjectDispose();
|
2010-07-16 08:00:15 +08:00
|
|
|
|
|
|
|
///@}
|
|
|
|
|
2019-02-06 03:17:50 +08:00
|
|
|
llvm::Function *getLLVMLifetimeStartFn();
|
|
|
|
llvm::Function *getLLVMLifetimeEndFn();
|
2013-03-23 14:43:35 +08:00
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
// Make sure that this type is translated.
|
2011-03-24 00:29:39 +08:00
|
|
|
void UpdateCompletedType(const TagDecl *TD);
|
2009-02-18 02:43:32 +08:00
|
|
|
|
2011-02-03 16:15:49 +08:00
|
|
|
llvm::Constant *getMemberPointerConstant(const UnaryOperator *e);
|
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Emit type info if type of an expression is a variably modified
|
2015-10-20 12:24:12 +08:00
|
|
|
/// type. Also emit proper debug info for cast types.
|
|
|
|
void EmitExplicitCastExprType(const ExplicitCastExpr *E,
|
|
|
|
CodeGenFunction *CGF = nullptr);
|
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Return the result of value-initializing the given type, i.e. a null
|
|
|
|
/// expression of the given type. This is usually, but not always, an LLVM
|
|
|
|
/// null constant.
|
2009-04-14 05:47:26 +08:00
|
|
|
llvm::Constant *EmitNullConstant(QualType T);
|
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Return a null constant appropriate for zero-initializing a base class with
|
|
|
|
/// the given type. This is usually, but not always, an LLVM null constant.
|
2011-10-14 10:27:24 +08:00
|
|
|
llvm::Constant *EmitNullConstantForBase(const CXXRecordDecl *Record);
|
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Emit a general error that something can't be done.
|
2012-03-31 03:44:53 +08:00
|
|
|
void Error(SourceLocation loc, StringRef error);
|
2011-03-18 10:56:14 +08:00
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Print out an error that codegen doesn't support the specified stmt yet.
|
2013-08-20 05:02:26 +08:00
|
|
|
void ErrorUnsupported(const Stmt *S, const char *Type);
|
2009-02-14 03:12:34 +08:00
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Print out an error that codegen doesn't support the specified decl yet.
|
2013-08-20 05:02:26 +08:00
|
|
|
void ErrorUnsupported(const Decl *D, const char *Type);
|
2008-05-22 08:50:06 +08:00
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Set the attributes on the LLVM function for the given decl and function
|
|
|
|
/// info. This applies attributes necessary for handling the ABI as well as
|
|
|
|
/// user specified attributes like section.
|
2018-03-01 07:46:35 +08:00
|
|
|
void SetInternalFunctionAttributes(GlobalDecl GD, llvm::Function *F,
|
2009-04-17 08:48:04 +08:00
|
|
|
const CGFunctionInfo &FI);
|
2008-09-05 07:41:35 +08:00
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Set the LLVM function attributes (sext, zext, etc).
|
2018-11-13 23:48:08 +08:00
|
|
|
void SetLLVMFunctionAttributes(GlobalDecl GD, const CGFunctionInfo &Info,
|
2009-04-14 15:08:30 +08:00
|
|
|
llvm::Function *F);
|
2008-09-10 08:41:16 +08:00
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Set the LLVM function attributes which only apply to a function
|
2014-08-16 04:04:40 +08:00
|
|
|
/// definition.
|
2009-04-14 16:05:55 +08:00
|
|
|
void SetLLVMFunctionAttributesForDefinition(const Decl *D, llvm::Function *F);
|
|
|
|
|
2020-09-30 01:44:36 +08:00
|
|
|
/// Set the LLVM function attributes that represent floating point
|
|
|
|
/// environment.
|
|
|
|
void setLLVMFunctionFEnvAttributes(const FunctionDecl *D, llvm::Function *F);
|
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Return true iff the given type uses 'sret' when used as a return type.
|
2010-07-15 07:39:36 +08:00
|
|
|
bool ReturnTypeUsesSRet(const CGFunctionInfo &FI);
|
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Return true iff the given type uses an argument slot when 'sret' is used
|
|
|
|
/// as a return type.
|
2014-03-29 21:28:05 +08:00
|
|
|
bool ReturnSlotInterferesWithArgs(const CGFunctionInfo &FI);
|
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Return true iff the given type uses 'fpret' when used as a return type.
|
2010-07-15 07:39:36 +08:00
|
|
|
bool ReturnTypeUsesFPRet(QualType ResultType);
|
2008-09-10 08:41:16 +08:00
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Return true iff the given type uses 'fp2ret' when used as a return type.
|
2011-11-01 00:27:11 +08:00
|
|
|
bool ReturnTypeUsesFP2Ret(QualType ResultType);
|
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Get the LLVM attributes and calling convention to use for a particular
|
|
|
|
/// function type.
|
2009-09-12 08:59:20 +08:00
|
|
|
///
|
2016-01-06 22:35:46 +08:00
|
|
|
/// \param Name - The function name.
|
2009-09-12 08:59:20 +08:00
|
|
|
/// \param Info - The function type information.
|
2015-11-24 06:04:44 +08:00
|
|
|
/// \param CalleeInfo - The callee information these attributes are being
|
|
|
|
/// constructed for. If valid, the attributes applied to this decl may
|
|
|
|
/// contribute to the function attributes and calling convention.
|
2017-04-19 07:50:03 +08:00
|
|
|
/// \param Attrs [out] - On return, the attribute list to use.
|
2009-09-12 08:59:20 +08:00
|
|
|
/// \param CallingConv [out] - On return, the LLVM calling convention to use.
|
2016-01-06 22:35:46 +08:00
|
|
|
void ConstructAttributeList(StringRef Name, const CGFunctionInfo &Info,
|
2017-04-19 07:50:03 +08:00
|
|
|
CGCalleeInfo CalleeInfo,
|
|
|
|
llvm::AttributeList &Attrs, unsigned &CallingConv,
|
|
|
|
bool AttrOnCallSite);
|
2008-09-10 08:41:16 +08:00
|
|
|
|
[CodeGen] [CUDA] Add the ability set default attrs on functions in linked modules.
Summary:
Now when you ask clang to link in a bitcode module, you can tell it to
set attributes on that module's functions to match what we would have
set if we'd emitted those functions ourselves.
This is particularly important for fast-math attributes in CUDA
compilations.
Each CUDA compilation links in libdevice, a bitcode library provided by
nvidia as part of the CUDA distribution. Without this patch, if we have
a user-function F that is compiled with -ffast-math that calls a
function G from libdevice, F will have the unsafe-fp-math=true (etc.)
attributes, but G will have no attributes.
Since F calls G, the inliner will merge G's attributes into F's. It
considers the lack of an unsafe-fp-math=true attribute on G to be
tantamount to unsafe-fp-math=false, so it "merges" these by setting
unsafe-fp-math=false on F.
This then continues up the call graph, until every function that
(transitively) calls something in libdevice gets unsafe-fp-math=false
set, thus disabling fastmath in almost all CUDA code.
Reviewers: echristo
Subscribers: hfinkel, llvm-commits, mehdi_amini
Differential Revision: https://reviews.llvm.org/D28538
llvm-svn: 293097
2017-01-26 05:29:48 +08:00
|
|
|
/// Adds attributes to F according to our CodeGenOptions and LangOptions, as
|
|
|
|
/// though we had emitted it ourselves. We remove any attributes on F that
|
|
|
|
/// conflict with the attributes we add here.
|
|
|
|
///
|
|
|
|
/// This is useful for adding attrs to bitcode modules that you want to link
|
|
|
|
/// with but don't control, such as CUDA's libdevice. When linking with such
|
|
|
|
/// a bitcode library, you might want to set e.g. its functions'
|
|
|
|
/// "unsafe-fp-math" attribute to match the attr of the functions you're
|
|
|
|
/// codegen'ing. Otherwise, LLVM will interpret the bitcode module's lack of
|
|
|
|
/// unsafe-fp-math attrs as tantamount to unsafe-fp-math=false, and then LLVM
|
|
|
|
/// will propagate unsafe-fp-math=false up to every transitive caller of a
|
|
|
|
/// function in the bitcode library!
|
|
|
|
///
|
|
|
|
/// With the exception of fast-math attrs, this will only make the attributes
|
|
|
|
/// on the function more conservative. But it's unsafe to call this on a
|
|
|
|
/// function which relies on particular fast-math attributes for correctness.
|
|
|
|
/// It's up to you to ensure that this is safe.
|
2020-05-17 02:44:54 +08:00
|
|
|
void addDefaultFunctionDefinitionAttributes(llvm::Function &F);
|
|
|
|
|
|
|
|
/// Like the overload taking a `Function &`, but intended specifically
|
|
|
|
/// for frontends that want to build on Clang's target-configuration logic.
|
|
|
|
void addDefaultFunctionDefinitionAttributes(llvm::AttrBuilder &attrs);
|
[CodeGen] [CUDA] Add the ability set default attrs on functions in linked modules.
Summary:
Now when you ask clang to link in a bitcode module, you can tell it to
set attributes on that module's functions to match what we would have
set if we'd emitted those functions ourselves.
This is particularly important for fast-math attributes in CUDA
compilations.
Each CUDA compilation links in libdevice, a bitcode library provided by
nvidia as part of the CUDA distribution. Without this patch, if we have
a user-function F that is compiled with -ffast-math that calls a
function G from libdevice, F will have the unsafe-fp-math=true (etc.)
attributes, but G will have no attributes.
Since F calls G, the inliner will merge G's attributes into F's. It
considers the lack of an unsafe-fp-math=true attribute on G to be
tantamount to unsafe-fp-math=false, so it "merges" these by setting
unsafe-fp-math=false on F.
This then continues up the call graph, until every function that
(transitively) calls something in libdevice gets unsafe-fp-math=false
set, thus disabling fastmath in almost all CUDA code.
Reviewers: echristo
Subscribers: hfinkel, llvm-commits, mehdi_amini
Differential Revision: https://reviews.llvm.org/D28538
llvm-svn: 293097
2017-01-26 05:29:48 +08:00
|
|
|
|
2011-07-20 14:58:45 +08:00
|
|
|
StringRef getMangledName(GlobalDecl GD);
|
2014-06-06 06:10:59 +08:00
|
|
|
StringRef getBlockMangledName(GlobalDecl GD, const BlockDecl *BD);
|
2009-04-22 01:11:58 +08:00
|
|
|
|
|
|
|
void EmitTentativeDefinition(const VarDecl *D);
|
2009-08-01 02:25:34 +08:00
|
|
|
|
2019-11-23 00:45:37 +08:00
|
|
|
void EmitExternalDeclaration(const VarDecl *D);
|
|
|
|
|
2015-01-15 12:07:35 +08:00
|
|
|
void EmitVTable(CXXRecordDecl *Class);
|
Rework when and how vtables are emitted, by tracking where vtables are
"used" (e.g., we will refer to the vtable in the generated code) and
when they are defined (i.e., because we've seen the key function
definition). Previously, we were effectively tracking "potential
definitions" rather than uses, so we were a bit too eager about emitting
vtables for classes without key functions.
The new scheme:
- For every use of a vtable, Sema calls MarkVTableUsed() to indicate
the use. For example, this occurs when calling a virtual member
function of the class, defining a constructor of that class type,
dynamic_cast'ing from that type to a derived class, casting
to/through a virtual base class, etc.
- For every definition of a vtable, Sema calls MarkVTableUsed() to
indicate the definition. This happens at the end of the translation
unit for classes whose key function has been defined (so we can
delay computation of the key function; see PR6564), and will also
occur with explicit template instantiation definitions.
- For every vtable defined/used, we mark all of the virtual member
functions of that vtable as defined/used, unless we know that the key
function is in another translation unit. This instantiates virtual
member functions when needed.
- At the end of the translation unit, Sema tells CodeGen (via the
ASTConsumer) which vtables must be defined (CodeGen will define
them) and which may be used (for which CodeGen will define the
vtables lazily).
From a language perspective, both the old and the new schemes are
permissible: we're allowed to instantiate virtual member functions
whenever we want per the standard. However, all other C++ compilers
were more lazy than we were, and our eagerness was both a performance
issue (we instantiated too much) and a portability problem (we broke
Boost test cases, which now pass).
Notes:
(1) There's a ton of churn in the tests, because the order in which
vtables get emitted to IR has changed. I've tried to isolate some of
the larger tests from these issues.
(2) Some diagnostics related to
implicitly-instantiated/implicitly-defined virtual member functions
have moved to the point of first use/definition. It's better this
way.
(3) I could use a review of the places where we MarkVTableUsed, to
see if I missed any place where the language effectively requires a
vtable.
Fixes PR7114 and PR6564.
llvm-svn: 103718
2010-05-14 00:44:06 +08:00
|
|
|
|
2016-01-27 03:30:26 +08:00
|
|
|
void RefreshTypeCacheForClass(const CXXRecordDecl *Class);
|
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Appends Opts to the "llvm.linker.options" metadata value.
|
2013-05-08 21:44:39 +08:00
|
|
|
void AppendLinkerOptions(StringRef Opts);
|
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Appends a detect mismatch command to the linker options.
|
2013-06-04 10:07:14 +08:00
|
|
|
void AddDetectMismatch(StringRef Name, StringRef Value);
|
|
|
|
|
[ELF] Implement Dependent Libraries Feature
This patch implements a limited form of autolinking primarily designed to allow
either the --dependent-library compiler option, or "comment lib" pragmas (
https://docs.microsoft.com/en-us/cpp/preprocessor/comment-c-cpp?view=vs-2017) in
C/C++ e.g. #pragma comment(lib, "foo"), to cause an ELF linker to automatically
add the specified library to the link when processing the input file generated
by the compiler.
Currently this extension is unique to LLVM and LLD. However, care has been taken
to design this feature so that it could be supported by other ELF linkers.
The design goals were to provide:
- A simple linking model for developers to reason about.
- The ability to to override autolinking from the linker command line.
- Source code compatibility, where possible, with "comment lib" pragmas in other
environments (MSVC in particular).
Dependent library support is implemented differently for ELF platforms than on
the other platforms. Primarily this difference is that on ELF we pass the
dependent library specifiers directly to the linker without manipulating them.
This is in contrast to other platforms where they are mapped to a specific
linker option by the compiler. This difference is a result of the greater
variety of ELF linkers and the fact that ELF linkers tend to handle libraries in
a more complicated fashion than on other platforms. This forces us to defer
handling the specifiers to the linker.
In order to achieve a level of source code compatibility with other platforms
we have restricted this feature to work with libraries that meet the following
"reasonable" requirements:
1. There are no competing defined symbols in a given set of libraries, or
if they exist, the program owner doesn't care which is linked to their
program.
2. There may be circular dependencies between libraries.
The binary representation is a mergeable string section (SHF_MERGE,
SHF_STRINGS), called .deplibs, with custom type SHT_LLVM_DEPENDENT_LIBRARIES
(0x6fff4c04). The compiler forms this section by concatenating the arguments of
the "comment lib" pragmas and --dependent-library options in the order they are
encountered. Partial (-r, -Ur) links are handled by concatenating .deplibs
sections with the normal mergeable string section rules. As an example, #pragma
comment(lib, "foo") would result in:
.section ".deplibs","MS",@llvm_dependent_libraries,1
.asciz "foo"
For LTO, equivalent information to the contents of a the .deplibs section can be
retrieved by the LLD for bitcode input files.
LLD processes the dependent library specifiers in the following way:
1. Dependent libraries which are found from the specifiers in .deplibs sections
of relocatable object files are added when the linker decides to include that
file (which could itself be in a library) in the link. Dependent libraries
behave as if they were appended to the command line after all other options. As
a consequence the set of dependent libraries are searched last to resolve
symbols.
2. It is an error if a file cannot be found for a given specifier.
3. Any command line options in effect at the end of the command line parsing apply
to the dependent libraries, e.g. --whole-archive.
4. The linker tries to add a library or relocatable object file from each of the
strings in a .deplibs section by; first, handling the string as if it was
specified on the command line; second, by looking for the string in each of the
library search paths in turn; third, by looking for a lib<string>.a or
lib<string>.so (depending on the current mode of the linker) in each of the
library search paths.
5. A new command line option --no-dependent-libraries tells LLD to ignore the
dependent libraries.
Rationale for the above points:
1. Adding the dependent libraries last makes the process simple to understand
from a developers perspective. All linkers are able to implement this scheme.
2. Error-ing for libraries that are not found seems like better behavior than
failing the link during symbol resolution.
3. It seems useful for the user to be able to apply command line options which
will affect all of the dependent libraries. There is a potential problem of
surprise for developers, who might not realize that these options would apply
to these "invisible" input files; however, despite the potential for surprise,
this is easy for developers to reason about and gives developers the control
that they may require.
4. This algorithm takes into account all of the different ways that ELF linkers
find input files. The different search methods are tried by the linker in most
obvious to least obvious order.
5. I considered adding finer grained control over which dependent libraries were
ignored (e.g. MSVC has /nodefaultlib:<library>); however, I concluded that this
is not necessary: if finer control is required developers can fall back to using
the command line directly.
RFC thread: http://lists.llvm.org/pipermail/llvm-dev/2019-March/131004.html.
Differential Revision: https://reviews.llvm.org/D60274
llvm-svn: 360984
2019-05-17 11:44:15 +08:00
|
|
|
/// Appends a dependent lib to the appropriate metadata value.
|
2013-05-08 21:44:39 +08:00
|
|
|
void AddDependentLib(StringRef Lib);
|
|
|
|
|
2018-02-07 09:46:46 +08:00
|
|
|
|
2013-06-06 01:49:37 +08:00
|
|
|
llvm::GlobalVariable::LinkageTypes getFunctionLinkage(GlobalDecl GD);
|
2010-02-19 09:32:20 +08:00
|
|
|
|
2014-05-08 22:46:46 +08:00
|
|
|
void setFunctionLinkage(GlobalDecl GD, llvm::Function *F) {
|
|
|
|
F->setLinkage(getFunctionLinkage(GD));
|
2010-05-25 12:30:21 +08:00
|
|
|
}
|
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Return the appropriate linkage for the vtable, VTT, and type information
|
|
|
|
/// of the given class.
|
2011-01-24 10:04:33 +08:00
|
|
|
llvm::GlobalVariable::LinkageTypes getVTableLinkage(const CXXRecordDecl *RD);
|
2010-01-26 21:48:07 +08:00
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Return the store size, in character units, of the given LLVM type.
|
2011-07-18 12:24:23 +08:00
|
|
|
CharUnits GetTargetTypeStoreSize(llvm::Type *Ty) const;
|
2018-07-31 03:24:48 +08:00
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Returns LLVM linkage for a declarator.
|
2014-04-29 06:17:59 +08:00
|
|
|
llvm::GlobalValue::LinkageTypes
|
2014-05-15 03:54:53 +08:00
|
|
|
getLLVMLinkageForDeclarator(const DeclaratorDecl *D, GVALinkage Linkage,
|
2014-05-28 09:52:23 +08:00
|
|
|
bool IsConstantVariable);
|
2014-04-29 06:17:59 +08:00
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Returns LLVM linkage for a declarator.
|
2014-04-29 06:17:59 +08:00
|
|
|
llvm::GlobalValue::LinkageTypes
|
|
|
|
getLLVMLinkageVarDefinition(const VarDecl *VD, bool IsConstant);
|
|
|
|
|
2011-09-10 06:41:49 +08:00
|
|
|
/// Emit all the global annotations.
|
|
|
|
void EmitGlobalAnnotations();
|
|
|
|
|
|
|
|
/// Emit an annotation string.
|
2013-01-13 03:30:44 +08:00
|
|
|
llvm::Constant *EmitAnnotationString(StringRef Str);
|
2011-09-10 06:41:49 +08:00
|
|
|
|
|
|
|
/// Emit the annotation's translation unit.
|
|
|
|
llvm::Constant *EmitAnnotationUnit(SourceLocation Loc);
|
|
|
|
|
|
|
|
/// Emit the annotation line number.
|
|
|
|
llvm::Constant *EmitAnnotationLineNo(SourceLocation L);
|
|
|
|
|
2020-10-26 16:58:20 +08:00
|
|
|
/// Emit additional args of the annotation.
|
|
|
|
llvm::Constant *EmitAnnotationArgs(const AnnotateAttr *Attr);
|
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Generate the llvm::ConstantStruct which contains the annotation
|
|
|
|
/// information for a given GlobalValue. The annotation struct is
|
2011-09-10 06:41:49 +08:00
|
|
|
/// {i8 *, i8 *, i8 *, i32}. The first field is a constant expression, the
|
|
|
|
/// GlobalValue being annotated. The second field is the constant string
|
|
|
|
/// created from the AnnotateAttr's annotation. The third field is a constant
|
|
|
|
/// string containing the name of the translation unit. The fourth field is
|
|
|
|
/// the line number in the file of the annotated value declaration.
|
|
|
|
llvm::Constant *EmitAnnotateAttr(llvm::GlobalValue *GV,
|
|
|
|
const AnnotateAttr *AA,
|
|
|
|
SourceLocation L);
|
|
|
|
|
|
|
|
/// Add global annotations that are set on D, for the global GV. Those
|
|
|
|
/// annotations are emitted during finalization of the LLVM code.
|
|
|
|
void AddGlobalAnnotations(const ValueDecl *D, llvm::GlobalValue *GV);
|
|
|
|
|
2021-02-23 03:47:29 +08:00
|
|
|
bool isInNoSanitizeList(SanitizerMask Kind, llvm::Function *Fn,
|
|
|
|
SourceLocation Loc) const;
|
2013-01-18 19:30:38 +08:00
|
|
|
|
2021-02-23 03:47:29 +08:00
|
|
|
bool isInNoSanitizeList(llvm::GlobalVariable *GV, SourceLocation Loc,
|
|
|
|
QualType Ty, StringRef Category = StringRef()) const;
|
2014-10-18 06:37:33 +08:00
|
|
|
|
2017-03-30 08:29:36 +08:00
|
|
|
/// Imbue XRay attributes to a function, applying the always/never attribute
|
|
|
|
/// lists in the process. Returns true if we did imbue attributes this way,
|
|
|
|
/// false otherwise.
|
|
|
|
bool imbueXRayAttrs(llvm::Function *Fn, SourceLocation Loc,
|
|
|
|
StringRef Category = StringRef()) const;
|
|
|
|
|
2021-01-15 17:14:37 +08:00
|
|
|
/// Returns true if function at the given location should be excluded from
|
|
|
|
/// profile instrumentation.
|
|
|
|
bool isProfileInstrExcluded(llvm::Function *Fn, SourceLocation Loc) const;
|
|
|
|
|
2014-08-02 05:35:28 +08:00
|
|
|
SanitizerMetadata *getSanitizerMetadata() {
|
|
|
|
return SanitizerMD.get();
|
|
|
|
}
|
2014-07-03 00:54:41 +08:00
|
|
|
|
2013-01-26 06:31:03 +08:00
|
|
|
void addDeferredVTable(const CXXRecordDecl *RD) {
|
|
|
|
DeferredVTables.push_back(RD);
|
|
|
|
}
|
|
|
|
|
2018-04-06 23:14:32 +08:00
|
|
|
/// Emit code for a single global function or var decl. Forward declarations
|
2014-05-09 09:34:38 +08:00
|
|
|
/// are emitted lazily.
|
[ms-cxxabi] Emit linkonce complete dtors in TUs that need them
Based on Peter Collingbourne's destructor patches.
Prior to this change, clang was considering ?1 to be the complete
destructor and the base destructor, which was wrong. This lead to
crashes when clang tried to emit two LLVM functions with the same name.
In this ABI, TUs with non-inline dtors might not emit a complete
destructor. They are emitted as inline thunks in TUs that need them,
and they always delegate to the base dtors of the complete class and its
virtual bases. This change uses the DeferredDecls machinery to emit
complete dtors as needed.
Currently in clang try body destructors can catch exceptions thrown by
virtual base destructors. In the Microsoft C++ ABI, clang may not have
the destructor definition, in which case clang won't wrap the virtual
virtual base destructor calls in a try-catch. Diagnosing this in user
code is TODO.
Finally, for classes that don't use virtual inheritance, MSVC always
calls the base destructor (?1) directly. This is a useful code size
optimization that avoids emitting lots of extra thunks or aliases.
Implementing it also means our existing tests continue to pass, and is
consistent with MSVC's output.
We can do the same for Itanium by tweaking GetAddrOfCXXDestructor, but
it will require further testing.
Reviewers: rjmccall
CC: cfe-commits
Differential Revision: http://llvm-reviews.chandlerc.com/D1066
llvm-svn: 186828
2013-07-22 21:51:44 +08:00
|
|
|
void EmitGlobal(GlobalDecl D);
|
|
|
|
|
2014-09-16 02:46:13 +08:00
|
|
|
bool TryEmitBaseDestructorAsAlias(const CXXDestructorDecl *D);
|
|
|
|
|
2011-07-20 14:58:45 +08:00
|
|
|
llvm::GlobalValue *GetGlobalValue(StringRef Ref);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2014-09-16 23:18:21 +08:00
|
|
|
/// Set attributes which are common to any form of a global definition (alias,
|
|
|
|
/// Objective-C method, function, global variable).
|
|
|
|
///
|
|
|
|
/// NOTE: This should only be called for definitions.
|
2018-03-01 08:06:55 +08:00
|
|
|
void SetCommonAttributes(GlobalDecl GD, llvm::GlobalValue *GV);
|
2014-09-16 23:18:21 +08:00
|
|
|
|
|
|
|
void addReplacement(StringRef Name, llvm::Constant *C);
|
2014-11-11 12:05:39 +08:00
|
|
|
|
2015-08-31 21:20:44 +08:00
|
|
|
void addGlobalValReplacement(llvm::GlobalValue *GV, llvm::Constant *C);
|
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Emit a code for threadprivate directive.
|
2014-11-11 12:05:39 +08:00
|
|
|
/// \param D Threadprivate declaration.
|
|
|
|
void EmitOMPThreadPrivateDecl(const OMPThreadPrivateDecl *D);
|
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Emit a code for declare reduction construct.
|
2016-03-04 17:22:22 +08:00
|
|
|
void EmitOMPDeclareReduction(const OMPDeclareReductionDecl *D,
|
|
|
|
CodeGenFunction *CGF = nullptr);
|
2016-03-03 13:21:39 +08:00
|
|
|
|
2019-02-02 04:25:04 +08:00
|
|
|
/// Emit a code for declare mapper construct.
|
|
|
|
void EmitOMPDeclareMapper(const OMPDeclareMapperDecl *D,
|
|
|
|
CodeGenFunction *CGF = nullptr);
|
|
|
|
|
2018-09-26 12:28:39 +08:00
|
|
|
/// Emit a code for requires directive.
|
|
|
|
/// \param D Requires declaration
|
|
|
|
void EmitOMPRequiresDecl(const OMPRequiresDecl *D);
|
|
|
|
|
2016-04-29 01:09:37 +08:00
|
|
|
/// Returns whether the given record has hidden LTO visibility and therefore
|
|
|
|
/// may participate in (single-module) CFI and whole-program vtable
|
|
|
|
/// optimization.
|
|
|
|
bool HasHiddenLTOVisibility(const CXXRecordDecl *RD);
|
2015-07-10 03:56:14 +08:00
|
|
|
|
2020-01-25 04:24:18 +08:00
|
|
|
/// Returns whether the given record has public std LTO visibility
|
|
|
|
/// and therefore may not participate in (single-module) CFI and whole-program
|
|
|
|
/// vtable optimization.
|
|
|
|
bool HasLTOVisibilityPublicStd(const CXXRecordDecl *RD);
|
|
|
|
|
Reland: Dead Virtual Function Elimination
Remove dead virtual functions from vtables with
replaceNonMetadataUsesWith, so that CGProfile metadata gets cleaned up
correctly.
Original commit message:
Currently, it is hard for the compiler to remove unused C++ virtual
functions, because they are all referenced from vtables, which are referenced
by constructors. This means that if the constructor is called from any live
code, then we keep every virtual function in the final link, even if there
are no call sites which can use it.
This patch allows unused virtual functions to be removed during LTO (and
regular compilation in limited circumstances) by using type metadata to match
virtual function call sites to the vtable slots they might load from. This
information can then be used in the global dead code elimination pass instead
of the references from vtables to virtual functions, to more accurately
determine which functions are reachable.
To make this transformation safe, I have changed clang's code-generation to
always load virtual function pointers using the llvm.type.checked.load
intrinsic, instead of regular load instructions. I originally tried writing
this using clang's existing code-generation, which uses the llvm.type.test
and llvm.assume intrinsics after doing a normal load. However, it is possible
for optimisations to obscure the relationship between the GEP, load and
llvm.type.test, causing GlobalDCE to fail to find virtual function call
sites.
The existing linkage and visibility types don't accurately describe the scope
in which a virtual call could be made which uses a given vtable. This is
wider than the visibility of the type itself, because a virtual function call
could be made using a more-visible base class. I've added a new
!vcall_visibility metadata type to represent this, described in
TypeMetadata.rst. The internalization pass and libLTO have been updated to
change this metadata when linking is performed.
This doesn't currently work with ThinLTO, because it needs to see every call
to llvm.type.checked.load in the linkage unit. It might be possible to
extend this optimisation to be able to use the ThinLTO summary, as was done
for devirtualization, but until then that combination is rejected in the
clang driver.
To test this, I've written a fuzzer which generates random C++ programs with
complex class inheritance graphs, and virtual functions called through object
and function pointers of different types. The programs are spread across
multiple translation units and DSOs to test the different visibility
restrictions.
I've also tried doing bootstrap builds of LLVM to test this. This isn't
ideal, because only classes in anonymous namespaces can be optimised with
-fvisibility=default, and some parts of LLVM (plugins and bugpoint) do not
work correctly with -fvisibility=hidden. However, there are only 12 test
failures when building with -fvisibility=hidden (and an unmodified compiler),
and this change does not cause any new failures for either value of
-fvisibility.
On the 7 C++ sub-benchmarks of SPEC2006, this gives a geomean code-size
reduction of ~6%, over a baseline compiled with "-O2 -flto
-fvisibility=hidden -fwhole-program-vtables". The best cases are reductions
of ~14% in 450.soplex and 483.xalancbmk, and there are no code size
increases.
I've also run this on a set of 8 mbed-os examples compiled for Armv7M, which
show a geomean size reduction of ~3%, again with no size increases.
I had hoped that this would have no effect on performance, which would allow
it to awlays be enabled (when using -fwhole-program-vtables). However, the
changes in clang to use the llvm.type.checked.load intrinsic are causing ~1%
performance regression in the C++ parts of SPEC2006. It should be possible to
recover some of this perf loss by teaching optimisations about the
llvm.type.checked.load intrinsic, which would make it worth turning this on
by default (though it's still dependent on -fwhole-program-vtables).
Differential revision: https://reviews.llvm.org/D63932
llvm-svn: 375094
2019-10-17 17:58:57 +08:00
|
|
|
/// Returns the vcall visibility of the given type. This is the scope in which
|
|
|
|
/// a virtual function call could be made which ends up being dispatched to a
|
|
|
|
/// member function of this class. This scope can be wider than the visibility
|
|
|
|
/// of the class itself when the class has a more-visible dynamic base class.
|
2020-11-18 06:44:25 +08:00
|
|
|
/// The client should pass in an empty Visited set, which is used to prevent
|
|
|
|
/// redundant recursive processing.
|
Reland: Dead Virtual Function Elimination
Remove dead virtual functions from vtables with
replaceNonMetadataUsesWith, so that CGProfile metadata gets cleaned up
correctly.
Original commit message:
Currently, it is hard for the compiler to remove unused C++ virtual
functions, because they are all referenced from vtables, which are referenced
by constructors. This means that if the constructor is called from any live
code, then we keep every virtual function in the final link, even if there
are no call sites which can use it.
This patch allows unused virtual functions to be removed during LTO (and
regular compilation in limited circumstances) by using type metadata to match
virtual function call sites to the vtable slots they might load from. This
information can then be used in the global dead code elimination pass instead
of the references from vtables to virtual functions, to more accurately
determine which functions are reachable.
To make this transformation safe, I have changed clang's code-generation to
always load virtual function pointers using the llvm.type.checked.load
intrinsic, instead of regular load instructions. I originally tried writing
this using clang's existing code-generation, which uses the llvm.type.test
and llvm.assume intrinsics after doing a normal load. However, it is possible
for optimisations to obscure the relationship between the GEP, load and
llvm.type.test, causing GlobalDCE to fail to find virtual function call
sites.
The existing linkage and visibility types don't accurately describe the scope
in which a virtual call could be made which uses a given vtable. This is
wider than the visibility of the type itself, because a virtual function call
could be made using a more-visible base class. I've added a new
!vcall_visibility metadata type to represent this, described in
TypeMetadata.rst. The internalization pass and libLTO have been updated to
change this metadata when linking is performed.
This doesn't currently work with ThinLTO, because it needs to see every call
to llvm.type.checked.load in the linkage unit. It might be possible to
extend this optimisation to be able to use the ThinLTO summary, as was done
for devirtualization, but until then that combination is rejected in the
clang driver.
To test this, I've written a fuzzer which generates random C++ programs with
complex class inheritance graphs, and virtual functions called through object
and function pointers of different types. The programs are spread across
multiple translation units and DSOs to test the different visibility
restrictions.
I've also tried doing bootstrap builds of LLVM to test this. This isn't
ideal, because only classes in anonymous namespaces can be optimised with
-fvisibility=default, and some parts of LLVM (plugins and bugpoint) do not
work correctly with -fvisibility=hidden. However, there are only 12 test
failures when building with -fvisibility=hidden (and an unmodified compiler),
and this change does not cause any new failures for either value of
-fvisibility.
On the 7 C++ sub-benchmarks of SPEC2006, this gives a geomean code-size
reduction of ~6%, over a baseline compiled with "-O2 -flto
-fvisibility=hidden -fwhole-program-vtables". The best cases are reductions
of ~14% in 450.soplex and 483.xalancbmk, and there are no code size
increases.
I've also run this on a set of 8 mbed-os examples compiled for Armv7M, which
show a geomean size reduction of ~3%, again with no size increases.
I had hoped that this would have no effect on performance, which would allow
it to awlays be enabled (when using -fwhole-program-vtables). However, the
changes in clang to use the llvm.type.checked.load intrinsic are causing ~1%
performance regression in the C++ parts of SPEC2006. It should be possible to
recover some of this perf loss by teaching optimisations about the
llvm.type.checked.load intrinsic, which would make it worth turning this on
by default (though it's still dependent on -fwhole-program-vtables).
Differential revision: https://reviews.llvm.org/D63932
llvm-svn: 375094
2019-10-17 17:58:57 +08:00
|
|
|
llvm::GlobalObject::VCallVisibility
|
2020-11-18 06:44:25 +08:00
|
|
|
GetVCallVisibilityLevel(const CXXRecordDecl *RD,
|
|
|
|
llvm::DenseSet<const CXXRecordDecl *> &Visited);
|
Reland: Dead Virtual Function Elimination
Remove dead virtual functions from vtables with
replaceNonMetadataUsesWith, so that CGProfile metadata gets cleaned up
correctly.
Original commit message:
Currently, it is hard for the compiler to remove unused C++ virtual
functions, because they are all referenced from vtables, which are referenced
by constructors. This means that if the constructor is called from any live
code, then we keep every virtual function in the final link, even if there
are no call sites which can use it.
This patch allows unused virtual functions to be removed during LTO (and
regular compilation in limited circumstances) by using type metadata to match
virtual function call sites to the vtable slots they might load from. This
information can then be used in the global dead code elimination pass instead
of the references from vtables to virtual functions, to more accurately
determine which functions are reachable.
To make this transformation safe, I have changed clang's code-generation to
always load virtual function pointers using the llvm.type.checked.load
intrinsic, instead of regular load instructions. I originally tried writing
this using clang's existing code-generation, which uses the llvm.type.test
and llvm.assume intrinsics after doing a normal load. However, it is possible
for optimisations to obscure the relationship between the GEP, load and
llvm.type.test, causing GlobalDCE to fail to find virtual function call
sites.
The existing linkage and visibility types don't accurately describe the scope
in which a virtual call could be made which uses a given vtable. This is
wider than the visibility of the type itself, because a virtual function call
could be made using a more-visible base class. I've added a new
!vcall_visibility metadata type to represent this, described in
TypeMetadata.rst. The internalization pass and libLTO have been updated to
change this metadata when linking is performed.
This doesn't currently work with ThinLTO, because it needs to see every call
to llvm.type.checked.load in the linkage unit. It might be possible to
extend this optimisation to be able to use the ThinLTO summary, as was done
for devirtualization, but until then that combination is rejected in the
clang driver.
To test this, I've written a fuzzer which generates random C++ programs with
complex class inheritance graphs, and virtual functions called through object
and function pointers of different types. The programs are spread across
multiple translation units and DSOs to test the different visibility
restrictions.
I've also tried doing bootstrap builds of LLVM to test this. This isn't
ideal, because only classes in anonymous namespaces can be optimised with
-fvisibility=default, and some parts of LLVM (plugins and bugpoint) do not
work correctly with -fvisibility=hidden. However, there are only 12 test
failures when building with -fvisibility=hidden (and an unmodified compiler),
and this change does not cause any new failures for either value of
-fvisibility.
On the 7 C++ sub-benchmarks of SPEC2006, this gives a geomean code-size
reduction of ~6%, over a baseline compiled with "-O2 -flto
-fvisibility=hidden -fwhole-program-vtables". The best cases are reductions
of ~14% in 450.soplex and 483.xalancbmk, and there are no code size
increases.
I've also run this on a set of 8 mbed-os examples compiled for Armv7M, which
show a geomean size reduction of ~3%, again with no size increases.
I had hoped that this would have no effect on performance, which would allow
it to awlays be enabled (when using -fwhole-program-vtables). However, the
changes in clang to use the llvm.type.checked.load intrinsic are causing ~1%
performance regression in the C++ parts of SPEC2006. It should be possible to
recover some of this perf loss by teaching optimisations about the
llvm.type.checked.load intrinsic, which would make it worth turning this on
by default (though it's still dependent on -fwhole-program-vtables).
Differential revision: https://reviews.llvm.org/D63932
llvm-svn: 375094
2019-10-17 17:58:57 +08:00
|
|
|
|
2016-06-25 05:21:46 +08:00
|
|
|
/// Emit type metadata for the given vtable using the given layout.
|
Reland: Dead Virtual Function Elimination
Remove dead virtual functions from vtables with
replaceNonMetadataUsesWith, so that CGProfile metadata gets cleaned up
correctly.
Original commit message:
Currently, it is hard for the compiler to remove unused C++ virtual
functions, because they are all referenced from vtables, which are referenced
by constructors. This means that if the constructor is called from any live
code, then we keep every virtual function in the final link, even if there
are no call sites which can use it.
This patch allows unused virtual functions to be removed during LTO (and
regular compilation in limited circumstances) by using type metadata to match
virtual function call sites to the vtable slots they might load from. This
information can then be used in the global dead code elimination pass instead
of the references from vtables to virtual functions, to more accurately
determine which functions are reachable.
To make this transformation safe, I have changed clang's code-generation to
always load virtual function pointers using the llvm.type.checked.load
intrinsic, instead of regular load instructions. I originally tried writing
this using clang's existing code-generation, which uses the llvm.type.test
and llvm.assume intrinsics after doing a normal load. However, it is possible
for optimisations to obscure the relationship between the GEP, load and
llvm.type.test, causing GlobalDCE to fail to find virtual function call
sites.
The existing linkage and visibility types don't accurately describe the scope
in which a virtual call could be made which uses a given vtable. This is
wider than the visibility of the type itself, because a virtual function call
could be made using a more-visible base class. I've added a new
!vcall_visibility metadata type to represent this, described in
TypeMetadata.rst. The internalization pass and libLTO have been updated to
change this metadata when linking is performed.
This doesn't currently work with ThinLTO, because it needs to see every call
to llvm.type.checked.load in the linkage unit. It might be possible to
extend this optimisation to be able to use the ThinLTO summary, as was done
for devirtualization, but until then that combination is rejected in the
clang driver.
To test this, I've written a fuzzer which generates random C++ programs with
complex class inheritance graphs, and virtual functions called through object
and function pointers of different types. The programs are spread across
multiple translation units and DSOs to test the different visibility
restrictions.
I've also tried doing bootstrap builds of LLVM to test this. This isn't
ideal, because only classes in anonymous namespaces can be optimised with
-fvisibility=default, and some parts of LLVM (plugins and bugpoint) do not
work correctly with -fvisibility=hidden. However, there are only 12 test
failures when building with -fvisibility=hidden (and an unmodified compiler),
and this change does not cause any new failures for either value of
-fvisibility.
On the 7 C++ sub-benchmarks of SPEC2006, this gives a geomean code-size
reduction of ~6%, over a baseline compiled with "-O2 -flto
-fvisibility=hidden -fwhole-program-vtables". The best cases are reductions
of ~14% in 450.soplex and 483.xalancbmk, and there are no code size
increases.
I've also run this on a set of 8 mbed-os examples compiled for Armv7M, which
show a geomean size reduction of ~3%, again with no size increases.
I had hoped that this would have no effect on performance, which would allow
it to awlays be enabled (when using -fwhole-program-vtables). However, the
changes in clang to use the llvm.type.checked.load intrinsic are causing ~1%
performance regression in the C++ parts of SPEC2006. It should be possible to
recover some of this perf loss by teaching optimisations about the
llvm.type.checked.load intrinsic, which would make it worth turning this on
by default (though it's still dependent on -fwhole-program-vtables).
Differential revision: https://reviews.llvm.org/D63932
llvm-svn: 375094
2019-10-17 17:58:57 +08:00
|
|
|
void EmitVTableTypeMetadata(const CXXRecordDecl *RD,
|
|
|
|
llvm::GlobalVariable *VTable,
|
2016-06-25 05:21:46 +08:00
|
|
|
const VTableLayout &VTLayout);
|
2015-02-21 04:30:56 +08:00
|
|
|
|
2016-06-25 05:21:46 +08:00
|
|
|
/// Generate a cross-DSO type identifier for MD.
|
|
|
|
llvm::ConstantInt *CreateCrossDsoCfiTypeId(llvm::Metadata *MD);
|
2015-12-16 07:00:20 +08:00
|
|
|
|
2015-09-09 07:01:30 +08:00
|
|
|
/// Create a metadata identifier for the given type. This may either be an
|
|
|
|
/// MDString (for external identifiers) or a distinct unnamed MDNode (for
|
|
|
|
/// internal identifiers).
|
|
|
|
llvm::Metadata *CreateMetadataIdentifierForType(QualType T);
|
|
|
|
|
2018-06-26 10:15:47 +08:00
|
|
|
/// Create a metadata identifier that is intended to be used to check virtual
|
|
|
|
/// calls via a member function pointer.
|
|
|
|
llvm::Metadata *CreateMetadataIdentifierForVirtualMemPtrType(QualType T);
|
|
|
|
|
2017-11-01 06:39:44 +08:00
|
|
|
/// Create a metadata identifier for the generalization of the given type.
|
|
|
|
/// This may either be an MDString (for external identifiers) or a distinct
|
|
|
|
/// unnamed MDNode (for internal identifiers).
|
|
|
|
llvm::Metadata *CreateMetadataIdentifierGeneralized(QualType T);
|
|
|
|
|
2016-06-25 05:21:46 +08:00
|
|
|
/// Create and attach type metadata to the given function.
|
2018-06-26 10:15:47 +08:00
|
|
|
void CreateFunctionTypeMetadataForIcall(const FunctionDecl *FD,
|
|
|
|
llvm::Function *F);
|
2015-12-16 07:00:20 +08:00
|
|
|
|
2021-02-11 10:34:01 +08:00
|
|
|
/// Whether this function's return type has no side effects, and thus may
|
|
|
|
/// be trivially discarded if it is unused.
|
|
|
|
bool MayDropFunctionReturn(const ASTContext &Context, QualType ReturnType);
|
|
|
|
|
2016-06-25 05:21:46 +08:00
|
|
|
/// Returns whether this module needs the "all-vtables" type identifier.
|
|
|
|
bool NeedAllVtablesTypeId() const;
|
2016-02-04 06:18:55 +08:00
|
|
|
|
2016-06-25 05:21:46 +08:00
|
|
|
/// Create and attach type metadata for the given vtable.
|
|
|
|
void AddVTableTypeMetadata(llvm::GlobalVariable *VTable, CharUnits Offset,
|
|
|
|
const CXXRecordDecl *RD);
|
2015-06-18 03:08:05 +08:00
|
|
|
|
2018-06-26 10:15:47 +08:00
|
|
|
/// Return a vector of most-base classes for RD. This is used to implement
|
|
|
|
/// control flow integrity checks for member function pointers.
|
|
|
|
///
|
|
|
|
/// A most-base class of a class C is defined as a recursive base class of C,
|
|
|
|
/// including C itself, that does not have any bases.
|
|
|
|
std::vector<const CXXRecordDecl *>
|
|
|
|
getMostBaseClasses(const CXXRecordDecl *RD);
|
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Get the declaration of std::terminate for the platform.
|
2019-02-06 00:42:33 +08:00
|
|
|
llvm::FunctionCallee getTerminateFn();
|
2015-03-04 03:21:04 +08:00
|
|
|
|
2016-01-16 08:31:22 +08:00
|
|
|
llvm::SanitizerStatReport &getSanStats();
|
|
|
|
|
2016-07-29 03:26:30 +08:00
|
|
|
llvm::Value *
|
|
|
|
createOpenCLIntToSamplerConversion(const Expr *E, CodeGenFunction &CGF);
|
|
|
|
|
2019-05-09 21:55:44 +08:00
|
|
|
/// OpenCL v1.2 s5.6.4.6 allows the compiler to store kernel argument
|
|
|
|
/// information in the program executable. The argument information stored
|
|
|
|
/// includes the argument name, its type, the address and access qualifiers
|
|
|
|
/// used. This helper can be used to generate metadata for source code kernel
|
|
|
|
/// function as well as generated implicitly kernels. If a kernel is generated
|
|
|
|
/// implicitly null value has to be passed to the last two parameters,
|
|
|
|
/// otherwise all parameters must have valid non-null values.
|
|
|
|
/// \param FN is a pointer to IR function being generated.
|
|
|
|
/// \param FD is a pointer to function declaration if any.
|
|
|
|
/// \param CGF is a pointer to CodeGenFunction that generates this function.
|
2019-05-10 18:36:37 +08:00
|
|
|
void GenOpenCLArgMetadata(llvm::Function *FN,
|
|
|
|
const FunctionDecl *FD = nullptr,
|
|
|
|
CodeGenFunction *CGF = nullptr);
|
2019-05-09 21:55:44 +08:00
|
|
|
|
2016-12-15 16:09:08 +08:00
|
|
|
/// Get target specific null pointer.
|
|
|
|
/// \param T is the LLVM type of the null pointer.
|
|
|
|
/// \param QT is the clang QualType of the null pointer.
|
|
|
|
llvm::Constant *getNullPointer(llvm::PointerType *T, QualType QT);
|
|
|
|
|
2020-05-19 02:29:11 +08:00
|
|
|
CharUnits getNaturalTypeAlignment(QualType T,
|
|
|
|
LValueBaseInfo *BaseInfo = nullptr,
|
|
|
|
TBAAAccessInfo *TBAAInfo = nullptr,
|
|
|
|
bool forPointeeType = false);
|
|
|
|
CharUnits getNaturalPointeeTypeAlignment(QualType T,
|
|
|
|
LValueBaseInfo *BaseInfo = nullptr,
|
|
|
|
TBAAAccessInfo *TBAAInfo = nullptr);
|
Add a flag to debug automatic variable initialization
Summary:
Add -ftrivial-auto-var-init-stop-after= to limit the number of times
stack variables are initialized when -ftrivial-auto-var-init= is used to
initialize stack variables to zero or a pattern. This flag can be used
to bisect uninitialized uses of a stack variable exposed by automatic
variable initialization, such as http://crrev.com/c/2020401.
Reviewers: jfb, vitalybuka, kcc, glider, rsmith, rjmccall, pcc, eugenis, vlad.tsyrklevich
Reviewed By: jfb
Subscribers: phosek, hubert.reinterpretcast, srhines, MaskRay, george.burgess.iv, dexonsmith, inglorion, gbiv, llozano, manojgupta, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D77168
2020-06-09 02:53:23 +08:00
|
|
|
bool stopAutoInit();
|
2020-05-19 02:29:11 +08:00
|
|
|
|
2021-01-20 06:36:58 +08:00
|
|
|
/// Print the postfix for externalized static variable for single source
|
|
|
|
/// offloading languages CUDA and HIP.
|
|
|
|
void printPostfixForExternalizedStaticVar(llvm::raw_ostream &OS) const;
|
|
|
|
|
2014-09-16 23:18:21 +08:00
|
|
|
private:
|
2017-03-22 00:57:30 +08:00
|
|
|
llvm::Constant *GetOrCreateLLVMFunction(
|
|
|
|
StringRef MangledName, llvm::Type *Ty, GlobalDecl D, bool ForVTable,
|
|
|
|
bool DontDefer = false, bool IsThunk = false,
|
|
|
|
llvm::AttributeList ExtraAttrs = llvm::AttributeList(),
|
|
|
|
ForDefinition_t IsForDefinition = NotForDefinition);
|
2013-12-09 12:29:47 +08:00
|
|
|
|
2018-10-26 02:57:19 +08:00
|
|
|
llvm::Constant *GetOrCreateMultiVersionResolver(GlobalDecl GD,
|
|
|
|
llvm::Type *DeclTy,
|
|
|
|
const FunctionDecl *FD);
|
Implement Attribute Target MultiVersioning
GCC's attribute 'target', in addition to being an optimization hint,
also allows function multiversioning. We currently have the former
implemented, this is the latter's implementation.
This works by enabling functions with the same name/signature to coexist,
so that they can all be emitted. Multiversion state is stored in the
FunctionDecl itself, and SemaDecl manages the definitions.
Note that it ends up having to permit redefinition of functions so
that they can all be emitted. Additionally, all versions of the function
must be emitted, so this also manages that.
Note that this includes some additional rules that GCC does not, since
defining something as a MultiVersion function after a usage has been made illegal.
The only 'history rewriting' that happens is if a function is emitted before
it has been converted to a multiversion'ed function, at which point its name
needs to be changed.
Function templates and virtual functions are NOT yet supported (not supported
in GCC either).
Additionally, constructors/destructors are disallowed, but the former is
planned.
llvm-svn: 322028
2018-01-09 05:34:17 +08:00
|
|
|
void UpdateMultiVersionNames(GlobalDecl GD, const FunctionDecl *FD);
|
|
|
|
|
2011-07-20 14:58:45 +08:00
|
|
|
llvm::Constant *GetOrCreateLLVMGlobal(StringRef MangledName,
|
2011-07-18 12:24:23 +08:00
|
|
|
llvm::PointerType *PTy,
|
2016-01-14 18:41:16 +08:00
|
|
|
const VarDecl *D,
|
2016-12-01 07:25:13 +08:00
|
|
|
ForDefinition_t IsForDefinition
|
|
|
|
= NotForDefinition);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2018-11-13 23:48:08 +08:00
|
|
|
bool GetCPUAndFeaturesAttributes(GlobalDecl GD,
|
2018-02-13 01:01:41 +08:00
|
|
|
llvm::AttrBuilder &AttrBuilder);
|
2018-03-01 07:54:23 +08:00
|
|
|
void setNonAliasAttributes(GlobalDecl GD, llvm::GlobalObject *GO);
|
2014-05-06 04:21:03 +08:00
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Set function attributes for a function declaration.
|
2014-11-01 13:42:23 +08:00
|
|
|
void SetFunctionAttributes(GlobalDecl GD, llvm::Function *F,
|
2018-02-08 03:04:41 +08:00
|
|
|
bool IsIncompleteFunction, bool IsThunk);
|
2008-06-08 23:45:52 +08:00
|
|
|
|
2014-05-21 13:09:00 +08:00
|
|
|
void EmitGlobalDefinition(GlobalDecl D, llvm::GlobalValue *GV = nullptr);
|
2009-02-19 15:15:39 +08:00
|
|
|
|
2013-12-10 00:01:03 +08:00
|
|
|
void EmitGlobalFunctionDefinition(GlobalDecl GD, llvm::GlobalValue *GV);
|
2018-11-13 23:48:08 +08:00
|
|
|
void EmitMultiVersionFunctionDefinition(GlobalDecl GD, llvm::GlobalValue *GV);
|
|
|
|
|
2016-01-14 18:41:16 +08:00
|
|
|
void EmitGlobalVarDefinition(const VarDecl *D, bool IsTentative = false);
|
2019-11-23 00:45:37 +08:00
|
|
|
void EmitExternalVarDeclaration(const VarDecl *D);
|
2010-03-20 07:29:14 +08:00
|
|
|
void EmitAliasDefinition(GlobalDecl GD);
|
2016-04-11 15:48:59 +08:00
|
|
|
void emitIFuncDefinition(GlobalDecl GD);
|
2018-07-20 22:13:28 +08:00
|
|
|
void emitCPUDispatchDefinition(GlobalDecl GD);
|
2008-08-26 16:29:31 +08:00
|
|
|
void EmitObjCPropertyImplementations(const ObjCImplementationDecl *D);
|
2010-04-29 05:28:56 +08:00
|
|
|
void EmitObjCIvarInitializations(ObjCImplementationDecl *D);
|
2018-07-31 03:24:48 +08:00
|
|
|
|
2009-04-15 23:55:24 +08:00
|
|
|
// C++ related functions.
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2016-09-09 07:14:54 +08:00
|
|
|
void EmitDeclContext(const DeclContext *DC);
|
2009-04-02 13:55:18 +08:00
|
|
|
void EmitLinkageSpec(const LinkageSpecDecl *D);
|
2009-04-15 23:55:24 +08:00
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Emit the function that initializes C++ thread_local variables.
|
2013-04-20 00:42:07 +08:00
|
|
|
void EmitCXXThreadLocalInitFunc();
|
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Emit the function that initializes C++ globals.
|
2009-08-09 07:24:23 +08:00
|
|
|
void EmitCXXGlobalInitFunc();
|
2010-01-08 08:50:11 +08:00
|
|
|
|
2020-05-28 05:04:43 +08:00
|
|
|
/// Emit the function that performs cleanup associated with C++ globals.
|
|
|
|
void EmitCXXGlobalCleanUpFunc();
|
2010-03-20 12:15:41 +08:00
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Emit the function that initializes the specified global (if PerformInit is
|
|
|
|
/// true) and registers its destructor.
|
2010-11-06 17:44:32 +08:00
|
|
|
void EmitCXXGlobalVarDeclInitFunc(const VarDecl *D,
|
2012-02-14 06:16:19 +08:00
|
|
|
llvm::GlobalVariable *Addr,
|
|
|
|
bool PerformInit);
|
2010-01-08 08:50:11 +08:00
|
|
|
|
2014-07-22 08:53:05 +08:00
|
|
|
void EmitPointerToInitFunc(const VarDecl *VD, llvm::GlobalVariable *Addr,
|
|
|
|
llvm::Function *InitFunc, InitSegAttr *ISA);
|
|
|
|
|
2008-08-01 08:01:51 +08:00
|
|
|
// FIXME: Hardcoding priority here is gross.
|
2014-05-24 05:13:45 +08:00
|
|
|
void AddGlobalCtor(llvm::Function *Ctor, int Priority = 65535,
|
2015-09-30 04:56:43 +08:00
|
|
|
llvm::Constant *AssociatedData = nullptr);
|
2020-11-19 21:58:38 +08:00
|
|
|
void AddGlobalDtor(llvm::Function *Dtor, int Priority = 65535,
|
|
|
|
bool IsDtorAttrFunc = false);
|
2008-08-01 08:01:51 +08:00
|
|
|
|
2016-10-27 17:12:20 +08:00
|
|
|
/// EmitCtorList - Generates a global array of functions and priorities using
|
|
|
|
/// the given list and name. This array will have appending linkage and is
|
|
|
|
/// suitable for use as a LLVM constructor or destructor array. Clears Fns.
|
|
|
|
void EmitCtorList(CtorList &Fns, const char *GlobalName);
|
2008-07-30 07:18:29 +08:00
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Emit any needed decls for which code generation was deferred.
|
2012-11-15 22:28:07 +08:00
|
|
|
void EmitDeferred();
|
2009-02-14 04:29:50 +08:00
|
|
|
|
2017-06-01 16:04:05 +08:00
|
|
|
/// Try to emit external vtables as available_externally if they have emitted
|
|
|
|
/// all inlined virtual functions. It runs after EmitDeferred() and therefore
|
|
|
|
/// is not allowed to create new references to things that need to be emitted
|
|
|
|
/// lazily.
|
|
|
|
void EmitVTablesOpportunistically();
|
|
|
|
|
2013-11-06 05:37:29 +08:00
|
|
|
/// Call replaceAllUsesWith on all pairs in Replacements.
|
|
|
|
void applyReplacements();
|
|
|
|
|
2015-08-31 21:20:44 +08:00
|
|
|
/// Call replaceAllUsesWith on all pairs in GlobalValReplacements.
|
|
|
|
void applyGlobalValReplacements();
|
|
|
|
|
2013-10-23 03:26:13 +08:00
|
|
|
void checkAliases();
|
|
|
|
|
2018-04-18 02:41:52 +08:00
|
|
|
std::map<int, llvm::TinyPtrVector<llvm::Function *>> DtorsUsingAtExit;
|
|
|
|
|
|
|
|
/// Register functions annotated with __attribute__((destructor)) using
|
|
|
|
/// __cxa_atexit, if it is available, or atexit otherwise.
|
|
|
|
void registerGlobalDtorsWithAtExit();
|
|
|
|
|
2020-11-19 21:58:38 +08:00
|
|
|
// When using sinit and sterm functions, unregister
|
|
|
|
// __attribute__((destructor)) annotated functions which were previously
|
|
|
|
// registered by the atexit subroutine using unatexit.
|
|
|
|
void unregisterGlobalDtorsWithUnAtExit();
|
|
|
|
|
Implement Attribute Target MultiVersioning
GCC's attribute 'target', in addition to being an optimization hint,
also allows function multiversioning. We currently have the former
implemented, this is the latter's implementation.
This works by enabling functions with the same name/signature to coexist,
so that they can all be emitted. Multiversion state is stored in the
FunctionDecl itself, and SemaDecl manages the definitions.
Note that it ends up having to permit redefinition of functions so
that they can all be emitted. Additionally, all versions of the function
must be emitted, so this also manages that.
Note that this includes some additional rules that GCC does not, since
defining something as a MultiVersion function after a usage has been made illegal.
The only 'history rewriting' that happens is if a function is emitted before
it has been converted to a multiversion'ed function, at which point its name
needs to be changed.
Function templates and virtual functions are NOT yet supported (not supported
in GCC either).
Additionally, constructors/destructors are disallowed, but the former is
planned.
llvm-svn: 322028
2018-01-09 05:34:17 +08:00
|
|
|
void emitMultiVersionFunctions();
|
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Emit any vtables which we deferred and still have a use for.
|
2013-01-26 06:31:03 +08:00
|
|
|
void EmitDeferredVTables();
|
|
|
|
|
2017-03-23 19:14:27 +08:00
|
|
|
/// Emit a dummy function that reference a CoreFoundation symbol when
|
|
|
|
/// @available is used on Darwin.
|
|
|
|
void emitAtAvailableLinkGuard();
|
|
|
|
|
2014-03-07 06:15:10 +08:00
|
|
|
/// Emit the llvm.used and llvm.compiler.used metadata.
|
|
|
|
void emitLLVMUsed();
|
2008-10-01 08:49:24 +08:00
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Emit the link options introduced by imported modules.
|
2013-01-15 04:53:57 +08:00
|
|
|
void EmitModuleLinkOptions();
|
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Emit aliases for internal-linkage declarations inside "C" language
|
2013-04-06 13:00:46 +08:00
|
|
|
/// linkage specifications, giving them the "expected" name where possible.
|
|
|
|
void EmitStaticExternCAliases();
|
|
|
|
|
2010-07-07 07:57:41 +08:00
|
|
|
void EmitDeclMetadata();
|
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Emit the Clang version as llvm.ident metadata.
|
2013-10-17 03:28:50 +08:00
|
|
|
void EmitVersionIdentMetadata();
|
|
|
|
|
2018-12-14 23:38:15 +08:00
|
|
|
/// Emit the Clang commandline as llvm.commandline metadata.
|
|
|
|
void EmitCommandLineMetadata();
|
|
|
|
|
2020-03-10 10:23:59 +08:00
|
|
|
/// Emit the module flag metadata used to pass options controlling the
|
|
|
|
/// the backend to LLVM.
|
|
|
|
void EmitBackendOptionsMetadata(const CodeGenOptions CodeGenOpts);
|
|
|
|
|
2017-06-20 22:30:18 +08:00
|
|
|
/// Emits OpenCL specific Metadata e.g. OpenCL version.
|
|
|
|
void EmitOpenCLMetadata();
|
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// 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.
|
2011-05-05 08:08:20 +08:00
|
|
|
void EmitCoverageFile();
|
2011-05-05 04:46:58 +08:00
|
|
|
|
2015-01-10 09:19:48 +08:00
|
|
|
/// Determine whether the definition must be emitted; if this returns \c
|
|
|
|
/// false, the definition can be emitted lazily if it's used.
|
|
|
|
bool MustBeEmitted(const ValueDecl *D);
|
|
|
|
|
|
|
|
/// Determine whether the definition can be emitted eagerly, or should be
|
|
|
|
/// delayed until the end of the translation unit. This is relevant for
|
|
|
|
/// definitions whose linkage can change, e.g. implicit function instantions
|
|
|
|
/// which may later be explicitly instantiated.
|
|
|
|
bool MayBeEmittedEagerly(const ValueDecl *D);
|
2010-09-16 14:16:50 +08:00
|
|
|
|
2014-05-09 09:34:38 +08:00
|
|
|
/// Check whether we can use a "simpler", more core exceptions personality
|
|
|
|
/// function.
|
2010-09-16 14:16:50 +08:00
|
|
|
void SimplifyPersonality();
|
[CodeGen] [CUDA] Add the ability set default attrs on functions in linked modules.
Summary:
Now when you ask clang to link in a bitcode module, you can tell it to
set attributes on that module's functions to match what we would have
set if we'd emitted those functions ourselves.
This is particularly important for fast-math attributes in CUDA
compilations.
Each CUDA compilation links in libdevice, a bitcode library provided by
nvidia as part of the CUDA distribution. Without this patch, if we have
a user-function F that is compiled with -ffast-math that calls a
function G from libdevice, F will have the unsafe-fp-math=true (etc.)
attributes, but G will have no attributes.
Since F calls G, the inliner will merge G's attributes into F's. It
considers the lack of an unsafe-fp-math=true attribute on G to be
tantamount to unsafe-fp-math=false, so it "merges" these by setting
unsafe-fp-math=false on F.
This then continues up the call graph, until every function that
(transitively) calls something in libdevice gets unsafe-fp-math=false
set, thus disabling fastmath in almost all CUDA code.
Reviewers: echristo
Subscribers: hfinkel, llvm-commits, mehdi_amini
Differential Revision: https://reviews.llvm.org/D28538
llvm-svn: 293097
2017-01-26 05:29:48 +08:00
|
|
|
|
2020-05-17 02:44:54 +08:00
|
|
|
/// Helper function for ConstructAttributeList and
|
|
|
|
/// addDefaultFunctionDefinitionAttributes. Builds a set of function
|
|
|
|
/// attributes to add to a function with the given properties.
|
|
|
|
void getDefaultFunctionAttributes(StringRef Name, bool HasOptnone,
|
|
|
|
bool AttrOnCallSite,
|
|
|
|
llvm::AttrBuilder &FuncAttrs);
|
2018-06-26 10:15:47 +08:00
|
|
|
|
|
|
|
llvm::Metadata *CreateMetadataIdentifierImpl(QualType T, MetadataTypeMap &Map,
|
|
|
|
StringRef Suffix);
|
2007-05-24 14:29:05 +08:00
|
|
|
};
|
2017-08-16 05:42:52 +08:00
|
|
|
|
2007-05-24 14:29:05 +08:00
|
|
|
} // end namespace CodeGen
|
|
|
|
} // end namespace clang
|
|
|
|
|
2015-09-30 04:56:43 +08:00
|
|
|
#endif // LLVM_CLANG_LIB_CODEGEN_CODEGENMODULE_H
|