[llvm-branch-commits] [cfe-branch] r124410 - in /cfe/branches/Apple/sill: lib/CodeGen/CGDecl.cpp lib/CodeGen/CGStmt.cpp test/CodeGen/asm-variable.c
Daniel Dunbar
daniel at zuster.org
Thu Jan 27 12:09:03 PST 2011
Author: ddunbar
Date: Thu Jan 27 14:09:03 2011
New Revision: 124410
URL: http://llvm.org/viewvc/llvm-project?rev=124410&view=rev
Log:
Merge r122643:
--
Author: Rafael Espindola <rafael.espindola at gmail.com>
Date: Thu Dec 30 22:59:32 2010 +0000
Add support for declaring register contraints in variables. They are only used
in asm statements:
register int foo asm("rdi");
asm("..." : ... "r" (foo) ...
We also only accept these variables if the constraint in the asm statement is "r".
This fixes most of PR3933.
Added:
cfe/branches/Apple/sill/test/CodeGen/asm-variable.c
Modified:
cfe/branches/Apple/sill/lib/CodeGen/CGDecl.cpp
cfe/branches/Apple/sill/lib/CodeGen/CGStmt.cpp
Modified: cfe/branches/Apple/sill/lib/CodeGen/CGDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/sill/lib/CodeGen/CGDecl.cpp?rev=124410&r1=124409&r2=124410&view=diff
==============================================================================
--- cfe/branches/Apple/sill/lib/CodeGen/CGDecl.cpp (original)
+++ cfe/branches/Apple/sill/lib/CodeGen/CGDecl.cpp Thu Jan 27 14:09:03 2011
@@ -103,9 +103,6 @@
/// EmitVarDecl - This method handles emission of any variable declaration
/// inside a function, including static vars etc.
void CodeGenFunction::EmitVarDecl(const VarDecl &D) {
- if (D.hasAttr<AsmLabelAttr>())
- CGM.ErrorUnsupported(&D, "__asm__");
-
switch (D.getStorageClass()) {
case SC_None:
case SC_Auto:
Modified: cfe/branches/Apple/sill/lib/CodeGen/CGStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/sill/lib/CodeGen/CGStmt.cpp?rev=124410&r1=124409&r2=124410&view=diff
==============================================================================
--- cfe/branches/Apple/sill/lib/CodeGen/CGStmt.cpp (original)
+++ cfe/branches/Apple/sill/lib/CodeGen/CGStmt.cpp Thu Jan 27 14:09:03 2011
@@ -904,6 +904,32 @@
return Result;
}
+static std::string
+AddVariableConstraits(const std::string &Constraint, const Expr &AsmExpr,
+ const TargetInfo &Target, CodeGenModule &CGM,
+ const AsmStmt &Stmt) {
+ const DeclRefExpr *AsmDeclRef = dyn_cast<DeclRefExpr>(&AsmExpr);
+ if (!AsmDeclRef)
+ return Constraint;
+ const ValueDecl &Value = *AsmDeclRef->getDecl();
+ const VarDecl *Variable = dyn_cast<VarDecl>(&Value);
+ if (!Variable)
+ return Constraint;
+ AsmLabelAttr *Attr = Variable->getAttr<AsmLabelAttr>();
+ if (!Attr)
+ return Constraint;
+ llvm::StringRef Register = Attr->getLabel();
+ if (!Target.isValidGCCRegisterName(Register)) {
+ CGM.ErrorUnsupported(Variable, "__asm__");
+ return Constraint;
+ }
+ if (Constraint != "r") {
+ CGM.ErrorUnsupported(&Stmt, "__asm__");
+ return Constraint;
+ }
+ return "{" + Register.str() + "}";
+}
+
llvm::Value*
CodeGenFunction::EmitAsmInputLValue(const AsmStmt &S,
const TargetInfo::ConstraintInfo &Info,
@@ -1012,6 +1038,9 @@
const Expr *OutExpr = S.getOutputExpr(i);
OutExpr = OutExpr->IgnoreParenNoopCasts(getContext());
+ OutputConstraint = AddVariableConstraits(OutputConstraint, *OutExpr, Target,
+ CGM, S);
+
LValue Dest = EmitLValue(OutExpr);
if (!Constraints.empty())
Constraints += ',';
@@ -1089,6 +1118,11 @@
InputConstraint = SimplifyConstraint(InputConstraint.c_str(), Target,
&OutputConstraintInfos);
+ InputConstraint =
+ AddVariableConstraits(InputConstraint,
+ *InputExpr->IgnoreParenNoopCasts(getContext()),
+ Target, CGM, S);
+
llvm::Value *Arg = EmitAsmInput(S, Info, InputExpr, Constraints);
// If this input argument is tied to a larger output result, extend the
Added: cfe/branches/Apple/sill/test/CodeGen/asm-variable.c
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/sill/test/CodeGen/asm-variable.c?rev=124410&view=auto
==============================================================================
--- cfe/branches/Apple/sill/test/CodeGen/asm-variable.c (added)
+++ cfe/branches/Apple/sill/test/CodeGen/asm-variable.c Thu Jan 27 14:09:03 2011
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck %s
+
+unsigned long long foo(unsigned long long addr, unsigned long long a0,
+ unsigned long long a1, unsigned long long a2,
+ unsigned long long a3, unsigned long long a4,
+ unsigned long long a5) {
+ register unsigned long long result asm("rax");
+ register unsigned long long b0 asm("rdi");
+ register unsigned long long b1 asm("rsi");
+ register unsigned long long b2 asm("rdx");
+ register unsigned long long b3 asm("rcx");
+ register unsigned long long b4 asm("r8");
+ register unsigned long long b5 asm("r9");
+
+ b0 = a0;
+ b1 = a1;
+ b2 = a2;
+ b3 = a3;
+ b4 = a4;
+ b5 = a5;
+
+ asm("call *%1" : "=r" (result)
+ : "r"(addr), "r" (b0), "r" (b1), "r" (b2), "r" (b3), "r" (b4), "r" (b5));
+ return result;
+}
+
+// CHECK: call i64 asm "call *$1", "={rax},r,{rdi},{rsi},{rdx},{rcx},{r8},{r9},~{dirflag},~{fpsr},~{flags}"
More information about the llvm-branch-commits
mailing list