Imported Upstream version 6.10.0.49

Former-commit-id: 1d6753294b2993e1fbf92de9366bb9544db4189b
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2020-01-16 16:38:04 +00:00
parent d94e79959b
commit 468663ddbb
48518 changed files with 2789335 additions and 61176 deletions

View File

@ -0,0 +1,54 @@
//===--- BackendUtil.h - LLVM Backend Utilities -----------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_CLANG_CODEGEN_BACKENDUTIL_H
#define LLVM_CLANG_CODEGEN_BACKENDUTIL_H
#include "clang/Basic/LLVM.h"
#include "llvm/IR/ModuleSummaryIndex.h"
#include <memory>
namespace llvm {
class BitcodeModule;
template <typename T> class Expected;
class Module;
class MemoryBufferRef;
}
namespace clang {
class DiagnosticsEngine;
class HeaderSearchOptions;
class CodeGenOptions;
class TargetOptions;
class LangOptions;
enum BackendAction {
Backend_EmitAssembly, ///< Emit native assembly files
Backend_EmitBC, ///< Emit LLVM bitcode files
Backend_EmitLL, ///< Emit human-readable LLVM assembly
Backend_EmitNothing, ///< Don't emit anything (benchmarking mode)
Backend_EmitMCNull, ///< Run CodeGen, but don't emit anything
Backend_EmitObj ///< Emit native object files
};
void EmitBackendOutput(DiagnosticsEngine &Diags, const HeaderSearchOptions &,
const CodeGenOptions &CGOpts,
const TargetOptions &TOpts, const LangOptions &LOpts,
const llvm::DataLayout &TDesc, llvm::Module *M,
BackendAction Action,
std::unique_ptr<raw_pwrite_stream> OS);
void EmbedBitcode(llvm::Module *M, const CodeGenOptions &CGOpts,
llvm::MemoryBufferRef Buf);
llvm::Expected<llvm::BitcodeModule>
FindThinLTOModule(llvm::MemoryBufferRef MBRef);
}
#endif

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,91 @@
//==---- CodeGenABITypes.h - Convert Clang types to LLVM types for ABI -----==//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// CodeGenABITypes is a simple interface for getting LLVM types for
// the parameters and the return value of a function given the Clang
// types.
//
// The class is implemented as a public wrapper around the private
// CodeGenTypes class in lib/CodeGen.
//
// It allows other clients, like LLDB, to determine the LLVM types that are
// actually used in function calls, which makes it possible to then determine
// the actual ABI locations (e.g. registers, stack locations, etc.) that
// these parameters are stored in.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_CLANG_CODEGEN_CODEGENABITYPES_H
#define LLVM_CLANG_CODEGEN_CODEGENABITYPES_H
#include "clang/AST/CanonicalType.h"
#include "clang/AST/Type.h"
#include "clang/CodeGen/CGFunctionInfo.h"
namespace llvm {
class DataLayout;
class Module;
class FunctionType;
class Type;
}
namespace clang {
class ASTContext;
class CXXRecordDecl;
class CXXMethodDecl;
class CodeGenOptions;
class CoverageSourceInfo;
class DiagnosticsEngine;
class HeaderSearchOptions;
class ObjCMethodDecl;
class PreprocessorOptions;
namespace CodeGen {
class CGFunctionInfo;
class CodeGenModule;
const CGFunctionInfo &arrangeObjCMessageSendSignature(CodeGenModule &CGM,
const ObjCMethodDecl *MD,
QualType receiverType);
const CGFunctionInfo &arrangeFreeFunctionType(CodeGenModule &CGM,
CanQual<FunctionProtoType> Ty,
const FunctionDecl *FD);
const CGFunctionInfo &arrangeFreeFunctionType(CodeGenModule &CGM,
CanQual<FunctionNoProtoType> Ty);
const CGFunctionInfo &arrangeCXXMethodType(CodeGenModule &CGM,
const CXXRecordDecl *RD,
const FunctionProtoType *FTP,
const CXXMethodDecl *MD);
const CGFunctionInfo &arrangeFreeFunctionCall(CodeGenModule &CGM,
CanQualType returnType,
ArrayRef<CanQualType> argTypes,
FunctionType::ExtInfo info,
RequiredArgs args);
/// Returns null if the function type is incomplete and can't be lowered.
llvm::FunctionType *convertFreeFunctionType(CodeGenModule &CGM,
const FunctionDecl *FD);
llvm::Type *convertTypeForMemory(CodeGenModule &CGM, QualType T);
/// Given a non-bitfield struct field, return its index within the elements of
/// the struct's converted type. The returned index refers to a field number in
/// the complete object type which is returned by convertTypeForMemory. FD must
/// be a field in RD directly (i.e. not an inherited field).
unsigned getLLVMFieldNumber(CodeGenModule &CGM,
const RecordDecl *RD, const FieldDecl *FD);
} // end namespace CodeGen
} // end namespace clang
#endif

