Skip to content

Commit

Permalink
Add LinkageType::ExternalPlusArgv (#6452) (#6463)
Browse files Browse the repository at this point in the history
Allows us to skip generating metadata for offloaded hexagon funcs, which will never use it.
  • Loading branch information
steven-johnson authored Dec 2, 2021
1 parent 4877d26 commit 479d839
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 8 deletions.
1 change: 1 addition & 0 deletions python_bindings/src/PyEnums.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ void define_enums(py::module &m) {
py::enum_<LinkageType>(m, "LinkageType")
.value("External", LinkageType::External)
.value("ExternalPlusMetadata", LinkageType::ExternalPlusMetadata)
.value("ExternalPlusArgv", LinkageType::ExternalPlusArgv)
.value("Internal", LinkageType::Internal);

py::enum_<LoopAlignStrategy>(m, "LoopAlignStrategy")
Expand Down
6 changes: 4 additions & 2 deletions src/CodeGen_C.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1888,11 +1888,13 @@ void CodeGen_C::compile(const LoweredFunc &f, const std::map<std::string, std::s
stream << "}\n";
}

if (f.linkage == LinkageType::ExternalPlusMetadata) {
if (f.linkage == LinkageType::ExternalPlusArgv || f.linkage == LinkageType::ExternalPlusMetadata) {
// Emit the argv version
emit_argv_wrapper(simple_name, args);
}

// And also the metadata.
if (f.linkage == LinkageType::ExternalPlusMetadata) {
// Emit the metadata.
emit_metadata_getter(simple_name, args, metadata_name_map);
}

Expand Down
13 changes: 8 additions & 5 deletions src/CodeGen_LLVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ llvm::GlobalValue::LinkageTypes llvm_linkage(LinkageType t) {
return llvm::GlobalValue::ExternalLinkage;

// switch (t) {
// case LinkageType::ExternalPlusArgv:
// case LinkageType::ExternalPlusMetadata:
// case LinkageType::External:
// return llvm::GlobalValue::ExternalLinkage;
Expand Down Expand Up @@ -511,13 +512,15 @@ std::unique_ptr<llvm::Module> CodeGen_LLVM::compile(const Module &input) {

// If the Func is externally visible, also create the argv wrapper and metadata.
// (useful for calling from JIT and other machine interfaces).
if (f.linkage == LinkageType::ExternalPlusMetadata) {
if (f.linkage == LinkageType::ExternalPlusArgv || f.linkage == LinkageType::ExternalPlusMetadata) {
llvm::Function *wrapper = add_argv_wrapper(function, names.argv_name);
llvm::Function *metadata_getter = embed_metadata_getter(names.metadata_name,
names.simple_name, f.args, input.get_metadata_name_map());
if (f.linkage == LinkageType::ExternalPlusMetadata) {
llvm::Function *metadata_getter = embed_metadata_getter(names.metadata_name,
names.simple_name, f.args, input.get_metadata_name_map());

if (target.has_feature(Target::Matlab)) {
define_matlab_wrapper(module.get(), wrapper, metadata_getter);
if (target.has_feature(Target::Matlab)) {
define_matlab_wrapper(module.get(), wrapper, metadata_getter);
}
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/HexagonOffload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,8 @@ class InjectHexagonRpc : public IRMutator {
LoweredArgument arg(i.first, Argument::InputScalar, i.second, 0, ArgumentEstimates{});
args.push_back(arg);
}
device_code.append(LoweredFunc(hex_name, args, body, LinkageType::ExternalPlusMetadata));
// We need the _argv function but not the _metadata.
device_code.append(LoweredFunc(hex_name, args, body, LinkageType::ExternalPlusArgv));

// Generate a call to hexagon_device_run.
std::vector<Expr> arg_sizes;
Expand Down
3 changes: 3 additions & 0 deletions src/IRPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,9 @@ ostream &operator<<(ostream &stream, const LoweredFunc &function) {

std::ostream &operator<<(std::ostream &stream, const LinkageType &type) {
switch (type) {
case LinkageType::ExternalPlusArgv:
stream << "external_plus_argv";
break;
case LinkageType::ExternalPlusMetadata:
stream << "external_plus_metadata";
break;
Expand Down
1 change: 1 addition & 0 deletions src/Module.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ enum class Output {
enum class LinkageType {
External, ///< Visible externally.
ExternalPlusMetadata, ///< Visible externally. Argument metadata and an argv wrapper are also generated.
ExternalPlusArgv, ///< Visible externally. Argv wrapper is generated but *not* argument metadata.
Internal, ///< Not visible externally, similar to 'static' linkage in C.
};

Expand Down

0 comments on commit 479d839

Please sign in to comment.