Skip to content

Commit

Permalink
Merged main:ee43dcaad75b into amd-gfx:4d7163f98445
Browse files Browse the repository at this point in the history
Local branch amd-gfx 4d7163f Merged main:d50d7c37a159 into amd-gfx:1e7a931d181a
Remote branch main ee43dca [mlir] Add section page for Rationale docs.
  • Loading branch information
Sw authored and Sw committed Dec 14, 2020
2 parents 4d7163f + ee43dca commit bdc55c2
Show file tree
Hide file tree
Showing 111 changed files with 3,428 additions and 1,487 deletions.
12 changes: 6 additions & 6 deletions clang-tools-extra/modularize/ModularizeUtilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,22 +258,22 @@ std::error_code ModularizeUtilities::loadProblemHeaderList(
std::error_code ModularizeUtilities::loadModuleMap(
llvm::StringRef InputPath) {
// Get file entry for module.modulemap file.
auto ModuleMapEntryOrErr =
SourceMgr->getFileManager().getFile(InputPath);
auto ExpectedModuleMapEntry =
SourceMgr->getFileManager().getFileRef(InputPath);

// return error if not found.
if (!ModuleMapEntryOrErr) {
if (!ExpectedModuleMapEntry) {
llvm::errs() << "error: File \"" << InputPath << "\" not found.\n";
return ModuleMapEntryOrErr.getError();
return errorToErrorCode(ExpectedModuleMapEntry.takeError());
}
const FileEntry *ModuleMapEntry = *ModuleMapEntryOrErr;
FileEntryRef ModuleMapEntry = *ExpectedModuleMapEntry;

// Because the module map parser uses a ForwardingDiagnosticConsumer,
// which doesn't forward the BeginSourceFile call, we do it explicitly here.
DC.BeginSourceFile(*LangOpts, nullptr);

// Figure out the home directory for the module map file.
const DirectoryEntry *Dir = ModuleMapEntry->getDir();
const DirectoryEntry *Dir = ModuleMapEntry.getDir();
StringRef DirName(Dir->getName());
if (llvm::sys::path::filename(DirName) == "Modules") {
DirName = llvm::sys::path::parent_path(DirName);
Expand Down
7 changes: 7 additions & 0 deletions clang/include/clang/Basic/Attr.td
Original file line number Diff line number Diff line change
Expand Up @@ -1448,6 +1448,13 @@ def LayoutVersion : InheritableAttr, TargetSpecificAttr<TargetMicrosoftCXXABI> {
let Documentation = [LayoutVersionDocs];
}

def Leaf : InheritableAttr {
let Spellings = [GCC<"leaf">];
let Subjects = SubjectList<[Function]>;
let Documentation = [LeafDocs];
let SimpleHandler = 1;
}

def LifetimeBound : DeclOrTypeAttr {
let Spellings = [Clang<"lifetimebound", 0>];
let Subjects = SubjectList<[ParmVar, ImplicitObjectParameter], ErrorDiag>;
Expand Down
16 changes: 16 additions & 0 deletions clang/include/clang/Basic/AttrDocs.td
Original file line number Diff line number Diff line change
Expand Up @@ -3976,6 +3976,22 @@ are used to instantiate the specialization.
}];
}

def LeafDocs : Documentation {
let Category = DocCatVariable;
let Content = [{

The ``leaf`` attribute is used as a compiler hint to improve dataflow analysis
in library functions. Functions marked with the ``leaf`` attribute are not allowed
to jump back into the caller's translation unit, whether through invoking a
callback function, an external function call, use of ``longjmp``, or other means.
Therefore, they cannot use or modify any data that does not escape the caller function's
compilation unit.

For more information see
`gcc documentation <https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html>`
}];
}

def NoStackProtectorDocs : Documentation {
let Category = DocCatFunction;
let Content = [{
Expand Down
13 changes: 6 additions & 7 deletions clang/include/clang/Lex/HeaderSearch.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ class HeaderSearch {

/// Set of module map files we've already loaded, and a flag indicating
/// whether they were valid or not.
llvm::DenseMap<const FileEntry *, bool> LoadedModuleMaps;
llvm::DenseMap<FileEntryRef, bool> LoadedModuleMaps;

/// Uniqued set of framework names, which is used to track which
/// headers were included as framework headers.
Expand Down Expand Up @@ -560,8 +560,8 @@ class HeaderSearch {

/// Try to find a module map file in the given directory, returning
/// \c nullptr if none is found.
const FileEntry *lookupModuleMapFile(const DirectoryEntry *Dir,
bool IsFramework);
Optional<FileEntryRef> lookupModuleMapFile(const DirectoryEntry *Dir,
bool IsFramework);

/// Determine whether there is a module map that may map the header
/// with the given file name to a (sub)module.
Expand Down Expand Up @@ -603,8 +603,8 @@ class HeaderSearch {
/// used to resolve paths within the module (this is required when
/// building the module from preprocessed source).
/// \returns true if an error occurred, false otherwise.
bool loadModuleMapFile(const FileEntry *File, bool IsSystem,
FileID ID = FileID(), unsigned *Offset = nullptr,
bool loadModuleMapFile(FileEntryRef File, bool IsSystem, FileID ID = FileID(),
unsigned *Offset = nullptr,
StringRef OriginalModuleMapFile = StringRef());

/// Collect the set of all known, top-level modules.
Expand Down Expand Up @@ -794,8 +794,7 @@ class HeaderSearch {
LMM_InvalidModuleMap
};

LoadModuleMapResult loadModuleMapFileImpl(const FileEntry *File,
bool IsSystem,
LoadModuleMapResult loadModuleMapFileImpl(FileEntryRef File, bool IsSystem,
const DirectoryEntry *Dir,
FileID ID = FileID(),
unsigned *Offset = nullptr);
Expand Down
6 changes: 3 additions & 3 deletions clang/include/clang/Lex/ModuleMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -684,9 +684,9 @@ class ModuleMap {
/// that caused us to load this module map file, if any.
///
/// \returns true if an error occurred, false otherwise.
bool parseModuleMapFile(const FileEntry *File, bool IsSystem,
const DirectoryEntry *HomeDir,
FileID ID = FileID(), unsigned *Offset = nullptr,
bool parseModuleMapFile(FileEntryRef File, bool IsSystem,
const DirectoryEntry *HomeDir, FileID ID = FileID(),
unsigned *Offset = nullptr,
SourceLocation ExternModuleLoc = SourceLocation());

/// Dump the contents of the module map, for debugging purposes.
Expand Down
2 changes: 2 additions & 0 deletions clang/lib/CodeGen/CGCall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1989,6 +1989,8 @@ void CodeGenModule::ConstructAttributeList(
FuncAttrs.addAttribute("no_caller_saved_registers");
if (TargetDecl->hasAttr<AnyX86NoCfCheckAttr>())
FuncAttrs.addAttribute(llvm::Attribute::NoCfCheck);
if (TargetDecl->hasAttr<LeafAttr>())
FuncAttrs.addAttribute(llvm::Attribute::NoCallback);

HasOptnone = TargetDecl->hasAttr<OptimizeNoneAttr>();
if (auto *AllocSize = TargetDecl->getAttr<AllocSizeAttr>()) {
Expand Down
35 changes: 23 additions & 12 deletions clang/lib/CodeGen/TargetInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2097,6 +2097,23 @@ bool X86_32TargetCodeGenInfo::isStructReturnInRegABI(
}
}

static void addX86InterruptAttrs(const FunctionDecl *FD, llvm::GlobalValue *GV,
CodeGen::CodeGenModule &CGM) {
if (!FD->hasAttr<AnyX86InterruptAttr>())
return;

llvm::Function *Fn = cast<llvm::Function>(GV);
Fn->setCallingConv(llvm::CallingConv::X86_INTR);
if (FD->getNumParams() == 0)
return;

auto PtrTy = cast<PointerType>(FD->getParamDecl(0)->getType());
llvm::Type *ByValTy = CGM.getTypes().ConvertType(PtrTy->getPointeeType());
llvm::Attribute NewAttr = llvm::Attribute::getWithByValType(
Fn->getContext(), ByValTy);
Fn->addParamAttr(0, NewAttr);
}

void X86_32TargetCodeGenInfo::setTargetAttributes(
const Decl *D, llvm::GlobalValue *GV, CodeGen::CodeGenModule &CGM) const {
if (GV->isDeclaration())
Expand All @@ -2106,10 +2123,8 @@ void X86_32TargetCodeGenInfo::setTargetAttributes(
llvm::Function *Fn = cast<llvm::Function>(GV);
Fn->addFnAttr("stackrealign");
}
if (FD->hasAttr<AnyX86InterruptAttr>()) {
llvm::Function *Fn = cast<llvm::Function>(GV);
Fn->setCallingConv(llvm::CallingConv::X86_INTR);
}

addX86InterruptAttrs(FD, GV, CGM);
}
}

Expand Down Expand Up @@ -2476,10 +2491,8 @@ class X86_64TargetCodeGenInfo : public TargetCodeGenInfo {
llvm::Function *Fn = cast<llvm::Function>(GV);
Fn->addFnAttr("stackrealign");
}
if (FD->hasAttr<AnyX86InterruptAttr>()) {
llvm::Function *Fn = cast<llvm::Function>(GV);
Fn->setCallingConv(llvm::CallingConv::X86_INTR);
}

addX86InterruptAttrs(FD, GV, CGM);
}
}

Expand Down Expand Up @@ -2689,10 +2702,8 @@ void WinX86_64TargetCodeGenInfo::setTargetAttributes(
llvm::Function *Fn = cast<llvm::Function>(GV);
Fn->addFnAttr("stackrealign");
}
if (FD->hasAttr<AnyX86InterruptAttr>()) {
llvm::Function *Fn = cast<llvm::Function>(GV);
Fn->setCallingConv(llvm::CallingConv::X86_INTR);
}

addX86InterruptAttrs(FD, GV, CGM);
}

addStackProbeTargetAttributes(D, GV, CGM);
Expand Down
81 changes: 80 additions & 1 deletion clang/lib/Driver/ToolChains/BareMetal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "InputInfo.h"
#include "Gnu.h"

#include "Arch/RISCV.h"
#include "clang/Driver/Compilation.h"
#include "clang/Driver/Driver.h"
#include "clang/Driver/DriverDiagnostic.h"
Expand All @@ -27,12 +28,77 @@ using namespace clang::driver;
using namespace clang::driver::tools;
using namespace clang::driver::toolchains;

static Multilib makeMultilib(StringRef commonSuffix) {
return Multilib(commonSuffix, commonSuffix, commonSuffix);
}

static bool findRISCVMultilibs(const Driver &D,
const llvm::Triple &TargetTriple,
const ArgList &Args, DetectedMultilibs &Result) {
Multilib::flags_list Flags;
StringRef Arch = riscv::getRISCVArch(Args, TargetTriple);
StringRef Abi = tools::riscv::getRISCVABI(Args, TargetTriple);

if (TargetTriple.getArch() == llvm::Triple::riscv64) {
Multilib Imac = makeMultilib("").flag("+march=rv64imac").flag("+mabi=lp64");
Multilib Imafdc = makeMultilib("/rv64imafdc/lp64d")
.flag("+march=rv64imafdc")
.flag("+mabi=lp64d");

// Multilib reuse
bool UseImafdc =
(Arch == "rv64imafdc") || (Arch == "rv64gc"); // gc => imafdc

addMultilibFlag((Arch == "rv64imac"), "march=rv64imac", Flags);
addMultilibFlag(UseImafdc, "march=rv64imafdc", Flags);
addMultilibFlag(Abi == "lp64", "mabi=lp64", Flags);
addMultilibFlag(Abi == "lp64d", "mabi=lp64d", Flags);

Result.Multilibs = MultilibSet().Either(Imac, Imafdc);
return Result.Multilibs.select(Flags, Result.SelectedMultilib);
}
if (TargetTriple.getArch() == llvm::Triple::riscv32) {
Multilib Imac =
makeMultilib("").flag("+march=rv32imac").flag("+mabi=ilp32");
Multilib I =
makeMultilib("/rv32i/ilp32").flag("+march=rv32i").flag("+mabi=ilp32");
Multilib Im =
makeMultilib("/rv32im/ilp32").flag("+march=rv32im").flag("+mabi=ilp32");
Multilib Iac = makeMultilib("/rv32iac/ilp32")
.flag("+march=rv32iac")
.flag("+mabi=ilp32");
Multilib Imafc = makeMultilib("/rv32imafc/ilp32f")
.flag("+march=rv32imafc")
.flag("+mabi=ilp32f");

// Multilib reuse
bool UseI = (Arch == "rv32i") || (Arch == "rv32ic"); // ic => i
bool UseIm = (Arch == "rv32im") || (Arch == "rv32imc"); // imc => im
bool UseImafc = (Arch == "rv32imafc") || (Arch == "rv32imafdc") ||
(Arch == "rv32gc"); // imafdc,gc => imafc

addMultilibFlag(UseI, "march=rv32i", Flags);
addMultilibFlag(UseIm, "march=rv32im", Flags);
addMultilibFlag((Arch == "rv32iac"), "march=rv32iac", Flags);
addMultilibFlag((Arch == "rv32imac"), "march=rv32imac", Flags);
addMultilibFlag(UseImafc, "march=rv32imafc", Flags);
addMultilibFlag(Abi == "ilp32", "mabi=ilp32", Flags);
addMultilibFlag(Abi == "ilp32f", "mabi=ilp32f", Flags);

Result.Multilibs = MultilibSet().Either(I, Im, Iac, Imac, Imafc);
return Result.Multilibs.select(Flags, Result.SelectedMultilib);
}
return false;
}

BareMetal::BareMetal(const Driver &D, const llvm::Triple &Triple,
const ArgList &Args)
: ToolChain(D, Triple, Args) {
getProgramPaths().push_back(getDriver().getInstalledDir());
if (getDriver().getInstalledDir() != getDriver().Dir)
getProgramPaths().push_back(getDriver().Dir);

findMultilibs(D, Triple, Args);
SmallString<128> SysRoot(computeSysRoot());
if (!SysRoot.empty()) {
llvm::sys::path::append(SysRoot, "lib");
Expand Down Expand Up @@ -73,6 +139,17 @@ static bool isRISCVBareMetal(const llvm::Triple &Triple) {
return Triple.getEnvironmentName() == "elf";
}

void BareMetal::findMultilibs(const Driver &D, const llvm::Triple &Triple,
const ArgList &Args) {
DetectedMultilibs Result;
if (isRISCVBareMetal(Triple)) {
if (findRISCVMultilibs(D, Triple, Args, Result)) {
SelectedMultilib = Result.SelectedMultilib;
Multilibs = Result.Multilibs;
}
}
}

bool BareMetal::handlesTarget(const llvm::Triple &Triple) {
return isARMBareMetal(Triple) || isRISCVBareMetal(Triple);
}
Expand All @@ -91,17 +168,19 @@ std::string BareMetal::getCompilerRTBasename(const llvm::opt::ArgList &,
std::string BareMetal::getRuntimesDir() const {
SmallString<128> Dir(getDriver().ResourceDir);
llvm::sys::path::append(Dir, "lib", "baremetal");
Dir += SelectedMultilib.gccSuffix();
return std::string(Dir.str());
}

std::string BareMetal::computeSysRoot() const {
if (!getDriver().SysRoot.empty())
return getDriver().SysRoot;
return getDriver().SysRoot + SelectedMultilib.osSuffix();

SmallString<128> SysRootDir;
llvm::sys::path::append(SysRootDir, getDriver().Dir, "../lib/clang-runtimes",
getDriver().getTargetTriple());

SysRootDir += SelectedMultilib.osSuffix();
return std::string(SysRootDir);
}

Expand Down
4 changes: 4 additions & 0 deletions clang/lib/Driver/ToolChains/BareMetal.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ class LLVM_LIBRARY_VISIBILITY BareMetal : public ToolChain {
~BareMetal() override = default;

static bool handlesTarget(const llvm::Triple &Triple);

void findMultilibs(const Driver &D, const llvm::Triple &Triple,
const llvm::opt::ArgList &Args);

protected:
Tool *buildLinker() const override;

Expand Down
6 changes: 3 additions & 3 deletions clang/lib/Frontend/FrontendAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ static bool loadModuleMapForModuleBuild(CompilerInstance &CI, bool IsSystem,

// Map the current input to a file.
FileID ModuleMapID = SrcMgr.getMainFileID();
const FileEntry *ModuleMap = SrcMgr.getFileEntryForID(ModuleMapID);
Optional<FileEntryRef> ModuleMap = SrcMgr.getFileEntryRefForID(ModuleMapID);

// If the module map is preprocessed, handle the initial line marker;
// line directives are not part of the module map syntax in general.
Expand All @@ -445,7 +445,7 @@ static bool loadModuleMapForModuleBuild(CompilerInstance &CI, bool IsSystem,
}

// Load the module map file.
if (HS.loadModuleMapFile(ModuleMap, IsSystem, ModuleMapID, &Offset,
if (HS.loadModuleMapFile(*ModuleMap, IsSystem, ModuleMapID, &Offset,
PresumedModuleMapFile))
return true;

Expand Down Expand Up @@ -807,7 +807,7 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI,

// If we were asked to load any module map files, do so now.
for (const auto &Filename : CI.getFrontendOpts().ModuleMapFiles) {
if (auto File = CI.getFileManager().getFile(Filename))
if (auto File = CI.getFileManager().getOptionalFileRef(Filename))
CI.getPreprocessor().getHeaderSearchInfo().loadModuleMapFile(
*File, /*IsSystem*/false);
else
Expand Down
Loading

0 comments on commit bdc55c2

Please sign in to comment.