View File

@ -0,0 +1,122 @@
//===--- CodeGenAction.h - LLVM Code Generation Frontend Action -*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_CLANG_CODEGEN_CODEGENACTION_H
#define LLVM_CLANG_CODEGEN_CODEGENACTION_H
#include "clang/Frontend/FrontendAction.h"
#include <memory>
namespace llvm {
class LLVMContext;
class Module;
}
namespace clang {
class BackendConsumer;
class CodeGenAction : public ASTFrontendAction {
private:
// Let BackendConsumer access LinkModule.
friend class BackendConsumer;
/// Info about module to link into a module we're generating.
struct LinkModule {
/// The module to link in.
std::unique_ptr<llvm::Module> Module;
/// If true, we set attributes on Module's functions according to our
/// CodeGenOptions and LangOptions, as though we were generating the
/// function ourselves.
bool PropagateAttrs;
/// If true, we use LLVM module internalizer.
bool Internalize;
/// Bitwise combination of llvm::LinkerFlags used when we link the module.
unsigned LinkFlags;
};
unsigned Act;
std::unique_ptr<llvm::Module> TheModule;
/// Bitcode modules to link in to our module.
SmallVector<LinkModule, 4> LinkModules;
llvm::LLVMContext *VMContext;
bool OwnsVMContext;
std::unique_ptr<llvm::Module> loadModule(llvm::MemoryBufferRef MBRef);
protected:
/// Create a new code generation action. If the optional \p _VMContext
/// parameter is supplied, the action uses it without taking ownership,
/// otherwise it creates a fresh LLVM context and takes ownership.
CodeGenAction(unsigned _Act, llvm::LLVMContext *_VMContext = nullptr);
bool hasIRSupport() const override;
std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
StringRef InFile) override;
void ExecuteAction() override;
void EndSourceFileAction() override;
public:
~CodeGenAction() override;
/// Take the generated LLVM module, for use after the action has been run.
/// The result may be null on failure.
std::unique_ptr<llvm::Module> takeModule();
/// Take the LLVM context used by this action.
llvm::LLVMContext *takeLLVMContext();
BackendConsumer *BEConsumer;
};
class EmitAssemblyAction : public CodeGenAction {
virtual void anchor();
public:
EmitAssemblyAction(llvm::LLVMContext *_VMContext = nullptr);
};
class EmitBCAction : public CodeGenAction {
virtual void anchor();
public:
EmitBCAction(llvm::LLVMContext *_VMContext = nullptr);
};
class EmitLLVMAction : public CodeGenAction {
virtual void anchor();
public:
EmitLLVMAction(llvm::LLVMContext *_VMContext = nullptr);
};
class EmitLLVMOnlyAction : public CodeGenAction {
virtual void anchor();
public:
EmitLLVMOnlyAction(llvm::LLVMContext *_VMContext = nullptr);
};
class EmitCodeGenOnlyAction : public CodeGenAction {
virtual void anchor();
public:
EmitCodeGenOnlyAction(llvm::LLVMContext *_VMContext = nullptr);
};
class EmitObjAction : public CodeGenAction {
virtual void anchor();
public:
EmitObjAction(llvm::LLVMContext *_VMContext = nullptr);
};
}
#endif

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,109 @@
//===- ConstantInitFuture.h - "Future" constant initializers ----*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This class defines the ConstantInitFuture class. This is split out
// from ConstantInitBuilder.h in order to allow APIs to work with it
// without having to include that entire header. This is particularly
// important because it is often useful to be able to default-construct
// a future in, say, a default argument.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_CLANG_CODEGEN_CONSTANTINITFUTURE_H
#define LLVM_CLANG_CODEGEN_CONSTANTINITFUTURE_H
#include "llvm/ADT/PointerUnion.h"
#include "llvm/IR/Constant.h"
// Forward-declare ConstantInitBuilderBase and give it a
// PointerLikeTypeTraits specialization so that we can safely use it
// in a PointerUnion below.
namespace clang {
namespace CodeGen {
class ConstantInitBuilderBase;
}
}
namespace llvm {
template <>
struct PointerLikeTypeTraits< ::clang::CodeGen::ConstantInitBuilderBase*> {
using T = ::clang::CodeGen::ConstantInitBuilderBase*;
static inline void *getAsVoidPointer(T p) { return p; }
static inline T getFromVoidPointer(void *p) {return static_cast<T>(p);}
enum { NumLowBitsAvailable = 2 };
};
}
namespace clang {
namespace CodeGen {
/// A "future" for a completed constant initializer, which can be passed
/// around independently of any sub-builders (but not the original parent).
class ConstantInitFuture {
using PairTy = llvm::PointerUnion<ConstantInitBuilderBase*, llvm::Constant*>;
PairTy Data;
friend class ConstantInitBuilderBase;
explicit ConstantInitFuture(ConstantInitBuilderBase *builder);
public:
ConstantInitFuture() {}
/// A future can be explicitly created from a fixed initializer.
explicit ConstantInitFuture(llvm::Constant *initializer) : Data(initializer) {
assert(initializer && "creating null future");
}
/// Is this future non-null?
explicit operator bool() const { return bool(Data); }
/// Return the type of the initializer.
llvm::Type *getType() const;
/// Abandon this initializer.
void abandon();
/// Install the initializer into a global variable. This cannot
/// be called multiple times.
void installInGlobal(llvm::GlobalVariable *global);
void *getOpaqueValue() const { return Data.getOpaqueValue(); }
static ConstantInitFuture getFromOpaqueValue(void *value) {
ConstantInitFuture result;
result.Data = PairTy::getFromOpaqueValue(value);
return result;
}
enum {
NumLowBitsAvailable =
llvm::PointerLikeTypeTraits<PairTy>::NumLowBitsAvailable
};
};
} // end namespace CodeGen
} // end namespace clang
namespace llvm {
template <>
struct PointerLikeTypeTraits< ::clang::CodeGen::ConstantInitFuture> {
using T = ::clang::CodeGen::ConstantInitFuture;
static inline void *getAsVoidPointer(T future) {
return future.getOpaqueValue();
}
static inline T getFromVoidPointer(void *p) {
return T::getFromOpaqueValue(p);
}
enum { NumLowBitsAvailable = T::NumLowBitsAvailable };
};
} // end namespace llvm
#endif

