class MDBuilder {
LLVMContext &Context;
- MDString *getFastString() {
- return createString("fast");
- }
public:
MDBuilder(LLVMContext &context) : Context(context) {}
// FPMath metadata.
//===------------------------------------------------------------------===//
- /// \brief Return metadata with appropriate settings for 'fast math'.
- MDNode *createFastFPMath() {
- return MDNode::get(Context, getFastString());
- }
-
- /// \brief Return metadata with the given settings. Special values for the
- /// Accuracy parameter are 0.0, which means the default (maximal precision)
- /// setting; and negative values which all mean 'fast'.
+ /// \brief Return metadata with the given settings. The special value 0.0
+ /// for the Accuracy parameter indicates the default (maximal precision)
+ /// setting.
MDNode *createFPMath(float Accuracy) {
if (Accuracy == 0.0)
return 0;
- if (Accuracy < 0.0)
- return MDNode::get(Context, getFastString());
assert(Accuracy > 0.0 && "Invalid fpmath accuracy!");
Value *Op = ConstantFP::get(Type::getFloatTy(Context), Accuracy);
return MDNode::get(Context, Op);
}
+ //===------------------------------------------------------------------===//
+ // Prof metadata.
+ //===------------------------------------------------------------------===//
+
+ /// \brief Return metadata containing two branch weights.
+ MDNode *createBranchWeights(uint32_t TrueWeight, uint32_t FalseWeight) {
+ uint32_t Weights[] = { TrueWeight, FalseWeight };
+ return createBranchWeights(Weights);
+ }
+
+ /// \brief Return metadata containing a number of branch weights.
+ MDNode *createBranchWeights(ArrayRef<uint32_t> Weights) {
+ assert(Weights.size() >= 2 && "Need at least two branch weights!");
+
+ SmallVector<Value *, 4> Vals(Weights.size()+1);
+ Vals[0] = createString("branch_weights");
+
+ Type *Int32Ty = Type::getInt32Ty(Context);
+ for (unsigned i = 0, e = Weights.size(); i != e; ++i)
+ Vals[i+1] = ConstantInt::get(Int32Ty, Weights[i]);
+
+ return MDNode::get(Context, Vals);
+ }
//===------------------------------------------------------------------===//
// Range metadata.