Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set up arch info for integrated assembler #22

Merged
merged 1 commit into from
Aug 13, 2022
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
33 changes: 20 additions & 13 deletions driver/CompileGo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -469,8 +469,25 @@ bool CompileGoImpl::setup(const Action &jobAction)
Options.AllowFPOpFusion = *dofuse;

// Support -march
std::string cpuStr;
opt::Arg *cpuarg = args_.getLastArg(gollvm::options::OPT_march_EQ);
if (!setupArch(cpuarg, targetCpuAttr_, targetFeaturesAttr_, triple_, progname_))
return false;

// Create target machine
Optional<llvm::CodeModel::Model> CM = None;
target_.reset(
TheTarget->createTargetMachine(triple_.getTriple(),
targetCpuAttr_, targetFeaturesAttr_,
Options, driver_.reconcileRelocModel(),
CM, cgolvl_));
assert(target_.get() && "Could not allocate target machine!");

return true;
}

bool setupArch(opt::Arg *cpuarg, std::string &cpu, std::string &attrs,
Triple triple_, const char *progname_) {
std::string cpuStr;
if (cpuarg != nullptr) {
std::string val(cpuarg->getValue());
if (val == "native")
Expand Down Expand Up @@ -510,18 +527,8 @@ bool CompileGoImpl::setup(const Action &jobAction)
return false;
}
}
targetCpuAttr_ = cpuAttrs->cpu;
targetFeaturesAttr_ = cpuAttrs->attrs;

// Create target machine
Optional<llvm::CodeModel::Model> CM = None;
target_.reset(
TheTarget->createTargetMachine(triple_.getTriple(),
targetCpuAttr_, targetFeaturesAttr_,
Options, driver_.reconcileRelocModel(),
CM, cgolvl_));
assert(target_.get() && "Could not allocate target machine!");

cpu = cpuAttrs->cpu;
attrs = cpuAttrs->attrs;
return true;
}

Expand Down
3 changes: 3 additions & 0 deletions driver/CompileGo.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ class CompileGo : public InternalTool {
std::unique_ptr<CompileGoImpl> impl_;
};

bool setupArch(llvm::opt::Arg *cpuarg, std::string &cpu, std::string &attrs,
llvm::Triple triple_, const char *progname_);

} // end namespace driver
} // end namespace gollvm

Expand Down
3 changes: 2 additions & 1 deletion driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ bool Driver::supportedAsmOptions()
continue;
}
if (value.startswith("-compress-debug-sections") ||
value.startswith("--compress-debug-sections")) {
value.startswith("--compress-debug-sections") ||
value.startswith("-march")) {
continue;
}
// Unrecognized -Wa,... option
Expand Down
15 changes: 5 additions & 10 deletions driver/IntegAssembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "GollvmOptions.h"
#include "GollvmConfig.h"
#include "GollvmPasses.h"
#include "CompileGo.h"

#include "Action.h"
#include "Artifact.h"
Expand Down Expand Up @@ -178,23 +179,15 @@ bool IntegAssemblerImpl::invokeAssembler()
assert(MRI && "Unable to create target register info!");

MCTargetOptions MCOptions;
if (triple_.getArch() == llvm::Triple::riscv64)
MCOptions.ABIName = "lp64d";
std::unique_ptr<MCAsmInfo> MAI(
TheTarget->createMCAsmInfo(*MRI, Trip, MCOptions));
assert(MAI && "Unable to create target asm info!");

// Note: -Xassembler and -Wa, options should already have been
// examined at this point.

// FIXME: no support yet for -march (bring over from CompileGo.cpp)
opt::Arg *cpuarg = args_.getLastArg(gollvm::options::OPT_march_EQ);
if (cpuarg != nullptr) {
errs() << progname_ << ": internal error: option '"
<< cpuarg->getAsString(args_)
<< "' not yet implemented in integrated assembler\n";
assert(false);
return false;
}

// Support for compressed debug.
llvm::DebugCompressionType CompressDebugSections =
llvm::DebugCompressionType::None;
Expand All @@ -208,6 +201,8 @@ bool IntegAssemblerImpl::invokeAssembler()
// Build up the feature string from the target feature list.
std::string FS;
std::string CPU;
opt::Arg *cpuarg = args_.getLastArg(gollvm::options::OPT_march_EQ);
setupArch(cpuarg, CPU, FS, triple_, progname_);
std::unique_ptr<MCStreamer> Str;
std::unique_ptr<MCInstrInfo> MCII(TheTarget->createMCInstrInfo());
std::unique_ptr<MCSubtargetInfo> STI(
Expand Down