Skip to content

Commit 7f16e37

Browse files
committed
WIP: Hack away special cases for *naked* DMD-style inline asm
1 parent c7907b7 commit 7f16e37

File tree

4 files changed

+25
-13
lines changed

4 files changed

+25
-13
lines changed

gen/asm-x86.h

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2340,7 +2340,7 @@ struct AsmProcessor {
23402340
AsmCode *asmcode, AsmArgMode mode = Mode_Input) {
23412341
using namespace dmd;
23422342

2343-
if (sc->func->isNaked()) {
2343+
if (false && sc->func->isNaked()) {
23442344
switch (type) {
23452345
case Arg_Integer:
23462346
if (e->type->isUnsigned()) {
@@ -2392,16 +2392,28 @@ struct AsmProcessor {
23922392
llvm_unreachable("Unsupported argument in asm.");
23932393
break;
23942394
}
2395-
} else {
2396-
insnTemplate << fmt << "<<" << (mode == Mode_Input ? "in" : "out")
2397-
<< asmcode->args.size() << ">>";
2398-
asmcode->args.push_back(AsmArg(type, e, mode));
2395+
} else { // non-naked
2396+
if (type == Arg_Integer) {
2397+
if (e->type->isUnsigned()) {
2398+
insnTemplate << "$$" << e->toUInteger();
2399+
} else {
2400+
#ifndef ASM_X86_64
2401+
insnTemplate << "$$" << static_cast<sinteger_t>(e->toInteger());
2402+
#else
2403+
insnTemplate << "$$" << e->toInteger();
2404+
#endif
2405+
}
2406+
} else {
2407+
insnTemplate << fmt << "<<" << (mode == Mode_Input ? "in" : "out")
2408+
<< asmcode->args.size() << ">>";
2409+
asmcode->args.push_back(AsmArg(type, e, mode));
2410+
}
23992411
}
24002412
}
24012413
void addOperand2(const char *fmtpre, const char *fmtpost, AsmArgType type,
24022414
Expression *e, AsmCode *asmcode,
24032415
AsmArgMode mode = Mode_Input) {
2404-
if (sc->func->isNaked()) {
2416+
if (false && sc->func->isNaked()) {
24052417
// taken from above
24062418
error(stmt->loc, "only global variables can be referenced by identifier in "
24072419
"naked asm");
@@ -3081,7 +3093,7 @@ struct AsmProcessor {
30813093
// (Only for non-naked asm, as this isn't an issue for naked asm.)
30823094
//
30833095
// See also: https://lists.llvm.org/pipermail/llvm-dev/2017-August/116244.html
3084-
const auto forceLeadingDisplacement = hasConstDisplacement && !sc->func->isNaked();
3096+
const auto forceLeadingDisplacement = hasConstDisplacement;// && !sc->func->isNaked();
30853097
if (forceLeadingDisplacement) {
30863098
// Subtract 8 from our const-displacement, and prepare to add the 8 from the `H` modifier.
30873099
insnTemplate << "-8+";
@@ -3092,7 +3104,7 @@ struct AsmProcessor {
30923104
use_star = false;
30933105
}
30943106

3095-
if (!sc->func->isNaked()) // no addrexp in naked asm please :)
3107+
if (true || !sc->func->isNaked()) // no addrexp in naked asm please :)
30963108
{
30973109
Type *tt = pointerTo(e->type);
30983110
e = createAddrExp(Loc(), e);

gen/asmstmt.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,7 @@ void CompoundAsmStatement_toIR(CompoundAsmStatement *stmt, IRState *p) {
538538
continue;
539539
}
540540

541+
/*
541542
// if we already set things up for this branch target, skip
542543
if (gotoToVal.find(targetLabel) != gotoToVal.end()) {
543544
continue;
@@ -561,6 +562,7 @@ void CompoundAsmStatement_toIR(CompoundAsmStatement *stmt, IRState *p) {
561562
code << asmGotoEnd;
562563
563564
++n_goto;
565+
*/
564566
}
565567
if (code.str() != asmGotoEnd) {
566568
// finalize code

gen/functions.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -773,10 +773,8 @@ static LinkageWithCOMDAT lowerFuncLinkage(FuncDeclaration *fdecl) {
773773
return LinkageWithCOMDAT(LLGlobalValue::ExternalLinkage, false);
774774
}
775775

776-
// A body-less declaration always needs to be marked as external in LLVM
777-
// (also e.g. naked template functions which would otherwise be weak_odr,
778-
// but where the definition is in module-level inline asm).
779-
if (!fdecl->fbody || fdecl->isNaked()) {
776+
// A body-less declaration always needs to be marked as external in LLVM.
777+
if (!fdecl->fbody) {
780778
return LinkageWithCOMDAT(LLGlobalValue::ExternalLinkage, false);
781779
}
782780

tests/codegen/naked_asm_output.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,4 @@ int instantiate1() {
106106
}
107107

108108
// Verify naked attribute is present in attributes group
109-
// IR: attributes #[[ATTRS]] = {{{.*}}naked{{.*}}noinline{{.*}}nounwind{{.*}}optnone
109+
// IR: attributes #[[ATTRS]] = {{{.*}}naked{{.*}}noinline

0 commit comments

Comments
 (0)