Skip to content

Commit

Permalink
Implement the fixed stack segment attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
pcwalton committed Apr 2, 2013
1 parent 7fe3ad5 commit 56dd407
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 16 deletions.
2 changes: 1 addition & 1 deletion include/llvm-c/Core.h
Original file line number Diff line number Diff line change
Expand Up @@ -1691,7 +1691,7 @@ void LLVMSetGC(LLVMValueRef Fn, const char *Name);
*
* @see llvm::Function::addAttribute()
*/
void LLVMAddFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
void LLVMAddFunctionAttr(LLVMValueRef Fn, unsigned PA, unsigned HighPA);

/**
* Obtain an attribute from a function.
Expand Down
1 change: 1 addition & 0 deletions include/llvm/IR/Attributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class Attribute {
///< 0 means unaligned (different from align(1))
AlwaysInline, ///< inline=always
ByVal, ///< Pass structure by value
FixedStackSegment, ///< Fixed-size stack segment
InlineHint, ///< Source said inlining was desirable
InReg, ///< Force argument to be passed in register
MinSize, ///< Function must be optimized for size first
Expand Down
4 changes: 4 additions & 0 deletions include/llvm/Target/TargetOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,10 @@ namespace llvm {
/// the value of this option.
FPOpFusion::FPOpFusionMode AllowFPOpFusion;

/// The size of the stack segment to use for functions with fixed-size
/// stack segments, in bytes.
unsigned FixedStackSegmentSize;

};
} // End llvm namespace

Expand Down
1 change: 1 addition & 0 deletions lib/AsmParser/LLLexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,7 @@ lltok::Kind LLLexer::LexIdentifier() {
KEYWORD(sanitize_memory);
KEYWORD(uwtable);
KEYWORD(zeroext);
KEYWORD(fixedstacksegment);

KEYWORD(type);
KEYWORD(opaque);
Expand Down
23 changes: 12 additions & 11 deletions lib/AsmParser/LLParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1159,17 +1159,18 @@ bool LLParser::ParseOptionalParamAttrs(AttrBuilder &B) {
case lltok::kw_sret: B.addAttribute(Attribute::StructRet); break;
case lltok::kw_zeroext: B.addAttribute(Attribute::ZExt); break;

case lltok::kw_alignstack: case lltok::kw_nounwind:
case lltok::kw_alwaysinline: case lltok::kw_optsize:
case lltok::kw_inlinehint: case lltok::kw_readnone:
case lltok::kw_minsize: case lltok::kw_readonly:
case lltok::kw_naked: case lltok::kw_returns_twice:
case lltok::kw_nobuiltin: case lltok::kw_sanitize_address:
case lltok::kw_noimplicitfloat: case lltok::kw_sanitize_memory:
case lltok::kw_noinline: case lltok::kw_sanitize_thread:
case lltok::kw_nonlazybind: case lltok::kw_ssp:
case lltok::kw_noredzone: case lltok::kw_sspreq:
case lltok::kw_noreturn: case lltok::kw_uwtable:
case lltok::kw_alignstack: case lltok::kw_nounwind:
case lltok::kw_alwaysinline: case lltok::kw_fixedstacksegment:
case lltok::kw_optsize: case lltok::kw_inlinehint:
case lltok::kw_readnone: case lltok::kw_minsize:
case lltok::kw_readonly: case lltok::kw_naked:
case lltok::kw_returns_twice: case lltok::kw_nobuiltin:
case lltok::kw_sanitize_address: case lltok::kw_noimplicitfloat:
case lltok::kw_sanitize_memory: case lltok::kw_noinline:
case lltok::kw_sanitize_thread: case lltok::kw_nonlazybind:
case lltok::kw_ssp: case lltok::kw_noredzone:
case lltok::kw_sspreq: case lltok::kw_noreturn:
case lltok::kw_uwtable:
HaveError |= Error(Lex.getLoc(), "invalid use of function-only attribute");
break;
}
Expand Down
1 change: 1 addition & 0 deletions lib/AsmParser/LLToken.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ namespace lltok {
kw_alwaysinline,
kw_sanitize_address,
kw_byval,
kw_fixedstacksegment,
kw_inlinehint,
kw_inreg,
kw_minsize,
Expand Down
6 changes: 5 additions & 1 deletion lib/IR/Attributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@ std::string Attribute::getAsString(bool InAttrGrp) const {
return "sanitize_thread";
if (hasAttribute(Attribute::SanitizeMemory))
return "sanitize_memory";
if (hasAttribute(Attribute::FixedStackSegment))
return "fixedstacksegment";
if (hasAttribute(Attribute::UWTable))
return "uwtable";
if (hasAttribute(Attribute::ZExt))
Expand Down Expand Up @@ -393,6 +395,7 @@ uint64_t AttributeImpl::getAttrMask(Attribute::AttrKind Val) {
case Attribute::SanitizeThread: return 1ULL << 36;
case Attribute::SanitizeMemory: return 1ULL << 37;
case Attribute::NoBuiltin: return 1ULL << 38;
case Attribute::FixedStackSegment: return 1ULL << 39;
}
llvm_unreachable("Unsupported attribute type");
}
Expand Down Expand Up @@ -1133,7 +1136,8 @@ void AttrBuilder::removeFunctionOnlyAttrs() {
.removeAttribute(Attribute::SanitizeMemory)
.removeAttribute(Attribute::MinSize)
.removeAttribute(Attribute::NoDuplicate)
.removeAttribute(Attribute::NoBuiltin);
.removeAttribute(Attribute::NoBuiltin)
.removeAttribute(Attribute::FixedStackSegment);
}

AttrBuilder &AttrBuilder::addRawValue(uint64_t Val) {
Expand Down
5 changes: 3 additions & 2 deletions lib/IR/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1385,10 +1385,11 @@ void LLVMSetGC(LLVMValueRef Fn, const char *GC) {
F->clearGC();
}

void LLVMAddFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA) {
void LLVMAddFunctionAttr(LLVMValueRef Fn, unsigned PA, unsigned HighPA) {
Function *Func = unwrap<Function>(Fn);
const AttributeSet PAL = Func->getAttributes();
AttrBuilder B(PA);
AttrBuilder B(((unsigned long long)PA) |
(((unsigned long long)HighPA) << 32));
const AttributeSet PALnew =
PAL.addAttributes(Func->getContext(), AttributeSet::FunctionIndex,
AttributeSet::get(Func->getContext(),
Expand Down
11 changes: 10 additions & 1 deletion lib/Target/ARM/ARMFrameLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1511,7 +1511,16 @@ ARMFrameLowering::adjustForSegmentedStacks(MachineFunction &MF) const {
MF.push_front(prevStackMBB);

// The required stack size that is aligend to ARM constant critarion.
AlignedStackSize = AlignToARMConstant(MFI->getStackSize());
uint64_t StackSize = MFI->getStackSize();

// If the front-end requested a fixed stack segment size, use that.
const Function *Fn = MF.getFunction();
if (Fn->getAttributes().hasAttribute(AttributeSet::FunctionIndex,
Attribute::FixedStackSegment)) {
StackSize = MF.getTarget().Options.FixedStackSegmentSize;
}

AlignedStackSize = AlignToARMConstant(StackSize);

// When the frame size is less than 256 we just compare the stack
// boundary directly to the value of the stack pointer, per gcc.
Expand Down
7 changes: 7 additions & 0 deletions lib/Target/X86/X86FrameLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1472,6 +1472,13 @@ X86FrameLowering::adjustForSegmentedStacks(MachineFunction &MF) const {
// prologue.
StackSize = MFI->getStackSize();

// If the front-end requested a fixed stack segment size, use that.
const Function *Fn = MF.getFunction();
if (Fn->getAttributes().hasAttribute(AttributeSet::FunctionIndex,
Attribute::FixedStackSegment)) {
StackSize = MF.getTarget().Options.FixedStackSegmentSize;
}

// When the frame size is less than 256 we just compare the stack
// boundary directly to the value of the stack pointer, per gcc.
bool CompareStackPointer = StackSize < kSplitStackAvailable;
Expand Down
6 changes: 6 additions & 0 deletions lib/Transforms/IPO/Inliner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ static bool InlineCallIfPossible(CallSite CS, InlineFunctionInfo &IFI,

AdjustCallerSSPLevel(Caller, Callee);

// If the inlined function has a fixed stack segment, then make the caller
// have a fixed stack segment as well.
if (Callee->getAttributes().hasAttribute(AttributeSet::FunctionIndex,
Attribute::FixedStackSegment))
Caller->addFnAttr(Attribute::FixedStackSegment);

// Look at all of the allocas that we inlined through this call site. If we
// have already inlined other allocas through other calls into this function,
// then we know that they have disjoint lifetimes and that we can merge them.
Expand Down

0 comments on commit 56dd407

Please sign in to comment.