Skip to content

Commit

Permalink
MC: support passing search paths to the IAS
Browse files Browse the repository at this point in the history
This is needed to support inclusion in inline assembly via the
`.include` directive.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@291085 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
compnerd committed Jan 5, 2017
1 parent 6974a46 commit 50116a2
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 1 deletion.
10 changes: 9 additions & 1 deletion include/llvm/MC/MCTargetOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#define LLVM_MC_MCTARGETOPTIONS_H

#include <string>
#include <vector>

namespace llvm {

Expand Down Expand Up @@ -51,11 +52,17 @@ class MCTargetOptions {
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();
};

Expand All @@ -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
}

Expand Down
2 changes: 2 additions & 0 deletions lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
13 changes: 13 additions & 0 deletions test/MC/AsmParser/include.ll
Original file line number Diff line number Diff line change
@@ -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

3 changes: 3 additions & 0 deletions test/MC/AsmParser/include/function.x
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

FUNCTION = 1

3 changes: 3 additions & 0 deletions test/MC/AsmParser/include/module.x
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

MODULE = 1

3 changes: 3 additions & 0 deletions tools/llc/llc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ static cl::opt<std::string> StartAfter("start-after",
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;

Expand Down Expand Up @@ -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<TargetMachine> Target(
TheTarget->createTargetMachine(TheTriple.getTriple(), CPUStr, FeaturesStr,
Expand Down

0 comments on commit 50116a2

Please sign in to comment.