calls. Remove special casing of inline asm from the
inliner. There is a potential problem: the verifier
rejects invokes of inline asm (not sure why). If an
asm call is not marked "nounwind" in some .ll, and
instcombine is not run, but the inliner is run, then
an illegal module will be created. This is bad but
I'm not sure what the best approach is. I'm tempted
to remove the check in the verifier...
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@45073
91177308-0d34-0410-b5e6-
96231b3b80d8
/// @brief Determine if the call does not access or only reads memory.
bool onlyReadsMemory() const;
+ /// @brief Determine if the call cannot unwind.
+ bool isNoUnwind() const;
+
/// getType - Return the type of the instruction that generated this call site
///
const Type *getType() const { return I->getType(); }
}
}
+ if (isa<InlineAsm>(Callee) && !CS.isNoUnwind()) {
+ // Inline asm calls cannot throw - mark them 'nounwind'.
+ const ParamAttrsList *PAL = CS.getParamAttrs();
+ uint16_t RAttributes = PAL ? PAL->getParamAttrs(0) : 0;
+ RAttributes |= ParamAttr::NoUnwind;
+
+ ParamAttrsVector modVec;
+ modVec.push_back(ParamAttrsWithIndex::get(0, RAttributes));
+ PAL = ParamAttrsList::getModified(PAL, modVec);
+ CS.setParamAttrs(PAL);
+ Changed = true;
+ }
+
return Changed ? CS.getInstruction() : 0;
}
if (!isa<CallInst>(I)) continue;
CallInst *CI = cast<CallInst>(I);
- // If this call cannot unwind or is an inline asm, don't
- // convert it to an invoke.
- if (CI->isNoUnwind() || isa<InlineAsm>(CI->getCalledValue()))
+ // If this call cannot unwind, don't convert it to an invoke.
+ if (CI->isNoUnwind())
continue;
// Convert this function call into an invoke instruction.
else
return cast<InvokeInst>(I)->onlyReadsMemory();
}
+bool CallSite::isNoUnwind() const {
+ if (CallInst *CI = dyn_cast<CallInst>(I))
+ return CI->isNoUnwind();
+ else
+ return cast<InvokeInst>(I)->isNoUnwind();
+}
--- /dev/null
+// RUN: %llvmgcc %s -S -o - | grep nounwind
+
+void bar() { asm (""); }
define void @bc__support__high_resolution_time__clock() {
entry:
- call void asm "rdtsc\0A\09movl %eax, $0\0A\09movl %edx, $1", "=*imr,=*imr,~{dirflag},~{fpsr},~{flags},~{dx},~{ax}"( i32* null, i32* null )
+ call void asm "rdtsc\0A\09movl %eax, $0\0A\09movl %edx, $1", "=*imr,=*imr,~{dirflag},~{fpsr},~{flags},~{dx},~{ax}"( i32* null, i32* null ) nounwind
unreachable
}
--- /dev/null
+; RUN: llvm-as < %s | opt -instcombine | llvm-dis | grep nounwind
+
+define void @bar() {
+entry:
+ call void asm sideeffect "", "~{dirflag},~{fpsr},~{flags}"( )
+ ret void
+}