summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorarphaman <arphaman@gmail.com>2013-07-16 17:38:26 +0100
committerarphaman <arphaman@gmail.com>2013-07-16 17:38:26 +0100
commitb74249ab6987393553c841301a8e7fcc08e06552 (patch)
treed799391d768c0fdb2fe8e4cb3705cf903c9e1b79
parenteaa434455ddeed5f4df2bc5d743e5e2bcc1ad1b7 (diff)
downloadflang-clang_branch.tar.gz
some fixes for flangclang_branch
-rw-r--r--include/flang/Frontend/ASTUnit.h702
-rw-r--r--include/flang/Frontend/FrontendAction.h8
-rw-r--r--lib/CodeGen/BackendUtil.cpp113
-rw-r--r--lib/CodeGen/CodeGenAction.cpp78
4 files changed, 29 insertions, 872 deletions
diff --git a/include/flang/Frontend/ASTUnit.h b/include/flang/Frontend/ASTUnit.h
index 52f7f098d6..a133f8f853 100644
--- a/include/flang/Frontend/ASTUnit.h
+++ b/include/flang/Frontend/ASTUnit.h
@@ -11,22 +11,14 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_FRONTEND_ASTUNIT_H
-#define LLVM_CLANG_FRONTEND_ASTUNIT_H
-
-#include "clang-c/Index.h"
-#include "clang/AST/ASTContext.h"
-#include "clang/Basic/FileManager.h"
-#include "clang/Basic/FileSystemOptions.h"
-#include "clang/Basic/LangOptions.h"
-#include "clang/Basic/SourceManager.h"
-#include "clang/Basic/TargetOptions.h"
-#include "clang/Lex/HeaderSearchOptions.h"
-#include "clang/Lex/ModuleLoader.h"
-#include "clang/Lex/PreprocessingRecord.h"
-#include "clang/Sema/CodeCompleteConsumer.h"
-#include "clang/Sema/Sema.h"
-#include "clang/Serialization/ASTBitCodes.h"
+#ifndef LLVM_FLANG_FRONTEND_ASTUNIT_H
+#define LLVM_FLANG_FRONTEND_ASTUNIT_H
+
+#include "flang/AST/ASTContext.h"
+#include "flang/AST/ASTConsumer.h"
+#include "flang/Basic/LangOptions.h"
+#include "flang/Basic/TargetOptions.h"
+#include "flang/Sema/Sema.h"
#include "llvm/ADT/IntrusiveRefCntPtr.h"
#include "llvm/ADT/OwningPtr.h"
#include "llvm/ADT/SmallVector.h"
@@ -43,7 +35,7 @@ namespace llvm {
class MemoryBuffer;
}
-namespace clang {
+namespace flang {
class ASTContext;
class ASTReader;
class CodeCompleteConsumer;
@@ -62,319 +54,32 @@ class ASTDeserializationListener;
/// \brief Utility class for loading a ASTContext from an AST file.
///
-class ASTUnit : public ModuleLoader {
+class ASTUnit {
private:
- IntrusiveRefCntPtr<LangOptions> LangOpts;
- IntrusiveRefCntPtr<DiagnosticsEngine> Diagnostics;
- IntrusiveRefCntPtr<FileManager> FileMgr;
- IntrusiveRefCntPtr<SourceManager> SourceMgr;
- OwningPtr<HeaderSearch> HeaderInfo;
- IntrusiveRefCntPtr<TargetInfo> Target;
- IntrusiveRefCntPtr<Preprocessor> PP;
- IntrusiveRefCntPtr<ASTContext> Ctx;
- IntrusiveRefCntPtr<TargetOptions> TargetOpts;
- IntrusiveRefCntPtr<HeaderSearchOptions> HSOpts;
- ASTReader *Reader;
- bool HadModuleLoaderFatalFailure;
-
- struct ASTWriterData;
- OwningPtr<ASTWriterData> WriterData;
-
- FileSystemOptions FileSystemOpts;
+ llvm::IntrusiveRefCntPtr<LangOptions> LangOpts;
+ llvm::IntrusiveRefCntPtr<DiagnosticsEngine> Diagnostics;
+ llvm::IntrusiveRefCntPtr<TargetInfo> Target;
+ llvm::IntrusiveRefCntPtr<ASTContext> Ctx;
+ llvm::IntrusiveRefCntPtr<TargetOptions> TargetOpts;
/// \brief The AST consumer that received information about the translation
/// unit as it was parsed or loaded.
- OwningPtr<ASTConsumer> Consumer;
+ llvm::OwningPtr<ASTConsumer> Consumer;
/// \brief The semantic analysis object used to type-check the translation
/// unit.
- OwningPtr<Sema> TheSema;
+ llvm::OwningPtr<Sema> TheSema;
/// Optional owned invocation, just used to make the invocation used in
/// LoadFromCommandLine available.
- IntrusiveRefCntPtr<CompilerInvocation> Invocation;
-
- // OnlyLocalDecls - when true, walking this AST should only visit declarations
- // that come from the AST itself, not from included precompiled headers.
- // FIXME: This is temporary; eventually, CIndex will always do this.
- bool OnlyLocalDecls;
-
- /// \brief Whether to capture any diagnostics produced.
- bool CaptureDiagnostics;
-
- /// \brief Track whether the main file was loaded from an AST or not.
- bool MainFileIsAST;
-
- /// \brief What kind of translation unit this AST represents.
- TranslationUnitKind TUKind;
-
- /// \brief Whether we should time each operation.
- bool WantTiming;
-
- /// \brief Whether the ASTUnit should delete the remapped buffers.
- bool OwnsRemappedFileBuffers;
-
- /// Track the top-level decls which appeared in an ASTUnit which was loaded
- /// from a source file.
- //
- // FIXME: This is just an optimization hack to avoid deserializing large parts
- // of a PCH file when using the Index library on an ASTUnit loaded from
- // source. In the long term we should make the Index library use efficient and
- // more scalable search mechanisms.
- std::vector<Decl*> TopLevelDecls;
-
- /// \brief Sorted (by file offset) vector of pairs of file offset/Decl.
- typedef SmallVector<std::pair<unsigned, Decl *>, 64> LocDeclsTy;
- typedef llvm::DenseMap<FileID, LocDeclsTy *> FileDeclsTy;
-
- /// \brief Map from FileID to the file-level declarations that it contains.
- /// The files and decls are only local (and non-preamble) ones.
- FileDeclsTy FileDecls;
+ llvm::IntrusiveRefCntPtr<CompilerInvocation> Invocation;
/// The name of the original source file used to generate this ASTUnit.
std::string OriginalSourceFile;
- /// \brief The set of diagnostics produced when creating the preamble.
- SmallVector<StoredDiagnostic, 4> PreambleDiagnostics;
-
- /// \brief The set of diagnostics produced when creating this
- /// translation unit.
- SmallVector<StoredDiagnostic, 4> StoredDiagnostics;
-
- /// \brief The set of diagnostics produced when failing to parse, e.g. due
- /// to failure to load the PCH.
- SmallVector<StoredDiagnostic, 4> FailedParseDiagnostics;
-
- /// \brief The number of stored diagnostics that come from the driver
- /// itself.
- ///
- /// Diagnostics that come from the driver are retained from one parse to
- /// the next.
- unsigned NumStoredDiagnosticsFromDriver;
-
- /// \brief Counter that determines when we want to try building a
- /// precompiled preamble.
- ///
- /// If zero, we will never build a precompiled preamble. Otherwise,
- /// it's treated as a counter that decrements each time we reparse
- /// without the benefit of a precompiled preamble. When it hits 1,
- /// we'll attempt to rebuild the precompiled header. This way, if
- /// building the precompiled preamble fails, we won't try again for
- /// some number of calls.
- unsigned PreambleRebuildCounter;
-
-public:
- class PreambleData {
- const FileEntry *File;
- std::vector<char> Buffer;
- mutable unsigned NumLines;
-
- public:
- PreambleData() : File(0), NumLines(0) { }
-
- void assign(const FileEntry *F, const char *begin, const char *end) {
- File = F;
- Buffer.assign(begin, end);
- NumLines = 0;
- }
-
- void clear() { Buffer.clear(); File = 0; NumLines = 0; }
-
- size_t size() const { return Buffer.size(); }
- bool empty() const { return Buffer.empty(); }
-
- const char *getBufferStart() const { return &Buffer[0]; }
-
- unsigned getNumLines() const {
- if (NumLines)
- return NumLines;
- countLines();
- return NumLines;
- }
-
- SourceRange getSourceRange(const SourceManager &SM) const {
- SourceLocation FileLoc = SM.getLocForStartOfFile(SM.getPreambleFileID());
- return SourceRange(FileLoc, FileLoc.getLocWithOffset(size()-1));
- }
-
- private:
- void countLines() const;
- };
-
- const PreambleData &getPreambleData() const {
- return Preamble;
- }
-
-private:
-
- /// \brief The contents of the preamble that has been precompiled to
- /// \c PreambleFile.
- PreambleData Preamble;
-
- /// \brief Whether the preamble ends at the start of a new line.
- ///
- /// Used to inform the lexer as to whether it's starting at the beginning of
- /// a line after skipping the preamble.
- bool PreambleEndsAtStartOfLine;
-
- /// \brief The size of the source buffer that we've reserved for the main
- /// file within the precompiled preamble.
- unsigned PreambleReservedSize;
-
- /// \brief Keeps track of the files that were used when computing the
- /// preamble, with both their buffer size and their modification time.
- ///
- /// If any of the files have changed from one compile to the next,
- /// the preamble must be thrown away.
- llvm::StringMap<std::pair<off_t, time_t> > FilesInPreamble;
-
- /// \brief When non-NULL, this is the buffer used to store the contents of
- /// the main file when it has been padded for use with the precompiled
- /// preamble.
- llvm::MemoryBuffer *SavedMainFileBuffer;
-
- /// \brief When non-NULL, this is the buffer used to store the
- /// contents of the preamble when it has been padded to build the
- /// precompiled preamble.
- llvm::MemoryBuffer *PreambleBuffer;
-
- /// \brief The number of warnings that occurred while parsing the preamble.
- ///
- /// This value will be used to restore the state of the \c DiagnosticsEngine
- /// object when re-using the precompiled preamble. Note that only the
- /// number of warnings matters, since we will not save the preamble
- /// when any errors are present.
- unsigned NumWarningsInPreamble;
-
- /// \brief A list of the serialization ID numbers for each of the top-level
- /// declarations parsed within the precompiled preamble.
- std::vector<serialization::DeclID> TopLevelDeclsInPreamble;
-
- /// \brief Whether we should be caching code-completion results.
- bool ShouldCacheCodeCompletionResults : 1;
-
- /// \brief Whether to include brief documentation within the set of code
- /// completions cached.
- bool IncludeBriefCommentsInCodeCompletion : 1;
-
- /// \brief True if non-system source files should be treated as volatile
- /// (likely to change while trying to use them).
- bool UserFilesAreVolatile : 1;
/// \brief The language options used when we load an AST file.
LangOptions ASTFileLangOpts;
-
- static void ConfigureDiags(IntrusiveRefCntPtr<DiagnosticsEngine> &Diags,
- const char **ArgBegin, const char **ArgEnd,
- ASTUnit &AST, bool CaptureDiagnostics);
-
- void TranslateStoredDiagnostics(ASTReader *MMan, StringRef ModName,
- SourceManager &SrcMan,
- const SmallVectorImpl<StoredDiagnostic> &Diags,
- SmallVectorImpl<StoredDiagnostic> &Out);
-
- void clearFileLevelDecls();
-
-public:
- /// \brief A cached code-completion result, which may be introduced in one of
- /// many different contexts.
- struct CachedCodeCompletionResult {
- /// \brief The code-completion string corresponding to this completion
- /// result.
- CodeCompletionString *Completion;
-
- /// \brief A bitmask that indicates which code-completion contexts should
- /// contain this completion result.
- ///
- /// The bits in the bitmask correspond to the values of
- /// CodeCompleteContext::Kind. To map from a completion context kind to a
- /// bit, shift 1 by that number of bits. Many completions can occur in
- /// several different contexts.
- uint64_t ShowInContexts;
-
- /// \brief The priority given to this code-completion result.
- unsigned Priority;
-
- /// \brief The libclang cursor kind corresponding to this code-completion
- /// result.
- CXCursorKind Kind;
-
- /// \brief The availability of this code-completion result.
- CXAvailabilityKind Availability;
-
- /// \brief The simplified type class for a non-macro completion result.
- SimplifiedTypeClass TypeClass;
-
- /// \brief The type of a non-macro completion result, stored as a unique
- /// integer used by the string map of cached completion types.
- ///
- /// This value will be zero if the type is not known, or a unique value
- /// determined by the formatted type string. Se \c CachedCompletionTypes
- /// for more information.
- unsigned Type;
- };
-
- /// \brief Retrieve the mapping from formatted type names to unique type
- /// identifiers.
- llvm::StringMap<unsigned> &getCachedCompletionTypes() {
- return CachedCompletionTypes;
- }
-
- /// \brief Retrieve the allocator used to cache global code completions.
- IntrusiveRefCntPtr<GlobalCodeCompletionAllocator>
- getCachedCompletionAllocator() {
- return CachedCompletionAllocator;
- }
-
- CodeCompletionTUInfo &getCodeCompletionTUInfo() {
- if (!CCTUInfo)
- CCTUInfo.reset(new CodeCompletionTUInfo(
- new GlobalCodeCompletionAllocator));
- return *CCTUInfo;
- }
-
-private:
- /// \brief Allocator used to store cached code completions.
- IntrusiveRefCntPtr<GlobalCodeCompletionAllocator>
- CachedCompletionAllocator;
-
- OwningPtr<CodeCompletionTUInfo> CCTUInfo;
-
- /// \brief The set of cached code-completion results.
- std::vector<CachedCodeCompletionResult> CachedCompletionResults;
-
- /// \brief A mapping from the formatted type name to a unique number for that
- /// type, which is used for type equality comparisons.
- llvm::StringMap<unsigned> CachedCompletionTypes;
-
- /// \brief A string hash of the top-level declaration and macro definition
- /// names processed the last time that we reparsed the file.
- ///
- /// This hash value is used to determine when we need to refresh the
- /// global code-completion cache.
- unsigned CompletionCacheTopLevelHashValue;
-
- /// \brief A string hash of the top-level declaration and macro definition
- /// names processed the last time that we reparsed the precompiled preamble.
- ///
- /// This hash value is used to determine when we need to refresh the
- /// global code-completion cache after a rebuild of the precompiled preamble.
- unsigned PreambleTopLevelHashValue;
-
- /// \brief The current hash value for the top-level declaration and macro
- /// definition names
- unsigned CurrentTopLevelHashValue;
-
- /// \brief Bit used by CIndex to mark when a translation unit may be in an
- /// inconsistent state, and is not safe to free.
- unsigned UnsafeToFree : 1;
-
- /// \brief Cache any "global" code-completion results, so that we can avoid
- /// recomputing them with each completion.
- void CacheCodeCompletionResults();
-
- /// \brief Clear out and deallocate
- void ClearCachedCompletionResults();
ASTUnit(const ASTUnit &) LLVM_DELETED_FUNCTION;
void operator=(const ASTUnit &) LLVM_DELETED_FUNCTION;
@@ -383,163 +88,34 @@ private:
void CleanTemporaryFiles();
bool Parse(llvm::MemoryBuffer *OverrideMainBuffer);
-
- std::pair<llvm::MemoryBuffer *, std::pair<unsigned, bool> >
- ComputePreamble(CompilerInvocation &Invocation,
- unsigned MaxLines, bool &CreatedBuffer);
-
- llvm::MemoryBuffer *getMainBufferWithPrecompiledPreamble(
- const CompilerInvocation &PreambleInvocationIn,
- bool AllowRebuild = true,
- unsigned MaxLines = 0);
- void RealizeTopLevelDeclsFromPreamble();
/// \brief Transfers ownership of the objects (like SourceManager) from
/// \param CI to this ASTUnit.
void transferASTDataFromCompilerInstance(CompilerInstance &CI);
- /// \brief Allows us to assert that ASTUnit is not being used concurrently,
- /// which is not supported.
- ///
- /// Clients should create instances of the ConcurrencyCheck class whenever
- /// using the ASTUnit in a way that isn't intended to be concurrent, which is
- /// just about any usage.
- /// Becomes a noop in release mode; only useful for debug mode checking.
- class ConcurrencyState {
-#ifndef NDEBUG
- void *Mutex; // a llvm::sys::MutexImpl in debug;
-#endif
-
- public:
- ConcurrencyState();
- ~ConcurrencyState();
-
- void start();
- void finish();
- };
- ConcurrencyState ConcurrencyCheckValue;
-
public:
- class ConcurrencyCheck {
- ASTUnit &Self;
-
- public:
- explicit ConcurrencyCheck(ASTUnit &Self)
- : Self(Self)
- {
- Self.ConcurrencyCheckValue.start();
- }
- ~ConcurrencyCheck() {
- Self.ConcurrencyCheckValue.finish();
- }
- };
- friend class ConcurrencyCheck;
~ASTUnit();
- bool isMainFileAST() const { return MainFileIsAST; }
-
- bool isUnsafeToFree() const { return UnsafeToFree; }
- void setUnsafeToFree(bool Value) { UnsafeToFree = Value; }
-
const DiagnosticsEngine &getDiagnostics() const { return *Diagnostics; }
DiagnosticsEngine &getDiagnostics() { return *Diagnostics; }
-
- const SourceManager &getSourceManager() const { return *SourceMgr; }
- SourceManager &getSourceManager() { return *SourceMgr; }
- const Preprocessor &getPreprocessor() const { return *PP; }
- Preprocessor &getPreprocessor() { return *PP; }
const ASTContext &getASTContext() const { return *Ctx; }
ASTContext &getASTContext() { return *Ctx; }
void setASTContext(ASTContext *ctx) { Ctx = ctx; }
- void setPreprocessor(Preprocessor *pp);
- bool hasSema() const { return TheSema.isValid(); }
+ bool hasSema() const { return TheSema.get() != nullptr; }
Sema &getSema() const {
assert(TheSema && "ASTUnit does not have a Sema object!");
return *TheSema;
}
-
- const FileManager &getFileManager() const { return *FileMgr; }
- FileManager &getFileManager() { return *FileMgr; }
-
- const FileSystemOptions &getFileSystemOpts() const { return FileSystemOpts; }
StringRef getOriginalSourceFileName() {
return OriginalSourceFile;
}
- ASTMutationListener *getASTMutationListener();
- ASTDeserializationListener *getDeserializationListener();
-
- /// \brief Add a temporary file that the ASTUnit depends on.
- ///
- /// This file will be erased when the ASTUnit is destroyed.
- void addTemporaryFile(StringRef TempFile);
-
- bool getOnlyLocalDecls() const { return OnlyLocalDecls; }
-
- bool getOwnsRemappedFileBuffers() const { return OwnsRemappedFileBuffers; }
- void setOwnsRemappedFileBuffers(bool val) { OwnsRemappedFileBuffers = val; }
-
- StringRef getMainFileName() const;
-
- /// \brief If this ASTUnit came from an AST file, returns the filename for it.
- StringRef getASTFileName() const;
-
- typedef std::vector<Decl *>::iterator top_level_iterator;
-
- top_level_iterator top_level_begin() {
- assert(!isMainFileAST() && "Invalid call for AST based ASTUnit!");
- if (!TopLevelDeclsInPreamble.empty())
- RealizeTopLevelDeclsFromPreamble();
- return TopLevelDecls.begin();
- }
-
- top_level_iterator top_level_end() {
- assert(!isMainFileAST() && "Invalid call for AST based ASTUnit!");
- if (!TopLevelDeclsInPreamble.empty())
- RealizeTopLevelDeclsFromPreamble();
- return TopLevelDecls.end();
- }
-
- std::size_t top_level_size() const {
- assert(!isMainFileAST() && "Invalid call for AST based ASTUnit!");
- return TopLevelDeclsInPreamble.size() + TopLevelDecls.size();
- }
-
- bool top_level_empty() const {
- assert(!isMainFileAST() && "Invalid call for AST based ASTUnit!");
- return TopLevelDeclsInPreamble.empty() && TopLevelDecls.empty();
- }
-
- /// \brief Add a new top-level declaration.
- void addTopLevelDecl(Decl *D) {
- TopLevelDecls.push_back(D);
- }
-
- /// \brief Add a new local file-level declaration.
- void addFileLevelDecl(Decl *D);
-
- /// \brief Get the decls that are contained in a file in the Offset/Length
- /// range. \p Length can be 0 to indicate a point at \p Offset instead of
- /// a range.
- void findFileRegionDecls(FileID File, unsigned Offset, unsigned Length,
- SmallVectorImpl<Decl *> &Decls);
-
- /// \brief Add a new top-level declaration, identified by its ID in
- /// the precompiled preamble.
- void addTopLevelDeclFromPreamble(serialization::DeclID D) {
- TopLevelDeclsInPreamble.push_back(D);
- }
-
- /// \brief Retrieve a reference to the current top-level name hash value.
- ///
- /// Note: This is used internally by the top-level tracking action
- unsigned &getCurrentTopLevelHashValue() { return CurrentTopLevelHashValue; }
/// \brief Get the source location for the given file:line:col triplet.
///
@@ -552,140 +128,13 @@ public:
/// \brief Get the source location for the given file:offset pair.
SourceLocation getLocation(const FileEntry *File, unsigned Offset) const;
- /// \brief If \p Loc is a loaded location from the preamble, returns
- /// the corresponding local location of the main file, otherwise it returns
- /// \p Loc.
- SourceLocation mapLocationFromPreamble(SourceLocation Loc);
-
- /// \brief If \p Loc is a local location of the main file but inside the
- /// preamble chunk, returns the corresponding loaded location from the
- /// preamble, otherwise it returns \p Loc.
- SourceLocation mapLocationToPreamble(SourceLocation Loc);
-
- bool isInPreambleFileID(SourceLocation Loc);
- bool isInMainFileID(SourceLocation Loc);
- SourceLocation getStartOfMainFileID();
- SourceLocation getEndOfPreambleFileID();
-
- /// \see mapLocationFromPreamble.
- SourceRange mapRangeFromPreamble(SourceRange R) {
- return SourceRange(mapLocationFromPreamble(R.getBegin()),
- mapLocationFromPreamble(R.getEnd()));
- }
-
- /// \see mapLocationToPreamble.
- SourceRange mapRangeToPreamble(SourceRange R) {
- return SourceRange(mapLocationToPreamble(R.getBegin()),
- mapLocationToPreamble(R.getEnd()));
- }
-
- // Retrieve the diagnostics associated with this AST
- typedef StoredDiagnostic *stored_diag_iterator;
- typedef const StoredDiagnostic *stored_diag_const_iterator;
- stored_diag_const_iterator stored_diag_begin() const {
- return StoredDiagnostics.begin();
- }
- stored_diag_iterator stored_diag_begin() {
- return StoredDiagnostics.begin();
- }
- stored_diag_const_iterator stored_diag_end() const {
- return StoredDiagnostics.end();
- }
- stored_diag_iterator stored_diag_end() {
- return StoredDiagnostics.end();
- }
- unsigned stored_diag_size() const { return StoredDiagnostics.size(); }
-
- stored_diag_iterator stored_diag_afterDriver_begin() {
- if (NumStoredDiagnosticsFromDriver > StoredDiagnostics.size())
- NumStoredDiagnosticsFromDriver = 0;
- return StoredDiagnostics.begin() + NumStoredDiagnosticsFromDriver;
- }
-
- typedef std::vector<CachedCodeCompletionResult>::iterator
- cached_completion_iterator;
-
- cached_completion_iterator cached_completion_begin() {
- return CachedCompletionResults.begin();
- }
-
- cached_completion_iterator cached_completion_end() {
- return CachedCompletionResults.end();
- }
-
- unsigned cached_completion_size() const {
- return CachedCompletionResults.size();
- }
-
- /// \brief Returns an iterator range for the local preprocessing entities
- /// of the local Preprocessor, if this is a parsed source file, or the loaded
- /// preprocessing entities of the primary module if this is an AST file.
- std::pair<PreprocessingRecord::iterator, PreprocessingRecord::iterator>
- getLocalPreprocessingEntities() const;
-
- /// \brief Type for a function iterating over a number of declarations.
- /// \returns true to continue iteration and false to abort.
- typedef bool (*DeclVisitorFn)(void *context, const Decl *D);
-
- /// \brief Iterate over local declarations (locally parsed if this is a parsed
- /// source file or the loaded declarations of the primary module if this is an
- /// AST file).
- /// \returns true if the iteration was complete or false if it was aborted.
- bool visitLocalTopLevelDecls(void *context, DeclVisitorFn Fn);
-
- /// \brief Get the PCH file if one was included.
- const FileEntry *getPCHFile();
-
- /// \brief Returns true if the ASTUnit was constructed from a serialized
- /// module file.
- bool isModuleFile();
llvm::MemoryBuffer *getBufferForFile(StringRef Filename,
std::string *ErrorStr = 0);
- /// \brief Determine what kind of translation unit this AST represents.
- TranslationUnitKind getTranslationUnitKind() const { return TUKind; }
-
- typedef llvm::PointerUnion<const char *, const llvm::MemoryBuffer *>
- FilenameOrMemBuf;
- /// \brief A mapping from a file name to the memory buffer that stores the
- /// remapped contents of that file.
- typedef std::pair<std::string, FilenameOrMemBuf> RemappedFile;
-
/// \brief Create a ASTUnit. Gets ownership of the passed CompilerInvocation.
static ASTUnit *create(CompilerInvocation *CI,
- IntrusiveRefCntPtr<DiagnosticsEngine> Diags,
- bool CaptureDiagnostics,
- bool UserFilesAreVolatile);
-
- /// \brief Create a ASTUnit from an AST file.
- ///
- /// \param Filename - The AST file to load.
- ///
- /// \param Diags - The diagnostics engine to use for reporting errors; its
- /// lifetime is expected to extend past that of the returned ASTUnit.
- ///
- /// \returns - The initialized ASTUnit or null if the AST failed to load.
- static ASTUnit *LoadFromASTFile(const std::string &Filename,
- IntrusiveRefCntPtr<DiagnosticsEngine> Diags,
- const FileSystemOptions &FileSystemOpts,
- bool OnlyLocalDecls = false,
- RemappedFile *RemappedFiles = 0,
- unsigned NumRemappedFiles = 0,
- bool CaptureDiagnostics = false,
- bool AllowPCHWithCompilerErrors = false,
- bool UserFilesAreVolatile = false);
-
-private:
- /// \brief Helper function for \c LoadFromCompilerInvocation() and
- /// \c LoadFromCommandLine(), which loads an AST from a compiler invocation.
- ///
- /// \param PrecompilePreamble Whether to precompile the preamble of this
- /// translation unit, to improve the performance of reparsing.
- ///
- /// \returns \c true if a catastrophic failure occurred (which means that the
- /// \c ASTUnit itself is invalid), or \c false otherwise.
- bool LoadFromCompilerInvocation(bool PrecompilePreamble);
+ llvm::IntrusiveRefCntPtr<DiagnosticsEngine> Diags);
public:
@@ -715,7 +164,7 @@ public:
/// created ASTUnit was passed in \p Unit then the caller can check that.
///
static ASTUnit *LoadFromCompilerInvocationAction(CompilerInvocation *CI,
- IntrusiveRefCntPtr<DiagnosticsEngine> Diags,
+ llvm::IntrusiveRefCntPtr<DiagnosticsEngine> Diags,
ASTFrontendAction *Action = 0,
ASTUnit *Unit = 0,
bool Persistent = true,
@@ -726,7 +175,7 @@ public:
bool CacheCodeCompletionResults = false,
bool IncludeBriefCommentsInCodeCompletion = false,
bool UserFilesAreVolatile = false,
- OwningPtr<ASTUnit> *ErrAST = 0);
+ llvm::OwningPtr<ASTUnit> *ErrAST = 0);
/// LoadFromCompilerInvocation - Create an ASTUnit from a source file, via a
/// CompilerInvocation object.
@@ -740,113 +189,8 @@ public:
// FIXME: Move OnlyLocalDecls, UseBumpAllocator to setters on the ASTUnit, we
// shouldn't need to specify them at construction time.
static ASTUnit *LoadFromCompilerInvocation(CompilerInvocation *CI,
- IntrusiveRefCntPtr<DiagnosticsEngine> Diags,
- bool OnlyLocalDecls = false,
- bool CaptureDiagnostics = false,
- bool PrecompilePreamble = false,
- TranslationUnitKind TUKind = TU_Complete,
- bool CacheCodeCompletionResults = false,
- bool IncludeBriefCommentsInCodeCompletion = false,
- bool UserFilesAreVolatile = false);
-
- /// LoadFromCommandLine - Create an ASTUnit from a vector of command line
- /// arguments, which must specify exactly one source file.
- ///
- /// \param ArgBegin - The beginning of the argument vector.
- ///
- /// \param ArgEnd - The end of the argument vector.
- ///
- /// \param Diags - The diagnostics engine to use for reporting errors; its
- /// lifetime is expected to extend past that of the returned ASTUnit.
- ///
- /// \param ResourceFilesPath - The path to the compiler resource files.
- ///
- /// \param ErrAST - If non-null and parsing failed without any AST to return
- /// (e.g. because the PCH could not be loaded), this accepts the ASTUnit
- /// mainly to allow the caller to see the diagnostics.
- ///
- // FIXME: Move OnlyLocalDecls, UseBumpAllocator to setters on the ASTUnit, we
- // shouldn't need to specify them at construction time.
- static ASTUnit *LoadFromCommandLine(const char **ArgBegin,
- const char **ArgEnd,
- IntrusiveRefCntPtr<DiagnosticsEngine> Diags,
- StringRef ResourceFilesPath,
- bool OnlyLocalDecls = false,
- bool CaptureDiagnostics = false,
- RemappedFile *RemappedFiles = 0,
- unsigned NumRemappedFiles = 0,
- bool RemappedFilesKeepOriginalName = true,
- bool PrecompilePreamble = false,
- TranslationUnitKind TUKind = TU_Complete,
- bool CacheCodeCompletionResults = false,
- bool IncludeBriefCommentsInCodeCompletion = false,
- bool AllowPCHWithCompilerErrors = false,
- bool SkipFunctionBodies = false,
- bool UserFilesAreVolatile = false,
- bool ForSerialization = false,
- OwningPtr<ASTUnit> *ErrAST = 0);
-
- /// \brief Reparse the source files using the same command-line options that
- /// were originally used to produce this translation unit.
- ///
- /// \returns True if a failure occurred that causes the ASTUnit not to
- /// contain any translation-unit information, false otherwise.
- bool Reparse(RemappedFile *RemappedFiles = 0,
- unsigned NumRemappedFiles = 0);
-
- /// \brief Perform code completion at the given file, line, and
- /// column within this translation unit.
- ///
- /// \param File The file in which code completion will occur.
- ///
- /// \param Line The line at which code completion will occur.
- ///
- /// \param Column The column at which code completion will occur.
- ///
- /// \param IncludeMacros Whether to include macros in the code-completion
- /// results.
- ///
- /// \param IncludeCodePatterns Whether to include code patterns (such as a
- /// for loop) in the code-completion results.
- ///
- /// \param IncludeBriefComments Whether to include brief documentation within
- /// the set of code completions returned.
- ///
- /// FIXME: The Diag, LangOpts, SourceMgr, FileMgr, StoredDiagnostics, and
- /// OwnedBuffers parameters are all disgusting hacks. They will go away.
- void CodeComplete(StringRef File, unsigned Line, unsigned Column,
- RemappedFile *RemappedFiles, unsigned NumRemappedFiles,
- bool IncludeMacros, bool IncludeCodePatterns,
- bool IncludeBriefComments,
- CodeCompleteConsumer &Consumer,
- DiagnosticsEngine &Diag, LangOptions &LangOpts,
- SourceManager &SourceMgr, FileManager &FileMgr,
- SmallVectorImpl<StoredDiagnostic> &StoredDiagnostics,
- SmallVectorImpl<const llvm::MemoryBuffer *> &OwnedBuffers);
-
- /// \brief Save this translation unit to a file with the given name.
- ///
- /// \returns true if there was a file error or false if the save was
- /// successful.
- bool Save(StringRef File);
-
- /// \brief Serialize this translation unit with the given output stream.
- ///
- /// \returns True if an error occurred, false otherwise.
- bool serialize(raw_ostream &OS);
-
- virtual ModuleLoadResult loadModule(SourceLocation ImportLoc,
- ModuleIdPath Path,
- Module::NameVisibilityKind Visibility,
- bool IsInclusionDirective) {
- // ASTUnit doesn't know how to load modules (not that this matters).
- return ModuleLoadResult();
- }
+ llvm::IntrusiveRefCntPtr<DiagnosticsEngine> Diags);
- virtual void makeModuleVisible(Module *Mod,
- Module::NameVisibilityKind Visibility,
- SourceLocation ImportLoc,
- bool Complain) { }
};
diff --git a/include/flang/Frontend/FrontendAction.h b/include/flang/Frontend/FrontendAction.h
index b9f236b688..bd52e44fe8 100644
--- a/include/flang/Frontend/FrontendAction.h
+++ b/include/flang/Frontend/FrontendAction.h
@@ -33,7 +33,7 @@ class CompilerInstance;
/// Abstract base class for actions which can be performed by the frontend.
class FrontendAction {
- OwningPtr<ASTUnit> CurrentASTUnit;
+ llvm::OwningPtr<ASTUnit> CurrentASTUnit;
CompilerInstance *Instance;
private:
@@ -124,13 +124,11 @@ public:
}
const StringRef getCurrentFile() const {
- assert(!CurrentInput.isEmpty() && "No current file!");
- return CurrentInput.getFile();
+ CurrentASTUnit.get()->getOriginalSourceFileName();
}
InputKind getCurrentFileKind() const {
- assert(!CurrentInput.isEmpty() && "No current file!");
- return CurrentInput.getKind();
+ return IK_None;
}
ASTUnit &getCurrentASTUnit() const {
diff --git a/lib/CodeGen/BackendUtil.cpp b/lib/CodeGen/BackendUtil.cpp
index 18aedc027d..f27dd83831 100644
--- a/lib/CodeGen/BackendUtil.cpp
+++ b/lib/CodeGen/BackendUtil.cpp
@@ -44,7 +44,7 @@ namespace {
class EmitAssemblyHelper {
DiagnosticsEngine &Diags;
const CodeGenOptions &CodeGenOpts;
- const clang::TargetOptions &TargetOpts;
+ const flang::TargetOptions &TargetOpts;
const LangOptions &LangOpts;
Module *TheModule;
@@ -107,7 +107,7 @@ private:
public:
EmitAssemblyHelper(DiagnosticsEngine &_Diags,
const CodeGenOptions &CGOpts,
- const clang::TargetOptions &TOpts,
+ const flang::TargetOptions &TOpts,
const LangOptions &LOpts,
Module *M)
: Diags(_Diags), CodeGenOpts(CGOpts), TargetOpts(TOpts), LangOpts(LOpts),
@@ -139,73 +139,11 @@ private:
}
-static void addObjCARCAPElimPass(const PassManagerBuilder &Builder, PassManagerBase &PM) {
- if (Builder.OptLevel > 0)
- PM.add(createObjCARCAPElimPass());
-}
-
-static void addObjCARCExpandPass(const PassManagerBuilder &Builder, PassManagerBase &PM) {
- if (Builder.OptLevel > 0)
- PM.add(createObjCARCExpandPass());
-}
-
-static void addObjCARCOptPass(const PassManagerBuilder &Builder, PassManagerBase &PM) {
- if (Builder.OptLevel > 0)
- PM.add(createObjCARCOptPass());
-}
-
static void addBoundsCheckingPass(const PassManagerBuilder &Builder,
PassManagerBase &PM) {
PM.add(createBoundsCheckingPass());
}
-static void addAddressSanitizerPasses(const PassManagerBuilder &Builder,
- PassManagerBase &PM) {
- const PassManagerBuilderWrapper &BuilderWrapper =
- static_cast<const PassManagerBuilderWrapper&>(Builder);
- const CodeGenOptions &CGOpts = BuilderWrapper.getCGOpts();
- const LangOptions &LangOpts = BuilderWrapper.getLangOpts();
- PM.add(createAddressSanitizerFunctionPass(
- LangOpts.Sanitize.InitOrder,
- LangOpts.Sanitize.UseAfterReturn,
- LangOpts.Sanitize.UseAfterScope,
- CGOpts.SanitizerBlacklistFile,
- CGOpts.SanitizeAddressZeroBaseShadow));
- PM.add(createAddressSanitizerModulePass(
- LangOpts.Sanitize.InitOrder,
- CGOpts.SanitizerBlacklistFile,
- CGOpts.SanitizeAddressZeroBaseShadow));
-}
-
-static void addMemorySanitizerPass(const PassManagerBuilder &Builder,
- PassManagerBase &PM) {
- const PassManagerBuilderWrapper &BuilderWrapper =
- static_cast<const PassManagerBuilderWrapper&>(Builder);
- const CodeGenOptions &CGOpts = BuilderWrapper.getCGOpts();
- PM.add(createMemorySanitizerPass(CGOpts.SanitizeMemoryTrackOrigins,
- CGOpts.SanitizerBlacklistFile));
-
- // MemorySanitizer inserts complex instrumentation that mostly follows
- // the logic of the original code, but operates on "shadow" values.
- // It can benefit from re-running some general purpose optimization passes.
- if (Builder.OptLevel > 0) {
- PM.add(createEarlyCSEPass());
- PM.add(createReassociatePass());
- PM.add(createLICMPass());
- PM.add(createGVNPass());
- PM.add(createInstructionCombiningPass());
- PM.add(createDeadStoreEliminationPass());
- }
-}
-
-static void addThreadSanitizerPass(const PassManagerBuilder &Builder,
- PassManagerBase &PM) {
- const PassManagerBuilderWrapper &BuilderWrapper =
- static_cast<const PassManagerBuilderWrapper&>(Builder);
- const CodeGenOptions &CGOpts = BuilderWrapper.getCGOpts();
- PM.add(createThreadSanitizerPass(CGOpts.SanitizerBlacklistFile));
-}
-
void EmitAssemblyHelper::CreatePasses(TargetMachine *TM) {
unsigned OptLevel = CodeGenOpts.OptimizationLevel;
CodeGenOptions::InliningMethod Inlining = CodeGenOpts.getInlining();
@@ -227,44 +165,6 @@ void EmitAssemblyHelper::CreatePasses(TargetMachine *TM) {
PMBuilder.DisableUnitAtATime = !CodeGenOpts.UnitAtATime;
PMBuilder.DisableUnrollLoops = !CodeGenOpts.UnrollLoops;
- // In ObjC ARC mode, add the main ARC optimization passes.
- if (LangOpts.ObjCAutoRefCount) {
- PMBuilder.addExtension(PassManagerBuilder::EP_EarlyAsPossible,
- addObjCARCExpandPass);
- PMBuilder.addExtension(PassManagerBuilder::EP_ModuleOptimizerEarly,
- addObjCARCAPElimPass);
- PMBuilder.addExtension(PassManagerBuilder::EP_ScalarOptimizerLate,
- addObjCARCOptPass);
- }
-
- if (LangOpts.Sanitize.Bounds) {
- PMBuilder.addExtension(PassManagerBuilder::EP_ScalarOptimizerLate,
- addBoundsCheckingPass);
- PMBuilder.addExtension(PassManagerBuilder::EP_EnabledOnOptLevel0,
- addBoundsCheckingPass);
- }
-
- if (LangOpts.Sanitize.Address) {
- PMBuilder.addExtension(PassManagerBuilder::EP_OptimizerLast,
- addAddressSanitizerPasses);
- PMBuilder.addExtension(PassManagerBuilder::EP_EnabledOnOptLevel0,
- addAddressSanitizerPasses);
- }
-
- if (LangOpts.Sanitize.Memory) {
- PMBuilder.addExtension(PassManagerBuilder::EP_OptimizerLast,
- addMemorySanitizerPass);
- PMBuilder.addExtension(PassManagerBuilder::EP_EnabledOnOptLevel0,
- addMemorySanitizerPass);
- }
-
- if (LangOpts.Sanitize.Thread) {
- PMBuilder.addExtension(PassManagerBuilder::EP_OptimizerLast,
- addThreadSanitizerPass);
- PMBuilder.addExtension(PassManagerBuilder::EP_EnabledOnOptLevel0,
- addThreadSanitizerPass);
- }
-
// Figure out TargetLibraryInfo.
Triple TargetTriple(TheModule->getTargetTriple());
PMBuilder.LibraryInfo = new TargetLibraryInfo(TargetTriple);
@@ -457,7 +357,7 @@ TargetMachine *EmitAssemblyHelper::CreateTargetMachine(bool MustCreateTM) {
Options.RealignStack = CodeGenOpts.StackRealignment;
Options.DisableTailCalls = CodeGenOpts.DisableTailCalls;
Options.TrapFuncName = CodeGenOpts.TrapFuncName;
- Options.PositionIndependentExecutable = LangOpts.PIELevel != 0;
+ //Options.PositionIndependentExecutable = LangOpts.PIELevel != 0;
Options.EnableSegmentedStacks = CodeGenOpts.EnableSegmentedStacks;
TargetMachine *TM = TheTarget->createTargetMachine(Triple, TargetOpts.CPU,
@@ -505,13 +405,6 @@ bool EmitAssemblyHelper::AddEmitPasses(BackendAction Action,
else
assert(Action == Backend_EmitAssembly && "Invalid action!");
- // Add ObjC ARC final-cleanup optimizations. This is done as part of the
- // "codegen" passes so that it isn't run multiple times when there is
- // inlining happening.
- if (LangOpts.ObjCAutoRefCount &&
- CodeGenOpts.OptimizationLevel > 0)
- PM->add(createObjCARCContractPass());
-
if (TM->addPassesToEmitFile(*PM, OS, CGFT,
/*DisableVerify=*/!CodeGenOpts.VerifyModule)) {
Diags.Report(diag::err_fe_unable_to_interface_with_target);
diff --git a/lib/CodeGen/CodeGenAction.cpp b/lib/CodeGen/CodeGenAction.cpp
index c922ac432f..bb02d0fd2a 100644
--- a/lib/CodeGen/CodeGenAction.cpp
+++ b/lib/CodeGen/CodeGenAction.cpp
@@ -205,28 +205,6 @@ ASTConsumer *CodeGenAction::CreateASTConsumer(CompilerInstance &CI,
llvm::Module *LinkModuleToUse = LinkModule;
- // If we were not given a link module, and the user requested that one be
- // loaded from bitcode, do so now.
- const std::string &LinkBCFile = CI.getCodeGenOpts().LinkBitcodeFile;
- if (!LinkModuleToUse && !LinkBCFile.empty()) {
- std::string ErrorStr;
-
- llvm::MemoryBuffer *BCBuf =
- CI.getFileManager().getBufferForFile(LinkBCFile, &ErrorStr);
- if (!BCBuf) {
- CI.getDiagnostics().Report(diag::err_cannot_open_file)
- << LinkBCFile << ErrorStr;
- return 0;
- }
-
- LinkModuleToUse = getLazyBitcodeModule(BCBuf, *VMContext, &ErrorStr);
- if (!LinkModuleToUse) {
- CI.getDiagnostics().Report(diag::err_cannot_open_file)
- << LinkBCFile << ErrorStr;
- return 0;
- }
- }
-
BEConsumer =
new BackendConsumer(BA, CI.getDiagnostics(),
CI.getCodeGenOpts(), CI.getTargetOpts(),
@@ -237,62 +215,6 @@ ASTConsumer *CodeGenAction::CreateASTConsumer(CompilerInstance &CI,
}
void CodeGenAction::ExecuteAction() {
- // If this is an IR file, we have to treat it specially.
- if (getCurrentFileKind() == IK_LLVM_IR) {
- BackendAction BA = static_cast<BackendAction>(Act);
- CompilerInstance &CI = getCompilerInstance();
- raw_ostream *OS = GetOutputStream(CI, getCurrentFile(), BA);
- if (BA != Backend_EmitNothing && !OS)
- return;
-
- bool Invalid;
- llvm::SourceMgr &SM = CI.getSourceManager();
- const llvm::MemoryBuffer *MainFile = SM.getBuffer(SM.getMainFileID(),
- &Invalid);
- if (Invalid)
- return;
-
- // FIXME: This is stupid, IRReader shouldn't take ownership.
- llvm::MemoryBuffer *MainFileCopy =
- llvm::MemoryBuffer::getMemBufferCopy(MainFile->getBuffer(),
- getCurrentFile());
-
- llvm::SMDiagnostic Err;
- TheModule.reset(ParseIR(MainFileCopy, Err, *VMContext));
- if (!TheModule) {
- // Translate from the diagnostic info to the SourceManager location.
- SourceLocation Loc = SM.translateFileLineCol(
- SM.getFileEntryForID(SM.getMainFileID()), Err.getLineNo(),
- Err.getColumnNo() + 1);
-
- // Get a custom diagnostic for the error. We strip off a leading
- // diagnostic code if there is one.
- StringRef Msg = Err.getMessage();
- if (Msg.startswith("error: "))
- Msg = Msg.substr(7);
-
- // Escape '%', which is interpreted as a format character.
- SmallString<128> EscapedMessage;
- for (unsigned i = 0, e = Msg.size(); i != e; ++i) {
- if (Msg[i] == '%')
- EscapedMessage += '%';
- EscapedMessage += Msg[i];
- }
-
- unsigned DiagID = CI.getDiagnostics().getCustomDiagID(
- DiagnosticsEngine::Error, EscapedMessage);
-
- CI.getDiagnostics().Report(Loc, DiagID);
- return;
- }
-
- EmitBackendOutput(CI.getDiagnostics(), CI.getCodeGenOpts(),
- CI.getTargetOpts(), CI.getLangOpts(),
- TheModule.get(),
- BA, OS);
- return;
- }
-
// Otherwise follow the normal AST path.
this->ASTFrontendAction::ExecuteAction();
}