[cfe-commits] r70523 - in /cfe/trunk: lib/CodeGen/CGStmt.cpp test/CodeGen/asm-2.c
Anders Carlsson
andersca at mac.com
Thu Apr 30 17:16:05 PDT 2009
Author: andersca
Date: Thu Apr 30 19:16:04 2009
New Revision: 70523
URL: http://llvm.org/viewvc/llvm-project?rev=70523&view=rev
Log:
Don't use indirect memory destinations for inline asm. Fixes 6841383.
Added:
cfe/trunk/test/CodeGen/asm-2.c
Modified:
cfe/trunk/lib/CodeGen/CGStmt.cpp
Modified: cfe/trunk/lib/CodeGen/CGStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGStmt.cpp?rev=70523&r1=70522&r2=70523&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGStmt.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGStmt.cpp Thu Apr 30 19:16:04 2009
@@ -781,8 +781,8 @@
std::string Constraints;
- llvm::Value *ResultAddr = 0;
- const llvm::Type *ResultType = llvm::Type::VoidTy;
+ std::vector<llvm::Value *> ResultAddrs;
+ std::vector<const llvm::Type *> ResultTypes;
std::vector<const llvm::Type*> ArgTypes;
std::vector<llvm::Value*> Args;
@@ -812,18 +812,17 @@
LValue Dest = EmitLValue(OutExpr);
const llvm::Type *DestValueType =
cast<llvm::PointerType>(Dest.getAddress()->getType())->getElementType();
-
- // If the first output operand is not a memory dest, we'll
- // make it the return value.
- if (i == 0 && !Info.allowsMemory() && DestValueType->isSingleValueType()) {
- ResultAddr = Dest.getAddress();
- ResultType = DestValueType;
+
+ if (i != 0)
+ Constraints += ',';
+
+ if (!Info.allowsMemory() && DestValueType->isSingleValueType()) {
+ ResultAddrs.push_back(Dest.getAddress());
+ ResultTypes.push_back(DestValueType);
Constraints += "=" + OutputConstraint;
} else {
ArgTypes.push_back(Dest.getAddress()->getType());
Args.push_back(Dest.getAddress());
- if (i != 0)
- Constraints += ',';
Constraints += "=*";
Constraints += OutputConstraint;
}
@@ -900,17 +899,30 @@
Constraints += ',';
Constraints += MachineClobbers;
}
-
+
+ const llvm::Type *ResultType;
+ if (ResultTypes.empty())
+ ResultType = llvm::Type::VoidTy;
+ else if (ResultTypes.size() == 1)
+ ResultType = ResultTypes[0];
+ else
+ ResultType = llvm::StructType::get(ResultTypes);
+
const llvm::FunctionType *FTy =
llvm::FunctionType::get(ResultType, ArgTypes, false);
llvm::InlineAsm *IA =
llvm::InlineAsm::get(FTy, AsmString, Constraints,
S.isVolatile() || S.getNumOutputs() == 0);
- llvm::CallInst *Result
- = Builder.CreateCall(IA, Args.begin(), Args.end(), "");
+ llvm::CallInst *Result = Builder.CreateCall(IA, Args.begin(), Args.end());
Result->addAttribute(~0, llvm::Attribute::NoUnwind);
- if (ResultAddr) // FIXME: volatility
- Builder.CreateStore(Result, ResultAddr);
+ if (ResultTypes.size() == 1) {
+ Builder.CreateStore(Result, ResultAddrs[0]);
+ } else {
+ for (unsigned i = 0, e = ResultTypes.size(); i != e; ++i) {
+ llvm::Value *Tmp = Builder.CreateExtractValue(Result, i, "asmresult");
+ Builder.CreateStore(Tmp, ResultAddrs[i]);
+ }
+ }
}
Added: cfe/trunk/test/CodeGen/asm-2.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/asm-2.c?rev=70523&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/asm-2.c (added)
+++ cfe/trunk/test/CodeGen/asm-2.c Thu Apr 30 19:16:04 2009
@@ -0,0 +1,10 @@
+// RUN: clang-cc -emit-llvm %s -o %t -arch=i386 -O2 &&
+// RUN: not grep "load" %t
+
+// <rdar://problem/6841383>
+int cpuid(unsigned data) {
+ int a, b;
+
+ asm("xyz" :"=a"(a), "=d"(b) : "a"(data));
+ return a + b;
+}
\ No newline at end of file
More information about the cfe-commits
mailing list