add __traits(getTargetInfo, "dcomputeTargets") (#3090)

This commit is contained in:
Nicholas Wilson 2019-06-14 10:49:46 +08:00 committed by GitHub
parent e11079513c
commit b750ce0c27
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 30 additions and 2 deletions

View file

@ -2758,6 +2758,11 @@ extern (C++) final class TupleExp : Expression
}
}
static TupleExp create(Loc loc, Expressions* exps)
{
return new TupleExp(loc, exps);
}
override TupleExp toTupleExp()
{
return this;

View file

@ -424,6 +424,7 @@ public:
*/
Expressions *exps;
static TupleExp *create(Loc loc, Expressions *exps);
TupleExp *toTupleExp();
Expression *syntaxCopy();
bool equals(RootObject *o);

View file

@ -1073,9 +1073,9 @@ void codegenModules(Modules &modules) {
if (!computeModules.empty()) {
for (auto &mod : computeModules)
dccg.emit(mod);
dccg.writeModules();
}
dccg.writeModules();
// We may have removed all object files, if so don't link.
if (global.params.objfiles.dim == 0)
global.params.link = false;

View file

@ -269,5 +269,20 @@ Expression *Target::getTargetInfo(const char *name_, const Loc &loc) {
if (name == "cppStd")
return createIntegerExp(static_cast<unsigned>(global.params.cplusplus));
#if LDC_LLVM_SUPPORTED_TARGET_SPIRV || LDC_LLVM_SUPPORTED_TARGET_NVPTX
if (name == "dcomputeTargets") {
Expressions* exps = new Expressions();
for (auto &targ : opts::dcomputeTargets) {
exps->push(createStringExp(mem.xstrdup(targ.c_str())));
}
return TupleExp::create(loc, exps);
}
if (name == "dcomputeFilePrefix") {
return createStringExp(
mem.xstrdup(opts::dcomputeFilePrefix.c_str()));
}
#endif
return nullptr;
}

View file

@ -0,0 +1,7 @@
// Tests LDC-specific target __traits
// RUN: %ldc -c %s -mdcompute-targets=cuda-350 -mdcompute-file-prefix=testing
// REQUIRES: target_NVPTX
static assert([ __traits(getTargetInfo, "dcomputeTargets") ] == ["cuda-350"]);
static assert(__traits(getTargetInfo, "dcomputeFilePrefix") == "testing");