View File

@ -0,0 +1,106 @@
//===--- CodeGen/ModuleBuilder.h - Build LLVM from ASTs ---------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file defines the ModuleBuilder interface.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_CLANG_CODEGEN_MODULEBUILDER_H
#define LLVM_CLANG_CODEGEN_MODULEBUILDER_H
#include "clang/AST/ASTConsumer.h"
namespace llvm {
class Constant;
class LLVMContext;
class Module;
class StringRef;
}
namespace clang {
class CodeGenOptions;
class CoverageSourceInfo;
class Decl;
class DiagnosticsEngine;
class GlobalDecl;
class HeaderSearchOptions;
class LangOptions;
class PreprocessorOptions;
namespace CodeGen {
class CodeGenModule;
class CGDebugInfo;
}
/// The primary public interface to the Clang code generator.
///
/// This is not really an abstract interface.
class CodeGenerator : public ASTConsumer {
virtual void anchor();
public:
/// Return an opaque reference to the CodeGenModule object, which can
/// be used in various secondary APIs. It is valid as long as the
/// CodeGenerator exists.
CodeGen::CodeGenModule &CGM();
/// Return the module that this code generator is building into.
///
/// This may return null after HandleTranslationUnit is called;
/// this signifies that there was an error generating code. A
/// diagnostic will have been generated in this case, and the module
/// will be deleted.
///
/// It will also return null if the module is released.
llvm::Module *GetModule();
/// Release ownership of the module to the caller.
///
/// It is illegal to call methods other than GetModule on the
/// CodeGenerator after releasing its module.
llvm::Module *ReleaseModule();
/// Return debug info code generator.
CodeGen::CGDebugInfo *getCGDebugInfo();
/// Given a mangled name, return a declaration which mangles that way
/// which has been added to this code generator via a Handle method.
///
/// This may return null if there was no matching declaration.
const Decl *GetDeclForMangledName(llvm::StringRef MangledName);
/// Return the LLVM address of the given global entity.
///
/// \param isForDefinition If true, the caller intends to define the
/// entity; the object returned will be an llvm::GlobalValue of
/// some sort. If false, the caller just intends to use the entity;
/// the object returned may be any sort of constant value, and the
/// code generator will schedule the entity for emission if a
/// definition has been registered with this code generator.
llvm::Constant *GetAddrOfGlobal(GlobalDecl decl, bool isForDefinition);
/// Create a new \c llvm::Module after calling HandleTranslationUnit. This
/// enable codegen in interactive processing environments.
llvm::Module* StartModule(llvm::StringRef ModuleName, llvm::LLVMContext &C);
};
/// CreateLLVMCodeGen - Create a CodeGenerator instance.
/// It is the responsibility of the caller to call delete on
/// the allocated CodeGenerator instance.
CodeGenerator *CreateLLVMCodeGen(DiagnosticsEngine &Diags,
llvm::StringRef ModuleName,
const HeaderSearchOptions &HeaderSearchOpts,
const PreprocessorOptions &PreprocessorOpts,
const CodeGenOptions &CGO,
llvm::LLVMContext& C,
CoverageSourceInfo *CoverageInfo = nullptr);
} // end namespace clang
#endif

