diff options
author | Jennifer Yu <jennifer.yu@intel.com> | 2019-05-30 01:05:46 +0000 |
---|---|---|
committer | Jennifer Yu <jennifer.yu@intel.com> | 2019-05-30 01:05:46 +0000 |
commit | 954ec09aed4f2be04bb5f4e10dbb4ea8bd19ef9a (patch) | |
tree | 23479cbe88acf8d056fb2e8d5c44a9978290c5fb /clang/lib/AST/Stmt.cpp | |
parent | 192dd7df2f3104274db57e3b853390faa7e1aa25 (diff) | |
download | bcm5719-llvm-954ec09aed4f2be04bb5f4e10dbb4ea8bd19ef9a.tar.gz bcm5719-llvm-954ec09aed4f2be04bb5f4e10dbb4ea8bd19ef9a.zip |
clang support gnu asm goto.
Syntax:
asm [volatile] goto ( AssemblerTemplate
:
: InputOperands
: Clobbers
: GotoLabels)
https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html
New llvm IR is "callbr" for inline asm goto instead "call" for inline asm
For:
asm goto("testl %0, %0; jne %l1;" :: "r"(cond)::label_true, loop);
IR:
callbr void asm sideeffect "testl $0, $0; jne ${1:l};", "r,X,X,~{dirflag},~{fpsr},~{flags}"(i32 %0, i8* blockaddress(@foo, %label_true), i8* blockaddress(@foo, %loop)) #1
to label %asm.fallthrough [label %label_true, label %loop], !srcloc !3
asm.fallthrough:
Compiler need to generate:
1> a dummy constarint 'X' for each label.
2> an unique fallthrough label for each asm goto stmt " asm.fallthrough%number".
Diagnostic
1> duplicate asm operand name are used in output, input and label.
2> goto out of scope.
llvm-svn: 362045
Diffstat (limited to 'clang/lib/AST/Stmt.cpp')
-rw-r--r-- | clang/lib/AST/Stmt.cpp | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/clang/lib/AST/Stmt.cpp b/clang/lib/AST/Stmt.cpp index 4796ee87f72..e9a2c58f1a1 100644 --- a/clang/lib/AST/Stmt.cpp +++ b/clang/lib/AST/Stmt.cpp @@ -444,6 +444,14 @@ void GCCAsmStmt::setInputExpr(unsigned i, Expr *E) { Exprs[i + NumOutputs] = E; } +AddrLabelExpr *GCCAsmStmt::getLabelExpr(unsigned i) const { + return cast<AddrLabelExpr>(Exprs[i + NumInputs]); +} + +StringRef GCCAsmStmt::getLabelName(unsigned i) const { + return getLabelExpr(i)->getLabel()->getName(); +} + /// getInputConstraint - Return the specified input constraint. Unlike output /// constraints, these can be empty. StringRef GCCAsmStmt::getInputConstraint(unsigned i) const { @@ -456,13 +464,16 @@ void GCCAsmStmt::setOutputsAndInputsAndClobbers(const ASTContext &C, Stmt **Exprs, unsigned NumOutputs, unsigned NumInputs, + unsigned NumLabels, StringLiteral **Clobbers, unsigned NumClobbers) { this->NumOutputs = NumOutputs; this->NumInputs = NumInputs; this->NumClobbers = NumClobbers; + this->NumLabels = NumLabels; + assert(!(NumOutputs && NumLabels) && "asm goto cannot have outputs"); - unsigned NumExprs = NumOutputs + NumInputs; + unsigned NumExprs = NumOutputs + NumInputs + NumLabels; C.Deallocate(this->Names); this->Names = new (C) IdentifierInfo*[NumExprs]; @@ -497,6 +508,10 @@ int GCCAsmStmt::getNamedOperand(StringRef SymbolicName) const { if (getInputName(i) == SymbolicName) return getNumOutputs() + NumPlusOperands + i; + for (unsigned i = 0, e = getNumLabels(); i != e; ++i) + if (getLabelName(i) == SymbolicName) + return i + getNumInputs(); + // Not found. return -1; } @@ -614,8 +629,8 @@ unsigned GCCAsmStmt::AnalyzeAsmString(SmallVectorImpl<AsmStringPiece>&Pieces, while (CurPtr != StrEnd && isDigit(*CurPtr)) N = N*10 + ((*CurPtr++)-'0'); - unsigned NumOperands = - getNumOutputs() + getNumPlusOperands() + getNumInputs(); + unsigned NumOperands = getNumOutputs() + getNumPlusOperands() + + getNumInputs() + getNumLabels(); if (N >= NumOperands) { DiagOffs = CurPtr-StrStart-1; return diag::err_asm_invalid_operand_number; @@ -728,10 +743,12 @@ GCCAsmStmt::GCCAsmStmt(const ASTContext &C, SourceLocation asmloc, unsigned numinputs, IdentifierInfo **names, StringLiteral **constraints, Expr **exprs, StringLiteral *asmstr, unsigned numclobbers, - StringLiteral **clobbers, SourceLocation rparenloc) + StringLiteral **clobbers, unsigned numlabels, + SourceLocation rparenloc) : AsmStmt(GCCAsmStmtClass, asmloc, issimple, isvolatile, numoutputs, - numinputs, numclobbers), RParenLoc(rparenloc), AsmStr(asmstr) { - unsigned NumExprs = NumOutputs + NumInputs; + numinputs, numclobbers), + RParenLoc(rparenloc), AsmStr(asmstr), NumLabels(numlabels) { + unsigned NumExprs = NumOutputs + NumInputs + NumLabels; Names = new (C) IdentifierInfo*[NumExprs]; std::copy(names, names + NumExprs, Names); |