[ms-inline asm] Add basic codegen support for simple asm stmts. Currently,

only machine specific clobbers are modeled.

llvm-svn: 161524
This commit is contained in:
Chad Rosier 2012-08-08 21:15:52 +00:00
parent 0415f3e138
commit 360e1763d5
2 changed files with 17 additions and 1 deletions

View File

@ -1686,4 +1686,19 @@ void CodeGenFunction::EmitMSAsmStmt(const MSAsmStmt &S) {
// MS-style inline assembly is not fully supported, so sema emits a warning. // MS-style inline assembly is not fully supported, so sema emits a warning.
if (!CGM.getCodeGenOpts().EmitMicrosoftInlineAsm) if (!CGM.getCodeGenOpts().EmitMicrosoftInlineAsm)
return; return;
assert (S.isSimple() && "CodeGen can only handle simple MSAsmStmts.");
std::vector<llvm::Value*> Args;
std::vector<llvm::Type *> ArgTypes;
std::string MachineClobbers = Target.getClobbers();
llvm::FunctionType *FTy =
llvm::FunctionType::get(VoidTy, ArgTypes, false);
llvm::InlineAsm *IA =
llvm::InlineAsm::get(FTy, *S.getAsmString(), MachineClobbers, true);
llvm::CallInst *Result = Builder.CreateCall(IA, Args);
Result->addAttribute(~0, llvm::Attribute::NoUnwind);
} }

View File

@ -1,7 +1,8 @@
// RUN: %clang_cc1 %s -triple x86_64-apple-darwin10 -O0 -fms-extensions -w -emit-llvm -o - | FileCheck %s // RUN: %clang_cc1 %s -triple x86_64-apple-darwin10 -O0 -fms-extensions -fenable-experimental-ms-inline-asm -w -emit-llvm -o - | FileCheck %s
void t1() { void t1() {
// CHECK: @t1 // CHECK: @t1
// CHECK: call void asm sideeffect "", "~{dirflag},~{fpsr},~{flags}"() nounwind
// CHECK: ret void // CHECK: ret void
__asm {} __asm {}
} }