View File

@ -0,0 +1,43 @@
//===-- CodeGen/ObjectFilePCHContainerOperations.h - ------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_CLANG_CODEGEN_OBJECT_FILE_PCH_CONTAINER_OPERATIONS_H
#define LLVM_CLANG_CODEGEN_OBJECT_FILE_PCH_CONTAINER_OPERATIONS_H
#include "clang/Frontend/PCHContainerOperations.h"
namespace clang {
/// A PCHContainerWriter implementation that uses LLVM to
/// wraps Clang modules inside a COFF, ELF, or Mach-O container.
class ObjectFilePCHContainerWriter : public PCHContainerWriter {
StringRef getFormat() const override { return "obj"; }
/// Return an ASTConsumer that can be chained with a
/// PCHGenerator that produces a wrapper file format
/// that also contains full debug info for the module.
std::unique_ptr<ASTConsumer>
CreatePCHContainerGenerator(CompilerInstance &CI,
const std::string &MainFileName,
const std::string &OutputFileName,
std::unique_ptr<llvm::raw_pwrite_stream> OS,
std::shared_ptr<PCHBuffer> Buffer) const override;
};
/// A PCHContainerReader implementation that uses LLVM to
/// wraps Clang modules inside a COFF, ELF, or Mach-O container.
class ObjectFilePCHContainerReader : public PCHContainerReader {
StringRef getFormat() const override { return "obj"; }
/// Returns the serialized AST inside the PCH container Buffer.
StringRef ExtractPCH(llvm::MemoryBufferRef Buffer) const override;
};
}
#endif

View File

