MC: support passing search paths to the IAS
This is needed to support inclusion in inline assembly via the
`.include` directive.
llvm-svn: 291085
diff --git a/llvm/include/llvm/MC/MCTargetOptions.h b/llvm/include/llvm/MC/MCTargetOptions.h
index a300c4f..2564237 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 <string>
+#include <vector>
namespace llvm {
@@ -51,11 +52,17 @@
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<std::string> IASSearchPaths;
+
MCTargetOptions();
};
@@ -75,7 +82,8 @@
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 20075e4..57864e4 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
@@ -100,6 +100,8 @@
}
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 0000000..cc733f7
--- /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 0000000..582bfdf
--- /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 0000000..e93c615
--- /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 aa0beb4..a76d324 100644
--- a/llvm/tools/llc/llc.cpp
+++ b/llvm/tools/llc/llc.cpp
@@ -134,6 +134,8 @@
cl::desc("Resume compilation after a specific pass"),
cl::value_desc("pass-name"), cl::init(""));
+static cl::list<std::string> IncludeDirs("I", cl::desc("include search path"));
+
namespace {
static ManagedStatic<std::vector<std::string>> RunPassNames;
@@ -398,6 +400,7 @@
Options.MCOptions.MCUseDwarfDirectory = EnableDwarfDirectory;
Options.MCOptions.AsmVerbose = AsmVerbose;
Options.MCOptions.PreserveAsmComments = PreserveComments;
+ Options.MCOptions.IASSearchPaths = IncludeDirs;
std::unique_ptr<TargetMachine> Target(
TheTarget->createTargetMachine(TheTriple.getTriple(), CPUStr, FeaturesStr,