From 6252bd8eac35653bc0e9c66bd7920735cee1b362 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Thu, 5 Jan 2017 05:56:39 +0000 Subject: [PATCH] MC: support passing search paths to the IAS This is needed to support inclusion in inline assembly via the `.include` directive. llvm-svn: 291085 --- llvm/include/llvm/MC/MCTargetOptions.h | 10 +++++++++- llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp | 2 ++ llvm/test/MC/AsmParser/include.ll | 13 +++++++++++++ llvm/test/MC/AsmParser/include/function.x | 3 +++ llvm/test/MC/AsmParser/include/module.x | 3 +++ llvm/tools/llc/llc.cpp | 3 +++ 6 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 llvm/test/MC/AsmParser/include.ll create mode 100644 llvm/test/MC/AsmParser/include/function.x create mode 100644 llvm/test/MC/AsmParser/include/module.x diff --git a/llvm/include/llvm/MC/MCTargetOptions.h b/llvm/include/llvm/MC/MCTargetOptions.h index a300c4f6fb00..25642379ac9f 100644 --- a/llvm/include/llvm/MC/MCTargetOptions.h +++ b/llvm/include/llvm/MC/MCTargetOptions.h @@ -11,6 +11,7 @@ #define LLVM_MC_MCTARGETOPTIONS_H #include +#include namespace llvm { @@ -51,11 +52,17 @@ public: bool PreserveAsmComments : 1; int DwarfVersion; + /// getABIName - If this returns a non-empty string this represents the /// textual name of the ABI that we want the backend to use, e.g. o32, or /// aapcs-linux. StringRef getABIName() const; std::string ABIName; + + /// Additional paths to search for `.include` directives when using the + /// integrated assembler. + std::vector IASSearchPaths; + MCTargetOptions(); }; @@ -75,7 +82,8 @@ inline bool operator==(const MCTargetOptions &LHS, const MCTargetOptions &RHS) { ARE_EQUAL(ShowMCInst) && ARE_EQUAL(AsmVerbose) && ARE_EQUAL(DwarfVersion) && - ARE_EQUAL(ABIName)); + ARE_EQUAL(ABIName) && + ARE_EQUAL(IASSearchPaths)); #undef ARE_EQUAL } diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp index 20075e41977f..57864e4e4d4f 100644 --- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp @@ -100,6 +100,8 @@ void AsmPrinter::EmitInlineAsm(StringRef Str, const MCSubtargetInfo &STI, } SourceMgr SrcMgr; + SrcMgr.setIncludeDirs(MCOptions.IASSearchPaths); + SrcMgrDiagInfo DiagInfo; // If the current LLVMContext has an inline asm handler, set it in SourceMgr. diff --git a/llvm/test/MC/AsmParser/include.ll b/llvm/test/MC/AsmParser/include.ll new file mode 100644 index 000000000000..cc733f70515f --- /dev/null +++ b/llvm/test/MC/AsmParser/include.ll @@ -0,0 +1,13 @@ +; RUN: llc -mtriple thumbv7--- -I %p/include -filetype asm -o - %s | FileCheck %s + +module asm ".include \22module.x\22" + +define arm_aapcscc void @f() { +entry: + call void asm sideeffect ".include \22function.x\22", ""() + ret void +} + +; CHECK: MODULE = 1 +; CHECK: FUNCTION = 1 + diff --git a/llvm/test/MC/AsmParser/include/function.x b/llvm/test/MC/AsmParser/include/function.x new file mode 100644 index 000000000000..582bfdfa6271 --- /dev/null +++ b/llvm/test/MC/AsmParser/include/function.x @@ -0,0 +1,3 @@ + +FUNCTION = 1 + diff --git a/llvm/test/MC/AsmParser/include/module.x b/llvm/test/MC/AsmParser/include/module.x new file mode 100644 index 000000000000..e93c615ef145 --- /dev/null +++ b/llvm/test/MC/AsmParser/include/module.x @@ -0,0 +1,3 @@ + +MODULE = 1 + diff --git a/llvm/tools/llc/llc.cpp b/llvm/tools/llc/llc.cpp index aa0beb45b4e9..a76d3249674f 100644 --- a/llvm/tools/llc/llc.cpp +++ b/llvm/tools/llc/llc.cpp @@ -134,6 +134,8 @@ static cl::opt StartAfter("start-after", cl::desc("Resume compilation after a specific pass"), cl::value_desc("pass-name"), cl::init("")); +static cl::list IncludeDirs("I", cl::desc("include search path")); + namespace { static ManagedStatic> RunPassNames; @@ -398,6 +400,7 @@ static int compileModule(char **argv, LLVMContext &Context) { Options.MCOptions.MCUseDwarfDirectory = EnableDwarfDirectory; Options.MCOptions.AsmVerbose = AsmVerbose; Options.MCOptions.PreserveAsmComments = PreserveComments; + Options.MCOptions.IASSearchPaths = IncludeDirs; std::unique_ptr Target( TheTarget->createTargetMachine(TheTriple.getTriple(), CPUStr, FeaturesStr,