@ -0,0 +1,170 @@
//==-- SwiftCallingConv.h - Swift ABI lowering -----------------------------==//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// Defines constants and types related to Swift ABI lowering.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_CLANG_CODEGEN_SWIFTCALLINGCONV_H
#define LLVM_CLANG_CODEGEN_SWIFTCALLINGCONV_H
#include "clang/AST/CanonicalType.h"
#include "clang/AST/CharUnits.h"
#include "clang/AST/Type.h"
#include "llvm/Support/TrailingObjects.h"
#include <cassert>
namespace llvm {
class IntegerType;
class Type;
class StructType;
class VectorType;
}
namespace clang {
class Decl;
class FieldDecl;
class ASTRecordLayout;
namespace CodeGen {
class ABIArgInfo;
class CodeGenModule;
class CGFunctionInfo;
namespace swiftcall {
class SwiftAggLowering {
CodeGenModule &CGM;
struct StorageEntry {
CharUnits Begin;
CharUnits End;
llvm::Type *Type;
CharUnits getWidth() const {
return End - Begin;
}
};
SmallVector<StorageEntry, 4> Entries;
bool Finished = false;
public:
SwiftAggLowering(CodeGenModule &CGM) : CGM(CGM) {}
void addOpaqueData(CharUnits begin, CharUnits end) {
addEntry(nullptr, begin, end);
}
void addTypedData(QualType type, CharUnits begin);
void addTypedData(const RecordDecl *record, CharUnits begin);
void addTypedData(const RecordDecl *record, CharUnits begin,
const ASTRecordLayout &layout);
void addTypedData(llvm::Type *type, CharUnits begin);
void addTypedData(llvm::Type *type, CharUnits begin, CharUnits end);
void finish();
/// Does this lowering require passing any data?
bool empty() const {
assert(Finished && "didn't finish lowering before calling empty()");
return Entries.empty();
}
/// According to the target Swift ABI, should a value with this lowering
/// be passed indirectly?
///
/// Note that this decision is based purely on the data layout of the
/// value and does not consider whether the type is address-only,
/// must be passed indirectly to match a function abstraction pattern, or
/// anything else that is expected to be handled by high-level lowering.
///
/// \param asReturnValue - if true, answer whether it should be passed
/// indirectly as a return value; if false, answer whether it should be
/// passed indirectly as an argument
bool shouldPassIndirectly(bool asReturnValue) const;
using EnumerationCallback =
llvm::function_ref<void(CharUnits offset, CharUnits end, llvm::Type *type)>;
/// Enumerate the expanded components of this type.
///
/// The component types will always be legal vector, floating-point,
/// integer, or pointer types.
void enumerateComponents(EnumerationCallback callback) const;
/// Return the types for a coerce-and-expand operation.
///
/// The first type matches the memory layout of the data that's been
/// added to this structure, including explicit [N x i8] arrays for any
/// internal padding.
///
/// The second type removes any internal padding members and, if only
/// one element remains, is simply that element type.
std::pair<llvm::StructType*, llvm::Type*> getCoerceAndExpandTypes() const;
private:
void addBitFieldData(const FieldDecl *field, CharUnits begin,
uint64_t bitOffset);
void addLegalTypedData(llvm::Type *type, CharUnits begin, CharUnits end);
void addEntry(llvm::Type *type, CharUnits begin, CharUnits end);
void splitVectorEntry(unsigned index);
};
/// Return the maximum voluntary integer size for the current target.
CharUnits getMaximumVoluntaryIntegerSize(CodeGenModule &CGM);
/// Return the Swift CC's notion of the natural alignment of a type.
CharUnits getNaturalAlignment(CodeGenModule &CGM, llvm::Type *type);
/// Is the given integer type "legal" for Swift's perspective on the
/// current platform?
bool isLegalIntegerType(CodeGenModule &CGM, llvm::IntegerType *type);
/// Is the given vector type "legal" for Swift's perspective on the
/// current platform?
bool isLegalVectorType(CodeGenModule &CGM, CharUnits vectorSize,
llvm::VectorType *vectorTy);
bool isLegalVectorType(CodeGenModule &CGM, CharUnits vectorSize,
llvm::Type *eltTy, unsigned numElts);
/// Minimally split a legal vector type.
std::pair<llvm::Type*, unsigned>
splitLegalVectorType(CodeGenModule &CGM, CharUnits vectorSize,
llvm::VectorType *vectorTy);
/// Turn a vector type in a sequence of legal component vector types.
///
/// The caller may assume that the sum of the data sizes of the resulting
/// types will equal the data size of the vector type.
void legalizeVectorType(CodeGenModule &CGM, CharUnits vectorSize,
llvm::VectorType *vectorTy,
llvm::SmallVectorImpl<llvm::Type*> &types);
/// Should a C++ record type be passed and returned indirectly?
bool shouldPassCXXRecordIndirectly(CodeGenModule &CGM,
const CXXRecordDecl *record);
/// Classify the rules for how to return a particular type.
ABIArgInfo classifyReturnType(CodeGenModule &CGM, CanQualType type);
/// Classify the rules for how to pass a particular type.
ABIArgInfo classifyArgumentType(CodeGenModule &CGM, CanQualType type);
/// Compute the ABI information of a swiftcall function. This is a
/// private interface for Clang.
void computeABIInfo(CodeGenModule &CGM, CGFunctionInfo &FI);
/// Is swifterror lowered to a register by the target ABI.
bool isSwiftErrorLoweredInRegister(CodeGenModule &CGM);
} // end namespace swiftcall
} // end namespace CodeGen
} // end namespace clang
#endif