Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions llvm/include/llvm/MC/MCTargetOptionsCommandFlags.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ namespace llvm {

class MCTargetOptions;
enum class EmitDwarfUnwindType;
class StringRef;

namespace mc {

Expand Down Expand Up @@ -62,9 +63,9 @@ LLVM_ABI bool getX86RelaxRelocations();

LLVM_ABI bool getX86Sse2Avx();

LLVM_ABI std::string getABIName();
LLVM_ABI StringRef getABIName();

LLVM_ABI std::string getAsSecureLogFile();
LLVM_ABI StringRef getAsSecureLogFile();

/// Create this object with static storage to register mc-related command
/// line options.
Expand Down
11 changes: 9 additions & 2 deletions llvm/lib/MC/MCTargetOptionsCommandFlags.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ using namespace llvm;
return *NAME##View; \
}

#define MCSTROPT(NAME) \
static cl::opt<std::string> *NAME##View; \
StringRef llvm::mc::get##NAME() { \
assert(NAME##View && "RegisterMCTargetOptionsFlags not created."); \
return *NAME##View; \
}

#define MCOPT_EXP(TY, NAME) \
MCOPT(TY, NAME) \
std::optional<TY> llvm::mc::getExplicit##NAME() { \
Expand Down Expand Up @@ -52,8 +59,8 @@ MCOPT(bool, Crel)
MCOPT(bool, ImplicitMapSyms)
MCOPT(bool, X86RelaxRelocations)
MCOPT(bool, X86Sse2Avx)
MCOPT(std::string, ABIName)
MCOPT(std::string, AsSecureLogFile)
MCSTROPT(ABIName)
MCSTROPT(AsSecureLogFile)

llvm::mc::RegisterMCTargetOptionsFlags::RegisterMCTargetOptionsFlags() {
#define MCBINDOPT(NAME) \
Expand Down
9 changes: 9 additions & 0 deletions llvm/test/tools/opt/infer-data-layout-target-abi.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
; REQUIRES: mips-registered-target
;; Check that we infer the correct datalayout from a target triple
; RUN: opt -mtriple=mips64-- -S -passes=no-op-module -target-abi=n32 < %s | FileCheck -check-prefix=N32 %s
; RUN: opt -mtriple=mips64-- -S -passes=no-op-module -target-abi=n64 < %s | FileCheck -check-prefix=N64 %s

target datalayout = ""

; N32: target datalayout = "E-m:e-p:32:32-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
; N64: target datalayout = "E-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
9 changes: 5 additions & 4 deletions llvm/tools/opt/optdriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "llvm/InitializePasses.h"
#include "llvm/LinkAllIR.h"
#include "llvm/LinkAllPasses.h"
#include "llvm/MC/MCTargetOptionsCommandFlags.h"
#include "llvm/MC/TargetRegistry.h"
#include "llvm/Passes/PassPlugin.h"
#include "llvm/Remarks/HotnessThresholdParser.h"
Expand Down Expand Up @@ -516,6 +517,8 @@ optMain(int argc, char **argv,

codegen::MaybeEnableStatistics();

StringRef ABIName = mc::getABIName(); // FIXME: Handle module flag.

// Load the input module...
auto SetDataLayout = [&](StringRef IRTriple,
StringRef IRLayout) -> std::optional<std::string> {
Expand All @@ -541,7 +544,7 @@ optMain(int argc, char **argv,

Triple TT(TripleStr);

std::string Str = TT.computeDataLayout();
std::string Str = TT.computeDataLayout(ABIName);
if (Str.empty()) {
errs() << argv[0]
<< ": warning: failed to infer data layout from target triple\n";
Expand Down Expand Up @@ -677,9 +680,7 @@ optMain(int argc, char **argv,

RTLIB::RuntimeLibcallsInfo RTLCI(ModuleTriple, codegen::getExceptionModel(),
codegen::getFloatABIForCalls(),
codegen::getEABIVersion(),
"", // FIXME: Get ABI name from MCOptions
VecLib);
codegen::getEABIVersion(), ABIName, VecLib);

// The -disable-simplify-libcalls flag actually disables all builtin optzns.
if (DisableSimplifyLibCalls)
Expand Down
Loading